mirror of
https://github.com/OpenTTD/OpenTTD.git
synced 2025-06-18 19:19:29 +01:00
Codechange: Iterate with VehiclesOnTile when attaching a just bought wagon to a locomotive (#14284)
This commit is contained in:
parent
de660cba02
commit
893a75f2c0
@ -32,8 +32,13 @@ void CcBuildWagon(Commands, const CommandCost &result, VehicleID new_veh_id, uin
|
||||
|
||||
/* find a locomotive in the depot. */
|
||||
const Vehicle *found = nullptr;
|
||||
for (const Train *t : Train::Iterate()) {
|
||||
if (t->IsFrontEngine() && t->tile == tile && t->IsStoppedInDepot()) {
|
||||
/* The non-deterministic order returned from VehiclesOnTile() does not
|
||||
* matter here as there must only be one locomotive for anything to happen. */
|
||||
for (const Vehicle *v : VehiclesOnTile(tile)) {
|
||||
if (v->type != VEH_TRAIN) continue;
|
||||
|
||||
const Train *t = Train::From(v);
|
||||
if (t->IsFrontEngine() && t->IsStoppedInDepot()) {
|
||||
if (found != nullptr) return; // must be exactly one.
|
||||
found = t;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user