summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorsmatz <smatz@openttd.org>2009-08-08 18:26:25 +0000
committersmatz <smatz@openttd.org>2009-08-08 18:26:25 +0000
commit046be0a1992690e8d2c1369138fcf63eb25548ec (patch)
treed11829f4c6472e88b239b6d6e86e43ed9c749df9 /src
parent134c5f3f9acaaad189f0f0dbd9917d319618d4ea (diff)
downloadopenttd-046be0a1992690e8d2c1369138fcf63eb25548ec.tar.xz
(svn r17119) -Codechange: replace constants in subsidy.cpp by enum values
Diffstat (limited to 'src')
-rw-r--r--src/saveload/afterload.cpp2
-rw-r--r--src/subsidy.cpp19
-rw-r--r--src/subsidy_base.h10
3 files changed, 22 insertions, 9 deletions
diff --git a/src/saveload/afterload.cpp b/src/saveload/afterload.cpp
index 0331feed7..8427c7d8e 100644
--- a/src/saveload/afterload.cpp
+++ b/src/saveload/afterload.cpp
@@ -1875,7 +1875,7 @@ bool AfterLoadGame()
Subsidy *s;
FOR_ALL_SUBSIDIES(s) {
/* Convert only nonawarded subsidies. The original source and destination town/industry
- * anymore for awarded subsidies, so invalidate them. */
+ * can't be determined anymore for awarded subsidies, so invalidate them. */
if (s->remaining < 12) {
s->remaining = 12 - s->remaining; // convert "age" to "remaining"
s->awarded = INVALID_COMPANY; // not awarded to anyone
diff --git a/src/subsidy.cpp b/src/subsidy.cpp
index 44431210a..03ab75926 100644
--- a/src/subsidy.cpp
+++ b/src/subsidy.cpp
@@ -29,7 +29,7 @@ void Subsidy::AwardTo(CompanyID company)
assert(!this->IsAwarded());
this->awarded = company;
- this->remaining = 12;
+ this->remaining = SUBSIDY_CONTRACT_MONTHS;
char *company_name = MallocT<char>(MAX_LENGTH_COMPANY_NAME_BYTES);
SetDParam(0, company);
@@ -192,10 +192,13 @@ static void FindSubsidyPassengerRoute(FoundRoute *fr)
fr->distance = UINT_MAX;
fr->from = from = Town::GetRandom();
- if (from == NULL || from->population < 400 || from->pct_pass_transported > 42) return;
+ if (from == NULL || from->population < SUBSIDY_PAX_MIN_POPULATION ||
+ from->pct_pass_transported > SUBSIDY_MAX_PCT_TRANSPORTED) {
+ return;
+ }
fr->to = to = Town::GetRandom();
- if (from == to || to == NULL || to->population < 400) return;
+ if (from == to || to == NULL || to->population < SUBSIDY_PAX_MIN_POPULATION) return;
fr->distance = DistanceManhattan(from->xy, to->xy);
}
@@ -225,7 +228,7 @@ static void FindSubsidyCargoRoute(FoundRoute *fr)
/* Quit if no production in this industry
* or if the cargo type is passengers
* or if the pct transported is already large enough */
- if (total == 0 || trans > 42 || cargo == CT_INVALID) return;
+ if (total == 0 || trans > SUBSIDY_MAX_PCT_TRANSPORTED || cargo == CT_INVALID) return;
const CargoSpec *cs = CargoSpec::Get(cargo);
if (cs->town_effect == TE_PASSENGERS) return;
@@ -237,7 +240,7 @@ static void FindSubsidyCargoRoute(FoundRoute *fr)
Town *t = Town::GetRandom();
/* Only want big towns */
- if (t == NULL || t->population < 900) return;
+ if (t == NULL || t->population < SUBSIDY_CARGO_MIN_POPULATION) return;
fr->distance = DistanceManhattan(i->xy, t->xy);
fr->to = t;
@@ -305,7 +308,7 @@ void SubsidyMonthlyLoop()
do {
FoundRoute fr;
FindSubsidyPassengerRoute(&fr);
- if (fr.distance <= 70) {
+ if (fr.distance <= SUBSIDY_MAX_DISTANCE) {
s->cargo_type = CT_PASSENGERS;
s->src_type = s->dst_type = ST_TOWN;
s->src = ((Town *)fr.from)->index;
@@ -313,7 +316,7 @@ void SubsidyMonthlyLoop()
goto add_subsidy;
}
FindSubsidyCargoRoute(&fr);
- if (fr.distance <= 70) {
+ if (fr.distance <= SUBSIDY_MAX_DISTANCE) {
s->cargo_type = fr.cargo;
s->src_type = ST_INDUSTRY;
s->src = ((Industry *)fr.from)->index;
@@ -329,7 +332,7 @@ void SubsidyMonthlyLoop()
}
add_subsidy:
if (!CheckSubsidyDuplicate(s)) {
- s->remaining = 12;
+ s->remaining = SUBSIDY_OFFER_MONTHS;
Pair reftype = SetupSubsidyDecodeParam(s, 0);
AddNewsItem(STR_NEWS_SERVICE_SUBSIDY_OFFERED, NS_SUBSIDIES, (NewsReferenceType)reftype.a, s->src, (NewsReferenceType)reftype.b, s->dst);
SetPartOfSubsidyFlag(s->src_type, s->src, POS_SRC);
diff --git a/src/subsidy_base.h b/src/subsidy_base.h
index 4750605bc..4367334cb 100644
--- a/src/subsidy_base.h
+++ b/src/subsidy_base.h
@@ -85,6 +85,16 @@ struct Subsidy {
static void Clean();
};
+/** Constants related to subsidies */
+enum {
+ SUBSIDY_OFFER_MONTHS = 12, ///< Duration of subsidy offer
+ SUBSIDY_CONTRACT_MONTHS = 12, ///< Duration of subsidy after awarding
+ SUBSIDY_PAX_MIN_POPULATION = 400, ///< Min. population of towns for subsidised pax route
+ SUBSIDY_CARGO_MIN_POPULATION = 900, ///< Min. population of destination town for cargo route
+ SUBSIDY_MAX_PCT_TRANSPORTED = 42, ///< Subsidy will be created only for towns/industries with less % transported
+ SUBSIDY_MAX_DISTANCE = 70, ///< Max. length of subsidised route (DistanceManhattan)
+};
+
#define FOR_ALL_SUBSIDIES_FROM(var, start) for (size_t subsidy_index = start; var = NULL, subsidy_index < Subsidy::GetArraySize(); subsidy_index++) \
if ((var = Subsidy::Get(subsidy_index))->IsValid())
#define FOR_ALL_SUBSIDIES(var) FOR_ALL_SUBSIDIES_FROM(var, 0)