From df92a056dffd9fa2a765246da10442717f459c7f Mon Sep 17 00:00:00 2001 From: Jonathan G Rennison Date: Tue, 14 Aug 2018 21:05:47 +0100 Subject: [PATCH] Fix #6875: Depot building cost does not include foundation build cost (#6883) --- bin/ai/regression/tst_regression/result.txt | 6 +++--- src/rail_cmd.cpp | 14 ++++++++------ src/road_cmd.cpp | 14 ++++++++------ 3 files changed, 19 insertions(+), 15 deletions(-) diff --git a/bin/ai/regression/tst_regression/result.txt b/bin/ai/regression/tst_regression/result.txt index f91a8780cd..4aa95d075c 100644 --- a/bin/ai/regression/tst_regression/result.txt +++ b/bin/ai/regression/tst_regression/result.txt @@ -7253,7 +7253,7 @@ ERROR: IsEnd() is invalid as Begin() is never called IsBuoyTile(): false IsLockTile(): false IsCanalTile(): false - GetBankBalance(): 479851 + GetBankBalance(): 479664 BuildWaterDepot(): true BuildDock(): true BuildBuoy(): true @@ -7266,7 +7266,7 @@ ERROR: IsEnd() is invalid as Begin() is never called IsBuoyTile(): true IsLockTile(): true IsCanalTile(): true - GetBankBalance(): 465257 + GetBankBalance(): 465070 --AIWaypointList(BUOY)-- Count(): 1 @@ -7285,7 +7285,7 @@ ERROR: IsEnd() is invalid as Begin() is never called IsBuoyTile(): false IsLockTile(): false IsCanalTile(): false - GetBankBalance(): 459862 + GetBankBalance(): 459675 BuildWaterDepot(): true BuildDock(): true diff --git a/src/rail_cmd.cpp b/src/rail_cmd.cpp index d21c1468ca..d5194e0c3b 100644 --- a/src/rail_cmd.cpp +++ b/src/rail_cmd.cpp @@ -967,6 +967,8 @@ CommandCost CmdBuildTrainDepot(TileIndex tile, DoCommandFlag flags, uint32 p1, u DiagDirection dir = Extract(p2); + CommandCost cost(EXPENSES_CONSTRUCTION); + /* Prohibit construction if * The tile is non-flat AND * 1) build-on-slopes is disabled @@ -974,14 +976,14 @@ CommandCost CmdBuildTrainDepot(TileIndex tile, DoCommandFlag flags, uint32 p1, u * 3) the exit points in the wrong direction */ - if (tileh != SLOPE_FLAT && ( - !_settings_game.construction.build_on_slopes || - !CanBuildDepotByTileh(dir, tileh) - )) { - return_cmd_error(STR_ERROR_FLAT_LAND_REQUIRED); + if (tileh != SLOPE_FLAT) { + if (!_settings_game.construction.build_on_slopes || !CanBuildDepotByTileh(dir, tileh)) { + return_cmd_error(STR_ERROR_FLAT_LAND_REQUIRED); + } + cost.AddCost(_price[PR_BUILD_FOUNDATION]); } - CommandCost cost = DoCommand(tile, 0, 0, flags, CMD_LANDSCAPE_CLEAR); + cost.AddCost(DoCommand(tile, 0, 0, flags, CMD_LANDSCAPE_CLEAR)); if (cost.Failed()) return cost; if (IsBridgeAbove(tile)) return_cmd_error(STR_ERROR_MUST_DEMOLISH_BRIDGE_FIRST); diff --git a/src/road_cmd.cpp b/src/road_cmd.cpp index 5e432a2e6b..bdc8ce7f30 100644 --- a/src/road_cmd.cpp +++ b/src/road_cmd.cpp @@ -1017,15 +1017,17 @@ CommandCost CmdBuildRoadDepot(TileIndex tile, DoCommandFlag flags, uint32 p1, ui if (!IsValidRoadType(rt) || !ValParamRoadType(rt)) return CMD_ERROR; + CommandCost cost(EXPENSES_CONSTRUCTION); + Slope tileh = GetTileSlope(tile); - if (tileh != SLOPE_FLAT && ( - !_settings_game.construction.build_on_slopes || - !CanBuildDepotByTileh(dir, tileh) - )) { - return_cmd_error(STR_ERROR_FLAT_LAND_REQUIRED); + if (tileh != SLOPE_FLAT) { + if (!_settings_game.construction.build_on_slopes || !CanBuildDepotByTileh(dir, tileh)) { + return_cmd_error(STR_ERROR_FLAT_LAND_REQUIRED); + } + cost.AddCost(_price[PR_BUILD_FOUNDATION]); } - CommandCost cost = DoCommand(tile, 0, 0, flags, CMD_LANDSCAPE_CLEAR); + cost.AddCost(DoCommand(tile, 0, 0, flags, CMD_LANDSCAPE_CLEAR)); if (cost.Failed()) return cost; if (IsBridgeAbove(tile)) return_cmd_error(STR_ERROR_MUST_DEMOLISH_BRIDGE_FIRST);