diff --git a/src/articulated_vehicles.cpp b/src/articulated_vehicles.cpp index 004ec87135..ea86b6130a 100644 --- a/src/articulated_vehicles.cpp +++ b/src/articulated_vehicles.cpp @@ -305,6 +305,19 @@ bool IsArticulatedVehicleCarryingDifferentCargoes(const Vehicle *v, CargoID *car return false; } +/** + * Returns the overall cargo of an articulated vehicle if all parts are refitted to the same cargo. + * Note: Vehicles not carrying anything are ignored + * @param v the first vehicle in the chain + * @return the common CargoID. (CT_INVALID if no part is carrying something or they are carrying different things) + */ +CargoID GetOverallCargoOfArticulatedVehicle(const Vehicle *v) +{ + CargoID cargo_id; + IsArticulatedVehicleCarryingDifferentCargoes(v, &cargo_id); + return cargo_id; +} + /** * Checks whether the specs of freshly build articulated vehicles are consistent with the information specified in the purchase list. * Only essential information is checked to leave room for magic tricks/workarounds to grfcoders. diff --git a/src/articulated_vehicles.h b/src/articulated_vehicles.h index 551d930b8a..559a82cb2c 100644 --- a/src/articulated_vehicles.h +++ b/src/articulated_vehicles.h @@ -22,6 +22,7 @@ void GetArticulatedRefitMasks(EngineID engine, bool include_initial_cargo_type, CargoTypes GetUnionOfArticulatedRefitMasks(EngineID engine, bool include_initial_cargo_type); CargoTypes GetIntersectionOfArticulatedRefitMasks(EngineID engine, bool include_initial_cargo_type); bool IsArticulatedVehicleCarryingDifferentCargoes(const Vehicle *v, CargoID *cargo_type); +CargoID GetOverallCargoOfArticulatedVehicle(const Vehicle *v); bool IsArticulatedVehicleRefittable(EngineID engine); bool IsArticulatedEngine(EngineID engine_type); void CheckConsistencyOfArticulatedVehicle(const Vehicle *v); diff --git a/src/economy.cpp b/src/economy.cpp index cc471681ce..52649dbd7a 100644 --- a/src/economy.cpp +++ b/src/economy.cpp @@ -1762,7 +1762,7 @@ static void HandleStationRefit(Vehicle *v, CargoArray &consist_capleft, Station } /* Refit if given a valid cargo. */ - if (new_cid < NUM_CARGO && new_cid != v_start->cargo_type) { + if (new_cid < NUM_CARGO && new_cid != GetOverallCargoOfArticulatedVehicle(v_start)) { /* INVALID_STATION because in the DT_MANUAL case that's correct and in the DT_(A)SYMMETRIC * cases the next hop of the vehicle doesn't really tell us anything if the cargo had been * "via any station" before reserving. We rather produce some more "any station" cargo than