MCPcopy Create free account
hub / github.com/OpenTTD/OpenTTD / CheckTrainsOnTrack

Function CheckTrainsOnTrack

src/pbs.cpp:267–280  ·  view source on GitHub ↗

Find the best matching vehicle on a tile. */

Source from the content-addressed store, hash-verified

265
266/** Find the best matching vehicle on a tile. */
267static void CheckTrainsOnTrack(FindTrainOnTrackInfo &info, TileIndex tile)
268{
269 for (Vehicle *v : VehiclesOnTile(tile)) {
270 if (v->type != VEH_TRAIN || v->vehstatus.Test(VehState::Crashed)) continue;
271
272 Train *t = Train::From(v);
273 if (t->track == TRACK_BIT_WORMHOLE || HasBit(static_cast<TrackBits>(t->track), TrackdirToTrack(info.res.trackdir))) {
274 t = t->First();
275
276 /* ALWAYS return the lowest ID (anti-desync!) */
277 if (info.best == nullptr || t->index < info.best->index) info.best = t;
278 }
279 }
280}
281
282/**
283 * Follow a train reservation to the last tile.

Callers 2

FollowTrainReservationFunction · 0.85
GetTrainForReservationFunction · 0.85

Calls 5

VehiclesOnTileClass · 0.85
HasBitFunction · 0.85
TrackdirToTrackFunction · 0.85
TestMethod · 0.80
FirstMethod · 0.45

Tested by

no test coverage detected