|
|
|
@ -995,7 +995,7 @@ static RoadBits GetTownRoadBits(TileIndex tile)
|
|
|
|
|
return GetAnyRoadBits(tile, RTT_ROAD, true);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
RoadType GetTownRoadType(const Town *t)
|
|
|
|
|
RoadType GetTownRoadType()
|
|
|
|
|
{
|
|
|
|
|
RoadType best_rt = ROADTYPE_ROAD;
|
|
|
|
|
const RoadTypeInfo *best = nullptr;
|
|
|
|
@ -1094,7 +1094,7 @@ static bool IsRoadAllowedHere(Town *t, TileIndex tile, DiagDirection dir)
|
|
|
|
|
/* No, try if we are able to build a road piece there.
|
|
|
|
|
* If that fails clear the land, and if that fails exit.
|
|
|
|
|
* This is to make sure that we can build a road here later. */
|
|
|
|
|
RoadType rt = GetTownRoadType(t);
|
|
|
|
|
RoadType rt = GetTownRoadType();
|
|
|
|
|
if (DoCommand(tile, ((dir == DIAGDIR_NW || dir == DIAGDIR_SE) ? ROAD_Y : ROAD_X) | (rt << 4), 0, DC_AUTO | DC_NO_WATER, CMD_BUILD_ROAD).Failed() &&
|
|
|
|
|
DoCommand(tile, 0, 0, DC_AUTO | DC_NO_WATER | DC_TOWN, CMD_LANDSCAPE_CLEAR).Failed()) {
|
|
|
|
|
return false;
|
|
|
|
@ -1263,7 +1263,7 @@ static bool GrowTownWithExtraHouse(Town *t, TileIndex tile)
|
|
|
|
|
*/
|
|
|
|
|
static bool GrowTownWithRoad(const Town *t, TileIndex tile, RoadBits rcmd)
|
|
|
|
|
{
|
|
|
|
|
RoadType rt = GetTownRoadType(t);
|
|
|
|
|
RoadType rt = GetTownRoadType();
|
|
|
|
|
if (DoCommand(tile, rcmd | (rt << 4), t->index, DC_EXEC | DC_AUTO | DC_NO_WATER | DC_TOWN, CMD_BUILD_ROAD).Succeeded()) {
|
|
|
|
|
_grow_town_result = GROWTH_SUCCEED;
|
|
|
|
|
return true;
|
|
|
|
@ -1284,8 +1284,6 @@ static bool CanRoadContinueIntoNextTile(const Town *t, const TileIndex tile, con
|
|
|
|
|
{
|
|
|
|
|
const int delta = TileOffsByDiagDir(road_dir); // +1 tile in the direction of the road
|
|
|
|
|
TileIndex next_tile = tile + delta; // The tile beyond which must be connectable to the target tile
|
|
|
|
|
RoadBits rcmd = DiagDirToRoadBits(ReverseDiagDir(road_dir));
|
|
|
|
|
RoadType rt = GetTownRoadType(t);
|
|
|
|
|
|
|
|
|
|
/* Before we try anything, make sure the tile is on the map and not the void. */
|
|
|
|
|
if (!IsValidTile(next_tile)) return false;
|
|
|
|
@ -1310,6 +1308,9 @@ static bool CanRoadContinueIntoNextTile(const Town *t, const TileIndex tile, con
|
|
|
|
|
* If level crossing are not allowed, reject the construction. Else allow DoCommand to determine if the rail track is buildable. */
|
|
|
|
|
if (IsTileType(next_tile, MP_RAILWAY) && !t->GetAllowBuildLevelCrossings()) return false;
|
|
|
|
|
|
|
|
|
|
RoadBits rcmd = DiagDirToRoadBits(ReverseDiagDir(road_dir));
|
|
|
|
|
RoadType rt = GetTownRoadType();
|
|
|
|
|
|
|
|
|
|
/* If a road tile can be built, the construction is allowed. */
|
|
|
|
|
return DoCommand(next_tile, rcmd | (rt << 4), t->index, DC_AUTO | DC_NO_WATER, CMD_BUILD_ROAD).Succeeded();
|
|
|
|
|
}
|
|
|
|
@ -1412,7 +1413,7 @@ static bool GrowTownWithBridge(const Town *t, const TileIndex tile, const DiagDi
|
|
|
|
|
|
|
|
|
|
for (;;) {
|
|
|
|
|
/* Can we actually build the bridge? */
|
|
|
|
|
RoadType rt = GetTownRoadType(t);
|
|
|
|
|
RoadType rt = GetTownRoadType();
|
|
|
|
|
if (MayTownBuildBridgeType(bridge_type) && DoCommand(tile, bridge_tile, bridge_type | rt << 8 | TRANSPORT_ROAD << 15, CommandFlagsToDCFlags(GetCommandFlags(CMD_BUILD_BRIDGE)) | DC_TOWN, CMD_BUILD_BRIDGE).Succeeded()) {
|
|
|
|
|
DoCommand(tile, bridge_tile, bridge_type | rt << 8 | TRANSPORT_ROAD << 15, DC_EXEC | CommandFlagsToDCFlags(GetCommandFlags(CMD_BUILD_BRIDGE)) | DC_TOWN, CMD_BUILD_BRIDGE);
|
|
|
|
|
_grow_town_result = GROWTH_SUCCEED;
|
|
|
|
@ -1502,7 +1503,7 @@ static bool GrowTownWithTunnel(const Town *t, const TileIndex tile, const DiagDi
|
|
|
|
|
if (!CanRoadContinueIntoNextTile(t, tunnel_tile, tunnel_dir)) return false;
|
|
|
|
|
|
|
|
|
|
/* Attempt to build the tunnel. Return false if it fails to let the town build a road instead. */
|
|
|
|
|
RoadType rt = GetTownRoadType(t);
|
|
|
|
|
RoadType rt = GetTownRoadType();
|
|
|
|
|
if (DoCommand(tile, rt | (TRANSPORT_ROAD << 8), 0, CommandFlagsToDCFlags(GetCommandFlags(CMD_BUILD_TUNNEL)), CMD_BUILD_TUNNEL).Succeeded()) {
|
|
|
|
|
DoCommand(tile, rt | (TRANSPORT_ROAD << 8), 0, DC_EXEC | CommandFlagsToDCFlags(GetCommandFlags(CMD_BUILD_TUNNEL)), CMD_BUILD_TUNNEL);
|
|
|
|
|
_grow_town_result = GROWTH_SUCCEED;
|
|
|
|
@ -2009,7 +2010,7 @@ static bool GrowTown(Town *t)
|
|
|
|
|
/* Only work with plain land that not already has a house */
|
|
|
|
|
if (!IsTileType(tile, MP_HOUSE) && IsTileFlat(tile)) {
|
|
|
|
|
if (DoCommand(tile, 0, 0, DC_AUTO | DC_NO_WATER | DC_TOWN, CMD_LANDSCAPE_CLEAR).Succeeded()) {
|
|
|
|
|
RoadType rt = GetTownRoadType(t);
|
|
|
|
|
RoadType rt = GetTownRoadType();
|
|
|
|
|
DoCommand(tile, GenRandomRoadBits() | (rt << 4), t->index, DC_EXEC | DC_AUTO | DC_TOWN, CMD_BUILD_ROAD);
|
|
|
|
|
cur_company.Restore();
|
|
|
|
|
return true;
|
|
|
|
|