summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorsmatz <smatz@openttd.org>2009-07-18 19:54:35 +0000
committersmatz <smatz@openttd.org>2009-07-18 19:54:35 +0000
commitaf13707e0085ff0b273a1f1577c4e1855dedfbe1 (patch)
tree23f18152ec75a44d0ba7074cb092c18979a24c09 /src
parent3fcfb9b248bd228d5885974858a14724205626ad (diff)
downloadopenttd-af13707e0085ff0b273a1f1577c4e1855dedfbe1.tar.xz
(svn r16877) -Codechange: use Subsidy::IsAwarded() instead of testing subsidy's age
Diffstat (limited to 'src')
-rw-r--r--src/ai/api/ai_subsidy.cpp2
-rw-r--r--src/economy.cpp2
-rw-r--r--src/saveload/afterload.cpp2
-rw-r--r--src/subsidy.cpp12
-rw-r--r--src/subsidy_base.h9
-rw-r--r--src/subsidy_gui.cpp12
6 files changed, 24 insertions, 15 deletions
diff --git a/src/ai/api/ai_subsidy.cpp b/src/ai/api/ai_subsidy.cpp
index de7616367..6e43982c3 100644
--- a/src/ai/api/ai_subsidy.cpp
+++ b/src/ai/api/ai_subsidy.cpp
@@ -17,7 +17,7 @@
{
if (!IsValidSubsidy(subsidy_id)) return false;
- return Subsidy::Get(subsidy_id)->age >= 12;
+ return Subsidy::Get(subsidy_id)->IsAwarded();
}
/* static */ AICompany::CompanyID AISubsidy::GetAwardedTo(SubsidyID subsidy_id)
diff --git a/src/economy.cpp b/src/economy.cpp
index 22425bd22..210ff0d49 100644
--- a/src/economy.cpp
+++ b/src/economy.cpp
@@ -329,7 +329,7 @@ void ChangeOwnershipOfCompanyItems(Owner old_owner, Owner new_owner)
if (new_owner == INVALID_OWNER) {
Subsidy *s;
FOR_ALL_SUBSIDIES(s) {
- if (s->age >= 12 && Station::Get(s->to)->owner == old_owner) {
+ if (s->IsAwarded() && Station::Get(s->to)->owner == old_owner) {
s->cargo_type = CT_INVALID;
}
}
diff --git a/src/saveload/afterload.cpp b/src/saveload/afterload.cpp
index 052d3d6e3..5831479cd 100644
--- a/src/saveload/afterload.cpp
+++ b/src/saveload/afterload.cpp
@@ -1887,7 +1887,7 @@ bool AfterLoadGame()
/* Delete invalid subsidies possibly present in old versions (but converted to new savegame) */
Subsidy *s;
FOR_ALL_SUBSIDIES(s) {
- if (s->age >= 12) {
+ if (s->IsAwarded()) {
/* Station -> Station */
const Station *from = Station::GetIfValid(s->from);
const Station *to = Station::GetIfValid(s->to);
diff --git a/src/subsidy.cpp b/src/subsidy.cpp
index f37e92232..158622a09 100644
--- a/src/subsidy.cpp
+++ b/src/subsidy.cpp
@@ -60,7 +60,7 @@ Pair SetupSubsidyDecodeParam(const Subsidy *s, bool mode)
const CargoSpec *cs = CargoSpec::Get(s->cargo_type);
SetDParam(0, mode ? cs->name : cs->name_single);
- if (s->age < 12) {
+ if (!s->IsAwarded()) {
if (cs->town_effect != TE_PASSENGERS && cs->town_effect != TE_MAIL) {
SetDParam(1, STR_INDUSTRY);
SetDParam(2, s->from);
@@ -102,7 +102,7 @@ void DeleteSubsidyWithTown(TownID index)
{
Subsidy *s;
FOR_ALL_SUBSIDIES(s) {
- if (s->age < 12) {
+ if (!s->IsAwarded()) {
const CargoSpec *cs = CargoSpec::Get(s->cargo_type);
if (((cs->town_effect == TE_PASSENGERS || cs->town_effect == TE_MAIL) && (index == s->from || index == s->to)) ||
((cs->town_effect == TE_GOODS || cs->town_effect == TE_FOOD) && index == s->to)) {
@@ -116,7 +116,7 @@ void DeleteSubsidyWithIndustry(IndustryID index)
{
Subsidy *s;
FOR_ALL_SUBSIDIES(s) {
- if (s->age < 12) {
+ if (!s->IsAwarded()) {
const CargoSpec *cs = CargoSpec::Get(s->cargo_type);
if (cs->town_effect != TE_PASSENGERS && cs->town_effect != TE_MAIL &&
(index == s->from || (cs->town_effect != TE_GOODS && cs->town_effect != TE_FOOD && index == s->to))) {
@@ -132,7 +132,7 @@ void DeleteSubsidyWithStation(StationID index)
Subsidy *s;
FOR_ALL_SUBSIDIES(s) {
- if (s->age >= 12 && (s->from == index || s->to == index)) {
+ if (s->IsAwarded() && (s->from == index || s->to == index)) {
s->cargo_type = CT_INVALID;
dirty = true;
}
@@ -315,7 +315,7 @@ bool CheckSubsidised(const Station *from, const Station *to, CargoID cargo_type,
/* check if there is an already existing subsidy that applies to us */
FOR_ALL_SUBSIDIES(s) {
if (s->cargo_type == cargo_type &&
- s->age >= 12 &&
+ s->IsAwarded() &&
s->from == from->index &&
s->to == to->index) {
return true;
@@ -324,7 +324,7 @@ bool CheckSubsidised(const Station *from, const Station *to, CargoID cargo_type,
/* check if there's a new subsidy that applies.. */
FOR_ALL_SUBSIDIES(s) {
- if (s->cargo_type == cargo_type && s->age < 12) {
+ if (s->cargo_type == cargo_type && !s->IsAwarded()) {
/* Check distance from source */
const CargoSpec *cs = CargoSpec::Get(cargo_type);
if (cs->town_effect == TE_PASSENGERS || cs->town_effect == TE_MAIL) {
diff --git a/src/subsidy_base.h b/src/subsidy_base.h
index aaba0fea5..adb03f83b 100644
--- a/src/subsidy_base.h
+++ b/src/subsidy_base.h
@@ -18,6 +18,15 @@ struct Subsidy {
uint16 to; ///< Index of destination. Either TownID, IndustryID or StationID, when awarded
/**
+ * Tests whether this subsidy has been awarded to someone
+ * @return is this subsidy awarded?
+ */
+ FORCEINLINE bool IsAwarded() const
+ {
+ return this->age >= 12;
+ }
+
+ /**
* Determines index of this subsidy
* @return index (in the Subsidy::array array)
*/
diff --git a/src/subsidy_gui.cpp b/src/subsidy_gui.cpp
index 392ec2095..3b24625b9 100644
--- a/src/subsidy_gui.cpp
+++ b/src/subsidy_gui.cpp
@@ -47,7 +47,7 @@ struct SubsidyListWindow : Window {
const Subsidy *s;
FOR_ALL_SUBSIDIES(s) {
- if (s->age < 12) {
+ if (!s->IsAwarded()) {
y -= FONT_HEIGHT_NORMAL;
if (y < 0) {
this->HandleClick(s);
@@ -66,7 +66,7 @@ struct SubsidyListWindow : Window {
if (y < 0) return;
FOR_ALL_SUBSIDIES(s) {
- if (s->age >= 12) {
+ if (s->IsAwarded()) {
y -= FONT_HEIGHT_NORMAL;
if (y < 0) {
this->HandleClick(s);
@@ -83,7 +83,7 @@ struct SubsidyListWindow : Window {
/* determine from coordinate for subsidy and try to scroll to it */
uint offs = s->from;
- if (s->age >= 12) {
+ if (s->IsAwarded()) {
xy = Station::Get(offs)->xy;
} else if (te == TE_PASSENGERS || te == TE_MAIL) {
xy = Town::Get(offs)->xy;
@@ -96,7 +96,7 @@ struct SubsidyListWindow : Window {
/* otherwise determine to coordinate for subsidy and scroll to it */
offs = s->to;
- if (s->age >= 12) {
+ if (s->IsAwarded()) {
xy = Station::Get(offs)->xy;
} else if (te == TE_PASSENGERS || te == TE_MAIL || te == TE_GOODS || te == TE_FOOD) {
xy = Town::Get(offs)->xy;
@@ -131,7 +131,7 @@ struct SubsidyListWindow : Window {
uint num = 0;
FOR_ALL_SUBSIDIES(s) {
- if (s->age < 12) {
+ if (!s->IsAwarded()) {
/* Displays the two offered towns */
SetupSubsidyDecodeParam(s, 1);
SetDParam(7, _date - ymd.day + 384 - s->age * 32);
@@ -153,7 +153,7 @@ struct SubsidyListWindow : Window {
num = 0;
FOR_ALL_SUBSIDIES(s) {
- if (s->age >= 12) {
+ if (s->IsAwarded()) {
SetupSubsidyDecodeParam(s, 1);
SetDParam(3, Station::Get(s->to)->owner);
SetDParam(4, _date - ymd.day + 768 - s->age * 32);