483 if (!StrEmpty(musicdriver)) ttd_strlcpy(_ini_musicdriver, musicdriver, sizeof(_ini_musicdriver)); |
483 if (!StrEmpty(musicdriver)) ttd_strlcpy(_ini_musicdriver, musicdriver, sizeof(_ini_musicdriver)); |
484 if (!StrEmpty(sounddriver)) ttd_strlcpy(_ini_sounddriver, sounddriver, sizeof(_ini_sounddriver)); |
484 if (!StrEmpty(sounddriver)) ttd_strlcpy(_ini_sounddriver, sounddriver, sizeof(_ini_sounddriver)); |
485 if (!StrEmpty(videodriver)) ttd_strlcpy(_ini_videodriver, videodriver, sizeof(_ini_videodriver)); |
485 if (!StrEmpty(videodriver)) ttd_strlcpy(_ini_videodriver, videodriver, sizeof(_ini_videodriver)); |
486 if (!StrEmpty(blitter)) ttd_strlcpy(_ini_blitter, blitter, sizeof(_ini_blitter)); |
486 if (!StrEmpty(blitter)) ttd_strlcpy(_ini_blitter, blitter, sizeof(_ini_blitter)); |
487 if (resolution[0] != 0) { _cur_resolution[0] = resolution[0]; _cur_resolution[1] = resolution[1]; } |
487 if (resolution[0] != 0) { _cur_resolution[0] = resolution[0]; _cur_resolution[1] = resolution[1]; } |
488 if (startyear != INVALID_YEAR) _patches_newgame.starting_year = startyear; |
488 if (startyear != INVALID_YEAR) _settings_newgame.game_creation.starting_year = startyear; |
489 if (generation_seed != GENERATE_NEW_SEED) _patches_newgame.generation_seed = generation_seed; |
489 if (generation_seed != GENERATE_NEW_SEED) _settings_newgame.game_creation.generation_seed = generation_seed; |
490 |
490 |
491 /* The width and height must be at least 1 pixel, this |
491 /* The width and height must be at least 1 pixel, this |
492 * way all internal drawing routines work correctly. */ |
492 * way all internal drawing routines work correctly. */ |
493 if (_cur_resolution[0] == 0) _cur_resolution[0] = 1; |
493 if (_cur_resolution[0] == 0) _cur_resolution[0] = 1; |
494 if (_cur_resolution[1] == 0) _cur_resolution[1] = 1; |
494 if (_cur_resolution[1] == 0) _cur_resolution[1] = 1; |
682 /* Create a single player */ |
682 /* Create a single player */ |
683 DoStartupNewPlayer(false); |
683 DoStartupNewPlayer(false); |
684 |
684 |
685 SetLocalPlayer(PLAYER_FIRST); |
685 SetLocalPlayer(PLAYER_FIRST); |
686 _current_player = _local_player; |
686 _current_player = _local_player; |
687 DoCommandP(0, (_patches.autorenew << 15 ) | (_patches.autorenew_months << 16) | 4, _patches.autorenew_money, NULL, CMD_SET_AUTOREPLACE); |
687 DoCommandP(0, (_settings.gui.autorenew << 15 ) | (_settings.gui.autorenew_months << 16) | 4, _settings.gui.autorenew_money, NULL, CMD_SET_AUTOREPLACE); |
688 |
688 |
689 SettingsDisableElrail(_patches.disable_elrails); |
689 SettingsDisableElrail(_settings.vehicle.disable_elrails); |
690 InitializeRailGUI(); |
690 InitializeRailGUI(); |
691 |
691 |
692 #ifdef ENABLE_NETWORK |
692 #ifdef ENABLE_NETWORK |
693 /* We are the server, we start a new player (not dedicated), |
693 /* We are the server, we start a new player (not dedicated), |
694 * so set the default password *if* needed. */ |
694 * so set the default password *if* needed. */ |
709 _house_mngr.ResetMapping(); |
709 _house_mngr.ResetMapping(); |
710 _industile_mngr.ResetMapping(); |
710 _industile_mngr.ResetMapping(); |
711 _industry_mngr.ResetMapping(); |
711 _industry_mngr.ResetMapping(); |
712 |
712 |
713 GenerateWorldSetCallback(&MakeNewGameDone); |
713 GenerateWorldSetCallback(&MakeNewGameDone); |
714 GenerateWorld(from_heightmap ? GW_HEIGHTMAP : GW_NEWGAME, 1 << _patches.map_x, 1 << _patches.map_y); |
714 GenerateWorld(from_heightmap ? GW_HEIGHTMAP : GW_NEWGAME, 1 << _settings.game_creation.map_x, 1 << _settings.game_creation.map_y); |
715 } |
715 } |
716 |
716 |
717 static void MakeNewEditorWorldDone() |
717 static void MakeNewEditorWorldDone() |
718 { |
718 { |
719 SetLocalPlayer(OWNER_NONE); |
719 SetLocalPlayer(OWNER_NONE); |
726 _game_mode = GM_EDITOR; |
726 _game_mode = GM_EDITOR; |
727 |
727 |
728 ResetGRFConfig(true); |
728 ResetGRFConfig(true); |
729 |
729 |
730 GenerateWorldSetCallback(&MakeNewEditorWorldDone); |
730 GenerateWorldSetCallback(&MakeNewEditorWorldDone); |
731 GenerateWorld(GW_EMPTY, 1 << _patches.map_x, 1 << _patches.map_y); |
731 GenerateWorld(GW_EMPTY, 1 << _settings.game_creation.map_x, 1 << _settings.game_creation.map_y); |
732 } |
732 } |
733 |
733 |
734 void StartupPlayers(); |
734 void StartupPlayers(); |
735 void StartupDisasters(); |
735 void StartupDisasters(); |
736 extern void StartupEconomy(); |
736 extern void StartupEconomy(); |
776 StartupEngines(); |
776 StartupEngines(); |
777 StartupDisasters(); |
777 StartupDisasters(); |
778 |
778 |
779 SetLocalPlayer(PLAYER_FIRST); |
779 SetLocalPlayer(PLAYER_FIRST); |
780 _current_player = _local_player; |
780 _current_player = _local_player; |
781 DoCommandP(0, (_patches.autorenew << 15 ) | (_patches.autorenew_months << 16) | 4, _patches.autorenew_money, NULL, CMD_SET_AUTOREPLACE); |
781 DoCommandP(0, (_settings.gui.autorenew << 15 ) | (_settings.gui.autorenew_months << 16) | 4, _settings.gui.autorenew_money, NULL, CMD_SET_AUTOREPLACE); |
782 |
782 |
783 MarkWholeScreenDirty(); |
783 MarkWholeScreenDirty(); |
784 } |
784 } |
785 |
785 |
786 /** Load the specified savegame but on error do different things. |
786 /** Load the specified savegame but on error do different things. |
835 /* But not if we are going to the menu */ |
835 /* But not if we are going to the menu */ |
836 if (new_mode != SM_MENU) { |
836 if (new_mode != SM_MENU) { |
837 /* check if we should reload the config */ |
837 /* check if we should reload the config */ |
838 if (_network_reload_cfg) { |
838 if (_network_reload_cfg) { |
839 LoadFromConfig(); |
839 LoadFromConfig(); |
840 _patches = _patches_newgame; |
840 _settings = _settings_newgame; |
841 _opt = _opt_newgame; |
841 _opt = _opt_newgame; |
842 ResetGRFConfig(false); |
842 ResetGRFConfig(false); |
843 } |
843 } |
844 NetworkServerStart(); |
844 NetworkServerStart(); |
845 } else { |
845 } else { |
909 break; |
909 break; |
910 |
910 |
911 case SM_LOAD_HEIGHTMAP: /* Load heightmap from scenario editor */ |
911 case SM_LOAD_HEIGHTMAP: /* Load heightmap from scenario editor */ |
912 SetLocalPlayer(OWNER_NONE); |
912 SetLocalPlayer(OWNER_NONE); |
913 |
913 |
914 GenerateWorld(GW_HEIGHTMAP, 1 << _patches.map_x, 1 << _patches.map_y); |
914 GenerateWorld(GW_HEIGHTMAP, 1 << _settings.game_creation.map_x, 1 << _settings.game_creation.map_y); |
915 MarkWholeScreenDirty(); |
915 MarkWholeScreenDirty(); |
916 break; |
916 break; |
917 |
917 |
918 case SM_LOAD_SCENARIO: { /* Load scenario from scenario editor */ |
918 case SM_LOAD_SCENARIO: { /* Load scenario from scenario editor */ |
919 if (SafeSaveOrLoad(_file_to_saveload.name, _file_to_saveload.mode, GM_EDITOR, NO_DIRECTORY)) { |
919 if (SafeSaveOrLoad(_file_to_saveload.name, _file_to_saveload.mode, GM_EDITOR, NO_DIRECTORY)) { |
920 SetLocalPlayer(OWNER_NONE); |
920 SetLocalPlayer(OWNER_NONE); |
921 _patches_newgame.starting_year = _cur_year; |
921 _settings_newgame.game_creation.starting_year = _cur_year; |
922 } else { |
922 } else { |
923 SetDParamStr(0, GetSaveLoadErrorString()); |
923 SetDParamStr(0, GetSaveLoadErrorString()); |
924 ShowErrorMessage(INVALID_STRING_ID, STR_012D, 0, 0); |
924 ShowErrorMessage(INVALID_STRING_ID, STR_012D, 0, 0); |
925 } |
925 } |
926 break; |
926 break; |
942 if (_networking && _pause_game == 2) _pause_game = 1; |
942 if (_networking && _pause_game == 2) _pause_game = 1; |
943 break; |
943 break; |
944 |
944 |
945 case SM_GENRANDLAND: /* Generate random land within scenario editor */ |
945 case SM_GENRANDLAND: /* Generate random land within scenario editor */ |
946 SetLocalPlayer(OWNER_NONE); |
946 SetLocalPlayer(OWNER_NONE); |
947 GenerateWorld(GW_RANDOM, 1 << _patches.map_x, 1 << _patches.map_y); |
947 GenerateWorld(GW_RANDOM, 1 << _settings.game_creation.map_x, 1 << _settings.game_creation.map_y); |
948 /* XXX: set date */ |
948 /* XXX: set date */ |
949 MarkWholeScreenDirty(); |
949 MarkWholeScreenDirty(); |
950 break; |
950 break; |
951 } |
951 } |
952 |
952 |
1058 #if defined(PSP) |
1058 #if defined(PSP) |
1059 /* Autosaving in networking is too time expensive for the PSP */ |
1059 /* Autosaving in networking is too time expensive for the PSP */ |
1060 if (_networking) return; |
1060 if (_networking) return; |
1061 #endif /* PSP */ |
1061 #endif /* PSP */ |
1062 |
1062 |
1063 if (_patches.keep_all_autosave && _local_player != PLAYER_SPECTATOR) { |
1063 if (_settings.gui.keep_all_autosave && _local_player != PLAYER_SPECTATOR) { |
1064 SetDParam(0, _local_player); |
1064 SetDParam(0, _local_player); |
1065 SetDParam(1, _date); |
1065 SetDParam(1, _date); |
1066 GetString(buf, STR_4004, lastof(buf)); |
1066 GetString(buf, STR_4004, lastof(buf)); |
1067 ttd_strlcat(buf, ".sav", lengthof(buf)); |
1067 ttd_strlcat(buf, ".sav", lengthof(buf)); |
1068 } else { |
1068 } else { |
1069 /* generate a savegame name and number according to _patches.max_num_autosaves */ |
1069 /* generate a savegame name and number according to _settings.gui.max_num_autosaves */ |
1070 snprintf(buf, sizeof(buf), "autosave%d.sav", _autosave_ctr); |
1070 snprintf(buf, sizeof(buf), "autosave%d.sav", _autosave_ctr); |
1071 |
1071 |
1072 if (++_autosave_ctr >= _patches.max_num_autosaves) _autosave_ctr = 0; |
1072 if (++_autosave_ctr >= _settings.gui.max_num_autosaves) _autosave_ctr = 0; |
1073 } |
1073 } |
1074 |
1074 |
1075 DEBUG(sl, 2, "Autosaving to '%s'", buf); |
1075 DEBUG(sl, 2, "Autosaving to '%s'", buf); |
1076 if (SaveOrLoad(buf, SL_SAVE, AUTOSAVE_DIR) != SL_OK) { |
1076 if (SaveOrLoad(buf, SL_SAVE, AUTOSAVE_DIR) != SL_OK) { |
1077 ShowErrorMessage(INVALID_STRING_ID, STR_AUTOSAVE_FAILED, 0, 0); |
1077 ShowErrorMessage(INVALID_STRING_ID, STR_AUTOSAVE_FAILED, 0, 0); |
1426 /* Update current year |
1426 /* Update current year |
1427 * must be done before loading sprites as some newgrfs check it */ |
1427 * must be done before loading sprites as some newgrfs check it */ |
1428 SetDate(_date); |
1428 SetDate(_date); |
1429 |
1429 |
1430 /* Force dynamic engines off when loading older savegames */ |
1430 /* Force dynamic engines off when loading older savegames */ |
1431 if (CheckSavegameVersion(95)) _patches.dynamic_engines = 0; |
1431 if (CheckSavegameVersion(95)) _settings.vehicle.dynamic_engines = 0; |
1432 |
1432 |
1433 /* Load the sprites */ |
1433 /* Load the sprites */ |
1434 GfxLoadSprites(); |
1434 GfxLoadSprites(); |
1435 LoadStringWidthTable(); |
1435 LoadStringWidthTable(); |
1436 |
1436 |
1633 * becomes player 0, unless we are in the scenario editor where all the |
1633 * becomes player 0, unless we are in the scenario editor where all the |
1634 * players are 'invalid'. |
1634 * players are 'invalid'. |
1635 */ |
1635 */ |
1636 if (!_network_dedicated && IsValidPlayer(PLAYER_FIRST)) { |
1636 if (!_network_dedicated && IsValidPlayer(PLAYER_FIRST)) { |
1637 p = GetPlayer(PLAYER_FIRST); |
1637 p = GetPlayer(PLAYER_FIRST); |
1638 p->engine_renew = _patches.autorenew; |
1638 p->engine_renew = _settings.gui.autorenew; |
1639 p->engine_renew_months = _patches.autorenew_months; |
1639 p->engine_renew_months = _settings.gui.autorenew_months; |
1640 p->engine_renew_money = _patches.autorenew_money; |
1640 p->engine_renew_money = _settings.gui.autorenew_money; |
1641 } |
1641 } |
1642 } |
1642 } |
1643 |
1643 |
1644 if (CheckSavegameVersion(48)) { |
1644 if (CheckSavegameVersion(48)) { |
1645 for (TileIndex t = 0; t < map_size; t++) { |
1645 for (TileIndex t = 0; t < map_size; t++) { |
2020 } |
2020 } |
2021 } |
2021 } |
2022 |
2022 |
2023 /* from version 38 we have optional elrails, since we cannot know the |
2023 /* from version 38 we have optional elrails, since we cannot know the |
2024 * preference of a user, let elrails enabled; it can be disabled manually */ |
2024 * preference of a user, let elrails enabled; it can be disabled manually */ |
2025 if (CheckSavegameVersion(38)) _patches.disable_elrails = false; |
2025 if (CheckSavegameVersion(38)) _settings.vehicle.disable_elrails = false; |
2026 /* do the same as when elrails were enabled/disabled manually just now */ |
2026 /* do the same as when elrails were enabled/disabled manually just now */ |
2027 SettingsDisableElrail(_patches.disable_elrails); |
2027 SettingsDisableElrail(_settings.vehicle.disable_elrails); |
2028 InitializeRailGUI(); |
2028 InitializeRailGUI(); |
2029 |
2029 |
2030 /* From version 53, the map array was changed for house tiles to allow |
2030 /* From version 53, the map array was changed for house tiles to allow |
2031 * space for newhouses grf features. A new byte, m7, was also added. */ |
2031 * space for newhouses grf features. A new byte, m7, was also added. */ |
2032 if (CheckSavegameVersion(53)) { |
2032 if (CheckSavegameVersion(53)) { |
2462 } |
2462 } |
2463 } |
2463 } |
2464 } |
2464 } |
2465 |
2465 |
2466 /* Convert old PF settings to new */ |
2466 /* Convert old PF settings to new */ |
2467 if (_patches.yapf.rail_use_yapf || CheckSavegameVersion(28)) { |
2467 if (_settings.pf.yapf.rail_use_yapf || CheckSavegameVersion(28)) { |
2468 _patches.pathfinder_for_trains = VPF_YAPF; |
2468 _settings.pf.pathfinder_for_trains = VPF_YAPF; |
2469 } else { |
2469 } else { |
2470 _patches.pathfinder_for_trains = (_patches.new_pathfinding_all ? VPF_NPF : VPF_NTP); |
2470 _settings.pf.pathfinder_for_trains = (_settings.pf.new_pathfinding_all ? VPF_NPF : VPF_NTP); |
2471 } |
2471 } |
2472 |
2472 |
2473 if (_patches.yapf.road_use_yapf || CheckSavegameVersion(28)) { |
2473 if (_settings.pf.yapf.road_use_yapf || CheckSavegameVersion(28)) { |
2474 _patches.pathfinder_for_roadvehs = VPF_YAPF; |
2474 _settings.pf.pathfinder_for_roadvehs = VPF_YAPF; |
2475 } else { |
2475 } else { |
2476 _patches.pathfinder_for_roadvehs = (_patches.new_pathfinding_all ? VPF_NPF : VPF_OPF); |
2476 _settings.pf.pathfinder_for_roadvehs = (_settings.pf.new_pathfinding_all ? VPF_NPF : VPF_OPF); |
2477 } |
2477 } |
2478 |
2478 |
2479 if (_patches.yapf.ship_use_yapf) { |
2479 if (_settings.pf.yapf.ship_use_yapf) { |
2480 _patches.pathfinder_for_ships = VPF_YAPF; |
2480 _settings.pf.pathfinder_for_ships = VPF_YAPF; |
2481 } else { |
2481 } else { |
2482 _patches.pathfinder_for_ships = (_patches.new_pathfinding_all ? VPF_NPF : VPF_OPF); |
2482 _settings.pf.pathfinder_for_ships = (_settings.pf.new_pathfinding_all ? VPF_NPF : VPF_OPF); |
2483 } |
2483 } |
2484 } |
2484 } |
2485 |
2485 |
2486 if (CheckSavegameVersion(88)) { |
2486 if (CheckSavegameVersion(88)) { |
2487 /* Profits are now with 8 bit fract */ |
2487 /* Profits are now with 8 bit fract */ |