(svn r3376) -Codechange: made enums for GenerateWorld and InitializeGame 'mode'

-Fix: [ FS#30 ] don't reset date in SE when pressing RandomLand (rewrote patch of MeusH, but Peter warned me I should put his name in, so... oh well)
This commit is contained in:
truelight 2006-01-06 21:57:37 +00:00
parent 10a2787fd5
commit efd3d42107
5 changed files with 30 additions and 15 deletions

View File

@ -1067,7 +1067,7 @@ static void ResetLandscape(void)
_random_seeds[0][0] = InteractiveRandom(); _random_seeds[0][0] = InteractiveRandom();
_random_seeds[0][1] = InteractiveRandom(); _random_seeds[0][1] = InteractiveRandom();
GenerateWorld(1, 1 << _patches.map_x, 1 << _patches.map_y); GenerateWorld(GW_EMPTY, 1 << _patches.map_x, 1 << _patches.map_y);
MarkWholeScreenDirty(); MarkWholeScreenDirty();
} }

12
misc.c
View File

@ -122,7 +122,7 @@ void GenerateTrees(void);
void ConvertGroundTilesIntoWaterTiles(void); void ConvertGroundTilesIntoWaterTiles(void);
void InitializeGame(uint size_x, uint size_y) void InitializeGame(int mode, uint size_x, uint size_y)
{ {
AllocateMap(size_x, size_y); AllocateMap(size_x, size_y);
@ -136,7 +136,7 @@ void InitializeGame(uint size_x, uint size_y)
_date_fract = 0; _date_fract = 0;
_cur_tileloop_tile = 0; _cur_tileloop_tile = 0;
{ if ((mode & IG_DATE_RESET) == IG_DATE_RESET) {
uint starting = ConvertIntDate(_patches.starting_date); uint starting = ConvertIntDate(_patches.starting_date);
if ( starting == (uint)-1) starting = 10958; if ( starting == (uint)-1) starting = 10958;
SetDate(starting); SetDate(starting);
@ -189,14 +189,14 @@ void GenerateWorld(int mode, uint size_x, uint size_y)
_current_player = OWNER_NONE; _current_player = OWNER_NONE;
_generating_world = true; _generating_world = true;
InitializeGame(size_x, size_y); InitializeGame(mode == GW_RANDOM ? 0 : IG_DATE_RESET, size_x, size_y);
SetObjectToPlace(SPR_CURSOR_ZZZ, 0, 0, 0); SetObjectToPlace(SPR_CURSOR_ZZZ, 0, 0, 0);
// Must start economy early because of the costs. // Must start economy early because of the costs.
StartupEconomy(); StartupEconomy();
// Don't generate landscape items when in the scenario editor. // Don't generate landscape items when in the scenario editor.
if (mode == 1) { if (mode == GW_EMPTY) {
// empty world in scenario editor // empty world in scenario editor
ConvertGroundTilesIntoWaterTiles(); ConvertGroundTilesIntoWaterTiles();
} else { } else {
@ -204,7 +204,7 @@ void GenerateWorld(int mode, uint size_x, uint size_y)
GenerateClearTile(); GenerateClearTile();
// only generate towns, tree and industries in newgame mode. // only generate towns, tree and industries in newgame mode.
if (mode == 0) { if (mode == GW_NEWGAME) {
GenerateTowns(); GenerateTowns();
GenerateTrees(); GenerateTrees();
GenerateIndustries(); GenerateIndustries();
@ -219,7 +219,7 @@ void GenerateWorld(int mode, uint size_x, uint size_y)
_generating_world = false; _generating_world = false;
// No need to run the tile loop in the scenario editor. // No need to run the tile loop in the scenario editor.
if (mode != 1) { if (mode != GW_EMPTY) {
for(i=0x500; i!=0; i--) for(i=0x500; i!=0; i--)
RunTileLoop(); RunTileLoop();
} }

View File

@ -279,7 +279,7 @@ static void LoadIntroGame(void)
sprintf(filename, "%sopntitle.dat", _path.second_data_dir); sprintf(filename, "%sopntitle.dat", _path.second_data_dir);
if (SaveOrLoad(filename, SL_LOAD) != SL_OK) if (SaveOrLoad(filename, SL_LOAD) != SL_OK)
#endif #endif
GenerateWorld(1, 64, 64); // if failed loading, make empty world. GenerateWorld(GW_EMPTY, 64, 64); // if failed loading, make empty world.
} }
_pause = 0; _pause = 0;
@ -461,7 +461,7 @@ int ttd_main(int argc, char* argv[])
InitializeGUI(); InitializeGUI();
IConsoleCmdExec("exec scripts/autoexec.scr 0"); IConsoleCmdExec("exec scripts/autoexec.scr 0");
GenerateWorld(1, 64, 64); // Make the viewport initialization happy GenerateWorld(GW_EMPTY, 64, 64); // Make the viewport initialization happy
#ifdef ENABLE_NETWORK #ifdef ENABLE_NETWORK
if ((network) && (_network_available)) { if ((network) && (_network_available)) {
@ -582,7 +582,7 @@ static void MakeNewGame(void)
SetupColorsAndInitialWindow(); SetupColorsAndInitialWindow();
// Randomize world // Randomize world
GenerateWorld(0, 1<<_patches.map_x, 1<<_patches.map_y); GenerateWorld(GW_NEWGAME, 1<<_patches.map_x, 1<<_patches.map_y);
// In a dedicated server, the server does not play // In a dedicated server, the server does not play
if (_network_dedicated) { if (_network_dedicated) {
@ -616,7 +616,7 @@ static void MakeNewEditorWorld(void)
SetupColorsAndInitialWindow(); SetupColorsAndInitialWindow();
// Startup the game system // Startup the game system
GenerateWorld(1, 1 << _patches.map_x, 1 << _patches.map_y); GenerateWorld(GW_EMPTY, 1 << _patches.map_x, 1 << _patches.map_y);
_local_player = OWNER_NONE; _local_player = OWNER_NONE;
MarkWholeScreenDirty(); MarkWholeScreenDirty();
@ -797,7 +797,7 @@ void SwitchMode(int new_mode)
break; break;
case SM_GENRANDLAND: /* Generate random land within scenario editor */ case SM_GENRANDLAND: /* Generate random land within scenario editor */
GenerateWorld(2, 1<<_patches.map_x, 1<<_patches.map_y); GenerateWorld(GW_RANDOM, 1<<_patches.map_x, 1<<_patches.map_y);
// XXX: set date // XXX: set date
_local_player = OWNER_NONE; _local_player = OWNER_NONE;
MarkWholeScreenDirty(); MarkWholeScreenDirty();

View File

@ -93,6 +93,21 @@ enum SwitchModes {
SM_START_SCENARIO = 10, SM_START_SCENARIO = 10,
}; };
/* Modes for GenerateWorld */
enum GenerateWorldModes {
GW_NEWGAME = 0, /* Generate a map for a new game */
GW_EMPTY = 1, /* Generate an empty map (sea-level) */
GW_RANDOM = 2, /* Generate a random map for SE */
};
/* Modes for InitializeGame, those are _bits_! */
enum InitializeGameModes {
IG_NONE = 0, /* Don't do anything special */
IG_DATE_RESET = 1, /* Reset the date when initializing a game */
};
typedef enum TransportTypes { typedef enum TransportTypes {
/* These constants are for now linked to the representation of bridges /* These constants are for now linked to the representation of bridges
* and tunnels, so they can be used by GetTileTrackStatus_TunnelBridge * and tunnels, so they can be used by GetTileTrackStatus_TunnelBridge

View File

@ -1232,7 +1232,7 @@ static const SaveLoadFormat *GetSavegameFormat(const char *s)
} }
// actual loader/saver function // actual loader/saver function
void InitializeGame(uint size_x, uint size_y); void InitializeGame(int mode, uint size_x, uint size_y);
extern bool AfterLoadGame(void); extern bool AfterLoadGame(void);
extern void BeforeSaveGame(void); extern void BeforeSaveGame(void);
extern bool LoadOldSaveGame(const char *file); extern bool LoadOldSaveGame(const char *file);
@ -1363,7 +1363,7 @@ SaveOrLoadResult SaveOrLoad(const char *filename, int mode)
/* Load a TTDLX or TTDPatch game */ /* Load a TTDLX or TTDPatch game */
if (mode == SL_OLD_LOAD) { if (mode == SL_OLD_LOAD) {
InitializeGame(256, 256); // set a mapsize of 256x256 for TTDPatch games or it might get confused InitializeGame(IG_DATE_RESET, 256, 256); // set a mapsize of 256x256 for TTDPatch games or it might get confused
if (!LoadOldSaveGame(filename)) return SL_REINIT; if (!LoadOldSaveGame(filename)) return SL_REINIT;
_sl_version = 0; _sl_version = 0;
AfterLoadGame(); AfterLoadGame();
@ -1487,7 +1487,7 @@ SaveOrLoadResult SaveOrLoad(const char *filename, int mode)
/* Old maps were hardcoded to 256x256 and thus did not contain /* Old maps were hardcoded to 256x256 and thus did not contain
* any mapsize information. Pre-initialize to 256x256 to not to * any mapsize information. Pre-initialize to 256x256 to not to
* confuse old games */ * confuse old games */
InitializeGame(256, 256); InitializeGame(IG_DATE_RESET, 256, 256);
SlLoadChunks(); SlLoadChunks();
fmt->uninit_read(); fmt->uninit_read();