Advanced Strategic Command
vehicle.h
Go to the documentation of this file.
1 /***************************************************************************
2  vehicle.h - description
3  -------------------
4  begin : Fri Sep 29 2000
5  copyright : (C) 2000 by Martin Bickel
6  email : bickel@asc-hq.org
7  ***************************************************************************/
8 
9 /***************************************************************************
10  * *
11  * This program is free software; you can redistribute it and/or modify *
12  * it under the terms of the GNU General Public License as published by *
13  * the Free Software Foundation; either version 2 of the License, or *
14  * (at your option) any later version. *
15  * *
16  ***************************************************************************/
17 
18 #ifndef vehicleH
19  #define vehicleH
20 
21  #include "typen.h"
22  #include "vehicletype.h"
23  #include "containerbase.h"
24  #include "ascstring.h"
25 
26 class BuildingType;
27 
28 class Context;
29 
32  static const int FuelConsumption;
33 
34  public:
35  static int calcFuelUsage( const Vehicle* veh );
36 
40  static int getEndurance ( const Vehicle* veh );
41  static int getEndurance ( const VehicleType* veh, int height = -1, int resourceModel = 0 );
42 
43 };
44 
45 
46  class Vehicle : public ContainerBase {
47  bool cleanRemove;
48 
50  Vehicle ( );
51 
53  Vehicle ( const Vehicle& v );
54 
56  bool viewOnMap;
57 
62  int _movement;
63 
64  void init ( void );
65 
66  ResourceMatrix repairEfficiency;
67 
68  bool generatoractive;
69 
70  bool movementLeft() const;
71 
72  Vehicle ( const VehicleType* t, GameMap* actmap, int player, int networkID );
73 
74 
75  public:
76 
77  Vehicle ( const VehicleType* t, GameMap* actmap, int player );
78 
79  int getRepairExperienceValue( int oldDamage, int newDamage, bool offensive, int rountToResolution );
80 
81  int repairableDamage() const { return damage; };
82 
83  bool isBuilding() const { return false; };
84 
85  const VehicleType* typ;
86 
87  const VehicleType* getType() const { return typ; };
88 
89  int ammo[16];
90  int weapstrength[16];
91 
92  private:
93  int experience_offensive;
94  int experience_defensive;
95  public:
96  static const int experienceResolution = 10;
97  int getExperience_offensive() const ;
98  int getExperience_defensive() const;
99  void setExperience_offensive( int experience );
100  void setExperience_defensive( int experience );
101 
102  int getExperience_offensive_raw() const ;
103  int getExperience_defensive_raw() const;
104  void setExperience_offensive_raw( int experience );
105  void setExperience_defensive_raw( int experience );
106 
107 
109  bool attacked;
110 
112  void setAttacked();
113 
115  void setAttacked( bool recursive, const Context& context );
116 
118  int height;
119 
121  Uint8 direction;
122 
124  int xpos, ypos;
125 #ifndef karteneditor
126  private:
127 #endif
128  Resources tank;
130  public:
131 
134 
135  int getArmor() const;
136 
141 
143  class ReactionFire {
144  friend class Vehicle;
145  friend class UnitPropertyEditor;
146  friend class ChangeUnitProperty;
147 
148  Vehicle* unit;
149  public:
150  ReactionFire ( Vehicle* _unit );
152 
154  // int enemiesAttackable;
155  Status getStatus() const { return status;};
156 
160  int enable();
161 
163  void disable();
164 
165  vector<int> weaponShots;
166  vector<int> nonattackableUnits;
167 
169  void endOwnTurn();
170  void endAnyTurn();
171  void checkData();
172 
173  bool canPerformAttack( Vehicle* target );
174 
175  bool canMove() const;
176  private:
177  Status status;
178  void resetShotCount();
179 
180  } reactionfire;
181 
183 
184 
186 
187  bool canMove ( void ) const;
189 
191  int getMovement ( bool checkFuel = true, bool checkRF = true ) const ;
192 
196  void setMovement ( int newmove, double cargoDivisor = -1 );
197 
199  bool hasMoved ( void ) const;
200 
202  int maxMovement ( ) const;
203 
206  void decreaseMovement ( int movement );
207 
209  void resetMovement( void );
210 
212 
213 
217  bool spawnMoveObjects( const MapCoordinate& start, const MapCoordinate& dest, const Context& context );
218 
220 
221 
222  int putResource ( int amount, int resourcetype, bool queryonly, int scope = 1, int player = -1 );
223  int getResource ( int amount, int resourcetype, bool queryonly, int scope = 1, int player = -1 );
224  int getAvailableResource ( int amount, int resourcetype, int scope = 1 ) const;
225  Resources getResource ( const Resources& res ) const;
226 
227  Resources putResource ( const Resources& res, bool queryonly, int scope = 1, int player = -1 ) { return ContainerBase::putResource ( res, queryonly, scope, player ); };
228  Resources getResource ( const Resources& res, bool queryonly, int scope = 1, int player = -1 ) { return ContainerBase::getResource ( res, queryonly, scope, player ); };
229 
231  Resources getTank() const;
232 
234 
236  int getHeight() const { return height; };
237 
238 
239 
241  ASCString getName() const;
242 
243 
244  int getAmmo( int type, int num, bool queryOnly );
245  int getAmmo( int type, int num ) const;
246  int putAmmo( int type, int num, bool queryOnly );
247  int maxAmmo( int type ) const ;
248 
250 
251 
253  int weight( void ) const;
254 
256  int freeWeight();
257 
259 
260  protected:
261  const ResourceMatrix& getRepairEfficiency() const { return repairEfficiency; };
262 
263  virtual void postRepair ( int oldDamage, bool autoRepair );
264 
265  private:
269  int searchstackforfreeweight ( Vehicle* searchedInnerVehicle );
270 
271  public:
272 
274  int size ( void );
275 
277  void beginTurn();
278 
280  void endOwnTurn( void );
281 
283  void endAnyTurn( void );
284 
286  void endRound ( void );
287 
288  int getIdentification() const { return networkid; };
289 
290 
292 
293  bool vehicleconstructable ( const VehicleType* tnk, int x, int y );
295 
297 
301  //bool buildingconstructable ( const BuildingType* bld, bool checkResources = true );
303 
305  void setnewposition ( int x, int y );
306  void setnewposition ( const MapCoordinate& mc );
307  void setnewposition ( const MapCoordinate& mc, const Context& context );
308 
310  void unregisterPosition();
311 
315  void convert ( int player, bool recursive = true );
316 
317 
319  void registerForNewOwner( int player );
320 
322  void setGeneratorStatus( bool status );
323  bool getGeneratorStatus () const { return generatoractive; };
324 
326  void postAttack( bool reactionFire, const Context& context );
327  void postAttack( bool reactionFire );
328 
331  void addview();
332 
335  void removeview();
336 
338  void resetview();
339 
342  bool isViewing ( ) const { return viewOnMap; };
343 
344  const SingleWeapon *getWeapon( unsigned weaponNum ) const;
345 
347  MapCoordinate3D getPosition ( ) const;
348 
350  MapCoordinate3D getPosition3D ( ) const;
351 
352 
357  bool canRepair( const ContainerBase* item ) const;
358 
362  void fillMagically( bool ammo = true, bool resources = true );
363 
364 
368  static Vehicle* newFromStream ( GameMap* gamemap, tnstream& stream, int forceNetworkID = -1 );
369 
373  void read ( tnstream& stream );
374 
375  void write ( tnstream& stream, bool includeLoadedUnits = true ) const ;
376 
378  void paint ( Surface& s, SPoint pos, int shadowDist = -1 ) const;
379  void paint ( Surface& s, SPoint pos, bool shaded, int shadowDist = -1 ) const;
380 
381  virtual Surface getImage() const;
382 
383 
384  private:
385  void readData ( tnstream& stream );
386  public:
387 
389  int getValueType ( int uheight ) const { return getFirstBit(uheight); };
390 
392  int getValueType ( ) const { return getFirstBit(height); };
393 
394 
396  void transform ( const VehicleType* type );
397 
402  const VehicleType::HeightChangeMethod* getHeightChange( int dir, int height = 0 ) const;
403 
405  bool weapexist() const;
406  void prepareForCleanRemove() { cleanRemove = true; };
407  ~Vehicle ( );
408 
409  int getMemoryFootprint() const;
410 
411  protected:
412  vector<MapCoordinate> getCoveredFields();
413 
414 };
415 
416 
417 #endif
418 
419 
420 
void write(tnstream &stream, bool includeLoadedUnits=true) const
Definition: vehicle.cpp:1121
void endAnyTurn(void)
hook that is called when any player (including owner) ends turn
Definition: vehicle.cpp:471
bool weapexist() const
Is the unit able to shoot ?
Definition: vehicle.cpp:796
The base class for buildings and vehicles.
A mathematical matrix for transforming Resources instance (which is mathematically a vector) into a d...
Definition: typen.h:158
int getMemoryFootprint() const
Definition: vehicle.cpp:1722
int getExperience_offensive_raw() const
Definition: vehicle.cpp:263
void prepareForCleanRemove()
Definition: vehicle.h:406
ReactionFire(Vehicle *_unit)
Definition: vehicle.cpp:661
int getExperience_defensive() const
Definition: vehicle.cpp:258
virtual int putResource(int amount, int resourcetype, bool queryonly, int scope=1, int player=-1)=0
scope: 0 = local 1 = resource network 2 = global in all buildings 3 = map wide pool( used only intern...
int getValueType(int uheight) const
For the AI: calculating the ValueType if the unit was on the height uheight.
Definition: vehicle.h:389
void fillMagically(bool ammo=true, bool resources=true)
fills a unit with all resources it can carry This function should only be called in the mapeditor ! ...
Definition: vehicle.cpp:1075
void beginTurn()
hook that called when the turn for a player starts
Definition: vehicle.cpp:435
int size(void)
Returns the size of a unit. A size is equal to the weight of the unit without any cargo or carried re...
Definition: vehicle.cpp:400
int maxMovement() const
the maximum distance that the unit can drive in a single turn on the current level of height ...
Definition: vehicle.cpp:1069
void transform(const VehicleType *type)
to be used with EXTREME caution, and only in the mapeditor !!
Definition: vehicle.cpp:405
int getResource(int amount, int resourcetype, bool queryonly, int scope=1, int player=-1)
Definition: vehicle.cpp:328
int damage
Damage. 0 is no damage, when damage reaches 100 the container is destroyed.
static int calcFuelUsage(const Vehicle *veh)
Definition: vehicle.cpp:1781
int getArmor() const
Definition: vehicle.cpp:1675
bool getGeneratorStatus() const
Definition: vehicle.h:323
void setnewposition(int x, int y)
checks whether the unit can construct a building of the given type.
Definition: vehicle.cpp:808
const VehicleType * getType() const
Definition: vehicle.h:87
AiParameter * aiparam[8]
Definition: vehicle.h:182
bool isViewing() const
returns true if the units view is currently added to the maps global visibility.
Definition: vehicle.h:342
int ammo[16]
Definition: vehicle.h:87
int maxAmmo(int type) const
Definition: vehicle.cpp:1664
int getFirstBit(int zahl)
Count the number of zero bits on the LSB side of "zahl".
Definition: misc.cpp:45
bool canMove() const
Definition: vehicle.cpp:754
void setMovement(int newmove, double cargoDivisor=-1)
sets a new distance that the unit can move
Definition: vehicle.cpp:527
int weight(void) const
weight of unit including cargo
Definition: vehicle.cpp:395
int getAmmo(int type, int num, bool queryOnly)
Definition: vehicle.cpp:1593
int getExperience_defensive_raw() const
Definition: vehicle.cpp:268
const ResourceMatrix & getRepairEfficiency() const
when a ContainerBase is repair by this ContainerBase, the default cost can be customized with this ma...
Definition: vehicle.h:261
vector< int > weaponShots
Definition: vehicle.h:165
void setExperience_defensive(int experience)
Definition: vehicle.cpp:279
void resetview()
resets the internal view state, so that addview() can be executed again
Definition: vehicle.cpp:1001
MapCoordinate3D getPosition() const
returns the units position
Definition: vehicle.cpp:1552
void setGeneratorStatus(bool status)
sets the status of the unit's energy generator
Definition: vehicle.cpp:385
The interface for all kinds of IO stream.
Resources getTank() const
returns the resources that the unit is carrying
Definition: vehicle.cpp:378
The class that manages the reaction fire which causes a unit to attack approaching enemies even if it...
Definition: vehicle.h:143
The ASCString class provides an abstract way to manipulate strings.
Definition: ascstring.h:14
const VehicleType::HeightChangeMethod * getHeightChange(int dir, int height=0) const
returns the method for changing the height in the specified direction, or none if there is none...
Definition: vehicle.cpp:777
virtual Surface getImage() const
returns an image for the Container.
Definition: vehicle.cpp:1706
int height
the current level of height ( BITMAPPED ! )
Definition: vehicle.h:118
Resources getResource(const Resources &res, bool queryonly, int scope=1, int player=-1)
Definition: vehicle.h:228
int getValueType() const
For the AI: calculating the ValueType.
Definition: vehicle.h:392
int repairableDamage() const
returns the amount of damage that can still be repaired this turn
Definition: vehicle.h:81
vector< MapCoordinate > getCoveredFields()
Definition: vehicle.cpp:1714
The class describing properties that are common to all vehicles of a certain kind.
Definition: vehicletype.h:177
class Vehicle::ReactionFire reactionfire
MapCoordinate3D getPosition3D() const
returns the units position; if inside building then Height is -1
Definition: vehicle.cpp:1557
void read(tnstream &stream)
replaces the parameters of the unit by the ones form the stream.
Definition: vehicle.cpp:1291
static int getEndurance(const Vehicle *veh)
calculates the time until the unit crashes because of lack of fuel
Definition: vehicle.cpp:1816
virtual int getResource(int amount, int resourcetype, bool queryonly, int scope=1, int player=-1)=0
The class describing properties that are common to all buildings of a certain kind.
Definition: buildingtype.h:35
int getAvailableResource(int amount, int resourcetype, int scope=1) const
Definition: vehicle.cpp:356
int enable()
enables the reaction fire or returns an error code ( result < 0 = -errorNr )
Definition: vehicle.cpp:689
int putResource(int amount, int resourcetype, bool queryonly, int scope=1, int player=-1)
scope: 0 = local 1 = resource network 2 = global in all buildings 3 = map wide pool( used only intern...
Definition: vehicle.cpp:297
void setExperience_offensive(int experience)
Definition: vehicle.cpp:274
Coordinate on the twodimensional map.
Definition: typen.h:202
ASCString getName() const
returns the units name or, if it does not exist, the unit type's name or description ...
Definition: vehicle.cpp:1569
int getRepairExperienceValue(int oldDamage, int newDamage, bool offensive, int rountToResolution)
Definition: vehicle.cpp:209
void postAttack(bool reactionFire, const Context &context)
callback that is called after the unit has attacked
Definition: vehicle.cpp:1019
void paint(Surface &s, SPoint pos, int shadowDist=-1) const
displays the unit at position spos on s
Definition: vehicle.cpp:1681
void endOwnTurn(void)
hook that is called when a player ends his turn
Definition: vehicle.cpp:478
void decreaseMovement(int movement)
reduces the movement by the given amount.
Definition: vehicle.cpp:572
Changes the properties of a unit.
bool canRepair(const ContainerBase *item) const
can the unit repair anything? This does not necessarily mean that the unit can repair other units...
Definition: vehicle.cpp:198
virtual void readData(tnstream &stream)
void removeview()
removes the units view to the map.
Definition: vehicle.cpp:1006
A single weapon of a #Vehicletype.
Definition: vehicletype.h:100
bool vehicleconstructable(const VehicleType *tnk, int x, int y)
checks whether the unit can construct a vehicle of the given type at the given position.
Definition: vehicle.cpp:875
friend class UnitPropertyEditor
Definition: vehicle.h:145
void setAttacked()
the the unit and all cargo to attacked = true
Definition: vehicle.cpp:1049
SDLmm::SPoint SPoint
Definition: surface.h:27
GameMap * gamemap
the map that this container is placed on
Definition: containerbase.h:52
static Vehicle * newFromStream(GameMap *gamemap, tnstream &stream, int forceNetworkID=-1)
generates a new unit, loads its parameters from the stream (where they have been previously written w...
Definition: vehicle.cpp:1728
All parameters the AI stores persistently about a unit.
int putAmmo(int type, int num, bool queryOnly)
Definition: vehicle.cpp:1630
int freeWeight()
returns the free weight that can be used for cargo
Definition: vehicle.cpp:971
vector< int > nonattackableUnits
Definition: vehicle.h:166
bool canMove(void) const
can the unit move from its current position (does not check neighbouring fields)
Definition: vehicle.cpp:599
bool hasMoved(void) const
did the unit move this turn
Definition: vehicle.cpp:552
int connection
if events are triggered by this unit (if it is lost for example), this will set connection != 0 ...
Definition: vehicle.h:133
int xpos
the position on the map
Definition: vehicle.h:124
Resources getExternalVehicleConstructionCost(const VehicleType *tnk) const
Definition: vehicle.cpp:900
bool isBuilding() const
Definition: vehicle.h:83
void endRound(void)
hook that is called the next round begins ( active player switching from player8 to player1 ) ...
Definition: vehicle.cpp:458
void setExperience_offensive_raw(int experience)
Definition: vehicle.cpp:285
static const int experienceResolution
Definition: vehicle.h:96
void convert(int player, bool recursive=true)
converts the unit so it is owned by 'player'.
Definition: vehicle.cpp:843
const VehicleType * typ
Definition: vehicle.h:83
~Vehicle()
Definition: vehicle.cpp:102
Uint8 direction
the direction in which the unit is facing
Definition: vehicle.h:121
bool attacked
did the unit already attack this turn
Definition: vehicle.h:109
Coordinate on the map including height.
Definition: typen.h:238
GameMap * actmap
Definition: spfst.cpp:64
bool canPerformAttack(Vehicle *target)
Definition: vehicle.cpp:763
The parent class of Vehicle and Building; The name Container originates from Battle Isle...
Definition: containerbase.h:40
Status getStatus() const
for each player that can still be attacked one bit is set
Definition: vehicle.h:155
void setExperience_defensive_raw(int experience)
Definition: vehicle.cpp:290
Resources are basically the currency of ASC.
Definition: typen.h:97
void resetMovement(void)
resets a units movement. This is called at the beginning of each turn.
Definition: vehicle.cpp:518
void endOwnTurn()
hook that is called when a turn ends
Definition: vehicle.cpp:742
int ypos
Definition: vehicle.h:124
const SingleWeapon * getWeapon(unsigned weaponNum) const
Returns the SingleWeapon corresponding to the weaponNum for this vehicle.
Definition: vehicle.cpp:1760
int getIdentification() const
Definition: vehicle.h:288
int networkid
a unique identification of the unit that is used everywhere in ASC (and not only the network protocol...
Definition: vehicle.h:140
void registerForNewOwner(int player)
this is a low level functions that changes the registration in the map. It's called by convert(int...
Definition: vehicle.cpp:857
virtual void postRepair(int oldDamage, bool autoRepair)
is called after a repair is performed. Vehicles use this to reduce their experience.
Definition: vehicle.cpp:423
int getHeight() const
returns the bitmapped level of height. Only one bit will be set, of course
Definition: vehicle.h:236
int getMovement(bool checkFuel=true, bool checkRF=true) const
returns the movement points the unit has left for this turn. CheckFuel should almost always be true...
Definition: vehicle.cpp:558
int weapstrength[16]
Definition: vehicle.h:90
Resources putResource(const Resources &res, bool queryonly, int scope=1, int player=-1)
Definition: vehicle.h:227
bool spawnMoveObjects(const MapCoordinate &start, const MapCoordinate &dest, const Context &context)
add the objects like tracks or broken ice
Definition: vehicle.cpp:621
void addview()
adds the units view to the map.
Definition: vehicle.cpp:990
void unregisterPosition()
unregisters the unit at its current position (e.g. from a map field, or inside a transport) ...
Definition: vehicle.cpp:830
The map. THE central structure of ASC, which holds everything not globally available together...
Definition: gamemap.h:182
int getExperience_offensive() const
Definition: vehicle.cpp:253