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

vehicle.h

Go to the documentation of this file.
00001 /***************************************************************************
00002                           vehicle.h  -  description
00003                              -------------------
00004     begin                : Fri Sep 29 2000
00005     copyright            : (C) 2000 by Martin Bickel
00006     email                : bickel@asc-hq.org
00007  ***************************************************************************/
00008 
00009 /***************************************************************************
00010  *                                                                         *
00011  *   This program is free software; you can redistribute it and/or modify  *
00012  *   it under the terms of the GNU General Public License as published by  *
00013  *   the Free Software Foundation; either version 2 of the License, or     *
00014  *   (at your option) any later version.                                   *
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 
00029 class UnitHooveringLogic {
00031       static const int FuelConsumption; 
00032 
00033    public:
00034       static int calcFuelUsage( const Vehicle* veh );
00035 
00039       static int getEndurance ( const Vehicle* veh );
00040       static int getEndurance ( const Vehicletype* veh, int height = -1, int resourceModel = 0 );
00041 
00042 };
00043 
00044  
00045  class Vehicle : public ContainerBase {
00046     bool cleanRemove;
00047 
00049     Vehicle (  );
00050 
00052     Vehicle ( const Vehicle& v );
00053 
00055     bool viewOnMap;
00056 
00061     int  _movement;
00062 
00063     void init ( void );
00064 
00065     ResourceMatrix repairEfficiency;
00066 
00067     bool generatoractive;
00068 
00069     bool movementLeft() const;
00070 
00071     Vehicle ( const Vehicletype* t, GameMap* actmap, int player, int networkID  );
00072 
00073 
00074    public:
00075 
00076     Vehicle ( const Vehicletype* t, GameMap* actmap, int player );
00077 
00078     int repairableDamage() { return damage; };
00079 
00080     bool isBuilding() const { return false; };
00081 
00082     const Vehicletype* typ;
00083     int          ammo[16];
00084     int          weapstrength[16];
00085     int          experience;
00086 
00088     bool         attacked;
00089 
00091     void setAttacked();
00092 
00094     int          height;
00095 
00097     char         direction;
00098 
00100     int          xpos, ypos;
00101 #ifndef karteneditor
00102   private:
00103 #endif
00104 
00105     Resources    tank;
00106   public:
00107 
00109     int          connection;
00110 
00111     int          getArmor() const;
00112 
00116     int          networkid;
00117     ASCString    name;
00118 
00120     class  ReactionFire {
00121          friend class Vehicle;
00122          friend class UnitPropertyEditor;
00123 
00124          Vehicle* unit;
00125        public:
00126          ReactionFire ( Vehicle* _unit );
00127          enum Status { off, init1a, init2, ready, init1b };
00128 
00130          // int enemiesAttackable;
00131          Status getStatus() const { return status;};
00132 
00134          int enable();
00135          void disable();
00136 
00137          vector<int> weaponShots;
00138          vector<int> nonattackableUnits;
00139 
00141          void endOwnTurn();
00142          void endAnyTurn();
00143          void checkData();
00144 
00145          bool canPerformAttack( Vehicle* target );
00146          
00147          bool canMove() const;
00148        private:
00149          Status status;
00150          void resetShotCount();
00151 
00152     } reactionfire;
00153 
00154     AiParameter* aiparam[8];
00155 
00156 
00158 
00159 
00160     bool canMove ( void ) const;
00161 
00163     int getMovement ( bool checkFuel = true, bool checkRF = true ) const ;
00164 
00168     void setMovement ( int newmove, double cargoDivisor = -1 );
00169 
00171     bool hasMoved ( void ) const;
00172 
00174     int maxMovement ( ) const;
00175 
00178     void decreaseMovement ( int movement );
00179 
00181     void resetMovement( void );
00182 
00184     
00185     
00186 
00188     void setNewHeight( int bitmappedheight );
00189 
00193     bool spawnMoveObjects( const MapCoordinate& start, const MapCoordinate& dest );
00194 
00196 
00197     
00198     int putResource ( int amount, int resourcetype, bool queryonly, int scope = 1, int player = -1 );
00199     int getResource ( int amount, int resourcetype, bool queryonly, int scope = 1, int player = -1 );
00200     int getAvailableResource ( int amount, int resourcetype, int scope = 1 ) const;
00201     Resources getResource ( const Resources& res ) const;
00202 
00203     Resources putResource ( const Resources& res, bool queryonly, int scope = 1, int player = -1 ) { return ContainerBase::putResource ( res, queryonly, scope, player ); };
00204     Resources getResource ( const Resources& res, bool queryonly, int scope = 1, int player = -1 ) { return ContainerBase::getResource ( res, queryonly, scope, player ); };
00205 
00207     Resources getTank() const;
00208 
00210     
00212     int getHeight() const { return height; };
00213     
00214 
00215 
00217     ASCString    getName() const;
00218 
00219     int getAmmo( int type, int num, bool queryOnly );
00220     int getAmmo( int type, int num ) const;
00221     int putAmmo( int type, int num, bool queryOnly );
00222     int maxAmmo( int type ) const ;
00223 
00225 
00226 
00228     int weight( void ) const;
00229     
00231     int freeWeight();
00232 
00234 
00235   protected:
00236     const ResourceMatrix& getRepairEfficiency ( void ) { return repairEfficiency; };
00237 
00238     virtual void postRepair ( int oldDamage );
00239 
00240   private:
00244     int searchstackforfreeweight ( Vehicle* searchedInnerVehicle );
00245 
00246   public:
00247 
00249     int size ( void );
00250 
00252     void endOwnTurn( void );
00253 
00255     void endAnyTurn( void );
00256 
00257 
00259     void endRound ( void );
00260 
00261     int getIdentification() { return networkid; };
00262 
00263 
00265 
00266 
00267     Vehicle* constructvehicle ( Vehicletype* tnk, int x, int y );
00268 
00270     bool vehicleconstructable ( Vehicletype* tnk, int x, int y );
00271 
00275     bool buildingconstructable ( const BuildingType* bld, bool checkResources = true );
00277     
00279     void setnewposition ( int x, int y );
00280     void setnewposition ( const MapCoordinate& mc );
00281 
00286     void convert ( int player );
00287 
00289     void setGeneratorStatus( bool status );
00290     bool getGeneratorStatus () const { return generatoractive; };
00291 
00293     void postAttack( bool reactionFire );
00294 
00297     void addview();
00298 
00301     void removeview();
00302 
00305     bool isViewing ( ) const { return viewOnMap; };
00306     const SingleWeapon *getWeapon( unsigned weaponNum );
00307 
00308 
00312     int searchForMineralResources( ) const;
00313 
00314 //    bool searchForMineralResourcesAvailable();
00315 
00317     MapCoordinate3D getPosition ( ) const;
00318 
00320     MapCoordinate3D getPosition3D ( ) const;
00321 
00322 
00323     // Searches this and all nested transport for the unit. Returns the direct parent carrier.
00324     // Vehicle* findCarrierUnit ( const Vehicle* veh );
00325 
00326     
00331     bool canRepair( const ContainerBase* item ) const;
00332 
00336     void fillMagically( bool ammo = true, bool resources = true );
00337 
00338 
00342     static Vehicle* newFromStream ( GameMap* gamemap, tnstream& stream, int forceNetworkID = -1 );
00343 
00347     void read ( tnstream& stream );
00348 
00349     void write ( tnstream& stream, bool includeLoadedUnits = true );
00350 
00352     void paint ( Surface& s, SPoint pos, int shadowDist = -1 ) const;
00353     void paint ( Surface& s, SPoint pos, bool shaded, int shadowDist = -1 ) const;
00354 
00355     virtual Surface getImage() const;
00356 
00357 
00358   private:
00359     void readData ( tnstream& stream );
00360   public:
00361 
00363     int getValueType ( int uheight ) const { return log2(uheight); };
00364 
00366     int getValueType ( ) const { return log2(height); };
00367 
00368 
00370     void transform ( const Vehicletype* type );
00371 
00376     const Vehicletype::HeightChangeMethod* getHeightChange( int dir, int height = 0 ) const;
00377 
00379     bool weapexist ( void );
00380     void prepareForCleanRemove() { cleanRemove = true; };
00381     ~Vehicle ( );
00382 
00383      int getMemoryFootprint() const;
00384 
00385   protected:
00386      vector<MapCoordinate> getCoveredFields();
00387        
00388 };
00389 
00390 
00391 #endif
00392 
00393 
00394 

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