summaryrefslogtreecommitdiff
path: root/vehicle.c
diff options
context:
space:
mode:
authorbjarni <bjarni@openttd.org>2006-07-07 07:19:38 +0000
committerbjarni <bjarni@openttd.org>2006-07-07 07:19:38 +0000
commit356954ca263bb27119453788c3dcdc38eb6b5ca9 (patch)
treeabbcb0769404624e023f12adc6310226dc3c6ee8 /vehicle.c
parent94692a2905efd4be61d726672f5048f9a31cfbb9 (diff)
downloadopenttd-356954ca263bb27119453788c3dcdc38eb6b5ca9.tar.xz
(svn r5465) -Feature: [autoreplace] replacing from a train engine without cargo capacity to one with cargo capacity will now make autoreplace refit the engine to carry the cargo type from the last wagon in the train
if the train is carrying the type of cargo, that is default for the engine, it will not be refitted if the last wagon do not carry cargo, the refit will be to the type of the last wagon, that do carry cargo
Diffstat (limited to 'vehicle.c')
-rw-r--r--vehicle.c26
1 files changed, 24 insertions, 2 deletions
diff --git a/vehicle.c b/vehicle.c
index 9674a2a99..b78cfad79 100644
--- a/vehicle.c
+++ b/vehicle.c
@@ -1659,13 +1659,35 @@ static int32 ReplaceVehicle(Vehicle **w, byte flags)
if (flags & DC_EXEC) {
new_v = GetVehicle(_new_vehicle_id);
*w = new_v; //we changed the vehicle, so MaybeReplaceVehicle needs to work on the new one. Now we tell it what the new one is
+ CargoID new_cargo_type = old_v->cargo_type;
/* refit if needed */
- if (old_v->cargo_type != new_v->cargo_type && old_v->cargo_cap != 0 && new_v->cargo_cap != 0) {// some train engines do not have cargo capacity
+ if (old_v->type == VEH_Train && old_v->cargo_cap == 0 && new_v->cargo_cap != 0) {
+ // the old engine didn't have cargo capacity, but the new one does
+ // now we will figure out what cargo the train is carrying and refit to fit this
+ Vehicle *v = old_v;
+ CargoID cargo_type_buffer = new_v->cargo_type;
+ printf("A: %d\n", cargo_type_buffer);
+ do {
+ if (v->cargo_cap == 0) continue;
+ printf("B: %d\n", cargo_type_buffer);
+ if (v->cargo_type == new_v->cargo_type) {
+ // the default type is already being carried on the train. No need to refit
+ cargo_type_buffer = new_v->cargo_type;
+ break;
+ }
+ printf("C: %d\n", cargo_type_buffer);
+ // now we know that the vehicle is carrying cargo and that it's not the same as
+ cargo_type_buffer = v->cargo_type;
+ } while ((v=v->next) != NULL);
+ new_cargo_type = cargo_type_buffer;
+ }
+
+ if (new_cargo_type != new_v->cargo_type && new_v->cargo_cap != 0) {
// we add the refit cost to cost, so it's added to the cost animation
// it's not in the calculation of having enough money to actually do the replace since it's rather hard to do by design, but since
// we pay for it, it's nice to make the cost animation include it
- int32 temp_cost = DoCommand(0, new_v->index, old_v->cargo_type, DC_EXEC, CMD_REFIT_VEH(new_v->type));
+ int32 temp_cost = DoCommand(0, new_v->index, new_cargo_type, DC_EXEC, CMD_REFIT_VEH(new_v->type));
if (!CmdFailed(temp_cost)) cost += temp_cost;
}
if (new_v->type == VEH_Train && HASBIT(old_v->u.rail.flags, VRF_REVERSE_DIRECTION) && !IsMultiheaded(new_v) && !(new_v->next != NULL && IsArticulatedPart(new_v->next))) {