(svn r12904) -Fix [FS#1953]: remove trams from savegames saved in OTTD without tram support, it is better than to simply crash
--- a/src/lang/english.txt Fri Apr 25 15:25:28 2008 +0000
+++ b/src/lang/english.txt Fri Apr 25 16:33:40 2008 +0000
@@ -3182,6 +3182,8 @@
STR_NEWGRF_UNPAUSE_WARNING_TITLE :{YELLOW}Missing GRF file(s)
STR_NEWGRF_UNPAUSE_WARNING :{WHITE}Unpausing can crash OpenTTD. Do not file bug reports for subsequent crashes.{}Do you really want to unpause?
+STR_LOADGAME_REMOVED_TRAMS :{WHITE}Game was saved in version without tram support. All trams have been removed.
+
STR_CURRENCY_WINDOW :{WHITE}Custom currency
STR_CURRENCY_EXCHANGE_RATE :{LTBLUE}Exchange rate: {ORANGE}{CURRENCY} = £ {COMMA}
STR_CURRENCY_SEPARATOR :{LTBLUE}Separator:
--- a/src/openttd.cpp Fri Apr 25 15:25:28 2008 +0000
+++ b/src/openttd.cpp Fri Apr 25 16:33:40 2008 +0000
@@ -2501,6 +2501,21 @@
}
}
+ if (CheckSavegameVersion(62)) {
+ /* Remove all trams from savegames without tram support.
+ * There would be trams without tram track under causing crashes sooner or later. */
+ Vehicle *v;
+ FOR_ALL_VEHICLES(v) {
+ if (v->type == VEH_ROAD && v->First() == v &&
+ HasBit(EngInfo(v->engine_type)->misc_flags, EF_ROAD_TRAM)) {
+ if (_switch_mode_errorstr == INVALID_STRING_ID || _switch_mode_errorstr == STR_NEWGRF_COMPATIBLE_LOAD_WARNING) {
+ _switch_mode_errorstr = STR_LOADGAME_REMOVED_TRAMS;
+ }
+ delete v;
+ }
+ }
+ }
+
return InitializeWindowsAndCaches();
}
--- a/src/vehicle.cpp Fri Apr 25 15:25:28 2008 +0000
+++ b/src/vehicle.cpp Fri Apr 25 16:33:40 2008 +0000
@@ -591,7 +591,7 @@
}
Window *w = FindWindowById(WC_MAIN_WINDOW, 0);
- if (WP(w, vp_d).follow_vehicle == this->index) {
+ if (w != NULL && WP(w, vp_d).follow_vehicle == this->index) {
ScrollMainWindowTo(this->x_pos, this->y_pos, true); // lock the main view on the vehicle's last position
WP(w, vp_d).follow_vehicle = INVALID_VEHICLE;
}