62 #include "clear_map.h" |
62 #include "clear_map.h" |
63 #include "rail_map.h" |
63 #include "rail_map.h" |
64 #include "road_map.h" |
64 #include "road_map.h" |
65 #include "water_map.h" |
65 #include "water_map.h" |
66 #include "industry_map.h" |
66 #include "industry_map.h" |
|
67 #include "unmovable_map.h" |
67 |
68 |
68 #include <stdarg.h> |
69 #include <stdarg.h> |
69 |
70 |
70 void CallLandscapeTick(void); |
71 void CallLandscapeTick(); |
71 void IncreaseDate(void); |
72 void IncreaseDate(); |
72 void DoPaletteAnimations(void); |
73 void DoPaletteAnimations(); |
73 void MusicLoop(void); |
74 void MusicLoop(); |
74 void ResetMusic(void); |
75 void ResetMusic(); |
75 |
76 |
76 extern void SetDifficultyLevel(int mode, GameOptions *gm_opt); |
77 extern void SetDifficultyLevel(int mode, GameOptions *gm_opt); |
77 extern Player* DoStartupNewPlayer(bool is_ai); |
78 extern Player* DoStartupNewPlayer(bool is_ai); |
78 extern void ShowOSErrorBox(const char *buf); |
79 extern void ShowOSErrorBox(const char *buf); |
79 |
80 |
263 |
264 |
264 res[0] = clamp(strtoul(s, NULL, 0), 64, MAX_SCREEN_WIDTH); |
265 res[0] = clamp(strtoul(s, NULL, 0), 64, MAX_SCREEN_WIDTH); |
265 res[1] = clamp(strtoul(t + 1, NULL, 0), 64, MAX_SCREEN_HEIGHT); |
266 res[1] = clamp(strtoul(t + 1, NULL, 0), 64, MAX_SCREEN_HEIGHT); |
266 } |
267 } |
267 |
268 |
268 static void InitializeDynamicVariables(void) |
269 static void InitializeDynamicVariables() |
269 { |
270 { |
270 /* Dynamic stuff needs to be initialized somewhere... */ |
271 /* Dynamic stuff needs to be initialized somewhere... */ |
271 _town_sort = NULL; |
272 _town_sort = NULL; |
272 _industry_sort = NULL; |
273 _industry_sort = NULL; |
273 } |
274 } |
274 |
275 |
275 |
276 |
276 static void UnInitializeGame(void) |
277 static void UnInitializeGame() |
277 { |
278 { |
278 UnInitWindowSystem(); |
279 UnInitWindowSystem(); |
279 |
280 |
280 /* Uninitialize airport state machines */ |
281 /* Uninitialize airport state machines */ |
281 UnInitializeAirports(); |
282 UnInitializeAirports(); |
317 if (SaveOrLoad(filename, SL_LOAD) != SL_OK) { |
318 if (SaveOrLoad(filename, SL_LOAD) != SL_OK) { |
318 GenerateWorld(GW_EMPTY, 64, 64); // if failed loading, make empty world. |
319 GenerateWorld(GW_EMPTY, 64, 64); // if failed loading, make empty world. |
319 WaitTillGeneratedWorld(); |
320 WaitTillGeneratedWorld(); |
320 } |
321 } |
321 |
322 |
322 _pause = 0; |
323 _pause_game = 0; |
323 SetLocalPlayer(PLAYER_FIRST); |
324 SetLocalPlayer(PLAYER_FIRST); |
324 /* Make sure you can't scroll in the menu */ |
325 /* Make sure you can't scroll in the menu */ |
325 _scrolling_viewport = 0; |
326 _scrolling_viewport = 0; |
326 _cursor.fix_at = false; |
327 _cursor.fix_at = false; |
327 MarkWholeScreenDirty(); |
328 MarkWholeScreenDirty(); |
416 if (mgo.opt != NULL) { |
417 if (mgo.opt != NULL) { |
417 strcpy(_file_to_saveload.name, mgo.opt); |
418 strcpy(_file_to_saveload.name, mgo.opt); |
418 _switch_mode = SM_LOAD; |
419 _switch_mode = SM_LOAD; |
419 } else { |
420 } else { |
420 _switch_mode = SM_NEWGAME; |
421 _switch_mode = SM_NEWGAME; |
|
422 /* Give a random map */ |
|
423 generation_seed = InteractiveRandom(); |
421 } |
424 } |
422 break; |
425 break; |
423 case 'G': generation_seed = atoi(mgo.opt); break; |
426 case 'G': generation_seed = atoi(mgo.opt); break; |
424 case 'c': _config_file = strdup(mgo.opt); break; |
427 case 'c': _config_file = strdup(mgo.opt); break; |
425 case 'x': save_config = false; break; |
428 case 'x': save_config = false; break; |
428 showhelp(); |
431 showhelp(); |
429 return 0; |
432 return 0; |
430 } |
433 } |
431 } |
434 } |
432 |
435 |
433 DeterminePaths(); |
436 DeterminePaths(argv[0]); |
434 CheckExternalFiles(); |
437 CheckExternalFiles(); |
435 |
438 |
436 #if defined(UNIX) && !defined(__MORPHOS__) |
439 #if defined(UNIX) && !defined(__MORPHOS__) |
437 // We must fork here, or we'll end up without some resources we need (like sockets) |
440 // We must fork here, or we'll end up without some resources we need (like sockets) |
438 if (_dedicated_forks) |
441 if (_dedicated_forks) |
608 |
611 |
609 /** Mutex so that only one thread can communicate with the main program |
612 /** Mutex so that only one thread can communicate with the main program |
610 * at any given time */ |
613 * at any given time */ |
611 static ThreadMsg _message = MSG_OTTD_NO_MESSAGE; |
614 static ThreadMsg _message = MSG_OTTD_NO_MESSAGE; |
612 |
615 |
613 static inline void OTTD_ReleaseMutex(void) {_message = MSG_OTTD_NO_MESSAGE;} |
616 static inline void OTTD_ReleaseMutex() {_message = MSG_OTTD_NO_MESSAGE;} |
614 static inline ThreadMsg OTTD_PollThreadEvent(void) {return _message;} |
617 static inline ThreadMsg OTTD_PollThreadEvent() {return _message;} |
615 |
618 |
616 /** Called by running thread to execute some action in the main game. |
619 /** Called by running thread to execute some action in the main game. |
617 * It will stall as long as the mutex is not freed (handled) by the game */ |
620 * It will stall as long as the mutex is not freed (handled) by the game */ |
618 void OTTD_SendThreadMessage(ThreadMsg msg) |
621 void OTTD_SendThreadMessage(ThreadMsg msg) |
619 { |
622 { |
647 ShowErrorMessage(INVALID_STRING_ID, STR_031C_SCREENSHOT_FAILED, 0, 0); |
650 ShowErrorMessage(INVALID_STRING_ID, STR_031C_SCREENSHOT_FAILED, 0, 0); |
648 } |
651 } |
649 |
652 |
650 } |
653 } |
651 |
654 |
652 static void MakeNewGameDone(void) |
655 static void MakeNewGameDone() |
653 { |
656 { |
654 /* In a dedicated server, the server does not play */ |
657 /* In a dedicated server, the server does not play */ |
655 if (_network_dedicated) { |
658 if (_network_dedicated) { |
656 SetLocalPlayer(PLAYER_SPECTATOR); |
659 SetLocalPlayer(PLAYER_SPECTATOR); |
657 return; |
660 return; |
677 |
680 |
678 GenerateWorldSetCallback(&MakeNewGameDone); |
681 GenerateWorldSetCallback(&MakeNewGameDone); |
679 GenerateWorld(from_heightmap ? GW_HEIGHTMAP : GW_NEWGAME, 1 << _patches.map_x, 1 << _patches.map_y); |
682 GenerateWorld(from_heightmap ? GW_HEIGHTMAP : GW_NEWGAME, 1 << _patches.map_x, 1 << _patches.map_y); |
680 } |
683 } |
681 |
684 |
682 static void MakeNewEditorWorldDone(void) |
685 static void MakeNewEditorWorldDone() |
683 { |
686 { |
684 SetLocalPlayer(OWNER_NONE); |
687 SetLocalPlayer(OWNER_NONE); |
685 |
688 |
686 MarkWholeScreenDirty(); |
689 MarkWholeScreenDirty(); |
687 } |
690 } |
688 |
691 |
689 static void MakeNewEditorWorld(void) |
692 static void MakeNewEditorWorld() |
690 { |
693 { |
691 _game_mode = GM_EDITOR; |
694 _game_mode = GM_EDITOR; |
692 |
695 |
693 ResetGRFConfig(true); |
696 ResetGRFConfig(true); |
694 |
697 |
695 GenerateWorldSetCallback(&MakeNewEditorWorldDone); |
698 GenerateWorldSetCallback(&MakeNewEditorWorldDone); |
696 GenerateWorld(GW_EMPTY, 1 << _patches.map_x, 1 << _patches.map_y); |
699 GenerateWorld(GW_EMPTY, 1 << _patches.map_x, 1 << _patches.map_y); |
697 } |
700 } |
698 |
701 |
699 void StartupPlayers(void); |
702 void StartupPlayers(); |
700 void StartupDisasters(void); |
703 void StartupDisasters(); |
701 extern void StartupEconomy(void); |
704 extern void StartupEconomy(); |
702 |
705 |
703 /** |
706 /** |
704 * Start Scenario starts a new game based on a scenario. |
707 * Start Scenario starts a new game based on a scenario. |
705 * Eg 'New Game' --> select a preset scenario |
708 * Eg 'New Game' --> select a preset scenario |
706 * This starts a scenario based on your current difficulty settings |
709 * This starts a scenario based on your current difficulty settings |
707 */ |
710 */ |
708 static void StartScenario(void) |
711 static void StartScenario() |
709 { |
712 { |
710 _game_mode = GM_NORMAL; |
713 _game_mode = GM_NORMAL; |
711 |
714 |
712 // invalid type |
715 // invalid type |
713 if (_file_to_saveload.mode == SL_INVALID) { |
716 if (_file_to_saveload.mode == SL_INVALID) { |
898 |
901 |
899 // State controlling game loop. |
902 // State controlling game loop. |
900 // The state must not be changed from anywhere |
903 // The state must not be changed from anywhere |
901 // but here. |
904 // but here. |
902 // That check is enforced in DoCommand. |
905 // That check is enforced in DoCommand. |
903 void StateGameLoop(void) |
906 void StateGameLoop() |
904 { |
907 { |
905 // dont execute the state loop during pause |
908 // dont execute the state loop during pause |
906 if (_pause) return; |
909 if (_pause_game) return; |
907 if (IsGeneratingWorld()) return; |
910 if (IsGeneratingWorld()) return; |
908 |
911 |
909 if (_game_mode == GM_EDITOR) { |
912 if (_game_mode == GM_EDITOR) { |
910 RunTileLoop(); |
913 RunTileLoop(); |
911 CallVehicleTicks(); |
914 CallVehicleTicks(); |
996 { 0, 2}, // 13 : left + right + down = down |
999 { 0, 2}, // 13 : left + right + down = down |
997 { 0, -2}, // 14 : left + right + up = up |
1000 { 0, -2}, // 14 : left + right + up = up |
998 { 0, 0}, // 15 : impossible |
1001 { 0, 0}, // 15 : impossible |
999 }; |
1002 }; |
1000 |
1003 |
1001 static void HandleKeyScrolling(void) |
1004 static void HandleKeyScrolling() |
1002 { |
1005 { |
1003 if (_dirkeys && !_no_scroll) { |
1006 if (_dirkeys && !_no_scroll) { |
1004 int factor = _shift_pressed ? 50 : 10; |
1007 int factor = _shift_pressed ? 50 : 10; |
1005 ScrollMainViewport(scrollamt[_dirkeys][0] * factor, scrollamt[_dirkeys][1] * factor); |
1008 ScrollMainViewport(scrollamt[_dirkeys][0] * factor, scrollamt[_dirkeys][1] * factor); |
1006 } |
1009 } |
1007 } |
1010 } |
1008 |
1011 |
1009 void GameLoop(void) |
1012 void GameLoop() |
1010 { |
1013 { |
1011 ThreadMsg message; |
1014 ThreadMsg message; |
1012 |
1015 |
1013 if ((message = OTTD_PollThreadEvent()) != 0) ProcessSentMessage(message); |
1016 if ((message = OTTD_PollThreadEvent()) != 0) ProcessSentMessage(message); |
1014 |
1017 |
1062 } |
1065 } |
1063 #else |
1066 #else |
1064 StateGameLoop(); |
1067 StateGameLoop(); |
1065 #endif /* ENABLE_NETWORK */ |
1068 #endif /* ENABLE_NETWORK */ |
1066 |
1069 |
1067 if (!_pause && _display_opt & DO_FULL_ANIMATION) DoPaletteAnimations(); |
1070 if (!_pause_game && _display_opt & DO_FULL_ANIMATION) DoPaletteAnimations(); |
1068 |
1071 |
1069 if (!_pause || _cheats.build_in_pause.value) MoveAllTextEffects(); |
1072 if (!_pause_game || _cheats.build_in_pause.value) MoveAllTextEffects(); |
1070 |
1073 |
1071 InputLoop(); |
1074 InputLoop(); |
1072 |
1075 |
1073 MusicLoop(); |
1076 MusicLoop(); |
1074 } |
1077 } |
1075 |
1078 |
1076 void BeforeSaveGame(void) |
1079 void BeforeSaveGame() |
1077 { |
1080 { |
1078 const Window *w = FindWindowById(WC_MAIN_WINDOW, 0); |
1081 const Window *w = FindWindowById(WC_MAIN_WINDOW, 0); |
1079 |
1082 |
1080 if (w != NULL) { |
1083 if (w != NULL) { |
1081 _saved_scrollpos_x = WP(w, const vp_d).scrollpos_x; |
1084 _saved_scrollpos_x = WP(w, const vp_d).scrollpos_x; |
1082 _saved_scrollpos_y = WP(w, const vp_d).scrollpos_y; |
1085 _saved_scrollpos_y = WP(w, const vp_d).scrollpos_y; |
1083 _saved_scrollpos_zoom = w->viewport->zoom; |
1086 _saved_scrollpos_zoom = w->viewport->zoom; |
1084 } |
1087 } |
1085 } |
1088 } |
1086 |
1089 |
1087 static void ConvertTownOwner(void) |
1090 static void ConvertTownOwner() |
1088 { |
1091 { |
1089 TileIndex tile; |
1092 TileIndex tile; |
1090 |
1093 |
1091 for (tile = 0; tile != MapSize(); tile++) { |
1094 for (tile = 0; tile != MapSize(); tile++) { |
1092 switch (GetTileType(tile)) { |
1095 switch (GetTileType(tile)) { |
1104 } |
1107 } |
1105 } |
1108 } |
1106 } |
1109 } |
1107 |
1110 |
1108 // before savegame version 4, the name of the company determined if it existed |
1111 // before savegame version 4, the name of the company determined if it existed |
1109 static void CheckIsPlayerActive(void) |
1112 static void CheckIsPlayerActive() |
1110 { |
1113 { |
1111 Player *p; |
1114 Player *p; |
1112 |
1115 |
1113 FOR_ALL_PLAYERS(p) { |
1116 FOR_ALL_PLAYERS(p) { |
1114 if (p->name_1 != 0) p->is_active = true; |
1117 if (p->name_1 != 0) p->is_active = true; |
1115 } |
1118 } |
1116 } |
1119 } |
1117 |
1120 |
1118 // since savegame version 4.1, exclusive transport rights are stored at towns |
1121 // since savegame version 4.1, exclusive transport rights are stored at towns |
1119 static void UpdateExclusiveRights(void) |
1122 static void UpdateExclusiveRights() |
1120 { |
1123 { |
1121 Town *t; |
1124 Town *t; |
1122 |
1125 |
1123 FOR_ALL_TOWNS(t) { |
1126 FOR_ALL_TOWNS(t) { |
1124 t->exclusivity = INVALID_PLAYER; |
1127 t->exclusivity = INVALID_PLAYER; |
1140 9, 11, 13, 6, 17, |
1143 9, 11, 13, 6, 17, |
1141 16, 22, 21, 7, 15, |
1144 16, 22, 21, 7, 15, |
1142 18, 2, 20, }; |
1145 18, 2, 20, }; |
1143 |
1146 |
1144 // since savegame version 4.2 the currencies are arranged differently |
1147 // since savegame version 4.2 the currencies are arranged differently |
1145 static void UpdateCurrencies(void) |
1148 static void UpdateCurrencies() |
1146 { |
1149 { |
1147 _opt.currency = convert_currency[_opt.currency]; |
1150 _opt.currency = convert_currency[_opt.currency]; |
1148 } |
1151 } |
1149 |
1152 |
1150 /* Up to revision 1413 the invisible tiles at the southern border have not been |
1153 /* Up to revision 1413 the invisible tiles at the southern border have not been |
1151 * MP_VOID, even though they should have. This is fixed by this function |
1154 * MP_VOID, even though they should have. This is fixed by this function |
1152 */ |
1155 */ |
1153 static void UpdateVoidTiles(void) |
1156 static void UpdateVoidTiles() |
1154 { |
1157 { |
1155 uint i; |
1158 uint i; |
1156 |
1159 |
1157 for (i = 0; i < MapMaxY(); ++i) MakeVoid(i * MapSizeX() + MapMaxX()); |
1160 for (i = 0; i < MapMaxY(); ++i) MakeVoid(i * MapSizeX() + MapMaxX()); |
1158 for (i = 0; i < MapSizeX(); ++i) MakeVoid(MapSizeX() * MapMaxY() + i); |
1161 for (i = 0; i < MapSizeX(); ++i) MakeVoid(MapSizeX() * MapMaxY() + i); |
1159 } |
1162 } |
1160 |
1163 |
1161 // since savegame version 6.0 each sign has an "owner", signs without owner (from old games are set to 255) |
1164 // since savegame version 6.0 each sign has an "owner", signs without owner (from old games are set to 255) |
1162 static void UpdateSignOwner(void) |
1165 static void UpdateSignOwner() |
1163 { |
1166 { |
1164 Sign *si; |
1167 Sign *si; |
1165 |
1168 |
1166 FOR_ALL_SIGNS(si) si->owner = OWNER_NONE; |
1169 FOR_ALL_SIGNS(si) si->owner = OWNER_NONE; |
1167 } |
1170 } |
1168 |
1171 |
1169 extern void UpdateOldAircraft( void ); |
1172 extern void UpdateOldAircraft(); |
1170 |
1173 |
1171 |
1174 |
1172 static inline RailType UpdateRailType(RailType rt, RailType min) |
1175 static inline RailType UpdateRailType(RailType rt, RailType min) |
1173 { |
1176 { |
1174 return rt >= min ? (RailType)(rt + 1): rt; |
1177 return rt >= min ? (RailType)(rt + 1): rt; |
1175 } |
1178 } |
1176 |
1179 |
1177 bool AfterLoadGame(void) |
1180 bool AfterLoadGame() |
1178 { |
1181 { |
1179 TileIndex map_size = MapSize(); |
1182 TileIndex map_size = MapSize(); |
1180 Window *w; |
1183 Window *w; |
1181 ViewPort *vp; |
1184 ViewPort *vp; |
1182 Player *p; |
1185 Player *p; |
1207 |
1210 |
1208 // convert road side to my format. |
1211 // convert road side to my format. |
1209 if (_opt.road_side) _opt.road_side = 1; |
1212 if (_opt.road_side) _opt.road_side = 1; |
1210 |
1213 |
1211 /* Check if all NewGRFs are present, we are very strict in MP mode */ |
1214 /* Check if all NewGRFs are present, we are very strict in MP mode */ |
1212 GCF_Flags gcf_res = IsGoodGRFConfigList(); |
1215 GRFListCompatibility gcf_res = IsGoodGRFConfigList(); |
1213 if (_networking && gcf_res != GCF_ACTIVATED) return false; |
1216 if (_networking && gcf_res != GLC_ALL_GOOD) return false; |
1214 |
1217 |
1215 switch (gcf_res) { |
1218 switch (gcf_res) { |
1216 case GCF_COMPATIBLE: _switch_mode_errorstr = STR_NEWGRF_COMPATIBLE_LOAD_WARNING; break; |
1219 case GLC_COMPATIBLE: _switch_mode_errorstr = STR_NEWGRF_COMPATIBLE_LOAD_WARNING; break; |
1217 case GCF_NOT_FOUND: _switch_mode_errorstr = STR_NEWGRF_DISABLED_WARNING; break; |
1220 case GLC_NOT_FOUND: _switch_mode_errorstr = STR_NEWGRF_DISABLED_WARNING; break; |
1218 default: break; |
1221 default: break; |
1219 } |
1222 } |
1220 |
1223 |
1221 /* Update current year |
1224 /* Update current year |
1222 * must be done before loading sprites as some newgrfs check it */ |
1225 * must be done before loading sprites as some newgrfs check it */ |
1442 } |
1445 } |
1443 } |
1446 } |
1444 } |
1447 } |
1445 |
1448 |
1446 FOR_ALL_VEHICLES(v) { |
1449 FOR_ALL_VEHICLES(v) { |
1447 if (v->type != VEH_Train && v->type != VEH_Road) continue; |
1450 if (v->type != VEH_TRAIN && v->type != VEH_ROAD) continue; |
1448 if (IsBridgeTile(v->tile)) { |
1451 if (IsBridgeTile(v->tile)) { |
1449 DiagDirection dir = GetBridgeRampDirection(v->tile); |
1452 DiagDirection dir = GetBridgeRampDirection(v->tile); |
1450 |
1453 |
1451 if (dir != DirToDiagDir(v->direction)) continue; |
1454 if (dir != DirToDiagDir(v->direction)) continue; |
1452 switch (dir) { |
1455 switch (dir) { |
1459 } else if (v->z_pos > GetSlopeZ(v->x_pos, v->y_pos)) { |
1462 } else if (v->z_pos > GetSlopeZ(v->x_pos, v->y_pos)) { |
1460 v->tile = GetNorthernBridgeEnd(v->tile); |
1463 v->tile = GetNorthernBridgeEnd(v->tile); |
1461 } else { |
1464 } else { |
1462 continue; |
1465 continue; |
1463 } |
1466 } |
1464 if (v->type == VEH_Train) { |
1467 if (v->type == VEH_TRAIN) { |
1465 v->u.rail.track = TRACK_BIT_WORMHOLE; |
1468 v->u.rail.track = TRACK_BIT_WORMHOLE; |
1466 } else { |
1469 } else { |
1467 v->u.road.state = RVSB_WORMHOLE; |
1470 v->u.road.state = RVSB_WORMHOLE; |
1468 } |
1471 } |
1469 } |
1472 } |
1501 if (CheckSavegameVersion(24)) { |
1504 if (CheckSavegameVersion(24)) { |
1502 Vehicle *v; |
1505 Vehicle *v; |
1503 RailType min_rail = RAILTYPE_ELECTRIC; |
1506 RailType min_rail = RAILTYPE_ELECTRIC; |
1504 |
1507 |
1505 FOR_ALL_VEHICLES(v) { |
1508 FOR_ALL_VEHICLES(v) { |
1506 if (v->type == VEH_Train) { |
1509 if (v->type == VEH_TRAIN) { |
1507 RailType rt = RailVehInfo(v->engine_type)->railtype; |
1510 RailType rt = RailVehInfo(v->engine_type)->railtype; |
1508 |
1511 |
1509 v->u.rail.railtype = rt; |
1512 v->u.rail.railtype = rt; |
1510 if (rt == RAILTYPE_ELECTRIC) min_rail = RAILTYPE_RAIL; |
1513 if (rt == RAILTYPE_ELECTRIC) min_rail = RAILTYPE_RAIL; |
1511 } |
1514 } |
1638 if (CheckSavegameVersion(22)) UpdatePatches(); |
1641 if (CheckSavegameVersion(22)) UpdatePatches(); |
1639 |
1642 |
1640 if (CheckSavegameVersion(25)) { |
1643 if (CheckSavegameVersion(25)) { |
1641 Vehicle *v; |
1644 Vehicle *v; |
1642 FOR_ALL_VEHICLES(v) { |
1645 FOR_ALL_VEHICLES(v) { |
1643 if (v->type == VEH_Road) { |
1646 if (v->type == VEH_ROAD) { |
1644 v->vehstatus &= ~0x40; |
1647 v->vehstatus &= ~0x40; |
1645 v->u.road.slot = NULL; |
1648 v->u.road.slot = NULL; |
1646 v->u.road.slot_age = 0; |
1649 v->u.road.slot_age = 0; |
1647 } |
1650 } |
1648 } |
1651 } |
1649 } else { |
1652 } else { |
1650 Vehicle *v; |
1653 Vehicle *v; |
1651 FOR_ALL_VEHICLES(v) { |
1654 FOR_ALL_VEHICLES(v) { |
1652 if (v->type == VEH_Road && v->u.road.slot != NULL) v->u.road.slot->num_vehicles++; |
1655 if (v->type == VEH_ROAD && v->u.road.slot != NULL) v->u.road.slot->num_vehicles++; |
1653 } |
1656 } |
1654 } |
1657 } |
1655 |
1658 |
1656 if (CheckSavegameVersion(26)) { |
1659 if (CheckSavegameVersion(26)) { |
1657 Station *st; |
1660 Station *st; |
1658 FOR_ALL_STATIONS(st) { |
1661 FOR_ALL_STATIONS(st) { |
1659 st->last_vehicle_type = VEH_Invalid; |
1662 st->last_vehicle_type = VEH_INVALID; |
1660 } |
1663 } |
1661 } |
1664 } |
1662 |
1665 |
1663 YapfNotifyTrackLayoutChange(INVALID_TILE, INVALID_TRACK); |
1666 YapfNotifyTrackLayoutChange(INVALID_TILE, INVALID_TRACK); |
1664 |
1667 |
1788 * where this situation exists, the cargo-source information is lost. in this case, we set the origin |
1791 * where this situation exists, the cargo-source information is lost. in this case, we set the origin |
1789 * to the current tile of the vehicle to prevent excessive profits |
1792 * to the current tile of the vehicle to prevent excessive profits |
1790 */ |
1793 */ |
1791 FOR_ALL_VEHICLES(v) { |
1794 FOR_ALL_VEHICLES(v) { |
1792 v->cargo_source_xy = IsValidStationID(v->cargo_source) ? GetStation(v->cargo_source)->xy : v->tile; |
1795 v->cargo_source_xy = IsValidStationID(v->cargo_source) ? GetStation(v->cargo_source)->xy : v->tile; |
|
1796 } |
|
1797 |
|
1798 /* Store position of the station where the goods come from, so there |
|
1799 * are no very high payments when stations get removed. However, if the |
|
1800 * station where the goods came from is already removed, the source |
|
1801 * information is lost. In that case we set it to the position of this |
|
1802 * station */ |
|
1803 Station *st; |
|
1804 FOR_ALL_STATIONS(st) { |
|
1805 for (CargoID c = 0; c < NUM_CARGO; c++) { |
|
1806 GoodsEntry *ge = &st->goods[c]; |
|
1807 |
|
1808 /* In old versions, enroute_from used 0xFF as INVALID_STATION */ |
|
1809 if (CheckSavegameVersion(7) && ge->enroute_from == 0xFF) { |
|
1810 ge->enroute_from = INVALID_STATION; |
|
1811 } |
|
1812 |
|
1813 ge->enroute_from_xy = IsValidStationID(ge->enroute_from) ? GetStation(ge->enroute_from)->xy : st->xy; |
|
1814 } |
1793 } |
1815 } |
1794 } |
1816 } |
1795 |
1817 |
1796 if (CheckSavegameVersion(45)) { |
1818 if (CheckSavegameVersion(45)) { |
1797 Vehicle *v; |
1819 Vehicle *v; |
1821 |
1843 |
1822 if (CheckSavegameVersion(50)) { |
1844 if (CheckSavegameVersion(50)) { |
1823 Vehicle *v; |
1845 Vehicle *v; |
1824 /* Aircraft units changed from 8 mph to 1 km/h */ |
1846 /* Aircraft units changed from 8 mph to 1 km/h */ |
1825 FOR_ALL_VEHICLES(v) { |
1847 FOR_ALL_VEHICLES(v) { |
1826 if (v->type == VEH_Aircraft && v->subtype <= AIR_AIRCRAFT) { |
1848 if (v->type == VEH_AIRCRAFT && v->subtype <= AIR_AIRCRAFT) { |
1827 const AircraftVehicleInfo *avi = AircraftVehInfo(v->engine_type); |
1849 const AircraftVehicleInfo *avi = AircraftVehInfo(v->engine_type); |
1828 v->cur_speed *= 129; |
1850 v->cur_speed *= 129; |
1829 v->cur_speed /= 10; |
1851 v->cur_speed /= 10; |
1830 v->max_speed = avi->max_speed; |
1852 v->max_speed = avi->max_speed; |
1831 v->acceleration = avi->acceleration; |
1853 v->acceleration = avi->acceleration; |
1832 } |
1854 } |
1833 } |
1855 } |
1834 } |
1856 } |
1835 |
1857 |
1836 if (CheckSavegameVersion(49)) FOR_ALL_PLAYERS(p) p->face = ConvertFromOldPlayerFace(p->face); |
1858 if (CheckSavegameVersion(49)) FOR_ALL_PLAYERS(p) p->face = ConvertFromOldPlayerFace(p->face); |
|
1859 |
|
1860 if (CheckSavegameVersion(52)) { |
|
1861 for (TileIndex t = 0; t < map_size; t++) { |
|
1862 if (IsStatueTile(t)) { |
|
1863 _m[t].m2 = CalcClosestTownFromTile(t, (uint)-1)->index; |
|
1864 } |
|
1865 } |
|
1866 } |
1837 |
1867 |
1838 return true; |
1868 return true; |
1839 } |
1869 } |
1840 |
1870 |
1841 /** Reload all NewGRF files during a running game. This is a cut-down |
1871 /** Reload all NewGRF files during a running game. This is a cut-down |
1842 * version of AfterLoadGame(). |
1872 * version of AfterLoadGame(). |
1843 * XXX - We need to reset the vehicle position hash because with a non-empty |
1873 * XXX - We need to reset the vehicle position hash because with a non-empty |
1844 * hash AfterLoadVehicles() will loop infinitely. We need AfterLoadVehicles() |
1874 * hash AfterLoadVehicles() will loop infinitely. We need AfterLoadVehicles() |
1845 * to recalculate vehicle data as some NewGRF vehicle sets could have been |
1875 * to recalculate vehicle data as some NewGRF vehicle sets could have been |
1846 * removed or added and changed statistics */ |
1876 * removed or added and changed statistics */ |
1847 void ReloadNewGRFData(void) |
1877 void ReloadNewGRFData() |
1848 { |
1878 { |
1849 /* reload grf data */ |
1879 /* reload grf data */ |
1850 GfxLoadSprites(); |
1880 GfxLoadSprites(); |
1851 LoadStringWidthTable(); |
1881 LoadStringWidthTable(); |
1852 /* reload vehicles */ |
1882 /* reload vehicles */ |