typen.h

Go to the documentation of this file.
00001 /*
00002      This file is part of Advanced Strategic Command; http://www.asc-hq.de
00003      Copyright (C) 1994-2010  Martin Bickel  and  Marc Schellenberger
00004  
00005      This program is free software; you can redistribute it and/or modify
00006      it under the terms of the GNU General Public License as published by
00007      the Free Software Foundation; either version 2 of the License, or
00008      (at your option) any later version.
00009  
00010      This program is distributed in the hope that it will be useful,
00011      but WITHOUT ANY WARRANTY; without even the implied warranty of
00012      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013      GNU General Public License for more details.
00014  
00015      You should have received a copy of the GNU General Public License
00016      along with this program; see the file COPYING. If not, write to the 
00017      Free Software Foundation, Inc., 59 Temple Place, Suite 330, 
00018      Boston, MA  02111-1307  USA
00019 */
00020 
00021 #ifndef typenH
00022 #define typenH
00023 
00024 #include <time.h>
00025 #include <list>
00026 #include <bitset>
00027 #include <map>
00028 #include <SDL_types.h>
00029 
00030 #include "global.h"
00031 
00032 
00033 #ifdef HAVE_LIMITS
00034  #include <limits>
00035 #else
00036  #include <limits.h>
00037 #endif
00038 
00039 #include "basictypes.h"
00040 
00041 #include "basestrm.h"
00042 #include "util/messaginghub.h"
00043 
00044 
00046 const int gamemapPixelSize = 4;
00047 
00054 const int playerNum = 9;
00055 
00056 
00058 const int waffenanzahl = 8;
00059 
00061 const int cwettertypennum = 6;
00062 
00064 extern const char*  cwettertypen[cwettertypennum];
00065 
00067 const int choehenstufennum =  8;
00068 
00070 const int maxbuildingpicnum  = 8;
00071 
00073 const int maxunitexperience = 23;
00074 
00075 
00077 const int resourceTypeNum = 3;
00079 const int resourceNum = resourceTypeNum;
00080 
00081 class PropertyContainer;
00082 
00097 class Resources {
00098   public:
00099      int energy;
00100      int material;
00101      int fuel;
00102 
00103      static const int count = 3;
00104      
00105      int& resource ( int type ) {
00106         switch ( type ) {
00107            case 0: return energy;
00108            case 1: return material;
00109            case 2: return fuel;
00110            default: throw OutOfRange();
00111         }
00112      };
00113 
00114      const int& resource ( int type ) const {
00115         switch ( type ) {
00116            case 0: return energy;
00117            case 1: return material;
00118            case 2: return fuel;
00119            default: throw OutOfRange();
00120         }
00121      };
00122      
00123      Resources ( void ) : energy ( 0 ), material ( 0 ), fuel ( 0 ) {};
00124      Resources ( int e, int m, int f ) : energy ( e ), material ( m ), fuel ( f ) {};
00125      Resources& operator-= ( const Resources& res ) { energy-=res.energy; material-=res.material; fuel-=res.fuel; return *this;};
00126      bool operator>= ( const Resources& res ) { return energy >= res.energy && material>=res.material && fuel>=res.fuel; };
00127      bool operator< ( const Resources& res ) { return !(*this >= res); };
00128 //     Resources operator* ( double d );
00129      bool operator== ( const Resources& res ) { return energy==res.energy && material==res.material && fuel==res.fuel; };
00130      bool operator!= ( const Resources& res ) { return energy!=res.energy || material!=res.material || fuel!=res.fuel; };
00131      Resources& operator+= ( const Resources& res ) { energy+=res.energy; material+=res.material; fuel+=res.fuel; return *this;};
00132      enum { Energy, Material, Fuel };
00133      void read ( tnstream& stream );
00134      void write ( tnstream& stream ) const;
00135      void runTextIO ( PropertyContainer& pc );
00136      void runTextIO ( PropertyContainer& pc, const Resources& defaultValue );
00137      static const char* name( int r );
00138      ASCString toString() const;
00139      
00140      static const int materialColor = 0xff0000; // 0x8b3d1e;
00141      static const int fuelColor = 0x00ff00; // 0x8b7800;
00142      static const int energyColor = 0x3b2dd7;
00143 };
00144 
00145 extern Resources operator- ( const Resources& res1, const Resources& res2 );
00146 extern Resources operator- ( const Resources& res1 );
00147 extern Resources operator+ ( const Resources& res1, const Resources& res2 );
00148 extern Resources operator* ( const Resources& res1, float a );
00149 extern Resources operator/ ( const Resources& res1, float a );
00150 
00152 extern const char*  resourceNames[3];
00153 
00154 
00155 
00158 class ResourceMatrix {
00159            float e[resourceTypeNum][resourceTypeNum];
00160         public:
00161            ResourceMatrix (  );
00162            ResourceMatrix ( const float* f );
00163            Resources operator* ( const Resources& r ) const;
00164            
00165            void read ( tnstream& stream );
00166            void write ( tnstream& stream ) const;
00167            void runTextIO ( const ASCString& name, PropertyContainer& pc );
00168            void runTextIO ( const ASCString& name, PropertyContainer& pc, const ResourceMatrix& defaultValue );
00169            
00170 };
00171 
00172 
00173 
00174 
00175 
00176 
00178 struct GameTime {
00179   GameTime() { abstime = 0; };
00180   int move() const { return abstime % 0x10000; };
00181   int turn() const { return abstime / 0x10000; };
00182   static bool comp ( const GameTime& a, const GameTime& b ) { return a.abstime > b.abstime; };
00183   void set ( int turn, int move ) { abstime = (turn * 0x10000) + move ; };
00184   int abstime;
00185 };
00186 
00187 
00189 class MapCoodinateVector {
00190    int dx;
00191    int dy;
00192    friend class MapCoordinate;
00193    
00194    public:
00195       MapCoodinateVector( int dx, int dy ) {
00196          this->dx = dx;
00197          this->dy = dy;
00198       }
00199 };
00200 
00202 class MapCoordinate {
00203          public:
00204             int x;
00205             int y;
00206             MapCoordinate ( ) : x(-1), y(-1 ) {};
00207             MapCoordinate ( int _x, int _y) : x(_x), y(_y) {};
00208             bool operator< ( const MapCoordinate& mc ) const { return y < mc.y || ( y == mc.y && x < mc.x );};
00209             bool operator== ( const MapCoordinate& mc ) const { return y == mc.y && x == mc.x;};
00210             bool operator!= ( const MapCoordinate& mc ) const { return y != mc.y || x != mc.x;};
00211             MapCoordinate& operator+=( const MapCoodinateVector& delta );
00212             void write( tnstream& stream ) const { stream.writeInt ( 3000 ); stream.writeInt ( x ); stream.writeInt ( y); };
00213             void read( tnstream& stream ) {
00214                int vers = stream.readInt ( );
00215                if ( vers == 3500 )
00216                   fatalError ( " MapCoordinate::read - data was written by MapCoordinate3D ");
00217 
00218                x = stream.readInt ( );
00219                y = stream.readInt ( );
00220             };
00221             bool valid() const { return x >= 0 && y >= 0 ; } ;
00222             void move(int width, int height);
00223             ASCString toString(bool coordinates = false) const;
00224       };
00225 
00226 inline MapCoordinate operator-( const MapCoordinate& a, const MapCoordinate& b )
00227 {
00228   return MapCoordinate(a.x - b.x, a.y - b.y );
00229 }  
00230       
00231 inline MapCoordinate operator+( const MapCoordinate& a, const MapCoordinate& b )
00232 {
00233    return MapCoordinate(a.x + b.x, a.y + b.y );
00234 }
00235       
00236 
00238 class MapCoordinate3D : public MapCoordinate {
00239             int z;
00240          public:
00241             int getBitmappedHeight ( ) const { if ( z >= 0 ) return 1<<z; else return 0;};
00242             int getNumericalHeight ( ) const { return z; };
00243             void setNumericalHeight ( int nh ) { z = nh; };
00244             // MapCoordinate3D& operator= ( const MapCoordinate& mc ) { x = mc.x; y = mc.y; z = -1 );
00245             MapCoordinate3D ( ) : MapCoordinate(), z(-1) {};
00246             MapCoordinate3D ( int _x, int _y, int bitmappedz) : MapCoordinate ( _x, _y ), z ( getFirstBit(bitmappedz) ) {};
00247             bool operator< ( const MapCoordinate3D& mc ) const { return y < mc.y || ( y == mc.y && x < mc.x ) || (y == mc.y && x == mc.x && z < mc.z);};
00248             // MapCoordinate3D ( const MapCoordinate& mc ) : MapCoordinate ( mc ), z ( -2 ) {};
00249             MapCoordinate3D ( const MapCoordinate& mc, int bitmappedHeight ) : MapCoordinate ( mc ), z ( getFirstBit(bitmappedHeight) ) {};
00250             void setnum ( int _x, int _y, int numericalz ) { x = _x; y = _y; z = numericalz; };
00251             bool operator== ( const MapCoordinate3D& mc ) const { return y == mc.y && x == mc.x && (z == mc.z || z == -2 || mc.z == -2);};
00252             bool operator!= ( const MapCoordinate3D& mc ) const { return !operator==(mc) ; };
00253             void write( tnstream& stream ) const { stream.writeInt ( 3500 ); stream.writeInt ( z ); MapCoordinate::write( stream ); };
00254             void read( tnstream& stream ) {
00255                stream.readInt ( );
00256                z = stream.readInt ( );
00257                MapCoordinate::read ( stream );
00258             };
00259       };
00260 
00261 
00268 extern int getheightdelta ( int height1, int height2 );
00269 
00270       
00272 class Properties {      
00273       std::map<ASCString, ASCString> data;
00274    public:
00275       ASCString getValue( const ASCString& key );
00276       void setValue( const ASCString& key, const ASCString& value );
00277       
00278       void write( tnstream& stream ) const;
00279       void read( tnstream& stream );
00280 };
00281 
00282 
00286 class LoadableItemType {
00287     public:
00289        ASCString filename;
00290 
00295        ASCString location;
00296        
00297        ASCString archive;
00298 
00300        virtual void read ( tnstream& stream ) = 0;
00301            
00303        virtual void write ( tnstream& stream ) const = 0;
00304            
00306        virtual void runTextIO ( PropertyContainer& pc ) = 0;
00307        virtual ~LoadableItemType() {};
00308 };
00309 
00310 
00312 template< typename T> 
00313 class deallocating_vector : public vector<T> {
00314    public:
00315       ~deallocating_vector() {
00316          for ( typename vector<T>::iterator i = vector<T>::begin(); i != vector<T>::end(); ++i )
00317             delete *i;
00318       };      
00319 };
00320 
00322 template< typename T, typename U>
00323 class deallocating_map : public std::map<T,U> {
00324    public:
00325       ~deallocating_map() {
00326          for ( typename std::map<T,U>::iterator i = std::map<T,U>::begin(); i != std::map<T,U>::end(); ++i )
00327             delete i->second;
00328       };
00329 };
00330 
00333 class IntRange {
00334      public:
00336            int from;
00337                    
00339            int to;
00340            IntRange(): from(-1), to(-1) {};
00341            IntRange( int oneValue ): from(oneValue), to(oneValue) {};
00342            IntRange( int from_, int to_ ): from(from_), to(to_) {};
00343            void read ( tnstream& stream );
00344            void write ( tnstream& stream ) const;
00345 };
00346 
00350 extern vector<IntRange> String2IntRangeVector( const ASCString& t );
00351 
00352 
00353 
00360 class MoveMalusType {
00361    public:
00362       enum {  deflt,
00363               light_tracked_vehicle,
00364               medium_tracked_vehicle,
00365               heavy_tracked_vehicle,
00366               light_wheeled_vehicle,
00367               medium_wheeled_vehicle,
00368               heavy_wheeled_vehicle,
00369               trooper,
00370               rail_vehicle,
00371               medium_aircraft,
00372               medium_ship,
00373               structure,
00374               light_aircraft,
00375               heavy_aircraft,
00376               light_ship,
00377               heavy_ship,
00378               helicopter,
00379               hoovercraft };
00380    };
00381 
00383 const int cmovemalitypenum  = 18;
00384 
00386 const int cmm_building = 11;
00387 
00389 const int cmm_trooper = 7;
00390 
00391    
00393 extern const char*  cmovemalitypes[cmovemalitypenum];
00394 
00396 extern const char*  moveMaliTypeIcons[cmovemalitypenum];
00397 
00398 
00399 
00400 
00402 enum VisibilityStates { visible_not, visible_ago, visible_now, visible_all };
00403 
00404 
00405 
00406 
00408 extern  const char*  choehenstufen[8] ;
00409  #define chtiefgetaucht 1  
00410  #define chgetaucht 2
00411  #define chschwimmend 4  
00412  #define chfahrend 8  
00413  #define chtieffliegend 16  
00414  #define chfliegend 32  
00415  #define chhochfliegend 64  
00416  #define chsatellit 128  
00417 
00418 extern ASCString heightToString( int bitmappedHeight );
00419       
00420 
00421 
00422 const int experienceDecreaseDamageBoundaryNum = 4;
00423 extern const int experienceDecreaseDamageBoundaries[experienceDecreaseDamageBoundaryNum];
00424 
00425 
00431 
00432 
00433  #define maxmalq 10
00434  #define minmalq 10
00435  #define fieldxsize 48    /*  Breite eines terrainbildes  */ 
00436  #define fieldysize 48  
00437  #define fielddistx 64
00438  #define fielddisty 24
00439  #define fielddisthalfx 32
00440 
00442  const int sidenum = 6;
00443 
00444 #define fieldsizex fieldxsize
00445 #define fieldsizey fieldysize
00446 
00447   extern const int directionangle [ sidenum ];
00448 
00449 
00450 #ifdef HAVE_LIMITS
00451 
00452  #ifdef max
00453   #undef max
00454  #endif
00455  #ifdef min
00456   #undef min
00457  #endif
00458 
00459  #define maxint numeric_limits<int>::max()
00460  #define minint numeric_limits<int>::min()
00461 
00462  #define maxfloat numeric_limits<float>::max()
00463  #define minfloat numeric_limits<float>::min()
00464 #else
00465 
00466  #define maxint INT_MAX
00467  #define minint INT_MIN
00468  
00469  #define maxfloat FLT_MAX
00470  #define minfloat FLT_MIN
00471 #endif
00472 
00473 
00474 
00475 
00481 
00483 const int attackmovecost = 0;  
00484 
00486 const int submarineMovement = 11;
00487 
00489 const int mineputmovedecrease = 10;
00490 
00492 const int mineremovemovedecrease = 10;
00493 
00496 const int minimumBuildingDamageForConquering = 80;
00497 
00499 const int recyclingoutput = 90;  
00500 
00502 const int destructoutput = 20;
00503 
00505 const int maxwindspeed = 60;          
00506 
00508 const int generatortruckefficiency = 2;  
00509 
00511 const int mine_movemalus_increase = 50; 
00512 
00513 #define cnet_storeenergy        0x001           // es wird garantiert,  dass material immer das 2 und fuel das 4 fache von energy ist
00514 #define cnet_storematerial      0x002
00515 #define cnet_storefuel          0x004
00516 
00517 #define cnet_moveenergyout      0x008
00518 #define cnet_movematerialout    0x010
00519 #define cnet_movefuelout        0x020
00520 
00521 #define cnet_stopenergyinput    0x040
00522 #define cnet_stopmaterialinput  0x080
00523 #define cnet_stopfuelinput      0x100
00524 
00525 #define cnet_stopenergyoutput   0x200
00526 #define cnet_stopmaterialoutput 0x400
00527 #define cnet_stopfueloutput     0x800
00528 
00532 const int resource_fuel_factor = 80;         
00533 const int resource_material_factor = 80;     
00534 
00536 const int destruct_building_material_get = 2; 
00537 #define destruct_building_fuel_usage 10  // beim Abreissen wird 10 * fuelconsumption Fuel fuelconsumptiont
00538 
00539 
00540 #define dissectunitresearchpointsplus  2    // Beim dissectn einer vehicle wird der sovielte Teil der Researchpoints jeder unbekannten Technologie gutgeschrieben
00541 
00542 #define dissectunitresearchpointsplus2 3    // Beim dissectn einer vehicle wird der sovielte Teil der Researchpoints jeder unbekannten Technologie gutgeschrieben.
00543   // fuer die Technologie existieren aber bereits von einem anderen sezierten vehicletype gutschriften.
00544 
00546 const int maxminingrange = 10;
00547 
00548 const double productionLineConstructionCostFactor = 0.5;
00549 const double productionLineRemovalCostFactor = 0.2;
00550 
00551 
00552 extern const int csolarkraftwerkleistung[];
00553 
00555 const int cnetcontrolnum  = 12;
00556 
00558 extern const char* cnetcontrol[cnetcontrolnum];
00559 
00560 extern const char* cgeneralnetcontrol[];
00561 
00562 const int maxViewRange = 255;
00563 
00564 #endif

Generated on Mon May 21 01:26:38 2012 for Advanced Strategic Command by  doxygen 1.5.1