|
@@ -482,14 +482,14 @@ int ttd_main(int argc, char *argv[])
|
|
|
/* override config? */
|
|
|
if (!StrEmpty(musicdriver)) ttd_strlcpy(_ini_musicdriver, musicdriver, sizeof(_ini_musicdriver));
|
|
|
if (!StrEmpty(sounddriver)) ttd_strlcpy(_ini_sounddriver, sounddriver, sizeof(_ini_sounddriver));
|
|
|
if (!StrEmpty(videodriver)) ttd_strlcpy(_ini_videodriver, videodriver, sizeof(_ini_videodriver));
|
|
|
if (!StrEmpty(blitter)) ttd_strlcpy(_ini_blitter, blitter, sizeof(_ini_blitter));
|
|
|
if (resolution[0] != 0) { _cur_resolution[0] = resolution[0]; _cur_resolution[1] = resolution[1]; }
|
|
|
if (startyear != INVALID_YEAR) _patches_newgame.starting_year = startyear;
|
|
|
if (generation_seed != GENERATE_NEW_SEED) _patches_newgame.generation_seed = generation_seed;
|
|
|
if (startyear != INVALID_YEAR) _settings_newgame.game_creation.starting_year = startyear;
|
|
|
if (generation_seed != GENERATE_NEW_SEED) _settings_newgame.game_creation.generation_seed = generation_seed;
|
|
|
|
|
|
/* The width and height must be at least 1 pixel, this
|
|
|
* way all internal drawing routines work correctly. */
|
|
|
if (_cur_resolution[0] == 0) _cur_resolution[0] = 1;
|
|
|
if (_cur_resolution[1] == 0) _cur_resolution[1] = 1;
|
|
|
|
|
@@ -649,13 +649,13 @@ int ttd_main(int argc, char *argv[])
|
|
|
}
|
|
|
|
|
|
void HandleExitGameRequest()
|
|
|
{
|
|
|
if (_game_mode == GM_MENU) { // do not ask to quit on the main screen
|
|
|
_exit_game = true;
|
|
|
} else if (_patches.autosave_on_exit) {
|
|
|
} else if (_settings.gui.autosave_on_exit) {
|
|
|
DoExitSave();
|
|
|
_exit_game = true;
|
|
|
} else {
|
|
|
AskExitGame();
|
|
|
}
|
|
|
}
|
|
@@ -681,15 +681,15 @@ static void MakeNewGameDone()
|
|
|
|
|
|
/* Create a single player */
|
|
|
DoStartupNewPlayer(false);
|
|
|
|
|
|
SetLocalPlayer(PLAYER_FIRST);
|
|
|
_current_player = _local_player;
|
|
|
DoCommandP(0, (_patches.autorenew << 15 ) | (_patches.autorenew_months << 16) | 4, _patches.autorenew_money, NULL, CMD_SET_AUTOREPLACE);
|
|
|
DoCommandP(0, (_settings.gui.autorenew << 15 ) | (_settings.gui.autorenew_months << 16) | 4, _settings.gui.autorenew_money, NULL, CMD_SET_AUTOREPLACE);
|
|
|
|
|
|
SettingsDisableElrail(_patches.disable_elrails);
|
|
|
SettingsDisableElrail(_settings.vehicle.disable_elrails);
|
|
|
InitializeRailGUI();
|
|
|
|
|
|
#ifdef ENABLE_NETWORK
|
|
|
/* We are the server, we start a new player (not dedicated),
|
|
|
* so set the default password *if* needed. */
|
|
|
if (_network_server && !StrEmpty(_network_default_company_pass)) {
|
|
@@ -708,13 +708,13 @@ static void MakeNewGame(bool from_height
|
|
|
ResetGRFConfig(true);
|
|
|
_house_mngr.ResetMapping();
|
|
|
_industile_mngr.ResetMapping();
|
|
|
_industry_mngr.ResetMapping();
|
|
|
|
|
|
GenerateWorldSetCallback(&MakeNewGameDone);
|
|
|
GenerateWorld(from_heightmap ? GW_HEIGHTMAP : GW_NEWGAME, 1 << _patches.map_x, 1 << _patches.map_y);
|
|
|
GenerateWorld(from_heightmap ? GW_HEIGHTMAP : GW_NEWGAME, 1 << _settings.game_creation.map_x, 1 << _settings.game_creation.map_y);
|
|
|
}
|
|
|
|
|
|
static void MakeNewEditorWorldDone()
|
|
|
{
|
|
|
SetLocalPlayer(OWNER_NONE);
|
|
|
|
|
@@ -725,13 +725,13 @@ static void MakeNewEditorWorld()
|
|
|
{
|
|
|
_game_mode = GM_EDITOR;
|
|
|
|
|
|
ResetGRFConfig(true);
|
|
|
|
|
|
GenerateWorldSetCallback(&MakeNewEditorWorldDone);
|
|
|
GenerateWorld(GW_EMPTY, 1 << _patches.map_x, 1 << _patches.map_y);
|
|
|
GenerateWorld(GW_EMPTY, 1 << _settings.game_creation.map_x, 1 << _settings.game_creation.map_y);
|
|
|
}
|
|
|
|
|
|
void StartupPlayers();
|
|
|
void StartupDisasters();
|
|
|
extern void StartupEconomy();
|
|
|
|
|
@@ -775,13 +775,13 @@ static void StartScenario()
|
|
|
StartupPlayers();
|
|
|
StartupEngines();
|
|
|
StartupDisasters();
|
|
|
|
|
|
SetLocalPlayer(PLAYER_FIRST);
|
|
|
_current_player = _local_player;
|
|
|
DoCommandP(0, (_patches.autorenew << 15 ) | (_patches.autorenew_months << 16) | 4, _patches.autorenew_money, NULL, CMD_SET_AUTOREPLACE);
|
|
|
DoCommandP(0, (_settings.gui.autorenew << 15 ) | (_settings.gui.autorenew_months << 16) | 4, _settings.gui.autorenew_money, NULL, CMD_SET_AUTOREPLACE);
|
|
|
|
|
|
MarkWholeScreenDirty();
|
|
|
}
|
|
|
|
|
|
/** Load the specified savegame but on error do different things.
|
|
|
* If loading fails due to corrupt savegame, bad version, etc. go back to
|
|
@@ -834,13 +834,13 @@ void SwitchMode(int new_mode)
|
|
|
if (_is_network_server) {
|
|
|
/* But not if we are going to the menu */
|
|
|
if (new_mode != SM_MENU) {
|
|
|
/* check if we should reload the config */
|
|
|
if (_network_reload_cfg) {
|
|
|
LoadFromConfig();
|
|
|
_patches = _patches_newgame;
|
|
|
_settings = _settings_newgame;
|
|
|
_opt = _opt_newgame;
|
|
|
ResetGRFConfig(false);
|
|
|
}
|
|
|
NetworkServerStart();
|
|
|
} else {
|
|
|
/* This client no longer wants to be a network-server */
|
|
@@ -908,20 +908,20 @@ void SwitchMode(int new_mode)
|
|
|
MakeNewGame(true);
|
|
|
break;
|
|
|
|
|
|
case SM_LOAD_HEIGHTMAP: /* Load heightmap from scenario editor */
|
|
|
SetLocalPlayer(OWNER_NONE);
|
|
|
|
|
|
GenerateWorld(GW_HEIGHTMAP, 1 << _patches.map_x, 1 << _patches.map_y);
|
|
|
GenerateWorld(GW_HEIGHTMAP, 1 << _settings.game_creation.map_x, 1 << _settings.game_creation.map_y);
|
|
|
MarkWholeScreenDirty();
|
|
|
break;
|
|
|
|
|
|
case SM_LOAD_SCENARIO: { /* Load scenario from scenario editor */
|
|
|
if (SafeSaveOrLoad(_file_to_saveload.name, _file_to_saveload.mode, GM_EDITOR, NO_DIRECTORY)) {
|
|
|
SetLocalPlayer(OWNER_NONE);
|
|
|
_patches_newgame.starting_year = _cur_year;
|
|
|
_settings_newgame.game_creation.starting_year = _cur_year;
|
|
|
} else {
|
|
|
SetDParamStr(0, GetSaveLoadErrorString());
|
|
|
ShowErrorMessage(INVALID_STRING_ID, STR_012D, 0, 0);
|
|
|
}
|
|
|
break;
|
|
|
}
|
|
@@ -941,13 +941,13 @@ void SwitchMode(int new_mode)
|
|
|
}
|
|
|
if (_networking && _pause_game == 2) _pause_game = 1;
|
|
|
break;
|
|
|
|
|
|
case SM_GENRANDLAND: /* Generate random land within scenario editor */
|
|
|
SetLocalPlayer(OWNER_NONE);
|
|
|
GenerateWorld(GW_RANDOM, 1 << _patches.map_x, 1 << _patches.map_y);
|
|
|
GenerateWorld(GW_RANDOM, 1 << _settings.game_creation.map_x, 1 << _settings.game_creation.map_y);
|
|
|
/* XXX: set date */
|
|
|
MarkWholeScreenDirty();
|
|
|
break;
|
|
|
}
|
|
|
|
|
|
if (_switch_mode_errorstr != INVALID_STRING_ID) {
|
|
@@ -1057,22 +1057,22 @@ static void DoAutosave()
|
|
|
|
|
|
#if defined(PSP)
|
|
|
/* Autosaving in networking is too time expensive for the PSP */
|
|
|
if (_networking) return;
|
|
|
#endif /* PSP */
|
|
|
|
|
|
if (_patches.keep_all_autosave && _local_player != PLAYER_SPECTATOR) {
|
|
|
if (_settings.gui.keep_all_autosave && _local_player != PLAYER_SPECTATOR) {
|
|
|
SetDParam(0, _local_player);
|
|
|
SetDParam(1, _date);
|
|
|
GetString(buf, STR_4004, lastof(buf));
|
|
|
ttd_strlcat(buf, ".sav", lengthof(buf));
|
|
|
} else {
|
|
|
/* generate a savegame name and number according to _patches.max_num_autosaves */
|
|
|
/* generate a savegame name and number according to _settings.gui.max_num_autosaves */
|
|
|
snprintf(buf, sizeof(buf), "autosave%d.sav", _autosave_ctr);
|
|
|
|
|
|
if (++_autosave_ctr >= _patches.max_num_autosaves) _autosave_ctr = 0;
|
|
|
if (++_autosave_ctr >= _settings.gui.max_num_autosaves) _autosave_ctr = 0;
|
|
|
}
|
|
|
|
|
|
DEBUG(sl, 2, "Autosaving to '%s'", buf);
|
|
|
if (SaveOrLoad(buf, SL_SAVE, AUTOSAVE_DIR) != SL_OK) {
|
|
|
ShowErrorMessage(INVALID_STRING_ID, STR_AUTOSAVE_FAILED, 0, 0);
|
|
|
}
|
|
@@ -1425,13 +1425,13 @@ bool AfterLoadGame()
|
|
|
|
|
|
/* Update current year
|
|
|
* must be done before loading sprites as some newgrfs check it */
|
|
|
SetDate(_date);
|
|
|
|
|
|
/* Force dynamic engines off when loading older savegames */
|
|
|
if (CheckSavegameVersion(95)) _patches.dynamic_engines = 0;
|
|
|
if (CheckSavegameVersion(95)) _settings.vehicle.dynamic_engines = 0;
|
|
|
|
|
|
/* Load the sprites */
|
|
|
GfxLoadSprites();
|
|
|
LoadStringWidthTable();
|
|
|
|
|
|
/* Copy temporary data to Engine pool */
|
|
@@ -1632,15 +1632,15 @@ bool AfterLoadGame()
|
|
|
* happen. In case we are not a dedicated server, the local player always
|
|
|
* becomes player 0, unless we are in the scenario editor where all the
|
|
|
* players are 'invalid'.
|
|
|
*/
|
|
|
if (!_network_dedicated && IsValidPlayer(PLAYER_FIRST)) {
|
|
|
p = GetPlayer(PLAYER_FIRST);
|
|
|
p->engine_renew = _patches.autorenew;
|
|
|
p->engine_renew_months = _patches.autorenew_months;
|
|
|
p->engine_renew_money = _patches.autorenew_money;
|
|
|
p->engine_renew = _settings.gui.autorenew;
|
|
|
p->engine_renew_months = _settings.gui.autorenew_months;
|
|
|
p->engine_renew_money = _settings.gui.autorenew_money;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
if (CheckSavegameVersion(48)) {
|
|
|
for (TileIndex t = 0; t < map_size; t++) {
|
|
|
switch (GetTileType(t)) {
|
|
@@ -2019,15 +2019,15 @@ bool AfterLoadGame()
|
|
|
v->current_order.SetRefit(CT_NO_REFIT);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
/* from version 38 we have optional elrails, since we cannot know the
|
|
|
* preference of a user, let elrails enabled; it can be disabled manually */
|
|
|
if (CheckSavegameVersion(38)) _patches.disable_elrails = false;
|
|
|
if (CheckSavegameVersion(38)) _settings.vehicle.disable_elrails = false;
|
|
|
/* do the same as when elrails were enabled/disabled manually just now */
|
|
|
SettingsDisableElrail(_patches.disable_elrails);
|
|
|
SettingsDisableElrail(_settings.vehicle.disable_elrails);
|
|
|
InitializeRailGUI();
|
|
|
|
|
|
/* From version 53, the map array was changed for house tiles to allow
|
|
|
* space for newhouses grf features. A new byte, m7, was also added. */
|
|
|
if (CheckSavegameVersion(53)) {
|
|
|
for (TileIndex t = 0; t < map_size; t++) {
|
|
@@ -2186,13 +2186,13 @@ bool AfterLoadGame()
|
|
|
* fast was added in version 54. From version 56 this is now saved in the
|
|
|
* town as cities can be built specifically in the scenario editor. */
|
|
|
if (CheckSavegameVersion(56)) {
|
|
|
Town *t;
|
|
|
|
|
|
FOR_ALL_TOWNS(t) {
|
|
|
if (_patches.larger_towns != 0 && (t->index % _patches.larger_towns) == 0) {
|
|
|
if (_settings.economy.larger_towns != 0 && (t->index % _settings.economy.larger_towns) == 0) {
|
|
|
t->larger_town = true;
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
if (CheckSavegameVersion(57)) {
|
|
@@ -2461,28 +2461,28 @@ bool AfterLoadGame()
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
/* Convert old PF settings to new */
|
|
|
if (_patches.yapf.rail_use_yapf || CheckSavegameVersion(28)) {
|
|
|
_patches.pathfinder_for_trains = VPF_YAPF;
|
|
|
if (_settings.pf.yapf.rail_use_yapf || CheckSavegameVersion(28)) {
|
|
|
_settings.pf.pathfinder_for_trains = VPF_YAPF;
|
|
|
} else {
|
|
|
_patches.pathfinder_for_trains = (_patches.new_pathfinding_all ? VPF_NPF : VPF_NTP);
|
|
|
_settings.pf.pathfinder_for_trains = (_settings.pf.new_pathfinding_all ? VPF_NPF : VPF_NTP);
|
|
|
}
|
|
|
|
|
|
if (_patches.yapf.road_use_yapf || CheckSavegameVersion(28)) {
|
|
|
_patches.pathfinder_for_roadvehs = VPF_YAPF;
|
|
|
if (_settings.pf.yapf.road_use_yapf || CheckSavegameVersion(28)) {
|
|
|
_settings.pf.pathfinder_for_roadvehs = VPF_YAPF;
|
|
|
} else {
|
|
|
_patches.pathfinder_for_roadvehs = (_patches.new_pathfinding_all ? VPF_NPF : VPF_OPF);
|
|
|
_settings.pf.pathfinder_for_roadvehs = (_settings.pf.new_pathfinding_all ? VPF_NPF : VPF_OPF);
|
|
|
}
|
|
|
|
|
|
if (_patches.yapf.ship_use_yapf) {
|
|
|
_patches.pathfinder_for_ships = VPF_YAPF;
|
|
|
if (_settings.pf.yapf.ship_use_yapf) {
|
|
|
_settings.pf.pathfinder_for_ships = VPF_YAPF;
|
|
|
} else {
|
|
|
_patches.pathfinder_for_ships = (_patches.new_pathfinding_all ? VPF_NPF : VPF_OPF);
|
|
|
_settings.pf.pathfinder_for_ships = (_settings.pf.new_pathfinding_all ? VPF_NPF : VPF_OPF);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
if (CheckSavegameVersion(88)) {
|
|
|
/* Profits are now with 8 bit fract */
|
|
|
Vehicle *v;
|