summaryrefslogtreecommitdiff
path: root/src/subsidy.cpp
diff options
context:
space:
mode:
authorTyler Trahan <tyler@tylertrahan.com>2021-04-22 13:54:32 -0400
committerMichael Lutz <michi@icosahedron.de>2021-06-10 23:26:16 +0200
commitd09210e1c6a446ec5a97de4e171aa101d047765a (patch)
treed45a31e2b65f3399888e14524b805b15ef94a90f /src/subsidy.cpp
parentc2db408d5d947cd4f3df42754a598226818c519f (diff)
downloadopenttd-d09210e1c6a446ec5a97de4e171aa101d047765a.tar.xz
Feature: Configurable subsidy duration
Diffstat (limited to 'src/subsidy.cpp')
-rw-r--r--src/subsidy.cpp30
1 files changed, 21 insertions, 9 deletions
diff --git a/src/subsidy.cpp b/src/subsidy.cpp
index 14679e4dc..8800da1bd 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<NewsReferenceType, NewsReferenceType> reftype = SetupSubsidyDecodeParam(this, false);
+ std::pair<NewsReferenceType, NewsReferenceType> 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<NewsReferenceType, NewsReferenceType> SetupSubsidyDecodeParam(const Subsidy *s, bool mode)
+std::pair<NewsReferenceType, NewsReferenceType> 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<NewsReferenceType, NewsReferenceType> 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<NewsReferenceType, NewsReferenceType>(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<NewsReferenceType, NewsReferenceType> reftype = SetupSubsidyDecodeParam(s, false);
+ std::pair<NewsReferenceType, NewsReferenceType> 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<NewsReferenceType, NewsReferenceType> reftype = SetupSubsidyDecodeParam(s, true);
+ std::pair<NewsReferenceType, NewsReferenceType> 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<NewsReferenceType, NewsReferenceType> reftype = SetupSubsidyDecodeParam(s, true);
+ std::pair<NewsReferenceType, NewsReferenceType> 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 &&