mirror of
https://github.com/OpenTTD/OpenTTD.git
synced 2025-01-22 15:11:54 +00:00
(svn r4790) Remove slope magic from EnsureNoVehicleZ() and rename it to EnsureNoVehicleOnGround() to make more clear what it does
This commit is contained in:
parent
e5bd292dab
commit
c9defc0fea
@ -193,9 +193,8 @@ bool ScrollWindowTo(int x, int y, Window * w);
|
||||
bool ScrollMainWindowToTile(TileIndex tile);
|
||||
bool ScrollMainWindowTo(int x, int y);
|
||||
void DrawSprite(uint32 img, int x, int y);
|
||||
uint GetCorrectTileHeight(TileIndex tile);
|
||||
bool EnsureNoVehicle(TileIndex tile);
|
||||
bool EnsureNoVehicleZ(TileIndex tile, byte z);
|
||||
bool EnsureNoVehicleOnGround(TileIndex tile);
|
||||
void MarkAllViewportsDirty(int left, int top, int right, int bottom);
|
||||
void ShowCostOrIncomeAnimation(int x, int y, int z, int32 cost);
|
||||
void ShowFeederIncomeAnimation(int x, int y, int z, int32 cost);
|
||||
|
@ -349,7 +349,7 @@ int32 CmdRemoveSingleRail(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
|
||||
GetTransportTypeUnderBridge(tile) != TRANSPORT_RAIL ||
|
||||
GetRailBitsUnderBridge(tile) != trackbit ||
|
||||
(_current_player != OWNER_WATER && !CheckTileOwnership(tile)) ||
|
||||
!EnsureNoVehicleZ(tile, TilePixelHeight(tile))) {
|
||||
!EnsureNoVehicleOnGround(tile)) {
|
||||
return CMD_ERROR;
|
||||
}
|
||||
|
||||
|
@ -125,7 +125,7 @@ int32 CmdRemoveRoad(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
|
||||
|
||||
switch (GetTileType(tile)) {
|
||||
case MP_TUNNELBRIDGE:
|
||||
if (!EnsureNoVehicleZ(tile, TilePixelHeight(tile))) return CMD_ERROR;
|
||||
if (!EnsureNoVehicleOnGround(tile)) return CMD_ERROR;
|
||||
|
||||
if (!IsBridge(tile) ||
|
||||
!IsBridgeMiddle(tile) ||
|
||||
|
7
tile.h
7
tile.h
@ -32,13 +32,6 @@ Slope GetTileSlope(TileIndex tile, uint *h);
|
||||
uint GetTileZ(TileIndex tile);
|
||||
uint GetTileMaxZ(TileIndex tile);
|
||||
|
||||
static inline bool CorrectZ(Slope tileh)
|
||||
{
|
||||
/* tile height must be corrected if the north corner is not raised, but
|
||||
* any other corner is. These are the cases 1 till 7 */
|
||||
return IS_INT_INSIDE(tileh, 1, 8);
|
||||
}
|
||||
|
||||
static inline uint TileHeight(TileIndex tile)
|
||||
{
|
||||
assert(tile < MapSize());
|
||||
|
@ -608,7 +608,7 @@ static int32 DoClearBridge(TileIndex tile, uint32 flags)
|
||||
int32 cost;
|
||||
|
||||
// check if we own the tile below the bridge..
|
||||
if (_current_player != OWNER_WATER && (!CheckTileOwnership(tile) || !EnsureNoVehicleZ(tile, TilePixelHeight(tile))))
|
||||
if (_current_player != OWNER_WATER && (!CheckTileOwnership(tile) || !EnsureNoVehicleOnGround(tile)))
|
||||
return CMD_ERROR;
|
||||
|
||||
if (GetTransportTypeUnderBridge(tile) == TRANSPORT_RAIL) {
|
||||
@ -626,7 +626,7 @@ static int32 DoClearBridge(TileIndex tile, uint32 flags)
|
||||
/* delete canal under bridge */
|
||||
|
||||
// check for vehicles under bridge
|
||||
if (!EnsureNoVehicleZ(tile, TilePixelHeight(tile))) return CMD_ERROR;
|
||||
if (!EnsureNoVehicleOnGround(tile)) return CMD_ERROR;
|
||||
|
||||
if (flags & DC_EXEC) {
|
||||
SetClearUnderBridge(tile);
|
||||
@ -752,7 +752,7 @@ int32 DoConvertTunnelBridgeRail(TileIndex tile, RailType totype, bool exec)
|
||||
IsTransportUnderBridge(tile) &&
|
||||
GetTransportTypeUnderBridge(tile) == TRANSPORT_RAIL) {
|
||||
// only check for train under bridge
|
||||
if (!CheckTileOwnership(tile) || !EnsureNoVehicleZ(tile, TilePixelHeight(tile)))
|
||||
if (!CheckTileOwnership(tile) || !EnsureNoVehicleOnGround(tile))
|
||||
return CMD_ERROR;
|
||||
|
||||
if (GetRailType(tile) == totype) return CMD_ERROR;
|
||||
|
17
vehicle.c
17
vehicle.c
@ -131,30 +131,19 @@ static void *EnsureNoVehicleProcZ(Vehicle *v, void *data)
|
||||
const TileInfo *ti = data;
|
||||
|
||||
if (v->tile != ti->tile || v->type == VEH_Disaster) return NULL;
|
||||
if (!IS_INT_INSIDE(ti->z - v->z_pos, 0, TILE_HEIGHT + 1)) return NULL;
|
||||
if (v->z_pos > ti->z) return NULL;
|
||||
|
||||
VehicleInTheWayErrMsg(v);
|
||||
return v;
|
||||
}
|
||||
|
||||
static inline uint Correct_Z(Slope tileh)
|
||||
{
|
||||
// needs z correction for slope-type graphics that have the NORTHERN tile lowered
|
||||
return CorrectZ(tileh) ? TILE_HEIGHT : 0;
|
||||
}
|
||||
|
||||
uint GetCorrectTileHeight(TileIndex tile)
|
||||
{
|
||||
return Correct_Z(GetTileSlope(tile, NULL));
|
||||
}
|
||||
|
||||
bool EnsureNoVehicleZ(TileIndex tile, byte z)
|
||||
bool EnsureNoVehicleOnGround(TileIndex tile)
|
||||
{
|
||||
TileInfo ti;
|
||||
|
||||
ti.tile = tile;
|
||||
ti.z = z + GetCorrectTileHeight(tile);
|
||||
|
||||
ti.z = GetTileMaxZ(tile);
|
||||
return VehicleFromPos(tile, &ti, EnsureNoVehicleProcZ) == NULL;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user