1
0
Fork 0

Codechange: Replace FOR_ALL_COMPANIES with range-based for loops

pull/7871/head
glx 2019-12-14 17:22:38 +01:00 committed by Niels Martin Hansen
parent 68f22134cb
commit 3a14cea068
27 changed files with 87 additions and 165 deletions

View File

@ -75,8 +75,7 @@
if ((AI::frame_counter & ((1 << (4 - _settings_game.difficulty.competitor_speed)) - 1)) != 0) return; if ((AI::frame_counter & ((1 << (4 - _settings_game.difficulty.competitor_speed)) - 1)) != 0) return;
Backup<CompanyID> cur_company(_current_company, FILE_LINE); Backup<CompanyID> cur_company(_current_company, FILE_LINE);
const Company *c; for (const Company *c : Company::Iterate()) {
FOR_ALL_COMPANIES(c) {
if (c->is_ai) { if (c->is_ai) {
PerformanceMeasurer framerate((PerformanceElement)(PFE_AI0 + c->index)); PerformanceMeasurer framerate((PerformanceElement)(PFE_AI0 + c->index));
cur_company.Change(c->index); cur_company.Change(c->index);
@ -154,8 +153,7 @@
/* It might happen there are no companies .. than we have nothing to loop */ /* It might happen there are no companies .. than we have nothing to loop */
if (Company::GetPoolSize() == 0) return; if (Company::GetPoolSize() == 0) return;
const Company *c; for (const Company *c : Company::Iterate()) {
FOR_ALL_COMPANIES(c) {
if (c->is_ai) AI::Stop(c->index); if (c->is_ai) AI::Stop(c->index);
} }
} }

View File

@ -1052,8 +1052,7 @@ struct AIDebugWindow : public Window {
ai_debug_company = INVALID_COMPANY; ai_debug_company = INVALID_COMPANY;
const Company *c; for (const Company *c : Company::Iterate()) {
FOR_ALL_COMPANIES(c) {
if (c->is_ai) { if (c->is_ai) {
ChangeToAI(c->index); ChangeToAI(c->index);
return; return;
@ -1312,8 +1311,7 @@ struct AIDebugWindow : public Window {
if ((_pause_mode & PM_PAUSED_NORMAL) == PM_PAUSED_NORMAL) { if ((_pause_mode & PM_PAUSED_NORMAL) == PM_PAUSED_NORMAL) {
bool all_unpaused = !Game::IsPaused(); bool all_unpaused = !Game::IsPaused();
if (all_unpaused) { if (all_unpaused) {
Company *c; for (const Company *c : Company::Iterate()) {
FOR_ALL_COMPANIES(c) {
if (c->is_ai && AI::IsPaused(c->index)) { if (c->is_ai && AI::IsPaused(c->index)) {
all_unpaused = false; all_unpaused = false;
break; break;
@ -1552,8 +1550,7 @@ void ShowAIDebugWindowIfAIError()
/* Network clients can't debug AIs. */ /* Network clients can't debug AIs. */
if (_networking && !_network_server) return; if (_networking && !_network_server) return;
Company *c; for (const Company *c : Company::Iterate()) {
FOR_ALL_COMPANIES(c) {
if (c->is_ai && c->ai_instance->IsDead()) { if (c->is_ai && c->ai_instance->IsDead()) {
ShowAIDebugWindow(c->index); ShowAIDebugWindow(c->index);
break; break;

View File

@ -168,9 +168,6 @@ struct Company : CompanyPool::PoolItem<&_company_pool>, CompanyProperties {
static void PostDestructor(size_t index); static void PostDestructor(size_t index);
}; };
#define FOR_ALL_COMPANIES_FROM(var, start) FOR_ALL_ITEMS_FROM(Company, company_index, var, start)
#define FOR_ALL_COMPANIES(var) FOR_ALL_COMPANIES_FROM(var, 0)
Money CalculateCompanyValue(const Company *c, bool including_loan = true); Money CalculateCompanyValue(const Company *c, bool including_loan = true);
extern uint _next_competitor_start; extern uint _next_competitor_start;

View File

@ -263,8 +263,7 @@ void SubtractMoneyFromCompanyFract(CompanyID company, CommandCost cst)
/** Update the landscaping limits per company. */ /** Update the landscaping limits per company. */
void UpdateLandscapingLimits() void UpdateLandscapingLimits()
{ {
Company *c; for (Company *c : Company::Iterate()) {
FOR_ALL_COMPANIES(c) {
c->terraform_limit = min(c->terraform_limit + _settings_game.construction.terraform_per_64k_frames, (uint32)_settings_game.construction.terraform_frame_burst << 16); c->terraform_limit = min(c->terraform_limit + _settings_game.construction.terraform_per_64k_frames, (uint32)_settings_game.construction.terraform_frame_burst << 16);
c->clear_limit = min(c->clear_limit + _settings_game.construction.clear_per_64k_frames, (uint32)_settings_game.construction.clear_frame_burst << 16); c->clear_limit = min(c->clear_limit + _settings_game.construction.clear_per_64k_frames, (uint32)_settings_game.construction.clear_frame_burst << 16);
c->tree_limit = min(c->tree_limit + _settings_game.construction.tree_per_64k_frames, (uint32)_settings_game.construction.tree_frame_burst << 16); c->tree_limit = min(c->tree_limit + _settings_game.construction.tree_per_64k_frames, (uint32)_settings_game.construction.tree_frame_burst << 16);
@ -360,8 +359,7 @@ static void GenerateCompanyName(Company *c)
verify_name:; verify_name:;
/* No companies must have this name already */ /* No companies must have this name already */
Company *cc; for (const Company *cc : Company::Iterate()) {
FOR_ALL_COMPANIES(cc) {
if (cc->name_1 == str && cc->name_2 == strp) goto bad_town_name; if (cc->name_1 == str && cc->name_2 == strp) goto bad_town_name;
} }
@ -447,8 +445,7 @@ static Colours GenerateCompanyColour()
} }
/* Move the colours that look similar to each company's colour to the side */ /* Move the colours that look similar to each company's colour to the side */
Company *c; for (const Company *c : Company::Iterate()) {
FOR_ALL_COMPANIES(c) {
Colours pcolour = (Colours)c->colour; Colours pcolour = (Colours)c->colour;
for (uint i = 0; i < COLOUR_END; i++) { for (uint i = 0; i < COLOUR_END; i++) {
@ -494,8 +491,7 @@ restart:;
GetString(buffer, STR_PRESIDENT_NAME, lastof(buffer)); GetString(buffer, STR_PRESIDENT_NAME, lastof(buffer));
if (Utf8StringLength(buffer) >= MAX_LENGTH_PRESIDENT_NAME_CHARS) continue; if (Utf8StringLength(buffer) >= MAX_LENGTH_PRESIDENT_NAME_CHARS) continue;
Company *cc; for (const Company *cc : Company::Iterate()) {
FOR_ALL_COMPANIES(cc) {
if (c != cc) { if (c != cc) {
/* Reserve extra space so even overlength president names can be compared. */ /* Reserve extra space so even overlength president names can be compared. */
char buffer2[(MAX_LENGTH_PRESIDENT_NAME_CHARS + 1) * MAX_CHAR_LENGTH]; char buffer2[(MAX_LENGTH_PRESIDENT_NAME_CHARS + 1) * MAX_CHAR_LENGTH];
@ -598,11 +594,9 @@ static bool MaybeStartNewCompany()
{ {
if (_networking && Company::GetNumItems() >= _settings_client.network.max_companies) return false; if (_networking && Company::GetNumItems() >= _settings_client.network.max_companies) return false;
Company *c;
/* count number of competitors */ /* count number of competitors */
uint n = 0; uint n = 0;
FOR_ALL_COMPANIES(c) { for (const Company *c : Company::Iterate()) {
if (c->is_ai) n++; if (c->is_ai) n++;
} }
@ -671,11 +665,11 @@ static void HandleBankruptcyTakeover(Company *c)
/* Did we ask everyone for bankruptcy? If so, bail out. */ /* Did we ask everyone for bankruptcy? If so, bail out. */
if (c->bankrupt_asked == MAX_UVALUE(CompanyMask)) return; if (c->bankrupt_asked == MAX_UVALUE(CompanyMask)) return;
Company *c2, *best = nullptr; Company *best = nullptr;
int32 best_performance = -1; int32 best_performance = -1;
/* Ask the company with the highest performance history first */ /* Ask the company with the highest performance history first */
FOR_ALL_COMPANIES(c2) { for (Company *c2 : Company::Iterate()) {
if (c2->bankrupt_asked == 0 && // Don't ask companies going bankrupt themselves if (c2->bankrupt_asked == 0 && // Don't ask companies going bankrupt themselves
!HasBit(c->bankrupt_asked, c2->index) && !HasBit(c->bankrupt_asked, c2->index) &&
best_performance < c2->old_economy[1].performance_history && best_performance < c2->old_economy[1].performance_history &&
@ -737,10 +731,8 @@ void OnTick_Companies()
*/ */
void CompaniesYearlyLoop() void CompaniesYearlyLoop()
{ {
Company *c;
/* Copy statistics */ /* Copy statistics */
FOR_ALL_COMPANIES(c) { for (Company *c : Company::Iterate()) {
memmove(&c->yearly_expenses[1], &c->yearly_expenses[0], sizeof(c->yearly_expenses) - sizeof(c->yearly_expenses[0])); memmove(&c->yearly_expenses[1], &c->yearly_expenses[0], sizeof(c->yearly_expenses) - sizeof(c->yearly_expenses[0]));
memset(&c->yearly_expenses[0], 0, sizeof(c->yearly_expenses[0])); memset(&c->yearly_expenses[0], 0, sizeof(c->yearly_expenses[0]));
SetWindowDirty(WC_FINANCES, c->index); SetWindowDirty(WC_FINANCES, c->index);
@ -748,7 +740,7 @@ void CompaniesYearlyLoop()
if (_settings_client.gui.show_finances && _local_company != COMPANY_SPECTATOR) { if (_settings_client.gui.show_finances && _local_company != COMPANY_SPECTATOR) {
ShowCompanyFinances(_local_company); ShowCompanyFinances(_local_company);
c = Company::Get(_local_company); Company *c = Company::Get(_local_company);
if (c->num_valid_stat_ent > 5 && c->old_economy[0].performance_history < c->old_economy[4].performance_history) { if (c->num_valid_stat_ent > 5 && c->old_economy[0].performance_history < c->old_economy[4].performance_history) {
if (_settings_client.sound.new_year) SndPlayFx(SND_01_BAD_YEAR); if (_settings_client.sound.new_year) SndPlayFx(SND_01_BAD_YEAR);
} else { } else {
@ -971,8 +963,7 @@ CommandCost CmdSetCompanyColour(TileIndex tile, DoCommandFlag flags, uint32 p1,
/* Ensure no two companies have the same primary colour */ /* Ensure no two companies have the same primary colour */
if (scheme == LS_DEFAULT && !second) { if (scheme == LS_DEFAULT && !second) {
const Company *cc; for (const Company *cc : Company::Iterate()) {
FOR_ALL_COMPANIES(cc) {
if (cc != c && cc->colour == colour) return CMD_ERROR; if (cc != c && cc->colour == colour) return CMD_ERROR;
} }
} }
@ -1053,9 +1044,7 @@ CommandCost CmdSetCompanyColour(TileIndex tile, DoCommandFlag flags, uint32 p1,
*/ */
static bool IsUniqueCompanyName(const char *name) static bool IsUniqueCompanyName(const char *name)
{ {
const Company *c; for (const Company *c : Company::Iterate()) {
FOR_ALL_COMPANIES(c) {
if (c->name != nullptr && strcmp(c->name, name) == 0) return false; if (c->name != nullptr && strcmp(c->name, name) == 0) return false;
} }
@ -1098,9 +1087,7 @@ CommandCost CmdRenameCompany(TileIndex tile, DoCommandFlag flags, uint32 p1, uin
*/ */
static bool IsUniquePresidentName(const char *name) static bool IsUniquePresidentName(const char *name)
{ {
const Company *c; for (const Company *c : Company::Iterate()) {
FOR_ALL_COMPANIES(c) {
if (c->president_name != nullptr && strcmp(c->president_name, name) == 0) return false; if (c->president_name != nullptr && strcmp(c->president_name, name) == 0) return false;
} }

View File

@ -574,7 +574,7 @@ private:
/* Disallow other company colours for the primary colour */ /* Disallow other company colours for the primary colour */
if (this->livery_class < LC_GROUP_RAIL && HasBit(this->sel, LS_DEFAULT) && primary) { if (this->livery_class < LC_GROUP_RAIL && HasBit(this->sel, LS_DEFAULT) && primary) {
FOR_ALL_COMPANIES(c) { for (const Company *c : Company::Iterate()) {
if (c->index != _local_company) SetBit(used_colours, c->colour); if (c->index != _local_company) SetBit(used_colours, c->colour);
} }
} }
@ -2396,9 +2396,7 @@ struct CompanyWindow : Window
break; break;
case WID_C_DESC_OWNERS: { case WID_C_DESC_OWNERS: {
const Company *c2; for (const Company *c2 : Company::Iterate()) {
FOR_ALL_COMPANIES(c2) {
SetDParamMaxValue(0, 75); SetDParamMaxValue(0, 75);
SetDParam(1, c2->index); SetDParam(1, c2->index);
@ -2500,10 +2498,9 @@ struct CompanyWindow : Window
} }
case WID_C_DESC_OWNERS: { case WID_C_DESC_OWNERS: {
const Company *c2;
uint y = r.top; uint y = r.top;
FOR_ALL_COMPANIES(c2) { for (const Company *c2 : Company::Iterate()) {
uint amt = GetAmountOwnedBy(c, c2->index); uint amt = GetAmountOwnedBy(c, c2->index);
if (amt != 0) { if (amt != 0) {
SetDParam(0, amt * 25); SetDParam(0, amt * 25);

View File

@ -1142,9 +1142,8 @@ DEF_CONSOLE_CMD(ConStartAI)
} }
int n = 0; int n = 0;
Company *c;
/* Find the next free slot */ /* Find the next free slot */
FOR_ALL_COMPANIES(c) { for (const Company *c : Company::Iterate()) {
if (c->index != n) break; if (c->index != n) break;
n++; n++;
} }
@ -1535,8 +1534,7 @@ DEF_CONSOLE_CMD(ConCompanies)
return true; return true;
} }
Company *c; for (const Company *c : Company::Iterate()) {
FOR_ALL_COMPANIES(c) {
/* Grab the company name */ /* Grab the company name */
char company_name[512]; char company_name[512];
SetDParam(0, c->index); SetDParam(0, c->index);

View File

@ -193,8 +193,7 @@ char *CrashLog::LogConfiguration(char *buffer, const char *last) const
); );
buffer += seprintf(buffer, last, "AI Configuration (local: %i) (current: %i):\n", (int)_local_company, (int)_current_company); buffer += seprintf(buffer, last, "AI Configuration (local: %i) (current: %i):\n", (int)_local_company, (int)_current_company);
const Company *c; for (const Company *c : Company::Iterate()) {
FOR_ALL_COMPANIES(c) {
if (c->ai_info == nullptr) { if (c->ai_info == nullptr) {
buffer += seprintf(buffer, last, " %2i: Human\n", (int)c->index); buffer += seprintf(buffer, last, " %2i: Human\n", (int)c->index);
} else { } else {

View File

@ -297,8 +297,7 @@ void ChangeOwnershipOfCompanyItems(Owner old_owner, Owner new_owner)
* There are no spectators in single player, so we must pick some other company. */ * There are no spectators in single player, so we must pick some other company. */
assert(!_networking); assert(!_networking);
Backup<CompanyID> cur_company2(_current_company, FILE_LINE); Backup<CompanyID> cur_company2(_current_company, FILE_LINE);
Company *c; for (const Company *c : Company::Iterate()) {
FOR_ALL_COMPANIES(c) {
if (c->index != old_owner) { if (c->index != old_owner) {
SetLocalCompany(c->index); SetLocalCompany(c->index);
break; break;
@ -313,11 +312,10 @@ void ChangeOwnershipOfCompanyItems(Owner old_owner, Owner new_owner)
assert(old_owner != new_owner); assert(old_owner != new_owner);
{ {
Company *c;
uint i; uint i;
/* See if the old_owner had shares in other companies */ /* See if the old_owner had shares in other companies */
FOR_ALL_COMPANIES(c) { for (const Company *c : Company::Iterate()) {
for (i = 0; i < 4; i++) { for (i = 0; i < 4; i++) {
if (c->share_owners[i] == old_owner) { if (c->share_owners[i] == old_owner) {
/* Sell his shares */ /* Sell his shares */
@ -331,7 +329,7 @@ void ChangeOwnershipOfCompanyItems(Owner old_owner, Owner new_owner)
/* Sell all the shares that people have on this company */ /* Sell all the shares that people have on this company */
Backup<CompanyID> cur_company2(_current_company, FILE_LINE); Backup<CompanyID> cur_company2(_current_company, FILE_LINE);
c = Company::Get(old_owner); const Company *c = Company::Get(old_owner);
for (i = 0; i < 4; i++) { for (i = 0; i < 4; i++) {
cur_company2.Change(c->share_owners[i]); cur_company2.Change(c->share_owners[i]);
if (_current_company != INVALID_OWNER) { if (_current_company != INVALID_OWNER) {
@ -658,8 +656,7 @@ static void CompanyCheckBankrupt(Company *c)
static void CompaniesGenStatistics() static void CompaniesGenStatistics()
{ {
/* Check for bankruptcy each month */ /* Check for bankruptcy each month */
Company *c; for (Company *c : Company::Iterate()) {
FOR_ALL_COMPANIES(c) {
CompanyCheckBankrupt(c); CompanyCheckBankrupt(c);
} }
@ -674,7 +671,7 @@ static void CompaniesGenStatistics()
} }
} else { } else {
/* Improved monthly infrastructure costs. */ /* Improved monthly infrastructure costs. */
FOR_ALL_COMPANIES(c) { for (const Company *c : Company::Iterate()) {
cur_company.Change(c->index); cur_company.Change(c->index);
CommandCost cost(EXPENSES_PROPERTY); CommandCost cost(EXPENSES_PROPERTY);
@ -700,7 +697,7 @@ static void CompaniesGenStatistics()
/* Only run the economic statics and update company stats every 3rd month (1st of quarter). */ /* Only run the economic statics and update company stats every 3rd month (1st of quarter). */
if (!HasBit(1 << 0 | 1 << 3 | 1 << 6 | 1 << 9, _cur_month)) return; if (!HasBit(1 << 0 | 1 << 3 | 1 << 6 | 1 << 9, _cur_month)) return;
FOR_ALL_COMPANIES(c) { for (Company *c : Company::Iterate()) {
/* Drop the oldest history off the end */ /* Drop the oldest history off the end */
std::copy_backward(c->old_economy, c->old_economy + MAX_HISTORY_QUARTERS - 1, c->old_economy + MAX_HISTORY_QUARTERS); std::copy_backward(c->old_economy, c->old_economy + MAX_HISTORY_QUARTERS - 1, c->old_economy + MAX_HISTORY_QUARTERS);
c->old_economy[0] = c->cur_economy; c->old_economy[0] = c->cur_economy;
@ -833,10 +830,8 @@ void RecomputePrices()
/** Let all companies pay the monthly interest on their loan. */ /** Let all companies pay the monthly interest on their loan. */
static void CompaniesPayInterest() static void CompaniesPayInterest()
{ {
const Company *c;
Backup<CompanyID> cur_company(_current_company, FILE_LINE); Backup<CompanyID> cur_company(_current_company, FILE_LINE);
FOR_ALL_COMPANIES(c) { for (const Company *c : Company::Iterate()) {
cur_company.Change(c->index); cur_company.Change(c->index);
/* Over a year the paid interest should be "loan * interest percentage", /* Over a year the paid interest should be "loan * interest percentage",

View File

@ -591,7 +591,6 @@ void DrawRailCatenary(const TileInfo *ti)
bool SettingsDisableElrail(int32 p1) bool SettingsDisableElrail(int32 p1)
{ {
Company *c;
Train *t; Train *t;
bool disable = (p1 != 0); bool disable = (p1 != 0);
@ -632,7 +631,7 @@ bool SettingsDisableElrail(int32 p1)
} }
} }
FOR_ALL_COMPANIES(c) c->avail_railtypes = GetCompanyRailtypes(c->index); for (Company *c : Company::Iterate()) c->avail_railtypes = GetCompanyRailtypes(c->index);
/* This resets the _last_built_railtype, which will be invalid for electric /* This resets the _last_built_railtype, which will be invalid for electric
* rails. It may have unintended consequences if that function is ever * rails. It may have unintended consequences if that function is ever

View File

@ -703,8 +703,7 @@ void StartupEngines()
} }
/* Update the bitmasks for the vehicle lists */ /* Update the bitmasks for the vehicle lists */
Company *c; for (Company *c : Company::Iterate()) {
FOR_ALL_COMPANIES(c) {
c->avail_railtypes = GetCompanyRailtypes(c->index); c->avail_railtypes = GetCompanyRailtypes(c->index);
c->avail_roadtypes = GetCompanyRoadTypes(c->index); c->avail_roadtypes = GetCompanyRoadTypes(c->index);
} }
@ -763,8 +762,7 @@ static CompanyID GetPreviewCompany(Engine *e)
CargoTypes cargomask = e->type != VEH_TRAIN ? GetUnionOfArticulatedRefitMasks(e->index, true) : ALL_CARGOTYPES; CargoTypes cargomask = e->type != VEH_TRAIN ? GetUnionOfArticulatedRefitMasks(e->index, true) : ALL_CARGOTYPES;
int32 best_hist = -1; int32 best_hist = -1;
const Company *c; for (const Company *c : Company::Iterate()) {
FOR_ALL_COMPANIES(c) {
if (c->block_preview == 0 && !HasBit(e->preview_asked, c->index) && if (c->block_preview == 0 && !HasBit(e->preview_asked, c->index) &&
c->old_economy[0].performance_history > best_hist) { c->old_economy[0].performance_history > best_hist) {
@ -806,8 +804,7 @@ static bool IsVehicleTypeDisabled(VehicleType type, bool ai)
/** Daily check to offer an exclusive engine preview to the companies. */ /** Daily check to offer an exclusive engine preview to the companies. */
void EnginesDailyLoop() void EnginesDailyLoop()
{ {
Company *c; for (Company *c : Company::Iterate()) {
FOR_ALL_COMPANIES(c) {
c->avail_railtypes = AddDateIntroducedRailTypes(c->avail_railtypes, _date); c->avail_railtypes = AddDateIntroducedRailTypes(c->avail_railtypes, _date);
c->avail_roadtypes = AddDateIntroducedRoadTypes(c->avail_roadtypes, _date); c->avail_roadtypes = AddDateIntroducedRoadTypes(c->avail_roadtypes, _date);
} }
@ -908,13 +905,12 @@ CommandCost CmdWantEnginePreview(TileIndex tile, DoCommandFlag flags, uint32 p1,
static void NewVehicleAvailable(Engine *e) static void NewVehicleAvailable(Engine *e)
{ {
Vehicle *v; Vehicle *v;
Company *c;
EngineID index = e->index; EngineID index = e->index;
/* In case the company didn't build the vehicle during the intro period, /* In case the company didn't build the vehicle during the intro period,
* prevent that company from getting future intro periods for a while. */ * prevent that company from getting future intro periods for a while. */
if (e->flags & ENGINE_EXCLUSIVE_PREVIEW) { if (e->flags & ENGINE_EXCLUSIVE_PREVIEW) {
FOR_ALL_COMPANIES(c) { for (Company *c : Company::Iterate()) {
uint block_preview = c->block_preview; uint block_preview = c->block_preview;
if (!HasBit(e->company_avail, c->index)) continue; if (!HasBit(e->company_avail, c->index)) continue;
@ -948,11 +944,11 @@ static void NewVehicleAvailable(Engine *e)
/* maybe make another rail type available */ /* maybe make another rail type available */
RailType railtype = e->u.rail.railtype; RailType railtype = e->u.rail.railtype;
assert(railtype < RAILTYPE_END); assert(railtype < RAILTYPE_END);
FOR_ALL_COMPANIES(c) c->avail_railtypes = AddDateIntroducedRailTypes(c->avail_railtypes | GetRailTypeInfo(e->u.rail.railtype)->introduces_railtypes, _date); for (Company *c : Company::Iterate()) c->avail_railtypes = AddDateIntroducedRailTypes(c->avail_railtypes | GetRailTypeInfo(e->u.rail.railtype)->introduces_railtypes, _date);
} else if (e->type == VEH_ROAD) { } else if (e->type == VEH_ROAD) {
/* maybe make another road type available */ /* maybe make another road type available */
assert(e->u.road.roadtype < ROADTYPE_END); assert(e->u.road.roadtype < ROADTYPE_END);
FOR_ALL_COMPANIES(c) c->avail_roadtypes = AddDateIntroducedRoadTypes(c->avail_roadtypes | GetRoadTypeInfo(e->u.road.roadtype)->introduces_roadtypes, _date); for (Company* c : Company::Iterate()) c->avail_roadtypes = AddDateIntroducedRoadTypes(c->avail_roadtypes | GetRoadTypeInfo(e->u.road.roadtype)->introduces_roadtypes, _date);
} }
/* Only broadcast event if AIs are able to build this vehicle type. */ /* Only broadcast event if AIs are able to build this vehicle type. */

View File

@ -567,8 +567,7 @@ public:
} }
byte nums = 0; byte nums = 0;
const Company *c; for (const Company *c : Company::Iterate()) {
FOR_ALL_COMPANIES(c) {
nums = min(this->num_vert_lines, max(nums, c->num_valid_stat_ent)); nums = min(this->num_vert_lines, max(nums, c->num_valid_stat_ent));
} }
@ -592,7 +591,7 @@ public:
int numd = 0; int numd = 0;
for (CompanyID k = COMPANY_FIRST; k < MAX_COMPANIES; k++) { for (CompanyID k = COMPANY_FIRST; k < MAX_COMPANIES; k++) {
c = Company::GetIfValid(k); const Company *c = Company::GetIfValid(k);
if (c != nullptr) { if (c != nullptr) {
this->colours[numd] = _colour_gradient[c->colour][6]; this->colours[numd] = _colour_gradient[c->colour][6];
for (int j = this->num_on_x_axis, i = 0; --j >= 0;) { for (int j = this->num_on_x_axis, i = 0; --j >= 0;) {
@ -1136,8 +1135,7 @@ private:
this->companies.clear(); this->companies.clear();
const Company *c; for (const Company *c : Company::Iterate()) {
FOR_ALL_COMPANIES(c) {
this->companies.push_back(c); this->companies.push_back(c);
} }
@ -1219,8 +1217,7 @@ public:
this->icon_width = d.width + 2; this->icon_width = d.width + 2;
this->line_height = max<int>(d.height + 2, FONT_HEIGHT_NORMAL); this->line_height = max<int>(d.height + 2, FONT_HEIGHT_NORMAL);
const Company *c; for (const Company *c : Company::Iterate()) {
FOR_ALL_COMPANIES(c) {
SetDParam(0, c->index); SetDParam(0, c->index);
SetDParam(1, c->index); SetDParam(1, c->index);
SetDParam(2, _performance_titles[widest_title]); SetDParam(2, _performance_titles[widest_title]);
@ -1299,8 +1296,7 @@ struct PerformanceRatingDetailWindow : Window {
{ {
/* Update all company stats with the current data /* Update all company stats with the current data
* (this is because _score_info is not saved to a savegame) */ * (this is because _score_info is not saved to a savegame) */
Company *c; for (Company *c : Company::Iterate()) {
FOR_ALL_COMPANIES(c) {
UpdateCompanyRatingAndValue(c, false); UpdateCompanyRatingAndValue(c, false);
} }
@ -1497,8 +1493,7 @@ struct PerformanceRatingDetailWindow : Window {
} }
if (this->company == INVALID_COMPANY) { if (this->company == INVALID_COMPANY) {
const Company *c; for (const Company *c : Company::Iterate()) {
FOR_ALL_COMPANIES(c) {
this->company = c->index; this->company = c->index;
break; break;
} }

View File

@ -101,8 +101,7 @@ void GroupStatistics::Clear()
/* static */ void GroupStatistics::UpdateAfterLoad() /* static */ void GroupStatistics::UpdateAfterLoad()
{ {
/* Set up the engine count for all companies */ /* Set up the engine count for all companies */
Company *c; for (Company *c : Company::Iterate()) {
FOR_ALL_COMPANIES(c) {
for (VehicleType type = VEH_BEGIN; type < VEH_COMPANY_END; type++) { for (VehicleType type = VEH_BEGIN; type < VEH_COMPANY_END; type++) {
c->group_all[type].Clear(); c->group_all[type].Clear();
c->group_default[type].Clear(); c->group_default[type].Clear();
@ -123,7 +122,7 @@ void GroupStatistics::Clear()
if (v->IsPrimaryVehicle()) GroupStatistics::CountVehicle(v, 1); if (v->IsPrimaryVehicle()) GroupStatistics::CountVehicle(v, 1);
} }
FOR_ALL_COMPANIES(c) { for (const Company *c : Company::Iterate()) {
GroupStatistics::UpdateAutoreplace(c->index); GroupStatistics::UpdateAutoreplace(c->index);
} }
} }
@ -183,8 +182,7 @@ void GroupStatistics::Clear()
/* static */ void GroupStatistics::UpdateProfits() /* static */ void GroupStatistics::UpdateProfits()
{ {
/* Set up the engine count for all companies */ /* Set up the engine count for all companies */
Company *c; for (Company *c : Company::Iterate()) {
FOR_ALL_COMPANIES(c) {
for (VehicleType type = VEH_BEGIN; type < VEH_COMPANY_END; type++) { for (VehicleType type = VEH_BEGIN; type < VEH_COMPANY_END; type++) {
c->group_all[type].ClearProfits(); c->group_all[type].ClearProfits();
c->group_default[type].ClearProfits(); c->group_default[type].ClearProfits();

View File

@ -87,13 +87,12 @@ static bool HighScoreSorter(const Company * const &a, const Company * const &b)
*/ */
int8 SaveHighScoreValueNetwork() int8 SaveHighScoreValueNetwork()
{ {
const Company *c;
const Company *cl[MAX_COMPANIES]; const Company *cl[MAX_COMPANIES];
uint count = 0; uint count = 0;
int8 company = -1; int8 company = -1;
/* Sort all active companies with the highest score first */ /* Sort all active companies with the highest score first */
FOR_ALL_COMPANIES(c) cl[count++] = c; for (const Company *c : Company::Iterate()) cl[count++] = c;
std::sort(std::begin(cl), std::begin(cl) + count, HighScoreSorter); std::sort(std::begin(cl), std::begin(cl) + count, HighScoreSorter);

View File

@ -399,8 +399,7 @@ NetworkRecvStatus ServerNetworkAdminSocketHandler::SendCompanyRemove(CompanyID c
/** Send economic information of all companies. */ /** Send economic information of all companies. */
NetworkRecvStatus ServerNetworkAdminSocketHandler::SendCompanyEconomy() NetworkRecvStatus ServerNetworkAdminSocketHandler::SendCompanyEconomy()
{ {
const Company *company; for (const Company *company : Company::Iterate()) {
FOR_ALL_COMPANIES(company) {
/* Get the income. */ /* Get the income. */
Money income = 0; Money income = 0;
for (uint i = 0; i < lengthof(company->yearly_expenses[0]); i++) { for (uint i = 0; i < lengthof(company->yearly_expenses[0]); i++) {
@ -438,10 +437,8 @@ NetworkRecvStatus ServerNetworkAdminSocketHandler::SendCompanyStats()
NetworkCompanyStats company_stats[MAX_COMPANIES]; NetworkCompanyStats company_stats[MAX_COMPANIES];
NetworkPopulateCompanyStats(company_stats); NetworkPopulateCompanyStats(company_stats);
const Company *company;
/* Go through all the companies. */ /* Go through all the companies. */
FOR_ALL_COMPANIES(company) { for (const Company *company : Company::Iterate()) {
Packet *p = new Packet(ADMIN_PACKET_SERVER_COMPANY_STATS); Packet *p = new Packet(ADMIN_PACKET_SERVER_COMPANY_STATS);
/* Send the information. */ /* Send the information. */
@ -748,13 +745,12 @@ NetworkRecvStatus ServerNetworkAdminSocketHandler::Receive_ADMIN_POLL(Packet *p)
case ADMIN_UPDATE_COMPANY_INFO: case ADMIN_UPDATE_COMPANY_INFO:
/* The admin is asking for company info. */ /* The admin is asking for company info. */
const Company *company;
if (d1 == UINT32_MAX) { if (d1 == UINT32_MAX) {
FOR_ALL_COMPANIES(company) { for (const Company *company : Company::Iterate()) {
this->SendCompanyInfo(company); this->SendCompanyInfo(company);
} }
} else { } else {
company = Company::GetIfValid(d1); const Company *company = Company::GetIfValid(d1);
if (company != nullptr) this->SendCompanyInfo(company); if (company != nullptr) this->SendCompanyInfo(company);
} }
break; break;

View File

@ -380,10 +380,9 @@ NetworkRecvStatus ServerNetworkGameSocketHandler::SendCompanyInfo()
/* Now send the data */ /* Now send the data */
Company *company;
Packet *p; Packet *p;
FOR_ALL_COMPANIES(company) { for (const Company *company : Company::Iterate()) {
p = new Packet(PACKET_SERVER_COMPANY_INFO); p = new Packet(PACKET_SERVER_COMPANY_INFO);
p->Send_uint8 (NETWORK_COMPANY_INFO_VERSION); p->Send_uint8 (NETWORK_COMPANY_INFO_VERSION);
@ -1619,7 +1618,6 @@ static void NetworkCheckRestartMap()
static void NetworkAutoCleanCompanies() static void NetworkAutoCleanCompanies()
{ {
const NetworkClientInfo *ci; const NetworkClientInfo *ci;
const Company *c;
bool clients_in_company[MAX_COMPANIES]; bool clients_in_company[MAX_COMPANIES];
int vehicles_in_company[MAX_COMPANIES]; int vehicles_in_company[MAX_COMPANIES];
@ -1648,7 +1646,7 @@ static void NetworkAutoCleanCompanies()
} }
/* Go through all the companies */ /* Go through all the companies */
FOR_ALL_COMPANIES(c) { for (const Company *c : Company::Iterate()) {
/* Skip the non-active once */ /* Skip the non-active once */
if (c->is_ai) continue; if (c->is_ai) continue;

View File

@ -198,8 +198,7 @@ void ServerNetworkUDPSocketHandler::Receive_CLIENT_DETAIL_INFO(Packet *p, Networ
for (;;) { for (;;) {
int free = SEND_MTU - packet.size; int free = SEND_MTU - packet.size;
Company *company; for (const Company *company : Company::Iterate()) {
FOR_ALL_COMPANIES(company) {
char company_name[NETWORK_COMPANY_NAME_LENGTH]; char company_name[NETWORK_COMPANY_NAME_LENGTH];
SetDParam(0, company->index); SetDParam(0, company->index);
GetString(company_name, STR_COMPANY_NAME, company_name + max_cname_length - 1); GetString(company_name, STR_COMPANY_NAME, company_name + max_cname_length - 1);
@ -214,9 +213,8 @@ void ServerNetworkUDPSocketHandler::Receive_CLIENT_DETAIL_INFO(Packet *p, Networ
} }
} }
Company *company;
/* Go through all the companies */ /* Go through all the companies */
FOR_ALL_COMPANIES(company) { for (const Company *company : Company::Iterate()) {
/* Send the information */ /* Send the information */
this->SendCompanyInformation(&packet, company, &company_stats[company->index], max_cname_length); this->SendCompanyInformation(&packet, company, &company_stats[company->index], max_cname_length);
} }

View File

@ -1207,14 +1207,13 @@ static void CheckCaches()
/* Check company infrastructure cache. */ /* Check company infrastructure cache. */
std::vector<CompanyInfrastructure> old_infrastructure; std::vector<CompanyInfrastructure> old_infrastructure;
Company *c; for (const Company *c : Company::Iterate()) old_infrastructure.push_back(c->infrastructure);
FOR_ALL_COMPANIES(c) old_infrastructure.push_back(c->infrastructure);
extern void AfterLoadCompanyStats(); extern void AfterLoadCompanyStats();
AfterLoadCompanyStats(); AfterLoadCompanyStats();
i = 0; i = 0;
FOR_ALL_COMPANIES(c) { for (const Company *c : Company::Iterate()) {
if (MemCmpT(old_infrastructure.data() + i, &c->infrastructure) != 0) { if (MemCmpT(old_infrastructure.data() + i, &c->infrastructure) != 0) {
DEBUG(desync, 2, "infrastructure cache mismatch: company %i", (int)c->index); DEBUG(desync, 2, "infrastructure cache mismatch: company %i", (int)c->index);
} }

View File

@ -243,8 +243,7 @@ static void InitializeWindowsAndCaches()
UpdateAllVirtCoords(); UpdateAllVirtCoords();
ResetViewportAfterLoadGame(); ResetViewportAfterLoadGame();
Company *c; for (Company *c : Company::Iterate()) {
FOR_ALL_COMPANIES(c) {
/* For each company, verify (while loading a scenario) that the inauguration date is the current year and set it /* For each company, verify (while loading a scenario) that the inauguration date is the current year and set it
* accordingly if it is not the case. No need to set it on companies that are not been used already, * accordingly if it is not the case. No need to set it on companies that are not been used already,
* thus the MIN_YEAR (which is really nothing more than Zero, initialized value) test */ * thus the MIN_YEAR (which is really nothing more than Zero, initialized value) test */
@ -644,8 +643,7 @@ bool AfterLoadGame()
} }
if (IsSavegameVersionBefore(SLV_84)) { if (IsSavegameVersionBefore(SLV_84)) {
Company *c; for (Company *c : Company::Iterate()) {
FOR_ALL_COMPANIES(c) {
c->name = CopyFromOldName(c->name_1); c->name = CopyFromOldName(c->name_1);
if (c->name != nullptr) c->name_1 = STR_SV_UNNAMED; if (c->name != nullptr) c->name_1 = STR_SV_UNNAMED;
c->president_name = CopyFromOldName(c->president_name_1); c->president_name = CopyFromOldName(c->president_name_1);
@ -678,8 +676,7 @@ bool AfterLoadGame()
} }
/* the same applies to Company::location_of_HQ */ /* the same applies to Company::location_of_HQ */
Company *c; for (Company *c : Company::Iterate()) {
FOR_ALL_COMPANIES(c) {
if (c->location_of_HQ == 0 || (IsSavegameVersionBefore(SLV_4) && c->location_of_HQ == 0xFFFF)) { if (c->location_of_HQ == 0 || (IsSavegameVersionBefore(SLV_4) && c->location_of_HQ == 0xFFFF)) {
c->location_of_HQ = INVALID_TILE; c->location_of_HQ = INVALID_TILE;
} }
@ -800,8 +797,7 @@ bool AfterLoadGame()
/* Make sure there is an AI attached to an AI company */ /* Make sure there is an AI attached to an AI company */
{ {
Company *c; for (const Company *c : Company::Iterate()) {
FOR_ALL_COMPANIES(c) {
if (c->is_ai && c->ai_instance == nullptr) AI::StartNew(c->index); if (c->is_ai && c->ai_instance == nullptr) AI::StartNew(c->index);
} }
} }
@ -1000,8 +996,7 @@ bool AfterLoadGame()
/* From version 16.0, we included autorenew on engines, which are now saved, but /* From version 16.0, we included autorenew on engines, which are now saved, but
* of course, we do need to initialize them for older savegames. */ * of course, we do need to initialize them for older savegames. */
if (IsSavegameVersionBefore(SLV_16)) { if (IsSavegameVersionBefore(SLV_16)) {
Company *c; for (Company *c : Company::Iterate()) {
FOR_ALL_COMPANIES(c) {
c->engine_renew_list = nullptr; c->engine_renew_list = nullptr;
c->settings.engine_renew = false; c->settings.engine_renew = false;
c->settings.engine_renew_months = 6; c->settings.engine_renew_months = 6;
@ -1014,7 +1009,7 @@ bool AfterLoadGame()
* becomes company 0, unless we are in the scenario editor where all the * becomes company 0, unless we are in the scenario editor where all the
* companies are 'invalid'. * companies are 'invalid'.
*/ */
c = Company::GetIfValid(COMPANY_FIRST); Company *c = Company::GetIfValid(COMPANY_FIRST);
if (!_network_dedicated && c != nullptr) { if (!_network_dedicated && c != nullptr) {
c->settings = _settings_client.company; c->settings = _settings_client.company;
} }
@ -1349,8 +1344,7 @@ bool AfterLoadGame()
* replaced, shall keep their old length. In all prior versions, just default * replaced, shall keep their old length. In all prior versions, just default
* to false */ * to false */
if (IsSavegameVersionBefore(SLV_16, 1)) { if (IsSavegameVersionBefore(SLV_16, 1)) {
Company *c; for (Company *c : Company::Iterate()) c->settings.renew_keep_length = false;
FOR_ALL_COMPANIES(c) c->settings.renew_keep_length = false;
} }
if (IsSavegameVersionBefore(SLV_123)) { if (IsSavegameVersionBefore(SLV_123)) {
@ -1413,12 +1407,10 @@ bool AfterLoadGame()
YapfNotifyTrackLayoutChange(INVALID_TILE, INVALID_TRACK); YapfNotifyTrackLayoutChange(INVALID_TILE, INVALID_TRACK);
if (IsSavegameVersionBefore(SLV_34)) { if (IsSavegameVersionBefore(SLV_34)) {
Company *c; for (Company *c : Company::Iterate()) ResetCompanyLivery(c);
FOR_ALL_COMPANIES(c) ResetCompanyLivery(c);
} }
Company *c; for (Company *c : Company::Iterate()) {
FOR_ALL_COMPANIES(c) {
c->avail_railtypes = GetCompanyRailtypes(c->index); c->avail_railtypes = GetCompanyRailtypes(c->index);
c->avail_roadtypes = GetCompanyRoadTypes(c->index); c->avail_roadtypes = GetCompanyRoadTypes(c->index);
} }
@ -1440,7 +1432,7 @@ bool AfterLoadGame()
FOR_ALL_STATIONS(st) st->build_date += DAYS_TILL_ORIGINAL_BASE_YEAR; FOR_ALL_STATIONS(st) st->build_date += DAYS_TILL_ORIGINAL_BASE_YEAR;
FOR_ALL_WAYPOINTS(wp) wp->build_date += DAYS_TILL_ORIGINAL_BASE_YEAR; FOR_ALL_WAYPOINTS(wp) wp->build_date += DAYS_TILL_ORIGINAL_BASE_YEAR;
FOR_ALL_ENGINES(e) e->intro_date += DAYS_TILL_ORIGINAL_BASE_YEAR; FOR_ALL_ENGINES(e) e->intro_date += DAYS_TILL_ORIGINAL_BASE_YEAR;
FOR_ALL_COMPANIES(c) c->inaugurated_year += ORIGINAL_BASE_YEAR; for (Company *c : Company::Iterate()) c->inaugurated_year += ORIGINAL_BASE_YEAR;
FOR_ALL_INDUSTRIES(i) i->last_prod_year += ORIGINAL_BASE_YEAR; FOR_ALL_INDUSTRIES(i) i->last_prod_year += ORIGINAL_BASE_YEAR;
FOR_ALL_VEHICLES(v) { FOR_ALL_VEHICLES(v) {
@ -1592,7 +1584,7 @@ bool AfterLoadGame()
} }
} }
if (IsSavegameVersionBefore(SLV_49)) FOR_ALL_COMPANIES(c) c->face = ConvertFromOldCompanyManagerFace(c->face); if (IsSavegameVersionBefore(SLV_49)) for (Company *c : Company::Iterate()) c->face = ConvertFromOldCompanyManagerFace(c->face);
if (IsSavegameVersionBefore(SLV_52)) { if (IsSavegameVersionBefore(SLV_52)) {
for (TileIndex t = 0; t < map_size; t++) { for (TileIndex t = 0; t < map_size; t++) {
@ -1792,7 +1784,7 @@ bool AfterLoadGame()
* *really* old revisions of OTTD; else it is already set in InitializeCompanies()) * *really* old revisions of OTTD; else it is already set in InitializeCompanies())
* 2) shares that are owned by inactive companies or self * 2) shares that are owned by inactive companies or self
* (caused by cheating clients in earlier revisions) */ * (caused by cheating clients in earlier revisions) */
FOR_ALL_COMPANIES(c) { for (Company *c : Company::Iterate()) {
for (uint i = 0; i < 4; i++) { for (uint i = 0; i < 4; i++) {
CompanyID company = c->share_owners[i]; CompanyID company = c->share_owners[i];
if (company == INVALID_COMPANY) continue; if (company == INVALID_COMPANY) continue;
@ -2061,8 +2053,7 @@ bool AfterLoadGame()
} }
/* More companies ... */ /* More companies ... */
Company *c; for (Company *c : Company::Iterate()) {
FOR_ALL_COMPANIES(c) {
if (c->bankrupt_asked == 0xFF) c->bankrupt_asked = 0xFFFF; if (c->bankrupt_asked == 0xFF) c->bankrupt_asked = 0xFFFF;
} }
@ -2199,8 +2190,7 @@ bool AfterLoadGame()
if (IsSavegameVersionBefore(SLV_120)) { if (IsSavegameVersionBefore(SLV_120)) {
extern VehicleDefaultSettings _old_vds; extern VehicleDefaultSettings _old_vds;
Company *c; for (Company *c : Company::Iterate()) {
FOR_ALL_COMPANIES(c) {
c->settings.vehicle = _old_vds; c->settings.vehicle = _old_vds;
} }
} }
@ -2663,8 +2653,7 @@ bool AfterLoadGame()
} }
/* Introduced terraform/clear limits. */ /* Introduced terraform/clear limits. */
Company *c; for (Company *c : Company::Iterate()) {
FOR_ALL_COMPANIES(c) {
c->terraform_limit = _settings_game.construction.terraform_frame_burst << 16; c->terraform_limit = _settings_game.construction.terraform_frame_burst << 16;
c->clear_limit = _settings_game.construction.clear_frame_burst << 16; c->clear_limit = _settings_game.construction.clear_frame_burst << 16;
} }
@ -2923,8 +2912,7 @@ bool AfterLoadGame()
if (IsSavegameVersionBefore(SLV_175)) { if (IsSavegameVersionBefore(SLV_175)) {
/* Introduced tree planting limit. */ /* Introduced tree planting limit. */
Company *c; for (Company *c : Company::Iterate()) c->tree_limit = _settings_game.construction.tree_frame_burst << 16;
FOR_ALL_COMPANIES(c) c->tree_limit = _settings_game.construction.tree_frame_burst << 16;
} }
if (IsSavegameVersionBefore(SLV_177)) { if (IsSavegameVersionBefore(SLV_177)) {
@ -2933,7 +2921,7 @@ bool AfterLoadGame()
if (_economy.inflation_payment > MAX_INFLATION) _economy.inflation_payment = MAX_INFLATION; if (_economy.inflation_payment > MAX_INFLATION) _economy.inflation_payment = MAX_INFLATION;
/* We have to convert the quarters of bankruptcy into months of bankruptcy */ /* We have to convert the quarters of bankruptcy into months of bankruptcy */
FOR_ALL_COMPANIES(c) { for (Company *c : Company::Iterate()) {
c->months_of_bankruptcy = 3 * c->months_of_bankruptcy; c->months_of_bankruptcy = 3 * c->months_of_bankruptcy;
} }
} }

View File

@ -94,8 +94,7 @@ CompanyManagerFace ConvertFromOldCompanyManagerFace(uint32 face)
void AfterLoadCompanyStats() void AfterLoadCompanyStats()
{ {
/* Reset infrastructure statistics to zero. */ /* Reset infrastructure statistics to zero. */
Company *c; for (Company *c : Company::Iterate()) MemSetT(&c->infrastructure, 0);
FOR_ALL_COMPANIES(c) MemSetT(&c->infrastructure, 0);
/* Collect airport count. */ /* Collect airport count. */
Station *st; Station *st;
@ -105,6 +104,7 @@ void AfterLoadCompanyStats()
} }
} }
Company *c;
for (TileIndex tile = 0; tile < MapSize(); tile++) { for (TileIndex tile = 0; tile < MapSize(); tile++) {
switch (GetTileType(tile)) { switch (GetTileType(tile)) {
case MP_RAILWAY: case MP_RAILWAY:
@ -486,8 +486,7 @@ static void SaveLoad_PLYR(Company *c)
static void Save_PLYR() static void Save_PLYR()
{ {
Company *c; for (Company *c : Company::Iterate()) {
FOR_ALL_COMPANIES(c) {
SlSetArrayIndex(c->index); SlSetArrayIndex(c->index);
SlAutolength((AutolengthProc*)SaveLoad_PLYR, c); SlAutolength((AutolengthProc*)SaveLoad_PLYR, c);
} }
@ -534,8 +533,7 @@ static void Check_PLYR()
static void Ptrs_PLYR() static void Ptrs_PLYR()
{ {
Company *c; for (Company *c : Company::Iterate()) {
FOR_ALL_COMPANIES(c) {
SlObject(c, _company_settings_desc); SlObject(c, _company_settings_desc);
} }
} }

View File

@ -459,8 +459,7 @@ static bool FixTTOEngines()
static void FixTTOCompanies() static void FixTTOCompanies()
{ {
Company *c; for (Company *c : Company::Iterate()) {
FOR_ALL_COMPANIES(c) {
c->cur_economy.company_value = CalculateCompanyValue(c); // company value history is zeroed c->cur_economy.company_value = CalculateCompanyValue(c); // company value history is zeroed
} }
} }

View File

@ -2816,8 +2816,7 @@ void GenerateDefaultSaveName(char *buf, const char *last)
* 'Spectator' as "company" name. */ * 'Spectator' as "company" name. */
CompanyID cid = _local_company; CompanyID cid = _local_company;
if (!Company::IsValidID(cid)) { if (!Company::IsValidID(cid)) {
const Company *c; for (const Company *c : Company::Iterate()) {
FOR_ALL_COMPANIES(c) {
cid = c->index; cid = c->index;
break; break;
} }

View File

@ -315,8 +315,7 @@ static bool MakePNGImage(const char *name, ScreenshotCallback *callb, void *user
p += seprintf(p, lastof(buf), " %s\n", c->filename); p += seprintf(p, lastof(buf), " %s\n", c->filename);
} }
p = strecpy(p, "\nCompanies:\n", lastof(buf)); p = strecpy(p, "\nCompanies:\n", lastof(buf));
const Company *c; for (const Company *c : Company::Iterate()) {
FOR_ALL_COMPANIES(c) {
if (c->ai_info == nullptr) { if (c->ai_info == nullptr) {
p += seprintf(p, lastof(buf), "%2i: Human\n", (int)c->index); p += seprintf(p, lastof(buf), "%2i: Human\n", (int)c->index);
} else { } else {

View File

@ -333,8 +333,7 @@ void BuildOwnerLegend()
_legend_land_owners[1].colour = _heightmap_schemes[_settings_client.gui.smallmap_land_colour].default_colour; _legend_land_owners[1].colour = _heightmap_schemes[_settings_client.gui.smallmap_land_colour].default_colour;
int i = NUM_NO_COMPANY_ENTRIES; int i = NUM_NO_COMPANY_ENTRIES;
const Company *c; for (const Company *c : Company::Iterate()) {
FOR_ALL_COMPANIES(c) {
_legend_land_owners[i].colour = _colour_gradient[c->colour][5]; _legend_land_owners[i].colour = _colour_gradient[c->colour][5];
_legend_land_owners[i].company = c->index; _legend_land_owners[i].company = c->index;
_legend_land_owners[i].show_on_map = true; _legend_land_owners[i].show_on_map = true;

View File

@ -120,8 +120,7 @@ struct StatusBarWindow : Window {
case WID_S_RIGHT: { case WID_S_RIGHT: {
int64 max_money = UINT32_MAX; int64 max_money = UINT32_MAX;
const Company *c; for (const Company *c : Company::Iterate()) max_money = max<int64>(c->money, max_money);
FOR_ALL_COMPANIES(c) max_money = max<int64>(c->money, max_money);
SetDParam(0, 100LL * max_money); SetDParam(0, 100LL * max_money);
d = GetStringBoundingBox(STR_COMPANY_MONEY); d = GetStringBoundingBox(STR_COMPANY_MONEY);
break; break;

View File

@ -500,8 +500,7 @@ static void ResetLandscapeConfirmationCallback(Window *w, bool confirmed)
_generating_world = true; _generating_world = true;
/* Delete all companies */ /* Delete all companies */
Company *c; for (Company *c : Company::Iterate()) {
FOR_ALL_COMPANIES(c) {
ChangeOwnershipOfCompanyItems(c->index, INVALID_OWNER); ChangeOwnershipOfCompanyItems(c->index, INVALID_OWNER);
delete c; delete c;
} }

View File

@ -3294,8 +3294,7 @@ static void ForAllStationsNearTown(Town *t, Func func)
static void UpdateTownRating(Town *t) static void UpdateTownRating(Town *t)
{ {
/* Increase company ratings if they're low */ /* Increase company ratings if they're low */
const Company *c; for (const Company *c : Company::Iterate()) {
FOR_ALL_COMPANIES(c) {
if (t->ratings[c->index] < RATING_GROWTH_MAXIMUM) { if (t->ratings[c->index] < RATING_GROWTH_MAXIMUM) {
t->ratings[c->index] = min((int)RATING_GROWTH_MAXIMUM, t->ratings[c->index] + RATING_GROWTH_UP_STEP); t->ratings[c->index] = min((int)RATING_GROWTH_MAXIMUM, t->ratings[c->index] + RATING_GROWTH_UP_STEP);
} }
@ -3451,9 +3450,7 @@ static void UpdateTownAmounts(Town *t)
static void UpdateTownUnwanted(Town *t) static void UpdateTownUnwanted(Town *t)
{ {
const Company *c; for (const Company *c : Company::Iterate()) {
FOR_ALL_COMPANIES(c) {
if (t->unwanted[c->index] > 0) t->unwanted[c->index]--; if (t->unwanted[c->index] > 0) t->unwanted[c->index]--;
} }
} }

View File

@ -149,8 +149,7 @@ public:
uint exclusive_left = rtl ? right - icon_width - exclusive_width - 2 : left + icon_width + 2; uint exclusive_left = rtl ? right - icon_width - exclusive_width - 2 : left + icon_width + 2;
/* Draw list of companies */ /* Draw list of companies */
const Company *c; for (const Company *c : Company::Iterate()) {
FOR_ALL_COMPANIES(c) {
if ((HasBit(this->town->have_ratings, c->index) || this->town->exclusivity == c->index)) { if ((HasBit(this->town->have_ratings, c->index) || this->town->exclusivity == c->index)) {
DrawCompanyIcon(c->index, icon_left, y + icon_y_offset); DrawCompanyIcon(c->index, icon_left, y + icon_y_offset);