From c7505539afbeac4ad50ed555b496ae1aa9ba2fa6 Mon Sep 17 00:00:00 2001 From: SamuXarick <43006711+SamuXarick@users.noreply.github.com> Date: Tue, 24 May 2022 21:11:23 +0100 Subject: [PATCH] Fix #9869: remove docking tile when doing a clear square Terraforming through objects placed on water didn't properly remove docking tiles as expected. By moving some logic regarding removal of docking tiles into DoClearSquare, the issue is solved, while also simplifying code, avoiding repetition elsewhere. --- src/landscape.cpp | 3 +++ src/rail_cmd.cpp | 2 -- src/tunnelbridge_cmd.cpp | 7 ------- src/water_cmd.cpp | 4 ---- 4 files changed, 3 insertions(+), 13 deletions(-) diff --git a/src/landscape.cpp b/src/landscape.cpp index b921deef22..0ce190fe1b 100644 --- a/src/landscape.cpp +++ b/src/landscape.cpp @@ -32,6 +32,7 @@ #include "saveload/saveload.h" #include "framerate_type.h" #include "landscape_cmd.h" +#include "station_func.h" #include #include #include @@ -574,8 +575,10 @@ void DoClearSquare(TileIndex tile) /* If the tile can have animation and we clear it, delete it from the animated tile list. */ if (_tile_type_procs[GetTileType(tile)]->animate_tile_proc != nullptr) DeleteAnimatedTile(tile); + bool remove = IsDockingTile(tile); MakeClear(tile, CLEAR_GRASS, _generating_world ? 3 : 0); MarkTileDirtyByTile(tile); + if (remove) RemoveDockingTile(tile); } /** diff --git a/src/rail_cmd.cpp b/src/rail_cmd.cpp index a0e0596042..6ef44c1f96 100644 --- a/src/rail_cmd.cpp +++ b/src/rail_cmd.cpp @@ -1819,9 +1819,7 @@ static CommandCost ClearTile_Track(TileIndex tile, DoCommandFlag flags) /* The track was removed, and left a coast tile. Now also clear the water. */ if (flags & DC_EXEC) { - bool remove = IsDockingTile(tile); DoClearSquare(tile); - if (remove) RemoveDockingTile(tile); } cost.AddCost(_price[PR_CLEAR_WATER]); } diff --git a/src/tunnelbridge_cmd.cpp b/src/tunnelbridge_cmd.cpp index dc345c8fee..9d3868c86d 100644 --- a/src/tunnelbridge_cmd.cpp +++ b/src/tunnelbridge_cmd.cpp @@ -968,9 +968,6 @@ static CommandCost DoClearBridge(TileIndex tile, DoCommandFlag flags) if (v != nullptr) FreeTrainTrackReservation(v); } - bool removetile = false; - bool removeendtile = false; - /* Update company infrastructure counts. */ if (rail) { if (Company::IsValidID(owner)) Company::Get(owner)->infrastructure.rail[GetRailType(tile)] -= len * TUNNELBRIDGE_TRACKBIT_FACTOR; @@ -980,16 +977,12 @@ static CommandCost DoClearBridge(TileIndex tile, DoCommandFlag flags) UpdateCompanyRoadInfrastructure(GetRoadTypeTram(tile), GetRoadOwner(tile, RTT_TRAM), -(int)(len * 2 * TUNNELBRIDGE_TRACKBIT_FACTOR)); } else { // Aqueduct if (Company::IsValidID(owner)) Company::Get(owner)->infrastructure.water -= len * TUNNELBRIDGE_TRACKBIT_FACTOR; - removetile = IsDockingTile(tile); - removeendtile = IsDockingTile(endtile); } DirtyCompanyInfrastructureWindows(owner); DoClearSquare(tile); DoClearSquare(endtile); - if (removetile) RemoveDockingTile(tile); - if (removeendtile) RemoveDockingTile(endtile); for (TileIndex c = tile + delta; c != endtile; c += delta) { /* do not let trees appear from 'nowhere' after removing bridge */ if (IsNormalRoadTile(c) && GetRoadside(c) == ROADSIDE_TREES) { diff --git a/src/water_cmd.cpp b/src/water_cmd.cpp index 211e89b4a0..4f3ed30620 100644 --- a/src/water_cmd.cpp +++ b/src/water_cmd.cpp @@ -548,10 +548,8 @@ static CommandCost ClearTile_Water(TileIndex tile, DoCommandFlag flags) Company::Get(owner)->infrastructure.water--; DirtyCompanyInfrastructureWindows(owner); } - bool remove = IsDockingTile(tile); DoClearSquare(tile); MarkCanalsAndRiversAroundDirty(tile); - if (remove) RemoveDockingTile(tile); } return CommandCost(EXPENSES_CONSTRUCTION, base_cost); @@ -565,10 +563,8 @@ static CommandCost ClearTile_Water(TileIndex tile, DoCommandFlag flags) if (ret.Failed()) return ret; if (flags & DC_EXEC) { - bool remove = IsDockingTile(tile); DoClearSquare(tile); MarkCanalsAndRiversAroundDirty(tile); - if (remove) RemoveDockingTile(tile); } if (IsSlopeWithOneCornerRaised(slope)) { return CommandCost(EXPENSES_CONSTRUCTION, _price[PR_CLEAR_WATER]);