TBTR: Close vehicles window when acquiring idle vehicle for replacement

This fixes possible duplicate vehicle windows, which is not allowed
This commit is contained in:
Jonathan G Rennison
2021-01-10 18:44:44 +00:00
parent e4555a1749
commit d666036ffd

View File

@@ -5606,6 +5606,20 @@ CommandCost CmdBuildVirtualRailVehicle(TileIndex tile, DoCommandFlag flags, uint
return CommandCost(); return CommandCost();
} }
void ClearVehicleWindows(const Train *v)
{
if (v->IsPrimaryVehicle()) {
DeleteWindowById(WC_VEHICLE_VIEW, v->index);
DeleteWindowById(WC_VEHICLE_ORDERS, v->index);
DeleteWindowById(WC_VEHICLE_REFIT, v->index);
DeleteWindowById(WC_VEHICLE_DETAILS, v->index);
DeleteWindowById(WC_VEHICLE_TIMETABLE, v->index);
DeleteWindowById(WC_SCHDISPATCH_SLOTS, v->index);
DeleteWindowById(WC_VEHICLE_CARGO_TYPE_LOAD_ORDERS, v->index);
DeleteWindowById(WC_VEHICLE_CARGO_TYPE_UNLOAD_ORDERS, v->index);
}
}
/** /**
* Replace a vehicle based on a template replacement order. * Replace a vehicle based on a template replacement order.
* @param tile unused * @param tile unused
@@ -5715,10 +5729,12 @@ CommandCost CmdTemplateReplaceVehicle(TileIndex tile, DoCommandFlag flags, uint3
} else if ((tmp_chain = ChainContainsEngine(eid, incoming)) && tmp_chain != nullptr) { // 2 } else if ((tmp_chain = ChainContainsEngine(eid, incoming)) && tmp_chain != nullptr) { // 2
// new_chain is the needed engine, move it to an empty spot in the depot // new_chain is the needed engine, move it to an empty spot in the depot
new_chain = tmp_chain; new_chain = tmp_chain;
if (flags & DC_EXEC) ClearVehicleWindows(tmp_chain);
move_cost.AddCost(DoCommand(tile, new_chain->index, INVALID_VEHICLE, flags, CMD_MOVE_RAIL_VEHICLE)); move_cost.AddCost(DoCommand(tile, new_chain->index, INVALID_VEHICLE, flags, CMD_MOVE_RAIL_VEHICLE));
remainder_chain = incoming; remainder_chain = incoming;
} else if (reuseDepot && (tmp_chain = DepotContainsEngine(tile, eid, incoming)) && tmp_chain != nullptr) { // 3 } else if (reuseDepot && (tmp_chain = DepotContainsEngine(tile, eid, incoming)) && tmp_chain != nullptr) { // 3
new_chain = tmp_chain; new_chain = tmp_chain;
if (flags & DC_EXEC) ClearVehicleWindows(tmp_chain);
move_cost.AddCost(DoCommand(tile, new_chain->index, INVALID_VEHICLE, flags, CMD_MOVE_RAIL_VEHICLE)); move_cost.AddCost(DoCommand(tile, new_chain->index, INVALID_VEHICLE, flags, CMD_MOVE_RAIL_VEHICLE));
remainder_chain = incoming; remainder_chain = incoming;
} else { // 4 } else { // 4