(svn r1548) Move AI_PATHFINDER_IS_ROAD from ai.h to ai_pathfinder.c to avoid global namespace pollution, turn it into a function called IsRoad and improve the commments a bit
authortron
Mon, 17 Jan 2005 09:16:43 +0000
changeset 1047 df93a1386892
parent 1046 f1d46abf7d35
child 1048 8611c5c02dcb
(svn r1548) Move AI_PATHFINDER_IS_ROAD from ai.h to ai_pathfinder.c to avoid global namespace pollution, turn it into a function called IsRoad and improve the commments a bit
ai.h
ai_pathfinder.c
--- a/ai.h	Sun Jan 16 18:19:33 2005 +0000
+++ b/ai.h	Mon Jan 17 09:16:43 2005 +0000
@@ -228,13 +228,6 @@
 #define AI_PATHFINDER_FLAG_BRIDGE 1
 #define AI_PATHFINDER_FLAG_TUNNEL 2
 
-// A macro for mp_street, where 0x20 is depot
-//   mp_tunnelbridge, where 0xf0 is a bridge, and 0x4/0x2 means: roadtunnel/bridge
-#define AI_PATHFINDER_IS_ROAD(tile) ((IsTileType(tile, MP_STREET) && !(_map5[tile] & 0x20)) || \
-(IsTileType(tile, MP_TUNNELBRIDGE) && \
-	(((_map5[tile] & 0x80) == 0 && (_map5[tile] & 0x4) == 0x4) || \
-	 ((_map5[tile] & 0x80) != 0 && (_map5[tile] & 0x2) == 0x2))))
-
 typedef void AiNew_StateFunction(Player *p);
 
 // ai_new.c
--- a/ai_pathfinder.c	Sun Jan 16 18:19:33 2005 +0000
+++ b/ai_pathfinder.c	Mon Jan 17 09:16:43 2005 +0000
@@ -27,6 +27,21 @@
     return true;
 }
 
+
+static bool IsRoad(TileIndex tile)
+{
+	return
+		// MP_STREET, but not a road depot?
+		(IsTileType(tile, MP_STREET) && !(_map5[tile] & 0x20)) ||
+		(IsTileType(tile, MP_TUNNELBRIDGE) && (
+			// road tunnel?
+			((_map5[tile] & 0x80) == 0 && (_map5[tile] & 0x4) == 0x4) ||
+			// road bridge?
+			((_map5[tile] & 0x80) != 0 && (_map5[tile] & 0x2) == 0x2)
+		));
+}
+
+
 // Checks if a tile 'a' is between the tiles 'b' and 'c'
 #define TILES_BETWEEN(a, b, c) (TileX(a) >= TileX(b) && TileX(a) <= TileX(c) && TileY(a) >= TileY(b) && TileY(a) <= TileY(c))
 
@@ -186,7 +201,7 @@
        		//  We do this simply by just building the tile!
 
        		// If the next step is a bridge, we have to enter it the right way
-       		if (!PathFinderInfo->rail_or_road && AI_PATHFINDER_IS_ROAD(current->path.node.tile + TileOffsByDir(i))) {
+       		if (!PathFinderInfo->rail_or_road && IsRoad(current->path.node.tile + TileOffsByDir(i))) {
        			if (IsTileType(current->path.node.tile + TileOffsByDir(i), MP_TUNNELBRIDGE)) {
        				// An existing bridge... let's test the direction ;)
        				if ((_map5[current->path.node.tile + TileOffsByDir(i)] & 1U) != (i & 1)) continue;
@@ -198,7 +213,7 @@
        			}
        		}
        		// But also if we are on a bridge, we can only move a certain direction
-       		if (!PathFinderInfo->rail_or_road && AI_PATHFINDER_IS_ROAD(current->path.node.tile)) {
+       		if (!PathFinderInfo->rail_or_road && IsRoad(current->path.node.tile)) {
        			if (IsTileType(current->path.node.tile, MP_TUNNELBRIDGE)) {
        				// An existing bridge/tunnel... let's test the direction ;)
        				if ((_map5[current->path.node.tile] & 1U) != (i & 1)) continue;
@@ -240,7 +255,7 @@
        			} else {
        				// Road check
        				dir = AiNew_GetRoadDirection(current->path.parent->node.tile, current->path.node.tile, current->path.node.tile + TileOffsByDir(i));
-       				if (AI_PATHFINDER_IS_ROAD(current->path.node.tile)) {
+       				if (IsRoad(current->path.node.tile)) {
        					if (IsTileType(current->path.node.tile, MP_TUNNELBRIDGE)) {
        						// We have a bridge, how nicely! We should mark it...
        						dir = 0;
@@ -361,7 +376,7 @@
 	if (!PathFinderInfo->rail_or_road) {
 		// Road has the lovely advantage it can use other road... check if
 		//  the current tile is road, and if so, give a good bonus
-		if (AI_PATHFINDER_IS_ROAD(current->tile)) {
+		if (IsRoad(current->tile)) {
 			res -= AI_PATHFINDER_ROAD_ALREADY_EXISTS_BONUS;
 		}
 	}
@@ -378,7 +393,7 @@
 					res += AI_PATHFINDER_TILE_GOES_UP_PENALTY;
 				}
 			} else {
-				if (!(AI_PATHFINDER_IS_ROAD(parent->path.node.tile) && IsTileType(parent->path.node.tile, MP_TUNNELBRIDGE))) {
+				if (!(IsRoad(parent->path.node.tile) && IsTileType(parent->path.node.tile, MP_TUNNELBRIDGE))) {
 					r = GetRoadFoundation(parent_ti.tileh, AiNew_GetRoadDirection(parent->path.parent->node.tile, parent->path.node.tile, current->tile));
 					if (r >= 15 || r == 0)
 						res += AI_PATHFINDER_TILE_GOES_UP_PENALTY;
@@ -423,7 +438,7 @@
 		if (parent->path.parent != NULL &&
 			AiNew_GetDirection(current->tile, parent->path.node.tile) != AiNew_GetDirection(parent->path.node.tile, parent->path.parent->node.tile)) {
 			// When road exists, we don't like turning, but its free, so don't be to piggy about it
-			if (AI_PATHFINDER_IS_ROAD(parent->path.node.tile))
+			if (IsRoad(parent->path.node.tile))
 				res += AI_PATHFINDER_DIRECTION_CHANGE_ON_EXISTING_ROAD_PENALTY;
 			else
 				res += AI_PATHFINDER_DIRECTION_CHANGE_PENALTY;