|
INET Framework for OMNeT++/OMNEST
|
00001 // 00002 // Copyright (C) 2005 Georg Lutz, Institut fuer Telematik, University of Karlsruhe 00003 // Copyright (C) 2005 Andras Varga 00004 // 00005 // This program is free software; you can redistribute it and/or 00006 // modify it under the terms of the GNU General Public License 00007 // as published by the Free Software Foundation; either version 2 00008 // of the License, or (at your option) any later version. 00009 // 00010 // This program is distributed in the hope that it will be useful, 00011 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00012 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00013 // GNU General Public License for more details. 00014 // 00015 // You should have received a copy of the GNU General Public License 00016 // along with this program; if not, see <http://www.gnu.org/licenses/>. 00017 // 00018 00019 #include "RandomWPMobility.h" 00020 00021 00022 Define_Module(RandomWPMobility); 00023 00024 00025 void RandomWPMobility::initialize(int stage) 00026 { 00027 LineSegmentsMobilityBase::initialize(stage); 00028 00029 if (stage == 0) 00030 { 00031 stationary = (par("speed").getType()=='L' || par("speed").getType()=='D') && (double)par("speed") == 0; 00032 nextMoveIsWait = false; 00033 } 00034 } 00035 00036 void RandomWPMobility::setTargetPosition() 00037 { 00038 if (nextMoveIsWait) 00039 { 00040 simtime_t waitTime = par("waitTime"); 00041 targetTime += waitTime; 00042 } 00043 else 00044 { 00045 targetPos = getRandomPosition(); 00046 double speed = par("speed"); 00047 double distance = pos.distance(targetPos); 00048 simtime_t travelTime = distance / speed; 00049 targetTime += travelTime; 00050 } 00051 00052 nextMoveIsWait = !nextMoveIsWait; 00053 } 00054 00055 void RandomWPMobility::fixIfHostGetsOutside() 00056 { 00057 raiseErrorIfOutside(); 00058 } 00059