(svn r3019) -Codechange: Replace explicit shifting/anding/oring with GB and SB

This commit is contained in:
tron 2005-10-05 07:20:26 +00:00
parent 102cf2615f
commit ae4a1f3675
17 changed files with 126 additions and 127 deletions

View File

@ -104,10 +104,10 @@ static inline DiagDirection GetDepotDirection(TileIndex tile, TransportType type
case TRANSPORT_RAIL: case TRANSPORT_RAIL:
case TRANSPORT_ROAD: case TRANSPORT_ROAD:
/* Rail and road store a diagonal direction in bits 0 and 1 */ /* Rail and road store a diagonal direction in bits 0 and 1 */
return (DiagDirection)(_m[tile].m5 & 3); return (DiagDirection)GB(_m[tile].m5, 0, 2);
case TRANSPORT_WATER: case TRANSPORT_WATER:
/* Water is stubborn, it stores the directions in a different order. */ /* Water is stubborn, it stores the directions in a different order. */
switch (_m[tile].m5 & 3) { switch (GB(_m[tile].m5, 0, 2)) {
case 0: return DIAGDIR_NE; case 0: return DIAGDIR_NE;
case 1: return DIAGDIR_SW; case 1: return DIAGDIR_SW;
case 2: return DIAGDIR_NW; case 2: return DIAGDIR_NW;

View File

@ -351,7 +351,7 @@ static void DrawTile_Industry(TileInfo *ti)
ormod = (ind->color_map+0x307) << PALETTE_SPRITE_START; ormod = (ind->color_map+0x307) << PALETTE_SPRITE_START;
/* Retrieve pointer to the draw industry tile struct */ /* Retrieve pointer to the draw industry tile struct */
dits = &_industry_draw_tile_data[(ti->map5 << 2) | (_m[ti->tile].m1 & 3)]; dits = &_industry_draw_tile_data[(ti->map5 << 2) | GB(_m[ti->tile].m1, 0, 2)];
image = dits->sprite_1; image = dits->sprite_1;
if (image & PALETTE_MODIFIER_COLOR && (image & PALETTE_SPRITE_MASK) == 0) if (image & PALETTE_MODIFIER_COLOR && (image & PALETTE_SPRITE_MASK) == 0)

View File

@ -145,11 +145,11 @@ static inline void swap_tile(TileIndex *a, TileIndex *b) { TileIndex t = *a; *a
#endif #endif
/// Fetch n bits starting at bit s from x /// Fetch n bits starting at bit s from x
#define GB(x, s, n) (((x) >> (s)) & ((1 << (n)) - 1)) #define GB(x, s, n) (((x) >> (s)) & ((1U << (n)) - 1))
/// Set n bits starting at bit s in x to d /// Set n bits starting at bit s in x to d
#define SB(x, s, n, d) ((x) = ((x) & ~(((1 << (n)) - 1) << (s))) | ((d) << (s))) #define SB(x, s, n, d) ((x) = ((x) & ~(((1U << (n)) - 1) << (s))) | ((d) << (s)))
/// Add i to the n bits starting at bit s in x /// Add i to the n bits starting at bit s in x
#define AB(x, s, n, i) ((x) = ((x) & ~(((1 << (n)) - 1) << (s))) | (((x) + ((i) << (s))) & (((1 << (n)) - 1) << (s)))) #define AB(x, s, n, i) ((x) = ((x) & ~(((1U << (n)) - 1) << (s))) | (((x) + ((i) << (s))) & (((1U << (n)) - 1) << (s))))
/** /**
* ROtate x Left/Right by n (must be >= 0) * ROtate x Left/Right by n (must be >= 0)

34
npf.c
View File

@ -60,8 +60,10 @@ static bool IsEndOfLine(TileIndex tile, Trackdir trackdir, RailType enginetype)
uint32 ts; uint32 ts;
/* Can always go into a tunnel */ /* Can always go into a tunnel */
if (IsTileType(tile, MP_TUNNELBRIDGE) && (_m[tile].m5 & 0xF0)==0 && (_m[tile].m5 & 3) == exitdir) if (IsTileType(tile, MP_TUNNELBRIDGE) && GB(_m[tile].m5, 4, 4) == 0 &&
GB(_m[tile].m5, 0, 2) == exitdir) {
return false; return false;
}
/* Cannot go through the back of a depot */ /* Cannot go through the back of a depot */
if (IsTileDepotType(tile, TRANSPORT_RAIL) && (exitdir != GetDepotDirection(tile, TRANSPORT_RAIL))) if (IsTileDepotType(tile, TRANSPORT_RAIL) && (exitdir != GetDepotDirection(tile, TRANSPORT_RAIL)))
@ -88,8 +90,11 @@ static bool IsEndOfLine(TileIndex tile, Trackdir trackdir, RailType enginetype)
return true; return true;
/* Prevent us from falling off a slope into a tunnel exit */ /* Prevent us from falling off a slope into a tunnel exit */
if (IsTileType(dst_tile, MP_TUNNELBRIDGE) && (_m[dst_tile].m5 & 0xF0)==0 && (DiagDirection)(_m[dst_tile].m5 & 3) == ReverseDiagdir(exitdir)) if (IsTileType(dst_tile, MP_TUNNELBRIDGE) &&
return true; GB(_m[dst_tile].m5, 4, 4) == 0 &&
(DiagDirection)GB(_m[dst_tile].m5, 0, 2) == ReverseDiagdir(exitdir)) {
return true;
}
/* Check for oneway signal against us */ /* Check for oneway signal against us */
if (IsTileType(dst_tile, MP_RAILWAY) && GetRailTileType(dst_tile) == RAIL_TYPE_SIGNALS) { if (IsTileType(dst_tile, MP_RAILWAY) && GetRailTileType(dst_tile) == RAIL_TYPE_SIGNALS) {
@ -312,7 +317,7 @@ static uint NPFTunnelCost(AyStarNode* current)
{ {
DiagDirection exitdir = TrackdirToExitdir((Trackdir)current->direction); DiagDirection exitdir = TrackdirToExitdir((Trackdir)current->direction);
TileIndex tile = current->tile; TileIndex tile = current->tile;
if ( (DiagDirection)(_m[tile].m5 & 3) == ReverseDiagdir(exitdir)) { if ((DiagDirection)GB(_m[tile].m5, 0, 2) == ReverseDiagdir(exitdir)) {
/* We just popped out if this tunnel, since were /* We just popped out if this tunnel, since were
* facing the tunnel exit */ * facing the tunnel exit */
FindLengthOfTunnelResult flotr; FindLengthOfTunnelResult flotr;
@ -364,13 +369,13 @@ static void NPFMarkTile(TileIndex tile)
/* DEBUG: mark visited tiles by mowing the grass under them /* DEBUG: mark visited tiles by mowing the grass under them
* ;-) */ * ;-) */
if (!IsTileDepotType(tile, TRANSPORT_RAIL)) { if (!IsTileDepotType(tile, TRANSPORT_RAIL)) {
_m[tile].m2 &= ~15; /* Clear bits 0-3 */ SB(_m[tile].m2, 0, 4, 0);
MarkTileDirtyByTile(tile); MarkTileDirtyByTile(tile);
} }
break; break;
case MP_STREET: case MP_STREET:
if (!IsTileDepotType(tile, TRANSPORT_ROAD)) { if (!IsTileDepotType(tile, TRANSPORT_ROAD)) {
_m[tile].m4 &= ~0x70; /* Clear bits 4-6 */ SB(_m[tile].m2, 4, 3, 0);
MarkTileDirtyByTile(tile); MarkTileDirtyByTile(tile);
} }
break; break;
@ -408,7 +413,7 @@ static int32 NPFRoadPathCost(AyStar* as, AyStarNode* current, OpenListNode* pare
/* Determine base length */ /* Determine base length */
switch (GetTileType(tile)) { switch (GetTileType(tile)) {
case MP_TUNNELBRIDGE: case MP_TUNNELBRIDGE:
if ((_m[tile].m5 & 0xF0)==0) { if (GB(_m[tile].m5, 4, 4) == 0) {
cost = NPFTunnelCost(current); cost = NPFTunnelCost(current);
break; break;
} }
@ -452,7 +457,7 @@ static int32 NPFRailPathCost(AyStar* as, AyStarNode* current, OpenListNode* pare
/* Determine base length */ /* Determine base length */
switch (GetTileType(tile)) { switch (GetTileType(tile)) {
case MP_TUNNELBRIDGE: case MP_TUNNELBRIDGE:
if ((_m[tile].m5 & 0xF0)==0) { if (GB(_m[tile].m5, 4, 4) == 0) {
cost = NPFTunnelCost(current); cost = NPFTunnelCost(current);
break; break;
} }
@ -659,10 +664,10 @@ static bool VehicleMayEnterTile(Owner owner, TileIndex tile, DiagDirection enter
* intensive owner check, instead we will just assume that if the vehicle * intensive owner check, instead we will just assume that if the vehicle
* managed to get on the bridge, it is probably allowed to :-) * managed to get on the bridge, it is probably allowed to :-)
*/ */
if ((_m[tile].m5 & 0xC6) == 0xC0 && (unsigned)(_m[tile].m5 & 0x1) == (enterdir & 0x1)) { if ((_m[tile].m5 & 0xC6) == 0xC0 && GB(_m[tile].m5, 0, 1) == (enterdir & 0x1)) {
/* on the middle part of a railway bridge: find bridge ending */ /* on the middle part of a railway bridge: find bridge ending */
while (IsTileType(tile, MP_TUNNELBRIDGE) && !((_m[tile].m5 & 0xC6) == 0x80)) { while (IsTileType(tile, MP_TUNNELBRIDGE) && !((_m[tile].m5 & 0xC6) == 0x80)) {
tile += TileOffsByDir(_m[tile].m5 & 0x1); tile += TileOffsByDir(GB(_m[tile].m5, 0, 1));
} }
} }
/* if we were on a railway middle part, we are now at a railway bridge ending */ /* if we were on a railway middle part, we are now at a railway bridge ending */
@ -670,7 +675,7 @@ static bool VehicleMayEnterTile(Owner owner, TileIndex tile, DiagDirection enter
if ( if (
(_m[tile].m5 & 0xFC) == 0 /* railway tunnel */ (_m[tile].m5 & 0xFC) == 0 /* railway tunnel */
|| (_m[tile].m5 & 0xC6) == 0x80 /* railway bridge ending */ || (_m[tile].m5 & 0xC6) == 0x80 /* railway bridge ending */
|| ((_m[tile].m5 & 0xF8) == 0xE0 && ((unsigned)_m[tile].m5 & 0x1) != (enterdir & 0x1)) /* railway under bridge */ || ((_m[tile].m5 & 0xF8) == 0xE0 && GB(_m[tile].m5, 0, 1) != (enterdir & 0x1)) /* railway under bridge */
) )
return IsTileOwner(tile, owner); return IsTileOwner(tile, owner);
break; break;
@ -704,7 +709,8 @@ static void NPFFollowTrack(AyStar* aystar, OpenListNode* current)
aystar->EndNodeCheck(aystar, current); aystar->EndNodeCheck(aystar, current);
/* Find dest tile */ /* Find dest tile */
if (IsTileType(src_tile, MP_TUNNELBRIDGE) && (_m[src_tile].m5 & 0xF0)==0 && (DiagDirection)(_m[src_tile].m5 & 3) == src_exitdir) { if (IsTileType(src_tile, MP_TUNNELBRIDGE) && GB(_m[src_tile].m5, 4, 4) == 0 &&
(DiagDirection)GB(_m[src_tile].m5, 0, 2) == src_exitdir) {
/* This is a tunnel. We know this tunnel is our type, /* This is a tunnel. We know this tunnel is our type,
* otherwise we wouldn't have got here. It is also facing us, * otherwise we wouldn't have got here. It is also facing us,
* so we should skip it's body */ * so we should skip it's body */
@ -749,8 +755,10 @@ static void NPFFollowTrack(AyStar* aystar, OpenListNode* current)
/* I can't enter a tunnel entry/exit tile from a tile above the tunnel. Note /* I can't enter a tunnel entry/exit tile from a tile above the tunnel. Note
* that I can enter the tunnel from a tile below the tunnel entrance. This * that I can enter the tunnel from a tile below the tunnel entrance. This
* solves the problem of vehicles wanting to drive off a tunnel entrance */ * solves the problem of vehicles wanting to drive off a tunnel entrance */
if (IsTileType(dst_tile, MP_TUNNELBRIDGE) && (_m[dst_tile].m5 & 0xF0) == 0 && GetTileZ(dst_tile) < GetTileZ(src_tile)) if (IsTileType(dst_tile, MP_TUNNELBRIDGE) && GB(_m[dst_tile].m5, 4, 4) == 0 &&
GetTileZ(dst_tile) < GetTileZ(src_tile)) {
return; return;
}
/* check correct rail type (mono, maglev, etc) */ /* check correct rail type (mono, maglev, etc) */
if (type == TRANSPORT_RAIL) { if (type == TRANSPORT_RAIL) {

View File

@ -209,7 +209,7 @@ static const int8 _get_tunlen_inc[5] = { -16, 0, 16, 0, -16 };
/* Returns the end tile and the length of a tunnel. The length does not /* Returns the end tile and the length of a tunnel. The length does not
* include the starting tile (entry), it does include the end tile (exit). * include the starting tile (entry), it does include the end tile (exit).
*/ */
FindLengthOfTunnelResult FindLengthOfTunnel(TileIndex tile, int direction) FindLengthOfTunnelResult FindLengthOfTunnel(TileIndex tile, uint direction)
{ {
FindLengthOfTunnelResult flotr; FindLengthOfTunnelResult flotr;
int x,y; int x,y;
@ -231,11 +231,12 @@ FindLengthOfTunnelResult FindLengthOfTunnel(TileIndex tile, int direction)
tile = TileVirtXY(x, y); tile = TileVirtXY(x, y);
if (IsTileType(tile, MP_TUNNELBRIDGE) && if (IsTileType(tile, MP_TUNNELBRIDGE) &&
(_m[tile].m5 & 0xF0) == 0 && // tunnel entrance/exit GB(_m[tile].m5, 4, 4) == 0 && // tunnel entrance/exit
//((_m[tile].m5>>2)&3) == type && // rail/road-tunnel <-- This is not necesary to check, right? // GB(_m[tile].m5, 2, 2) == type && // rail/road-tunnel <-- This is not necesary to check, right?
((_m[tile].m5 & 3)^2) == direction && // entrance towards: 0 = NE, 1 = SE, 2 = SW, 3 = NW (GB(_m[tile].m5, 0, 2) ^ 2) == direction && // entrance towards: 0 = NE, 1 = SE, 2 = SW, 3 = NW
GetSlopeZ(x+8, y+8) == z) GetSlopeZ(x + 8, y + 8) == z) {
break; break;
}
} }
flotr.tile = tile; flotr.tile = tile;
@ -274,16 +275,18 @@ const byte _ffb_64[128] = {
48,56,56,58,56,60,60,62, 48,56,56,58,56,60,60,62,
}; };
static void TPFMode1(TrackPathFinder *tpf, TileIndex tile, int direction) static void TPFMode1(TrackPathFinder *tpf, TileIndex tile, uint direction)
{ {
uint bits; uint bits;
int i; int i;
RememberData rd; RememberData rd;
TileIndex tile_org = tile; TileIndex tile_org = tile;
if (IsTileType(tile, MP_TUNNELBRIDGE) && (_m[tile].m5 & 0xF0) == 0) { if (IsTileType(tile, MP_TUNNELBRIDGE) && GB(_m[tile].m5, 4, 4) == 0) {
if ((_m[tile].m5 & 3) != direction || ((_m[tile].m5>>2)&3) != tpf->tracktype) if (GB(_m[tile].m5, 0, 2) != direction ||
GB(_m[tile].m5, 2, 2) != tpf->tracktype) {
return; return;
}
tile = SkipToEndOfTunnel(tpf, tile, direction); tile = SkipToEndOfTunnel(tpf, tile, direction);
} }
tile += TileOffsByDir(direction); tile += TileOffsByDir(direction);
@ -704,11 +707,11 @@ start_at:
// If the tile is the entry tile of a tunnel, and we're not going out of the tunnel, // If the tile is the entry tile of a tunnel, and we're not going out of the tunnel,
// need to find the exit of the tunnel. // need to find the exit of the tunnel.
if (IsTileType(tile, MP_TUNNELBRIDGE)) { if (IsTileType(tile, MP_TUNNELBRIDGE)) {
if ((_m[tile].m5 & 0xF0) == 0 && if (GB(_m[tile].m5, 4, 4) == 0 &&
(uint)(_m[tile].m5 & 3) != (direction ^ 2)) { GB(_m[tile].m5, 0, 2) != (direction ^ 2)) {
/* This is a tunnel tile */ /* This is a tunnel tile */
/* We are not just driving out of the tunnel */ /* We are not just driving out of the tunnel */
if ( (uint)(_m[tile].m5 & 3) != direction || GB(_m[tile].m5, 2, 2) != tpf->tracktype) if (GB(_m[tile].m5, 0, 2) != direction || GB(_m[tile].m5, 2, 2) != tpf->tracktype)
/* We are not driving into the tunnel, or it /* We are not driving into the tunnel, or it
* is an invalid tunnel */ * is an invalid tunnel */
continue; continue;
@ -761,7 +764,7 @@ start_at:
// The tile has no reachable tracks, or // The tile has no reachable tracks, or
// does the tile contain more than one track? // does the tile contain more than one track?
if (bits == 0 || KILL_FIRST_BIT(_m[tile].m5 & 0x3F) != 0) if (bits == 0 || KILL_FIRST_BIT(GB(_m[tile].m5, 0, 6)) != 0)
break; break;
// If we reach here, the tile has exactly one track, and this // If we reach here, the tile has exactly one track, and this

View File

@ -64,7 +64,7 @@ typedef struct {
TileIndex tile; TileIndex tile;
int length; int length;
} FindLengthOfTunnelResult; } FindLengthOfTunnelResult;
FindLengthOfTunnelResult FindLengthOfTunnel(TileIndex tile, int direction); FindLengthOfTunnelResult FindLengthOfTunnel(TileIndex tile, uint direction);
void NewTrainPathfind(TileIndex tile, TileIndex dest, byte direction, NTPEnumProc *enum_proc, void *data); void NewTrainPathfind(TileIndex tile, TileIndex dest, byte direction, NTPEnumProc *enum_proc, void *data);

22
pbs.c
View File

@ -57,15 +57,14 @@ void PBSReserveTrack(TileIndex tile, Track track) {
SETBIT(_m[tile].m3, 6); SETBIT(_m[tile].m3, 6);
} else { } else {
// normal rail track // normal rail track
byte encrt = (_m[tile].m4 & 0xF0) >> 4; // get current encoded info (see comments at top of file) byte encrt = GB(_m[tile].m4, 4, 4); // get current encoded info (see comments at top of file)
if (encrt == 0) // nothing reserved before if (encrt == 0) // nothing reserved before
encrt = track + 1; encrt = track + 1;
else if (encrt == (track^1) + 1) // opposite track reserved before else if (encrt == (track^1) + 1) // opposite track reserved before
encrt |= 8; encrt |= 8;
_m[tile].m4 &= ~0xF0; SB(_m[tile].m4, 4, 4, encrt);
_m[tile].m4 |= encrt << 4;
} }
break; break;
case MP_TUNNELBRIDGE: case MP_TUNNELBRIDGE:
@ -99,12 +98,12 @@ byte PBSTileReserved(TileIndex tile) {
return HASBIT(_m[tile].m5, 0) ? 2 : 1; return HASBIT(_m[tile].m5, 0) ? 2 : 1;
} else { } else {
// normal track // normal track
byte res = encrt_to_reserved[(_m[tile].m4 & 0xF0) >> 4]; byte res = encrt_to_reserved[GB(_m[tile].m4, 4, 4)];
assert(res != 0xFF); assert(res != 0xFF);
return res; return res;
} }
case MP_TUNNELBRIDGE: case MP_TUNNELBRIDGE:
return (_m[tile].m4 & 3); return GB(_m[tile].m4, 0, 2);
case MP_STATION: case MP_STATION:
// check if its reserved // check if its reserved
if (!HASBIT(_m[tile].m3, 6)) return 0; if (!HASBIT(_m[tile].m3, 6)) return 0;
@ -131,12 +130,12 @@ uint16 PBSTileUnavail(TileIndex tile) {
return HASBIT(_m[tile].m3, 6) ? TRACKDIR_BIT_MASK : 0; return HASBIT(_m[tile].m3, 6) ? TRACKDIR_BIT_MASK : 0;
} else { } else {
// normal track // normal track
uint16 res = encrt_to_unavail[(_m[tile].m4 & 0xF0) >> 4]; uint16 res = encrt_to_unavail[GB(_m[tile].m4, 4, 4)];
assert(res != 0xFFFF); assert(res != 0xFFFF);
return res; return res;
} }
case MP_TUNNELBRIDGE: case MP_TUNNELBRIDGE:
return (_m[tile].m4 & 3) | ((_m[tile].m4 & 3) << 8); return GB(_m[tile].m4, 0, 2) | (GB(_m[tile].m4, 0, 2) << 8);
case MP_STATION: case MP_STATION:
return HASBIT(_m[tile].m3, 6) ? TRACKDIR_BIT_MASK : 0; return HASBIT(_m[tile].m3, 6) ? TRACKDIR_BIT_MASK : 0;
case MP_STREET: case MP_STREET:
@ -159,7 +158,7 @@ void PBSClearTrack(TileIndex tile, Track track) {
CLRBIT(_m[tile].m3, 6); CLRBIT(_m[tile].m3, 6);
} else { } else {
// normal rail track // normal rail track
byte encrt = (_m[tile].m4 & 0xF0) >> 4; byte encrt = GB(_m[tile].m4, 4, 4);
if (encrt == track + 1) if (encrt == track + 1)
encrt = 0; encrt = 0;
@ -168,8 +167,7 @@ void PBSClearTrack(TileIndex tile, Track track) {
else if (encrt == (track^1) + 1 + 8) else if (encrt == (track^1) + 1 + 8)
encrt &= 7; encrt &= 7;
_m[tile].m4 &= ~0xF0; SB(_m[tile].m4, 4, 4, encrt);
_m[tile].m4 |= encrt << 4;
} }
break; break;
case MP_TUNNELBRIDGE: case MP_TUNNELBRIDGE:
@ -203,7 +201,9 @@ void PBSClearPath(TileIndex tile, Trackdir trackdir, TileIndex end_tile, Trackdi
if (tile == end_tile && TrackdirToTrack(trackdir) == TrackdirToTrack(end_trackdir)) if (tile == end_tile && TrackdirToTrack(trackdir) == TrackdirToTrack(end_trackdir))
return; return;
if (IsTileType(tile, MP_TUNNELBRIDGE) && (_m[tile].m5 & 0xF0)==0 && (unsigned)(_m[tile].m5 & 3) == TrackdirToExitdir(trackdir)) { if (IsTileType(tile, MP_TUNNELBRIDGE) &&
GB(_m[tile].m5, 4, 4) == 0 &&
GB(_m[tile].m5, 0, 2) == TrackdirToExitdir(trackdir)) {
// this is a tunnel // this is a tunnel
flotr = FindLengthOfTunnel(tile, TrackdirToExitdir(trackdir)); flotr = FindLengthOfTunnel(tile, TrackdirToExitdir(trackdir));

View File

@ -300,8 +300,7 @@ int32 CmdBuildSingleRail(int x, int y, uint32 flags, uint32 p1, uint32 p2)
if (flags & DC_EXEC) { if (flags & DC_EXEC) {
SetTileOwner(tile, _current_player); SetTileOwner(tile, _current_player);
_m[tile].m3 &= ~0x0F; SB(_m[tile].m3, 0, 4, p1);
_m[tile].m3 |= p1;
_m[tile].m5 = (m5 & 0xC7) | 0x20; // railroad under bridge _m[tile].m5 = (m5 & 0xC7) | 0x20; // railroad under bridge
} }
break; break;
@ -322,7 +321,7 @@ int32 CmdBuildSingleRail(int x, int y, uint32 flags, uint32 p1, uint32 p2)
} }
if (m5 & RAIL_TYPE_SPECIAL || if (m5 & RAIL_TYPE_SPECIAL ||
!IsTileOwner(tile, _current_player) || !IsTileOwner(tile, _current_player) ||
(_m[tile].m3 & 0xFU) != p1) { GB(_m[tile].m3, 0, 4) != p1) {
// Get detailed error message // Get detailed error message
return DoCommandByTile(tile, 0, 0, flags, CMD_LANDSCAPE_CLEAR); return DoCommandByTile(tile, 0, 0, flags, CMD_LANDSCAPE_CLEAR);
} }
@ -453,11 +452,7 @@ int32 CmdRemoveSingleRail(int x, int y, uint32 flags, uint32 p1, uint32 p2)
_m[tile].m5 = _m[tile].m5 & 0xC7; _m[tile].m5 = _m[tile].m5 & 0xC7;
break; break;
case MP_STREET: case MP_STREET:
if (!(_m[tile].m5 & 0xF0)) if (!IsLevelCrossing(tile)) return CMD_ERROR;
return CMD_ERROR;
if (_m[tile].m5 & 0xE0)
return CMD_ERROR;
/* This is a crossing, let's check if the direction is correct */ /* This is a crossing, let's check if the direction is correct */
if (_m[tile].m5 & 8) { if (_m[tile].m5 & 8) {
@ -793,8 +788,7 @@ int32 CmdBuildSingleSignal(int x, int y, uint32 flags, uint32 p1, uint32 p2)
if (pre_signal) { if (pre_signal) {
// cycle between normal -> pre -> exit -> combo -> pbs ->... // cycle between normal -> pre -> exit -> combo -> pbs ->...
byte type = ((GetSignalType(tile, track) + 1) % 5); byte type = ((GetSignalType(tile, track) + 1) % 5);
_m[tile].m4 &= ~0x07; SB(_m[tile].m4, 0, 3, type);
_m[tile].m4 |= type ;
} else { } else {
// cycle between two-way -> one-way -> one-way -> ... // cycle between two-way -> one-way -> one-way -> ...
/* TODO: Rewrite switch into something more general */ /* TODO: Rewrite switch into something more general */
@ -961,9 +955,9 @@ int32 CmdRemoveSingleSignal(int x, int y, uint32 flags, uint32 p1, uint32 p2)
_m[tile].m3 &= ~SignalOnTrack(track); _m[tile].m3 &= ~SignalOnTrack(track);
/* removed last signal from tile? */ /* removed last signal from tile? */
if ((_m[tile].m3 & 0xF0) == 0) { if (GB(_m[tile].m3, 4, 4) == 0) {
_m[tile].m5 &= ~RAIL_TYPE_SIGNALS; SB(_m[tile].m2, 4, 4, 0);
_m[tile].m2 &= ~0xF0; SB(_m[tile].m5, 6, 2, RAIL_TYPE_NORMAL >> 6); // XXX >> because the constant is meant for direct application, not use with SB
CLRBIT(_m[tile].m4, 3); // remove any possible semaphores CLRBIT(_m[tile].m4, 3); // remove any possible semaphores
} }
@ -997,7 +991,7 @@ static int32 DoConvertRail(TileIndex tile, uint totype, bool exec)
// change type. // change type.
if (exec) { if (exec) {
_m[tile].m3 = (_m[tile].m3 & 0xF0) + totype; SB(_m[tile].m3, 4, 4, totype);
MarkTileDirtyByTile(tile); MarkTileDirtyByTile(tile);
} }
@ -1757,10 +1751,10 @@ bool SignalVehicleCheck(TileIndex tile, uint track)
* is some kind of invisible black hole, and there is some special magic going * is some kind of invisible black hole, and there is some special magic going
* on in there. This 'workaround' can be removed once the maprewrite is done. * on in there. This 'workaround' can be removed once the maprewrite is done.
*/ */
if (GetTileType(tile)==MP_TUNNELBRIDGE && ((_m[tile].m5 & 0xF0)==0)) { if (GetTileType(tile) == MP_TUNNELBRIDGE && GB(_m[tile].m5, 4, 4) == 0) {
// It is a tunnel we're checking, we need to do some special stuff // It is a tunnel we're checking, we need to do some special stuff
// because VehicleFromPos will not find the vihicle otherwise // because VehicleFromPos will not find the vihicle otherwise
byte direction = _m[tile].m5 & 3; byte direction = GB(_m[tile].m5, 0, 2);
FindLengthOfTunnelResult flotr; FindLengthOfTunnelResult flotr;
flotr = FindLengthOfTunnel(tile, direction); flotr = FindLengthOfTunnel(tile, direction);
dest.track = 1 << (direction & 1); // get the trackbit the vehicle would have if it has not entered the tunnel yet (ie is still visible) dest.track = 1 << (direction & 1); // get the trackbit the vehicle would have if it has not entered the tunnel yet (ie is still visible)
@ -1845,8 +1839,7 @@ static void ChangeSignalStates(SetSignalsData *ssd)
if (_patches.auto_pbs_placement && !(ssd->stop) && (ssd->has_pbssignal == 0xE) && !ssd->has_presignal && (ssd->presignal_exits == 0)) // 0xE means at least 2 pbs signals, and at least 1 entry and 1 exit, see comments ssd->has_pbssignal if (_patches.auto_pbs_placement && !(ssd->stop) && (ssd->has_pbssignal == 0xE) && !ssd->has_presignal && (ssd->presignal_exits == 0)) // 0xE means at least 2 pbs signals, and at least 1 entry and 1 exit, see comments ssd->has_pbssignal
for(i=0; i!=ssd->pbs_cur; i++) { for(i=0; i!=ssd->pbs_cur; i++) {
TileIndex tile = ssd->pbs_tile[i]; TileIndex tile = ssd->pbs_tile[i];
_m[tile].m4 &= ~0x07; SB(_m[tile].m4, 0, 3, SIGTYPE_PBS);
_m[tile].m4 |= 0x04;
MarkTileDirtyByTile(tile); MarkTileDirtyByTile(tile);
}; };
@ -2006,7 +1999,7 @@ static void TileLoop_Track(TileIndex tile)
uint16 m2; uint16 m2;
byte owner; byte owner;
m2 = _m[tile].m2 & 0xF; m2 = GB(_m[tile].m2, 0, 4);
/* special code for alps landscape */ /* special code for alps landscape */
if (_opt.landscape == LT_HILLY) { if (_opt.landscape == LT_HILLY) {
@ -2158,7 +2151,7 @@ static void GetTileDesc_Track(TileIndex tile, TileDesc *td)
STR_NULL, STR_NULL STR_NULL, STR_NULL
}; };
td->str = signal_type[_m[tile].m4 & 0x7]; td->str = signal_type[GB(_m[tile].m4, 0, 3)];
break; break;
} }

View File

@ -231,11 +231,11 @@ int32 CmdRemoveRoad(int x, int y, uint32 flags, uint32 p1, uint32 p2)
ChangeTownRating(t, -road_remove_cost[(byte)edge_road], RATING_ROAD_MINIMUM); ChangeTownRating(t, -road_remove_cost[(byte)edge_road], RATING_ROAD_MINIMUM);
_m[tile].m5 ^= c; _m[tile].m5 ^= c;
if ((_m[tile].m5&0xF) == 0) if (GB(_m[tile].m5, 0, 4) == 0) {
DoClearSquare(tile); DoClearSquare(tile);
else } else {
MarkTileDirtyByTile(tile); MarkTileDirtyByTile(tile);
}
} }
return cost; return cost;
} else if ((ti.map5 & 0xE0) == 0) { // railroad crossing } else if ((ti.map5 & 0xE0) == 0) { // railroad crossing
@ -499,11 +499,11 @@ int32 DoConvertStreetRail(TileIndex tile, uint totype, bool exec)
if (!CheckTileOwnership(tile) || !EnsureNoVehicle(tile)) return CMD_ERROR; if (!CheckTileOwnership(tile) || !EnsureNoVehicle(tile)) return CMD_ERROR;
// tile is already of requested type? // tile is already of requested type?
if ((_m[tile].m4 & 0xFU) == totype) return CMD_ERROR; if (GB(_m[tile].m4, 0, 4) == totype) return CMD_ERROR;
if (exec) { if (exec) {
// change type. // change type.
_m[tile].m4 = (_m[tile].m4 & 0xF0) + totype; SB(_m[tile].m4, 0, 4, totype);
MarkTileDirtyByTile(tile); MarkTileDirtyByTile(tile);
} }
@ -866,7 +866,7 @@ static void DrawTile_Road(TileInfo *ti)
if (m2 > 1) image += 4; if (m2 > 1) image += 4;
} }
DrawGroundSprite(image + (_m[ti->tile].m4 & 0xF) * 12); DrawGroundSprite(image + GB(_m[ti->tile].m4, 0, 4) * 12);
if (_debug_pbs_level >= 1) { if (_debug_pbs_level >= 1) {
byte pbs = PBSTileReserved(ti->tile); byte pbs = PBSTileReserved(ti->tile);
@ -1072,7 +1072,7 @@ static void TileLoop_Road(TileIndex tile)
} else { } else {
b = 0; b = 0;
} }
_m[tile].m4 = (_m[tile].m4 & ~0x70) | (b << 4); SB(_m[tile].m4, 4, 3, b);
MarkTileDirtyByTile(tile); MarkTileDirtyByTile(tile);
} }
} else { } else {
@ -1097,9 +1097,7 @@ void ShowRoadDepotWindow(TileIndex tile);
static void ClickTile_Road(TileIndex tile) static void ClickTile_Road(TileIndex tile)
{ {
if ((_m[tile].m5 & 0xF0) == 0x20) { if (GB(_m[tile].m5, 4, 4) == 2) ShowRoadDepotWindow(tile);
ShowRoadDepotWindow(tile);
}
} }
static const byte _road_trackbits[16] = { static const byte _road_trackbits[16] = {
@ -1163,15 +1161,15 @@ static const byte _roadveh_enter_depot_unk0[4] = {
static uint32 VehicleEnter_Road(Vehicle *v, TileIndex tile, int x, int y) static uint32 VehicleEnter_Road(Vehicle *v, TileIndex tile, int x, int y)
{ {
if (IsLevelCrossing(tile)) { if (IsLevelCrossing(tile)) {
if (v->type == VEH_Train && (_m[tile].m5 & 4) == 0) { if (v->type == VEH_Train && GB(_m[tile].m5, 2, 1) == 0) {
/* train crossing a road */ /* train crossing a road */
SndPlayVehicleFx(SND_0E_LEVEL_CROSSING, v); SndPlayVehicleFx(SND_0E_LEVEL_CROSSING, v);
_m[tile].m5 |= 4; SB(_m[tile].m5, 2, 1, 1);
MarkTileDirtyByTile(tile); MarkTileDirtyByTile(tile);
} }
} else if ((_m[tile].m5&0xF0) == 0x20){ } else if (GB(_m[tile].m5, 4, 4) == 2) {
if (v->type == VEH_Road && v->u.road.frame == 11) { if (v->type == VEH_Road && v->u.road.frame == 11) {
if (_roadveh_enter_depot_unk0[_m[tile].m5&3] == v->u.road.state) { if (_roadveh_enter_depot_unk0[GB(_m[tile].m5, 0, 2)] == v->u.road.state) {
RoadVehEnterDepot(v); RoadVehEnterDepot(v);
return 4; return 4;
} }
@ -1184,15 +1182,13 @@ static void VehicleLeave_Road(Vehicle *v, TileIndex tile, int x, int y)
{ {
if (IsLevelCrossing(tile) && v->type == VEH_Train && v->next == NULL) { if (IsLevelCrossing(tile) && v->type == VEH_Train && v->next == NULL) {
// Turn off level crossing lights // Turn off level crossing lights
_m[tile].m5 &= ~4; SB(_m[tile].m5, 2, 1, 0);
MarkTileDirtyByTile(tile); MarkTileDirtyByTile(tile);
} }
} }
static void ChangeTileOwner_Road(TileIndex tile, PlayerID old_player, PlayerID new_player) static void ChangeTileOwner_Road(TileIndex tile, PlayerID old_player, PlayerID new_player)
{ {
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 == _m[tile].m3 && IsLevelCrossing(tile)) { if (old_player == _m[tile].m3 && IsLevelCrossing(tile)) {
_m[tile].m3 = (new_player == OWNER_SPECTATOR) ? OWNER_NONE : new_player; _m[tile].m3 = (new_player == OWNER_SPECTATOR) ? OWNER_NONE : new_player;
@ -1203,8 +1199,7 @@ static void ChangeTileOwner_Road(TileIndex tile, PlayerID old_player, PlayerID n
if (new_player != 255) { if (new_player != 255) {
SetTileOwner(tile, new_player); SetTileOwner(tile, new_player);
} else { } else {
b = _m[tile].m5&0xF0; if (GB(_m[tile].m5, 4, 4) == 0) {
if (b == 0) {
SetTileOwner(tile, OWNER_NONE); SetTileOwner(tile, OWNER_NONE);
} else if (IsLevelCrossing(tile)) { } else if (IsLevelCrossing(tile)) {
_m[tile].m5 = (_m[tile].m5&8) ? 0x5 : 0xA; _m[tile].m5 = (_m[tile].m5&8) ? 0x5 : 0xA;

View File

@ -284,7 +284,7 @@ static bool EnumRoadSignalFindDepot(TileIndex tile, RoadFindDepotData *rfdd, int
tile += TileOffsByDir(_road_pf_directions[track]); tile += TileOffsByDir(_road_pf_directions[track]);
if (IsTileType(tile, MP_STREET) && if (IsTileType(tile, MP_STREET) &&
(_m[tile].m5 & 0xF0) == 0x20 && GB(_m[tile].m5, 4, 4) == 2 &&
IsTileOwner(tile, rfdd->owner)) { IsTileOwner(tile, rfdd->owner)) {
if (length < rfdd->best_length) { if (length < rfdd->best_length) {
@ -1034,7 +1034,7 @@ static int RoadFindPathToDest(Vehicle *v, TileIndex tile, int enterdir)
} }
if (IsTileType(tile, MP_STREET)) { if (IsTileType(tile, MP_STREET)) {
if ((_m[tile].m5&0xF0) == 0x20 && IsTileOwner(tile, v->owner)) if (GB(_m[tile].m5, 4, 4) == 2 && IsTileOwner(tile, v->owner))
/* Road crossing */ /* Road crossing */
bitmask |= _road_veh_fp_ax_or[_m[tile].m5&3]; bitmask |= _road_veh_fp_ax_or[_m[tile].m5&3];
} else if (IsTileType(tile, MP_STATION)) { } else if (IsTileType(tile, MP_STATION)) {
@ -1237,7 +1237,7 @@ static void RoadVehController(Vehicle *v)
v->cur_speed = 0; v->cur_speed = 0;
dir = _m[v->tile].m5&3; dir = GB(_m[v->tile].m5, 0, 2);
v->direction = dir*2+1; v->direction = dir*2+1;
rd2 = _roadveh_data_2[dir]; rd2 = _roadveh_data_2[dir];
@ -1286,7 +1286,7 @@ static void RoadVehController(Vehicle *v)
} }
if (IsTileType(gp.new_tile, MP_TUNNELBRIDGE) && if (IsTileType(gp.new_tile, MP_TUNNELBRIDGE) &&
(_m[gp.new_tile].m5&0xF0) == 0 && GB(_m[gp.new_tile].m5, 4, 4) == 0 &&
(VehicleEnterTile(v, gp.new_tile, gp.x, gp.y)&4)) { (VehicleEnterTile(v, gp.new_tile, gp.x, gp.y)&4)) {
//new_dir = RoadGetNewDirection(v, gp.x, gp.y) //new_dir = RoadGetNewDirection(v, gp.x, gp.y)

View File

@ -1430,11 +1430,11 @@ int32 DoConvertStationRail(TileIndex tile, uint totype, bool exec)
if (_m[tile].m5 >= 8) return CMD_ERROR; if (_m[tile].m5 >= 8) return CMD_ERROR;
// tile is already of requested type? // tile is already of requested type?
if ((_m[tile].m3 & 0xFU) == totype) return CMD_ERROR; if (GB(_m[tile].m3, 0, 4) == totype) return CMD_ERROR;
if (exec) { if (exec) {
// change type. // change type.
_m[tile].m3 = (_m[tile].m3 & 0xF0) + totype; SB(_m[tile].m3, 0, 4, totype);
MarkTileDirtyByTile(tile); MarkTileDirtyByTile(tile);
} }
@ -2131,7 +2131,7 @@ static void DrawTile_Station(TileInfo *ti)
uint32 image; uint32 image;
const DrawTileSeqStruct *dtss; const DrawTileSeqStruct *dtss;
const DrawTileSprites *t = NULL; const DrawTileSprites *t = NULL;
byte railtype = _m[ti->tile].m3 & 0xF; byte railtype = GB(_m[ti->tile].m3, 0, 4);
const RailtypeInfo *rti = GetRailTypeInfo(railtype); const RailtypeInfo *rti = GetRailTypeInfo(railtype);
SpriteID offset; SpriteID offset;
uint32 relocation = 0; uint32 relocation = 0;

2
tile.h
View File

@ -99,7 +99,7 @@ static inline bool IsTileType(TileIndex tile, TileType type)
static inline bool IsTunnelTile(TileIndex tile) static inline bool IsTunnelTile(TileIndex tile)
{ {
return IsTileType(tile, MP_TUNNELBRIDGE) && (_m[tile].m5 & 0xF0) == 0; return IsTileType(tile, MP_TUNNELBRIDGE) && GB(_m[tile].m5, 4, 4) == 0;
} }
static inline Owner GetTileOwner(TileIndex tile) static inline Owner GetTileOwner(TileIndex tile)

View File

@ -78,7 +78,7 @@ typedef struct DrawTownTileStruct {
static void TownDrawHouseLift(const TileInfo *ti) static void TownDrawHouseLift(const TileInfo *ti)
{ {
AddChildSpriteScreen(0x5A3, 0xE, 0x3C - (_m[ti->tile].m1 & 0x7F)); AddChildSpriteScreen(0x5A3, 0xE, 0x3C - GB(_m[ti->tile].m1, 0, 7));
} }
typedef void TownDrawTileProc(const TileInfo *ti); typedef void TownDrawTileProc(const TileInfo *ti);
@ -183,10 +183,10 @@ static void AnimateTile_Town(TileIndex tile)
SB(_m[tile].m5, 0, 6, i); SB(_m[tile].m5, 0, 6, i);
} }
a = _m[tile].m1 & 0x7F; a = GB(_m[tile].m1, 0, 7);
b = (_m[tile].m5&0x3F) * 6; b = GB(_m[tile].m5, 0, 6) * 6;
a += (a < b) ? 1 : -1; a += (a < b) ? 1 : -1;
_m[tile].m1 = (_m[tile].m1 & 0x80) | a; SB(_m[tile].m1, 0, 7, a);
if (a == b) { if (a == b) {
_m[tile].m1 &= 0x7F; _m[tile].m1 &= 0x7F;
@ -623,7 +623,7 @@ static void GrowTownInTile(TileIndex *tile_ptr, uint mask, int block, Town *t1)
// Reached a tunnel? Then continue at the other side of it. // Reached a tunnel? Then continue at the other side of it.
if (IsTileType(tile, MP_TUNNELBRIDGE) && (_m[tile].m5& ~3) == 4) { if (IsTileType(tile, MP_TUNNELBRIDGE) && (_m[tile].m5& ~3) == 4) {
FindLengthOfTunnelResult flotr = FindLengthOfTunnel(tile, _m[tile].m5&3); FindLengthOfTunnelResult flotr = FindLengthOfTunnel(tile, GB(_m[tile].m5, 0, 2));
*tile_ptr = flotr.tile; *tile_ptr = flotr.tile;
return; return;
} }

View File

@ -1258,8 +1258,8 @@ static void DisableTrainCrossing(TileIndex 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 */
if (_m[tile].m5 & 4) { if (GB(_m[tile].m5, 2, 1) != 0) {
_m[tile].m5 &= ~4; SB(_m[tile].m5, 2, 1, 0);
MarkTileDirtyByTile(tile); MarkTileDirtyByTile(tile);
} }
} }
@ -1322,7 +1322,7 @@ TileIndex GetVehicleTileOutOfTunnel(const Vehicle *v, bool reverse)
return v->tile; return v->tile;
for (tile = v->tile;; tile += delta) { for (tile = v->tile;; tile += delta) {
if (IsTunnelTile(tile) && (_m[tile].m5 & 0x3) != (direction) && GetTileZ(tile) == v->z_pos) if (IsTunnelTile(tile) && GB(_m[tile].m5, 0, 2) != direction && GetTileZ(tile) == v->z_pos)
break; break;
} }
return tile; return tile;
@ -2466,7 +2466,7 @@ static bool CheckCompatibleRail(const Vehicle *v, TileIndex tile)
// tracks over roads, do owner check of tracks // tracks over roads, do owner check of tracks
return return
IsTileOwner(tile, v->owner) && IsTileOwner(tile, v->owner) &&
(v->subtype != TS_Front_Engine || (_m[tile].m4 & 0xF) == v->u.rail.railtype); (v->subtype != TS_Front_Engine || GB(_m[tile].m4, 0, 4) == v->u.rail.railtype);
default: default:
return true; return true;
@ -3173,8 +3173,8 @@ 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) && IsLevelCrossing(tile)) { if (IsTileType(tile, MP_STREET) && IsLevelCrossing(tile)) {
if (!(_m[tile].m5 & 4)) { if (GB(_m[tile].m5, 2, 1) == 0) {
_m[tile].m5 |= 4; SB(_m[tile].m5, 2, 1, 1);
SndPlayVehicleFx(SND_0E_LEVEL_CROSSING, v); SndPlayVehicleFx(SND_0E_LEVEL_CROSSING, v);
MarkTileDirtyByTile(tile); MarkTileDirtyByTile(tile);
} }
@ -3319,7 +3319,7 @@ static bool ValidateTrainInDepot( uint data_a, uint data_b )
void TrainEnterDepot(Vehicle *v, TileIndex tile) void TrainEnterDepot(Vehicle *v, TileIndex tile)
{ {
SetSignalsOnBothDir(tile, _depot_track_ind[_m[tile].m5&3]); SetSignalsOnBothDir(tile, _depot_track_ind[GB(_m[tile].m5, 0, 2)]);
if (v->subtype != TS_Front_Engine) if (v->subtype != TS_Front_Engine)
v = GetFirstVehicleInChain(v); v = GetFirstVehicleInChain(v);

View File

@ -341,7 +341,7 @@ static void ShowBuildTrainWindow(TileIndex tile)
if (tile != 0) { if (tile != 0) {
w->caption_color = GetTileOwner(tile); w->caption_color = GetTileOwner(tile);
WP(w,buildtrain_d).railtype = _m[tile].m3 & 0xF; WP(w,buildtrain_d).railtype = GB(_m[tile].m3, 0, 4);
} else { } else {
w->caption_color = _local_player; w->caption_color = _local_player;
WP(w,buildtrain_d).railtype = GetBestRailtype(GetPlayer(_local_player)); WP(w,buildtrain_d).railtype = GetBestRailtype(GetPlayer(_local_player));

View File

@ -627,7 +627,7 @@ TileIndex CheckTunnelBusy(TileIndex tile, uint *length)
len++; len++;
} while ( } while (
!IsTileType(tile, MP_TUNNELBRIDGE) || !IsTileType(tile, MP_TUNNELBRIDGE) ||
(_m[tile].m5 & 0xF0) != 0 || GB(_m[tile].m5, 4, 4) != 0 ||
(_m[tile].m5 ^ 2) != m5 || (_m[tile].m5 ^ 2) != m5 ||
GetTileZ(tile) != z GetTileZ(tile) != z
); );
@ -676,8 +676,8 @@ static int32 DoClearTunnel(TileIndex tile, uint32 flags)
if (flags & DC_EXEC) { if (flags & DC_EXEC) {
// We first need to request the direction before calling DoClearSquare // We first need to request the direction before calling DoClearSquare
// else the direction is always 0.. dah!! ;) // else the direction is always 0.. dah!! ;)
byte tile_dir = _m[tile].m5&3; byte tile_dir = GB(_m[tile].m5, 0, 2);
byte endtile_dir = _m[endtile].m5&3; byte endtile_dir = GB(_m[endtile].m5, 0, 2);
DoClearSquare(tile); DoClearSquare(tile);
DoClearSquare(endtile); DoClearSquare(endtile);
UpdateSignalsOnSegment(tile, _updsignals_tunnel_dir[tile_dir]); UpdateSignalsOnSegment(tile, _updsignals_tunnel_dir[tile_dir]);
@ -690,7 +690,7 @@ static int32 DoClearTunnel(TileIndex tile, uint32 flags)
static TileIndex FindEdgesOfBridge(TileIndex tile, TileIndex *endtile) static TileIndex FindEdgesOfBridge(TileIndex tile, TileIndex *endtile)
{ {
int direction = _m[tile].m5 & 1; int direction = GB(_m[tile].m5, 0, 1);
TileIndex start; TileIndex start;
// find start of bridge // find start of bridge
@ -723,7 +723,7 @@ static int32 DoClearBridge(TileIndex tile, uint32 flags)
SET_EXPENSES_TYPE(EXPENSES_CONSTRUCTION); SET_EXPENSES_TYPE(EXPENSES_CONSTRUCTION);
direction = _m[tile].m5&1; direction = GB(_m[tile].m5, 0, 1);
/* delete stuff under the middle part if there's a transport route there..? */ /* delete stuff under the middle part if there's a transport route there..? */
if ((_m[tile].m5 & 0xE0) == 0xE0) { if ((_m[tile].m5 & 0xE0) == 0xE0) {
@ -871,14 +871,14 @@ int32 DoConvertTunnelBridgeRail(TileIndex tile, uint totype, bool exec)
// railway tunnel // railway tunnel
if (!CheckTileOwnership(tile)) return CMD_ERROR; if (!CheckTileOwnership(tile)) return CMD_ERROR;
if ((_m[tile].m3 & 0xFU) == totype) return CMD_ERROR; if (GB(_m[tile].m3, 0, 4) == totype) return CMD_ERROR;
endtile = CheckTunnelBusy(tile, &length); endtile = CheckTunnelBusy(tile, &length);
if (endtile == INVALID_TILE) return CMD_ERROR; if (endtile == INVALID_TILE) return CMD_ERROR;
if (exec) { if (exec) {
_m[tile].m3 = (_m[tile].m3 & 0xF0) + totype; SB(_m[tile].m3, 0, 4, totype);
_m[endtile].m3 = (_m[endtile].m3 & 0xF0) + totype; SB(_m[endtile].m3, 0, 4, totype);
MarkTileDirtyByTile(tile); MarkTileDirtyByTile(tile);
MarkTileDirtyByTile(endtile); MarkTileDirtyByTile(endtile);
} }
@ -890,10 +890,10 @@ int32 DoConvertTunnelBridgeRail(TileIndex tile, uint totype, bool exec)
return CMD_ERROR; return CMD_ERROR;
// tile is already of requested type? // tile is already of requested type?
if ((_m[tile].m3 & 0xFU) == totype) return CMD_ERROR; if (GB(_m[tile].m3, 0, 4) == totype) return CMD_ERROR;
// change type. // change type.
if (exec) { if (exec) {
_m[tile].m3 = (_m[tile].m3 & 0xF0) + totype; SB(_m[tile].m3, 0, 4, totype);
MarkTileDirtyByTile(tile); MarkTileDirtyByTile(tile);
} }
return _price.build_rail >> 1; return _price.build_rail >> 1;
@ -919,19 +919,19 @@ int32 DoConvertTunnelBridgeRail(TileIndex tile, uint totype, bool exec)
return CMD_ERROR; return CMD_ERROR;
} }
if ((_m[tile].m3 & 0xFU) == totype) return CMD_ERROR; if (GB(_m[tile].m3, 0, 4) == totype) return CMD_ERROR;
cost = 0; cost = 0;
do { do {
if (exec) { if (exec) {
if (tile == starttile || tile == endtile) { if (tile == starttile || tile == endtile) {
_m[tile].m3 = (_m[tile].m3 & 0xF0) + totype; SB(_m[tile].m3, 0, 4, totype);
} else { } else {
_m[tile].m3 = (_m[tile].m3 & 0x0F) + (totype << 4); SB(_m[tile].m3, 4, 4, totype);
} }
MarkTileDirtyByTile(tile); MarkTileDirtyByTile(tile);
} }
cost += (_price.build_rail>>1); cost += (_price.build_rail>>1);
tile += _m[tile].m5 & 1 ? TileDiffXY(0, 1) : TileDiffXY(1, 0); tile += GB(_m[tile].m5, 0, 1) ? TileDiffXY(0, 1) : TileDiffXY(1, 0);
} while (tile <= endtile); } while (tile <= endtile);
return cost; return cost;
@ -947,7 +947,7 @@ static uint GetBridgeHeight(const TileInfo *ti)
TileIndex tile = ti->tile; TileIndex tile = ti->tile;
// find the end tile of the bridge. // find the end tile of the bridge.
delta = (_m[tile].m5 & 1) ? TileDiffXY(0, 1) : TileDiffXY(1, 0); delta = GB(_m[tile].m5, 0, 1) ? TileDiffXY(0, 1) : TileDiffXY(1, 0);
do { do {
assert((_m[tile].m5 & 0xC0) == 0xC0); // bridge and middle part assert((_m[tile].m5 & 0xC0) == 0xC0); // bridge and middle part
tile += delta; tile += delta;
@ -1124,7 +1124,7 @@ static void DrawTile_TunnelBridge(TileInfo *ti)
} }
if (!(image&1)) { if (!(image&1)) {
const RailtypeInfo *rti = GetRailTypeInfo(_m[ti->tile].m3 & 0xF); const RailtypeInfo *rti = GetRailTypeInfo(GB(_m[ti->tile].m3, 0, 4));
// railway // railway
image = 0x3F3 + (ti->map5 & 1); image = 0x3F3 + (ti->map5 & 1);
if (ti->tileh != 0) image = _track_sloped_sprites[ti->tileh - 1] + 0x3F3; if (ti->tileh != 0) image = _track_sloped_sprites[ti->tileh - 1] + 0x3F3;
@ -1316,7 +1316,7 @@ static void GetTileDesc_TunnelBridge(TileIndex tile, TileDesc *td)
/* scan to the end of the bridge, that's where the owner is stored */ /* scan to the end of the bridge, that's where the owner is stored */
if (_m[tile].m5 & 0x40) { if (_m[tile].m5 & 0x40) {
TileIndexDiff delta = _m[tile].m5 & 1 ? TileDiffXY(0, -1) : TileDiffXY(-1, 0); TileIndexDiff delta = GB(_m[tile].m5, 0, 1) ? TileDiffXY(0, -1) : TileDiffXY(-1, 0);
do tile += delta; while (_m[tile].m5 & 0x40); do tile += delta; while (_m[tile].m5 & 0x40);
} }
@ -1450,7 +1450,7 @@ static uint32 VehicleEnter_TunnelBridge(Vehicle *v, TileIndex tile, int x, int y
int dir, vdir; int dir, vdir;
byte fc; byte fc;
if ((_m[tile].m5 & 0xF0) == 0) { if (GB(_m[tile].m5, 4, 4) == 0) {
z = GetSlopeZ(x, y) - v->z_pos; z = GetSlopeZ(x, y) - v->z_pos;
if (myabs(z) > 2) if (myabs(z) > 2)
return 8; return 8;
@ -1458,7 +1458,7 @@ static uint32 VehicleEnter_TunnelBridge(Vehicle *v, TileIndex tile, int x, int y
if (v->type == VEH_Train) { if (v->type == VEH_Train) {
fc = (x&0xF)+(y<<4); fc = (x&0xF)+(y<<4);
dir = _m[tile].m5 & 3; dir = GB(_m[tile].m5, 0, 2);
vdir = v->direction >> 1; vdir = v->direction >> 1;
if (v->u.rail.track != 0x40 && dir == vdir) { if (v->u.rail.track != 0x40 && dir == vdir) {
@ -1487,7 +1487,7 @@ static uint32 VehicleEnter_TunnelBridge(Vehicle *v, TileIndex tile, int x, int y
} }
} else if (v->type == VEH_Road) { } else if (v->type == VEH_Road) {
fc = (x&0xF)+(y<<4); fc = (x&0xF)+(y<<4);
dir = _m[tile].m5 & 3; dir = GB(_m[tile].m5, 0, 2);
vdir = v->direction >> 1; vdir = v->direction >> 1;
// Enter tunnel? // Enter tunnel?
@ -1542,7 +1542,7 @@ TileIndex GetVehicleOutOfTunnelTile(const Vehicle *v)
byte z = v->z_pos; byte z = v->z_pos;
for (tile = v->tile;; tile += delta) { for (tile = v->tile;; tile += delta) {
if (IsTileType(tile, MP_TUNNELBRIDGE) && (_m[tile].m5 & 0xF0) == 0 && if (IsTileType(tile, MP_TUNNELBRIDGE) && GB(_m[tile].m5, 4, 4) == 0 &&
GetTileZ(tile) == z) GetTileZ(tile) == z)
break; break;
} }

View File

@ -144,7 +144,7 @@ static int32 DoBuildShiplift(TileIndex tile, int dir, uint32 flags)
static int32 RemoveShiplift(TileIndex tile, uint32 flags) static int32 RemoveShiplift(TileIndex tile, uint32 flags)
{ {
TileIndexDiff delta = TileOffsByDir(_m[tile].m5 & 3); TileIndexDiff delta = TileOffsByDir(GB(_m[tile].m5, 0, 2));
// make sure no vehicle is on the tile. // make sure no vehicle is on the tile.
if (!EnsureNoVehicle(tile) || !EnsureNoVehicle(tile + delta) || !EnsureNoVehicle(tile - delta)) if (!EnsureNoVehicle(tile) || !EnsureNoVehicle(tile + delta) || !EnsureNoVehicle(tile - delta))
@ -500,7 +500,7 @@ static void TileLoopWaterHelper(TileIndex tile, const TileIndexDiffC *offs)
switch (GetTileType(target)) { switch (GetTileType(target)) {
case MP_RAILWAY: { case MP_RAILWAY: {
uint slope = GetTileSlope(target, NULL); uint slope = GetTileSlope(target, NULL);
byte tracks = _m[target].m5 & 0x3F; byte tracks = GB(_m[target].m5, 0, 6);
if (!( if (!(
(slope == 1 && tracks == 0x20) || (slope == 1 && tracks == 0x20) ||
(slope == 2 && tracks == 0x04) || (slope == 2 && tracks == 0x04) ||