1
0
Fork 0

(svn r3644) Don't use FindLandscapeHeightByTile() when it's overkill - often it was just a complicated way of writing GetTileSlope(tile, NULL)

release/0.5
tron 2006-02-21 07:41:54 +00:00
parent 35fb17947a
commit 4b46883751
6 changed files with 83 additions and 86 deletions

View File

@ -315,18 +315,18 @@ static void AyStar_AiPathFinder_GetNeighbours(AyStar *aystar, OpenListNode *curr
// Next step, check for bridges and tunnels // Next step, check for bridges and tunnels
if (current->path.parent != NULL && current->path.node.user_data[0] == 0) { if (current->path.parent != NULL && current->path.node.user_data[0] == 0) {
TileInfo ti;
// First we get the dir from this tile and his parent // First we get the dir from this tile and his parent
int dir = AiNew_GetDirection(current->path.parent->node.tile, current->path.node.tile); int dir = AiNew_GetDirection(current->path.parent->node.tile, current->path.node.tile);
// It means we can only walk with the track, so the bridge has to be in the same direction // It means we can only walk with the track, so the bridge has to be in the same direction
TileIndex tile = current->path.node.tile; TileIndex tile = current->path.node.tile;
TileIndex new_tile = tile; TileIndex new_tile = tile;
uint tileh;
FindLandscapeHeightByTile(&ti, tile); tileh = GetTileSlope(tile, NULL);
// Bridges can only be build on land that is not flat // Bridges can only be build on land that is not flat
// And if there is a road or rail blocking // And if there is a road or rail blocking
if (ti.tileh != 0 || if (tileh != 0 ||
(PathFinderInfo->rail_or_road && IsTileType(tile + TileOffsByDir(dir), MP_STREET)) || (PathFinderInfo->rail_or_road && IsTileType(tile + TileOffsByDir(dir), MP_STREET)) ||
(!PathFinderInfo->rail_or_road && IsTileType(tile + TileOffsByDir(dir), MP_RAILWAY))) { (!PathFinderInfo->rail_or_road && IsTileType(tile + TileOffsByDir(dir), MP_RAILWAY))) {
for (;;) { for (;;) {
@ -353,14 +353,14 @@ static void AyStar_AiPathFinder_GetNeighbours(AyStar *aystar, OpenListNode *curr
// Next, check for tunnels! // Next, check for tunnels!
// Tunnels can only be build with tileh of 3, 6, 9 or 12, depending on the direction // Tunnels can only be build with tileh of 3, 6, 9 or 12, depending on the direction
// For now, we check both sides for this tile.. terraforming gives fuzzy result // For now, we check both sides for this tile.. terraforming gives fuzzy result
if ((dir == 0 && ti.tileh == 12) || if ((dir == 0 && tileh == 12) ||
(dir == 1 && ti.tileh == 6) || (dir == 1 && tileh == 6) ||
(dir == 2 && ti.tileh == 3) || (dir == 2 && tileh == 3) ||
(dir == 3 && ti.tileh == 9)) { (dir == 3 && tileh == 9)) {
// Now simply check if a tunnel can be build // Now simply check if a tunnel can be build
ret = AI_DoCommand(tile, (PathFinderInfo->rail_or_road?0:0x200), 0, DC_AUTO, CMD_BUILD_TUNNEL); ret = AI_DoCommand(tile, (PathFinderInfo->rail_or_road?0:0x200), 0, DC_AUTO, CMD_BUILD_TUNNEL);
FindLandscapeHeightByTile(&ti, _build_tunnel_endtile); tileh = GetTileSlope(_build_tunnel_endtile, NULL);
if (!CmdFailed(ret) && (ti.tileh == 3 || ti.tileh == 6 || ti.tileh == 9 || ti.tileh == 12)) { if (!CmdFailed(ret) && (tileh == 3 || tileh == 6 || tileh == 9 || tileh == 12)) {
aystar->neighbours[aystar->num_neighbours].tile = _build_tunnel_endtile; aystar->neighbours[aystar->num_neighbours].tile = _build_tunnel_endtile;
aystar->neighbours[aystar->num_neighbours].user_data[0] = AI_PATHFINDER_FLAG_TUNNEL + (dir << 8); aystar->neighbours[aystar->num_neighbours].user_data[0] = AI_PATHFINDER_FLAG_TUNNEL + (dir << 8);
aystar->neighbours[aystar->num_neighbours++].direction = 0; aystar->neighbours[aystar->num_neighbours++].direction = 0;
@ -382,11 +382,8 @@ static int32 AyStar_AiPathFinder_CalculateG(AyStar *aystar, AyStarNode *current,
{ {
Ai_PathFinderInfo *PathFinderInfo = (Ai_PathFinderInfo*)aystar->user_target; Ai_PathFinderInfo *PathFinderInfo = (Ai_PathFinderInfo*)aystar->user_target;
int r, res = 0; int r, res = 0;
TileInfo ti, parent_ti; uint tileh = GetTileSlope(current->tile, NULL);
uint parent_tileh = GetTileSlope(parent->path.node.tile, NULL);
// Gather some information about the tile..
FindLandscapeHeightByTile(&ti, current->tile);
FindLandscapeHeightByTile(&parent_ti, parent->path.node.tile);
// Check if we hit the end-tile // Check if we hit the end-tile
if (TILES_BETWEEN(current->tile, PathFinderInfo->end_tile_tl, PathFinderInfo->end_tile_br)) { if (TILES_BETWEEN(current->tile, PathFinderInfo->end_tile_tl, PathFinderInfo->end_tile_br)) {
@ -416,20 +413,20 @@ static int32 AyStar_AiPathFinder_CalculateG(AyStar *aystar, AyStarNode *current,
// when there is a flat land all around, they are more expensive to build, and // when there is a flat land all around, they are more expensive to build, and
// especially they essentially block the ability to connect or cross the road // especially they essentially block the ability to connect or cross the road
// from one side. // from one side.
if (parent_ti.tileh != 0 && parent->path.parent != NULL) { if (parent_tileh != 0 && parent->path.parent != NULL) {
// Skip if the tile was from a bridge or tunnel // Skip if the tile was from a bridge or tunnel
if (parent->path.node.user_data[0] == 0 && current->user_data[0] == 0) { if (parent->path.node.user_data[0] == 0 && current->user_data[0] == 0) {
if (PathFinderInfo->rail_or_road) { if (PathFinderInfo->rail_or_road) {
r = GetRailFoundation(parent_ti.tileh, 1 << AiNew_GetRailDirection(parent->path.parent->node.tile, parent->path.node.tile, current->tile)); r = GetRailFoundation(parent_tileh, 1 << AiNew_GetRailDirection(parent->path.parent->node.tile, parent->path.node.tile, current->tile));
// Maybe is BRIDGE_NO_FOUNDATION a bit strange here, but it contains just the right information.. // Maybe is BRIDGE_NO_FOUNDATION a bit strange here, but it contains just the right information..
if (r >= 15 || (r == 0 && (BRIDGE_NO_FOUNDATION & (1 << ti.tileh)))) { if (r >= 15 || (r == 0 && (BRIDGE_NO_FOUNDATION & (1 << tileh)))) {
res += AI_PATHFINDER_TILE_GOES_UP_PENALTY; res += AI_PATHFINDER_TILE_GOES_UP_PENALTY;
} else { } else {
res += AI_PATHFINDER_FOUNDATION_PENALTY; res += AI_PATHFINDER_FOUNDATION_PENALTY;
} }
} else { } else {
if (!(IsRoad(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)); r = GetRoadFoundation(parent_tileh, AiNew_GetRoadDirection(parent->path.parent->node.tile, parent->path.node.tile, current->tile));
if (r >= 15 || r == 0) if (r >= 15 || r == 0)
res += AI_PATHFINDER_TILE_GOES_UP_PENALTY; res += AI_PATHFINDER_TILE_GOES_UP_PENALTY;
else else
@ -453,17 +450,17 @@ static int32 AyStar_AiPathFinder_CalculateG(AyStar *aystar, AyStarNode *current,
res += AI_PATHFINDER_BRIDGE_PENALTY * GetBridgeLength(current->tile, parent->path.node.tile); res += AI_PATHFINDER_BRIDGE_PENALTY * GetBridgeLength(current->tile, parent->path.node.tile);
// Check if we are going up or down, first for the starting point // Check if we are going up or down, first for the starting point
// In user_data[0] is at the 8th bit the direction // In user_data[0] is at the 8th bit the direction
if (!(BRIDGE_NO_FOUNDATION & (1 << parent_ti.tileh))) { if (!(BRIDGE_NO_FOUNDATION & (1 << parent_tileh))) {
if (GetBridgeFoundation(parent_ti.tileh, (current->user_data[0] >> 8) & 1) < 15) if (GetBridgeFoundation(parent_tileh, (current->user_data[0] >> 8) & 1) < 15)
res += AI_PATHFINDER_BRIDGE_GOES_UP_PENALTY; res += AI_PATHFINDER_BRIDGE_GOES_UP_PENALTY;
} }
// Second for the end point // Second for the end point
if (!(BRIDGE_NO_FOUNDATION & (1 << ti.tileh))) { if (!(BRIDGE_NO_FOUNDATION & (1 << tileh))) {
if (GetBridgeFoundation(ti.tileh, (current->user_data[0] >> 8) & 1) < 15) if (GetBridgeFoundation(tileh, (current->user_data[0] >> 8) & 1) < 15)
res += AI_PATHFINDER_BRIDGE_GOES_UP_PENALTY; res += AI_PATHFINDER_BRIDGE_GOES_UP_PENALTY;
} }
if (parent_ti.tileh == 0) res += AI_PATHFINDER_BRIDGE_GOES_UP_PENALTY; if (parent_tileh == 0) res += AI_PATHFINDER_BRIDGE_GOES_UP_PENALTY;
if (ti.tileh == 0) res += AI_PATHFINDER_BRIDGE_GOES_UP_PENALTY; if (tileh == 0) res += AI_PATHFINDER_BRIDGE_GOES_UP_PENALTY;
} }
// To prevent the AI from taking the fastest way in tiles, but not the fastest way // To prevent the AI from taking the fastest way in tiles, but not the fastest way

View File

@ -840,10 +840,8 @@ static void AiNew_State_FindDepot(Player *p)
// Is the terrain clear? // Is the terrain clear?
if (IsTileType(tile + TileOffsByDir(j), MP_CLEAR) || if (IsTileType(tile + TileOffsByDir(j), MP_CLEAR) ||
IsTileType(tile + TileOffsByDir(j), MP_TREES)) { IsTileType(tile + TileOffsByDir(j), MP_TREES)) {
TileInfo ti;
FindLandscapeHeightByTile(&ti, tile);
// If the current tile is on a slope (tileh != 0) then we do not allow this // If the current tile is on a slope (tileh != 0) then we do not allow this
if (ti.tileh != 0) continue; if (GetTileSlope(tile, NULL) != 0) continue;
// Check if everything went okay.. // Check if everything went okay..
r = AiNew_Build_Depot(p, tile + TileOffsByDir(j), j ^ 2, 0); r = AiNew_Build_Depot(p, tile + TileOffsByDir(j), j ^ 2, 0);
if (CmdFailed(r)) continue; if (CmdFailed(r)) continue;

View File

@ -620,25 +620,24 @@ int32 CmdRemoveLongRoad(int x, int y, uint32 flags, uint32 p1, uint32 p2)
*/ */
int32 CmdBuildRoadDepot(int x, int y, uint32 flags, uint32 p1, uint32 p2) int32 CmdBuildRoadDepot(int x, int y, uint32 flags, uint32 p1, uint32 p2)
{ {
TileInfo ti;
int32 cost; int32 cost;
Depot *dep; Depot *dep;
TileIndex tile; TileIndex tile;
uint tileh;
SET_EXPENSES_TYPE(EXPENSES_CONSTRUCTION); SET_EXPENSES_TYPE(EXPENSES_CONSTRUCTION);
if (p1 > 3) return CMD_ERROR; // check direction if (p1 > 3) return CMD_ERROR; // check direction
FindLandscapeHeight(&ti, x, y); tile = TileVirtXY(x, y);
tile = ti.tile;
if (!EnsureNoVehicle(tile)) return CMD_ERROR; if (!EnsureNoVehicle(tile)) return CMD_ERROR;
if (ti.tileh != 0 && ( tileh = GetTileSlope(tile, NULL);
if (tileh != 0 && (
!_patches.build_on_slopes || !_patches.build_on_slopes ||
IsSteepTileh(ti.tileh) || IsSteepTileh(tileh) ||
!CanBuildDepotByTileh(p1, ti.tileh) !CanBuildDepotByTileh(p1, tileh)
)) { )) {
return_cmd_error(STR_0007_FLAT_LAND_REQUIRED); return_cmd_error(STR_0007_FLAT_LAND_REQUIRED);
} }

View File

@ -1691,27 +1691,29 @@ static int32 RemoveAirport(Station *st, uint32 flags)
*/ */
int32 CmdBuildBuoy(int x, int y, uint32 flags, uint32 p1, uint32 p2) int32 CmdBuildBuoy(int x, int y, uint32 flags, uint32 p1, uint32 p2)
{ {
TileInfo ti; TileIndex tile = TileVirtXY(x, y);
Station *st; Station *st;
SET_EXPENSES_TYPE(EXPENSES_CONSTRUCTION); SET_EXPENSES_TYPE(EXPENSES_CONSTRUCTION);
FindLandscapeHeight(&ti, x, y); if (!IsTileType(tile, MP_WATER) ||
_m[tile].m5 != 0 ||
if (ti.type != MP_WATER || ti.tileh != 0 || ti.map5 != 0 || ti.tile == 0) GetTileSlope(tile, NULL) != 0 ||
tile == 0) {
return_cmd_error(STR_304B_SITE_UNSUITABLE); return_cmd_error(STR_304B_SITE_UNSUITABLE);
}
st = AllocateStation(); st = AllocateStation();
if (st == NULL) return CMD_ERROR; if (st == NULL) return CMD_ERROR;
st->town = ClosestTownFromTile(ti.tile, (uint)-1); st->town = ClosestTownFromTile(tile, (uint)-1);
st->sign.width_1 = 0; st->sign.width_1 = 0;
if (!GenerateStationName(st, ti.tile, 4)) return CMD_ERROR; if (!GenerateStationName(st, tile, 4)) return CMD_ERROR;
if (flags & DC_EXEC) { if (flags & DC_EXEC) {
StationInitialize(st, ti.tile); StationInitialize(st, tile);
st->dock_tile = ti.tile; st->dock_tile = tile;
st->facilities |= FACIL_DOCK; st->facilities |= FACIL_DOCK;
/* Buoys are marked in the Station struct by this flag. Yes, it is this /* Buoys are marked in the Station struct by this flag. Yes, it is this
* braindead.. */ * braindead.. */
@ -1720,7 +1722,7 @@ int32 CmdBuildBuoy(int x, int y, uint32 flags, uint32 p1, uint32 p2)
st->build_date = _date; st->build_date = _date;
ModifyTile(ti.tile, ModifyTile(tile,
MP_SETTYPE(MP_STATION) | MP_SETTYPE(MP_STATION) |
MP_MAP2 | MP_MAP3LO_CLEAR | MP_MAP3HI_CLEAR | MP_MAPOWNER | MP_MAP5, MP_MAP2 | MP_MAP3LO_CLEAR | MP_MAP3HI_CLEAR | MP_MAPOWNER | MP_MAP5,
st->index, /* map2 */ st->index, /* map2 */
@ -1805,41 +1807,42 @@ static const byte _dock_h_chk[4] = { 1,2,1,2 };
*/ */
int32 CmdBuildDock(int x, int y, uint32 flags, uint32 p1, uint32 p2) int32 CmdBuildDock(int x, int y, uint32 flags, uint32 p1, uint32 p2)
{ {
TileInfo ti; TileIndex tile = TileVirtXY(x, y);
TileIndex tile_cur;
int direction; int direction;
int32 cost; int32 cost;
TileIndex tile, tile_cur;
Station *st; Station *st;
SET_EXPENSES_TYPE(EXPENSES_CONSTRUCTION); SET_EXPENSES_TYPE(EXPENSES_CONSTRUCTION);
FindLandscapeHeight(&ti, x, y); switch (GetTileSlope(tile, NULL)) {
case 3: direction = 0; break;
case 6: direction = 3; break;
case 9: direction = 1; break;
case 12: direction = 2; break;
default: return_cmd_error(STR_304B_SITE_UNSUITABLE);
}
if ((direction=0,ti.tileh) != 3 && if (!EnsureNoVehicle(tile)) return CMD_ERROR;
(direction++,ti.tileh) != 9 &&
(direction++,ti.tileh) != 12 &&
(direction++,ti.tileh) != 6)
return_cmd_error(STR_304B_SITE_UNSUITABLE);
if (!EnsureNoVehicle(ti.tile)) return CMD_ERROR; cost = DoCommandByTile(tile, 0, 0, flags, CMD_LANDSCAPE_CLEAR);
cost = DoCommandByTile(ti.tile, 0, 0, flags, CMD_LANDSCAPE_CLEAR);
if (CmdFailed(cost)) return CMD_ERROR; if (CmdFailed(cost)) return CMD_ERROR;
tile_cur = (tile=ti.tile) + TileOffsByDir(direction); tile_cur = tile + TileOffsByDir(direction);
if (!EnsureNoVehicle(tile_cur)) return CMD_ERROR; if (!EnsureNoVehicle(tile_cur)) return CMD_ERROR;
FindLandscapeHeightByTile(&ti, tile_cur); if (!IsTileType(tile_cur, MP_WATER) || GetTileSlope(tile_cur, NULL) != 0) {
if (ti.tileh != 0 || ti.type != MP_WATER) return_cmd_error(STR_304B_SITE_UNSUITABLE); return_cmd_error(STR_304B_SITE_UNSUITABLE);
}
cost = DoCommandByTile(tile_cur, 0, 0, flags, CMD_LANDSCAPE_CLEAR); cost = DoCommandByTile(tile_cur, 0, 0, flags, CMD_LANDSCAPE_CLEAR);
if (CmdFailed(cost)) return CMD_ERROR; if (CmdFailed(cost)) return CMD_ERROR;
tile_cur = tile_cur + TileOffsByDir(direction); tile_cur = tile_cur + TileOffsByDir(direction);
FindLandscapeHeightByTile(&ti, tile_cur); if (!IsTileType(tile_cur, MP_WATER) || GetTileSlope(tile_cur, NULL) != 0) {
if (ti.tileh != 0 || ti.type != MP_WATER)
return_cmd_error(STR_304B_SITE_UNSUITABLE); return_cmd_error(STR_304B_SITE_UNSUITABLE);
}
/* middle */ /* middle */
st = GetStationAround( st = GetStationAround(

View File

@ -549,17 +549,18 @@ static bool TerraformTownTile(TileIndex tile, int edges, int dir)
static void LevelTownLand(TileIndex tile) static void LevelTownLand(TileIndex tile)
{ {
TileInfo ti; uint tileh;
TILE_ASSERT(tile); TILE_ASSERT(tile);
// Don't terraform if land is plain or if there's a house there. // Don't terraform if land is plain or if there's a house there.
FindLandscapeHeightByTile(&ti, tile); if (IsTileType(tile, MP_HOUSE)) return;
if (ti.tileh == 0 || ti.type == MP_HOUSE) return; tileh = GetTileSlope(tile, NULL);
if (tileh == 0) return;
// First try up, then down // First try up, then down
if (!TerraformTownTile(tile, ~ti.tileh & 0xF, 1)) { if (!TerraformTownTile(tile, ~tileh & 0xF, 1)) {
TerraformTownTile(tile, ti.tileh & 0xF, 0); TerraformTownTile(tile, tileh & 0xF, 0);
} }
} }
@ -569,7 +570,6 @@ static void GrowTownInTile(TileIndex *tile_ptr, uint mask, int block, Town *t1)
{ {
int a,b,rcmd; int a,b,rcmd;
TileIndex tmptile; TileIndex tmptile;
TileInfo ti;
uint i; uint i;
int j; int j;
TileIndex tile = *tile_ptr; TileIndex tile = *tile_ptr;
@ -658,21 +658,23 @@ static void GrowTownInTile(TileIndex *tile_ptr, uint mask, int block, Town *t1)
rcmd = 1 << i; rcmd = 1 << i;
} }
FindLandscapeHeightByTile(&ti, tile);
// Return if a water tile // Return if a water tile
if (ti.type == MP_WATER && ti.map5 == 0) return; if (IsTileType(tile, MP_WATER) && _m[tile].m5 == 0) return;
// Determine direction of slope, // Determine direction of slope,
// and build a road if not a special slope. // and build a road if not a special slope.
if ((i=0,ti.tileh != 3) && switch (GetTileSlope(tile, NULL)) {
(i++,ti.tileh != 9) && case 3: i = 0; break;
(i++,ti.tileh != 12) && case 6: i = 3; break;
(i++,ti.tileh != 6)) { case 9: i = 1; break;
case 12: i = 2; break;
default:
build_road_and_exit: build_road_and_exit:
if (!CmdFailed(DoCommandByTile(tile, rcmd, t1->index, DC_EXEC | DC_AUTO | DC_NO_WATER, CMD_BUILD_ROAD))) if (!CmdFailed(DoCommandByTile(tile, rcmd, t1->index, DC_EXEC | DC_AUTO | DC_NO_WATER, CMD_BUILD_ROAD))) {
_grow_town_result = -1; _grow_town_result = -1;
return; }
return;
} }
tmptile = tile; tmptile = tile;
@ -773,7 +775,6 @@ static bool GrowTown(Town *t)
{ {
TileIndex tile; TileIndex tile;
const TileIndexDiffC *ptr; const TileIndexDiffC *ptr;
TileInfo ti;
PlayerID old_player; PlayerID old_player;
static const TileIndexDiffC _town_coord_mod[] = { static const TileIndexDiffC _town_coord_mod[] = {
@ -811,10 +812,9 @@ static bool GrowTown(Town *t)
// clearing some land and then building a road there. // clearing some land and then building a road there.
tile = t->xy; tile = t->xy;
for (ptr = _town_coord_mod; ptr != endof(_town_coord_mod); ++ptr) { for (ptr = _town_coord_mod; ptr != endof(_town_coord_mod); ++ptr) {
FindLandscapeHeightByTile(&ti, tile);
// Only work with plain land that not already has a house with map5=0 // Only work with plain land that not already has a house with map5=0
if (ti.tileh == 0 && (ti.type != MP_HOUSE || ti.map5 != 0)) { if ((!IsTileType(tile, MP_HOUSE) || _m[tile].m5 != 0) &&
GetTileSlope(tile, NULL) == 0) {
if (!CmdFailed(DoCommandByTile(tile, 0, 0, DC_AUTO, CMD_LANDSCAPE_CLEAR))) { if (!CmdFailed(DoCommandByTile(tile, 0, 0, DC_AUTO, CMD_LANDSCAPE_CLEAR))) {
DoCommandByTile(tile, GenRandomRoadBits(), t->index, DC_EXEC | DC_AUTO, CMD_BUILD_ROAD); DoCommandByTile(tile, GenRandomRoadBits(), t->index, DC_EXEC | DC_AUTO, CMD_BUILD_ROAD);
_current_player = old_player; _current_player = old_player;

View File

@ -428,17 +428,17 @@ not_valid_below:;
static bool DoCheckTunnelInWay(TileIndex tile, uint z, uint dir) static bool DoCheckTunnelInWay(TileIndex tile, uint z, uint dir)
{ {
TileIndexDiff delta = TileOffsByDir(dir); TileIndexDiff delta = TileOffsByDir(dir);
TileInfo ti; uint height;
do { do {
tile -= delta; tile -= delta;
FindLandscapeHeightByTile(&ti, tile); height = GetTileZ(tile);
} while (z < ti.z); } while (z < tile);
if (z == ti.z && if (z == tile &&
ti.type == MP_TUNNELBRIDGE && IsTileType(tile, MP_TUNNELBRIDGE) &&
GB(ti.map5, 4, 4) == 0 && GB(_m[tile].m5, 4, 4) == 0 &&
GB(ti.map5, 0, 2) == dir) { GB(_m[tile].m5, 0, 2) == dir) {
_error_message = STR_5003_ANOTHER_TUNNEL_IN_THE_WAY; _error_message = STR_5003_ANOTHER_TUNNEL_IN_THE_WAY;
return false; return false;
} }