00001
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
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 class RandomGenerator{
00046 public:
00047
00048 RandomGenerator(int seedValue);
00049 ~RandomGenerator();
00050
00051 unsigned int getPercentage();
00052 unsigned int getRandomValue(int upperLimit);
00053 unsigned int getRandomValue (int lowerLimit, int upperLimit);
00054 };
00055
00056
00057 #ifdef WEATHERGENERATOR
00058 class WeatherSystem;
00059 #endif
00060
00062 const int gameparameternum = 35;
00063
00064 enum GameParameter { cgp_fahrspur,
00065 cgp_eis,
00066 cgp_movefrominvalidfields,
00067 cgp_building_material_factor,
00068 cgp_building_fuel_factor,
00069 cgp_forbid_building_construction,
00070 cgp_forbid_unitunit_construction,
00071 cgp_bi3_training,
00072 cgp_maxminesonfield,
00073 cgp_antipersonnelmine_lifetime,
00074 cgp_antitankmine_lifetime,
00075 cgp_mooredmine_lifetime,
00076 cgp_floatingmine_lifetime,
00077 cgp_buildingarmor,
00078 cgp_maxbuildingrepair,
00079 cgp_buildingrepairfactor,
00080 cgp_globalfuel,
00081 cgp_maxtrainingexperience,
00082 cgp_initialMapVisibility,
00083 cgp_attackPower,
00084 cgp_jammingAmplifier,
00085 cgp_jammingSlope,
00086 cgp_superVisorCanSaveMap,
00087 cgp_objectsDestroyedByTerrain,
00088 cgp_trainingIncrement,
00089 cgp_experienceDivisorAttack,
00090 cgp_disableDirectView,
00091 cgp_disableUnitTransfer,
00092 cgp_experienceDivisorDefense,
00093 cgp_debugEvents,
00094 cgp_objectGrowthMultiplier,
00095 cgp_objectGrowOnOtherObjects,
00096 cgp_researchOutputMultiplier,
00097 cgp_produceOnlyResearchedStuffInternally,
00098 cgp_produceOnlyResearchedStuffExternally };
00099
00100
00101 struct GameParameterSettings {
00102 const char* name;
00103 int defaultValue;
00104 int minValue;
00105 int maxValue;
00106 bool changeableByEvent;
00107 bool legacy;
00108 const char* longName;
00109 };
00110 extern GameParameterSettings gameParameterSettings[gameparameternum ];
00111
00112 class LoadNextMap {
00113 public:
00114 int id;
00115 LoadNextMap( int ID ) : id(ID) {};
00116 };
00117
00118
00119
00120
00121
00122
00123 class OverviewMapHolder : public SigC::Object {
00124 GameMap& map;
00125 Surface overviewMapImage;
00126 Surface completedMapImage;
00127 bool initialized;
00128 bool secondMapReady;
00129 bool completed;
00130 bool connected;
00131 int x;
00132 int y;
00133 Surface createNewSurface();
00134
00135 protected:
00136 bool idleHandler( );
00137 bool init();
00138 void drawNextField( bool signalOnCompletion = true );
00139 bool updateField( const MapCoordinate& pos );
00140
00141 public:
00142 OverviewMapHolder( GameMap& gamemap );
00143
00148 const Surface& getOverviewMap( bool complete = true );
00149
00150 static void clearmap( GameMap* actmap );
00151
00152 static SigC::Signal0<void> generationComplete;
00153
00154 void resetSize();
00155
00156 void startUpdate();
00157 void clear( bool allImages = false );
00158 void connect();
00159 };
00160
00161
00162 class Event;
00163
00164
00166 class GameMap {
00167 void operator= ( const GameMap& map );
00168 bool dialogsHooked;
00169 public:
00171 int xsize, ysize;
00172
00174
00175
00177 tfield* field;
00178
00180 ASCString codeWord;
00181
00183 ASCString maptitle;
00184
00185
00186 struct Campaign {
00188 bool avail;
00189
00191 int id;
00192
00194 bool directaccess;
00195 Campaign();
00196 } campaign;
00197
00199 signed char actplayer;
00200
00202 GameTime time;
00203
00204 struct Weather {
00205 Weather():windSpeed(0),windDirection(0){};
00206 int windSpeed;
00207 int windDirection;
00208 } weather;
00209
00210 #ifdef WEATHERGENERATOR
00211 WeatherSystem* weatherSystem;
00212 #endif
00213
00217 int _resourcemode;
00218
00219
00220 Player player[9];
00221
00222 int getPlayerCount() const { return 8; };
00223
00224 Player& getPlayer( PlayerID p )
00225 {
00226 return player[p.getID() ];
00227 }
00228
00229 const Player& getPlayer( PlayerID p ) const
00230 {
00231 return player[p.getID() ];
00232 }
00233
00234
00235 Player& getCurrentPlayer()
00236 {
00237 return player[actplayer];
00238 }
00239
00240 int getNeutralPlayerNum() const { return 8; };
00241
00242 MapCoordinate& getCursor();
00243
00244
00245 int eventID;
00246
00247 typedef PointerList<Event*> Events;
00248 Events events;
00249
00250 vector<GameTime> eventTimes;
00251
00252 int eventpassed ( int saveas, int action, int mapid );
00253 int eventpassed ( int id, int mapid );
00254
00255 private:
00256 int unitnetworkid;
00257 typedef map<int, Vehicle*> VehicleLookupCache;
00258 VehicleLookupCache vehicleLookupCache;
00259 public:
00260 int getNewNetworkID();
00261 void registerUnitNetworkID( Vehicle* veh );
00262 void unregisterUnitNetworkID( Vehicle* veh );
00263
00264
00265 char levelfinished;
00266
00267 enum State {
00268 Normal,
00269
00270
00271 Replay,
00272 Destruction
00273 } state;
00274
00275
00281 class ResourceTribute {
00282 public:
00283 Resources avail[8][8];
00284 Resources paid[8][8];
00285
00287 Resources payStatusLastTurn[8][8];
00288 bool empty ( );
00289 void read ( tnstream& stream );
00290 void write ( tnstream& stream );
00291 } tribute;
00292
00294 MessagePntrContainer unsentmessage;
00295 bool __loadunsentmessage;
00296
00298 MessageContainer messages;
00299 bool __loadmessages;
00300
00302 int messageid;
00303
00305 bool ___loadJournal, ___loadNewJournal, ___loadtitle, ___loadLegacyNetwork;
00306
00307 void allocateFields ( int x, int y, TerrainType::Weather* terrain = NULL );
00308
00309 ASCString gameJournal;
00310 ASCString newJournal;
00311
00312 Password supervisorpasswordcrc;
00313
00314 class ReplayInfo {
00315 public:
00316 ReplayInfo ( void );
00317
00318 tmemorystreambuf* guidata[8];
00319 tmemorystreambuf* map[8];
00320 tmemorystream* actmemstream;
00321
00323 int stopRecordingActions;
00324 void read ( tnstream& stream );
00325 void write ( tnstream& stream );
00326
00328 void closeLogging();
00329 ~ReplayInfo ( );
00330 };
00331
00332
00333 ReplayInfo* replayinfo;
00334
00336 bool __loadreplayinfo;
00337
00338
00339 private:
00340 int playerView;
00341 public:
00342
00347 int getPlayerView() const;
00348 void setPlayerView( int player );
00349
00350 GameTime lastjournalchange;
00351
00353 Resources bi_resource[8];
00354
00355 struct PreferredFilenames {
00356 ASCString mapname[8];
00357 ASCString savegame[8];
00358 } preferredFileNames;
00359
00361 int graphicset;
00362 int gameparameter_num;
00363 int* game_parameter;
00364
00365 int mineralResourcesDisplayed;
00366
00367 class ArchivalInformation {
00368 public:
00369 ArchivalInformation() : modifytime ( 0 ) {};
00370 ASCString author;
00371 ASCString description;
00372 ASCString tags;
00373 ASCString requirements;
00374 time_t modifytime;
00375 } archivalInformation;
00376
00378 class UnitProduction {
00379 public:
00380 typedef vector<int> IDsAllowed;
00381 bool check ( int id );
00382 IDsAllowed idsAllowed;
00383 } unitProduction;
00384
00385 GameMap ( void );
00386
00387 Vehicle* getUnit ( int x, int y, int nwid );
00388 Vehicle* getUnit ( int nwid, bool consistencyCheck = true );
00389 ContainerBase* getContainer ( int nwid );
00390 int getgameparameter ( GameParameter num ) const;
00391 void setgameparameter ( GameParameter num, int value );
00392 void cleartemps( int b = -1, int value = 0 );
00393 bool isResourceGlobal ( int resource );
00394 tfield* getField ( int x, int y );
00395 tfield* getField ( const MapCoordinate& pos );
00396
00397
00402
00404 void startGame ( );
00405
00407 void beginTurn();
00408
00409
00411 void endTurn();
00412
00414 void endRound();
00415
00416
00417 SigC::Signal1<void,Player&> sigPlayerTurnBegins;
00418 SigC::Signal1<void,Player&> sigPlayerUserInteractionBegins;
00419 SigC::Signal1<void,Player&> sigPlayerUserInteractionEnds;
00420 SigC::Signal1<void,Player&> sigPlayerTurnEnds;
00421 SigC::Signal1<void,Player&> sigPlayerTurnHasEnded;
00422
00423 static SigC::Signal1<void,GameMap&> sigMapDeletion;
00424
00426 SigC::Signal0<void> newRound;
00427
00428
00430 bool continueplaying;
00431
00432
00434
00435
00436
00437
00438 VisibilityStates getInitialMapVisibility( int player );
00439
00441 int resize( int top, int bottom, int left, int right );
00442
00443
00444
00445 void calculateAllObjects ( void );
00446
00447 void read ( tnstream& stream );
00448 void write ( tnstream& stream );
00449
00450 OverviewMapHolder overviewMapHolder;
00451
00456
00457
00458 pterraintype getterraintype_byid ( int id );
00459 ObjectType* getobjecttype_byid ( int id );
00460 Vehicletype* getvehicletype_byid ( int id );
00461 BuildingType* getbuildingtype_byid ( int id );
00462 const Technology* gettechnology_byid ( int id );
00463
00464 pterraintype getterraintype_bypos ( int pos );
00465 ObjectType* getobjecttype_bypos ( int pos );
00466 Vehicletype* getvehicletype_bypos ( int pos );
00467 BuildingType* getbuildingtype_bypos ( int pos );
00468 const Technology* gettechnology_bypos ( int pos );
00469
00470 int getTerrainTypeNum ( );
00471 int getObjectTypeNum ( );
00472 int getVehicleTypeNum ( );
00473 int getBuildingTypeNum ( );
00474 int getTechnologyNum ( );
00475
00477
00478 ~GameMap();
00479
00481 bool loadOldEvents;
00482
00484 int random( int max );
00485
00486 void guiHooked();
00487 bool getGuiHooked() { return dialogsHooked; };
00488
00489
00490 GameTransferMechanism* network;
00491
00492 int getMemoryFootprint() const;
00493
00494 private:
00495 Vehicle* getUnit ( Vehicle* eht, int nwid );
00496
00497 void objectGrowth();
00498 void setupResources ( void );
00499
00501 void processJournal();
00502
00503 unsigned int randomSeed;
00504
00505 static void setPlayerMode( Player& p, State s );
00506 };
00507
00508
00509
00510 #endif
00511