* Update a level crossing to barred or open (crossing may include multiple adjacent tiles). * @param tile Tile which causes the update. * @param sound Should we play sound? * @param force_bar Should we force the crossing to be barred? */
| 1789 | * @param force_bar Should we force the crossing to be barred? |
| 1790 | */ |
| 1791 | void UpdateLevelCrossing(TileIndex tile, bool sound, bool force_bar) |
| 1792 | { |
| 1793 | if (!IsLevelCrossingTile(tile)) return; |
| 1794 | |
| 1795 | bool forced_state = force_bar; |
| 1796 | |
| 1797 | const Axis axis = GetCrossingRoadAxis(tile); |
| 1798 | const DiagDirection dir1 = AxisToDiagDir(axis); |
| 1799 | const DiagDirection dir2 = ReverseDiagDir(dir1); |
| 1800 | |
| 1801 | /* Check if an adjacent crossing is barred. */ |
| 1802 | for (DiagDirection dir : { dir1, dir2 }) { |
| 1803 | for (TileIndex t = tile; !forced_state && t < Map::Size() && IsLevelCrossingTile(t) && GetCrossingRoadAxis(t) == axis; t = TileAddByDiagDir(t, dir)) { |
| 1804 | forced_state |= CheckLevelCrossing(t); |
| 1805 | } |
| 1806 | } |
| 1807 | |
| 1808 | /* Now that we know whether all tiles in this crossing should be barred or open, |
| 1809 | * we need to update those tiles. We start with the tile itself, then look along the road axis. */ |
| 1810 | UpdateLevelCrossingTile(tile, sound, forced_state); |
| 1811 | for (DiagDirection dir : { dir1, dir2 }) { |
| 1812 | for (TileIndex t = TileAddByDiagDir(tile, dir); t < Map::Size() && IsLevelCrossingTile(t) && GetCrossingRoadAxis(t) == axis; t = TileAddByDiagDir(t, dir)) { |
| 1813 | UpdateLevelCrossingTile(t, sound, forced_state); |
| 1814 | } |
| 1815 | } |
| 1816 | } |
| 1817 | |
| 1818 | /** |
| 1819 | * Find adjacent level crossing tiles in this multi-track crossing and mark them dirty. |
no test coverage detected