summaryrefslogtreecommitdiff
path: root/npf.c
diff options
context:
space:
mode:
authortron <tron@openttd.org>2005-10-05 07:20:26 +0000
committertron <tron@openttd.org>2005-10-05 07:20:26 +0000
commitae4a1f3675bab50b93e443dcca07fd297fcdc58d (patch)
tree8281c38dbbb38386dacf57d352e00b62be0edc77 /npf.c
parent102cf2615f8ffb4e260680a5f2b3b7d9f2a7a130 (diff)
downloadopenttd-ae4a1f3675bab50b93e443dcca07fd297fcdc58d.tar.xz
(svn r3019) -Codechange: Replace explicit shifting/anding/oring with GB and SB
Diffstat (limited to 'npf.c')
-rw-r--r--npf.c34
1 files changed, 21 insertions, 13 deletions
diff --git a/npf.c b/npf.c
index ff5a70137..17dfa4310 100644
--- a/npf.c
+++ b/npf.c
@@ -60,8 +60,10 @@ static bool IsEndOfLine(TileIndex tile, Trackdir trackdir, RailType enginetype)
uint32 ts;
/* 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;
+ }
/* Cannot go through the back of a depot */
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;
/* 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))
- return true;
+ if (IsTileType(dst_tile, MP_TUNNELBRIDGE) &&
+ 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 */
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);
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
* facing the tunnel exit */
FindLengthOfTunnelResult flotr;
@@ -364,13 +369,13 @@ static void NPFMarkTile(TileIndex tile)
/* DEBUG: mark visited tiles by mowing the grass under them
* ;-) */
if (!IsTileDepotType(tile, TRANSPORT_RAIL)) {
- _m[tile].m2 &= ~15; /* Clear bits 0-3 */
+ SB(_m[tile].m2, 0, 4, 0);
MarkTileDirtyByTile(tile);
}
break;
case MP_STREET:
if (!IsTileDepotType(tile, TRANSPORT_ROAD)) {
- _m[tile].m4 &= ~0x70; /* Clear bits 4-6 */
+ SB(_m[tile].m2, 4, 3, 0);
MarkTileDirtyByTile(tile);
}
break;
@@ -408,7 +413,7 @@ static int32 NPFRoadPathCost(AyStar* as, AyStarNode* current, OpenListNode* pare
/* Determine base length */
switch (GetTileType(tile)) {
case MP_TUNNELBRIDGE:
- if ((_m[tile].m5 & 0xF0)==0) {
+ if (GB(_m[tile].m5, 4, 4) == 0) {
cost = NPFTunnelCost(current);
break;
}
@@ -452,7 +457,7 @@ static int32 NPFRailPathCost(AyStar* as, AyStarNode* current, OpenListNode* pare
/* Determine base length */
switch (GetTileType(tile)) {
case MP_TUNNELBRIDGE:
- if ((_m[tile].m5 & 0xF0)==0) {
+ if (GB(_m[tile].m5, 4, 4) == 0) {
cost = NPFTunnelCost(current);
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
* 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 */
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 */
@@ -670,7 +675,7 @@ static bool VehicleMayEnterTile(Owner owner, TileIndex tile, DiagDirection enter
if (
(_m[tile].m5 & 0xFC) == 0 /* railway tunnel */
|| (_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);
break;
@@ -704,7 +709,8 @@ static void NPFFollowTrack(AyStar* aystar, OpenListNode* current)
aystar->EndNodeCheck(aystar, current);
/* 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,
* otherwise we wouldn't have got here. It is also facing us,
* 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
* 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 */
- 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;
+ }
/* check correct rail type (mono, maglev, etc) */
if (type == TRANSPORT_RAIL) {