From a27bdbb3e23d6809fe7eb926b2a8533c89c5f7a8 Mon Sep 17 00:00:00 2001 From: Jonathan G Rennison Date: Sat, 13 Feb 2016 16:51:19 +0000 Subject: [PATCH] Add company settings to enable competitors' to buy/renew in own depots. --- src/lang/english.txt | 4 ++++ src/settings_gui.cpp | 4 ++++ src/settings_type.h | 1 + src/table/company_settings.ini | 32 ++++++++++++++++++++++++++++++++ src/vehicle_cmd.cpp | 8 +++++++- 5 files changed, 48 insertions(+), 1 deletion(-) diff --git a/src/lang/english.txt b/src/lang/english.txt index ac00761800..be6c9a58ed 100644 --- a/src/lang/english.txt +++ b/src/lang/english.txt @@ -1472,6 +1472,10 @@ STR_CONFIG_SETTING_SHARING_FEE_AIR :Terminal fee fo STR_CONFIG_SETTING_SHARING_PAYMENT_IN_DEBT :Allow companies in debt to pay sharing fees: {STRING2} STR_CONFIG_SETTING_SHARING_USED_BY_VEHICLES :Can't change this setting, vehicles are using shared infrastructure. STR_CONFIG_SETTING_SHARING_ORDERS_TO_OTHERS :Can't change this setting, vehicles have orders to destinations of others. +STR_CONFIG_SETTING_INFRA_OTHERS_BUY_IN_DEPOT_RAIL :Enable competitors to buy and renew trains in depots: {STRING2} +STR_CONFIG_SETTING_INFRA_OTHERS_BUY_IN_DEPOT_ROAD :Enable competitors to buy and renew road vehicles in depots: {STRING2} +STR_CONFIG_SETTING_INFRA_OTHERS_BUY_IN_DEPOT_WATER :Enable competitors to buy and renew ships in depots: {STRING2} +STR_CONFIG_SETTING_INFRA_OTHERS_BUY_IN_DEPOT_AIR :Enable competitors to buy and renew aircraft in hangars: {STRING2} STR_CONFIG_SETTING_SERVINT_ISPERCENT :Service intervals are in percents: {STRING2} STR_CONFIG_SETTING_SERVINT_ISPERCENT_HELPTEXT :Choose whether servicing of vehicles is triggered by the time passed since last service or by reliability dropping by a certain percentage of the maximum reliability diff --git a/src/settings_gui.cpp b/src/settings_gui.cpp index 7a32e9a1d6..bbeadd90f4 100644 --- a/src/settings_gui.cpp +++ b/src/settings_gui.cpp @@ -1586,6 +1586,10 @@ static SettingsContainer &GetSettingsTree() company->Add(new SettingEntry("vehicle.servint_roadveh")); company->Add(new SettingEntry("vehicle.servint_ships")); company->Add(new SettingEntry("vehicle.servint_aircraft")); + company->Add(new SettingEntry("company.infra_others_buy_in_depot[0]")); + company->Add(new SettingEntry("company.infra_others_buy_in_depot[1]")); + company->Add(new SettingEntry("company.infra_others_buy_in_depot[2]")); + company->Add(new SettingEntry("company.infra_others_buy_in_depot[3]")); } SettingsPage *accounting = main->Add(new SettingsPage(STR_CONFIG_SETTING_ACCOUNTING)); diff --git a/src/settings_type.h b/src/settings_type.h index db16469d58..864d26fee5 100644 --- a/src/settings_type.h +++ b/src/settings_type.h @@ -538,6 +538,7 @@ struct CompanySettings { uint32 engine_renew_money; ///< minimum amount of money before autorenew is used bool renew_keep_length; ///< sell some wagons if after autoreplace the train is longer than before VehicleDefaultSettings vehicle; ///< default settings for vehicles + bool infra_others_buy_in_depot[4]; ///< other companies can buy/autorenew in this companies depots (where infra sharing enabled) }; /** All settings together for the game. */ diff --git a/src/table/company_settings.ini b/src/table/company_settings.ini index 8296890a74..a5807b2246 100644 --- a/src/table/company_settings.ini +++ b/src/table/company_settings.ini @@ -135,6 +135,38 @@ strhelp = STR_CONFIG_SETTING_SERVINT_AIRCRAFT_HELPTEXT strval = STR_CONFIG_SETTING_SERVINT_VALUE proc = UpdateIntervalAircraft +[SDT_BOOL] +base = CompanySettings +var = infra_others_buy_in_depot[0] +guiflags = SGF_PER_COMPANY +def = false +str = STR_CONFIG_SETTING_INFRA_OTHERS_BUY_IN_DEPOT_RAIL +patxname = ""infra_sharing.infra_others_buy_in_depot.rail"" + +[SDT_BOOL] +base = CompanySettings +var = infra_others_buy_in_depot[1] +guiflags = SGF_PER_COMPANY +def = false +str = STR_CONFIG_SETTING_INFRA_OTHERS_BUY_IN_DEPOT_ROAD +patxname = ""infra_sharing.infra_others_buy_in_depot.road"" + +[SDT_BOOL] +base = CompanySettings +var = infra_others_buy_in_depot[2] +guiflags = SGF_PER_COMPANY +def = false +str = STR_CONFIG_SETTING_INFRA_OTHERS_BUY_IN_DEPOT_WATER +patxname = ""infra_sharing.infra_others_buy_in_depot.water"" + +[SDT_BOOL] +base = CompanySettings +var = infra_others_buy_in_depot[3] +guiflags = SGF_PER_COMPANY +def = false +str = STR_CONFIG_SETTING_INFRA_OTHERS_BUY_IN_DEPOT_AIR +patxname = ""infra_sharing.infra_others_buy_in_depot.air"" + [SDT_END] diff --git a/src/vehicle_cmd.cpp b/src/vehicle_cmd.cpp index 13c93c065b..e57ea8e38c 100644 --- a/src/vehicle_cmd.cpp +++ b/src/vehicle_cmd.cpp @@ -86,9 +86,15 @@ CommandCost CmdBuildAircraft (TileIndex tile, DoCommandFlag flags, const Engin CommandCost CmdBuildVehicle(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text) { /* Elementary check for valid location. */ - if (!IsDepotTile(tile) || !IsTileOwner(tile, _current_company)) return CMD_ERROR; + if (!IsDepotTile(tile)) return CMD_ERROR; VehicleType type = GetDepotVehicleType(tile); + if (!IsTileOwner(tile, _current_company)) { + if (!_settings_game.economy.infrastructure_sharing[type]) return CMD_ERROR; + + const Company *c = Company::GetIfValid(GetTileOwner(tile)); + if (c == NULL || !c->settings.infra_others_buy_in_depot[type]) return CMD_ERROR; + } /* Validate the engine type. */ EngineID eid = GB(p1, 0, 16);