96 void ResetOldNames(); |
96 void ResetOldNames(); |
97 void ProcessAsyncSaveFinish(); |
97 void ProcessAsyncSaveFinish(); |
98 void CallWindowTickEvent(); |
98 void CallWindowTickEvent(); |
99 |
99 |
100 extern void SetDifficultyLevel(int mode, DifficultySettings *gm_opt); |
100 extern void SetDifficultyLevel(int mode, DifficultySettings *gm_opt); |
101 extern Player* DoStartupNewPlayer(bool is_ai); |
101 extern Company *DoStartupNewCompany(bool is_ai); |
102 extern void ShowOSErrorBox(const char *buf, bool system); |
102 extern void ShowOSErrorBox(const char *buf, bool system); |
103 extern void InitializeRailGUI(); |
103 extern void InitializeRailGUI(); |
104 |
104 |
105 /** |
105 /** |
106 * Error handling for fatal user errors. |
106 * Error handling for fatal user errors. |
180 " -d [[fac=]lvl[,...]]= Debug mode\n" |
180 " -d [[fac=]lvl[,...]]= Debug mode\n" |
181 " -e = Start Editor\n" |
181 " -e = Start Editor\n" |
182 " -g [savegame] = Start new/save game immediately\n" |
182 " -g [savegame] = Start new/save game immediately\n" |
183 " -G seed = Set random seed\n" |
183 " -G seed = Set random seed\n" |
184 #if defined(ENABLE_NETWORK) |
184 #if defined(ENABLE_NETWORK) |
185 " -n [ip:port#player] = Start networkgame\n" |
185 " -n [ip:port#company]= Start networkgame\n" |
186 " -D [ip][:port] = Start dedicated server\n" |
186 " -D [ip][:port] = Start dedicated server\n" |
187 " -l ip[:port] = Redirect DEBUG()\n" |
187 " -l ip[:port] = Redirect DEBUG()\n" |
188 #if !defined(__MORPHOS__) && !defined(__AMIGA__) && !defined(WIN32) |
188 #if !defined(__MORPHOS__) && !defined(__AMIGA__) && !defined(WIN32) |
189 " -f = Fork into the background (dedicated only)\n" |
189 " -f = Fork into the background (dedicated only)\n" |
190 #endif |
190 #endif |
305 static void InitializeDynamicVariables() |
305 static void InitializeDynamicVariables() |
306 { |
306 { |
307 /* Dynamic stuff needs to be initialized somewhere... */ |
307 /* Dynamic stuff needs to be initialized somewhere... */ |
308 _industry_mngr.ResetMapping(); |
308 _industry_mngr.ResetMapping(); |
309 _industile_mngr.ResetMapping(); |
309 _industile_mngr.ResetMapping(); |
310 _Player_pool.AddBlockToPool(); |
310 _Company_pool.AddBlockToPool(); |
311 } |
311 } |
312 |
312 |
313 |
313 |
314 /** Unitializes drivers, frees allocated memory, cleans pools, ... |
314 /** Unitializes drivers, frees allocated memory, cleans pools, ... |
315 * Generally, prepares the game for shutting down |
315 * Generally, prepares the game for shutting down |
339 _Sign_pool.CleanPool(); |
339 _Sign_pool.CleanPool(); |
340 _Order_pool.CleanPool(); |
340 _Order_pool.CleanPool(); |
341 _Group_pool.CleanPool(); |
341 _Group_pool.CleanPool(); |
342 _CargoPacket_pool.CleanPool(); |
342 _CargoPacket_pool.CleanPool(); |
343 _Engine_pool.CleanPool(); |
343 _Engine_pool.CleanPool(); |
344 _Player_pool.CleanPool(); |
344 _Company_pool.CleanPool(); |
345 |
345 |
346 free(_config_file); |
346 free(_config_file); |
347 |
347 |
348 /* Close all and any open filehandles */ |
348 /* Close all and any open filehandles */ |
349 FioCloseAll(); |
349 FioCloseAll(); |
361 |
361 |
362 /* Load the default opening screen savegame */ |
362 /* Load the default opening screen savegame */ |
363 if (SaveOrLoad("opntitle.dat", SL_LOAD, DATA_DIR) != SL_OK) { |
363 if (SaveOrLoad("opntitle.dat", SL_LOAD, DATA_DIR) != SL_OK) { |
364 GenerateWorld(GW_EMPTY, 64, 64); // if failed loading, make empty world. |
364 GenerateWorld(GW_EMPTY, 64, 64); // if failed loading, make empty world. |
365 WaitTillGeneratedWorld(); |
365 WaitTillGeneratedWorld(); |
366 SetLocalPlayer(PLAYER_SPECTATOR); |
366 SetLocalCompany(COMPANY_SPECTATOR); |
367 } else { |
367 } else { |
368 SetLocalPlayer(PLAYER_FIRST); |
368 SetLocalCompany(COMPANY_FIRST); |
369 } |
369 } |
370 |
370 |
371 _pause_game = 0; |
371 _pause_game = 0; |
372 _cursor.fix_at = false; |
372 _cursor.fix_at = false; |
373 MarkWholeScreenDirty(); |
373 MarkWholeScreenDirty(); |
435 strcpy(videodriver, "dedicated"); |
435 strcpy(videodriver, "dedicated"); |
436 strcpy(blitter, "null"); |
436 strcpy(blitter, "null"); |
437 dedicated = true; |
437 dedicated = true; |
438 if (mgo.opt != NULL) { |
438 if (mgo.opt != NULL) { |
439 /* Use the existing method for parsing (openttd -n). |
439 /* Use the existing method for parsing (openttd -n). |
440 * However, we do ignore the #player part. */ |
440 * However, we do ignore the #company part. */ |
441 const char *temp = NULL; |
441 const char *temp = NULL; |
442 const char *port = NULL; |
442 const char *port = NULL; |
443 ParseConnectionString(&temp, &port, mgo.opt); |
443 ParseConnectionString(&temp, &port, mgo.opt); |
444 if (!StrEmpty(mgo.opt)) dedicated_host = mgo.opt; |
444 if (!StrEmpty(mgo.opt)) dedicated_host = mgo.opt; |
445 if (port != NULL) dedicated_port = atoi(port); |
445 if (port != NULL) dedicated_port = atoi(port); |
647 |
647 |
648 #ifdef ENABLE_NETWORK |
648 #ifdef ENABLE_NETWORK |
649 if (network && _network_available) { |
649 if (network && _network_available) { |
650 if (network_conn != NULL) { |
650 if (network_conn != NULL) { |
651 const char *port = NULL; |
651 const char *port = NULL; |
652 const char *player = NULL; |
652 const char *company = NULL; |
653 uint16 rport; |
653 uint16 rport; |
654 |
654 |
655 rport = NETWORK_DEFAULT_PORT; |
655 rport = NETWORK_DEFAULT_PORT; |
656 _network_playas = PLAYER_NEW_COMPANY; |
656 _network_playas = COMPANY_NEW_COMPANY; |
657 |
657 |
658 ParseConnectionString(&player, &port, network_conn); |
658 ParseConnectionString(&company, &port, network_conn); |
659 |
659 |
660 if (player != NULL) { |
660 if (company != NULL) { |
661 _network_playas = (PlayerID)atoi(player); |
661 _network_playas = (CompanyID)atoi(company); |
662 |
662 |
663 if (_network_playas != PLAYER_SPECTATOR) { |
663 if (_network_playas != COMPANY_SPECTATOR) { |
664 _network_playas--; |
664 _network_playas--; |
665 if (_network_playas >= MAX_PLAYERS) return false; |
665 if (_network_playas >= MAX_COMPANIES) return false; |
666 } |
666 } |
667 } |
667 } |
668 if (port != NULL) rport = atoi(port); |
668 if (port != NULL) rport = atoi(port); |
669 |
669 |
670 LoadIntroGame(); |
670 LoadIntroGame(); |
717 { |
717 { |
718 SettingsDisableElrail(_settings_game.vehicle.disable_elrails); |
718 SettingsDisableElrail(_settings_game.vehicle.disable_elrails); |
719 |
719 |
720 /* In a dedicated server, the server does not play */ |
720 /* In a dedicated server, the server does not play */ |
721 if (_network_dedicated) { |
721 if (_network_dedicated) { |
722 SetLocalPlayer(PLAYER_SPECTATOR); |
722 SetLocalCompany(COMPANY_SPECTATOR); |
723 return; |
723 return; |
724 } |
724 } |
725 |
725 |
726 /* Create a single player */ |
726 /* Create a single company */ |
727 DoStartupNewPlayer(false); |
727 DoStartupNewCompany(false); |
728 |
728 |
729 SetLocalPlayer(PLAYER_FIRST); |
729 SetLocalCompany(COMPANY_FIRST); |
730 _current_player = _local_player; |
730 _current_company = _local_company; |
731 DoCommandP(0, (_settings_client.gui.autorenew << 15 ) | (_settings_client.gui.autorenew_months << 16) | 4, _settings_client.gui.autorenew_money, NULL, CMD_SET_AUTOREPLACE); |
731 DoCommandP(0, (_settings_client.gui.autorenew << 15 ) | (_settings_client.gui.autorenew_months << 16) | 4, _settings_client.gui.autorenew_money, NULL, CMD_SET_AUTOREPLACE); |
732 |
732 |
733 InitializeRailGUI(); |
733 InitializeRailGUI(); |
734 |
734 |
735 #ifdef ENABLE_NETWORK |
735 #ifdef ENABLE_NETWORK |
736 /* We are the server, we start a new player (not dedicated), |
736 /* We are the server, we start a new company (not dedicated), |
737 * so set the default password *if* needed. */ |
737 * so set the default password *if* needed. */ |
738 if (_network_server && !StrEmpty(_settings_client.network.default_company_pass)) { |
738 if (_network_server && !StrEmpty(_settings_client.network.default_company_pass)) { |
739 char *password = _settings_client.network.default_company_pass; |
739 char *password = _settings_client.network.default_company_pass; |
740 NetworkChangeCompanyPassword(1, &password); |
740 NetworkChangeCompanyPassword(1, &password); |
741 } |
741 } |
757 GenerateWorld(from_heightmap ? GW_HEIGHTMAP : GW_NEWGAME, 1 << _settings_game.game_creation.map_x, 1 << _settings_game.game_creation.map_y); |
757 GenerateWorld(from_heightmap ? GW_HEIGHTMAP : GW_NEWGAME, 1 << _settings_game.game_creation.map_x, 1 << _settings_game.game_creation.map_y); |
758 } |
758 } |
759 |
759 |
760 static void MakeNewEditorWorldDone() |
760 static void MakeNewEditorWorldDone() |
761 { |
761 { |
762 SetLocalPlayer(OWNER_NONE); |
762 SetLocalCompany(OWNER_NONE); |
763 |
763 |
764 MarkWholeScreenDirty(); |
764 MarkWholeScreenDirty(); |
765 } |
765 } |
766 |
766 |
767 static void MakeNewEditorWorld() |
767 static void MakeNewEditorWorld() |
772 |
772 |
773 GenerateWorldSetCallback(&MakeNewEditorWorldDone); |
773 GenerateWorldSetCallback(&MakeNewEditorWorldDone); |
774 GenerateWorld(GW_EMPTY, 1 << _settings_game.game_creation.map_x, 1 << _settings_game.game_creation.map_y); |
774 GenerateWorld(GW_EMPTY, 1 << _settings_game.game_creation.map_x, 1 << _settings_game.game_creation.map_y); |
775 } |
775 } |
776 |
776 |
777 void StartupPlayers(); |
777 void StartupCompanies(); |
778 void StartupDisasters(); |
778 void StartupDisasters(); |
779 extern void StartupEconomy(); |
779 extern void StartupEconomy(); |
780 |
780 |
781 /** |
781 /** |
782 * Start Scenario starts a new game based on a scenario. |
782 * Start Scenario starts a new game based on a scenario. |
814 |
814 |
815 _settings_game.difficulty = _settings_newgame.difficulty; |
815 _settings_game.difficulty = _settings_newgame.difficulty; |
816 |
816 |
817 /* Inititalize data */ |
817 /* Inititalize data */ |
818 StartupEconomy(); |
818 StartupEconomy(); |
819 StartupPlayers(); |
819 StartupCompanies(); |
820 StartupEngines(); |
820 StartupEngines(); |
821 StartupDisasters(); |
821 StartupDisasters(); |
822 |
822 |
823 SetLocalPlayer(PLAYER_FIRST); |
823 SetLocalCompany(COMPANY_FIRST); |
824 _current_player = _local_player; |
824 _current_company = _local_company; |
825 DoCommandP(0, (_settings_client.gui.autorenew << 15 ) | (_settings_client.gui.autorenew_months << 16) | 4, _settings_client.gui.autorenew_money, NULL, CMD_SET_AUTOREPLACE); |
825 DoCommandP(0, (_settings_client.gui.autorenew << 15 ) | (_settings_client.gui.autorenew_months << 16) | 4, _settings_client.gui.autorenew_money, NULL, CMD_SET_AUTOREPLACE); |
826 |
826 |
827 MarkWholeScreenDirty(); |
827 MarkWholeScreenDirty(); |
828 } |
828 } |
829 |
829 |
925 ShowErrorMessage(INVALID_STRING_ID, STR_012D, 0, 0); |
925 ShowErrorMessage(INVALID_STRING_ID, STR_012D, 0, 0); |
926 } else { |
926 } else { |
927 if (_saveload_mode == SLD_LOAD_SCENARIO) { |
927 if (_saveload_mode == SLD_LOAD_SCENARIO) { |
928 StartupEngines(); |
928 StartupEngines(); |
929 } |
929 } |
930 /* Update the local player for a loaded game. It is either always |
930 /* Update the local company for a loaded game. It is either always |
931 * player #1 (eg 0) or in the case of a dedicated server a spectator */ |
931 * company #1 (eg 0) or in the case of a dedicated server a spectator */ |
932 SetLocalPlayer(_network_dedicated ? PLAYER_SPECTATOR : PLAYER_FIRST); |
932 SetLocalCompany(_network_dedicated ? COMPANY_SPECTATOR : COMPANY_FIRST); |
933 /* Decrease pause counter (was increased from opening load dialog) */ |
933 /* Decrease pause counter (was increased from opening load dialog) */ |
934 DoCommandP(0, 0, 0, NULL, CMD_PAUSE); |
934 DoCommandP(0, 0, 0, NULL, CMD_PAUSE); |
935 #ifdef ENABLE_NETWORK |
935 #ifdef ENABLE_NETWORK |
936 if (_network_server) { |
936 if (_network_server) { |
937 snprintf(_network_game_info.map_name, lengthof(_network_game_info.map_name), "%s (Loaded game)", _file_to_saveload.title); |
937 snprintf(_network_game_info.map_name, lengthof(_network_game_info.map_name), "%s (Loaded game)", _file_to_saveload.title); |
949 #endif /* ENABLE_NETWORK */ |
949 #endif /* ENABLE_NETWORK */ |
950 MakeNewGame(true); |
950 MakeNewGame(true); |
951 break; |
951 break; |
952 |
952 |
953 case SM_LOAD_HEIGHTMAP: /* Load heightmap from scenario editor */ |
953 case SM_LOAD_HEIGHTMAP: /* Load heightmap from scenario editor */ |
954 SetLocalPlayer(OWNER_NONE); |
954 SetLocalCompany(OWNER_NONE); |
955 |
955 |
956 GenerateWorld(GW_HEIGHTMAP, 1 << _settings_game.game_creation.map_x, 1 << _settings_game.game_creation.map_y); |
956 GenerateWorld(GW_HEIGHTMAP, 1 << _settings_game.game_creation.map_x, 1 << _settings_game.game_creation.map_y); |
957 MarkWholeScreenDirty(); |
957 MarkWholeScreenDirty(); |
958 break; |
958 break; |
959 |
959 |
960 case SM_LOAD_SCENARIO: { /* Load scenario from scenario editor */ |
960 case SM_LOAD_SCENARIO: { /* Load scenario from scenario editor */ |
961 if (SafeSaveOrLoad(_file_to_saveload.name, _file_to_saveload.mode, GM_EDITOR, NO_DIRECTORY)) { |
961 if (SafeSaveOrLoad(_file_to_saveload.name, _file_to_saveload.mode, GM_EDITOR, NO_DIRECTORY)) { |
962 SetLocalPlayer(OWNER_NONE); |
962 SetLocalCompany(OWNER_NONE); |
963 _settings_newgame.game_creation.starting_year = _cur_year; |
963 _settings_newgame.game_creation.starting_year = _cur_year; |
964 } else { |
964 } else { |
965 SetDParam(0, STR_JUST_RAW_STRING); |
965 SetDParam(0, STR_JUST_RAW_STRING); |
966 SetDParamStr(1, GetSaveLoadErrorString()); |
966 SetDParamStr(1, GetSaveLoadErrorString()); |
967 ShowErrorMessage(INVALID_STRING_ID, STR_012D, 0, 0); |
967 ShowErrorMessage(INVALID_STRING_ID, STR_012D, 0, 0); |
985 } |
985 } |
986 if (_networking && _pause_game == 2) _pause_game = 1; |
986 if (_networking && _pause_game == 2) _pause_game = 1; |
987 break; |
987 break; |
988 |
988 |
989 case SM_GENRANDLAND: /* Generate random land within scenario editor */ |
989 case SM_GENRANDLAND: /* Generate random land within scenario editor */ |
990 SetLocalPlayer(OWNER_NONE); |
990 SetLocalCompany(OWNER_NONE); |
991 GenerateWorld(GW_RANDOM, 1 << _settings_game.game_creation.map_x, 1 << _settings_game.game_creation.map_y); |
991 GenerateWorld(GW_RANDOM, 1 << _settings_game.game_creation.map_x, 1 << _settings_game.game_creation.map_y); |
992 /* XXX: set date */ |
992 /* XXX: set date */ |
993 MarkWholeScreenDirty(); |
993 MarkWholeScreenDirty(); |
994 break; |
994 break; |
995 } |
995 } |
1049 TrainConsistChanged(v, true); |
1049 TrainConsistChanged(v, true); |
1050 |
1050 |
1051 length = 0; |
1051 length = 0; |
1052 for (Vehicle *u = v; u != NULL; u = u->Next()) { |
1052 for (Vehicle *u = v; u != NULL; u = u->Next()) { |
1053 if (memcmp(&wagons[length], &u->u.rail, sizeof(VehicleRail)) != 0) { |
1053 if (memcmp(&wagons[length], &u->u.rail, sizeof(VehicleRail)) != 0) { |
1054 printf("cache mismatch: vehicle %i, player %i, unit number %i, wagon %i\n", v->index, (int)v->owner, v->unitnumber, length); |
1054 printf("cache mismatch: vehicle %i, company %i, unit number %i, wagon %i\n", v->index, (int)v->owner, v->unitnumber, length); |
1055 } |
1055 } |
1056 length++; |
1056 length++; |
1057 } |
1057 } |
1058 |
1058 |
1059 free(wagons); |
1059 free(wagons); |
1061 |
1061 |
1062 case VEH_AIRCRAFT: { |
1062 case VEH_AIRCRAFT: { |
1063 uint speed = v->u.air.cached_max_speed; |
1063 uint speed = v->u.air.cached_max_speed; |
1064 UpdateAircraftCache(v); |
1064 UpdateAircraftCache(v); |
1065 if (speed != v->u.air.cached_max_speed) { |
1065 if (speed != v->u.air.cached_max_speed) { |
1066 printf("cache mismatch: vehicle %i, player %i, unit number %i\n", v->index, (int)v->owner, v->unitnumber); |
1066 printf("cache mismatch: vehicle %i, company %i, unit number %i\n", v->index, (int)v->owner, v->unitnumber); |
1067 } |
1067 } |
1068 } break; |
1068 } break; |
1069 |
1069 |
1070 default: |
1070 default: |
1071 break; |
1071 break; |
1102 #if defined(PSP) |
1102 #if defined(PSP) |
1103 /* Autosaving in networking is too time expensive for the PSP */ |
1103 /* Autosaving in networking is too time expensive for the PSP */ |
1104 if (_networking) return; |
1104 if (_networking) return; |
1105 #endif /* PSP */ |
1105 #endif /* PSP */ |
1106 |
1106 |
1107 if (_settings_client.gui.keep_all_autosave && _local_player != PLAYER_SPECTATOR) { |
1107 if (_settings_client.gui.keep_all_autosave && _local_company != COMPANY_SPECTATOR) { |
1108 SetDParam(0, _local_player); |
1108 SetDParam(0, _local_company); |
1109 SetDParam(1, _date); |
1109 SetDParam(1, _date); |
1110 GetString(buf, STR_4004, lastof(buf)); |
1110 GetString(buf, STR_4004, lastof(buf)); |
1111 ttd_strlcat(buf, ".sav", lengthof(buf)); |
1111 ttd_strlcat(buf, ".sav", lengthof(buf)); |
1112 } else { |
1112 } else { |
1113 /* generate a savegame name and number according to _settings_client.gui.max_num_autosaves */ |
1113 /* generate a savegame name and number according to _settings_client.gui.max_num_autosaves */ |
1201 static void UpdateExclusiveRights() |
1201 static void UpdateExclusiveRights() |
1202 { |
1202 { |
1203 Town *t; |
1203 Town *t; |
1204 |
1204 |
1205 FOR_ALL_TOWNS(t) { |
1205 FOR_ALL_TOWNS(t) { |
1206 t->exclusivity = INVALID_PLAYER; |
1206 t->exclusivity = INVALID_COMPANY; |
1207 } |
1207 } |
1208 |
1208 |
1209 /* FIXME old exclusive rights status is not being imported (stored in s->blocked_months_obsolete) |
1209 /* FIXME old exclusive rights status is not being imported (stored in s->blocked_months_obsolete) |
1210 * could be implemented this way: |
1210 * could be implemented this way: |
1211 * 1.) Go through all stations |
1211 * 1.) Go through all stations |
1212 * Build an array town_blocked[ town_id ][ player_id ] |
1212 * Build an array town_blocked[ town_id ][ company_id ] |
1213 * that stores if at least one station in that town is blocked for a player |
1213 * that stores if at least one station in that town is blocked for a company |
1214 * 2.) Go through that array, if you find a town that is not blocked for |
1214 * 2.) Go through that array, if you find a town that is not blocked for |
1215 * one player, but for all others, then give him exclusivity. |
1215 * one company, but for all others, then give him exclusivity. |
1216 */ |
1216 */ |
1217 } |
1217 } |
1218 |
1218 |
1219 static const byte convert_currency[] = { |
1219 static const byte convert_currency[] = { |
1220 0, 1, 12, 8, 3, |
1220 0, 1, 12, 8, 3, |
1280 UpdateAllStationVirtCoord(); |
1280 UpdateAllStationVirtCoord(); |
1281 UpdateAllSignVirtCoords(); |
1281 UpdateAllSignVirtCoords(); |
1282 UpdateAllTownVirtCoords(); |
1282 UpdateAllTownVirtCoords(); |
1283 UpdateAllWaypointSigns(); |
1283 UpdateAllWaypointSigns(); |
1284 |
1284 |
1285 Player *p; |
1285 Company *c; |
1286 FOR_ALL_PLAYERS(p) { |
1286 FOR_ALL_COMPANIES(c) { |
1287 /* For each player, verify (while loading a scenario) that the inauguration date is the current year and set it |
1287 /* For each company, verify (while loading a scenario) that the inauguration date is the current year and set it |
1288 * accordingly if it is not the case. No need to set it on players that are not been used already, |
1288 * accordingly if it is not the case. No need to set it on companies that are not been used already, |
1289 * thus the MIN_YEAR (which is really nothing more than Zero, initialized value) test */ |
1289 * thus the MIN_YEAR (which is really nothing more than Zero, initialized value) test */ |
1290 if (_file_to_saveload.filetype == FT_SCENARIO && p->inaugurated_year != MIN_YEAR) { |
1290 if (_file_to_saveload.filetype == FT_SCENARIO && c->inaugurated_year != MIN_YEAR) { |
1291 p->inaugurated_year = _cur_year; |
1291 c->inaugurated_year = _cur_year; |
1292 } |
1292 } |
1293 } |
1293 } |
1294 |
1294 |
1295 SetCachedEngineCounts(); |
1295 SetCachedEngineCounts(); |
1296 |
1296 |
1332 * OWNER_NONE, not OWNER_WATER.. I can't replicate it for the current |
1332 * OWNER_NONE, not OWNER_WATER.. I can't replicate it for the current |
1333 * (4.3) version, so I just check when versions are older, and then |
1333 * (4.3) version, so I just check when versions are older, and then |
1334 * walk through the whole map.. */ |
1334 * walk through the whole map.. */ |
1335 if (CheckSavegameVersionOldStyle(4, 3)) { |
1335 if (CheckSavegameVersionOldStyle(4, 3)) { |
1336 for (TileIndex t = 0; t < map_size; t++) { |
1336 for (TileIndex t = 0; t < map_size; t++) { |
1337 if (IsTileType(t, MP_WATER) && GetTileOwner(t) >= MAX_PLAYERS) { |
1337 if (IsTileType(t, MP_WATER) && GetTileOwner(t) >= MAX_COMPANIES) { |
1338 SetTileOwner(t, OWNER_WATER); |
1338 SetTileOwner(t, OWNER_WATER); |
1339 } |
1339 } |
1340 } |
1340 } |
1341 } |
1341 } |
1342 |
1342 |
1343 if (CheckSavegameVersion(84)) { |
1343 if (CheckSavegameVersion(84)) { |
1344 Player *p; |
1344 FOR_ALL_COMPANIES(c) { |
1345 FOR_ALL_PLAYERS(p) { |
1345 c->name = CopyFromOldName(c->name_1); |
1346 p->name = CopyFromOldName(p->name_1); |
1346 if (c->name != NULL) c->name_1 = STR_SV_UNNAMED; |
1347 if (p->name != NULL) p->name_1 = STR_SV_UNNAMED; |
1347 c->president_name = CopyFromOldName(c->president_name_1); |
1348 p->president_name = CopyFromOldName(p->president_name_1); |
1348 if (c->president_name != NULL) c->president_name_1 = SPECSTR_PRESIDENT_NAME; |
1349 if (p->president_name != NULL) p->president_name_1 = SPECSTR_PRESIDENT_NAME; |
|
1350 } |
1349 } |
1351 |
1350 |
1352 Station *st; |
1351 Station *st; |
1353 FOR_ALL_STATIONS(st) { |
1352 FOR_ALL_STATIONS(st) { |
1354 st->name = CopyFromOldName(st->string_id); |
1353 st->name = CopyFromOldName(st->string_id); |
1367 wp->name = CopyFromOldName(wp->string); |
1366 wp->name = CopyFromOldName(wp->string); |
1368 wp->string = STR_EMPTY; |
1367 wp->string = STR_EMPTY; |
1369 } |
1368 } |
1370 |
1369 |
1371 for (uint i = 0; i < GetSignPoolSize(); i++) { |
1370 for (uint i = 0; i < GetSignPoolSize(); i++) { |
1372 /* invalid signs are determined by si->ower == INVALID_PLAYER now */ |
1371 /* invalid signs are determined by si->ower == INVALID_COMPANY now */ |
1373 Sign *si = GetSign(i); |
1372 Sign *si = GetSign(i); |
1374 if (!si->IsValid() && si->name != NULL) { |
1373 if (!si->IsValid() && si->name != NULL) { |
1375 si->owner = OWNER_NONE; |
1374 si->owner = OWNER_NONE; |
1376 } |
1375 } |
1377 } |
1376 } |
1442 * savegame and saving again, the buggy map array could be converted to new savegame |
1441 * savegame and saving again, the buggy map array could be converted to new savegame |
1443 * version. It didn't show up before r12070. */ |
1442 * version. It didn't show up before r12070. */ |
1444 if (CheckSavegameVersion(87)) UpdateVoidTiles(); |
1443 if (CheckSavegameVersion(87)) UpdateVoidTiles(); |
1445 |
1444 |
1446 /* If Load Scenario / New (Scenario) Game is used, |
1445 /* If Load Scenario / New (Scenario) Game is used, |
1447 * a player does not exist yet. So create one here. |
1446 * a company does not exist yet. So create one here. |
1448 * 1 exeption: network-games. Those can have 0 players |
1447 * 1 exeption: network-games. Those can have 0 companies |
1449 * But this exeption is not true for non dedicated network_servers! */ |
1448 * But this exeption is not true for non dedicated network_servers! */ |
1450 if (!IsValidPlayerID(PLAYER_FIRST) && (!_networking || (_networking && _network_server && !_network_dedicated))) |
1449 if (!IsValidCompanyID(COMPANY_FIRST) && (!_networking || (_networking && _network_server && !_network_dedicated))) |
1451 DoStartupNewPlayer(false); |
1450 DoStartupNewCompany(false); |
1452 |
1451 |
1453 if (CheckSavegameVersion(72)) { |
1452 if (CheckSavegameVersion(72)) { |
1454 /* Locks/shiplifts in very old savegames had OWNER_WATER as owner */ |
1453 /* Locks/shiplifts in very old savegames had OWNER_WATER as owner */ |
1455 for (TileIndex t = 0; t < MapSize(); t++) { |
1454 for (TileIndex t = 0; t < MapSize(); t++) { |
1456 switch (GetTileType(t)) { |
1455 switch (GetTileType(t)) { |
1587 } |
1586 } |
1588 |
1587 |
1589 /* From version 16.0, we included autorenew on engines, which are now saved, but |
1588 /* From version 16.0, we included autorenew on engines, which are now saved, but |
1590 * of course, we do need to initialize them for older savegames. */ |
1589 * of course, we do need to initialize them for older savegames. */ |
1591 if (CheckSavegameVersion(16)) { |
1590 if (CheckSavegameVersion(16)) { |
1592 FOR_ALL_PLAYERS(p) { |
1591 FOR_ALL_COMPANIES(c) { |
1593 p->engine_renew_list = NULL; |
1592 c->engine_renew_list = NULL; |
1594 p->engine_renew = false; |
1593 c->engine_renew = false; |
1595 p->engine_renew_months = -6; |
1594 c->engine_renew_months = -6; |
1596 p->engine_renew_money = 100000; |
1595 c->engine_renew_money = 100000; |
1597 } |
1596 } |
1598 |
1597 |
1599 /* When loading a game, _local_player is not yet set to the correct value. |
1598 /* When loading a game, _local_company is not yet set to the correct value. |
1600 * However, in a dedicated server we are a spectator, so nothing needs to |
1599 * However, in a dedicated server we are a spectator, so nothing needs to |
1601 * happen. In case we are not a dedicated server, the local player always |
1600 * happen. In case we are not a dedicated server, the local company always |
1602 * becomes player 0, unless we are in the scenario editor where all the |
1601 * becomes company 0, unless we are in the scenario editor where all the |
1603 * players are 'invalid'. |
1602 * companies are 'invalid'. |
1604 */ |
1603 */ |
1605 if (!_network_dedicated && IsValidPlayerID(PLAYER_FIRST)) { |
1604 if (!_network_dedicated && IsValidCompanyID(COMPANY_FIRST)) { |
1606 p = GetPlayer(PLAYER_FIRST); |
1605 c = GetCompany(COMPANY_FIRST); |
1607 p->engine_renew = _settings_client.gui.autorenew; |
1606 c->engine_renew = _settings_client.gui.autorenew; |
1608 p->engine_renew_months = _settings_client.gui.autorenew_months; |
1607 c->engine_renew_months = _settings_client.gui.autorenew_months; |
1609 p->engine_renew_money = _settings_client.gui.autorenew_money; |
1608 c->engine_renew_money = _settings_client.gui.autorenew_money; |
1610 } |
1609 } |
1611 } |
1610 } |
1612 |
1611 |
1613 if (CheckSavegameVersion(48)) { |
1612 if (CheckSavegameVersion(48)) { |
1614 for (TileIndex t = 0; t < map_size; t++) { |
1613 for (TileIndex t = 0; t < map_size; t++) { |
1806 if (v->type == VEH_TRAIN && (IsFrontEngine(v) || IsFreeWagon(v))) TrainConsistChanged(v, true); |
1805 if (v->type == VEH_TRAIN && (IsFrontEngine(v) || IsFreeWagon(v))) TrainConsistChanged(v, true); |
1807 } |
1806 } |
1808 |
1807 |
1809 } |
1808 } |
1810 |
1809 |
1811 /* In version 16.1 of the savegame a player can decide if trains, which get |
1810 /* In version 16.1 of the savegame a company can decide if trains, which get |
1812 * replaced, shall keep their old length. In all prior versions, just default |
1811 * replaced, shall keep their old length. In all prior versions, just default |
1813 * to false */ |
1812 * to false */ |
1814 if (CheckSavegameVersionOldStyle(16, 1)) { |
1813 if (CheckSavegameVersionOldStyle(16, 1)) { |
1815 FOR_ALL_PLAYERS(p) p->renew_keep_length = false; |
1814 FOR_ALL_COMPANIES(c) c->renew_keep_length = false; |
1816 } |
1815 } |
1817 |
1816 |
1818 /* In version 17, ground type is moved from m2 to m4 for depots and |
1817 /* In version 17, ground type is moved from m2 to m4 for depots and |
1819 * waypoints to make way for storing the index in m2. The custom graphics |
1818 * waypoints to make way for storing the index in m2. The custom graphics |
1820 * id which was stored in m4 is now saved as a grf/id reference in the |
1819 * id which was stored in m4 is now saved as a grf/id reference in the |
1911 } |
1910 } |
1912 } |
1911 } |
1913 |
1912 |
1914 YapfNotifyTrackLayoutChange(INVALID_TILE, INVALID_TRACK); |
1913 YapfNotifyTrackLayoutChange(INVALID_TILE, INVALID_TRACK); |
1915 |
1914 |
1916 if (CheckSavegameVersion(34)) FOR_ALL_PLAYERS(p) ResetPlayerLivery(p); |
1915 if (CheckSavegameVersion(34)) FOR_ALL_COMPANIES(c) ResetCompanyLivery(c); |
1917 |
1916 |
1918 FOR_ALL_PLAYERS(p) { |
1917 FOR_ALL_COMPANIES(c) { |
1919 p->avail_railtypes = GetPlayerRailtypes(p->index); |
1918 c->avail_railtypes = GetCompanyRailtypes(c->index); |
1920 p->avail_roadtypes = GetPlayerRoadtypes(p->index); |
1919 c->avail_roadtypes = GetCompanyRoadtypes(c->index); |
1921 } |
1920 } |
1922 |
1921 |
1923 if (!CheckSavegameVersion(27)) AfterLoadStations(); |
1922 if (!CheckSavegameVersion(27)) AfterLoadStations(); |
1924 |
1923 |
1925 /* Time starts at 0 instead of 1920. |
1924 /* Time starts at 0 instead of 1920. |
1926 * Account for this in older games by adding an offset */ |
1925 * Account for this in older games by adding an offset */ |
1927 if (CheckSavegameVersion(31)) { |
1926 if (CheckSavegameVersion(31)) { |
1928 Station *st; |
1927 Station *st; |
1929 Waypoint *wp; |
1928 Waypoint *wp; |
1930 Engine *e; |
1929 Engine *e; |
1931 Player *player; |
|
1932 Industry *i; |
1930 Industry *i; |
1933 Vehicle *v; |
1931 Vehicle *v; |
1934 |
1932 |
1935 _date += DAYS_TILL_ORIGINAL_BASE_YEAR; |
1933 _date += DAYS_TILL_ORIGINAL_BASE_YEAR; |
1936 _cur_year += ORIGINAL_BASE_YEAR; |
1934 _cur_year += ORIGINAL_BASE_YEAR; |
1937 |
1935 |
1938 FOR_ALL_STATIONS(st) st->build_date += DAYS_TILL_ORIGINAL_BASE_YEAR; |
1936 FOR_ALL_STATIONS(st) st->build_date += DAYS_TILL_ORIGINAL_BASE_YEAR; |
1939 FOR_ALL_WAYPOINTS(wp) wp->build_date += DAYS_TILL_ORIGINAL_BASE_YEAR; |
1937 FOR_ALL_WAYPOINTS(wp) wp->build_date += DAYS_TILL_ORIGINAL_BASE_YEAR; |
1940 FOR_ALL_ENGINES(e) e->intro_date += DAYS_TILL_ORIGINAL_BASE_YEAR; |
1938 FOR_ALL_ENGINES(e) e->intro_date += DAYS_TILL_ORIGINAL_BASE_YEAR; |
1941 FOR_ALL_PLAYERS(player) player->inaugurated_year += ORIGINAL_BASE_YEAR; |
1939 FOR_ALL_COMPANIES(c) c->inaugurated_year += ORIGINAL_BASE_YEAR; |
1942 FOR_ALL_INDUSTRIES(i) i->last_prod_year += ORIGINAL_BASE_YEAR; |
1940 FOR_ALL_INDUSTRIES(i) i->last_prod_year += ORIGINAL_BASE_YEAR; |
1943 |
1941 |
1944 FOR_ALL_VEHICLES(v) { |
1942 FOR_ALL_VEHICLES(v) { |
1945 v->date_of_last_service += DAYS_TILL_ORIGINAL_BASE_YEAR; |
1943 v->date_of_last_service += DAYS_TILL_ORIGINAL_BASE_YEAR; |
1946 v->build_year += ORIGINAL_BASE_YEAR; |
1944 v->build_year += ORIGINAL_BASE_YEAR; |
1947 } |
1945 } |
2137 v->acceleration = avi->acceleration; |
2135 v->acceleration = avi->acceleration; |
2138 } |
2136 } |
2139 } |
2137 } |
2140 } |
2138 } |
2141 |
2139 |
2142 if (CheckSavegameVersion(49)) FOR_ALL_PLAYERS(p) p->face = ConvertFromOldPlayerFace(p->face); |
2140 if (CheckSavegameVersion(49)) FOR_ALL_COMPANIES(c) c->face = ConvertFromOldCompanyManagerFace(c->face); |
2143 |
2141 |
2144 if (CheckSavegameVersion(52)) { |
2142 if (CheckSavegameVersion(52)) { |
2145 for (TileIndex t = 0; t < map_size; t++) { |
2143 for (TileIndex t = 0; t < map_size; t++) { |
2146 if (IsStatueTile(t)) { |
2144 if (IsStatueTile(t)) { |
2147 _m[t].m2 = CalcClosestTownFromTile(t, (uint)-1)->index; |
2145 _m[t].m2 = CalcClosestTownFromTile(t, (uint)-1)->index; |
2335 order->SetLoadType(OLF_LOAD_IF_POSSIBLE); |
2333 order->SetLoadType(OLF_LOAD_IF_POSSIBLE); |
2336 order->SetUnloadType(OUF_UNLOAD_IF_POSSIBLE); |
2334 order->SetUnloadType(OUF_UNLOAD_IF_POSSIBLE); |
2337 } |
2335 } |
2338 } |
2336 } |
2339 |
2337 |
2340 /* Set all share owners to PLAYER_SPECTATOR for |
2338 /* Set all share owners to INVALID_COMPANY for |
2341 * 1) all inactive players |
2339 * 1) all inactive companies |
2342 * (when inactive players were stored in the savegame - TTD, TTDP and some |
2340 * (when inactive companies were stored in the savegame - TTD, TTDP and some |
2343 * *really* old revisions of OTTD; else it is already set in InitializePlayers()) |
2341 * *really* old revisions of OTTD; else it is already set in InitializeCompanies()) |
2344 * 2) shares that are owned by inactive players or self |
2342 * 2) shares that are owned by inactive companies or self |
2345 * (caused by cheating players in earlier revisions) */ |
2343 * (caused by cheating clients in earlier revisions) */ |
2346 Player *p; |
2344 FOR_ALL_COMPANIES(c) { |
2347 FOR_ALL_PLAYERS(p) { |
|
2348 for (uint i = 0; i < 4; i++) { |
2345 for (uint i = 0; i < 4; i++) { |
2349 PlayerID o = p->share_owners[i]; |
2346 CompanyID company = c->share_owners[i]; |
2350 if (o == PLAYER_SPECTATOR) continue; |
2347 if (company == INVALID_COMPANY) continue; |
2351 if (!IsValidPlayerID(o) || o == p->index) p->share_owners[i] = PLAYER_SPECTATOR; |
2348 if (!IsValidCompanyID(company) || company == c->index) c->share_owners[i] = INVALID_COMPANY; |
2352 } |
2349 } |
2353 } |
2350 } |
2354 } |
2351 } |
2355 |
2352 |
2356 if (CheckSavegameVersion(86)) { |
2353 if (CheckSavegameVersion(86)) { |
2394 SetWaterClass(t, WATER_CLASS_SEA); |
2391 SetWaterClass(t, WATER_CLASS_SEA); |
2395 } |
2392 } |
2396 |
2393 |
2397 if (IsBuoyTile(t) || IsDriveThroughStopTile(t) || IsTileType(t, MP_WATER)) { |
2394 if (IsBuoyTile(t) || IsDriveThroughStopTile(t) || IsTileType(t, MP_WATER)) { |
2398 Owner o = GetTileOwner(t); |
2395 Owner o = GetTileOwner(t); |
2399 if (o < MAX_PLAYERS && !IsValidPlayerID(o)) { |
2396 if (o < MAX_COMPANIES && !IsValidCompanyID(o)) { |
2400 _current_player = o; |
2397 _current_company = o; |
2401 ChangeTileOwner(t, o, PLAYER_SPECTATOR); |
2398 ChangeTileOwner(t, o, INVALID_OWNER); |
2402 } |
2399 } |
2403 if (IsBuoyTile(t)) { |
2400 if (IsBuoyTile(t)) { |
2404 /* reset buoy owner to OWNER_NONE in the station struct |
2401 /* reset buoy owner to OWNER_NONE in the station struct |
2405 * (even if it is owned by active player) */ |
2402 * (even if it is owned by active company) */ |
2406 GetStationByTile(t)->owner = OWNER_NONE; |
2403 GetStationByTile(t)->owner = OWNER_NONE; |
2407 } |
2404 } |
2408 } else if (IsTileType(t, MP_ROAD)) { |
2405 } else if (IsTileType(t, MP_ROAD)) { |
2409 /* works for all RoadTileType */ |
2406 /* works for all RoadTileType */ |
2410 for (RoadType rt = ROADTYPE_ROAD; rt < ROADTYPE_END; rt++) { |
2407 for (RoadType rt = ROADTYPE_ROAD; rt < ROADTYPE_END; rt++) { |
2411 /* update even non-existing road types to update tile owner too */ |
2408 /* update even non-existing road types to update tile owner too */ |
2412 Owner o = GetRoadOwner(t, rt); |
2409 Owner o = GetRoadOwner(t, rt); |
2413 if (o < MAX_PLAYERS && !IsValidPlayerID(o)) SetRoadOwner(t, rt, OWNER_NONE); |
2410 if (o < MAX_COMPANIES && !IsValidCompanyID(o)) SetRoadOwner(t, rt, OWNER_NONE); |
2414 } |
2411 } |
2415 if (IsLevelCrossing(t)) { |
2412 if (IsLevelCrossing(t)) { |
2416 Owner o = GetTileOwner(t); |
2413 Owner o = GetTileOwner(t); |
2417 if (!IsValidPlayerID(o)) { |
2414 if (!IsValidCompanyID(o)) { |
2418 /* remove leftover rail piece from crossing (from very old savegames) */ |
2415 /* remove leftover rail piece from crossing (from very old savegames) */ |
2419 _current_player = o; |
2416 _current_company = o; |
2420 DoCommand(t, 0, GetCrossingRailTrack(t), DC_EXEC | DC_BANKRUPT, CMD_REMOVE_SINGLE_RAIL); |
2417 DoCommand(t, 0, GetCrossingRailTrack(t), DC_EXEC | DC_BANKRUPT, CMD_REMOVE_SINGLE_RAIL); |
2421 } |
2418 } |
2422 } |
2419 } |
2423 } |
2420 } |
2424 } |
2421 } |
2549 /* Give owners to waypoints, based on rail tracks it is sitting on. |
2546 /* Give owners to waypoints, based on rail tracks it is sitting on. |
2550 * If none is available, specify OWNER_NONE */ |
2547 * If none is available, specify OWNER_NONE */ |
2551 Waypoint *wp; |
2548 Waypoint *wp; |
2552 FOR_ALL_WAYPOINTS(wp) { |
2549 FOR_ALL_WAYPOINTS(wp) { |
2553 Owner owner = (IsRailWaypointTile(wp->xy) ? GetTileOwner(wp->xy) : OWNER_NONE); |
2550 Owner owner = (IsRailWaypointTile(wp->xy) ? GetTileOwner(wp->xy) : OWNER_NONE); |
2554 wp->owner = IsValidPlayerID(owner) ? owner : OWNER_NONE; |
2551 wp->owner = IsValidCompanyID(owner) ? owner : OWNER_NONE; |
2555 } |
2552 } |
2556 } |
2553 } |
2557 |
2554 |
2558 if (CheckSavegameVersion(102)) { |
2555 if (CheckSavegameVersion(102)) { |
2559 for (TileIndex t = 0; t < map_size; t++) { |
2556 for (TileIndex t = 0; t < map_size; t++) { |
2596 AfterLoadWaypoints(); |
2593 AfterLoadWaypoints(); |
2597 AfterLoadStations(); |
2594 AfterLoadStations(); |
2598 /* Check and update house and town values */ |
2595 /* Check and update house and town values */ |
2599 UpdateHousesAndTowns(); |
2596 UpdateHousesAndTowns(); |
2600 /* Update livery selection windows */ |
2597 /* Update livery selection windows */ |
2601 for (PlayerID i = PLAYER_FIRST; i < MAX_PLAYERS; i++) InvalidateWindowData(WC_PLAYER_COLOR, i, _loaded_newgrf_features.has_2CC); |
2598 for (CompanyID i = COMPANY_FIRST; i < MAX_COMPANIES; i++) InvalidateWindowData(WC_COMPANY_COLOR, i, _loaded_newgrf_features.has_2CC); |
2602 /* redraw the whole screen */ |
2599 /* redraw the whole screen */ |
2603 MarkWholeScreenDirty(); |
2600 MarkWholeScreenDirty(); |
2604 CheckTrainsLengths(); |
2601 CheckTrainsLengths(); |
2605 } |
2602 } |