From a5c8365aa470f6c18981c6e9a87a80380fbc1102 Mon Sep 17 00:00:00 2001 From: mrmbernardi Date: Sat, 2 Sep 2023 12:46:24 +0200 Subject: [PATCH] Feature: Setting to disallow level crossings with competitors (#10755) --- src/lang/english.txt | 3 +++ src/rail_cmd.cpp | 5 +++++ src/road_cmd.cpp | 5 +++++ src/settings_gui.cpp | 1 + src/settings_type.h | 1 + src/table/settings/world_settings.ini | 7 +++++++ 6 files changed, 22 insertions(+) diff --git a/src/lang/english.txt b/src/lang/english.txt index caec9c7aa6..674eacbc4b 100644 --- a/src/lang/english.txt +++ b/src/lang/english.txt @@ -1426,6 +1426,9 @@ STR_CONFIG_SETTING_PLANE_CRASHES_NONE :None* STR_CONFIG_SETTING_PLANE_CRASHES_REDUCED :Reduced STR_CONFIG_SETTING_PLANE_CRASHES_NORMAL :Normal +STR_CONFIG_SETTING_CROSSING_WITH_COMPETITOR :Allow level crossings with roads or rails owned by competitors: {STRING2} +STR_CONFIG_SETTING_CROSSING_WITH_COMPETITOR_HELPTEXT :Allow construction of level crossings on roads or rails owned by competitors + STR_CONFIG_SETTING_STOP_ON_TOWN_ROAD :Allow drive-through road stops on roads owned by towns: {STRING2} STR_CONFIG_SETTING_STOP_ON_TOWN_ROAD_HELPTEXT :Allow construction of drive-through road stops on roads owned by towns STR_CONFIG_SETTING_STOP_ON_COMPETITOR_ROAD :Allow drive-through road stops on roads owned by competitors: {STRING2} diff --git a/src/rail_cmd.cpp b/src/rail_cmd.cpp index 684bdf639e..7c0e52dd1f 100644 --- a/src/rail_cmd.cpp +++ b/src/rail_cmd.cpp @@ -507,6 +507,11 @@ CommandCost CmdBuildSingleRail(DoCommandFlag flags, TileIndex tile, RailType rai /* Level crossings may only be built on these slopes */ if (!HasBit(VALID_LEVEL_CROSSING_SLOPES, tileh)) return_cmd_error(STR_ERROR_LAND_SLOPED_IN_WRONG_DIRECTION); + if (!_settings_game.construction.crossing_with_competitor && _current_company != OWNER_DEITY) { + CommandCost ret = CheckTileOwnership(tile); + if (ret.Failed()) return ret; + } + CommandCost ret = EnsureNoVehicleOnGround(tile); if (ret.Failed()) return ret; diff --git a/src/road_cmd.cpp b/src/road_cmd.cpp index 00394750a9..7bfbce0970 100644 --- a/src/road_cmd.cpp +++ b/src/road_cmd.cpp @@ -737,6 +737,11 @@ CommandCost CmdBuildRoad(DoCommandFlag flags, TileIndex tile, RoadBits pieces, R return_cmd_error(STR_ERROR_LAND_SLOPED_IN_WRONG_DIRECTION); } + if (!_settings_game.construction.crossing_with_competitor && company != OWNER_TOWN && company != OWNER_DEITY) { + CommandCost ret = CheckTileOwnership(tile); + if (ret.Failed()) return ret; + } + if (GetRailTileType(tile) != RAIL_TILE_NORMAL) goto do_clear; if (RoadNoLevelCrossing(rt)) { diff --git a/src/settings_gui.cpp b/src/settings_gui.cpp index 8718f70e24..2f1fedf05d 100644 --- a/src/settings_gui.cpp +++ b/src/settings_gui.cpp @@ -1932,6 +1932,7 @@ static SettingsContainer &GetSettingsTree() limitations->Add(new SettingEntry("station.distant_join_stations")); limitations->Add(new SettingEntry("construction.road_stop_on_town_road")); limitations->Add(new SettingEntry("construction.road_stop_on_competitor_road")); + limitations->Add(new SettingEntry("construction.crossing_with_competitor")); limitations->Add(new SettingEntry("vehicle.disable_elrails")); } diff --git a/src/settings_type.h b/src/settings_type.h index d31381bbe2..b345caae11 100644 --- a/src/settings_type.h +++ b/src/settings_type.h @@ -368,6 +368,7 @@ struct ConstructionSettings { bool extra_dynamite; ///< extra dynamite bool road_stop_on_town_road; ///< allow building of drive-through road stops on town owned roads bool road_stop_on_competitor_road; ///< allow building of drive-through road stops on roads owned by competitors + 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 freeform_edges; ///< allow terraforming the tiles at the map edges diff --git a/src/table/settings/world_settings.ini b/src/table/settings/world_settings.ini index 490221dc0a..ba698ba756 100644 --- a/src/table/settings/world_settings.ini +++ b/src/table/settings/world_settings.ini @@ -523,6 +523,13 @@ str = STR_CONFIG_SETTING_STOP_ON_COMPETITOR_ROAD strhelp = STR_CONFIG_SETTING_STOP_ON_COMPETITOR_ROAD_HELPTEXT cat = SC_BASIC +[SDT_BOOL] +var = construction.crossing_with_competitor +def = true +str = STR_CONFIG_SETTING_CROSSING_WITH_COMPETITOR +strhelp = STR_CONFIG_SETTING_CROSSING_WITH_COMPETITOR_HELPTEXT +cat = SC_BASIC + [SDT_VAR] var = construction.raw_industry_construction type = SLE_UINT8