00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023 #ifndef BASE_MOBILITY_H
00024 #define BASE_MOBILITY_H
00025
00026 #include "BatteryAccess.h"
00027 #include "BaseWorldUtility.h"
00028 #include "Coord.h"
00029 #include "Move.h"
00030
00060 class BaseMobility : public BatteryAccess
00061 {
00062 public:
00069 enum BorderPolicy {
00070 REFLECT,
00071 WRAP,
00072 PLACERANDOMLY,
00073 RAISEERROR
00074 };
00075
00081 enum BaseMobilityMsgKinds {
00082 MOVE_HOST = 21311,
00083 MOVE_TO_BORDER,
00086 LAST_BASE_MOBILITY_KIND,
00087 };
00088
00092 enum BorderHandling {
00093 NOWHERE,
00094 X_SMALLER,
00095 X_BIGGER,
00096 Y_SMALLER,
00097 Y_BIGGER,
00098 Z_SMALLER,
00099 Z_BIGGER
00100 };
00101
00102 protected:
00103
00105 BaseWorldUtility *world;
00106
00108 cModule* hostPtr;
00109 int hostId;
00110
00112 Move move;
00113
00115 int moveCategory;
00116
00118 simtime_t updateInterval;
00119
00121 cMessage* moveMsg;
00122
00124 bool coreDebug;
00125
00128 bool scaleNodeByDepth;
00129
00131 double playgroundScaleX;
00133 double playgroundScaleY;
00134
00136 double origDisplayWidth;
00138 double origDisplayHeight;
00139
00141 double origIconSize;
00142 public:
00143
00144 BaseMobility();
00145
00151 void handleMessage(cMessage *msg);
00152
00167 virtual void initialize(int);
00168
00170 virtual void finish(){};
00171
00172 protected:
00179 virtual int iconSizeTagToSize(const char* tag);
00180
00188 virtual const char* iconSizeToTag(double size);
00189
00199 virtual void handleSelfMsg( cMessage* );
00200
00210 virtual void handleBorderMsg( cMessage* );
00211
00221 virtual void makeMove(){
00222 error("BaseMobility does not move the host");
00223 };
00224
00234 virtual void updatePosition();
00235
00237 double playgroundSizeX() const {return world->getPgs()->getX();}
00238
00240 double playgroundSizeY() const {return world->getPgs()->getY();}
00241
00243 double playgroundSizeZ() const {return world->getPgs()->getZ();}
00244
00246 Coord getRandomPosition() { return world->getRandomPosition();}
00247
00256
00284 bool handleIfOutside(BorderPolicy, Coord&, Coord&, Coord&, double&);
00285
00298 virtual void fixIfHostGetsOutside(){
00299 error("fixIfHostGetsOutside has to be redefined by the user");
00300 };
00301
00312 BorderHandling checkIfOutside( Coord, Coord& );
00313
00320 void goToBorder( BorderPolicy, BorderHandling, Coord&, Coord& );
00321
00332 void reflectCoordinate(BorderHandling border, Coord& c);
00333
00349 void reflectIfOutside(BorderHandling, Coord&, Coord&, Coord&, double&);
00350
00362 void wrapIfOutside(BorderHandling, Coord&, Coord&);
00363
00374 void placeRandomlyIfOutside( Coord& );
00375
00378 };
00379
00380 #endif
00381