summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDarkvater <darkvater@openttd.org>2005-06-07 21:37:00 +0000
committerDarkvater <darkvater@openttd.org>2005-06-07 21:37:00 +0000
commit0171aae10965259aa146749b0bd6e47ad9d3e4f7 (patch)
tree25e2a197e45756770b59b3d230e466026cb1ca95
parentfa8f46c0b7f4723c12ddefd77d619ca98b6c7c6c (diff)
downloadopenttd-0171aae10965259aa146749b0bd6e47ad9d3e4f7.tar.xz
(svn r2433) - CodeChange: unmagicify all road/train crossings with IsLevelCrossing() function (peter1138)
-rw-r--r--ai.c2
-rw-r--r--npf.c2
-rw-r--r--openttd.c2
-rw-r--r--rail_cmd.c2
-rw-r--r--road_cmd.c23
-rw-r--r--roadveh_cmd.c5
-rw-r--r--tile.h5
-rw-r--r--town_cmd.c2
-rw-r--r--train_cmd.c4
9 files changed, 26 insertions, 21 deletions
diff --git a/ai.c b/ai.c
index 4f0b3ea4f..09ca26fc6 100644
--- a/ai.c
+++ b/ai.c
@@ -3700,7 +3700,7 @@ pos_3:
} else if (IsTileType(tile, MP_STREET)) {
if (!IsTileOwner(tile, _current_player)) return;
- if ( (_map5[tile]&0xF0) == 0x10)
+ if (IsLevelCrossing(tile))
goto is_rail_crossing;
if ( (_map5[tile]&0xF0) == 0x20) {
diff --git a/npf.c b/npf.c
index 0c24c0592..c3d0f0bef 100644
--- a/npf.c
+++ b/npf.c
@@ -484,7 +484,7 @@ static inline RailType GetTileRailType(TileIndex tile, byte trackdir)
break;
case MP_STREET:
/* rail/road crossing */
- if ((_map5[tile] & 0xF0) == 0x10)
+ if (IsLevelCrossing(tile))
type = _map3_hi[tile] & RAILTYPE_MASK;
break;
case MP_STATION:
diff --git a/openttd.c b/openttd.c
index c1205eda3..cedffb08a 100644
--- a/openttd.c
+++ b/openttd.c
@@ -1185,7 +1185,7 @@ static void ConvertTownOwner(void)
for (tile = 0; tile != MapSize(); tile++) {
if (IsTileType(tile, MP_STREET)) {
- if ((_map5[tile] & 0xF0) == 0x10 && _map3_lo[tile] & 0x80)
+ if (IsLevelCrossing(tile) && _map3_lo[tile] & 0x80)
_map3_lo[tile] = OWNER_TOWN;
if (_map_owner[tile] & 0x80) SetTileOwner(tile, OWNER_TOWN);
diff --git a/rail_cmd.c b/rail_cmd.c
index edc8345b2..0fcec1455 100644
--- a/rail_cmd.c
+++ b/rail_cmd.c
@@ -374,7 +374,7 @@ int32 CmdBuildSingleRail(int x, int y, uint32 flags, uint32 p1, uint32 p2)
break;
}
- if ((m5 & 0xF0) == 0x10 && (m5 & 0x08 ? 1 : 2) == rail_bit)
+ if (IsLevelCrossing(tile) == 0x10 && (m5 & 0x08 ? 1 : 2) == rail_bit)
return_cmd_error(STR_1007_ALREADY_BUILT);
/* FALLTHROUGH */
diff --git a/road_cmd.c b/road_cmd.c
index f48fb4461..ad59a0936 100644
--- a/road_cmd.c
+++ b/road_cmd.c
@@ -32,7 +32,7 @@ static bool HasTileRoadAt(uint tile, int i)
b = _map5[tile];
if ((b & 0xF0) == 0) {
- } else if ((b & 0xF0) == 0x10) {
+ } else if (IsLevelCrossing(tile)) {
b = (b&8)?5:10;
} else if ((b & 0xF0) == 0x20) {
return (~b & 3) == i;
@@ -78,7 +78,7 @@ static bool CheckAllowRemoveRoad(uint tile, uint br, bool *edge_road)
return true;
// A railway crossing has the road owner in the map3_lo byte.
- if (IsTileType(tile, MP_STREET) && (_map5[tile] & 0xF0) == 0x10) {
+ if (IsTileType(tile, MP_STREET) && IsLevelCrossing(tile)) {
owner = _map3_lo[tile];
} else {
owner = GetTileOwner(tile);
@@ -154,7 +154,7 @@ int32 CmdRemoveRoad(int x, int y, uint32 flags, uint32 p1, uint32 p2)
// owner for railraod crossing is stored somewhere else
// XXX - Fix this so for a given tiletype the owner of the type is in the same variable
- if (IsTileType(tile, MP_STREET) && (_map5[tile] & 0xF0) == 0x10) {
+ if (IsTileType(tile, MP_STREET) && IsLevelCrossing(tile)) {
owner = _map3_lo[tile];
} else
owner = GetTileOwner(tile);
@@ -483,7 +483,7 @@ do_clear:;
int32 DoConvertStreetRail(uint tile, uint totype, bool exec)
{
// not a railroad crossing?
- if ((_map5[tile] & 0xF0) != 0x10) return CMD_ERROR;
+ if (!IsLevelCrossing(tile)) return CMD_ERROR;
// not owned by me?
if (!CheckTileOwnership(tile) || !EnsureNoVehicle(tile)) return CMD_ERROR;
@@ -937,7 +937,7 @@ static void GetAcceptedCargo_Road(uint tile, AcceptedCargo ac)
static void AnimateTile_Road(uint tile)
{
- if ((_map5[tile] & 0xF0) == 0x10) {
+ if (IsLevelCrossing(tile)) {
MarkTileDirtyByTile(tile);
}
}
@@ -1057,7 +1057,7 @@ static const byte _road_trackbits[16] = {
static uint32 GetTileTrackStatus_Road(uint tile, TransportType mode) {
if (mode == TRANSPORT_RAIL) {
- if ((_map5[tile] & 0xF0) != 0x10)
+ if (!IsLevelCrossing(tile))
return 0;
return _map5[tile] & 8 ? 0x101 : 0x202;
} else if (mode == TRANSPORT_ROAD) {
@@ -1067,7 +1067,7 @@ static uint32 GetTileTrackStatus_Road(uint tile, TransportType mode) {
if (!_road_special_gettrackstatus && ((_map3_hi[tile]&0x70) >> 4) >= 6)
return 0;
return _road_trackbits[b&0xF] * 0x101;
- } else if ((b&0xF0) == 0x10) {
+ } else if (IsLevelCrossing(tile)) {
/* Crossing */
uint32 r = 0x101;
if (b&8) r <<= 1;
@@ -1110,7 +1110,7 @@ static const byte _roadveh_enter_depot_unk0[4] = {
static uint32 VehicleEnter_Road(Vehicle *v, uint tile, int x, int y)
{
- if ((_map5[tile] & 0xF0) == 0x10) {
+ if (IsLevelCrossing(tile)) {
if (v->type == VEH_Train && (_map5[tile] & 4) == 0) {
/* train crossing a road */
SndPlayVehicleFx(SND_0E_LEVEL_CROSSING, v);
@@ -1130,7 +1130,8 @@ static uint32 VehicleEnter_Road(Vehicle *v, uint tile, int x, int y)
static void VehicleLeave_Road(Vehicle *v, uint tile, int x, int y)
{
- if ((_map5[tile] & 0xF0) == 0x10 && v->type == VEH_Train && v->next == NULL) {
+ if (IsLevelCrossing(tile) && v->type == VEH_Train && v->next == NULL) {
+ // Turn off level crossing lights
_map5[tile] &= ~4;
MarkTileDirtyByTile(tile);
}
@@ -1141,7 +1142,7 @@ static void ChangeTileOwner_Road(uint tile, byte old_player, byte new_player)
byte b;
// road/rail crossing where the road is owned by the current player?
- if (old_player == _map3_lo[tile] && (_map5[tile]&0xF0) == 0x10) {
+ if (old_player == _map3_lo[tile] && IsLevelCrossing(tile)) {
_map3_lo[tile] = (new_player == 0xFF) ? OWNER_NONE : new_player;
}
@@ -1153,7 +1154,7 @@ static void ChangeTileOwner_Road(uint tile, byte old_player, byte new_player)
b = _map5[tile]&0xF0;
if (b == 0) {
SetTileOwner(tile, OWNER_NONE);
- } else if (b == 0x10) {
+ } else if (IsLevelCrossing(tile)) {
_map5[tile] = (_map5[tile]&8) ? 0x5 : 0xA;
SetTileOwner(tile, _map3_lo[tile]);
_map3_lo[tile] = 0;
diff --git a/roadveh_cmd.c b/roadveh_cmd.c
index 8aea4ee4d..0935136a2 100644
--- a/roadveh_cmd.c
+++ b/roadveh_cmd.c
@@ -592,9 +592,8 @@ static void RoadVehCheckTrainCrash(Vehicle *v)
tile = v->tile;
// Make sure it's a road/rail crossing
- if (!IsTileType(tile, MP_STREET) ||
- (_map5[tile] & 0xF0) != 0x10)
- return;
+ if (!IsTileType(tile, MP_STREET) || !IsLevelCrossing(tile))
+ return;
if (VehicleFromPos(tile, v, (VehicleFromPosProc*)EnumCheckRoadVehCrashTrain) != NULL)
RoadVehCrash(v);
diff --git a/tile.h b/tile.h
index 1d8cd094a..9b0b45dfd 100644
--- a/tile.h
+++ b/tile.h
@@ -103,4 +103,9 @@ static inline bool IsTileOwner(TileIndex tile, Owner owner)
return GetTileOwner(tile) == owner;
}
+static inline bool IsLevelCrossing(TileIndex tile)
+{
+ return (_map5[tile] & 0xF0) == 0x10;
+}
+
#endif
diff --git a/town_cmd.c b/town_cmd.c
index 4b13be7b6..e659033d9 100644
--- a/town_cmd.c
+++ b/town_cmd.c
@@ -1841,7 +1841,7 @@ Town *ClosestTownFromTile(uint tile, uint threshold)
// XXX - Fix this so for a given tiletype the owner of the type is in the same variable
if (IsTileType(tile, MP_HOUSE) || (
IsTileType(tile, MP_STREET) &&
- ((_map5[tile] & 0xF0) != 0x10 ? GetTileOwner(tile) : _map3_lo[tile]) == OWNER_TOWN
+ (IsLevelCrossing(tile) ? _map3_lo[tile] == OWNER_TOWN : GetTileOwner(tile))
))
return GetTown(_map2[tile]);
diff --git a/train_cmd.c b/train_cmd.c
index 547aedf88..ded96b417 100644
--- a/train_cmd.c
+++ b/train_cmd.c
@@ -1258,7 +1258,7 @@ static void *TestTrainOnCrossing(Vehicle *v, void *data)
static void DisableTrainCrossing(TileIndex tile)
{
/* Test if we have a rail/road-crossing */
- if (IsTileType(tile, MP_STREET) && (_map5[tile] & 0xF0) == 0x10) {
+ if (IsTileType(tile, MP_STREET) && IsLevelCrossing(tile)) {
/* Check if there is a train on the tile itself */
if (VehicleFromPos(tile, &tile, TestTrainOnCrossing) == NULL) {
/* If light is on, switch light off */
@@ -3082,7 +3082,7 @@ static bool TrainCheckIfLineEnds(Vehicle *v)
}
if ((ts &= (ts >> 16)) == 0) {
// make a rail/road crossing red
- if (IsTileType(tile, MP_STREET) && (_map5[tile] & 0xF0) == 0x10) {
+ if (IsTileType(tile, MP_STREET) && IsLevelCrossing(tile)) {
if (!(_map5[tile] & 4)) {
_map5[tile] |= 4;
SndPlayVehicleFx(SND_0E_LEVEL_CROSSING, v);