summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorrubidium <rubidium@openttd.org>2009-09-12 14:37:29 +0000
committerrubidium <rubidium@openttd.org>2009-09-12 14:37:29 +0000
commit4c65a04a50660eaffd684efd05ab530ea5e3e3b8 (patch)
treef6f86540b213fbd9f2e358e2c51c7104020b6f5e
parentc60cebd4bb2a2c0ad68e2bbec814d768cab939f1 (diff)
downloadopenttd-4c65a04a50660eaffd684efd05ab530ea5e3e3b8.tar.xz
(svn r17509) -Fix [FS#3196]: if building a part fails during cloning, sell what was already cloned instead of leaving it 'for free'
-Fix: make cloning multiheaded trains possible with with 'max - 1' vehicles existing
-rw-r--r--src/vehicle_cmd.cpp17
1 files changed, 15 insertions, 2 deletions
diff --git a/src/vehicle_cmd.cpp b/src/vehicle_cmd.cpp
index b51fd06ec..c757c2ae2 100644
--- a/src/vehicle_cmd.cpp
+++ b/src/vehicle_cmd.cpp
@@ -359,10 +359,23 @@ CommandCost CmdCloneVehicle(TileIndex tile, DoCommandFlag flags, uint32 p1, uint
continue;
}
- CommandCost cost = DoCommand(tile, v->engine_type, build_argument, flags, GetCmdBuildVeh(v));
+ /* In case we're building a multi headed vehicle and the maximum number of
+ * vehicles is almost reached (e.g. max trains - 1) not all vehicles would
+ * be cloned. When the non-primary engines were build they were seen as
+ * 'new' vehicles whereas they would immediately be joined with a primary
+ * engine. This caused the vehicle to be not build as 'the limit' had been
+ * reached, resulting in partially build vehicles and such. */
+ DoCommandFlag build_flags = flags;
+ if ((flags & DC_EXEC) && !v->IsPrimaryVehicle()) build_flags |= DC_AUTOREPLACE;
+
+ CommandCost cost = DoCommand(tile, v->engine_type, build_argument, build_flags, GetCmdBuildVeh(v));
build_argument = 3; // ensure that we only assign a number to the first engine
- if (CmdFailed(cost)) return cost;
+ if (CmdFailed(cost)) {
+ /* Can't build a part, then sell the stuff we already made; clear up the mess */
+ if (w_front != NULL) DoCommand(w_front->tile, w_front->index, 1, flags, GetCmdSellVeh(w_front));
+ return cost;
+ }
total_cost.AddCost(cost);