Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | File List | Namespace Members | Class Members | File Members | Related Pages

weatherarea.h

Go to the documentation of this file.
00001 //
00002 // C++ Interface: weatherarea
00003 //
00004 // Description: 
00005 //
00006 //
00007 // Author: Kevin Hirschmann <hirsch@dhcppc0>, (C) 2004
00008 //
00009 // Copyright: See COPYING file that comes with this distribution
00010 //
00011 //
00012 #ifndef WEATHERAREA_H
00013 #define WEATHERAREA_H
00014 
00015 #include <list>
00016 #include <map>
00017 #include <set>
00018 
00019 #include "gamemap.h"
00020 //#include "error.h"
00021 #include "ascstring.h"
00022 #include "geometry.h"
00023 #include "typen.h"
00024 #include "basestreaminterface.h"
00025 // #include "graphics/ascttfont.h"
00026 
00033 class Vector2D{
00034    private:
00035       int xComponent;
00036       int yComponent;
00037 
00038    public:
00042       Vector2D();
00048       Vector2D(int x, int y);
00052       ~Vector2D();
00057       int getXComponent() const;
00062       int getYComponent() const;
00067       double getLength() const;
00072       bool isZeroVector() const;
00073 };
00074 
00075 
00076 
00077 class IllegalValueException: public ASCmsgException{
00078 public:
00079 IllegalValueException(const ASCString& msg);
00080 ~IllegalValueException();
00081 };
00082 
00083 extern const char*  cdirections[];
00084 enum Direction {
00085 N,
00086 NE,
00087 SE,
00088 S,
00089 SW,
00090 NW,
00091 };
00092 
00093 
00094 enum FalloutType {
00095 DRY,
00096 LRAIN,
00097 HRAIN,
00098 LSNOW,
00099 HSNOW,
00100 ICE
00101 };
00102 
00103 struct WindData{
00104   unsigned int speed;
00105   Direction direction;
00106 };
00107 
00108 struct WeatherRect {
00109   int a, b, c, d;
00110 
00111 };
00112 
00113 typedef map<int, WindData> WindChanges;
00114 typedef multiset<tfield*> FieldSet;
00115 class WeatherSystem;
00116 class WeatherField;
00117 
00118 
00119 typedef list<tfield*> MapFields;
00120 typedef vector<WeatherField*> WeatherFields;
00121 typedef vector<int> Percentages;
00122 
00123 struct ltGTime{
00124 bool operator()(const GameTime& gt1, const GameTime& gt2) const{
00125   return gt1.abstime < gt2.abstime;
00126 }
00127 
00128 };
00132 class WeatherArea{
00133 private:
00134 WeatherFields area;
00135 GameMap* map;
00136 MapCoordinate center;
00137 int duration;
00138 int width;
00139 int height;
00140 int radius;
00141 FalloutType ft;
00142 Vector2D currentMovement;
00143 int stepCount;
00144 static const int MAXVALUE;
00145 static const int MAXOFFSET;
00146 float horizontalWindAccu;
00147 float verticalWindAccu;
00148 bool clustered;
00149 int seedValue;
00150 WeatherArea &operator=(const WeatherArea&);
00151 WeatherArea(const WeatherArea&);
00152 MapCoordinate calculateFieldPosition(MapCoordinate center, Vector2D relPos);
00153 
00154 
00155 short createAlgebraicSign();
00156 void step(WeatherRect r);
00157 int calculateCornerPoint(int a, int b, int c);
00158 int calculateDiamondPoint(int a, int b, int c, int d);
00159 int calculateCurrentOffset(int currentOffset);
00160 int calculateCornerPointValue(int a, int b, int c);
00161 int calculateDiamondPointValue(int a, int b, int c, int d);
00162 void createWeatherFields();
00163 
00164 public:
00165     WeatherArea(GameMap* map, int xCenter, int yCenter, int width, int height, int duration, FalloutType fType, unsigned int seedValue, bool clustered = true);
00166     WeatherArea(GameMap* map, int xCenter, int yCenter, int radius);
00167     WeatherArea(GameMap* map);
00168     
00169     ~WeatherArea();
00170     inline GameMap* getMap() const;
00171     
00172     Vector2D getWindVector() const;
00173    // void setWindVector(unsigned int speed, Direction windDirection);
00174     void updateMovementVector(unsigned int speed, Direction windDirection, double ratio);
00175     void setFalloutType(FalloutType fallout);    
00176     FalloutType getFalloutType() const;
00177     FalloutType getFalloutType(int value) const;
00178     int getWidth() const;
00179     int getHeight() const;
00180     float getHorizontalWindAccu() const;
00181     float getVerticalWindAccu() const;
00182     
00183     MapCoordinate getCenterPos() const{
00184       return center;
00185     }
00186     
00187     const WeatherField* getCenterField() const{
00188       return area[static_cast<int>(height/2 * ((area.size() % height)-1) +  (width/2 +0.5))];
00189     };
00190     
00191     int getDuration() const;
00192     void setDuration(int duration);
00193     
00194     void update(WeatherSystem* wSystem, FieldSet& processedFields);                
00195     void placeArea();
00196     void removeArea(FieldSet& processedFields);
00197     unsigned int createRandomValue(int limit); 
00198     
00199     void write (tnstream& outputStream) const;
00200     void read (tnstream& inputStream);
00201     
00202     
00203     
00204 };
00205 
00206 typedef multimap<GameTime, WeatherArea*, ltGTime> WeatherAreas;
00207 typedef list<WeatherArea*> WeatherAreaList;
00208 
00209 enum WeatherSystemMode {
00210 EVENTMODE,
00211 RANDOMMODE
00212 };
00213 
00214 class WeatherField{
00215 private:
00216 tfield* mapField;
00217 GameMap* map;
00218 int counter;
00219 int value;
00220 
00221 void setMapField(tfield* mapField);
00222 
00223 public:
00224 WeatherField(GameMap* map);
00225 WeatherField(MapCoordinate mapPos, const WeatherArea* area);
00226 ~WeatherField();
00227 void move(const Vector2D& vector);
00228 bool isOnMap(const GameMap* map) const;
00229 void update(const WeatherArea*, FieldSet& processedFields);
00230 void reset(GameMap* m, const WeatherArea*, FieldSet& processedFields);
00231 void write (tnstream& outputStream) const;
00232 void read (tnstream& inputStream);
00233 void setValue(int v);
00234 int getValue();
00235 
00236 MapCoordinate posInArea;
00237 };
00238 //**************************************************************************************************************************************
00239 class WeatherSystem : public SigC::Object{
00240 private:
00241 
00242 static const int WEATHERVERSION = 1;
00243 unsigned int seedValue;
00244 int timeInterval;
00245 int areaSpawnAmount;
00246 int access2RandCount;
00247 int maxForecast;
00248 
00249 
00250 float windspeed2FieldRatio;
00251 int windspeed;
00252 Direction globalWindDirection;
00253 
00254 float lowerRandomSize;
00255 float upperRandomSize;
00256 
00257 int lowerRandomDuration;
00258 int upperRandomDuration;
00259 
00260 bool seedValueIsSet;
00261 FalloutType defaultFallout;
00262 
00263 WeatherAreas weatherAreas;
00264 WeatherAreaList activeWeatherAreas;
00265 WindChanges windTriggers;
00266 FieldSet processedFields;
00267 
00268 Percentages falloutPercentages;
00269 Percentages windDirPercentages;
00270 Percentages windSpeedPercentages;
00271 
00272 GameMap* gameMap;
00273 WeatherSystemMode currentMode;
00274 
00275 WeatherSystem(const WeatherSystem&);
00276 WeatherSystem& operator=(const WeatherSystem&);
00277 void randomWeatherChange(GameTime currentTime, Direction windDirection, int delay = 0);
00278 Direction randomWindChange(int currentTurn, int delay = 0);
00279 
00280 float createRandomValue(float lowerlimit, float upperlimit);
00281 Direction getNthTurnWindDirection(int turn, GameTime currentTime);
00282 
00283 public:
00284   static const int FallOutNum = 6;
00285   static const int WindDirNum = 6;
00286   static const int WINDSPEEDDETAILLEVEL = 8;
00287   
00288   //Used to support old wind data
00289   //Once the read order of GameMap is changed and fields + weather are read inside of gamemap::read
00290   //get rid of this
00291   
00292   static int legacyWindSpeed;
00293   static int legacyWindDirection;
00294   
00295   
00296   WeatherSystem(GameMap* map);
00297   WeatherSystem(GameMap* map, int areaSpawns, float windspeed2FieldRatio, unsigned int timeInterval = 6, WeatherSystemMode mode = EVENTMODE, FalloutType defaultFallout = DRY);
00298   ~WeatherSystem();
00299   inline void setSeedValue();
00300   void setLikelihoodFallOut(const Percentages& fol) throw (IllegalValueException);
00301   void setLikelihoodWindDirection(const Percentages&  wd) throw (IllegalValueException);
00302   void setLikelihoodWindSpeed(const Percentages&  wd) throw (IllegalValueException);
00303   void setRandomSizeBorders(float lower, float upper);
00304   void setGlobalWind(unsigned int speed, Direction direction) throw (IllegalValueException);
00305   void setDefaultFallout(FalloutType newFalloutType);
00306   void addWeatherArea(WeatherArea* area, GameTime time);
00307   void removeWeatherArea(GameTime time, WeatherArea* area);
00308   void removeWindChange(int time, WindData);
00309   void addGlobalWindChange(int speed, Direction direction, int time) throw (IllegalValueException);  
00310   void update();  
00311   void write (tnstream& outputStream) const;
00312   void read (tnstream& inputStream);
00313   
00314   pair<GameTime, WeatherArea*> getNthWeatherArea(int n) const;
00315   const WeatherArea* getNthActiveWeatherArea(int n) const;
00316   pair<int, WindData> getNthWindChange(int n) const;
00317   const int getQueuedWeatherAreasSize() const;
00318   const int getActiveWeatherAreasSize() const;
00319   const int getQueuedWindChangesSize() const;
00320   void setSeedValueGeneration(bool setNew);
00321 
00322   unsigned int createRandomValue(unsigned int limit = 1000);  
00323   void skipRandomValue() const;  
00324   
00325   FalloutType getDefaultFalloutType() const{
00326     return defaultFallout;  
00327   };
00328   
00329   inline int getCurrentWindSpeed() const{
00330     return windspeed;
00331   }
00332   
00333   inline Direction getCurrentWindDirection() const{
00334     return globalWindDirection;
00335   }
00336   
00337   int getMaxForecast() const;
00338   
00339   bool isSeedValueSet(){
00340     return seedValueIsSet;
00341   }  
00342   inline int getSpawnsAmount(){
00343     return areaSpawnAmount;
00344   }
00345   
00346   inline void setEventMode(const WeatherSystemMode& mode){
00347     currentMode = mode;
00348   }
00349   
00350   inline int getTimeInterval(){
00351     return timeInterval;
00352   }
00353   
00354   inline void setTimeInterval(int i){
00355     timeInterval = i;
00356   }
00357   
00358   inline void setWindSpeed2FieldRatio(float ratio){
00359     windspeed2FieldRatio = ratio;
00360   }
00361   
00362   inline void setSpawnAmount(int a){
00363     areaSpawnAmount = a;
00364   }
00365   
00366   void setLowerDurationLimit(int udl){
00367     lowerRandomDuration = udl;
00368   }
00369   
00370   void setUpperDurationLimit(int ldl){
00371     upperRandomDuration = ldl;
00372   }
00373   
00374   inline const WeatherSystemMode getEventMode() const{
00375     return currentMode;
00376   }
00377   inline float getWindspeed2FieldRatio() const{
00378     return windspeed2FieldRatio;
00379   }
00380   inline const int getFalloutPercentage(int i) const{
00381     return falloutPercentages[i];
00382   }
00383   
00384   inline const int getWindSpeedPercentage(int i) const{
00385     return windSpeedPercentages[i];
00386   }
00387   
00388   inline const int getWindDirPercentage(int i) const{
00389     return windDirPercentages[i];
00390   }
00391   
00392   inline const float getLowerSizeLimit() const{
00393     return lowerRandomSize;
00394   }
00395   
00396   inline const float getUpperSizeLimit() const{
00397     return upperRandomSize;
00398   }
00399   
00400   const int getLowerDurationLimit() const{
00401     return lowerRandomDuration;
00402   }
00403   
00404   const int getUpperDurationLimit() const{
00405     return upperRandomDuration;
00406   }
00407   
00408   
00409   WindData getWindDataOfTurn(int turn) const;
00410 };
00411 
00412 #endif
00413 
00414 
00415 
00416 
00417 
00418 

Generated on Tue Jun 24 01:27:55 2008 for Advanced Strategic Command by  doxygen 1.4.2