Mercurial > hg > openttd
changeset 1927:f8c72566d325 draft
(svn r2433) - CodeChange: unmagicify all road/train crossings with IsLevelCrossing() function (peter1138)
author | Darkvater <Darkvater@openttd.org> |
---|---|
date | Tue, 07 Jun 2005 21:37:00 +0000 |
parents | ae98b5ce63ee |
children | 1bc6551d0516 |
files | ai.c npf.c openttd.c rail_cmd.c road_cmd.c roadveh_cmd.c tile.h town_cmd.c train_cmd.c |
diffstat | 9 files changed, 26 insertions(+), 21 deletions(-) [+] |
line wrap: on
line diff
--- a/ai.c +++ b/ai.c @@ -3700,7 +3700,7 @@ } 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) {
--- a/npf.c +++ b/npf.c @@ -484,7 +484,7 @@ 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:
--- a/openttd.c +++ b/openttd.c @@ -1185,7 +1185,7 @@ 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);
--- a/rail_cmd.c +++ b/rail_cmd.c @@ -374,7 +374,7 @@ 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 */
--- a/road_cmd.c +++ b/road_cmd.c @@ -32,7 +32,7 @@ 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 @@ 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 @@ // 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 @@ 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 AnimateTile_Road(uint tile) { - if ((_map5[tile] & 0xF0) == 0x10) { + if (IsLevelCrossing(tile)) { MarkTileDirtyByTile(tile); } } @@ -1057,7 +1057,7 @@ 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 @@ 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 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 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 @@ 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 @@ 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;
--- a/roadveh_cmd.c +++ b/roadveh_cmd.c @@ -592,9 +592,8 @@ 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);
--- a/tile.h +++ b/tile.h @@ -103,4 +103,9 @@ return GetTileOwner(tile) == owner; } +static inline bool IsLevelCrossing(TileIndex tile) +{ + return (_map5[tile] & 0xF0) == 0x10; +} + #endif
--- a/town_cmd.c +++ b/town_cmd.c @@ -1841,7 +1841,7 @@ // 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]);
--- a/train_cmd.c +++ b/train_cmd.c @@ -1258,7 +1258,7 @@ 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 @@ } 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);