summaryrefslogtreecommitdiff
path: root/src/autoreplace_cmd.cpp
diff options
context:
space:
mode:
authorbjarni <bjarni@openttd.org>2007-06-04 20:46:01 +0000
committerbjarni <bjarni@openttd.org>2007-06-04 20:46:01 +0000
commit1026c865fd939f8c0b2a4a058646195cb210af5d (patch)
treeee3f013a011339dc2654e47e54ed8fa583c4caeb /src/autoreplace_cmd.cpp
parent1102c157eb9d87069bfb64695842a869f26dbc9a (diff)
downloadopenttd-1026c865fd939f8c0b2a4a058646195cb210af5d.tar.xz
(svn r10039) -Fix: [autoreplace] when trying to replace an engine that can't carry the wagons the old one carries (GRF restrictoin), then don't try to replace at all
Diffstat (limited to 'src/autoreplace_cmd.cpp')
-rw-r--r--src/autoreplace_cmd.cpp19
1 files changed, 14 insertions, 5 deletions
diff --git a/src/autoreplace_cmd.cpp b/src/autoreplace_cmd.cpp
index 006925ed1..a906274aa 100644
--- a/src/autoreplace_cmd.cpp
+++ b/src/autoreplace_cmd.cpp
@@ -246,9 +246,19 @@ static int32 ReplaceVehicle(Vehicle **w, byte flags, int32 total_cost)
GetName(vehicle_name, old_v->string_id & 0x7FF, lastof(vehicle_name));
}
} else { // flags & DC_EXEC not set
+ int32 tmp_move = 0;
+ if (old_v->type == VEH_TRAIN && IsFrontEngine(old_v) && old_v->next != NULL) {
+ /* Verify that the wagons can be placed on the engine in question.
+ * This is done by building an engine, test if the wagons can be added and then sell the test engine. */
+ DoCommand(old_v->tile, new_engine_type, 3, DC_EXEC, GetCmdBuildVeh(old_v));
+ Vehicle *temp = GetVehicle(_new_vehicle_id);
+ tmp_move = DoCommand(0, (temp->index << 16) | old_v->next->index, 1, 0, CMD_MOVE_RAIL_VEHICLE);
+ DoCommand(0, temp->index, 0, DC_EXEC, GetCmdSellVeh(old_v));
+ }
+
/* Ensure that the player will not end up having negative money while autoreplacing
* This is needed because the only other check is done after the income from selling the old vehicle is substracted from the cost */
- if (p->money64 < (cost + total_cost)) {
+ if (CmdFailed(tmp_move) || p->money64 < (cost + total_cost)) {
SET_EXPENSES_TYPE(EXPENSES_NEW_VEHICLES);
SubtractMoneyFromPlayer(-sell_value); // Pay back the loan
return CMD_ERROR;
@@ -344,6 +354,8 @@ int32 MaybeReplaceVehicle(Vehicle *v, bool check, bool display_costs)
/* Now replace the vehicle */
temp_cost = ReplaceVehicle(&w, flags, cost);
+ if (CmdFailed(temp_cost)) break; // replace failed for some reason. Leave the vehicle alone
+
if (flags & DC_EXEC &&
(w->type != VEH_TRAIN || w->u.rail.first_engine == INVALID_ENGINE)) {
/* now we bought a new engine and sold the old one. We need to fix the
@@ -352,10 +364,7 @@ int32 MaybeReplaceVehicle(Vehicle *v, bool check, bool display_costs)
*/
v = w;
}
-
- if (!CmdFailed(temp_cost)) {
- cost += temp_cost;
- }
+ cost += temp_cost;
} while (w->type == VEH_TRAIN && (w = GetNextVehicle(w)) != NULL);
if (!(flags & DC_EXEC) && (p->money64 < (int32)(cost + p->engine_renew_money) || cost == 0)) {