summaryrefslogtreecommitdiff
path: root/src/autoreplace_cmd.cpp
diff options
context:
space:
mode:
authorrubidium <rubidium@openttd.org>2011-02-14 19:18:12 +0000
committerrubidium <rubidium@openttd.org>2011-02-14 19:18:12 +0000
commit95b6aeaabd933ebe4a292635d6392e602c3d51b3 (patch)
tree097983fb424a08d9ef754ac43dfe4f23252f9e6a /src/autoreplace_cmd.cpp
parent95ec99132e0d6175e837eb50099d8d4abed77665 (diff)
downloadopenttd-95b6aeaabd933ebe4a292635d6392e602c3d51b3.tar.xz
(svn r22078) -Fix [FS#4499]: maximum train length interfered with wagon replacement when wagon removal was turned on
Diffstat (limited to 'src/autoreplace_cmd.cpp')
-rw-r--r--src/autoreplace_cmd.cpp6
1 files changed, 5 insertions, 1 deletions
diff --git a/src/autoreplace_cmd.cpp b/src/autoreplace_cmd.cpp
index fccab0c0a..19a740de1 100644
--- a/src/autoreplace_cmd.cpp
+++ b/src/autoreplace_cmd.cpp
@@ -494,7 +494,10 @@ static CommandCost ReplaceChain(Vehicle **chain, DoCommandFlag flags, bool wagon
/* Insert wagon after 'last_engine' */
CommandCost res = CmdMoveVehicle(append, last_engine, DC_EXEC, false);
- if (res.Succeeded() && wagon_removal && new_head->gcache.cached_total_length > old_total_length) {
+ /* When we allow removal of wagons, either the move failing due
+ * to the train becoming too long, or the train becoming longer
+ * would move the vehicle to the empty vehicle chain. */
+ if (wagon_removal && (res.Failed() ? res.GetErrorMessage() == STR_ERROR_TRAIN_TOO_LONG : new_head->gcache.cached_total_length > old_total_length)) {
CmdMoveVehicle(append, NULL, DC_EXEC | DC_AUTOREPLACE, false);
break;
}
@@ -511,6 +514,7 @@ static CommandCost ReplaceChain(Vehicle **chain, DoCommandFlag flags, bool wagon
/* Sell superfluous new vehicles that could not be inserted. */
if (cost.Succeeded() && wagon_removal) {
+ assert(new_head->gcache.cached_total_length <= _settings_game.vehicle.max_train_length * TILE_SIZE);
for (int i = 1; i < num_units; i++) {
Vehicle *wagon = new_vehs[i];
if (wagon == NULL) continue;