summaryrefslogtreecommitdiff
path: root/src/autoreplace_cmd.cpp
diff options
context:
space:
mode:
authorfrosch <frosch@openttd.org>2011-12-10 21:09:21 +0000
committerfrosch <frosch@openttd.org>2011-12-10 21:09:21 +0000
commit2fe8e89a45c90a1bced09e8fbcfc7e5b526d54ed (patch)
tree5576200e898adcbae733dc9121423bc3ac281711 /src/autoreplace_cmd.cpp
parenta8960f64be1a7796e90e2634fc2a5419e369f0b5 (diff)
downloadopenttd-2fe8e89a45c90a1bced09e8fbcfc7e5b526d54ed.tar.xz
(svn r23487) -Change/Fix: Make autoreplace, autorenew, cloning and autorefit check all articulated parts of a vehicle to find a shared cargo subtype.
Diffstat (limited to 'src/autoreplace_cmd.cpp')
-rw-r--r--src/autoreplace_cmd.cpp25
1 files changed, 4 insertions, 21 deletions
diff --git a/src/autoreplace_cmd.cpp b/src/autoreplace_cmd.cpp
index 39e294f6c..593a5c49c 100644
--- a/src/autoreplace_cmd.cpp
+++ b/src/autoreplace_cmd.cpp
@@ -182,15 +182,7 @@ static CargoID GetNewCargoTypeForReplace(Vehicle *v, EngineID engine_type, bool
for (v = v->First(); v != NULL; v = v->Next()) {
if (v->cargo_cap == 0) continue;
/* Now we found a cargo type being carried on the train and we will see if it is possible to carry to this one */
- if (HasBit(available_cargo_types, v->cargo_type)) {
- /* Do we have to refit the vehicle, or is it already carrying the right cargo? */
- CargoArray default_capacity = GetCapacityOfArticulatedParts(engine_type);
- for (CargoID cid = 0; cid < NUM_CARGO; cid++) {
- if (cid != v->cargo_type && default_capacity[cid] > 0) return v->cargo_type;
- }
-
- return CT_NO_REFIT;
- }
+ if (HasBit(available_cargo_types, v->cargo_type)) return v->cargo_type;
}
return CT_NO_REFIT; // We failed to find a cargo type on the old vehicle and we will not refit the new one
@@ -199,13 +191,7 @@ static CargoID GetNewCargoTypeForReplace(Vehicle *v, EngineID engine_type, bool
if (part_of_chain && !VerifyAutoreplaceRefitForOrders(v, engine_type)) return CT_INVALID; // Some refit orders lose their effect
- /* Do we have to refit the vehicle, or is it already carrying the right cargo? */
- CargoArray default_capacity = GetCapacityOfArticulatedParts(engine_type);
- for (CargoID cid = 0; cid < NUM_CARGO; cid++) {
- if (cid != cargo_type && default_capacity[cid] > 0) return cargo_type;
- }
-
- return CT_NO_REFIT;
+ return cargo_type;
}
}
@@ -275,12 +261,9 @@ static CommandCost BuildReplacementVehicle(Vehicle *old_veh, Vehicle **new_vehic
*new_vehicle = new_veh;
/* Refit the vehicle if needed */
- byte subtype = GetBestFittingSubType(old_veh, new_veh);
- /* If the subtype isn't zero and the refit cargo is not set,
- * we're better off setting the refit cargo too. */
- if (subtype != 0 && refit_cargo == CT_NO_REFIT) refit_cargo = old_veh->cargo_type;
-
if (refit_cargo != CT_NO_REFIT) {
+ byte subtype = GetBestFittingSubType(old_veh, new_veh, refit_cargo);
+
cost.AddCost(DoCommand(0, new_veh->index, refit_cargo | (subtype << 8), DC_EXEC, GetCmdRefitVeh(new_veh)));
assert(cost.Succeeded()); // This should be ensured by GetNewCargoTypeForReplace()
}