Advanced Strategic Command
mapfield.h
Go to the documentation of this file.
1 
2 /***************************************************************************
3  * *
4  * This program is free software; you can redistribute it and/or modify *
5  * it under the terms of the GNU General Public License as published by *
6  * the Free Software Foundation; either version 2 of the License, or *
7  * (at your option) any later version. *
8  * *
9  ***************************************************************************/
10 
11 
12 #ifndef mapfieldH
13  #define mapfieldH
14 
15  #include <vector>
16 
17  #include "typen.h"
18  #include "vehicle.h"
19  #include "basestrm.h"
20  #include "explosivemines.h"
21 
22 
23 class Context;
24 
26 class MapField {
27  GameMap* gamemap;
28  void init();
29  int index;
30  protected:
31  MapField ( ) { init(); };
32  friend class GameMap;
33  public:
34  MapField ( GameMap* gamemap_, int index_ ) { init(); setMap(gamemap_, index_); };
35  void operator= ( const MapField& f );
36 
37  void setMap ( GameMap* gamemap_, int index_ ) { gamemap = gamemap_; index = index_; };
38  GameMap* getMap() const { return gamemap; };
39 
42 
44  const TerrainType* getTerrainType() const;
45 
46 
48  void changeTerrainType( const TerrainType* terrain );
49 
50 
54  Uint8 fuel, material;
55 
56  int getMineralMaterial() const;
57  int getMineralFuel() const;
58 
59  void setMineralMaterial( int material );
60  void setMineralFuel( int fuel );
61 
63  Uint16 visible;
64 
66  int viewbonus;
67 
68 
70  // These getters/setters are used for this.
72  void setaTemp (Uint8 atemp);
73  Uint8 getaTemp ();
74 
75  void setaTemp2 (Uint8 atemp2);
76  Uint8 getaTemp2 ();
77 
78  void setTempw (Uint16 tempw);
79  Uint16 getTempw ();
80 
81  void setTemp3 (int temp3);
82  int getTemp3 ();
83 
84  void setTemp4 (int temp4);
85  int getTemp4 ();
86 
88 
90 
93 
94  inline Vehicle* getVehicle() const {
95  if ( secondvehicle )
96  return secondvehicle;
97  else
98  return vehicle;
99  }
100 
101 
103 
104  struct Resourceview {
105  Resourceview ( void );
106  void setview( int player, int material, int fuel );
107  void resetview( int player );
108  Uint8 visible; // BM
109  Uint8 fuelvisible[8];
110  Uint8 materialvisible[8];
111  };
112 
115 
116  typedef list<Mine> MineContainer;
118 
120  Mine& getMine ( int n );
121 
122 
123  typedef vector< ::Object> ObjectContainer;
125 
128  public:
129  virtual void removeObject( MapField* fld, const ObjectType* obj ) = 0;
131  };
132 
133 
140  bool addobject ( const ObjectType* obj, int dir = -1, bool force = false, ObjectRemovalStrategy* objectRemovalStrategy = NULL );
141 
147  bool removeObject ( const ObjectType* obj, bool force = false, ObjectRemovalStrategy* objectRemovalStrategy = NULL );
148 
150  void sortobjects ( void );
151 
153  void moveUnitHere( Vehicle* veh );
154 
155 
157  Object* checkForObject ( const ObjectType* o );
158 
159 
162 
165 
166 
168  void deleteeverything ( void );
169 
170 
172  void setparams ( ObjectRemovalStrategy* objectRemovalStrategy );
173 
175  void setparams ( );
176 
178  int getdefensebonus ( void );
179 
181  int getattackbonus ( void );
182 
184  int getWeather();
185  void setWeather( int weather );
186 
187  ASCString getName();
188 
190  int getjamming ( void );
191  int getmovemalus ( const Vehicle* veh );
192  int getmovemalus ( int type );
193 
195  int mineattacks ( const Vehicle* veh );
196 
198  int mineowner ( void );
199 
201  bool unitHere ( const Vehicle* veh );
202 
205  const ContainerBase* getContainer() const;
206 
207 
210 
212  void removeBuilding();
213 
215  void removeUnit();
216 
218  bool putmine ( int owner, MineTypes typ, int strength );
219 
223  void removemine ( int num );
224 
225  void endRound( int turn );
226 
228  struct View {
229  int view;
230  int jamming;
232  } view[8];
233 
238  void setVisibility ( VisibilityStates valtoset, int actplayer );
239 
240  VisibilityStates getVisibility( int actplayer ) {
241  return VisibilityStates((visible >> (2*actplayer)) & 3);
242  };
243 
244  static void resetView( GameMap* gamemap, int playersToReset );
245 
246  int getx();
247  int gety();
249 
250  int getMemoryFootprint() const;
251 
252  ~MapField();
253  private:
254  TerrainType::MoveMalus __movemalus;
255 };
256 
257 
258 
259 
260 
261 #endif
262 
TerrainType::Weather * typ
the terraintype of the field
Definition: mapfield.h:38
Uint8 materialvisible[8]
Definition: mapfield.h:110
const TerrainType * getTerrainType() const
returns the terrain of the field
Definition: mapfield.cpp:177
The type of a field.
Definition: terraintype.h:75
void setVisibility(VisibilityStates valtoset, int actplayer)
The visibility status for all players is stored in a bitmapped variable.
Definition: mapfield.cpp:404
void setaTemp(Uint8 atemp)
Various algorithms need to store some information in the fields they process.
Definition: mapfield.cpp:49
void deleteeverything(void)
deletes everything placed on the field
Definition: mapfield.cpp:295
Mine & getMine(int n)
returns the nth mine. This function should only be used by legacy code; new code should store an iter...
Definition: mapfield.cpp:204
bool putmine(int owner, MineTypes typ, int strength)
put a mine of type typ for player owner and a punch of strength on the field. Strength is an absolute...
Definition: mapfield.cpp:441
int getattackbonus(void)
the attack bonus that unit get when they are attacking
Definition: mapfield.cpp:490
Vehicle * vehicle
Definition: mapfield.h:89
int connection
are any events connected to this field
Definition: mapfield.h:164
MapField(GameMap *gamemap_, int index_)
Definition: mapfield.h:34
void changeTerrainType(const TerrainType *terrain)
changes the terrain type to a new one; weather is not changed
Definition: mapfield.cpp:182
void removeBuilding()
if there is a building on the field, the building is deleted (may affect othere fields too...
Definition: mapfield.cpp:348
Uint8 material
Definition: mapfield.h:54
vector< ::Object > ObjectContainer
Definition: mapfield.h:123
Vehicle * getVehicle() const
Definition: mapfield.h:94
bool unitHere(const Vehicle *veh)
checks if the unit is standing on this field. Since units are being cloned for some checks...
Definition: mapfield.cpp:311
struct MapField::View view[8]
VisibilityStates
the different states that a player's view on a field can have
Definition: typen.h:403
int getMineralMaterial() const
Definition: mapfield.cpp:85
int mineowner(void)
the player who placed the mines on this field.
Definition: mapfield.cpp:454
ContainerBase * getContainer()
returns a pointer to the ContainerBase of the field or NULL if there is none
Definition: mapfield.cpp:331
a single field of the map
Definition: mapfield.h:26
Interface for removing objects from a field when it turns out that they can no longer exist...
Definition: mapfield.h:127
list< Mine > MineContainer
Definition: mapfield.h:116
Uint8 satellite
Definition: mapfield.h:231
The ASCString class provides an abstract way to manipulate strings.
Definition: ascstring.h:14
void setparams()
uses the SimpleObjectRemoval strategy
Definition: mapfield.cpp:599
static void resetView(GameMap *gamemap, int playersToReset)
Definition: mapfield.cpp:413
int getWeather()
the weather that is on this field
Definition: mapfield.cpp:370
void removemine(int num)
removes a mine
Definition: mapfield.cpp:463
int viewbonus
units standing on this object will get a bonus to their view
Definition: mapfield.h:66
void setview(int player, int material, int fuel)
Definition: mapfield.cpp:116
void resetview(int player)
Definition: mapfield.cpp:123
MineTypes
Definition: objects.h:70
Building * getBuildingEntrance()
returns the building if there is one with its entrance on this field
Definition: mapfield.cpp:321
the properties of a terrain describing which units can move onto this field and which can't ...
Definition: terraintype.h:32
void setMineralFuel(int fuel)
Definition: mapfield.cpp:105
void sortobjects(void)
sorts the objects. Since objects can be on different levels of height, the lower one must be displaye...
Definition: mapfield.cpp:436
void setTemp3(int temp3)
Definition: mapfield.cpp:71
Uint8 fuel
mineral resources on this field.
Definition: mapfield.h:54
GameMap * getMap() const
Definition: mapfield.h:38
An object that can be placed on fields. Roads, pipelines and ditches are examples of objects...
Definition: objecttype.h:30
Coordinate on the twodimensional map.
Definition: typen.h:202
void setMineralMaterial(int material)
Definition: mapfield.cpp:95
Uint8 getaTemp()
Definition: mapfield.cpp:52
Uint16 visible
can this field be seen be the player. Variable is bitmapped; two bits for each player. These two bits can have the states defined in VisibilityStates
Definition: mapfield.h:63
void removeUnit()
if there is a unit on the field, the unit will be deleted
Definition: mapfield.cpp:354
The interface for the various streams that ASC offers, like file and memory streams.
bool addobject(const ObjectType *obj, int dir=-1, bool force=false, ObjectRemovalStrategy *objectRemovalStrategy=NULL)
add an object to the field
Definition: mapfield.cpp:212
virtual void removeObject(MapField *fld, const ObjectType *obj)=0
int getx()
Definition: mapfield.cpp:477
int gety()
Definition: mapfield.cpp:483
int * temp4
Definition: gamemap.h:190
TerrainBits bdt
the terraintype properties. They determine which units can move over the field. This variable is reca...
Definition: mapfield.h:161
MineContainer mines
Definition: mapfield.h:117
Uint8 direct
Definition: mapfield.h:231
void operator=(const MapField &f)
Definition: mapfield.cpp:155
void setWeather(int weather)
Definition: mapfield.cpp:380
void moveUnitHere(Vehicle *veh)
registers the unit on the field, and unregisters it whereever it previously was
Definition: mapfield.cpp:362
int getTemp4()
Definition: mapfield.cpp:81
Building * building
Definition: mapfield.h:102
int getjamming(void)
the radar jamming that is on this field
Definition: mapfield.cpp:537
void setTempw(Uint16 tempw)
Definition: mapfield.cpp:63
Vehicle * secondvehicle
two units and the same field are only allowed temporary during movement
Definition: mapfield.h:92
Uint16 getTempw()
Definition: mapfield.cpp:67
The parent class of Vehicle and Building; The name Container originates from Battle Isle...
Definition: containerbase.h:40
An actual building on the map, which references a BuildingType Buildings have an owner,.
Definition: buildings.h:38
int getMemoryFootprint() const
Definition: mapfield.cpp:666
an instance of an object type (ObjectType) on the map
Definition: objects.h:46
void setaTemp2(Uint8 atemp2)
Definition: mapfield.cpp:56
some variables for the viewcalculation algorithm. see viewcalculation.cpp for details ...
Definition: mapfield.h:228
int getdefensebonus(void)
the defense bonus that unit get when they are attacked
Definition: mapfield.cpp:506
MapCoordinate getPosition()
Definition: mapfield.cpp:578
VisibilityStates getVisibility(int actplayer)
Definition: mapfield.h:240
Object * checkForObject(const ObjectType *o)
checks if there are objects from the given type on the field and returns them
Definition: mapfield.cpp:648
void setTemp4(int temp4)
Definition: mapfield.cpp:78
bool removeObject(const ObjectType *obj, bool force=false, ObjectRemovalStrategy *objectRemovalStrategy=NULL)
removes all objects of the given type from the field
Definition: mapfield.cpp:256
ASCString getName()
Definition: mapfield.cpp:522
int getMineralFuel() const
Definition: mapfield.cpp:90
void endRound(int turn)
Definition: mapfield.cpp:129
MapField()
Definition: mapfield.h:31
int getmovemalus(const Vehicle *veh)
Definition: mapfield.cpp:552
int getTemp3()
Definition: mapfield.cpp:74
void setMap(GameMap *gamemap_, int index_)
Definition: mapfield.h:37
int mineattacks(const Vehicle *veh)
can any of the mines on this field attack this unit
Definition: mapfield.cpp:194
Resourceview * resourceview
the mineral resources that were seen by a player on this field; since the actual amount may have decr...
Definition: mapfield.h:114
ObjectContainer objects
Definition: mapfield.h:124
Uint8 getaTemp2()
Definition: mapfield.cpp:59
The map. THE central structure of ASC, which holds everything not globally available together...
Definition: gamemap.h:182
int * temp3
Definition: gamemap.h:189