gamemap.h

Go to the documentation of this file.
00001 
00005 /***************************************************************************
00006                           gamemap.h  -  description
00007                              -------------------
00008     begin                : Tue Feb 17 2001
00009     copyright            : (C) 2001 by Martin Bickel
00010     email                : bickel@asc-hq.org
00011  ***************************************************************************/
00012 
00013 /***************************************************************************
00014  *                                                                         *
00015  *   This program is free software; you can redistribute it and/or modify  *
00016  *   it under the terms of the GNU General Public License as published by  *
00017  *   the Free Software Foundation; either version 2 of the License, or     *
00018  *   (at your option) any later version.                                   *
00019  *                                                                         *
00020  ***************************************************************************/
00021 
00022 
00023 #ifndef gamemapH
00024  #define gamemapH
00025 
00026  #include <vector>
00027  #include <time.h>
00028 
00029  #include "typen.h"
00030  #include "baseaiinterface.h"
00031  #include "vehicle.h"
00032  #include "buildings.h"
00033  #include "basestrm.h"
00034  #include "messages.h"
00035  #include "research.h"
00036  #include "password.h"
00037 #ifdef WEATHERGENERATOR
00038  # include "weatherarea.h"
00039 #endif
00040  #include "objects.h"
00041  #include "mapfield.h"
00042  #include "networkinterface.h"
00043  #include "player.h"
00044  
00045  #include "actions/actioncontainer.h"
00046  
00047  class AbstractTaskContainer;
00048  
00049  class RandomGenerator{
00050    public:
00051 
00052       RandomGenerator(int seedValue);
00053       ~RandomGenerator();
00054       
00055       unsigned int getPercentage();
00056       unsigned int getRandomValue(int upperLimit);
00057       unsigned int getRandomValue (int lowerLimit, int upperLimit);
00058  };
00059  
00060   
00061 #ifdef WEATHERGENERATOR
00062 class WeatherSystem;
00063 #endif
00064 
00065 
00066 class ActionRecorder {
00067    public:
00068       virtual void readData ( tnstream& stream ) = 0;
00069       virtual void writeData ( tnstream& stream ) = 0;
00070       virtual ~ActionRecorder() {};
00071 };
00072 
00073 
00075 const int gameparameternum = 35;
00076 
00077 enum GameParameter { cgp_fahrspur, // 0
00078        cgp_eis,
00079        cgp_movefrominvalidfields,
00080        cgp_building_material_factor,
00081        cgp_building_fuel_factor,
00082        cgp_forbid_building_construction, // 5
00083        cgp_forbid_unitunit_construction,
00084        cgp_bi3_training,
00085        cgp_maxminesonfield,
00086        cgp_antipersonnelmine_lifetime,
00087        cgp_antitankmine_lifetime,      // 10
00088        cgp_mooredmine_lifetime,
00089        cgp_floatingmine_lifetime,
00090        cgp_buildingarmor,
00091        cgp_maxbuildingrepair,
00092        cgp_buildingrepairfactor, // 15
00093        cgp_globalfuel,
00094        cgp_maxtrainingexperience,
00095        cgp_initialMapVisibility,
00096        cgp_attackPower,
00097        cgp_jammingAmplifier,  // 20
00098        cgp_jammingSlope,
00099        cgp_superVisorCanSaveMap,
00100        cgp_objectsDestroyedByTerrain,
00101        cgp_trainingIncrement,
00102        cgp_experienceDivisorAttack,  // 25
00103        cgp_disableDirectView,
00104        cgp_disableUnitTransfer,
00105        cgp_experienceDivisorDefense,
00106        cgp_debugEvents,
00107        cgp_objectGrowthMultiplier, // 30
00108        cgp_objectGrowOnOtherObjects,
00109        cgp_researchOutputMultiplier,
00110        cgp_produceOnlyResearchedStuffInternally,
00111        cgp_produceOnlyResearchedStuffExternally };
00112 
00113 
00114 struct GameParameterSettings {
00115          const char* name;
00116          int defaultValue;
00117          int minValue;
00118          int maxValue;
00119          bool changeableByEvent;
00120          bool legacy;
00121          const char* longName;
00122 };
00123 extern GameParameterSettings gameParameterSettings[gameparameternum ];
00124        
00125 class LoadNextMap {
00126        public:
00127           int id;
00128           LoadNextMap( int ID ) : id(ID) {};
00129 };
00130 
00131 
00132 
00133 
00134 
00135 
00136 class OverviewMapHolder : public SigC::Object {
00137       GameMap& map;
00138       Surface overviewMapImage;
00139       Surface completedMapImage;
00140       bool initialized;
00141       bool secondMapReady;
00142       bool completed;
00143       bool connected;
00144       int x;
00145       int y;
00146       Surface createNewSurface();
00147       
00148    protected:   
00149       bool idleHandler( );
00150       bool init();
00151       void drawNextField( bool signalOnCompletion = true );
00152       bool updateField( const MapCoordinate& pos );
00153       
00154    public:
00155       OverviewMapHolder( GameMap& gamemap );
00156    
00161       const Surface& getOverviewMap( bool complete = true );
00162       
00163       static void clearmap( GameMap* actmap );
00164       
00165       static SigC::Signal0<void> generationComplete;
00166       
00167       void resetSize();
00168             
00169       void startUpdate();
00170       void clear( bool allImages = false );
00171       void connect();
00172 };
00173 
00174 
00175 class Event;
00176 class PackageData;
00177 
00179 class GameMap {
00180       void operator= ( const GameMap& map );
00181       bool dialogsHooked;
00182       int serverMapID;
00183    public:
00184 
00185       void setServerMapID( int id ) { serverMapID = id; };
00186       int  getServerMapID() const { return serverMapID; };
00187 
00188       static const int maxTotalPlayers = 8;
00189       
00191       int          xsize, ysize;
00192 
00193       int width() const { return xsize; };
00194       int height() const { return ysize; };
00195 
00197       MapField*       field;
00198 
00200       ASCString    codeWord;
00201 
00203       ASCString    maptitle;
00204 
00205       void setTitle( const ASCString& title ) { maptitle = title; };
00206       ASCString  getTitle() const { return maptitle; };
00207       
00208 
00209       struct Campaign {
00211           bool avail;
00212          
00214           int         id;
00215 
00217           bool      directaccess;
00218           Campaign();
00219       } campaign;
00220 
00222       signed char  actplayer; 
00223 
00225       GameTime    time;
00226 
00227       struct Weather {
00228          Weather():windSpeed(0),windDirection(0){};
00229          int windSpeed;
00230          int windDirection;
00231       } weather;
00232 
00233 #ifdef WEATHERGENERATOR
00234       WeatherSystem* weatherSystem;
00235 #endif
00236 
00240       int _resourcemode;
00241 
00242 
00243       Player player[9];
00244 
00245       int getPlayerCount() const { return 8; };
00246       
00247       Player& getPlayer( PlayerID p )
00248       {
00249          return player[p.getID() ];
00250       }
00251 
00252       const Player& getPlayer( PlayerID p ) const
00253       {
00254          return player[p.getID() ];
00255       }
00256 
00257 
00258       Player& getCurrentPlayer()
00259       {
00260          return player[actplayer];
00261       }
00262 
00263       const Player& getCurrentPlayer() const
00264       {
00265          return player[actplayer];
00266       }
00267       
00268       int getNeutralPlayerNum() const { return 8; };
00269       
00270    private:
00271       MapCoordinate findFirstContainer() const;
00272    public:
00273       
00274       MapCoordinate& getCursor();
00275       MapCoordinate getCursor() const;
00276       
00277 
00278       int eventID;
00279 
00280       typedef PointerList<Event*> Events;
00281       Events events;
00282 
00283       vector<GameTime> eventTimes;
00284 
00285       int eventpassed ( int saveas, int action, int mapid );
00286       int eventpassed ( int id, int mapid );
00287 
00288       class IDManager {
00289             int          unitnetworkid;
00290             typedef map<int, Vehicle*> VehicleLookupCache;
00291             VehicleLookupCache vehicleLookupCache; 
00292             
00293             friend class SpawnUnit;
00294             friend class SpawnMine;
00295             friend class GameMap;
00296                         
00297             
00298          public:
00299             IDManager() : unitnetworkid(0) {};
00300             
00302             int getNewNetworkID();
00303             void registerUnitNetworkID( Vehicle* veh );
00304             void unregisterUnitNetworkID( Vehicle* veh );
00305             
00306             void readData ( tnstream& stream );
00307             void writeData ( tnstream& stream ) const;
00308       } idManager;
00309 
00310 
00311       char         levelfinished;
00312 
00313       enum State { 
00314          Normal,
00315          // NormalAuto,    /*!< normal operation, without user interaction */
00316          // NormalManual,  /*!< normal operation, with user interaction  */
00317          Replay,        
00318          Destruction    
00319       } state;
00320 
00321 
00327       class ResourceTribute {
00328         public:
00329            Resources avail[8][8];
00330            Resources paid[8][8];
00331 
00333            Resources payStatusLastTurn[8][8];
00334            bool empty ( );
00335            void read ( tnstream& stream );
00336            void write ( tnstream& stream );
00337       } tribute;
00338 
00340       MessagePntrContainer  unsentmessage;
00341       bool __loadunsentmessage;
00342 
00344       MessageContainer messages;
00345       bool __loadmessages;
00346 
00348       int           messageid;
00349 
00351       bool ___loadJournal, ___loadNewJournal, ___loadtitle, ___loadLegacyNetwork;
00352 
00353       void allocateFields ( int x, int y, TerrainType::Weather* terrain = NULL );
00354 
00355       ASCString     gameJournal;
00356       ASCString     newJournal;
00357       
00358       Password      supervisorpasswordcrc;
00359 
00360       class ReplayInfo {
00361       public:
00362           ReplayInfo ( void );
00363 
00364           MemoryStreamStorage* guidata[8];
00365           MemoryStreamStorage* map[8];
00366           MemoryStream*    actmemstream;
00367 
00369           int stopRecordingActions;
00370           void read ( tnstream& stream );
00371           void write ( tnstream& stream );
00372           
00374           void closeLogging();
00375           ~ReplayInfo ( );
00376           
00377         };
00378 
00380       ActionContainer actions;
00381       ActionRecorder* actionRecorder;
00382 
00383       
00384       AbstractTaskContainer* tasks;
00385       
00386       ReplayInfo*  replayinfo;
00387 
00389       bool          __loadreplayinfo;
00390 
00391 
00392    private:
00393       int           playerView;
00394    public:
00395 
00400       int   getPlayerView() const;
00401       void  setPlayerView( int player );
00402 
00403       GameTime     lastjournalchange;
00404 
00406       Resources     bi_resource[8];
00407 
00408       struct PreferredFilenames {
00409         ASCString mapname[8];
00410         ASCString savegame[8];
00411       } preferredFileNames;
00412 
00414       int           graphicset;
00415       int           gameparameter_num;
00416       int*          game_parameter;
00417 
00422       ASCString     nativeMessageLanguage;
00423       
00424       int           mineralResourcesDisplayed;
00425 
00426       class ArchivalInformation {
00427          public:
00428             ArchivalInformation() : modifytime ( 0 ) {};
00429             ASCString author;
00430             ASCString description;
00431             ASCString tags;
00432             ASCString requirements;
00433             time_t modifytime;
00434       } archivalInformation;
00435 
00437       class UnitProduction {
00438          public:
00439             typedef vector<int> IDsAllowed;
00440             bool check ( int id );
00441             IDsAllowed idsAllowed;
00442       } unitProduction;
00443 
00444       GameMap ( void );
00445 
00446       Vehicle* getUnit ( int x, int y, int nwid );
00447       Vehicle* getUnit ( int nwid, bool consistencyCheck = true );
00448       const Vehicle* getUnit ( int nwid, bool consistencyCheck = true ) const;
00449       ContainerBase* getContainer ( int nwid );
00450       const ContainerBase* getContainer ( int nwid ) const;
00451       int  getgameparameter ( GameParameter num ) const;
00452       void setgameparameter ( GameParameter num, int value );
00453       void cleartemps( int b = -1, int value = 0 );
00454       bool isResourceGlobal ( int resource );
00455       MapField* getField ( int x, int y );
00456       const MapField* getField ( int x, int y ) const;
00457       MapField* getField ( const MapCoordinate& pos );
00458       
00459       
00464       
00466       void startGame ( );
00467 
00469       void beginTurn();
00470       
00471       
00473       void endTurn();
00474 
00476       void endRound();
00477 
00478 
00479       SigC::Signal1<void,Player&> sigPlayerTurnBegins;
00480       SigC::Signal1<void,Player&> sigPlayerUserInteractionBegins;
00481       SigC::Signal1<void,Player&> sigPlayerUserInteractionEnds;
00482       SigC::Signal1<void,Player&> sigPlayerTurnEnds;
00483       SigC::Signal1<void,Player&> sigPlayerTurnHasEnded;
00484       SigC::Signal1<void,Player&> sigMapWon;
00485 
00486       static SigC::Signal1<void,GameMap&> sigMapCreation;
00487       static SigC::Signal1<void,GameMap&> sigMapDeletion;
00488       static SigC::Signal2<void,GameMap*,Player&> sigPlayerTurnEndsStatic;
00489       
00491       SigC::Signal1<void,const MapCoodinateVector&> sigCoordinateShift;
00492       
00494       SigC::Signal0<void> newRound;
00495 
00496 
00498       bool  continueplaying;
00499       
00500       
00502 
00503       
00504             
00505       
00506       VisibilityStates getInitialMapVisibility( int player );
00507 
00509       int  resize( int top, int bottom, int left, int right );
00510 
00511       // bool compareResources( GameMap* replaymap, int player, ASCString* log = NULL );
00512 
00513       void calculateAllObjects ( void );
00514 
00515       void read ( tnstream& stream );
00516       void write ( tnstream& stream );
00517 
00518       OverviewMapHolder overviewMapHolder;
00519 
00524 
00525       
00526       pterraintype getterraintype_byid ( int id );
00527       ObjectType* getobjecttype_byid ( int id );
00528       const ObjectType* getobjecttype_byid ( int id ) const;
00529       VehicleType* getvehicletype_byid ( int id );
00530       const VehicleType* getvehicletype_byid ( int id ) const;
00531       BuildingType* getbuildingtype_byid ( int id );
00532       const BuildingType* getbuildingtype_byid ( int id ) const;
00533       const Technology* gettechnology_byid ( int id );
00534 
00535       pterraintype getterraintype_bypos ( int pos );
00536       ObjectType* getobjecttype_bypos ( int pos );
00537       VehicleType* getvehicletype_bypos ( int pos );
00538       BuildingType* getbuildingtype_bypos ( int pos );
00539       const Technology* gettechnology_bypos ( int pos );
00540 
00541       int getTerrainTypeNum ( );
00542       int getObjectTypeNum ( );
00543       int getVehicleTypeNum ( );
00544       int getBuildingTypeNum ( );
00545       int getTechnologyNum ( );
00546 
00548       
00549       ~GameMap();
00550 
00552       bool loadOldEvents;
00553 
00555       int random( int max );
00556       
00557       void guiHooked();
00558       bool getGuiHooked() { return dialogsHooked; };
00559 
00561       Properties properties;
00562       Properties& getProperties() { return properties; };
00563       
00564       GameTransferMechanism* network;
00565 
00566       int getMemoryFootprint() const;
00567 
00568       mutable PackageData* packageData;
00569       
00570    private:
00571       Vehicle* getUnit ( Vehicle* eht, int nwid );
00572 
00573       void objectGrowth();
00574       void setupResources ( void );
00575       
00577       void processJournal();
00578 
00579       unsigned int randomSeed;
00580 
00581       static void setPlayerMode( Player& p, State s );
00582 };
00583 
00584 
00585 
00586 #endif
00587 

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