Fix refit in station with articulated vehicles with no capacity in leading part

pull/556/head
Jonathan G Rennison 1 year ago
parent dadebfa759
commit 846737e56a

@ -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.

@ -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);

@ -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

Loading…
Cancel
Save