summaryrefslogtreecommitdiff
path: root/src/subsidy.cpp
diff options
context:
space:
mode:
authorsmatz <smatz@openttd.org>2009-08-07 20:24:33 +0000
committersmatz <smatz@openttd.org>2009-08-07 20:24:33 +0000
commit3532592e7d026fb077f584946e48010e4a5b65a1 (patch)
tree4c8a5a0f9d938fac1f32c56a28f8ef3cd9d1974a /src/subsidy.cpp
parentc2a3e28d9dfdca865749dd979464f589364446b7 (diff)
downloadopenttd-3532592e7d026fb077f584946e48010e4a5b65a1.tar.xz
(svn r17104) -Codechange: move code related to subsidy awarding to separate procedure
Diffstat (limited to 'src/subsidy.cpp')
-rw-r--r--src/subsidy.cpp59
1 files changed, 36 insertions, 23 deletions
diff --git a/src/subsidy.cpp b/src/subsidy.cpp
index 04f0df118..1d183cc9a 100644
--- a/src/subsidy.cpp
+++ b/src/subsidy.cpp
@@ -14,12 +14,47 @@
#include "strings_func.h"
#include "window_func.h"
#include "subsidy_base.h"
+#include "subsidy_func.h"
#include "table/strings.h"
/* static */ Subsidy Subsidy::array[MAX_COMPANIES];
/**
+ * Marks subsidy as awarded, creates news and AI event
+ * @param from source station
+ * @param to destination station
+ * @param company awarded company
+ */
+void Subsidy::AwardTo(StationID from, StationID to, CompanyID company)
+{
+ assert(!this->IsAwarded());
+
+ this->age = 12;
+ this->from = from;
+ this->to = to;
+
+ /* Add a news item */
+ Pair reftype = SetupSubsidyDecodeParam(this, 0);
+ InjectDParam(1);
+
+ char *company_name = MallocT<char>(MAX_LENGTH_COMPANY_NAME_BYTES);
+ SetDParam(0, company);
+ GetString(company_name, STR_COMPANY_NAME, company_name + MAX_LENGTH_COMPANY_NAME_BYTES - 1);
+
+ SetDParamStr(0, company_name);
+ AddNewsItem(
+ STR_NEWS_SERVICE_SUBSIDY_AWARDED_HALF + _settings_game.difficulty.subsidy_multiplier,
+ NS_SUBSIDIES,
+ (NewsReferenceType)reftype.a, this->from, (NewsReferenceType)reftype.b, this->to,
+ company_name
+ );
+ AI::BroadcastNewEvent(new AIEventSubsidyAwarded(this->Index()));
+
+ InvalidateWindow(WC_SUBSIDIES_LIST, 0);
+}
+
+/**
* Allocates one subsidy
* @return pointer to first invalid subsidy, NULL if there is none
*/
@@ -349,29 +384,7 @@ bool CheckSubsidised(const Station *from, const Station *to, CargoID cargo_type,
}
if (DistanceMax(xy, to->xy) > 9) continue;
- /* Found a subsidy, change the values to indicate that it's in use */
- s->age = 12;
- s->from = from->index;
- s->to = to->index;
-
- /* Add a news item */
- Pair reftype = SetupSubsidyDecodeParam(s, 0);
- InjectDParam(1);
-
- char *company_name = MallocT<char>(MAX_LENGTH_COMPANY_NAME_BYTES);
- SetDParam(0, company);
- GetString(company_name, STR_COMPANY_NAME, company_name + MAX_LENGTH_COMPANY_NAME_BYTES - 1);
-
- SetDParamStr(0, company_name);
- AddNewsItem(
- STR_NEWS_SERVICE_SUBSIDY_AWARDED_HALF + _settings_game.difficulty.subsidy_multiplier,
- NS_SUBSIDIES,
- (NewsReferenceType)reftype.a, s->from, (NewsReferenceType)reftype.b, s->to,
- company_name
- );
- AI::BroadcastNewEvent(new AIEventSubsidyAwarded(s->Index()));
-
- InvalidateWindow(WC_SUBSIDIES_LIST, 0);
+ s->AwardTo(from->index, to->index, company);
return true;
}
}