mirror of https://github.com/OpenTTD/OpenTTD.git
(svn r16711) -Codechange: use FOR_ALL_SUBSIDIES macro when iterating over all subsidies
This commit is contained in:
parent
023f78b5ff
commit
f4d0d94184
|
@ -8,7 +8,8 @@
|
||||||
|
|
||||||
AISubsidyList::AISubsidyList()
|
AISubsidyList::AISubsidyList()
|
||||||
{
|
{
|
||||||
for (uint i = 0; i < lengthof(_subsidies); i++) {
|
const Subsidy *s;
|
||||||
if (AISubsidy::IsValidSubsidy(i)) this->AddItem(i);
|
FOR_ALL_SUBSIDIES(s) {
|
||||||
|
this->AddItem(s - _subsidies);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -327,10 +327,9 @@ void ChangeOwnershipOfCompanyItems(Owner old_owner, Owner new_owner)
|
||||||
|
|
||||||
if (new_owner == INVALID_OWNER) {
|
if (new_owner == INVALID_OWNER) {
|
||||||
Subsidy *s;
|
Subsidy *s;
|
||||||
|
FOR_ALL_SUBSIDIES(s) {
|
||||||
for (s = _subsidies; s != endof(_subsidies); s++) {
|
if (s->age >= 12 && Station::Get(s->to)->owner == old_owner) {
|
||||||
if (s->cargo_type != CT_INVALID && s->age >= 12) {
|
s->cargo_type = CT_INVALID;
|
||||||
if (Station::Get(s->to)->owner == old_owner) s->cargo_type = CT_INVALID;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1916,8 +1916,8 @@ bool AfterLoadGame()
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Delete invalid subsidies possibly present in old versions (but converted to new savegame) */
|
/* Delete invalid subsidies possibly present in old versions (but converted to new savegame) */
|
||||||
for (Subsidy *s = _subsidies; s < endof(_subsidies); s++) {
|
Subsidy *s;
|
||||||
if (s->cargo_type == CT_INVALID) continue;
|
FOR_ALL_SUBSIDIES(s) {
|
||||||
if (s->age >= 12) {
|
if (s->age >= 12) {
|
||||||
/* Station -> Station */
|
/* Station -> Station */
|
||||||
const Station *from = Station::GetIfValid(s->from);
|
const Station *from = Station::GetIfValid(s->from);
|
||||||
|
|
|
@ -19,15 +19,10 @@ static const SaveLoad _subsidies_desc[] = {
|
||||||
|
|
||||||
void Save_SUBS()
|
void Save_SUBS()
|
||||||
{
|
{
|
||||||
int i;
|
|
||||||
Subsidy *s;
|
Subsidy *s;
|
||||||
|
FOR_ALL_SUBSIDIES(s) {
|
||||||
for (i = 0; i != lengthof(_subsidies); i++) {
|
SlSetArrayIndex(s - _subsidies);
|
||||||
s = &_subsidies[i];
|
SlObject(s, _subsidies_desc);
|
||||||
if (s->cargo_type != CT_INVALID) {
|
|
||||||
SlSetArrayIndex(i);
|
|
||||||
SlObject(s, _subsidies_desc);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -69,9 +69,8 @@ Pair SetupSubsidyDecodeParam(const Subsidy *s, bool mode)
|
||||||
void DeleteSubsidyWithTown(TownID index)
|
void DeleteSubsidyWithTown(TownID index)
|
||||||
{
|
{
|
||||||
Subsidy *s;
|
Subsidy *s;
|
||||||
|
FOR_ALL_SUBSIDIES(s) {
|
||||||
for (s = _subsidies; s != endof(_subsidies); s++) {
|
if (s->age < 12) {
|
||||||
if (s->cargo_type != CT_INVALID && s->age < 12) {
|
|
||||||
const CargoSpec *cs = GetCargo(s->cargo_type);
|
const CargoSpec *cs = GetCargo(s->cargo_type);
|
||||||
if (((cs->town_effect == TE_PASSENGERS || cs->town_effect == TE_MAIL) && (index == s->from || index == s->to)) ||
|
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)) {
|
((cs->town_effect == TE_GOODS || cs->town_effect == TE_FOOD) && index == s->to)) {
|
||||||
|
@ -84,9 +83,8 @@ void DeleteSubsidyWithTown(TownID index)
|
||||||
void DeleteSubsidyWithIndustry(IndustryID index)
|
void DeleteSubsidyWithIndustry(IndustryID index)
|
||||||
{
|
{
|
||||||
Subsidy *s;
|
Subsidy *s;
|
||||||
|
FOR_ALL_SUBSIDIES(s) {
|
||||||
for (s = _subsidies; s != endof(_subsidies); s++) {
|
if (s->age < 12) {
|
||||||
if (s->cargo_type != CT_INVALID && s->age < 12) {
|
|
||||||
const CargoSpec *cs = GetCargo(s->cargo_type);
|
const CargoSpec *cs = GetCargo(s->cargo_type);
|
||||||
if (cs->town_effect != TE_PASSENGERS && cs->town_effect != TE_MAIL &&
|
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))) {
|
(index == s->from || (cs->town_effect != TE_GOODS && cs->town_effect != TE_FOOD && index == s->to))) {
|
||||||
|
@ -98,12 +96,11 @@ void DeleteSubsidyWithIndustry(IndustryID index)
|
||||||
|
|
||||||
void DeleteSubsidyWithStation(StationID index)
|
void DeleteSubsidyWithStation(StationID index)
|
||||||
{
|
{
|
||||||
Subsidy *s;
|
|
||||||
bool dirty = false;
|
bool dirty = false;
|
||||||
|
|
||||||
for (s = _subsidies; s != endof(_subsidies); s++) {
|
Subsidy *s;
|
||||||
if (s->cargo_type != CT_INVALID && s->age >= 12 &&
|
FOR_ALL_SUBSIDIES(s) {
|
||||||
(s->from == index || s->to == index)) {
|
if (s->age >= 12 && (s->from == index || s->to == index)) {
|
||||||
s->cargo_type = CT_INVALID;
|
s->cargo_type = CT_INVALID;
|
||||||
dirty = true;
|
dirty = true;
|
||||||
}
|
}
|
||||||
|
@ -196,8 +193,7 @@ static void FindSubsidyCargoRoute(FoundRoute *fr)
|
||||||
static bool CheckSubsidyDuplicate(Subsidy *s)
|
static bool CheckSubsidyDuplicate(Subsidy *s)
|
||||||
{
|
{
|
||||||
const Subsidy *ss;
|
const Subsidy *ss;
|
||||||
|
FOR_ALL_SUBSIDIES(ss) {
|
||||||
for (ss = _subsidies; ss != endof(_subsidies); ss++) {
|
|
||||||
if (s != ss &&
|
if (s != ss &&
|
||||||
ss->from == s->from &&
|
ss->from == s->from &&
|
||||||
ss->to == s->to &&
|
ss->to == s->to &&
|
||||||
|
@ -212,15 +208,13 @@ static bool CheckSubsidyDuplicate(Subsidy *s)
|
||||||
|
|
||||||
void SubsidyMonthlyLoop()
|
void SubsidyMonthlyLoop()
|
||||||
{
|
{
|
||||||
Subsidy *s;
|
|
||||||
Station *st;
|
Station *st;
|
||||||
uint n;
|
uint n;
|
||||||
FoundRoute fr;
|
FoundRoute fr;
|
||||||
bool modified = false;
|
bool modified = false;
|
||||||
|
|
||||||
for (s = _subsidies; s != endof(_subsidies); s++) {
|
Subsidy *s;
|
||||||
if (s->cargo_type == CT_INVALID) continue;
|
FOR_ALL_SUBSIDIES(s) {
|
||||||
|
|
||||||
if (s->age == 12 - 1) {
|
if (s->age == 12 - 1) {
|
||||||
Pair reftype = SetupSubsidyDecodeParam(s, 1);
|
Pair reftype = SetupSubsidyDecodeParam(s, 1);
|
||||||
AddNewsItem(STR_NEWS_OFFER_OF_SUBSIDY_EXPIRED, NS_SUBSIDIES, (NewsReferenceType)reftype.a, s->from, (NewsReferenceType)reftype.b, s->to);
|
AddNewsItem(STR_NEWS_OFFER_OF_SUBSIDY_EXPIRED, NS_SUBSIDIES, (NewsReferenceType)reftype.a, s->from, (NewsReferenceType)reftype.b, s->to);
|
||||||
|
@ -290,7 +284,7 @@ bool CheckSubsidised(const Station *from, const Station *to, CargoID cargo_type,
|
||||||
TileIndex xy;
|
TileIndex xy;
|
||||||
|
|
||||||
/* check if there is an already existing subsidy that applies to us */
|
/* check if there is an already existing subsidy that applies to us */
|
||||||
for (s = _subsidies; s != endof(_subsidies); s++) {
|
FOR_ALL_SUBSIDIES(s) {
|
||||||
if (s->cargo_type == cargo_type &&
|
if (s->cargo_type == cargo_type &&
|
||||||
s->age >= 12 &&
|
s->age >= 12 &&
|
||||||
s->from == from->index &&
|
s->from == from->index &&
|
||||||
|
@ -300,7 +294,7 @@ bool CheckSubsidised(const Station *from, const Station *to, CargoID cargo_type,
|
||||||
}
|
}
|
||||||
|
|
||||||
/* check if there's a new subsidy that applies.. */
|
/* check if there's a new subsidy that applies.. */
|
||||||
for (s = _subsidies; s != endof(_subsidies); s++) {
|
FOR_ALL_SUBSIDIES(s) {
|
||||||
if (s->cargo_type == cargo_type && s->age < 12) {
|
if (s->cargo_type == cargo_type && s->age < 12) {
|
||||||
/* Check distance from source */
|
/* Check distance from source */
|
||||||
const CargoSpec *cs = GetCargo(cargo_type);
|
const CargoSpec *cs = GetCargo(cargo_type);
|
||||||
|
|
|
@ -43,8 +43,10 @@ struct SubsidyListWindow : Window {
|
||||||
if (y < 0) return;
|
if (y < 0) return;
|
||||||
|
|
||||||
uint num = 0;
|
uint num = 0;
|
||||||
for (const Subsidy *s = _subsidies; s != endof(_subsidies); s++) {
|
|
||||||
if (s->cargo_type != CT_INVALID && s->age < 12) {
|
const Subsidy *s;
|
||||||
|
FOR_ALL_SUBSIDIES(s) {
|
||||||
|
if (s->age < 12) {
|
||||||
y -= FONT_HEIGHT_NORMAL;
|
y -= FONT_HEIGHT_NORMAL;
|
||||||
if (y < 0) {
|
if (y < 0) {
|
||||||
this->HandleClick(s);
|
this->HandleClick(s);
|
||||||
|
@ -62,8 +64,8 @@ struct SubsidyListWindow : Window {
|
||||||
y -= 11; // "Services already subsidised:"
|
y -= 11; // "Services already subsidised:"
|
||||||
if (y < 0) return;
|
if (y < 0) return;
|
||||||
|
|
||||||
for (const Subsidy *s = _subsidies; s != endof(_subsidies); s++) {
|
FOR_ALL_SUBSIDIES(s) {
|
||||||
if (s->cargo_type != CT_INVALID && s->age >= 12) {
|
if (s->age >= 12) {
|
||||||
y -= FONT_HEIGHT_NORMAL;
|
y -= FONT_HEIGHT_NORMAL;
|
||||||
if (y < 0) {
|
if (y < 0) {
|
||||||
this->HandleClick(s);
|
this->HandleClick(s);
|
||||||
|
@ -127,8 +129,8 @@ struct SubsidyListWindow : Window {
|
||||||
y += FONT_HEIGHT_NORMAL;
|
y += FONT_HEIGHT_NORMAL;
|
||||||
uint num = 0;
|
uint num = 0;
|
||||||
|
|
||||||
for (s = _subsidies; s != endof(_subsidies); s++) {
|
FOR_ALL_SUBSIDIES(s) {
|
||||||
if (s->cargo_type != CT_INVALID && s->age < 12) {
|
if (s->age < 12) {
|
||||||
/* Displays the two offered towns */
|
/* Displays the two offered towns */
|
||||||
SetupSubsidyDecodeParam(s, 1);
|
SetupSubsidyDecodeParam(s, 1);
|
||||||
SetDParam(7, _date - ymd.day + 384 - s->age * 32);
|
SetDParam(7, _date - ymd.day + 384 - s->age * 32);
|
||||||
|
@ -149,8 +151,8 @@ struct SubsidyListWindow : Window {
|
||||||
y += FONT_HEIGHT_NORMAL;
|
y += FONT_HEIGHT_NORMAL;
|
||||||
num = 0;
|
num = 0;
|
||||||
|
|
||||||
for (s = _subsidies; s != endof(_subsidies); s++) {
|
FOR_ALL_SUBSIDIES(s) {
|
||||||
if (s->cargo_type != CT_INVALID && s->age >= 12) {
|
if (s->age >= 12) {
|
||||||
SetupSubsidyDecodeParam(s, 1);
|
SetupSubsidyDecodeParam(s, 1);
|
||||||
SetDParam(3, Station::Get(s->to)->owner);
|
SetDParam(3, Station::Get(s->to)->owner);
|
||||||
SetDParam(4, _date - ymd.day + 768 - s->age * 32);
|
SetDParam(4, _date - ymd.day + 768 - s->age * 32);
|
||||||
|
|
|
@ -18,4 +18,8 @@ struct Subsidy {
|
||||||
|
|
||||||
extern Subsidy _subsidies[MAX_COMPANIES];
|
extern Subsidy _subsidies[MAX_COMPANIES];
|
||||||
|
|
||||||
|
#define FOR_ALL_SUBSIDIES_FROM(var, start) for (var = &_subsidies[start]; var < endof(_subsidies); var++) \
|
||||||
|
if (var->cargo_type != CT_INVALID)
|
||||||
|
#define FOR_ALL_SUBSIDIES(var) FOR_ALL_SUBSIDIES_FROM(var, 0)
|
||||||
|
|
||||||
#endif /* SUBSIDY_TYPE_H */
|
#endif /* SUBSIDY_TYPE_H */
|
||||||
|
|
Loading…
Reference in New Issue