Chunnel patch 28394: Codechange: Rework IsTunnelInWay proc.
https://www.tt-forums.net/viewtopic.php?p=1183416#p1183416
This commit is contained in:

committed by
Jonathan G Rennison

parent
67e7d12eb7
commit
f7ced74c22
@@ -40,28 +40,6 @@ TileIndex GetOtherTunnelEnd(TileIndex tile)
|
||||
return t->tile_n == tile ? t->tile_s : t->tile_n;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Is there a tunnel in the way in the given direction?
|
||||
* @param tile the tile to search from.
|
||||
* @param z the 'z' to search on.
|
||||
* @param dir the direction to start searching to.
|
||||
* @return true if and only if there is a tunnel.
|
||||
*/
|
||||
bool IsTunnelInWayDir(TileIndex tile, int z, DiagDirection dir)
|
||||
{
|
||||
TileIndexDiff delta = TileOffsByDiagDir(dir);
|
||||
int height;
|
||||
|
||||
do {
|
||||
tile -= delta;
|
||||
if (!IsValidTile(tile)) return false;
|
||||
height = GetTileZ(tile);
|
||||
} while (z < height);
|
||||
|
||||
return z == height && IsTunnelTile(tile) && GetTunnelBridgeDirection(tile) == dir;
|
||||
}
|
||||
|
||||
/**
|
||||
* Is there a tunnel in the way in any direction?
|
||||
* @param tile the tile to search from.
|
||||
@@ -70,6 +48,20 @@ bool IsTunnelInWayDir(TileIndex tile, int z, DiagDirection dir)
|
||||
*/
|
||||
bool IsTunnelInWay(TileIndex tile, int z)
|
||||
{
|
||||
return IsTunnelInWayDir(tile, z, (TileX(tile) > (MapMaxX() / 2)) ? DIAGDIR_NE : DIAGDIR_SW) ||
|
||||
IsTunnelInWayDir(tile, z, (TileY(tile) > (MapMaxY() / 2)) ? DIAGDIR_NW : DIAGDIR_SE);
|
||||
uint x = TileX(tile);
|
||||
uint y = TileY(tile);
|
||||
|
||||
Tunnel *t;
|
||||
FOR_ALL_TUNNELS(t) {
|
||||
if (t->tile_n > tile || tile > t->tile_s) continue;
|
||||
|
||||
if (t->tile_s - t->tile_n > MapMaxX()){
|
||||
if (TileX(t->tile_n) != x || (int)TileHeight(t->tile_n) != z) continue; // dir DIAGDIR_SE
|
||||
} else {
|
||||
if (TileY(t->tile_n) != y || (int)TileHeight(t->tile_n) != z) continue; // dir DIAGDIR_SW
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
@@ -52,7 +52,6 @@ static inline TunnelID GetTunnelIndex(TileIndex t)
|
||||
|
||||
TileIndex GetOtherTunnelEnd(TileIndex);
|
||||
bool IsTunnelInWay(TileIndex, int z);
|
||||
bool IsTunnelInWayDir(TileIndex tile, int z, DiagDirection dir);
|
||||
|
||||
/**
|
||||
* Makes a road tunnel entrance
|
||||
|
@@ -663,12 +663,6 @@ CommandCost CmdBuildTunnel(TileIndex start_tile, DoCommandFlag flags, uint32 p1,
|
||||
* position, because of increased-cost-by-length: 'cost += cost >> 3' */
|
||||
|
||||
TileIndexDiff delta = TileOffsByDiagDir(direction);
|
||||
DiagDirection tunnel_in_way_dir;
|
||||
if (DiagDirToAxis(direction) == AXIS_Y) {
|
||||
tunnel_in_way_dir = (TileX(start_tile) < (MapMaxX() / 2)) ? DIAGDIR_SW : DIAGDIR_NE;
|
||||
} else {
|
||||
tunnel_in_way_dir = (TileY(start_tile) < (MapMaxX() / 2)) ? DIAGDIR_SE : DIAGDIR_NW;
|
||||
}
|
||||
|
||||
TileIndex end_tile = start_tile;
|
||||
|
||||
@@ -688,7 +682,7 @@ CommandCost CmdBuildTunnel(TileIndex start_tile, DoCommandFlag flags, uint32 p1,
|
||||
|
||||
if (start_z == end_z) break;
|
||||
|
||||
if (!_cheats.crossing_tunnels.value && IsTunnelInWayDir(end_tile, start_z, tunnel_in_way_dir)) {
|
||||
if (!_cheats.crossing_tunnels.value && IsTunnelInWay(end_tile, start_z)) {
|
||||
return_cmd_error(STR_ERROR_ANOTHER_TUNNEL_IN_THE_WAY);
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user