diff --git a/src/date_type.h b/src/date_type.h index fb652b19ee..8542128cd2 100644 --- a/src/date_type.h +++ b/src/date_type.h @@ -30,6 +30,7 @@ typedef uint8 Day; ///< Type for the day of the month, note: 1 based, first d static const int DAY_TICKS = 74; ///< ticks per day static const int DAYS_IN_YEAR = 365; ///< days per year static const int DAYS_IN_LEAP_YEAR = 366; ///< sometimes, you need one day more... +static const int MONTHS_IN_YEAR = 12; ///< months per year #define DATE_UNIT_SIZE (_settings_time.time_in_minutes ? _settings_time.ticks_per_minute : (DAY_TICKS * _settings_game.economy.day_length_factor)) diff --git a/src/lang/english.txt b/src/lang/english.txt index 1eb837b14c..c9acdb65b8 100644 --- a/src/lang/english.txt +++ b/src/lang/english.txt @@ -913,11 +913,11 @@ STR_NEWS_STATION_NOW_ACCEPTS_CARGO_AND_CARGO :{WHITE}{STATION STR_NEWS_OFFER_OF_SUBSIDY_EXPIRED :{BIG_FONT}{BLACK}Offer of subsidy expired:{}{}{STRING} from {STRING2} to {STRING2} will now not attract a subsidy STR_NEWS_SUBSIDY_WITHDRAWN_SERVICE :{BIG_FONT}{BLACK}Subsidy withdrawn:{}{}{STRING} service from {STRING2} to {STRING2} is no longer subsidised -STR_NEWS_SERVICE_SUBSIDY_OFFERED :{BIG_FONT}{BLACK}Service subsidy offered:{}{}First {STRING} service from {STRING2} to {STRING2} will attract a year's subsidy from the local authority! -STR_NEWS_SERVICE_SUBSIDY_AWARDED_HALF :{BIG_FONT}{BLACK}Service subsidy awarded to {RAW_STRING}!{}{}{STRING} service from {STRING2} to {STRING2} will pay 50% extra for the next year! -STR_NEWS_SERVICE_SUBSIDY_AWARDED_DOUBLE :{BIG_FONT}{BLACK}Service subsidy awarded to {RAW_STRING}!{}{}{STRING} service from {STRING2} to {STRING2} will pay double rates for the next year! -STR_NEWS_SERVICE_SUBSIDY_AWARDED_TRIPLE :{BIG_FONT}{BLACK}Service subsidy awarded to {RAW_STRING}!{}{}{STRING} service from {STRING2} to {STRING2} will pay triple rates for the next year! -STR_NEWS_SERVICE_SUBSIDY_AWARDED_QUADRUPLE :{BIG_FONT}{BLACK}Service subsidy awarded to {RAW_STRING}!{}{}{STRING} service from {STRING2} to {STRING2} will pay quadruple rates for the next year! +STR_NEWS_SERVICE_SUBSIDY_OFFERED :{BIG_FONT}{BLACK}Service subsidy offered:{}{}First {STRING} service from {STRING2} to {STRING2} will attract a {NUM} year subsidy from the local authority! +STR_NEWS_SERVICE_SUBSIDY_AWARDED_HALF :{BIG_FONT}{BLACK}Service subsidy awarded to {RAW_STRING}!{}{}{STRING} service from {STRING2} to {STRING2} will pay 50% extra for the next {NUM} year{P "" s}! +STR_NEWS_SERVICE_SUBSIDY_AWARDED_DOUBLE :{BIG_FONT}{BLACK}Service subsidy awarded to {RAW_STRING}!{}{}{STRING} service from {STRING2} to {STRING2} will pay double rates for the next {NUM} year{P "" s}! +STR_NEWS_SERVICE_SUBSIDY_AWARDED_TRIPLE :{BIG_FONT}{BLACK}Service subsidy awarded to {RAW_STRING}!{}{}{STRING} service from {STRING2} to {STRING2} will pay triple rates for the next {NUM} year{P "" s}! +STR_NEWS_SERVICE_SUBSIDY_AWARDED_QUADRUPLE :{BIG_FONT}{BLACK}Service subsidy awarded to {RAW_STRING}!{}{}{STRING} service from {STRING2} to {STRING2} will pay quadruple rates for the next {NUM} year{P "" s}! STR_NEWS_ROAD_REBUILDING :{BIG_FONT}{BLACK}Traffic chaos in {TOWN}!{}{}Road rebuilding programme funded by {RAW_STRING} brings 6 months of misery to motorists! STR_NEWS_EXCLUSIVE_RIGHTS_TITLE :{BIG_FONT}{BLACK}Transport monopoly! @@ -1240,6 +1240,10 @@ STR_CONFIG_SETTING_VEHICLE_BREAKDOWNS :Vehicle breakdo STR_CONFIG_SETTING_VEHICLE_BREAKDOWNS_HELPTEXT :Control how often inadequately serviced vehicles may break down STR_CONFIG_SETTING_SUBSIDY_MULTIPLIER :Subsidy multiplier: {STRING2} STR_CONFIG_SETTING_SUBSIDY_MULTIPLIER_HELPTEXT :Set how much is paid for subsidised connections +STR_CONFIG_SETTING_SUBSIDY_DURATION :Subsidy duration: {STRING2} +STR_CONFIG_SETTING_SUBSIDY_DURATION_HELPTEXT :Set the number of years for which a subsidy is awarded +STR_CONFIG_SETTING_SUBSIDY_DURATION_VALUE :{NUM} year{P "" s} +STR_CONFIG_SETTING_SUBSIDY_DURATION_DISABLED :No subsidies STR_CONFIG_SETTING_CONSTRUCTION_COSTS :Construction costs: {STRING2} STR_CONFIG_SETTING_CONSTRUCTION_COSTS_HELPTEXT :Set level of construction and purchase costs STR_CONFIG_SETTING_RECESSIONS :Recessions: {STRING2} diff --git a/src/saveload/saveload.h b/src/saveload/saveload.h index c0d1186e76..83b5ed197a 100644 --- a/src/saveload/saveload.h +++ b/src/saveload/saveload.h @@ -330,6 +330,7 @@ enum SaveLoadVersion : uint16 { SLV_INDUSTRY_TEXT, ///< 289 PR#8576 v1.11.0-RC1 Additional GS text for industries. SLV_MAPGEN_SETTINGS_REVAMP, ///< 290 PR#8891 v1.11 Revamp of some mapgen settings (snow coverage, desert coverage, heightmap height, custom terrain type). SLV_GROUP_REPLACE_WAGON_REMOVAL, ///< 291 PR#7441 Per-group wagon removal flag. + SLV_CUSTOM_SUBSIDY_DURATION, ///< 292 PR#9081 Configurable subsidy duration. SL_MAX_VERSION, ///< Highest possible saveload version diff --git a/src/saveload/subsidy_sl.cpp b/src/saveload/subsidy_sl.cpp index d0db78b61d..13b6bcd287 100644 --- a/src/saveload/subsidy_sl.cpp +++ b/src/saveload/subsidy_sl.cpp @@ -16,15 +16,15 @@ static const SaveLoad _subsidies_desc[] = { SLE_VAR(Subsidy, cargo_type, SLE_UINT8), - SLE_VAR(Subsidy, remaining, SLE_UINT8), - SLE_CONDVAR(Subsidy, awarded, SLE_UINT8, SLV_125, SL_MAX_VERSION), - SLE_CONDVAR(Subsidy, src_type, SLE_UINT8, SLV_125, SL_MAX_VERSION), - SLE_CONDVAR(Subsidy, dst_type, SLE_UINT8, SLV_125, SL_MAX_VERSION), - SLE_CONDVAR(Subsidy, src, SLE_FILE_U8 | SLE_VAR_U16, SL_MIN_VERSION, SLV_5), - SLE_CONDVAR(Subsidy, src, SLE_UINT16, SLV_5, SL_MAX_VERSION), - SLE_CONDVAR(Subsidy, dst, SLE_FILE_U8 | SLE_VAR_U16, SL_MIN_VERSION, SLV_5), - SLE_CONDVAR(Subsidy, dst, SLE_UINT16, SLV_5, SL_MAX_VERSION), - SLE_END() + SLE_CONDVAR(Subsidy, remaining, SLE_FILE_U8 | SLE_VAR_U16, SL_MIN_VERSION, SLV_CUSTOM_SUBSIDY_DURATION), + SLE_CONDVAR(Subsidy, remaining, SLE_UINT16, SLV_CUSTOM_SUBSIDY_DURATION, SL_MAX_VERSION), + SLE_CONDVAR(Subsidy, awarded, SLE_UINT8, SLV_125, SL_MAX_VERSION), + SLE_CONDVAR(Subsidy, src_type, SLE_UINT8, SLV_125, SL_MAX_VERSION), + SLE_CONDVAR(Subsidy, dst_type, SLE_UINT8, SLV_125, SL_MAX_VERSION), + SLE_CONDVAR(Subsidy, src, SLE_FILE_U8 | SLE_VAR_U16, SL_MIN_VERSION, SLV_5), + SLE_CONDVAR(Subsidy, src, SLE_UINT16, SLV_5, SL_MAX_VERSION), + SLE_CONDVAR(Subsidy, dst, SLE_FILE_U8 | SLE_VAR_U16, SL_MIN_VERSION, SLV_5), + SLE_CONDVAR(Subsidy, dst, SLE_UINT16, SLV_5, SL_MAX_VERSION), }; static void Save_SUBS() diff --git a/src/settings_gui.cpp b/src/settings_gui.cpp index 25e5bdc7ac..d13c77b8de 100644 --- a/src/settings_gui.cpp +++ b/src/settings_gui.cpp @@ -1935,6 +1935,7 @@ static SettingsContainer &GetSettingsTree() accounting->Add(new SettingEntry("difficulty.initial_interest")); accounting->Add(new SettingEntry("difficulty.max_loan")); accounting->Add(new SettingEntry("difficulty.subsidy_multiplier")); + accounting->Add(new SettingEntry("difficulty.subsidy_duration")); accounting->Add(new SettingEntry("economy.feeder_payment_share")); accounting->Add(new SettingEntry("economy.infrastructure_maintenance")); accounting->Add(new SettingEntry("difficulty.vehicle_costs")); diff --git a/src/settings_type.h b/src/settings_type.h index 26c5c6bd7b..50be90bac8 100644 --- a/src/settings_type.h +++ b/src/settings_type.h @@ -69,7 +69,8 @@ struct DifficultySettings { byte vehicle_costs; ///< amount of money spent on vehicle running cost byte competitor_speed; ///< the speed at which the AI builds byte vehicle_breakdowns; ///< likelihood of vehicles breaking down - byte subsidy_multiplier; ///< amount of subsidy + byte subsidy_multiplier; ///< payment multiplier for subsidized deliveries + uint16 subsidy_duration; ///< duration of subsidies byte construction_cost; ///< how expensive is building byte terrain_type; ///< the mountainousness of the landscape byte quantity_sea_lakes; ///< the amount of seas/lakes diff --git a/src/subsidy.cpp b/src/subsidy.cpp index 4cf42eb5c9..5ca9e4ec1f 100644 --- a/src/subsidy.cpp +++ b/src/subsidy.cpp @@ -41,7 +41,7 @@ void Subsidy::AwardTo(CompanyID company) assert(!this->IsAwarded()); this->awarded = company; - this->remaining = SUBSIDY_CONTRACT_MONTHS; + this->remaining = _settings_game.difficulty.subsidy_duration * MONTHS_IN_YEAR; char company_name[MAX_LENGTH_COMPANY_NAME_CHARS * MAX_CHAR_LENGTH]; SetDParam(0, company); @@ -50,7 +50,7 @@ void Subsidy::AwardTo(CompanyID company) char *cn = stredup(company_name); /* Add a news item */ - std::pair reftype = SetupSubsidyDecodeParam(this, false); + std::pair reftype = SetupSubsidyDecodeParam(this, SubsidyDecodeParamType::NewsAwarded); InjectDParam(1); SetDParamStr(0, cn); @@ -69,17 +69,21 @@ void Subsidy::AwardTo(CompanyID company) /** * Setup the string parameters for printing the subsidy at the screen, and compute the news reference for the subsidy. * @param s %Subsidy being printed. - * @param mode Unit of cargo used, \c true means general name, \c false means singular form. + * @param mode Type of subsidy news message to decide on parameter format. * @return Reference of the subsidy in the news system. */ -std::pair SetupSubsidyDecodeParam(const Subsidy *s, bool mode) +std::pair SetupSubsidyDecodeParam(const Subsidy *s, SubsidyDecodeParamType mode) { NewsReferenceType reftype1 = NR_NONE; NewsReferenceType reftype2 = NR_NONE; - /* if mode is false, use the singular form */ + /* Choose whether to use the singular or plural form of the cargo name based on how we're printing the subsidy */ const CargoSpec *cs = CargoSpec::Get(s->cargo_type); - SetDParam(0, mode ? cs->name : cs->name_single); + if (mode == SubsidyDecodeParamType::Gui || mode == SubsidyDecodeParamType::NewsWithdrawn) { + SetDParam(0, cs->name); + } else { + SetDParam(0, cs->name_single); + } switch (s->src_type) { case ST_INDUSTRY: @@ -107,6 +111,11 @@ std::pair SetupSubsidyDecodeParam(const Su } SetDParam(5, s->dst); + /* If the subsidy is being offered or awarded, the news item mentions the subsidy duration. */ + if (mode == SubsidyDecodeParamType::NewsOffered || mode == SubsidyDecodeParamType::NewsAwarded) { + SetDParam(7, _settings_game.difficulty.subsidy_duration); + } + return std::pair(reftype1, reftype2); } @@ -216,7 +225,7 @@ void CreateSubsidy(CargoID cid, SourceType src_type, SourceID src, SourceType ds s->remaining = SUBSIDY_OFFER_MONTHS; s->awarded = INVALID_COMPANY; - std::pair reftype = SetupSubsidyDecodeParam(s, false); + std::pair reftype = SetupSubsidyDecodeParam(s, SubsidyDecodeParamType::NewsOffered); AddNewsItem(STR_NEWS_SERVICE_SUBSIDY_OFFERED, NT_SUBSIDIES, NF_NORMAL, reftype.first, s->src, reftype.second, s->dst); SetPartOfSubsidyFlag(s->src_type, s->src, POS_SRC); SetPartOfSubsidyFlag(s->dst_type, s->dst, POS_DST); @@ -491,13 +500,13 @@ void SubsidyMonthlyLoop() for (Subsidy *s : Subsidy::Iterate()) { if (--s->remaining == 0) { if (!s->IsAwarded()) { - std::pair reftype = SetupSubsidyDecodeParam(s, true); + std::pair reftype = SetupSubsidyDecodeParam(s, SubsidyDecodeParamType::NewsWithdrawn); AddNewsItem(STR_NEWS_OFFER_OF_SUBSIDY_EXPIRED, NT_SUBSIDIES, NF_NORMAL, reftype.first, s->src, reftype.second, s->dst); AI::BroadcastNewEvent(new ScriptEventSubsidyOfferExpired(s->index)); Game::NewEvent(new ScriptEventSubsidyOfferExpired(s->index)); } else { if (s->awarded == _local_company) { - std::pair reftype = SetupSubsidyDecodeParam(s, true); + std::pair reftype = SetupSubsidyDecodeParam(s, SubsidyDecodeParamType::NewsWithdrawn); AddNewsItem(STR_NEWS_SUBSIDY_WITHDRAWN_SERVICE, NT_SUBSIDIES, NF_NORMAL, reftype.first, s->src, reftype.second, s->dst); } AI::BroadcastNewEvent(new ScriptEventSubsidyExpired(s->index)); @@ -510,6 +519,9 @@ void SubsidyMonthlyLoop() if (modified) { RebuildSubsidisedSourceAndDestinationCache(); + } else if (_settings_game.difficulty.subsidy_duration == 0) { + /* If subsidy duration is set to 0, subsidies are disabled, so bail out. */ + return; } else if (_settings_game.linkgraph.distribution_pax != DT_MANUAL && _settings_game.linkgraph.distribution_mail != DT_MANUAL && _settings_game.linkgraph.distribution_armoured != DT_MANUAL && diff --git a/src/subsidy_base.h b/src/subsidy_base.h index ef9276433f..120c5cecef 100644 --- a/src/subsidy_base.h +++ b/src/subsidy_base.h @@ -21,7 +21,7 @@ extern SubsidyPool _subsidy_pool; /** Struct about subsidies, offered and awarded */ struct Subsidy : SubsidyPool::PoolItem<&_subsidy_pool> { CargoID cargo_type; ///< Cargo type involved in this subsidy, CT_INVALID for invalid subsidy - byte remaining; ///< Remaining months when this subsidy is valid + uint16 remaining; ///< Remaining months when this subsidy is valid CompanyID awarded; ///< Subsidy is awarded to this company; INVALID_COMPANY if it's not awarded to anyone SourceType src_type; ///< Source of subsidised path (ST_INDUSTRY or ST_TOWN) SourceType dst_type; ///< Destination of subsidised path (ST_INDUSTRY or ST_TOWN) @@ -52,11 +52,18 @@ struct Subsidy : SubsidyPool::PoolItem<&_subsidy_pool> { /** Constants related to subsidies */ static const uint SUBSIDY_OFFER_MONTHS = 12; ///< Duration of subsidy offer -static const uint SUBSIDY_CONTRACT_MONTHS = 12; ///< Duration of subsidy after awarding static const uint SUBSIDY_PAX_MIN_POPULATION = 400; ///< Min. population of towns for subsidised pax route static const uint SUBSIDY_CARGO_MIN_POPULATION = 900; ///< Min. population of destination town for cargo route static const uint SUBSIDY_MAX_PCT_TRANSPORTED = 42; ///< Subsidy will be created only for towns/industries with less % transported static const uint SUBSIDY_MAX_DISTANCE = 70; ///< Max. length of subsidised route (DistanceManhattan) static const uint SUBSIDY_TOWN_CARGO_RADIUS = 6; ///< Extent of a tile area around town center when scanning for town cargo acceptance and production (6 ~= min catchmement + min station / 2) +/** Types of subsidy news messages, which determine how the date is printed and whether to use singular or plural cargo names */ +enum class SubsidyDecodeParamType { + NewsOffered = 0, ///< News item for an offered subsidy + NewsAwarded = 1, ///< News item for an awarded subsidy + NewsWithdrawn = 2, ///< News item for a subsidy offer withdrawn, or expired subsidy + Gui = 3, ///< Subsidies listed in the Subsidy GUI +}; + #endif /* SUBSIDY_BASE_H */ diff --git a/src/subsidy_func.h b/src/subsidy_func.h index cc63577d33..5cd7a31181 100644 --- a/src/subsidy_func.h +++ b/src/subsidy_func.h @@ -15,8 +15,9 @@ #include "company_type.h" #include "cargo_type.h" #include "news_type.h" +#include "subsidy_base.h" -std::pair SetupSubsidyDecodeParam(const struct Subsidy *s, bool mode); +std::pair SetupSubsidyDecodeParam(const struct Subsidy *s, SubsidyDecodeParamType mode); void DeleteSubsidyWith(SourceType type, SourceID index); bool CheckSubsidised(CargoID cargo_type, CompanyID company, SourceType src_type, SourceID src, const Station *st); void RebuildSubsidisedSourceAndDestinationCache(); diff --git a/src/subsidy_gui.cpp b/src/subsidy_gui.cpp index dde2d432b8..4dc541b36d 100644 --- a/src/subsidy_gui.cpp +++ b/src/subsidy_gui.cpp @@ -158,7 +158,7 @@ struct SubsidyListWindow : Window { if (!s->IsAwarded()) { if (IsInsideMM(pos, 0, cap)) { /* Displays the two offered towns */ - SetupSubsidyDecodeParam(s, true); + SetupSubsidyDecodeParam(s, SubsidyDecodeParamType::Gui); SetDParam(7, _date - _cur_date_ymd.day + s->remaining * 32); DrawString(x, right, y + pos * FONT_HEIGHT_NORMAL, STR_SUBSIDIES_OFFERED_FROM_TO); } @@ -181,7 +181,7 @@ struct SubsidyListWindow : Window { for (const Subsidy *s : Subsidy::Iterate()) { if (s->IsAwarded()) { if (IsInsideMM(pos, 0, cap)) { - SetupSubsidyDecodeParam(s, true); + SetupSubsidyDecodeParam(s, SubsidyDecodeParamType::Gui); SetDParam(7, s->awarded); SetDParam(8, _date - _cur_date_ymd.day + s->remaining * 32); diff --git a/src/table/settings.ini b/src/table/settings.ini index e0d000bb19..41ab17824c 100644 --- a/src/table/settings.ini +++ b/src/table/settings.ini @@ -333,6 +333,20 @@ str = STR_CONFIG_SETTING_SUBSIDY_MULTIPLIER strhelp = STR_CONFIG_SETTING_SUBSIDY_MULTIPLIER_HELPTEXT strval = STR_SUBSIDY_X1_5 +[SDT_VAR] +base = GameSettings +var = difficulty.subsidy_duration +type = SLE_UINT16 +from = SLV_CUSTOM_SUBSIDY_DURATION +guiflags = SGF_0ISDISABLED +def = 1 +min = 0 +max = 5000 +interval = 1 +str = STR_CONFIG_SETTING_SUBSIDY_DURATION +strhelp = STR_CONFIG_SETTING_SUBSIDY_DURATION_HELPTEXT +strval = STR_CONFIG_SETTING_SUBSIDY_DURATION_VALUE + [SDT_VAR] base = GameSettings var = difficulty.construction_cost