mirror of https://github.com/OpenTTD/OpenTTD
(svn r20668) -Codechange: add (more) support for bridges over objects
parent
3e67b4fe5f
commit
41a80490be
|
@ -127,7 +127,7 @@ void UpdateCompanyHQ(TileIndex tile, uint score)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
extern CommandCost CheckBuildableTile(TileIndex tile, uint invalid_dirs, int &allowed_z);
|
extern CommandCost CheckBuildableTile(TileIndex tile, uint invalid_dirs, int &allowed_z, bool check_bridge);
|
||||||
static CommandCost ClearTile_Object(TileIndex tile, DoCommandFlag flags);
|
static CommandCost ClearTile_Object(TileIndex tile, DoCommandFlag flags);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -189,12 +189,22 @@ CommandCost CmdBuildObject(TileIndex tile, DoCommandFlag flags, uint32 p1, uint3
|
||||||
/* Check whether the ground is flat enough. */
|
/* Check whether the ground is flat enough. */
|
||||||
int allowed_z = -1;
|
int allowed_z = -1;
|
||||||
TILE_AREA_LOOP(t, ta) {
|
TILE_AREA_LOOP(t, ta) {
|
||||||
cost.AddCost(CheckBuildableTile(t, 0, allowed_z));
|
/* We'll do the bridge test later; it's quite custom. */
|
||||||
|
cost.AddCost(CheckBuildableTile(t, 0, allowed_z, false));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (cost.Failed()) return cost;
|
if (cost.Failed()) return cost;
|
||||||
|
|
||||||
|
/* Finally do a check for bridges. */
|
||||||
|
TILE_AREA_LOOP(t, ta) {
|
||||||
|
if (MayHaveBridgeAbove(t) && IsBridgeAbove(t) && (
|
||||||
|
!(spec->flags & OBJECT_FLAG_ALLOW_UNDER_BRIDGE) ||
|
||||||
|
(GetTileMaxZ(t) + spec->height * TILE_HEIGHT >= GetBridgeHeight(GetSouthernBridgeEnd(t))))) {
|
||||||
|
return_cmd_error(STR_ERROR_MUST_DEMOLISH_BRIDGE_FIRST);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
int hq_score = 0;
|
int hq_score = 0;
|
||||||
switch (type) {
|
switch (type) {
|
||||||
case OBJECT_TRANSMITTER:
|
case OBJECT_TRANSMITTER:
|
||||||
|
|
|
@ -667,11 +667,12 @@ CommandCost ClearTile_Station(TileIndex tile, DoCommandFlag flags);
|
||||||
* @param tile TileIndex to check.
|
* @param tile TileIndex to check.
|
||||||
* @param invalid_dirs Prohibited directions for slopes (set of #DiagDirection).
|
* @param invalid_dirs Prohibited directions for slopes (set of #DiagDirection).
|
||||||
* @param allowed_z Height allowed for the tile. If allowed_z is negative, it will be set to the height of this tile.
|
* @param allowed_z Height allowed for the tile. If allowed_z is negative, it will be set to the height of this tile.
|
||||||
|
* @param check_bridge Check for the existance of a bridge.
|
||||||
* @return The cost in case of success, or an error code if it failed.
|
* @return The cost in case of success, or an error code if it failed.
|
||||||
*/
|
*/
|
||||||
CommandCost CheckBuildableTile(TileIndex tile, uint invalid_dirs, int &allowed_z)
|
CommandCost CheckBuildableTile(TileIndex tile, uint invalid_dirs, int &allowed_z, bool check_bridge = true)
|
||||||
{
|
{
|
||||||
if (MayHaveBridgeAbove(tile) && IsBridgeAbove(tile)) {
|
if (check_bridge && MayHaveBridgeAbove(tile) && IsBridgeAbove(tile)) {
|
||||||
return_cmd_error(STR_ERROR_MUST_DEMOLISH_BRIDGE_FIRST);
|
return_cmd_error(STR_ERROR_MUST_DEMOLISH_BRIDGE_FIRST);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -394,6 +394,7 @@ CommandCost CmdBuildBridge(TileIndex end_tile, DoCommandFlag flags, uint32 p1, u
|
||||||
case MP_OBJECT: {
|
case MP_OBJECT: {
|
||||||
const ObjectSpec *spec = ObjectSpec::GetByTile(tile);
|
const ObjectSpec *spec = ObjectSpec::GetByTile(tile);
|
||||||
if ((spec->flags & OBJECT_FLAG_ALLOW_UNDER_BRIDGE) == 0) goto not_valid_below;
|
if ((spec->flags & OBJECT_FLAG_ALLOW_UNDER_BRIDGE) == 0) goto not_valid_below;
|
||||||
|
if (GetTileMaxZ(tile) + spec->height * TILE_HEIGHT > z_start) return_cmd_error(STR_ERROR_OBJECT_IN_THE_WAY);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue