Mercurial > hg > openttd
changeset 12443:575fb5207d86 draft
(svn r16877) -Codechange: use Subsidy::IsAwarded() instead of testing subsidy's age
author | smatz <smatz@openttd.org> |
---|---|
date | Sat, 18 Jul 2009 19:54:35 +0000 |
parents | 3cad0460973f |
children | a75f797c6017 |
files | src/ai/api/ai_subsidy.cpp src/economy.cpp src/saveload/afterload.cpp src/subsidy.cpp src/subsidy_base.h src/subsidy_gui.cpp |
diffstat | 6 files changed, 24 insertions(+), 15 deletions(-) [+] |
line wrap: on
line diff
--- 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)
--- a/src/economy.cpp +++ b/src/economy.cpp @@ -329,7 +329,7 @@ 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; } }
--- a/src/saveload/afterload.cpp +++ b/src/saveload/afterload.cpp @@ -1887,7 +1887,7 @@ /* 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);
--- a/src/subsidy.cpp +++ b/src/subsidy.cpp @@ -60,7 +60,7 @@ 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 @@ { 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 @@ { 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 @@ 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 @@ /* 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 @@ /* 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) {
--- a/src/subsidy_base.h +++ b/src/subsidy_base.h @@ -18,6 +18,15 @@ 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) */
--- a/src/subsidy_gui.cpp +++ b/src/subsidy_gui.cpp @@ -47,7 +47,7 @@ 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 @@ 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 @@ /* 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 @@ /* 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 @@ 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 @@ 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);