changeset 3088:4b45e7ce0d2d draft

(svn r3677) Remove the FindLandscapeHeightByTile()s from the default AI. The corresponding TileInfos look like global variables at the first glance, but always get written to before reading in each function they are used in.
author tron <tron@openttd.org>
date Mon, 27 Feb 2006 08:08:10 +0000
parents ebffade131ee
children 58bd38c42ea7
files ai/default/default.c
diffstat 1 files changed, 30 insertions(+), 27 deletions(-) [+]
line wrap: on
line diff
--- a/ai/default/default.c
+++ b/ai/default/default.c
@@ -1837,7 +1837,6 @@
 	TileIndex cur_best_tile, best_tile;
 	TileIndex bridge_end_tile;
 	Player *player;
-	TileInfo ti;
 } AiRailFinder;
 
 static const byte _ai_table_15[4][8] = {
@@ -1916,26 +1915,29 @@
 static inline void AiCheckBuildRailBridgeHere(AiRailFinder *arf, TileIndex tile, const byte *p)
 {
 	TileIndex tile_new;
+	uint tileh;
+	uint z;
 	bool flag;
 
 	int dir2 = p[0] & 3;
 
-	FindLandscapeHeightByTile(&arf->ti, tile);
-
-	if (arf->ti.tileh == _dir_table_1[dir2] || (arf->ti.tileh==0 && arf->ti.z!=0)) {
+	tileh = GetTileSlope(tile, &z);
+	if (tileh == _dir_table_1[dir2] || (tileh == 0 && z != 0)) {
 		tile_new = tile;
 		// Allow bridges directly over bottom tiles
-		flag = arf->ti.z == 0;
+		flag = z == 0;
 		for (;;) {
+			TileType type;
+
 			if ((TileIndexDiff)tile_new < -TileOffsByDir(dir2)) return; // Wraping around map, no bridge possible!
 			tile_new = TILE_MASK(tile_new + TileOffsByDir(dir2));
-			FindLandscapeHeightByTile(&arf->ti, tile_new);
-			if (arf->ti.tileh != 0 || arf->ti.type == MP_CLEAR || arf->ti.type == MP_TREES) {
+			type = GetTileType(tile_new);
+
+			if (type == MP_CLEAR || type == MP_TREES || GetTileSlope(tile_new, NULL) != 0) {
 				if (!flag) return;
 				break;
 			}
-			if (arf->ti.type != MP_WATER && arf->ti.type != MP_RAILWAY && arf->ti.type != MP_STREET)
-				return;
+			if (type != MP_WATER && type != MP_RAILWAY && type != MP_STREET) return;
 			flag = true;
 		}
 
@@ -1955,9 +1957,9 @@
 
 static inline void AiCheckBuildRailTunnelHere(AiRailFinder *arf, TileIndex tile, const byte *p)
 {
-	FindLandscapeHeightByTile(&arf->ti, tile);
-
-	if (arf->ti.tileh == _dir_table_2[p[0]&3] && arf->ti.z!=0) {
+	uint z;
+
+	if (GetTileSlope(tile, &z) == _dir_table_2[p[0] & 3] && z != 0) {
 		int32 cost = DoCommandByTile(tile, arf->player->ai.railtype_to_use, 0, DC_AUTO, CMD_BUILD_TUNNEL);
 
 		if (!CmdFailed(cost) && cost <= (arf->player->player_money>>4)) {
@@ -2011,8 +2013,7 @@
 	p = _ai_table_15[dir];
 
 	// Try to build a single rail in all directions.
-	FindLandscapeHeightByTile(&arf->ti, tile);
-	if (arf->ti.z == 0) {
+	if (GetTileZ(tile) == 0) {
 		p += 6;
 	} else {
 		do {
@@ -2669,7 +2670,6 @@
 	TileIndex cur_best_tile, best_tile;
 	TileIndex bridge_end_tile;
 	Player *player;
-	TileInfo ti;
 } AiRoadFinder;
 
 typedef struct AiRoadEnum {
@@ -2790,27 +2790,31 @@
 static inline void AiCheckBuildRoadBridgeHere(AiRoadFinder *arf, TileIndex tile, const byte *p)
 {
 	TileIndex tile_new;
+	uint tileh;
+	uint z;
 	bool flag;
 
 	int dir2 = p[0] & 3;
 
-	FindLandscapeHeightByTile(&arf->ti, tile);
-	if (arf->ti.tileh == _dir_table_1[dir2] || (arf->ti.tileh==0 && arf->ti.z!=0)) {
+	tileh = GetTileSlope(tile, &z);
+	if (tileh == _dir_table_1[dir2] || (tileh == 0 && z != 0)) {
 		tile_new = tile;
 		// Allow bridges directly over bottom tiles
-		flag = arf->ti.z == 0;
+		flag = z == 0;
 		for (;;) {
+			TileType type;
+
 			if ((TileIndexDiff)tile_new < -TileOffsByDir(dir2)) return; // Wraping around map, no bridge possible!
 			tile_new = TILE_MASK(tile_new + TileOffsByDir(dir2));
-			FindLandscapeHeightByTile(&arf->ti, tile_new);
-			if (arf->ti.tileh != 0 || arf->ti.type == MP_CLEAR || arf->ti.type == MP_TREES) {
+			type = GetTileType(tile_new);
+
+			if (type == MP_CLEAR || type == MP_TREES || GetTileSlope(tile, NULL) != 0) {
 				// Allow a bridge if either we have a tile that's water, rail or street,
 				// or if we found an up tile.
 				if (!flag) return;
 				break;
 			}
-			if (arf->ti.type != MP_WATER && arf->ti.type != MP_RAILWAY && arf->ti.type != MP_STREET)
-				return;
+			if (type != MP_WATER && type != MP_RAILWAY && type != MP_STREET) return;
 			flag = true;
 		}
 
@@ -2828,9 +2832,9 @@
 
 static inline void AiCheckBuildRoadTunnelHere(AiRoadFinder *arf, TileIndex tile, const byte *p)
 {
-	FindLandscapeHeightByTile(&arf->ti, tile);
-
-	if (arf->ti.tileh == _dir_table_2[p[0]&3] && arf->ti.z!=0) {
+	uint z;
+
+	if (GetTileSlope(tile, &z) == _dir_table_2[p[0] & 3] && z != 0) {
 		int32 cost = DoCommandByTile(tile, 0x200, 0, DC_AUTO, CMD_BUILD_TUNNEL);
 
 		if (!CmdFailed(cost) && cost <= (arf->player->player_money>>4)) {
@@ -2879,8 +2883,7 @@
 	p = _ai_table_15[dir];
 
 	// Try to build a single rail in all directions.
-	FindLandscapeHeightByTile(&arf->ti, tile);
-	if (arf->ti.z == 0) {
+	if (GetTileZ(tile) == 0) {
 		p += 6;
 	} else {
 		do {