mirror of
https://github.com/OpenTTD/OpenTTD.git
synced 2025-08-21 21:49:10 +00:00
Codechange: Iterate with VehiclesOnTile when moving free wagons to the new vehicle
This commit is contained in:
@@ -692,12 +692,19 @@ static CommandCost CmdBuildRailWagon(DoCommandFlags flags, TileIndex tile, const
|
|||||||
void NormalizeTrainVehInDepot(const Train *u)
|
void NormalizeTrainVehInDepot(const Train *u)
|
||||||
{
|
{
|
||||||
assert(u->IsEngine());
|
assert(u->IsEngine());
|
||||||
for (const Train *v : Train::Iterate()) {
|
std::vector<VehicleID> freewagons;
|
||||||
if (v->IsFreeWagon() && v->tile == u->tile &&
|
for (const Vehicle *w : VehiclesOnTile(u->tile)) {
|
||||||
v->track == TRACK_BIT_DEPOT) {
|
if (w->type != VEH_TRAIN) continue;
|
||||||
if (Command<CMD_MOVE_RAIL_VEHICLE>::Do(DoCommandFlag::Execute, v->index, u->index, true).Failed()) {
|
|
||||||
break;
|
const Train *v = Train::From(w);
|
||||||
}
|
if (v->IsFreeWagon() && v->track == TRACK_BIT_DEPOT) {
|
||||||
|
freewagons.push_back(v->index);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
std::ranges::sort(freewagons);
|
||||||
|
for (VehicleID veh_id : freewagons) {
|
||||||
|
if (Command<CMD_MOVE_RAIL_VEHICLE>::Do(DoCommandFlag::Execute, veh_id, u->index, true).Failed()) {
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user