Advanced Strategic Command
weatherarea.h
Go to the documentation of this file.
1 //
2 // C++ Interface: weatherarea
3 //
4 // Description:
5 //
6 //
7 // Author: Kevin Hirschmann <hirsch@dhcppc0>, (C) 2004
8 //
9 // Copyright: See COPYING file that comes with this distribution
10 //
11 //
12 #ifndef WEATHERAREA_H
13 #define WEATHERAREA_H
14 
15 #include <list>
16 #include <map>
17 #include <set>
18 
19 #include "gamemap.h"
20 //#include "error.h"
21 #include "ascstring.h"
22 #include "geometry.h"
23 #include "typen.h"
24 #include "basestreaminterface.h"
25 // #include "graphics/ascttfont.h"
26 
33 class Vector2D{
34  private:
35  int xComponent;
36  int yComponent;
37 
38  public:
42  Vector2D();
48  Vector2D(int x, int y);
52  ~Vector2D();
57  int getXComponent() const;
62  int getYComponent() const;
67  double getLength() const;
72  bool isZeroVector() const;
73 };
74 
75 
76 
78 public:
81 };
82 
83 extern const char* cdirections[];
84 enum Direction {
85 N,
88 S,
91 };
92 
93 
101 };
102 
103 struct WindData{
104  unsigned int speed;
106 };
107 
108 struct WeatherRect {
109  int a, b, c, d;
110 
111 };
112 
113 typedef map<int, WindData> WindChanges;
114 typedef multiset<MapField*> FieldSet;
115 class WeatherSystem;
117 
118 
119 typedef list<MapField*> MapFields;
120 typedef vector<WeatherField*> WeatherFields;
121 typedef vector<int> Percentages;
122 
123 struct ltGTime{
124 bool operator()(const GameTime& gt1, const GameTime& gt2) const{
125  return gt1.abstime < gt2.abstime;
126 }
127 
128 };
133 private:
134 WeatherFields area;
135 GameMap* map;
136 MapCoordinate center;
137 int duration;
138 int width;
139 int height;
140 int radius;
141 FalloutType ft;
142 Vector2D currentMovement;
143 int stepCount;
144 static const int MAXVALUE;
145 static const int MAXOFFSET;
146 float horizontalWindAccu;
147 float verticalWindAccu;
148 bool clustered;
149 int seedValue;
150 WeatherArea &operator=(const WeatherArea&);
151 WeatherArea(const WeatherArea&);
152 MapCoordinate calculateFieldPosition(MapCoordinate center, Vector2D relPos);
153 
154 
155 short createAlgebraicSign();
156 void step(WeatherRect r);
157 int calculateCornerPoint(int a, int b, int c);
158 int calculateDiamondPoint(int a, int b, int c, int d);
159 int calculateCurrentOffset(int currentOffset);
160 int calculateCornerPointValue(int a, int b, int c);
161 int calculateDiamondPointValue(int a, int b, int c, int d);
162 void createWeatherFields();
163 
164 public:
165  WeatherArea(GameMap* map, int xCenter, int yCenter, int width, int height, int duration, FalloutType fType, unsigned int seedValue, bool clustered = true);
166  WeatherArea(GameMap* map, int xCenter, int yCenter, int radius);
167  WeatherArea(GameMap* map);
168 
169  ~WeatherArea();
170  inline GameMap* getMap() const;
171 
172  Vector2D getWindVector() const;
173  // void setWindVector(unsigned int speed, Direction windDirection);
174  void updateMovementVector(unsigned int speed, Direction windDirection, double ratio);
175  void setFalloutType(FalloutType fallout);
176  FalloutType getFalloutType() const;
177  FalloutType getFalloutType(int value) const;
178  int getWidth() const;
179  int getHeight() const;
180  float getHorizontalWindAccu() const;
181  float getVerticalWindAccu() const;
182 
184  return center;
185  }
186 
187  const WeatherField* getCenterField() const{
188  return area[static_cast<int>(height/2 * ((area.size() % height)-1) + (width/2 +0.5))];
189  };
190 
191  int getDuration() const;
192  void setDuration(int duration);
193 
194  void update(WeatherSystem* wSystem, FieldSet& processedFields);
195  void placeArea();
196  void removeArea(FieldSet& processedFields);
197  unsigned int createRandomValue(int limit);
198 
199  void write (tnstream& outputStream) const;
200  void read (tnstream& inputStream);
201 
202 
203 
204 };
205 
206 typedef multimap<GameTime, WeatherArea*, ltGTime> WeatherAreas;
207 typedef list<WeatherArea*> WeatherAreaList;
208 
212 };
213 
215 private:
216 MapField* mapField;
217 GameMap* map;
218 int counter;
219 int value;
220 
221 void setMapField(MapField* mapField);
222 
223 public:
224 WeatherField(GameMap* map);
225 WeatherField(MapCoordinate mapPos, const WeatherArea* area);
226 ~WeatherField();
227 void move(const Vector2D& vector);
228 bool isOnMap(const GameMap* map) const;
229 void update(const WeatherArea*, FieldSet& processedFields);
230 void reset(GameMap* m, const WeatherArea*, FieldSet& processedFields);
231 void write (tnstream& outputStream) const;
232 void read (tnstream& inputStream);
233 void setValue(int v);
234 int getValue();
235 
237 };
238 //**************************************************************************************************************************************
239 class WeatherSystem : public sigc::trackable{
240 private:
241 
242 static const int WEATHERVERSION = 1;
243 unsigned int seedValue;
244 int timeInterval;
245 int areaSpawnAmount;
246 int access2RandCount;
247 int maxForecast;
248 
249 
250 float windspeed2FieldRatio;
251 int windspeed;
252 Direction globalWindDirection;
253 
254 float lowerRandomSize;
255 float upperRandomSize;
256 
257 int lowerRandomDuration;
258 int upperRandomDuration;
259 
260 bool seedValueIsSet;
261 FalloutType defaultFallout;
262 
263 WeatherAreas weatherAreas;
264 WeatherAreaList activeWeatherAreas;
265 WindChanges windTriggers;
266 FieldSet processedFields;
267 
268 Percentages falloutPercentages;
269 Percentages windDirPercentages;
270 Percentages windSpeedPercentages;
271 
272 GameMap* gameMap;
273 WeatherSystemMode currentMode;
274 
276 WeatherSystem& operator=(const WeatherSystem&);
277 void randomWeatherChange(GameTime currentTime, Direction windDirection, int delay = 0);
278 Direction randomWindChange(int currentTurn, int delay = 0);
279 
280 float createRandomValue(float lowerlimit, float upperlimit);
281 Direction getNthTurnWindDirection(int turn, GameTime currentTime);
282 
283 public:
284  static const int FallOutNum = 6;
285  static const int WindDirNum = 6;
286  static const int WINDSPEEDDETAILLEVEL = 8;
287 
288  //Used to support old wind data
289  //Once the read order of GameMap is changed and fields + weather are read inside of gamemap::read
290  //get rid of this
291 
292  static int legacyWindSpeed;
294 
295 
296  WeatherSystem(GameMap* map);
297  WeatherSystem(GameMap* map, int areaSpawns, float windspeed2FieldRatio, unsigned int timeInterval = 6, WeatherSystemMode mode = EVENTMODE, FalloutType defaultFallout = DRY);
298  ~WeatherSystem();
299  inline void setSeedValue();
300  void setLikelihoodFallOut(const Percentages& fol) throw (IllegalValueException);
303  void setRandomSizeBorders(float lower, float upper);
304  void setGlobalWind(unsigned int speed, Direction direction) throw (IllegalValueException);
305  void setDefaultFallout(FalloutType newFalloutType);
306  void addWeatherArea(WeatherArea* area, GameTime time);
307  void removeWeatherArea(GameTime time, WeatherArea* area);
308  void removeWindChange(int time, WindData);
309  void addGlobalWindChange(int speed, Direction direction, int time) throw (IllegalValueException);
310  void update();
311  void write (tnstream& outputStream) const;
312  void read (tnstream& inputStream);
313 
314  pair<GameTime, WeatherArea*> getNthWeatherArea(int n) const;
315  const WeatherArea* getNthActiveWeatherArea(int n) const;
316  pair<int, WindData> getNthWindChange(int n) const;
317  const int getQueuedWeatherAreasSize() const;
318  const int getActiveWeatherAreasSize() const;
319  const int getQueuedWindChangesSize() const;
320  void setSeedValueGeneration(bool setNew);
321 
322  unsigned int createRandomValue(unsigned int limit = 1000);
323  void skipRandomValue() const;
324 
326  return defaultFallout;
327  };
328 
329  inline int getCurrentWindSpeed() const{
330  return windspeed;
331  }
332 
334  return globalWindDirection;
335  }
336 
337  int getMaxForecast() const;
338 
340  return seedValueIsSet;
341  }
342  inline int getSpawnsAmount(){
343  return areaSpawnAmount;
344  }
345 
346  inline void setEventMode(const WeatherSystemMode& mode){
347  currentMode = mode;
348  }
349 
350  inline int getTimeInterval(){
351  return timeInterval;
352  }
353 
354  inline void setTimeInterval(int i){
355  timeInterval = i;
356  }
357 
358  inline void setWindSpeed2FieldRatio(float ratio){
359  windspeed2FieldRatio = ratio;
360  }
361 
362  inline void setSpawnAmount(int a){
363  areaSpawnAmount = a;
364  }
365 
366  void setLowerDurationLimit(int udl){
367  lowerRandomDuration = udl;
368  }
369 
370  void setUpperDurationLimit(int ldl){
371  upperRandomDuration = ldl;
372  }
373 
374  inline const WeatherSystemMode getEventMode() const{
375  return currentMode;
376  }
377  inline float getWindspeed2FieldRatio() const{
378  return windspeed2FieldRatio;
379  }
380  inline const int getFalloutPercentage(int i) const{
381  return falloutPercentages[i];
382  }
383 
384  inline const int getWindSpeedPercentage(int i) const{
385  return windSpeedPercentages[i];
386  }
387 
388  inline const int getWindDirPercentage(int i) const{
389  return windDirPercentages[i];
390  }
391 
392  inline const float getLowerSizeLimit() const{
393  return lowerRandomSize;
394  }
395 
396  inline const float getUpperSizeLimit() const{
397  return upperRandomSize;
398  }
399 
400  const int getLowerDurationLimit() const{
401  return lowerRandomDuration;
402  }
403 
404  const int getUpperDurationLimit() const{
405  return upperRandomDuration;
406  }
407 
408 
409  WindData getWindDataOfTurn(int turn) const;
410 };
411 
412 #endif
413 
414 
415 
416 
417 
418 
the time in ASC, measured in turns and moves
Definition: typen.h:178
void removeWindChange(int time, WindData)
void setLikelihoodWindSpeed(const Percentages &wd)
int getTimeInterval()
Definition: weatherarea.h:350
float getWindspeed2FieldRatio() const
Definition: weatherarea.h:377
static int legacyWindSpeed
Definition: weatherarea.h:292
void setSeedValueGeneration(bool setNew)
int getDuration() const
unsigned int createRandomValue(int limit)
void updateMovementVector(unsigned int speed, Direction windDirection, double ratio)
void setSpawnAmount(int a)
Definition: weatherarea.h:362
void read(tnstream &inputStream)
Definition: weatherarea.h:86
list< MapField * > MapFields
Definition: weatherarea.h:116
int getSpawnsAmount()
Definition: weatherarea.h:342
int abstime
Definition: typen.h:183
const WeatherArea * getNthActiveWeatherArea(int n) const
list< WeatherArea * > WeatherAreaList
Definition: weatherarea.h:207
void setGlobalWind(unsigned int speed, Direction direction)
const char * cdirections[]
Definition: weatherarea.cpp:20
int getHeight() const
int getMaxForecast() const
static const int WindDirNum
Definition: weatherarea.h:285
void write(tnstream &outputStream) const
static int legacyWindDirection
Definition: weatherarea.h:293
Definition: weatherarea.h:87
void update(const WeatherArea *, FieldSet &processedFields)
void read(tnstream &inputStream)
~Vector2D()
Destructor.
Definition: weatherarea.cpp:34
void removeArea(FieldSet &processedFields)
void addGlobalWindChange(int speed, Direction direction, int time)
bool isZeroVector() const
Checks if the vector is the zero-vector.
Definition: weatherarea.cpp:47
const int getWindSpeedPercentage(int i) const
Definition: weatherarea.h:384
float getHorizontalWindAccu() const
void setRandomSizeBorders(float lower, float upper)
The interface for all kinds of IO stream.
a single field of the map
Definition: mapfield.h:26
void placeArea()
MapCoordinate getCenterPos() const
Definition: weatherarea.h:183
const int getActiveWeatherAreasSize() const
void setValue(int v)
Direction direction
Definition: weatherarea.h:105
The ASCString class provides an abstract way to manipulate strings.
Definition: ascstring.h:14
WindData getWindDataOfTurn(int turn) const
Definition: weatherarea.h:90
const int getWindDirPercentage(int i) const
Definition: weatherarea.h:388
FalloutType
Definition: weatherarea.h:94
Vector2D getWindVector() const
void setUpperDurationLimit(int ldl)
Definition: weatherarea.h:370
void setDuration(int duration)
int getXComponent() const
Retrieves the xComponent of the Vector.
Definition: weatherarea.cpp:36
WeatherSystemMode
Definition: weatherarea.h:209
float getVerticalWindAccu() const
const float getUpperSizeLimit() const
Definition: weatherarea.h:396
void removeWeatherArea(GameTime time, WeatherArea *area)
int getWidth() const
int getCurrentWindSpeed() const
Definition: weatherarea.h:329
void move(const Vector2D &vector)
Coordinate on the twodimensional map.
Definition: typen.h:202
void addWeatherArea(WeatherArea *area, GameTime time)
GameMap * getMap() const
Definition: weatherarea.cpp:99
Definition of THE central asc class: GameMap.
const int getQueuedWindChangesSize() const
vector< int > Percentages
Definition: weatherarea.h:121
void setLikelihoodWindDirection(const Percentages &wd)
void write(tnstream &outputStream) const
unsigned int speed
Definition: weatherarea.h:104
Definition: weatherarea.h:88
void reset(GameMap *m, const WeatherArea *, FieldSet &processedFields)
const int getQueuedWeatherAreasSize() const
A Vector2D is a line (without a defined start point) in a 2 dimensional space and is deccribed by its...
Definition: weatherarea.h:33
vector< WeatherField * > WeatherFields
Definition: weatherarea.h:120
void setTimeInterval(int i)
Definition: weatherarea.h:354
void update(WeatherSystem *wSystem, FieldSet &processedFields)
multimap< GameTime, WeatherArea *, ltGTime > WeatherAreas
Definition: weatherarea.h:206
WeatherField(GameMap *map)
Vector2D()
Default constructor.
Definition: weatherarea.cpp:30
Direction getCurrentWindDirection() const
Definition: weatherarea.h:333
bool operator()(const GameTime &gt1, const GameTime &gt2) const
Definition: weatherarea.h:124
pair< int, WindData > getNthWindChange(int n) const
const float getLowerSizeLimit() const
Definition: weatherarea.h:392
FalloutType getFalloutType() const
IllegalValueException(const ASCString &msg)
Definition: weatherarea.cpp:16
const int getUpperDurationLimit() const
Definition: weatherarea.h:404
void write(tnstream &outputStream) const
const WeatherSystemMode getEventMode() const
Definition: weatherarea.h:374
const WeatherField * getCenterField() const
Definition: weatherarea.h:187
bool isOnMap(const GameMap *map) const
Direction
Definition: weatherarea.h:84
Definition: weatherarea.h:85
void skipRandomValue() const
MapCoordinate posInArea
Definition: weatherarea.h:236
FalloutType getDefaultFalloutType() const
Definition: weatherarea.h:325
void setDefaultFallout(FalloutType newFalloutType)
int getYComponent() const
Retrieves the yComponent of the Vector.
Definition: weatherarea.cpp:40
multiset< MapField * > FieldSet
Definition: weatherarea.h:114
void setWindSpeed2FieldRatio(float ratio)
Definition: weatherarea.h:358
const int getFalloutPercentage(int i) const
Definition: weatherarea.h:380
void read(tnstream &inputStream)
pair< GameTime, WeatherArea * > getNthWeatherArea(int n) const
void setLowerDurationLimit(int udl)
Definition: weatherarea.h:366
map< int, WindData > WindChanges
Definition: weatherarea.h:113
void setEventMode(const WeatherSystemMode &mode)
Definition: weatherarea.h:346
void setSeedValue()
void setFalloutType(FalloutType fallout)
Definition: weatherarea.h:89
double getLength() const
Calculates the length of the vector (Pythagoras)
Definition: weatherarea.cpp:43
void setLikelihoodFallOut(const Percentages &fol)
The standard interface for ASC streams. This is the parent class for all kinds of streams: normal fil...
const int getLowerDurationLimit() const
Definition: weatherarea.h:400
static const int FallOutNum
Definition: weatherarea.h:284
static const int WINDSPEEDDETAILLEVEL
Definition: weatherarea.h:286
The map. THE central structure of ASC, which holds everything not globally available together...
Definition: gamemap.h:182
bool isSeedValueSet()
Definition: weatherarea.h:339