From 4d23dccaca51c547db27a685cb92eb04214dce85 Mon Sep 17 00:00:00 2001 From: Tyler Trahan Date: Fri, 3 Jan 2025 15:35:14 -0500 Subject: [PATCH] Feature: Setting to allow bulldozing unserved industries --- src/industry_cmd.cpp | 22 +++++++++++++++++++++- src/lang/english.txt | 3 +++ src/settings_gui.cpp | 1 + src/settings_type.h | 1 + src/table/settings/world_settings.ini | 7 +++++++ 5 files changed, 33 insertions(+), 1 deletion(-) diff --git a/src/industry_cmd.cpp b/src/industry_cmd.cpp index 9d5d761639..7cf54ea46b 100644 --- a/src/industry_cmd.cpp +++ b/src/industry_cmd.cpp @@ -493,13 +493,33 @@ static CommandCost ClearTile_Industry(TileIndex tile, DoCommandFlag flags) Industry *i = Industry::GetByTile(tile); const IndustrySpec *indspec = GetIndustrySpec(i->type); + /* Check if the player can bulldoze the industry. */ + bool bulldoze_allowed = _settings_game.construction.bulldoze_industries; + if (bulldoze_allowed) { + /* Don't bulldoze industries that have recently had any cargo transported...*/ + for (const auto &p : i->produced) { + if (p.history[LAST_MONTH].PctTransported() > 0) { + bulldoze_allowed = false; + break; + } + } + + /* ...or received. */ + for (const auto &a : i->accepted) { + if (a.last_accepted + EconomyTime::DAYS_IN_ECONOMY_YEAR > TimerGameEconomy::date) { + bulldoze_allowed = false; + break; + } + } + } + /* water can destroy industries * in editor you can bulldoze industries * with magic_bulldozer cheat you can destroy industries * (area around OILRIG is water, so water shouldn't flood it */ if ((_current_company != OWNER_WATER && _game_mode != GM_EDITOR && - !_cheats.magic_bulldozer.value) || + !bulldoze_allowed) || ((flags & DC_AUTO) != 0) || (_current_company == OWNER_WATER && ((indspec->behaviour & INDUSTRYBEH_BUILT_ONWATER) || diff --git a/src/lang/english.txt b/src/lang/english.txt index 4244c77792..b8e4f3e3d5 100644 --- a/src/lang/english.txt +++ b/src/lang/english.txt @@ -1395,6 +1395,9 @@ STR_CONFIG_SETTING_INDUSTRY_PLATFORM_HELPTEXT :Amount of flat STR_CONFIG_SETTING_MULTIPINDTOWN :Allow multiple similar industries per town: {STRING2} STR_CONFIG_SETTING_MULTIPINDTOWN_HELPTEXT :Normally, a town does not want more than one industry of each type. With this setting, it will allow several industries of the same type in the same town +STR_CONFIG_SETTING_BULLDOZE_INDUSTRIES :Allow bulldozing unserved industries +STR_CONFIG_SETTING_BULLDOZE_INDUSTRIES_HELPTEXT :Allow industries to be demolished if 0% of their output is currently being transported + STR_CONFIG_SETTING_SIGNALSIDE :Show signals: {STRING2} STR_CONFIG_SETTING_SIGNALSIDE_HELPTEXT :Select on which side of the track to place signals ###length 3 diff --git a/src/settings_gui.cpp b/src/settings_gui.cpp index 708a78f623..9ff5aa7970 100644 --- a/src/settings_gui.cpp +++ b/src/settings_gui.cpp @@ -2149,6 +2149,7 @@ static SettingsContainer &GetSettingsTree() limitations->Add(new SettingEntry("construction.command_pause_level")); limitations->Add(new SettingEntry("construction.autoslope")); limitations->Add(new SettingEntry("construction.extra_dynamite")); + limitations->Add(new SettingEntry("construction.bulldoze_industries")); limitations->Add(new SettingEntry("construction.map_height_limit")); limitations->Add(new SettingEntry("construction.max_bridge_length")); limitations->Add(new SettingEntry("construction.max_bridge_height")); diff --git a/src/settings_type.h b/src/settings_type.h index 157bdf6058..6a06c4f7dc 100644 --- a/src/settings_type.h +++ b/src/settings_type.h @@ -392,6 +392,7 @@ struct ConstructionSettings { bool crossing_with_competitor; ///< allow building of level crossings with competitor roads or rails uint8_t raw_industry_construction; ///< type of (raw) industry construction (none, "normal", prospecting) uint8_t industry_platform; ///< the amount of flat land around an industry + bool bulldoze_industries; ///< whether players can bulldozed unserved industries bool freeform_edges; ///< allow terraforming the tiles at the map edges uint8_t extra_tree_placement; ///< (dis)allow building extra trees in-game uint8_t command_pause_level; ///< level/amount of commands that can't be executed while paused diff --git a/src/table/settings/world_settings.ini b/src/table/settings/world_settings.ini index 6b5d1466e0..5331dfcd94 100644 --- a/src/table/settings/world_settings.ini +++ b/src/table/settings/world_settings.ini @@ -560,6 +560,13 @@ strhelp = STR_CONFIG_SETTING_INDUSTRY_PLATFORM_HELPTEXT strval = STR_CONFIG_SETTING_TILE_LENGTH cat = SC_EXPERT +[SDT_BOOL] +var = construction.bulldoze_industries +def = false +str = STR_CONFIG_SETTING_BULLDOZE_INDUSTRIES +strhelp = STR_CONFIG_SETTING_BULLDOZE_INDUSTRIES_HELPTEXT +cat = SC_BASIC + [SDT_BOOL] var = construction.freeform_edges from = SLV_111