* Determines whether train is approaching a rail-road crossing * (thus making it barred) * @param v front engine of train * @return TileIndex of crossing the train is approaching, else INVALID_TILE * @pre v in non-crashed front engine */
| 3867 | * @pre v in non-crashed front engine |
| 3868 | */ |
| 3869 | static TileIndex TrainApproachingCrossingTile(const Train *v) |
| 3870 | { |
| 3871 | assert(v->IsFrontEngine()); |
| 3872 | assert(!v->vehstatus.Test(VehState::Crashed)); |
| 3873 | |
| 3874 | if (!TrainCanLeaveTile(v)) return INVALID_TILE; |
| 3875 | |
| 3876 | DiagDirection dir = VehicleExitDir(v->direction, v->track); |
| 3877 | TileIndex tile = v->tile + TileOffsByDiagDir(dir); |
| 3878 | |
| 3879 | /* not a crossing || wrong axis || unusable rail (wrong type or owner) */ |
| 3880 | if (!IsLevelCrossingTile(tile) || DiagDirToAxis(dir) == GetCrossingRoadAxis(tile) || |
| 3881 | !CheckCompatibleRail(v, tile)) { |
| 3882 | return INVALID_TILE; |
| 3883 | } |
| 3884 | |
| 3885 | return tile; |
| 3886 | } |
| 3887 | |
| 3888 | |
| 3889 | /** |
no test coverage detected