From 4db69283c1fe64ced99f74ad4d96c1920ea162fb Mon Sep 17 00:00:00 2001 From: Jonathan G Rennison Date: Sun, 30 Jul 2017 14:27:42 +0100 Subject: [PATCH] Add setting to disable removing sea/rivers --- src/command_type.h | 1 + src/landscape.cpp | 4 +++- src/lang/english.txt | 2 ++ src/rail_cmd.cpp | 11 +++++++++-- src/settings_gui.cpp | 1 + src/settings_type.h | 1 + src/table/settings.ini | 9 +++++++++ src/water_cmd.cpp | 14 +++++++++----- 8 files changed, 35 insertions(+), 8 deletions(-) diff --git a/src/command_type.h b/src/command_type.h index 9a1a506d4e..282571184c 100644 --- a/src/command_type.h +++ b/src/command_type.h @@ -420,6 +420,7 @@ enum DoCommandFlag { DC_ALL_TILES = 0x200, ///< allow this command also on MP_VOID tiles DC_NO_MODIFY_TOWN_RATING = 0x400, ///< do not change town rating DC_FORCE_CLEAR_TILE = 0x800, ///< do not only remove the object on the tile, but also clear any water left on it + DC_ALLOW_REMOVE_WATER = 0x1000,///< always allow removing water }; DECLARE_ENUM_AS_BIT_SET(DoCommandFlag) diff --git a/src/landscape.cpp b/src/landscape.cpp index 18efa43c49..be2da322ef 100644 --- a/src/landscape.cpp +++ b/src/landscape.cpp @@ -622,7 +622,9 @@ CommandCost CmdLandscapeClear(TileIndex tile, DoCommandFlag flags, uint32 p1, ui if ((flags & DC_FORCE_CLEAR_TILE) && HasTileWaterClass(tile) && IsTileOnWater(tile) && !IsWaterTile(tile) && !IsCoastTile(tile)) { if ((flags & DC_AUTO) && GetWaterClass(tile) == WATER_CLASS_CANAL) return_cmd_error(STR_ERROR_MUST_DEMOLISH_CANAL_FIRST); do_clear = true; - cost.AddCost(GetWaterClass(tile) == WATER_CLASS_CANAL ? _price[PR_CLEAR_CANAL] : _price[PR_CLEAR_WATER]); + const bool is_canal = GetWaterClass(tile) == WATER_CLASS_CANAL; + if (!is_canal && _game_mode != GM_EDITOR && !_settings_game.construction.enable_remove_water && !(flags & DC_ALLOW_REMOVE_WATER)) return_cmd_error(STR_ERROR_CAN_T_BUILD_ON_WATER); + cost.AddCost(is_canal ? _price[PR_CLEAR_CANAL] : _price[PR_CLEAR_WATER]); } Company *c = (flags & (DC_AUTO | DC_BANKRUPT)) ? NULL : Company::GetIfValid(_current_company); diff --git a/src/lang/english.txt b/src/lang/english.txt index 6c854ba938..dc86d29a1f 100644 --- a/src/lang/english.txt +++ b/src/lang/english.txt @@ -1502,6 +1502,8 @@ STR_CONFIG_SETTING_EXPENSES_LAYOUT_HELPTEXT :Define the layo STR_CONFIG_SETTING_ENABLE_BUILD_RIVER :Enable building rivers: {STRING2} STR_CONFIG_SETTING_ENABLE_BUILD_RIVER_HELPTEXT :Enable building rivers outside of the scenario editor +STR_CONFIG_SETTING_ENABLE_REMOVE_WATER :Enable removing sea and rivers: {STRING2} +STR_CONFIG_SETTING_ENABLE_REMOVE_WATER_HELPTEXT :Enable removing sea and rivers outside of the scenario editor STR_CONFIG_SETTING_SOUND_TICKER :News ticker: {STRING2} STR_CONFIG_SETTING_SOUND_TICKER_HELPTEXT :Play sound for summarised news messages diff --git a/src/rail_cmd.cpp b/src/rail_cmd.cpp index e1dd99c0f9..9a2ade80c1 100644 --- a/src/rail_cmd.cpp +++ b/src/rail_cmd.cpp @@ -581,7 +581,7 @@ CommandCost CmdBuildSingleRail(TileIndex tile, DoCommandFlag flags, uint32 p1, u if (ret.Failed()) return ret; cost.AddCost(ret); - ret = DoCommand(tile, 0, 0, flags, CMD_LANDSCAPE_CLEAR); + ret = DoCommand(tile, 0, 0, flags | DC_ALLOW_REMOVE_WATER, CMD_LANDSCAPE_CLEAR); if (ret.Failed()) return ret; cost.AddCost(ret); @@ -2014,6 +2014,8 @@ static CommandCost ClearTile_Track(TileIndex tile, DoCommandFlag flags) CommandCost ret = EnsureNoVehicleOnGround(tile); if (ret.Failed()) return ret; + if (_game_mode != GM_EDITOR && !_settings_game.construction.enable_remove_water && !(flags & DC_ALLOW_REMOVE_WATER)) return_cmd_error(STR_ERROR_CAN_T_BUILD_ON_WATER); + /* The track was removed, and left a coast tile. Now also clear the water. */ if (flags & DC_EXEC) DoClearSquare(tile); cost.AddCost(_price[PR_CLEAR_WATER]); @@ -3239,7 +3241,10 @@ static CommandCost TestAutoslopeOnRailTile(TileIndex tile, uint flags, int z_old /* Make the ground dirty, if surface slope has changed */ if (tileh_old != tileh_new) { /* If there is flat water on the lower halftile add the cost for clearing it */ - if (GetRailGroundType(tile) == RAIL_GROUND_WATER && IsSlopeWithOneCornerRaised(tileh_old)) cost.AddCost(_price[PR_CLEAR_WATER]); + if (GetRailGroundType(tile) == RAIL_GROUND_WATER && IsSlopeWithOneCornerRaised(tileh_old)) { + if (_game_mode != GM_EDITOR && !_settings_game.construction.enable_remove_water && !(flags & DC_ALLOW_REMOVE_WATER)) return_cmd_error(STR_ERROR_CAN_T_BUILD_ON_WATER); + cost.AddCost(_price[PR_CLEAR_WATER]); + } if ((flags & DC_EXEC) != 0) SetRailGroundType(tile, RAIL_GROUND_BARREN); } return cost; @@ -3265,6 +3270,8 @@ static CommandCost TerraformTile_Track(TileIndex tile, DoCommandFlag flags, int /* Allow clearing the water only if there is no ship */ if (was_water && HasVehicleOnPos(tile, NULL, &EnsureNoShipProc)) return_cmd_error(STR_ERROR_SHIP_IN_THE_WAY); + if (was_water && _game_mode != GM_EDITOR && !_settings_game.construction.enable_remove_water && !(flags & DC_ALLOW_REMOVE_WATER)) return_cmd_error(STR_ERROR_CAN_T_BUILD_ON_WATER); + /* First test autoslope. However if it succeeds we still have to test the rest, because non-autoslope terraforming is cheaper. */ CommandCost autoslope_result = TestAutoslopeOnRailTile(tile, flags, z_old, tileh_old, z_new, tileh_new, rail_bits); diff --git a/src/settings_gui.cpp b/src/settings_gui.cpp index df22e1895a..c0463b4cd7 100644 --- a/src/settings_gui.cpp +++ b/src/settings_gui.cpp @@ -1721,6 +1721,7 @@ static SettingsContainer &GetSettingsTree() limitations->Add(new SettingEntry("vehicle.disable_elrails")); limitations->Add(new SettingEntry("construction.maximum_signal_evaluations")); limitations->Add(new SettingEntry("construction.enable_build_river")); + limitations->Add(new SettingEntry("construction.enable_remove_water")); limitations->Add(new SettingEntry("construction.road_custom_bridge_heads")); } diff --git a/src/settings_type.h b/src/settings_type.h index b15416ad2d..ea48c8e457 100644 --- a/src/settings_type.h +++ b/src/settings_type.h @@ -356,6 +356,7 @@ struct ConstructionSettings { uint16 maximum_signal_evaluations; ///< maximum number of programmable signals which may be evaluated in one pass byte simulated_wormhole_signals; ///< simulate signals in tunnel bool enable_build_river; ///< enable building rivers in-game + bool enable_remove_water; ///< enable removing sea and rivers in-game uint8 road_custom_bridge_heads; ///< allow construction of road custom bridge heads bool chunnel; ///< allow construction of tunnels under water diff --git a/src/table/settings.ini b/src/table/settings.ini index 2e9466a178..a3f3174479 100644 --- a/src/table/settings.ini +++ b/src/table/settings.ini @@ -468,6 +468,15 @@ str = STR_CONFIG_SETTING_ENABLE_BUILD_RIVER strhelp = STR_CONFIG_SETTING_ENABLE_BUILD_RIVER_HELPTEXT patxname = ""enable_build_river.construction.enable_build_river"" +[SDT_BOOL] +base = GameSettings +var = construction.enable_remove_water +def = true +cat = SC_BASIC +str = STR_CONFIG_SETTING_ENABLE_REMOVE_WATER +strhelp = STR_CONFIG_SETTING_ENABLE_REMOVE_WATER_HELPTEXT +patxname = ""enable_build_river.construction.enable_remove_water"" + [SDT_VAR] base = GameSettings var = construction.terraform_per_64k_frames diff --git a/src/water_cmd.cpp b/src/water_cmd.cpp index ecfe4a6e48..57ea8f1f45 100644 --- a/src/water_cmd.cpp +++ b/src/water_cmd.cpp @@ -476,6 +476,8 @@ static CommandCost ClearTile_Water(TileIndex tile, DoCommandFlag flags) case WATER_TILE_CLEAR: { if (flags & DC_NO_WATER) return_cmd_error(STR_ERROR_CAN_T_BUILD_ON_WATER); + if (!IsCanal(tile) && _game_mode != GM_EDITOR && !_settings_game.construction.enable_remove_water && !(flags & DC_ALLOW_REMOVE_WATER)) return_cmd_error(STR_ERROR_CAN_T_BUILD_ON_WATER); + Money base_cost = IsCanal(tile) ? _price[PR_CLEAR_CANAL] : _price[PR_CLEAR_WATER]; /* Make sure freeform edges are allowed or it's not an edge tile. */ if (!_settings_game.construction.freeform_edges && (!IsInsideMM(TileX(tile), 1, MapMaxX() - 1) || @@ -512,15 +514,17 @@ static CommandCost ClearTile_Water(TileIndex tile, DoCommandFlag flags) CommandCost ret = EnsureNoVehicleOnGround(tile); if (ret.Failed()) return ret; + if (IsSlopeWithOneCornerRaised(slope)) { + if (_game_mode != GM_EDITOR && !_settings_game.construction.enable_remove_water && !(flags & DC_ALLOW_REMOVE_WATER)) return_cmd_error(STR_ERROR_CAN_T_BUILD_ON_WATER); + ret = CommandCost(EXPENSES_CONSTRUCTION, _price[PR_CLEAR_WATER]); + } else { + ret = CommandCost(EXPENSES_CONSTRUCTION, _price[PR_CLEAR_ROUGH]); + } if (flags & DC_EXEC) { DoClearSquare(tile); MarkCanalsAndRiversAroundDirty(tile); } - if (IsSlopeWithOneCornerRaised(slope)) { - return CommandCost(EXPENSES_CONSTRUCTION, _price[PR_CLEAR_WATER]); - } else { - return CommandCost(EXPENSES_CONSTRUCTION, _price[PR_CLEAR_ROUGH]); - } + return ret; } case WATER_TILE_LOCK: {