(svn r16877) -Codechange: use Subsidy::IsAwarded() instead of testing subsidy's age

This commit is contained in:
smatz 2009-07-18 19:54:35 +00:00
parent 3fcfb9b248
commit af13707e00
6 changed files with 24 additions and 15 deletions

View File

@ -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)

View File

@ -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;
}
}

View File

@ -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);

View File

@ -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) {

View File

@ -17,6 +17,15 @@ struct Subsidy {
uint16 from; ///< Index of source. Either TownID, IndustryID or StationID, when awarded
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)

View File

@ -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);