summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/openttd.cpp2
-rw-r--r--src/rail_cmd.cpp2
-rw-r--r--src/road_cmd.cpp2
-rw-r--r--src/road_func.h2
-rw-r--r--src/road_map.h19
-rw-r--r--src/train_cmd.cpp19
6 files changed, 26 insertions, 20 deletions
diff --git a/src/openttd.cpp b/src/openttd.cpp
index b1753490a..cff06481b 100644
--- a/src/openttd.cpp
+++ b/src/openttd.cpp
@@ -2317,7 +2317,7 @@ bool AfterLoadGame()
if (CheckSavegameVersion(86)) {
/* Now all crossings should be in correct state */
for (TileIndex t = 0; t < map_size; t++) {
- if (IsLevelCrossingTile(t)) UpdateLevelCrossing(t);
+ if (IsLevelCrossingTile(t)) UpdateLevelCrossing(t, false);
}
}
diff --git a/src/rail_cmd.cpp b/src/rail_cmd.cpp
index 3e9b94cc9..3c39cf266 100644
--- a/src/rail_cmd.cpp
+++ b/src/rail_cmd.cpp
@@ -383,7 +383,7 @@ CommandCost CmdBuildSingleRail(TileIndex tile, uint32 flags, uint32 p1, uint32 p
(track == TRACK_Y && road == ROAD_X)) {
if (flags & DC_EXEC) {
MakeRoadCrossing(tile, GetRoadOwner(tile, ROADTYPE_ROAD), GetRoadOwner(tile, ROADTYPE_TRAM), GetRoadOwner(tile, ROADTYPE_HWAY), _current_player, (track == TRACK_X ? AXIS_Y : AXIS_X), railtype, roadtypes, GetTownIndex(tile));
- UpdateLevelCrossing(tile);
+ UpdateLevelCrossing(tile, false);
}
break;
}
diff --git a/src/road_cmd.cpp b/src/road_cmd.cpp
index ee530a225..ac60aafa1 100644
--- a/src/road_cmd.cpp
+++ b/src/road_cmd.cpp
@@ -487,7 +487,7 @@ CommandCost CmdBuildRoad(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
YapfNotifyTrackLayoutChange(tile, FindFirstTrack(GetTrackBits(tile)));
/* Always add road to the roadtypes (can't draw without it) */
MakeRoadCrossing(tile, _current_player, _current_player, _current_player, GetTileOwner(tile), roaddir, GetRailType(tile), RoadTypeToRoadTypes(rt) | ROADTYPES_ROAD, p2);
- UpdateLevelCrossing(tile);
+ UpdateLevelCrossing(tile, false);
MarkTileDirtyByTile(tile);
}
return CommandCost(EXPENSES_CONSTRUCTION, _price.build_road * (rt == ROADTYPE_ROAD ? 2 : 4));
diff --git a/src/road_func.h b/src/road_func.h
index a93e1af78..3139ea022 100644
--- a/src/road_func.h
+++ b/src/road_func.h
@@ -136,6 +136,6 @@ bool ValParamRoadType(const RoadType rt);
*/
RoadTypes GetPlayerRoadtypes(const PlayerID p);
-void UpdateLevelCrossing(TileIndex tile);
+void UpdateLevelCrossing(TileIndex tile, bool sound = true);
#endif /* ROAD_FUNC_H */
diff --git a/src/road_map.h b/src/road_map.h
index 5d5d5dd5d..705961b95 100644
--- a/src/road_map.h
+++ b/src/road_map.h
@@ -191,23 +191,26 @@ static inline TrackBits GetCrossingRailBits(TileIndex tile)
return AxisToTrackBits(OtherAxis(GetCrossingRoadAxis(tile)));
}
-
-static inline void UnbarCrossing(TileIndex t)
+static inline bool IsCrossingBarred(TileIndex t)
{
assert(GetRoadTileType(t) == ROAD_TILE_CROSSING);
- ClrBit(_m[t].m4, 5);
+ return HasBit(_m[t].m4, 5);
}
-static inline void BarCrossing(TileIndex t)
+static inline void SetCrossingBarred(TileIndex t, bool barred)
{
assert(GetRoadTileType(t) == ROAD_TILE_CROSSING);
- SetBit(_m[t].m4, 5);
+ SB(_m[t].m4, 5, 1, barred);
}
-static inline bool IsCrossingBarred(TileIndex t)
+static inline void UnbarCrossing(TileIndex t)
{
- assert(GetRoadTileType(t) == ROAD_TILE_CROSSING);
- return HasBit(_m[t].m4, 5);
+ SetCrossingBarred(t, false);
+}
+
+static inline void BarCrossing(TileIndex t)
+{
+ SetCrossingBarred(t, true);
}
#define IsOnDesert IsOnSnow
diff --git a/src/train_cmd.cpp b/src/train_cmd.cpp
index 68c5080f2..ad6a8afe3 100644
--- a/src/train_cmd.cpp
+++ b/src/train_cmd.cpp
@@ -1683,20 +1683,23 @@ static Vehicle *TrainApproachingCrossing(TileIndex tile)
/**
* Sets correct crossing state
* @param tile tile to update
+ * @param sound should we play sound?
* @pre tile is a rail-road crossing
*/
-void UpdateLevelCrossing(TileIndex tile)
+void UpdateLevelCrossing(TileIndex tile, bool sound)
{
assert(IsLevelCrossingTile(tile));
- UnbarCrossing(tile);
-
/* train on crossing || train approaching crossing */
- if (VehicleFromPos(tile, NULL, &TrainOnTileEnum) || TrainApproachingCrossing(tile)) {
- BarCrossing(tile);
- }
+ bool new_state = VehicleFromPos(tile, NULL, &TrainOnTileEnum) || TrainApproachingCrossing(tile);
- MarkTileDirtyByTile(tile);
+ if (new_state != IsCrossingBarred(tile)) {
+ if (new_state && sound) {
+ SndPlayTileFx(SND_0E_LEVEL_CROSSING, tile);
+ }
+ SetCrossingBarred(tile, new_state);
+ MarkTileDirtyByTile(tile);
+ }
}
@@ -3458,7 +3461,7 @@ static bool TrainCheckIfLineEnds(Vehicle *v)
/* approaching a rail/road crossing? then make it red */
if (IsLevelCrossingTile(tile) && !IsCrossingBarred(tile)) {
BarCrossing(tile);
- SndPlayVehicleFx(SND_0E_LEVEL_CROSSING, v);
+ SndPlayTileFx(SND_0E_LEVEL_CROSSING, tile);
MarkTileDirtyByTile(tile);
}