00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018 #ifndef vehicleH
00019 #define vehicleH
00020
00021 #include "typen.h"
00022 #include "vehicletype.h"
00023 #include "containerbase.h"
00024 #include "ascstring.h"
00025
00026 class BuildingType;
00027
00028 class Context;
00029
00030 class UnitHooveringLogic {
00032 static const int FuelConsumption;
00033
00034 public:
00035 static int calcFuelUsage( const Vehicle* veh );
00036
00040 static int getEndurance ( const Vehicle* veh );
00041 static int getEndurance ( const VehicleType* veh, int height = -1, int resourceModel = 0 );
00042
00043 };
00044
00045
00046 class Vehicle : public ContainerBase {
00047 bool cleanRemove;
00048
00050 Vehicle ( );
00051
00053 Vehicle ( const Vehicle& v );
00054
00056 bool viewOnMap;
00057
00062 int _movement;
00063
00064 void init ( void );
00065
00066 ResourceMatrix repairEfficiency;
00067
00068 bool generatoractive;
00069
00070 bool movementLeft() const;
00071
00072 Vehicle ( const VehicleType* t, GameMap* actmap, int player, int networkID );
00073
00074
00075 public:
00076
00077 Vehicle ( const VehicleType* t, GameMap* actmap, int player );
00078
00079 int repairableDamage() const { return damage; };
00080
00081 bool isBuilding() const { return false; };
00082
00083 const VehicleType* typ;
00084
00085 const VehicleType* getType() const { return typ; };
00086
00087 int ammo[16];
00088 int weapstrength[16];
00089 int experience;
00090
00092 bool attacked;
00093
00095 void setAttacked();
00096
00098 void setAttacked( bool recursive, const Context& context );
00099
00101 int height;
00102
00104 char direction;
00105
00107 int xpos, ypos;
00108 #ifndef karteneditor
00109 private:
00110 #endif
00112 Resources tank;
00113 public:
00114
00116 int connection;
00117
00118 int getArmor() const;
00119
00123 int networkid;
00124
00126 class ReactionFire {
00127 friend class Vehicle;
00128 friend class UnitPropertyEditor;
00129 friend class ChangeUnitProperty;
00130
00131 Vehicle* unit;
00132 public:
00133 ReactionFire ( Vehicle* _unit );
00134 enum Status { off, init1a, init2, ready, init1b };
00135
00137
00138 Status getStatus() const { return status;};
00139
00143 int enable();
00144
00146 void disable();
00147
00148 vector<int> weaponShots;
00149 vector<int> nonattackableUnits;
00150
00152 void endOwnTurn();
00153 void endAnyTurn();
00154 void checkData();
00155
00156 bool canPerformAttack( Vehicle* target );
00157
00158 bool canMove() const;
00159 private:
00160 Status status;
00161 void resetShotCount();
00162
00163 } reactionfire;
00164
00165 AiParameter* aiparam[8];
00166
00167
00169
00170
00171 bool canMove ( void ) const;
00172
00174 int getMovement ( bool checkFuel = true, bool checkRF = true ) const ;
00175
00179 void setMovement ( int newmove, double cargoDivisor = -1 );
00180
00182 bool hasMoved ( void ) const;
00183
00185 int maxMovement ( ) const;
00186
00189 void decreaseMovement ( int movement );
00190
00192 void resetMovement( void );
00193
00195
00196
00200 bool spawnMoveObjects( const MapCoordinate& start, const MapCoordinate& dest, const Context& context );
00201
00203
00204
00205 int putResource ( int amount, int resourcetype, bool queryonly, int scope = 1, int player = -1 );
00206 int getResource ( int amount, int resourcetype, bool queryonly, int scope = 1, int player = -1 );
00207 int getAvailableResource ( int amount, int resourcetype, int scope = 1 ) const;
00208 Resources getResource ( const Resources& res ) const;
00209
00210 Resources putResource ( const Resources& res, bool queryonly, int scope = 1, int player = -1 ) { return ContainerBase::putResource ( res, queryonly, scope, player ); };
00211 Resources getResource ( const Resources& res, bool queryonly, int scope = 1, int player = -1 ) { return ContainerBase::getResource ( res, queryonly, scope, player ); };
00212
00214 Resources getTank() const;
00215
00217
00219 int getHeight() const { return height; };
00220
00221
00222
00224 ASCString getName() const;
00225
00226
00227 int getAmmo( int type, int num, bool queryOnly );
00228 int getAmmo( int type, int num ) const;
00229 int putAmmo( int type, int num, bool queryOnly );
00230 int maxAmmo( int type ) const ;
00231
00233
00234
00236 int weight( void ) const;
00237
00239 int freeWeight();
00240
00242
00243 protected:
00244 const ResourceMatrix& getRepairEfficiency() const { return repairEfficiency; };
00245
00246 virtual void postRepair ( int oldDamage );
00247
00248 private:
00252 int searchstackforfreeweight ( Vehicle* searchedInnerVehicle );
00253
00254 public:
00255
00257 int size ( void );
00258
00260 void beginTurn();
00261
00263 void endOwnTurn( void );
00264
00266 void endAnyTurn( void );
00267
00269 void endRound ( void );
00270
00271 int getIdentification() const { return networkid; };
00272
00273
00275
00276
00277 bool vehicleconstructable ( const VehicleType* tnk, int x, int y );
00278
00279 Resources getExternalVehicleConstructionCost( const VehicleType* tnk ) const;
00280
00284
00286
00288 void setnewposition ( int x, int y );
00289 void setnewposition ( const MapCoordinate& mc );
00290 void setnewposition ( const MapCoordinate& mc, const Context& context );
00291
00295 void convert ( int player, bool recursive = true );
00296
00297
00299 void registerForNewOwner( int player );
00300
00302 void setGeneratorStatus( bool status );
00303 bool getGeneratorStatus () const { return generatoractive; };
00304
00306 void postAttack( bool reactionFire, const Context& context );
00307 void postAttack( bool reactionFire );
00308
00311 void addview();
00312
00315 void removeview();
00316
00318 void resetview();
00319
00322 bool isViewing ( ) const { return viewOnMap; };
00323
00324 const SingleWeapon *getWeapon( unsigned weaponNum ) const;
00325
00327 MapCoordinate3D getPosition ( ) const;
00328
00330 MapCoordinate3D getPosition3D ( ) const;
00331
00332
00337 bool canRepair( const ContainerBase* item ) const;
00338
00342 void fillMagically( bool ammo = true, bool resources = true );
00343
00344
00348 static Vehicle* newFromStream ( GameMap* gamemap, tnstream& stream, int forceNetworkID = -1 );
00349
00353 void read ( tnstream& stream );
00354
00355 void write ( tnstream& stream, bool includeLoadedUnits = true ) const ;
00356
00358 void paint ( Surface& s, SPoint pos, int shadowDist = -1 ) const;
00359 void paint ( Surface& s, SPoint pos, bool shaded, int shadowDist = -1 ) const;
00360
00361 virtual Surface getImage() const;
00362
00363
00364 private:
00365 void readData ( tnstream& stream );
00366 public:
00367
00369 int getValueType ( int uheight ) const { return getFirstBit(uheight); };
00370
00372 int getValueType ( ) const { return getFirstBit(height); };
00373
00374
00376 void transform ( const VehicleType* type );
00377
00382 const VehicleType::HeightChangeMethod* getHeightChange( int dir, int height = 0 ) const;
00383
00385 bool weapexist() const;
00386 void prepareForCleanRemove() { cleanRemove = true; };
00387 ~Vehicle ( );
00388
00389 int getMemoryFootprint() const;
00390
00391 protected:
00392 vector<MapCoordinate> getCoveredFields();
00393
00394 };
00395
00396
00397 #endif
00398
00399
00400