summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--road_cmd.c9
-rw-r--r--road_map.h14
-rw-r--r--train_cmd.c8
3 files changed, 22 insertions, 9 deletions
diff --git a/road_cmd.c b/road_cmd.c
index 82284a7f9..fcc7ecd7a 100644
--- a/road_cmd.c
+++ b/road_cmd.c
@@ -776,7 +776,7 @@ static void DrawTile_Road(TileInfo *ti)
if (GetCrossingRoadAxis(ti->tile) == AXIS_X) image++;
- if ((ti->map5 & 4) != 0) image += 2;
+ if (IsCrossingBarred(ti->tile)) image += 2;
if ( _m[ti->tile].m4 & 0x80) {
image += 8;
@@ -1059,10 +1059,10 @@ static uint32 VehicleEnter_Road(Vehicle *v, TileIndex tile, int x, int y)
{
switch (GetRoadType(tile)) {
case ROAD_CROSSING:
- if (v->type == VEH_Train && GB(_m[tile].m5, 2, 1) == 0) {
+ if (v->type == VEH_Train && !IsCrossingBarred(tile)) {
/* train crossing a road */
SndPlayVehicleFx(SND_0E_LEVEL_CROSSING, v);
- SB(_m[tile].m5, 2, 1, 1);
+ BarCrossing(tile);
MarkTileDirtyByTile(tile);
}
break;
@@ -1084,8 +1084,7 @@ static uint32 VehicleEnter_Road(Vehicle *v, TileIndex tile, int x, int y)
static void VehicleLeave_Road(Vehicle *v, TileIndex tile, int x, int y)
{
if (IsLevelCrossing(tile) && v->type == VEH_Train && v->next == NULL) {
- // Turn off level crossing lights
- SB(_m[tile].m5, 2, 1, 0);
+ UnbarCrossing(tile);
MarkTileDirtyByTile(tile);
}
}
diff --git a/road_map.h b/road_map.h
index feb7656cb..412616a65 100644
--- a/road_map.h
+++ b/road_map.h
@@ -66,6 +66,20 @@ static inline void SetCrossingRoadOwner(TileIndex t, Owner o)
_m[t].m3 = o;
}
+static inline void UnbarCrossing(TileIndex t)
+{
+ CLRBIT(_m[t].m5, 2);
+}
+
+static inline void BarCrossing(TileIndex t)
+{
+ SETBIT(_m[t].m5, 2);
+}
+
+static inline bool IsCrossingBarred(TileIndex t)
+{
+ return HASBIT(_m[t].m5, 2);
+}
typedef enum RoadType {
ROAD_NORMAL,
diff --git a/train_cmd.c b/train_cmd.c
index e9c58bae9..354b86aea 100644
--- a/train_cmd.c
+++ b/train_cmd.c
@@ -1482,8 +1482,8 @@ static void DisableTrainCrossing(TileIndex tile)
if (IsTileType(tile, MP_STREET) &&
IsLevelCrossing(tile) &&
VehicleFromPos(tile, &tile, TestTrainOnCrossing) == NULL && // empty?
- GB(_m[tile].m5, 2, 1) != 0) { // Lights on?
- SB(_m[tile].m5, 2, 1, 0); // Switch lights off
+ IsCrossingBarred(tile)) {
+ UnbarCrossing(tile);
MarkTileDirtyByTile(tile);
}
}
@@ -3206,8 +3206,8 @@ static bool TrainCheckIfLineEnds(Vehicle *v)
if ((ts &= (ts >> 16)) == 0) {
// make a rail/road crossing red
if (IsTileType(tile, MP_STREET) && IsLevelCrossing(tile)) {
- if (GB(_m[tile].m5, 2, 1) == 0) {
- SB(_m[tile].m5, 2, 1, 1);
+ if (!IsCrossingBarred(tile)) {
+ BarCrossing(tile);
SndPlayVehicleFx(SND_0E_LEVEL_CROSSING, v);
MarkTileDirtyByTile(tile);
}