Prevent AIs/scripts from creating road custom bridge heads.

pull/19/head
Jonathan G Rennison 7 years ago
parent 0a345efc27
commit f3dde49ff8

@ -519,6 +519,7 @@ static CommandCost CheckRoadSlope(Slope tileh, RoadBits *pieces, RoadBits existi
* @param p1 bit 0..3 road pieces to build (RoadBits)
* bit 4..5 road type
* bit 6..7 disallowed directions to toggle
* bit 8 disable custom bridge heads
* @param p2 the town that is building the road (0 if not applicable)
* @param text unused
* @return the cost of this operation or an error
@ -558,6 +559,8 @@ CommandCost CmdBuildRoad(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32
DisallowedRoadDirections toggle_drd = Extract<DisallowedRoadDirections, 6, 2>(p1);
bool disable_custom_bridge_heads = HasBit(p1, 8);
Slope tileh = GetTileSlope(tile);
bool need_to_clear = false;
@ -721,7 +724,7 @@ CommandCost CmdBuildRoad(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32
const RoadBits axial_pieces = AxisToRoadBits(DiagDirToAxis(entrance_dir));
existing = GetCustomBridgeHeadRoadBits(tile, rt);
if (!(_settings_game.construction.road_custom_bridge_heads && HasBridgeFlatRamp(tileh, DiagDirToAxis(entrance_dir)))) {
if (!(_settings_game.construction.road_custom_bridge_heads && HasBridgeFlatRamp(tileh, DiagDirToAxis(entrance_dir))) || disable_custom_bridge_heads) {
/* Ordinary bridge heads only */
/* Only allow building the outer roadbit, so building long roads stops at existing bridges */
if (MirrorRoadBits(entrance_piece) != pieces) goto do_clear;
@ -955,7 +958,7 @@ static bool CanConnectToRoad(TileIndex tile, RoadType rt, DiagDirection dir)
* - p2 = (bit 5) - set road direction
* - p2 = (bit 6) - defines two different behaviors for this command:
* - 0 = Build up to an obstacle. Do not build the first and last roadbits unless they can be connected to something, or if we are building a single tile
* - 1 = Fail if an obstacle is found. Always take into account bit 0 and 1. This behavior is used for scripts
* - 1 = Fail if an obstacle is found. Always take into account bit 0 and 1. Disable custom bridge heads. This behavior is used for scripts
* @param text unused
* @return the cost of this operation or an error
*/
@ -1014,7 +1017,7 @@ CommandCost CmdBuildLongRoad(TileIndex start_tile, DoCommandFlag flags, uint32 p
if (tile == start_tile && HasBit(p2, 0)) bits &= DiagDirToRoadBits(dir);
}
CommandCost ret = DoCommand(tile, drd << 6 | rt << 4 | bits, 0, flags, CMD_BUILD_ROAD);
CommandCost ret = DoCommand(tile, drd << 6 | rt << 4 | bits | (is_ai ? 1 << 8 : 0), 0, flags, CMD_BUILD_ROAD);
if (ret.Failed()) {
last_error = ret;
if (last_error.GetErrorMessage() != STR_ERROR_ALREADY_BUILT) {

@ -113,7 +113,7 @@ static void _DoCommandReturnBuildBridge1(class ScriptInstance *instance)
DiagDirection dir_1 = ::DiagdirBetweenTiles(end, start);
DiagDirection dir_2 = ::ReverseDiagDir(dir_1);
return ScriptObject::DoCommand(start + ::TileOffsByDiagDir(dir_1), ::DiagDirToRoadBits(dir_2) | (ScriptObject::GetRoadType() << 4), 0, CMD_BUILD_ROAD, NULL, &::_DoCommandReturnBuildBridge2);
return ScriptObject::DoCommand(start + ::TileOffsByDiagDir(dir_1), ::DiagDirToRoadBits(dir_2) | (ScriptObject::GetRoadType() << 4) | (1 << 8), 0, CMD_BUILD_ROAD, NULL, &::_DoCommandReturnBuildBridge2);
}
/* static */ bool ScriptBridge::_BuildBridgeRoad2()
@ -125,7 +125,7 @@ static void _DoCommandReturnBuildBridge1(class ScriptInstance *instance)
DiagDirection dir_1 = ::DiagdirBetweenTiles(end, start);
DiagDirection dir_2 = ::ReverseDiagDir(dir_1);
return ScriptObject::DoCommand(end + ::TileOffsByDiagDir(dir_2), ::DiagDirToRoadBits(dir_1) | (ScriptObject::GetRoadType() << 4), 0, CMD_BUILD_ROAD);
return ScriptObject::DoCommand(end + ::TileOffsByDiagDir(dir_2), ::DiagDirToRoadBits(dir_1) | (ScriptObject::GetRoadType() << 4) | (1 << 8), 0, CMD_BUILD_ROAD);
}
/* static */ bool ScriptBridge::RemoveBridge(TileIndex tile)

Loading…
Cancel
Save