From 83880920fbe54e058e46813254bddefd2dcd4ac2 Mon Sep 17 00:00:00 2001 From: Jonathan G Rennison Date: Sun, 29 Jan 2023 16:51:32 +0000 Subject: [PATCH] Fix water infrastructure accounting when building ship depots See: https://github.com/OpenTTD/OpenTTD/issues/10419 --- src/water_cmd.cpp | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/src/water_cmd.cpp b/src/water_cmd.cpp index 66dd686c2b..22f3a4f80f 100644 --- a/src/water_cmd.cpp +++ b/src/water_cmd.cpp @@ -148,11 +148,12 @@ CommandCost CmdBuildShipDepot(TileIndex tile, DoCommandFlag flags, uint32 p1, ui Depot *depot = new Depot(tile); depot->build_date = _date; - if (wc1 == WATER_CLASS_CANAL || wc2 == WATER_CLASS_CANAL) { - /* Update infrastructure counts after the unconditional clear earlier. */ - Company::Get(_current_company)->infrastructure.water += wc1 == WATER_CLASS_CANAL && wc2 == WATER_CLASS_CANAL ? 2 : 1; - } - Company::Get(_current_company)->infrastructure.water += 2 * LOCK_DEPOT_TILE_FACTOR; + uint new_water_infra = 2 * LOCK_DEPOT_TILE_FACTOR; + /* Update infrastructure counts after the tile clears earlier. */ + if (wc1 == WATER_CLASS_CANAL && !(HasTileWaterClass(tile) && GetWaterClass(tile) == WATER_CLASS_CANAL && IsTileOwner(tile, _current_company))) new_water_infra++; + if (wc2 == WATER_CLASS_CANAL && !(HasTileWaterClass(tile2) && GetWaterClass(tile2) == WATER_CLASS_CANAL && IsTileOwner(tile2, _current_company))) new_water_infra++; + + Company::Get(_current_company)->infrastructure.water += new_water_infra; DirtyCompanyInfrastructureWindows(_current_company); MakeShipDepot(tile, _current_company, depot->index, DEPOT_PART_NORTH, axis, wc1);