Fix #10502: Refit engine before attaching free wagons. (#10926)

Caused by incorrect order of operations when buying a train engine with refit and attaching free wagons.
This commit is contained in:
PeterN
2023-06-04 15:57:36 +01:00
committed by GitHub
parent 87ccff16b5
commit ee2d0745e9
4 changed files with 10 additions and 9 deletions

View File

@@ -135,7 +135,7 @@ std::tuple<CommandCost, VehicleID, uint, uint16, CargoArray> CmdBuildVehicle(DoC
Vehicle *v = nullptr;
switch (type) {
case VEH_TRAIN: value.AddCost(CmdBuildRailVehicle(subflags, tile, e, use_free_vehicles, &v)); break;
case VEH_TRAIN: value.AddCost(CmdBuildRailVehicle(subflags, tile, e, &v)); break;
case VEH_ROAD: value.AddCost(CmdBuildRoadVehicle(subflags, tile, e, &v)); break;
case VEH_SHIP: value.AddCost(CmdBuildShip (subflags, tile, e, &v)); break;
case VEH_AIRCRAFT: value.AddCost(CmdBuildAircraft (subflags, tile, e, &v)); break;
@@ -172,6 +172,11 @@ std::tuple<CommandCost, VehicleID, uint, uint16, CargoArray> CmdBuildVehicle(DoC
}
if (flags & DC_EXEC) {
if (type == VEH_TRAIN && use_free_vehicles && !(flags & DC_AUTOREPLACE)) {
/* Move any free wagons to the new vehicle. */
NormalizeTrainVehInDepot(Train::From(v));
}
InvalidateWindowData(WC_VEHICLE_DEPOT, v->tile);
InvalidateWindowClassesData(GetWindowClassForVehicleType(type), 0);
SetWindowDirty(WC_COMPANY, _current_company);