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

Function UpdateLevelCrossing

src/train_cmd.cpp:1791–1816  ·  view source on GitHub ↗

* 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? */

Source from the content-addressed store, hash-verified

1789 * @param force_bar Should we force the crossing to be barred?
1790 */
1791void 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.

Callers 11

CmdBuildSingleRailFunction · 0.85
TryReserveRailTrackFunction · 0.85
UnreserveRailTrackFunction · 0.85
ReverseTrainDirectionFunction · 0.85
CrashMethod · 0.85
TrainControllerFunction · 0.85
DeleteLastWagonFunction · 0.85
CmdBuildRoadFunction · 0.85
AfterLoadGameFunction · 0.85

Calls 7

IsLevelCrossingTileFunction · 0.85
GetCrossingRoadAxisFunction · 0.85
AxisToDiagDirFunction · 0.85
ReverseDiagDirFunction · 0.85
TileAddByDiagDirFunction · 0.85
CheckLevelCrossingFunction · 0.85
UpdateLevelCrossingTileFunction · 0.85

Tested by

no test coverage detected