Changeset - r3055:a4566916e6bc
[Not reviewed]
master
0 6 0
tron - 18 years ago 2006-02-21 07:41:54
tron@openttd.org
(svn r3644) Don't use FindLandscapeHeightByTile() when it's overkill - often it was just a complicated way of writing GetTileSlope(tile, NULL)
6 files changed with 85 insertions and 88 deletions:
0 comments (0 inline, 0 general)
ai/trolly/pathfinder.c
Show inline comments
 
@@ -315,18 +315,18 @@ static void AyStar_AiPathFinder_GetNeigh
 

	
 
	// Next step, check for bridges and tunnels
 
	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
 
		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
 
		TileIndex tile = current->path.node.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
 
		//  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_RAILWAY))) {
 
			for (;;) {
 
@@ -353,14 +353,14 @@ static void AyStar_AiPathFinder_GetNeigh
 
		// Next, check for tunnels!
 
		// 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
 
		if ((dir == 0 && ti.tileh == 12) ||
 
				(dir == 1 && ti.tileh == 6) ||
 
				(dir == 2 && ti.tileh == 3) ||
 
				(dir == 3 && ti.tileh == 9)) {
 
		if ((dir == 0 && tileh == 12) ||
 
				(dir == 1 && tileh == 6) ||
 
				(dir == 2 && tileh == 3) ||
 
				(dir == 3 && tileh == 9)) {
 
			// 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);
 
			FindLandscapeHeightByTile(&ti, _build_tunnel_endtile);
 
			if (!CmdFailed(ret) && (ti.tileh == 3 || ti.tileh == 6 || ti.tileh == 9 || ti.tileh == 12)) {
 
			tileh = GetTileSlope(_build_tunnel_endtile, NULL);
 
			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].user_data[0] = AI_PATHFINDER_FLAG_TUNNEL + (dir << 8);
 
				aystar->neighbours[aystar->num_neighbours++].direction = 0;
 
@@ -382,11 +382,8 @@ static int32 AyStar_AiPathFinder_Calcula
 
{
 
	Ai_PathFinderInfo *PathFinderInfo = (Ai_PathFinderInfo*)aystar->user_target;
 
	int r, res = 0;
 
	TileInfo ti, parent_ti;
 

	
 
	// Gather some information about the tile..
 
	FindLandscapeHeightByTile(&ti, current->tile);
 
	FindLandscapeHeightByTile(&parent_ti, parent->path.node.tile);
 
	uint tileh = GetTileSlope(current->tile, NULL);
 
	uint parent_tileh = GetTileSlope(parent->path.node.tile, NULL);
 

	
 
	// Check if we hit the end-tile
 
	if (TILES_BETWEEN(current->tile, PathFinderInfo->end_tile_tl, PathFinderInfo->end_tile_br)) {
 
@@ -416,20 +413,20 @@ static int32 AyStar_AiPathFinder_Calcula
 
	//  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
 
	//  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
 
		if (parent->path.node.user_data[0] == 0 && current->user_data[0] == 0) {
 
			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..
 
				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;
 
				} else {
 
					res += AI_PATHFINDER_FOUNDATION_PENALTY;
 
				}
 
			} else {
 
				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)
 
						res += AI_PATHFINDER_TILE_GOES_UP_PENALTY;
 
					else
 
@@ -453,17 +450,17 @@ static int32 AyStar_AiPathFinder_Calcula
 
		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
 
		// In user_data[0] is at the 8th bit the direction
 
		if (!(BRIDGE_NO_FOUNDATION & (1 << parent_ti.tileh))) {
 
			if (GetBridgeFoundation(parent_ti.tileh, (current->user_data[0] >> 8) & 1) < 15)
 
		if (!(BRIDGE_NO_FOUNDATION & (1 << parent_tileh))) {
 
			if (GetBridgeFoundation(parent_tileh, (current->user_data[0] >> 8) & 1) < 15)
 
				res += AI_PATHFINDER_BRIDGE_GOES_UP_PENALTY;
 
		}
 
		// Second for the end point
 
		if (!(BRIDGE_NO_FOUNDATION & (1 << ti.tileh))) {
 
			if (GetBridgeFoundation(ti.tileh, (current->user_data[0] >> 8) & 1) < 15)
 
		if (!(BRIDGE_NO_FOUNDATION & (1 << tileh))) {
 
			if (GetBridgeFoundation(tileh, (current->user_data[0] >> 8) & 1) < 15)
 
				res += AI_PATHFINDER_BRIDGE_GOES_UP_PENALTY;
 
		}
 
		if (parent_ti.tileh == 0) res += AI_PATHFINDER_BRIDGE_GOES_UP_PENALTY;
 
		if (ti.tileh == 0) res += AI_PATHFINDER_BRIDGE_GOES_UP_PENALTY;
 
		if (parent_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
ai/trolly/trolly.c
Show inline comments
 
@@ -840,10 +840,8 @@ static void AiNew_State_FindDepot(Player
 
			// Is the terrain clear?
 
			if (IsTileType(tile + TileOffsByDir(j), MP_CLEAR) ||
 
					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 (ti.tileh != 0) continue;
 
				if (GetTileSlope(tile, NULL) != 0) continue;
 
				// Check if everything went okay..
 
				r = AiNew_Build_Depot(p, tile + TileOffsByDir(j), j ^ 2, 0);
 
				if (CmdFailed(r)) continue;
road_cmd.c
Show inline comments
 
@@ -620,25 +620,24 @@ int32 CmdRemoveLongRoad(int x, int y, ui
 
 */
 
int32 CmdBuildRoadDepot(int x, int y, uint32 flags, uint32 p1, uint32 p2)
 
{
 
	TileInfo ti;
 
	int32 cost;
 
	Depot *dep;
 
	TileIndex tile;
 
	uint tileh;
 

	
 
	SET_EXPENSES_TYPE(EXPENSES_CONSTRUCTION);
 

	
 
	if (p1 > 3) return CMD_ERROR; // check direction
 

	
 
	FindLandscapeHeight(&ti, x, y);
 

	
 
	tile = ti.tile;
 
	tile = TileVirtXY(x, y);
 

	
 
	if (!EnsureNoVehicle(tile)) return CMD_ERROR;
 

	
 
	if (ti.tileh != 0 && (
 
	tileh = GetTileSlope(tile, NULL);
 
	if (tileh != 0 && (
 
				!_patches.build_on_slopes ||
 
				IsSteepTileh(ti.tileh) ||
 
				!CanBuildDepotByTileh(p1, ti.tileh)
 
				IsSteepTileh(tileh) ||
 
				!CanBuildDepotByTileh(p1, tileh)
 
			)) {
 
		return_cmd_error(STR_0007_FLAT_LAND_REQUIRED);
 
	}
station_cmd.c
Show inline comments
 
@@ -1691,27 +1691,29 @@ static int32 RemoveAirport(Station *st, 
 
 */
 
int32 CmdBuildBuoy(int x, int y, uint32 flags, uint32 p1, uint32 p2)
 
{
 
	TileInfo ti;
 
	TileIndex tile = TileVirtXY(x, y);
 
	Station *st;
 

	
 
	SET_EXPENSES_TYPE(EXPENSES_CONSTRUCTION);
 

	
 
	FindLandscapeHeight(&ti, x, y);
 

	
 
	if (ti.type != MP_WATER || ti.tileh != 0 || ti.map5 != 0 || ti.tile == 0)
 
	if (!IsTileType(tile, MP_WATER) ||
 
			_m[tile].m5 != 0 ||
 
			GetTileSlope(tile, NULL) != 0 ||
 
			tile == 0) {
 
		return_cmd_error(STR_304B_SITE_UNSUITABLE);
 
	}
 

	
 
	st = AllocateStation();
 
	if (st == NULL) return CMD_ERROR;
 

	
 
	st->town = ClosestTownFromTile(ti.tile, (uint)-1);
 
	st->town = ClosestTownFromTile(tile, (uint)-1);
 
	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) {
 
		StationInitialize(st, ti.tile);
 
		st->dock_tile = ti.tile;
 
		StationInitialize(st, tile);
 
		st->dock_tile = tile;
 
		st->facilities |= FACIL_DOCK;
 
		/* Buoys are marked in the Station struct by this flag. Yes, it is this
 
		 * braindead.. */
 
@@ -1720,7 +1722,7 @@ int32 CmdBuildBuoy(int x, int y, uint32 
 

	
 
		st->build_date = _date;
 

	
 
		ModifyTile(ti.tile,
 
		ModifyTile(tile,
 
			MP_SETTYPE(MP_STATION) |
 
			MP_MAP2 | MP_MAP3LO_CLEAR | MP_MAP3HI_CLEAR | MP_MAPOWNER | MP_MAP5,
 
			st->index,		/* map2 */
 
@@ -1805,41 +1807,42 @@ static const byte _dock_h_chk[4] = { 1,2
 
 */
 
int32 CmdBuildDock(int x, int y, uint32 flags, uint32 p1, uint32 p2)
 
{
 
	TileInfo ti;
 
	TileIndex tile = TileVirtXY(x, y);
 
	TileIndex tile_cur;
 
	int direction;
 
	int32 cost;
 
	TileIndex tile, tile_cur;
 
	Station *st;
 

	
 
	SET_EXPENSES_TYPE(EXPENSES_CONSTRUCTION);
 

	
 
	FindLandscapeHeight(&ti, x, y);
 

	
 
	if ((direction=0,ti.tileh) != 3 &&
 
			(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(ti.tile, 0, 0, flags, CMD_LANDSCAPE_CLEAR);
 
	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 (!EnsureNoVehicle(tile)) return CMD_ERROR;
 

	
 
	cost = DoCommandByTile(tile, 0, 0, flags, CMD_LANDSCAPE_CLEAR);
 
	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;
 

	
 
	FindLandscapeHeightByTile(&ti, tile_cur);
 
	if (ti.tileh != 0 || ti.type != MP_WATER) return_cmd_error(STR_304B_SITE_UNSUITABLE);
 
	if (!IsTileType(tile_cur, MP_WATER) || GetTileSlope(tile_cur, NULL) != 0) {
 
		return_cmd_error(STR_304B_SITE_UNSUITABLE);
 
	}
 

	
 
	cost = DoCommandByTile(tile_cur, 0, 0, flags, CMD_LANDSCAPE_CLEAR);
 
	if (CmdFailed(cost)) return CMD_ERROR;
 

	
 
	tile_cur = tile_cur + TileOffsByDir(direction);
 
	FindLandscapeHeightByTile(&ti, tile_cur);
 
	if (ti.tileh != 0 || ti.type != MP_WATER)
 
	if (!IsTileType(tile_cur, MP_WATER) || GetTileSlope(tile_cur, NULL) != 0) {
 
		return_cmd_error(STR_304B_SITE_UNSUITABLE);
 
	}
 

	
 
	/* middle */
 
	st = GetStationAround(
town_cmd.c
Show inline comments
 
@@ -549,17 +549,18 @@ static bool TerraformTownTile(TileIndex 
 

	
 
static void LevelTownLand(TileIndex tile)
 
{
 
	TileInfo ti;
 
	uint tileh;
 

	
 
	TILE_ASSERT(tile);
 

	
 
	// Don't terraform if land is plain or if there's a house there.
 
	FindLandscapeHeightByTile(&ti, tile);
 
	if (ti.tileh == 0 || ti.type == MP_HOUSE) return;
 
	if (IsTileType(tile, MP_HOUSE)) return;
 
	tileh = GetTileSlope(tile, NULL);
 
	if (tileh == 0) return;
 

	
 
	// First try up, then down
 
	if (!TerraformTownTile(tile, ~ti.tileh & 0xF, 1)) {
 
		TerraformTownTile(tile, ti.tileh & 0xF, 0);
 
	if (!TerraformTownTile(tile, ~tileh & 0xF, 1)) {
 
		TerraformTownTile(tile, tileh & 0xF, 0);
 
	}
 
}
 

	
 
@@ -569,7 +570,6 @@ static void GrowTownInTile(TileIndex *ti
 
{
 
	int a,b,rcmd;
 
	TileIndex tmptile;
 
	TileInfo ti;
 
	uint i;
 
	int j;
 
	TileIndex tile = *tile_ptr;
 
@@ -658,21 +658,23 @@ static void GrowTownInTile(TileIndex *ti
 
		rcmd = 1 << i;
 
	}
 

	
 
	FindLandscapeHeightByTile(&ti, 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,
 
	//  and build a road if not a special slope.
 
	if ((i=0,ti.tileh != 3) &&
 
			(i++,ti.tileh != 9) &&
 
			(i++,ti.tileh != 12) &&
 
			(i++,ti.tileh != 6)) {
 
	switch (GetTileSlope(tile, NULL)) {
 
		case  3: i = 0; break;
 
		case  6: i = 3; break;
 
		case  9: i = 1; break;
 
		case 12: i = 2; break;
 

	
 
		default:
 
build_road_and_exit:
 
		if (!CmdFailed(DoCommandByTile(tile, rcmd, t1->index, DC_EXEC | DC_AUTO | DC_NO_WATER, CMD_BUILD_ROAD)))
 
			_grow_town_result = -1;
 
		return;
 
			if (!CmdFailed(DoCommandByTile(tile, rcmd, t1->index, DC_EXEC | DC_AUTO | DC_NO_WATER, CMD_BUILD_ROAD))) {
 
				_grow_town_result = -1;
 
			}
 
			return;
 
	}
 

	
 
	tmptile = tile;
 
@@ -773,7 +775,6 @@ static bool GrowTown(Town *t)
 
{
 
	TileIndex tile;
 
	const TileIndexDiffC *ptr;
 
	TileInfo ti;
 
	PlayerID old_player;
 

	
 
	static const TileIndexDiffC _town_coord_mod[] = {
 
@@ -811,10 +812,9 @@ static bool GrowTown(Town *t)
 
	// clearing some land and then building a road there.
 
	tile = t->xy;
 
	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
 
		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))) {
 
				DoCommandByTile(tile, GenRandomRoadBits(), t->index, DC_EXEC | DC_AUTO, CMD_BUILD_ROAD);
 
				_current_player = old_player;
tunnelbridge_cmd.c
Show inline comments
 
@@ -428,17 +428,17 @@ not_valid_below:;
 
static bool DoCheckTunnelInWay(TileIndex tile, uint z, uint dir)
 
{
 
	TileIndexDiff delta = TileOffsByDir(dir);
 
	TileInfo ti;
 
	uint height;
 

	
 
	do {
 
		tile -= delta;
 
		FindLandscapeHeightByTile(&ti, tile);
 
	} while (z < ti.z);
 
		height = GetTileZ(tile);
 
	} while (z < tile);
 

	
 
	if (z == ti.z &&
 
			ti.type == MP_TUNNELBRIDGE &&
 
			GB(ti.map5, 4, 4) == 0 &&
 
			GB(ti.map5, 0, 2) == dir) {
 
	if (z == tile &&
 
			IsTileType(tile, MP_TUNNELBRIDGE) &&
 
			GB(_m[tile].m5, 4, 4) == 0 &&
 
			GB(_m[tile].m5, 0, 2) == dir) {
 
		_error_message = STR_5003_ANOTHER_TUNNEL_IN_THE_WAY;
 
		return false;
 
	}
0 comments (0 inline, 0 general)