mirror of https://github.com/OpenTTD/OpenTTD.git
Codechange: Replace FOR_ALL_SUBSIDIES with range-based for loops
This commit is contained in:
parent
847e5f33d4
commit
0b489f9924
|
@ -345,8 +345,7 @@ void ChangeOwnershipOfCompanyItems(Owner old_owner, Owner new_owner)
|
||||||
Company::Get(old_owner)->money = UINT64_MAX >> 2; // jackpot ;p
|
Company::Get(old_owner)->money = UINT64_MAX >> 2; // jackpot ;p
|
||||||
}
|
}
|
||||||
|
|
||||||
Subsidy *s;
|
for (Subsidy *s : Subsidy::Iterate()) {
|
||||||
FOR_ALL_SUBSIDIES(s) {
|
|
||||||
if (s->awarded == old_owner) {
|
if (s->awarded == old_owner) {
|
||||||
if (new_owner == INVALID_OWNER) {
|
if (new_owner == INVALID_OWNER) {
|
||||||
delete s;
|
delete s;
|
||||||
|
|
|
@ -2219,8 +2219,7 @@ bool AfterLoadGame()
|
||||||
|
|
||||||
if (IsSavegameVersionBefore(SLV_125)) {
|
if (IsSavegameVersionBefore(SLV_125)) {
|
||||||
/* Convert old subsidies */
|
/* Convert old subsidies */
|
||||||
Subsidy *s;
|
for (Subsidy *s : Subsidy::Iterate()) {
|
||||||
FOR_ALL_SUBSIDIES(s) {
|
|
||||||
if (s->remaining < 12) {
|
if (s->remaining < 12) {
|
||||||
/* Converting nonawarded subsidy */
|
/* Converting nonawarded subsidy */
|
||||||
s->remaining = 12 - s->remaining; // convert "age" to "remaining"
|
s->remaining = 12 - s->remaining; // convert "age" to "remaining"
|
||||||
|
|
|
@ -29,8 +29,7 @@ static const SaveLoad _subsidies_desc[] = {
|
||||||
|
|
||||||
static void Save_SUBS()
|
static void Save_SUBS()
|
||||||
{
|
{
|
||||||
Subsidy *s;
|
for (Subsidy *s : Subsidy::Iterate()) {
|
||||||
FOR_ALL_SUBSIDIES(s) {
|
|
||||||
SlSetArrayIndex(s->index);
|
SlSetArrayIndex(s->index);
|
||||||
SlObject(s, _subsidies_desc);
|
SlObject(s, _subsidies_desc);
|
||||||
}
|
}
|
||||||
|
|
|
@ -15,8 +15,7 @@
|
||||||
|
|
||||||
ScriptSubsidyList::ScriptSubsidyList()
|
ScriptSubsidyList::ScriptSubsidyList()
|
||||||
{
|
{
|
||||||
const Subsidy *s;
|
for (const Subsidy *s : Subsidy::Iterate()) {
|
||||||
FOR_ALL_SUBSIDIES(s) {
|
|
||||||
this->AddItem(s->index);
|
this->AddItem(s->index);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -135,8 +135,7 @@ void RebuildSubsidisedSourceAndDestinationCache()
|
||||||
|
|
||||||
for (Industry *i : Industry::Iterate()) i->part_of_subsidy = POS_NONE;
|
for (Industry *i : Industry::Iterate()) i->part_of_subsidy = POS_NONE;
|
||||||
|
|
||||||
const Subsidy *s;
|
for (const Subsidy *s : Subsidy::Iterate()) {
|
||||||
FOR_ALL_SUBSIDIES(s) {
|
|
||||||
SetPartOfSubsidyFlag(s->src_type, s->src, POS_SRC);
|
SetPartOfSubsidyFlag(s->src_type, s->src, POS_SRC);
|
||||||
SetPartOfSubsidyFlag(s->dst_type, s->dst, POS_DST);
|
SetPartOfSubsidyFlag(s->dst_type, s->dst, POS_DST);
|
||||||
}
|
}
|
||||||
|
@ -151,8 +150,7 @@ void DeleteSubsidyWith(SourceType type, SourceID index)
|
||||||
{
|
{
|
||||||
bool dirty = false;
|
bool dirty = false;
|
||||||
|
|
||||||
Subsidy *s;
|
for (Subsidy *s : Subsidy::Iterate()) {
|
||||||
FOR_ALL_SUBSIDIES(s) {
|
|
||||||
if ((s->src_type == type && s->src == index) || (s->dst_type == type && s->dst == index)) {
|
if ((s->src_type == type && s->src == index) || (s->dst_type == type && s->dst == index)) {
|
||||||
delete s;
|
delete s;
|
||||||
dirty = true;
|
dirty = true;
|
||||||
|
@ -176,8 +174,7 @@ void DeleteSubsidyWith(SourceType type, SourceID index)
|
||||||
*/
|
*/
|
||||||
static bool CheckSubsidyDuplicate(CargoID cargo, SourceType src_type, SourceID src, SourceType dst_type, SourceID dst)
|
static bool CheckSubsidyDuplicate(CargoID cargo, SourceType src_type, SourceID src, SourceType dst_type, SourceID dst)
|
||||||
{
|
{
|
||||||
const Subsidy *s;
|
for (const Subsidy *s : Subsidy::Iterate()) {
|
||||||
FOR_ALL_SUBSIDIES(s) {
|
|
||||||
if (s->cargo_type == cargo &&
|
if (s->cargo_type == cargo &&
|
||||||
s->src_type == src_type && s->src == src &&
|
s->src_type == src_type && s->src == src &&
|
||||||
s->dst_type == dst_type && s->dst == dst) {
|
s->dst_type == dst_type && s->dst == dst) {
|
||||||
|
@ -471,8 +468,7 @@ void SubsidyMonthlyLoop()
|
||||||
{
|
{
|
||||||
bool modified = false;
|
bool modified = false;
|
||||||
|
|
||||||
Subsidy *s;
|
for (Subsidy *s : Subsidy::Iterate()) {
|
||||||
FOR_ALL_SUBSIDIES(s) {
|
|
||||||
if (--s->remaining == 0) {
|
if (--s->remaining == 0) {
|
||||||
if (!s->IsAwarded()) {
|
if (!s->IsAwarded()) {
|
||||||
Pair reftype = SetupSubsidyDecodeParam(s, true);
|
Pair reftype = SetupSubsidyDecodeParam(s, true);
|
||||||
|
@ -564,8 +560,7 @@ bool CheckSubsidised(CargoID cargo_type, CompanyID company, SourceType src_type,
|
||||||
* which are destination of subsidised path. Do that only if needed */
|
* which are destination of subsidised path. Do that only if needed */
|
||||||
std::vector<const Town *> towns_near;
|
std::vector<const Town *> towns_near;
|
||||||
if (!st->rect.IsEmpty()) {
|
if (!st->rect.IsEmpty()) {
|
||||||
Subsidy *s;
|
for (const Subsidy *s : Subsidy::Iterate()) {
|
||||||
FOR_ALL_SUBSIDIES(s) {
|
|
||||||
/* Don't create the cache if there is no applicable subsidy with town as destination */
|
/* Don't create the cache if there is no applicable subsidy with town as destination */
|
||||||
if (s->dst_type != ST_TOWN) continue;
|
if (s->dst_type != ST_TOWN) continue;
|
||||||
if (s->cargo_type != cargo_type || s->src_type != src_type || s->src != src) continue;
|
if (s->cargo_type != cargo_type || s->src_type != src_type || s->src != src) continue;
|
||||||
|
@ -585,8 +580,7 @@ bool CheckSubsidised(CargoID cargo_type, CompanyID company, SourceType src_type,
|
||||||
|
|
||||||
/* Check if there's a (new) subsidy that applies. There can be more subsidies triggered by this delivery!
|
/* Check if there's a (new) subsidy that applies. There can be more subsidies triggered by this delivery!
|
||||||
* Think about the case that subsidies are A->B and A->C and station has both B and C in its catchment area */
|
* Think about the case that subsidies are A->B and A->C and station has both B and C in its catchment area */
|
||||||
Subsidy *s;
|
for (Subsidy *s : Subsidy::Iterate()) {
|
||||||
FOR_ALL_SUBSIDIES(s) {
|
|
||||||
if (s->cargo_type == cargo_type && s->src_type == src_type && s->src == src && (!s->IsAwarded() || s->awarded == company)) {
|
if (s->cargo_type == cargo_type && s->src_type == src_type && s->src == src && (!s->IsAwarded() || s->awarded == company)) {
|
||||||
switch (s->dst_type) {
|
switch (s->dst_type) {
|
||||||
case ST_INDUSTRY:
|
case ST_INDUSTRY:
|
||||||
|
|
|
@ -58,7 +58,4 @@ static const uint SUBSIDY_CARGO_MIN_POPULATION = 900; ///< Min. population of de
|
||||||
static const uint SUBSIDY_MAX_PCT_TRANSPORTED = 42; ///< Subsidy will be created only for towns/industries with less % transported
|
static const uint SUBSIDY_MAX_PCT_TRANSPORTED = 42; ///< Subsidy will be created only for towns/industries with less % transported
|
||||||
static const uint SUBSIDY_MAX_DISTANCE = 70; ///< Max. length of subsidised route (DistanceManhattan)
|
static const uint SUBSIDY_MAX_DISTANCE = 70; ///< Max. length of subsidised route (DistanceManhattan)
|
||||||
|
|
||||||
#define FOR_ALL_SUBSIDIES_FROM(var, start) FOR_ALL_ITEMS_FROM(Subsidy, subsidy_index, var, start)
|
|
||||||
#define FOR_ALL_SUBSIDIES(var) FOR_ALL_SUBSIDIES_FROM(var, 0)
|
|
||||||
|
|
||||||
#endif /* SUBSIDY_BASE_H */
|
#endif /* SUBSIDY_BASE_H */
|
||||||
|
|
|
@ -42,8 +42,7 @@ struct SubsidyListWindow : Window {
|
||||||
|
|
||||||
int y = this->vscroll->GetScrolledRowFromWidget(pt.y, this, WID_SUL_PANEL, WD_FRAMERECT_TOP);
|
int y = this->vscroll->GetScrolledRowFromWidget(pt.y, this, WID_SUL_PANEL, WD_FRAMERECT_TOP);
|
||||||
int num = 0;
|
int num = 0;
|
||||||
const Subsidy *s;
|
for (const Subsidy *s : Subsidy::Iterate()) {
|
||||||
FOR_ALL_SUBSIDIES(s) {
|
|
||||||
if (!s->IsAwarded()) {
|
if (!s->IsAwarded()) {
|
||||||
y--;
|
y--;
|
||||||
if (y == 0) {
|
if (y == 0) {
|
||||||
|
@ -62,7 +61,7 @@ struct SubsidyListWindow : Window {
|
||||||
y -= 2; // "Services already subsidised:"
|
y -= 2; // "Services already subsidised:"
|
||||||
if (y < 0) return;
|
if (y < 0) return;
|
||||||
|
|
||||||
FOR_ALL_SUBSIDIES(s) {
|
for (const Subsidy *s : Subsidy::Iterate()) {
|
||||||
if (s->IsAwarded()) {
|
if (s->IsAwarded()) {
|
||||||
y--;
|
y--;
|
||||||
if (y == 0) {
|
if (y == 0) {
|
||||||
|
@ -110,8 +109,7 @@ struct SubsidyListWindow : Window {
|
||||||
/* Count number of (non) awarded subsidies */
|
/* Count number of (non) awarded subsidies */
|
||||||
uint num_awarded = 0;
|
uint num_awarded = 0;
|
||||||
uint num_not_awarded = 0;
|
uint num_not_awarded = 0;
|
||||||
const Subsidy *s;
|
for (const Subsidy *s : Subsidy::Iterate()) {
|
||||||
FOR_ALL_SUBSIDIES(s) {
|
|
||||||
if (!s->IsAwarded()) {
|
if (!s->IsAwarded()) {
|
||||||
num_not_awarded++;
|
num_not_awarded++;
|
||||||
} else {
|
} else {
|
||||||
|
@ -159,8 +157,7 @@ struct SubsidyListWindow : Window {
|
||||||
pos++;
|
pos++;
|
||||||
|
|
||||||
uint num = 0;
|
uint num = 0;
|
||||||
const Subsidy *s;
|
for (const Subsidy *s : Subsidy::Iterate()) {
|
||||||
FOR_ALL_SUBSIDIES(s) {
|
|
||||||
if (!s->IsAwarded()) {
|
if (!s->IsAwarded()) {
|
||||||
if (IsInsideMM(pos, 0, cap)) {
|
if (IsInsideMM(pos, 0, cap)) {
|
||||||
/* Displays the two offered towns */
|
/* Displays the two offered towns */
|
||||||
|
@ -184,7 +181,7 @@ struct SubsidyListWindow : Window {
|
||||||
pos++;
|
pos++;
|
||||||
num = 0;
|
num = 0;
|
||||||
|
|
||||||
FOR_ALL_SUBSIDIES(s) {
|
for (const Subsidy *s : Subsidy::Iterate()) {
|
||||||
if (s->IsAwarded()) {
|
if (s->IsAwarded()) {
|
||||||
if (IsInsideMM(pos, 0, cap)) {
|
if (IsInsideMM(pos, 0, cap)) {
|
||||||
SetupSubsidyDecodeParam(s, true);
|
SetupSubsidyDecodeParam(s, true);
|
||||||
|
|
Loading…
Reference in New Issue