mirror of
https://github.com/OpenTTD/OpenTTD.git
synced 2025-08-27 00:19:09 +00:00
Codechange: Iterate with VehiclesOnTile when moving rail vehicle in a depot
This commit is contained in:
@@ -827,18 +827,25 @@ static Train *FindGoodVehiclePos(const Train *src)
|
|||||||
EngineID eng = src->engine_type;
|
EngineID eng = src->engine_type;
|
||||||
TileIndex tile = src->tile;
|
TileIndex tile = src->tile;
|
||||||
|
|
||||||
for (Train *dst : Train::Iterate()) {
|
Train *pos = nullptr;
|
||||||
if (dst->IsFreeWagon() && dst->tile == tile && !dst->vehstatus.Test(VehState::Crashed)) {
|
for (Vehicle *v : VehiclesOnTile(tile)) {
|
||||||
|
if (v->type != VEH_TRAIN) continue;
|
||||||
|
|
||||||
|
Train *dst = Train::From(v);
|
||||||
|
if (dst->IsFreeWagon() && !dst->vehstatus.Test(VehState::Crashed)) {
|
||||||
/* check so all vehicles in the line have the same engine. */
|
/* check so all vehicles in the line have the same engine. */
|
||||||
Train *t = dst;
|
Train *t = dst;
|
||||||
while (t->engine_type == eng) {
|
while (t->engine_type == eng) {
|
||||||
t = t->Next();
|
t = t->Next();
|
||||||
if (t == nullptr) return dst;
|
if (t == nullptr && (pos == nullptr || pos->index > dst->index)) {
|
||||||
|
pos = dst;
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return nullptr;
|
return pos;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Helper type for lists/vectors of trains */
|
/** Helper type for lists/vectors of trains */
|
||||||
|
Reference in New Issue
Block a user