summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorsmatz <smatz@openttd.org>2008-01-18 21:44:20 +0000
committersmatz <smatz@openttd.org>2008-01-18 21:44:20 +0000
commitf05caedf7c7b8a0d6ce9e2d84baf91401dfa090f (patch)
tree1c7cca64b5c71e2808004a67556fb138b62c8b8f
parentf6684c9afd4159cad775c2aa83d7b49c25207ec6 (diff)
downloadopenttd-f05caedf7c7b8a0d6ce9e2d84baf91401dfa090f.tar.xz
(svn r11922) -Codechange: use MaybeBarCrossingWithSound() to bar crossing with sound
-rw-r--r--src/train_cmd.cpp23
1 files changed, 17 insertions, 6 deletions
diff --git a/src/train_cmd.cpp b/src/train_cmd.cpp
index 820b8731c..554fb65b5 100644
--- a/src/train_cmd.cpp
+++ b/src/train_cmd.cpp
@@ -1704,6 +1704,21 @@ void UpdateLevelCrossing(TileIndex tile, bool sound)
/**
+ * Bars crossing and plays ding-ding sound if not barred already
+ * @param tile tile with crossing
+ * @pre tile is a rail-road crossing
+ */
+static inline void MaybeBarCrossingWithSound(TileIndex tile)
+{
+ if (!IsCrossingBarred(tile)) {
+ BarCrossing(tile);
+ SndPlayTileFx(SND_0E_LEVEL_CROSSING, tile);
+ MarkTileDirtyByTile(tile);
+ }
+}
+
+
+/**
* Advances wagons for train reversing, needed for variable length wagons.
* Needs to be called once before the train is reversed, and once after it.
* @param v First vehicle in chain
@@ -1780,7 +1795,7 @@ static void ReverseTrainDirection(Vehicle *v)
/* maybe we are approaching crossing now, after reversal */
crossing = TrainApproachingCrossingTile(v);
- if (crossing != INVALID_TILE) UpdateLevelCrossing(crossing);
+ if (crossing != INVALID_TILE) MaybeBarCrossingWithSound(crossing);
}
/** Reverse train.
@@ -3459,11 +3474,7 @@ static bool TrainCheckIfLineEnds(Vehicle *v)
if ((ts & (ts >> 16)) != 0) return TrainApproachingLineEnd(v, true);
/* approaching a rail/road crossing? then make it red */
- if (IsLevelCrossingTile(tile) && !IsCrossingBarred(tile)) {
- BarCrossing(tile);
- SndPlayTileFx(SND_0E_LEVEL_CROSSING, tile);
- MarkTileDirtyByTile(tile);
- }
+ if (IsLevelCrossingTile(tile)) MaybeBarCrossingWithSound(tile);
return true;
}