Find the best matching vehicle on a tile. */
| 265 | |
| 266 | /** Find the best matching vehicle on a tile. */ |
| 267 | static 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. |
no test coverage detected