(svn r2433) - CodeChange: unmagicify all road/train crossings with IsLevelCrossing() function (peter1138)

This commit is contained in:
Darkvater 2005-06-07 21:37:00 +00:00
parent fa8f46c0b7
commit 0171aae109
9 changed files with 26 additions and 21 deletions

2
ai.c
View File

@ -3700,7 +3700,7 @@ pos_3:
} else if (IsTileType(tile, MP_STREET)) { } else if (IsTileType(tile, MP_STREET)) {
if (!IsTileOwner(tile, _current_player)) return; if (!IsTileOwner(tile, _current_player)) return;
if ( (_map5[tile]&0xF0) == 0x10) if (IsLevelCrossing(tile))
goto is_rail_crossing; goto is_rail_crossing;
if ( (_map5[tile]&0xF0) == 0x20) { if ( (_map5[tile]&0xF0) == 0x20) {

2
npf.c
View File

@ -484,7 +484,7 @@ static inline RailType GetTileRailType(TileIndex tile, byte trackdir)
break; break;
case MP_STREET: case MP_STREET:
/* rail/road crossing */ /* rail/road crossing */
if ((_map5[tile] & 0xF0) == 0x10) if (IsLevelCrossing(tile))
type = _map3_hi[tile] & RAILTYPE_MASK; type = _map3_hi[tile] & RAILTYPE_MASK;
break; break;
case MP_STATION: case MP_STATION:

View File

@ -1185,7 +1185,7 @@ static void ConvertTownOwner(void)
for (tile = 0; tile != MapSize(); tile++) { for (tile = 0; tile != MapSize(); tile++) {
if (IsTileType(tile, MP_STREET)) { 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; _map3_lo[tile] = OWNER_TOWN;
if (_map_owner[tile] & 0x80) SetTileOwner(tile, OWNER_TOWN); if (_map_owner[tile] & 0x80) SetTileOwner(tile, OWNER_TOWN);

View File

@ -374,7 +374,7 @@ int32 CmdBuildSingleRail(int x, int y, uint32 flags, uint32 p1, uint32 p2)
break; 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); return_cmd_error(STR_1007_ALREADY_BUILT);
/* FALLTHROUGH */ /* FALLTHROUGH */

View File

@ -32,7 +32,7 @@ static bool HasTileRoadAt(uint tile, int i)
b = _map5[tile]; b = _map5[tile];
if ((b & 0xF0) == 0) { if ((b & 0xF0) == 0) {
} else if ((b & 0xF0) == 0x10) { } else if (IsLevelCrossing(tile)) {
b = (b&8)?5:10; b = (b&8)?5:10;
} else if ((b & 0xF0) == 0x20) { } else if ((b & 0xF0) == 0x20) {
return (~b & 3) == i; return (~b & 3) == i;
@ -78,7 +78,7 @@ static bool CheckAllowRemoveRoad(uint tile, uint br, bool *edge_road)
return true; return true;
// A railway crossing has the road owner in the map3_lo byte. // 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]; owner = _map3_lo[tile];
} else { } else {
owner = GetTileOwner(tile); 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 // 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 // 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]; owner = _map3_lo[tile];
} else } else
owner = GetTileOwner(tile); owner = GetTileOwner(tile);
@ -483,7 +483,7 @@ do_clear:;
int32 DoConvertStreetRail(uint tile, uint totype, bool exec) int32 DoConvertStreetRail(uint tile, uint totype, bool exec)
{ {
// not a railroad crossing? // not a railroad crossing?
if ((_map5[tile] & 0xF0) != 0x10) return CMD_ERROR; if (!IsLevelCrossing(tile)) return CMD_ERROR;
// not owned by me? // not owned by me?
if (!CheckTileOwnership(tile) || !EnsureNoVehicle(tile)) return CMD_ERROR; 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) static void AnimateTile_Road(uint tile)
{ {
if ((_map5[tile] & 0xF0) == 0x10) { if (IsLevelCrossing(tile)) {
MarkTileDirtyByTile(tile); MarkTileDirtyByTile(tile);
} }
} }
@ -1057,7 +1057,7 @@ static const byte _road_trackbits[16] = {
static uint32 GetTileTrackStatus_Road(uint tile, TransportType mode) { static uint32 GetTileTrackStatus_Road(uint tile, TransportType mode) {
if (mode == TRANSPORT_RAIL) { if (mode == TRANSPORT_RAIL) {
if ((_map5[tile] & 0xF0) != 0x10) if (!IsLevelCrossing(tile))
return 0; return 0;
return _map5[tile] & 8 ? 0x101 : 0x202; return _map5[tile] & 8 ? 0x101 : 0x202;
} else if (mode == TRANSPORT_ROAD) { } 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) if (!_road_special_gettrackstatus && ((_map3_hi[tile]&0x70) >> 4) >= 6)
return 0; return 0;
return _road_trackbits[b&0xF] * 0x101; return _road_trackbits[b&0xF] * 0x101;
} else if ((b&0xF0) == 0x10) { } else if (IsLevelCrossing(tile)) {
/* Crossing */ /* Crossing */
uint32 r = 0x101; uint32 r = 0x101;
if (b&8) r <<= 1; 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) 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) { if (v->type == VEH_Train && (_map5[tile] & 4) == 0) {
/* train crossing a road */ /* train crossing a road */
SndPlayVehicleFx(SND_0E_LEVEL_CROSSING, v); 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) 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; _map5[tile] &= ~4;
MarkTileDirtyByTile(tile); MarkTileDirtyByTile(tile);
} }
@ -1141,7 +1142,7 @@ static void ChangeTileOwner_Road(uint tile, byte old_player, byte new_player)
byte b; byte b;
// road/rail crossing where the road is owned by the current player? // 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; _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; b = _map5[tile]&0xF0;
if (b == 0) { if (b == 0) {
SetTileOwner(tile, OWNER_NONE); SetTileOwner(tile, OWNER_NONE);
} else if (b == 0x10) { } else if (IsLevelCrossing(tile)) {
_map5[tile] = (_map5[tile]&8) ? 0x5 : 0xA; _map5[tile] = (_map5[tile]&8) ? 0x5 : 0xA;
SetTileOwner(tile, _map3_lo[tile]); SetTileOwner(tile, _map3_lo[tile]);
_map3_lo[tile] = 0; _map3_lo[tile] = 0;

View File

@ -592,9 +592,8 @@ static void RoadVehCheckTrainCrash(Vehicle *v)
tile = v->tile; tile = v->tile;
// Make sure it's a road/rail crossing // Make sure it's a road/rail crossing
if (!IsTileType(tile, MP_STREET) || if (!IsTileType(tile, MP_STREET) || !IsLevelCrossing(tile))
(_map5[tile] & 0xF0) != 0x10) return;
return;
if (VehicleFromPos(tile, v, (VehicleFromPosProc*)EnumCheckRoadVehCrashTrain) != NULL) if (VehicleFromPos(tile, v, (VehicleFromPosProc*)EnumCheckRoadVehCrashTrain) != NULL)
RoadVehCrash(v); RoadVehCrash(v);

5
tile.h
View File

@ -103,4 +103,9 @@ static inline bool IsTileOwner(TileIndex tile, Owner owner)
return GetTileOwner(tile) == owner; return GetTileOwner(tile) == owner;
} }
static inline bool IsLevelCrossing(TileIndex tile)
{
return (_map5[tile] & 0xF0) == 0x10;
}
#endif #endif

View File

@ -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 // XXX - Fix this so for a given tiletype the owner of the type is in the same variable
if (IsTileType(tile, MP_HOUSE) || ( if (IsTileType(tile, MP_HOUSE) || (
IsTileType(tile, MP_STREET) && 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]); return GetTown(_map2[tile]);

View File

@ -1258,7 +1258,7 @@ static void *TestTrainOnCrossing(Vehicle *v, void *data)
static void DisableTrainCrossing(TileIndex tile) static void DisableTrainCrossing(TileIndex tile)
{ {
/* Test if we have a rail/road-crossing */ /* 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 */ /* Check if there is a train on the tile itself */
if (VehicleFromPos(tile, &tile, TestTrainOnCrossing) == NULL) { if (VehicleFromPos(tile, &tile, TestTrainOnCrossing) == NULL) {
/* If light is on, switch light off */ /* If light is on, switch light off */
@ -3082,7 +3082,7 @@ static bool TrainCheckIfLineEnds(Vehicle *v)
} }
if ((ts &= (ts >> 16)) == 0) { if ((ts &= (ts >> 16)) == 0) {
// make a rail/road crossing red // 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)) { if (!(_map5[tile] & 4)) {
_map5[tile] |= 4; _map5[tile] |= 4;
SndPlayVehicleFx(SND_0E_LEVEL_CROSSING, v); SndPlayVehicleFx(SND_0E_LEVEL_CROSSING, v);