1
0
mirror of https://github.com/OpenTTD/OpenTTD.git synced 2025-08-12 09:09:09 +00:00

Codechange: Iterate with VehiclesOnTile when attaching a just bought wagon to a locomotive (#14284)

This commit is contained in:
SamuXarick
2025-06-08 21:45:58 +01:00
committed by GitHub
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;
}