summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorsmatz <smatz@openttd.org>2008-04-25 16:33:40 +0000
committersmatz <smatz@openttd.org>2008-04-25 16:33:40 +0000
commit805e1db332d3a746a7ce453f62b83d4442078a0b (patch)
treed8db094c166ef1686fc3cbd441747a5c0dc23cb1
parent4e80f3f3b1befb54a7818ab678fa27e79273ddc3 (diff)
downloadopenttd-805e1db332d3a746a7ce453f62b83d4442078a0b.tar.xz
(svn r12904) -Fix [FS#1953]: remove trams from savegames saved in OTTD without tram support, it is better than to simply crash
-rw-r--r--src/lang/english.txt2
-rw-r--r--src/openttd.cpp15
-rw-r--r--src/vehicle.cpp2
3 files changed, 18 insertions, 1 deletions
diff --git a/src/lang/english.txt b/src/lang/english.txt
index 165a3c618..972666cc3 100644
--- a/src/lang/english.txt
+++ b/src/lang/english.txt
@@ -3182,6 +3182,8 @@ STR_NEWGRF_NOT_FOUND_WARNING :{WHITE}Missing
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:
diff --git a/src/openttd.cpp b/src/openttd.cpp
index 2d32c04f6..50bf799c7 100644
--- a/src/openttd.cpp
+++ b/src/openttd.cpp
@@ -2501,6 +2501,21 @@ bool AfterLoadGame()
}
}
+ 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();
}
diff --git a/src/vehicle.cpp b/src/vehicle.cpp
index d8acda4ab..ec4908669 100644
--- a/src/vehicle.cpp
+++ b/src/vehicle.cpp
@@ -591,7 +591,7 @@ void Vehicle::PreDestructor()
}
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;
}