summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorbjarni <bjarni@openttd.org>2006-09-16 16:21:47 +0000
committerbjarni <bjarni@openttd.org>2006-09-16 16:21:47 +0000
commit3d3d9a11bd455236670f7e4eb3f746a1def8df11 (patch)
tree267bc2ab0879df1691d27cd58194d5e366c9303b
parentb28b547a810e290145a2c5f90594a5fbbca13a34 (diff)
downloadopenttd-3d3d9a11bd455236670f7e4eb3f746a1def8df11.tar.xz
(svn r6464) -Fix r6393: killed a warning when compiling without asserts
added an error popup in the game if autoreplace fails to refit Since it's only triggered by conditions bugs can trigger, it works kind of like a non-fatal assert in builds without asserts
-rw-r--r--lang/english.txt2
-rw-r--r--vehicle.c13
2 files changed, 13 insertions, 2 deletions
diff --git a/lang/english.txt b/lang/english.txt
index 467fc8523..793d83e13 100644
--- a/lang/english.txt
+++ b/lang/english.txt
@@ -2906,6 +2906,8 @@ STR_REPLACE_REMOVE_WAGON_HELP :{BLACK}Make aut
STR_REPLACE_ENGINE_WAGON_SELECT :{BLACK}Replacing: {ORANGE}{SKIP}{SKIP}{STRING}
STR_REPLACE_ENGINE_WAGON_SELECT_HELP :{BLACK} EXPERIMENTAL FEATURE {}Switch between engine and wagon replacement windows.{}Wagon replacement will only be done if the new wagon can be refitted into carrying the same type of cargo as the old one. This is checked for each wagon when the actual replacement takes place.
STR_ENGINE_NOT_BUILDABLE :{WHITE}Engine is not buildable
+STR_AUTOREPLACE_FAILED :{WHITE}BUG: Autoreplace refit failure
+STR_AUTOREPLACE_REFIT_FAILURE :{WHITE}{STRING} replaced into {STRING} failed to refit to {STRING}
STR_ENGINES :Engines
STR_WAGONS :Wagons
diff --git a/vehicle.c b/vehicle.c
index 6d16bf60a..17cc63f1b 100644
--- a/vehicle.c
+++ b/vehicle.c
@@ -1778,9 +1778,18 @@ static int32 ReplaceVehicle(Vehicle **w, byte flags, int32 total_cost)
/* refit if needed */
if (replacement_cargo_type != CT_NO_REFIT) {
- int32 temp_cost = DoCommand(0, new_v->index, replacement_cargo_type, DC_EXEC, CMD_REFIT_VEH(new_v->type));
- assert(!CmdFailed(temp_cost)); // assert failure here indicates a bug in GetNewCargoTypeForReplace()
+ if (CmdFailed(DoCommand(0, new_v->index, replacement_cargo_type, DC_EXEC, CMD_REFIT_VEH(new_v->type)))) {
+ /* We should not be here
+ * being here shows a failure indicates a bug in GetNewCargoTypeForReplace() or incorrect estimation costs */
+ SetDParam(0, GetCustomEngineName(old_v->engine_type));
+ SetDParam(1, GetCustomEngineName(new_v->engine_type));
+ SetDParam(2, _cargoc.names_s[replacement_cargo_type]);
+ ShowInfo("Error: Autoreplace failed to refit (bug)");
+ ShowErrorMessage(STR_AUTOREPLACE_REFIT_FAILURE, STR_AUTOREPLACE_FAILED, 0 ,0);
+ NOT_REACHED(); // stop debug builds at this error for easier debugging
+ }
}
+
if (new_v->type == VEH_Train && HASBIT(old_v->u.rail.flags, VRF_REVERSE_DIRECTION) && !IsMultiheaded(new_v) && !(new_v->next != NULL && IsArticulatedPart(new_v->next))) {
// we are autorenewing to a single engine, so we will turn it as the old one was turned as well
SETBIT(new_v->u.rail.flags, VRF_REVERSE_DIRECTION);