summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormaedhros <maedhros@openttd.org>2007-04-04 14:21:46 +0000
committermaedhros <maedhros@openttd.org>2007-04-04 14:21:46 +0000
commitabf88b687ccbc7e344b3eacf8a84c1f71cac73a3 (patch)
tree5c1252fe5c41c1984b403c774027a6871a9000b6
parent3b8dd00bae0ca79bdab4c76c6fc9b73c31dd4615 (diff)
downloadopenttd-abf88b687ccbc7e344b3eacf8a84c1f71cac73a3.tar.xz
(svn r9562) -Fix: When cloning, pay for the refit costs as well.
-rw-r--r--src/command.cpp8
-rw-r--r--src/vehicle.cpp20
2 files changed, 19 insertions, 9 deletions
diff --git a/src/command.cpp b/src/command.cpp
index 7bd6a3992..e72f6963a 100644
--- a/src/command.cpp
+++ b/src/command.cpp
@@ -455,13 +455,17 @@ bool DoCommandP(TileIndex tile, uint32 p1, uint32 p2, CommandCallback *callback,
* restrictions which may cause the test run to fail (the previous
* road fragments still stay there and the town won't let you
* disconnect the road system), but the exec will succeed and this
- * fact will trigger an assertion failure. --pasky */
+ * fact will trigger an assertion failure. --pasky
+ * CMD_CLONE_VEHICLE: You can only refit vehicles once they have been
+ * bought, so you can't estimate the cost of cloning if the vehicle to be
+ * cloned has been refitted. */
notest =
(cmd & 0xFF) == CMD_CLEAR_AREA ||
(cmd & 0xFF) == CMD_CONVERT_RAIL ||
(cmd & 0xFF) == CMD_LEVEL_LAND ||
(cmd & 0xFF) == CMD_REMOVE_ROAD ||
- (cmd & 0xFF) == CMD_REMOVE_LONG_ROAD;
+ (cmd & 0xFF) == CMD_REMOVE_LONG_ROAD ||
+ (cmd & 0xFF) == CMD_CLONE_VEHICLE;
_docommand_recursive = 1;
diff --git a/src/vehicle.cpp b/src/vehicle.cpp
index 870a291f2..1b1db2197 100644
--- a/src/vehicle.cpp
+++ b/src/vehicle.cpp
@@ -1807,10 +1807,9 @@ int32 CmdCloneVehicle(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
w_front = NULL;
w_rear = NULL;
-
/*
* v_front is the front engine in the original vehicle
- * v is the car/vehicle of the original vehicle, that is currently being copied
+ * v is the car/vehicle of the original vehicle that is currently being copied
* w_front is the front engine of the cloned vehicle
* w is the car/vehicle currently being cloned
* w_rear is the rear end of the cloned train. It's used to add more cars and is only used by trains
@@ -1855,11 +1854,18 @@ int32 CmdCloneVehicle(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
Vehicle *v2 = v;
do {
if (v2->cargo_type != w2->cargo_type || v2->cargo_subtype != w2->cargo_subtype) {
- /* We can't pay for refitting because we can't estimate refitting costs for a vehicle before it's build.
- * If we pay for it anyway, the cost and the estimated cost will not be the same and we will have an assert.
- * We need to check the whole chain if it is a train because some newgrf articulated engines can refit some units only (and not the front) */
- DoCommand(0, w->index, v2->cargo_type | (v2->cargo_subtype << 8), flags, GetCmdRefitVeh(v));
- break; // We learned that the engine in question needed a refit. No need to check anymore
+ /* We need to check the whole chain if it is a train
+ * because some newgrf articulated engines can refit some
+ * units only (and not the front). */
+ cost = DoCommand(0, w->index, v2->cargo_type | (v2->cargo_subtype << 8), flags, GetCmdRefitVeh(v));
+ if (CmdFailed(cost)) return cost;
+
+ total_cost += cost;
+
+ /* The refit command will refit all the remaining
+ * articulated parts if possible, so we don't need to
+ * carry on checking. */
+ break;
}
} while (v->type == VEH_TRAIN && (w2 = w2->next) != NULL && (v2 = v2->next) != NULL);