mirror of https://github.com/OpenTTD/OpenTTD
(svn r3779) Move CheckTunnelInWay() to a more appropriate place, invert its result and give it a less ambiguous name (IsTunnelInWay)
parent
a172b194c2
commit
313754011d
|
@ -10,6 +10,7 @@
|
||||||
#include "tile.h"
|
#include "tile.h"
|
||||||
#include "viewport.h"
|
#include "viewport.h"
|
||||||
#include "command.h"
|
#include "command.h"
|
||||||
|
#include "tunnel_map.h"
|
||||||
#include "variables.h"
|
#include "variables.h"
|
||||||
#include "table/sprites.h"
|
#include "table/sprites.h"
|
||||||
|
|
||||||
|
@ -277,7 +278,7 @@ int32 CmdTerraformLand(int x, int y, uint32 flags, uint32 p1, uint32 p2)
|
||||||
t = TerraformGetHeightOfTile(&ts, tile + TileDiffXY(0, 1));
|
t = TerraformGetHeightOfTile(&ts, tile + TileDiffXY(0, 1));
|
||||||
if (t <= z) z = t;
|
if (t <= z) z = t;
|
||||||
|
|
||||||
if (!CheckTunnelInWay(tile, z * 8)) {
|
if (IsTunnelInWay(tile, z * 8)) {
|
||||||
return_cmd_error(STR_1002_EXCAVATION_WOULD_DAMAGE);
|
return_cmd_error(STR_1002_EXCAVATION_WOULD_DAMAGE);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -145,7 +145,6 @@ void AnimateAnimatedTiles(void);
|
||||||
void InitializeAnimatedTiles(void);
|
void InitializeAnimatedTiles(void);
|
||||||
|
|
||||||
/* tunnelbridge_cmd.c */
|
/* tunnelbridge_cmd.c */
|
||||||
bool CheckTunnelInWay(TileIndex tile, int z);
|
|
||||||
bool CheckBridge_Stuff(byte bridge_type, uint bridge_len);
|
bool CheckBridge_Stuff(byte bridge_type, uint bridge_len);
|
||||||
uint32 GetBridgeLength(TileIndex begin, TileIndex end);
|
uint32 GetBridgeLength(TileIndex begin, TileIndex end);
|
||||||
int CalcBridgeLenCostFactor(int x);
|
int CalcBridgeLenCostFactor(int x);
|
||||||
|
|
27
tunnel_map.c
27
tunnel_map.c
|
@ -23,3 +23,30 @@ TileIndex GetOtherTunnelEnd(TileIndex tile)
|
||||||
|
|
||||||
return tile;
|
return tile;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
static bool IsTunnelInWayDir(TileIndex tile, uint z, DiagDirection dir)
|
||||||
|
{
|
||||||
|
TileIndexDiff delta = TileOffsByDir(dir);
|
||||||
|
uint height;
|
||||||
|
|
||||||
|
do {
|
||||||
|
tile -= delta;
|
||||||
|
height = GetTileZ(tile);
|
||||||
|
} while (z < height);
|
||||||
|
|
||||||
|
return
|
||||||
|
z == height &&
|
||||||
|
IsTileType(tile, MP_TUNNELBRIDGE) &&
|
||||||
|
GB(_m[tile].m5, 4, 4) == 0 &&
|
||||||
|
GetTunnelDirection(tile) == dir;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool IsTunnelInWay(TileIndex tile, uint z)
|
||||||
|
{
|
||||||
|
return
|
||||||
|
IsTunnelInWayDir(tile, z, DIAGDIR_NE) ||
|
||||||
|
IsTunnelInWayDir(tile, z, DIAGDIR_SE) ||
|
||||||
|
IsTunnelInWayDir(tile, z, DIAGDIR_SW) ||
|
||||||
|
IsTunnelInWayDir(tile, z, DIAGDIR_NW);
|
||||||
|
}
|
||||||
|
|
|
@ -22,6 +22,7 @@ static inline TransportType GetTunnelTransportType(TileIndex t)
|
||||||
|
|
||||||
|
|
||||||
TileIndex GetOtherTunnelEnd(TileIndex);
|
TileIndex GetOtherTunnelEnd(TileIndex);
|
||||||
|
bool IsTunnelInWay(TileIndex, uint z);
|
||||||
|
|
||||||
|
|
||||||
static inline void MakeRoadTunnel(TileIndex t, Owner o, DiagDirection d)
|
static inline void MakeRoadTunnel(TileIndex t, Owner o, DiagDirection d)
|
||||||
|
|
|
@ -428,36 +428,6 @@ not_valid_below:;
|
||||||
return cost;
|
return cost;
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool DoCheckTunnelInWay(TileIndex tile, uint z, DiagDirection dir)
|
|
||||||
{
|
|
||||||
TileIndexDiff delta = TileOffsByDir(dir);
|
|
||||||
uint height;
|
|
||||||
|
|
||||||
do {
|
|
||||||
tile -= delta;
|
|
||||||
height = GetTileZ(tile);
|
|
||||||
} while (z < height);
|
|
||||||
|
|
||||||
if (z == height &&
|
|
||||||
IsTileType(tile, MP_TUNNELBRIDGE) &&
|
|
||||||
GB(_m[tile].m5, 4, 4) == 0 &&
|
|
||||||
GetTunnelDirection(tile) == dir) {
|
|
||||||
_error_message = STR_5003_ANOTHER_TUNNEL_IN_THE_WAY;
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool CheckTunnelInWay(TileIndex tile, int z)
|
|
||||||
{
|
|
||||||
return
|
|
||||||
DoCheckTunnelInWay(tile, z, DIAGDIR_NE) &&
|
|
||||||
DoCheckTunnelInWay(tile, z, DIAGDIR_SE) &&
|
|
||||||
DoCheckTunnelInWay(tile, z, DIAGDIR_SW) &&
|
|
||||||
DoCheckTunnelInWay(tile, z, DIAGDIR_NW);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/** Build Tunnel.
|
/** Build Tunnel.
|
||||||
* @param x,y start tile coord of tunnel
|
* @param x,y start tile coord of tunnel
|
||||||
|
@ -504,8 +474,8 @@ int32 CmdBuildTunnel(int x, int y, uint32 flags, uint32 p1, uint32 p2)
|
||||||
|
|
||||||
if (start_z == end_z) break;
|
if (start_z == end_z) break;
|
||||||
|
|
||||||
if (!_cheats.crossing_tunnels.value && !CheckTunnelInWay(end_tile, start_z)) {
|
if (!_cheats.crossing_tunnels.value && IsTunnelInWay(end_tile, start_z)) {
|
||||||
return CMD_ERROR;
|
return_cmd_error(STR_5003_ANOTHER_TUNNEL_IN_THE_WAY);
|
||||||
}
|
}
|
||||||
|
|
||||||
cost += _price.build_tunnel;
|
cost += _price.build_tunnel;
|
||||||
|
|
Loading…
Reference in New Issue