mirror of https://github.com/OpenTTD/OpenTTD.git
Codechange: Replace FOR_ALL_COMPANIES with range-based for loops
This commit is contained in:
parent
68f22134cb
commit
3a14cea068
|
@ -75,8 +75,7 @@
|
|||
if ((AI::frame_counter & ((1 << (4 - _settings_game.difficulty.competitor_speed)) - 1)) != 0) return;
|
||||
|
||||
Backup<CompanyID> cur_company(_current_company, FILE_LINE);
|
||||
const Company *c;
|
||||
FOR_ALL_COMPANIES(c) {
|
||||
for (const Company *c : Company::Iterate()) {
|
||||
if (c->is_ai) {
|
||||
PerformanceMeasurer framerate((PerformanceElement)(PFE_AI0 + c->index));
|
||||
cur_company.Change(c->index);
|
||||
|
@ -154,8 +153,7 @@
|
|||
/* It might happen there are no companies .. than we have nothing to loop */
|
||||
if (Company::GetPoolSize() == 0) return;
|
||||
|
||||
const Company *c;
|
||||
FOR_ALL_COMPANIES(c) {
|
||||
for (const Company *c : Company::Iterate()) {
|
||||
if (c->is_ai) AI::Stop(c->index);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1052,8 +1052,7 @@ struct AIDebugWindow : public Window {
|
|||
|
||||
ai_debug_company = INVALID_COMPANY;
|
||||
|
||||
const Company *c;
|
||||
FOR_ALL_COMPANIES(c) {
|
||||
for (const Company *c : Company::Iterate()) {
|
||||
if (c->is_ai) {
|
||||
ChangeToAI(c->index);
|
||||
return;
|
||||
|
@ -1312,8 +1311,7 @@ struct AIDebugWindow : public Window {
|
|||
if ((_pause_mode & PM_PAUSED_NORMAL) == PM_PAUSED_NORMAL) {
|
||||
bool all_unpaused = !Game::IsPaused();
|
||||
if (all_unpaused) {
|
||||
Company *c;
|
||||
FOR_ALL_COMPANIES(c) {
|
||||
for (const Company *c : Company::Iterate()) {
|
||||
if (c->is_ai && AI::IsPaused(c->index)) {
|
||||
all_unpaused = false;
|
||||
break;
|
||||
|
@ -1552,8 +1550,7 @@ void ShowAIDebugWindowIfAIError()
|
|||
/* Network clients can't debug AIs. */
|
||||
if (_networking && !_network_server) return;
|
||||
|
||||
Company *c;
|
||||
FOR_ALL_COMPANIES(c) {
|
||||
for (const Company *c : Company::Iterate()) {
|
||||
if (c->is_ai && c->ai_instance->IsDead()) {
|
||||
ShowAIDebugWindow(c->index);
|
||||
break;
|
||||
|
|
|
@ -168,9 +168,6 @@ struct Company : CompanyPool::PoolItem<&_company_pool>, CompanyProperties {
|
|||
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);
|
||||
|
||||
extern uint _next_competitor_start;
|
||||
|
|
|
@ -263,8 +263,7 @@ void SubtractMoneyFromCompanyFract(CompanyID company, CommandCost cst)
|
|||
/** Update the landscaping limits per company. */
|
||||
void UpdateLandscapingLimits()
|
||||
{
|
||||
Company *c;
|
||||
FOR_ALL_COMPANIES(c) {
|
||||
for (Company *c : Company::Iterate()) {
|
||||
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->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:;
|
||||
/* No companies must have this name already */
|
||||
Company *cc;
|
||||
FOR_ALL_COMPANIES(cc) {
|
||||
for (const Company *cc : Company::Iterate()) {
|
||||
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 */
|
||||
Company *c;
|
||||
FOR_ALL_COMPANIES(c) {
|
||||
for (const Company *c : Company::Iterate()) {
|
||||
Colours pcolour = (Colours)c->colour;
|
||||
|
||||
for (uint i = 0; i < COLOUR_END; i++) {
|
||||
|
@ -494,8 +491,7 @@ restart:;
|
|||
GetString(buffer, STR_PRESIDENT_NAME, lastof(buffer));
|
||||
if (Utf8StringLength(buffer) >= MAX_LENGTH_PRESIDENT_NAME_CHARS) continue;
|
||||
|
||||
Company *cc;
|
||||
FOR_ALL_COMPANIES(cc) {
|
||||
for (const Company *cc : Company::Iterate()) {
|
||||
if (c != cc) {
|
||||
/* Reserve extra space so even overlength president names can be compared. */
|
||||
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;
|
||||
|
||||
Company *c;
|
||||
|
||||
/* count number of competitors */
|
||||
uint n = 0;
|
||||
FOR_ALL_COMPANIES(c) {
|
||||
for (const Company *c : Company::Iterate()) {
|
||||
if (c->is_ai) n++;
|
||||
}
|
||||
|
||||
|
@ -671,11 +665,11 @@ static void HandleBankruptcyTakeover(Company *c)
|
|||
/* Did we ask everyone for bankruptcy? If so, bail out. */
|
||||
if (c->bankrupt_asked == MAX_UVALUE(CompanyMask)) return;
|
||||
|
||||
Company *c2, *best = nullptr;
|
||||
Company *best = nullptr;
|
||||
int32 best_performance = -1;
|
||||
|
||||
/* 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
|
||||
!HasBit(c->bankrupt_asked, c2->index) &&
|
||||
best_performance < c2->old_economy[1].performance_history &&
|
||||
|
@ -737,10 +731,8 @@ void OnTick_Companies()
|
|||
*/
|
||||
void CompaniesYearlyLoop()
|
||||
{
|
||||
Company *c;
|
||||
|
||||
/* 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]));
|
||||
memset(&c->yearly_expenses[0], 0, sizeof(c->yearly_expenses[0]));
|
||||
SetWindowDirty(WC_FINANCES, c->index);
|
||||
|
@ -748,7 +740,7 @@ void CompaniesYearlyLoop()
|
|||
|
||||
if (_settings_client.gui.show_finances && _local_company != COMPANY_SPECTATOR) {
|
||||
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 (_settings_client.sound.new_year) SndPlayFx(SND_01_BAD_YEAR);
|
||||
} else {
|
||||
|
@ -971,8 +963,7 @@ CommandCost CmdSetCompanyColour(TileIndex tile, DoCommandFlag flags, uint32 p1,
|
|||
|
||||
/* Ensure no two companies have the same primary colour */
|
||||
if (scheme == LS_DEFAULT && !second) {
|
||||
const Company *cc;
|
||||
FOR_ALL_COMPANIES(cc) {
|
||||
for (const Company *cc : Company::Iterate()) {
|
||||
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)
|
||||
{
|
||||
const Company *c;
|
||||
|
||||
FOR_ALL_COMPANIES(c) {
|
||||
for (const Company *c : Company::Iterate()) {
|
||||
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)
|
||||
{
|
||||
const Company *c;
|
||||
|
||||
FOR_ALL_COMPANIES(c) {
|
||||
for (const Company *c : Company::Iterate()) {
|
||||
if (c->president_name != nullptr && strcmp(c->president_name, name) == 0) return false;
|
||||
}
|
||||
|
||||
|
|
|
@ -574,7 +574,7 @@ private:
|
|||
|
||||
/* Disallow other company colours for the primary colour */
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
@ -2396,9 +2396,7 @@ struct CompanyWindow : Window
|
|||
break;
|
||||
|
||||
case WID_C_DESC_OWNERS: {
|
||||
const Company *c2;
|
||||
|
||||
FOR_ALL_COMPANIES(c2) {
|
||||
for (const Company *c2 : Company::Iterate()) {
|
||||
SetDParamMaxValue(0, 75);
|
||||
SetDParam(1, c2->index);
|
||||
|
||||
|
@ -2500,10 +2498,9 @@ struct CompanyWindow : Window
|
|||
}
|
||||
|
||||
case WID_C_DESC_OWNERS: {
|
||||
const Company *c2;
|
||||
uint y = r.top;
|
||||
|
||||
FOR_ALL_COMPANIES(c2) {
|
||||
for (const Company *c2 : Company::Iterate()) {
|
||||
uint amt = GetAmountOwnedBy(c, c2->index);
|
||||
if (amt != 0) {
|
||||
SetDParam(0, amt * 25);
|
||||
|
|
|
@ -1142,9 +1142,8 @@ DEF_CONSOLE_CMD(ConStartAI)
|
|||
}
|
||||
|
||||
int n = 0;
|
||||
Company *c;
|
||||
/* Find the next free slot */
|
||||
FOR_ALL_COMPANIES(c) {
|
||||
for (const Company *c : Company::Iterate()) {
|
||||
if (c->index != n) break;
|
||||
n++;
|
||||
}
|
||||
|
@ -1535,8 +1534,7 @@ DEF_CONSOLE_CMD(ConCompanies)
|
|||
return true;
|
||||
}
|
||||
|
||||
Company *c;
|
||||
FOR_ALL_COMPANIES(c) {
|
||||
for (const Company *c : Company::Iterate()) {
|
||||
/* Grab the company name */
|
||||
char company_name[512];
|
||||
SetDParam(0, c->index);
|
||||
|
|
|
@ -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);
|
||||
const Company *c;
|
||||
FOR_ALL_COMPANIES(c) {
|
||||
for (const Company *c : Company::Iterate()) {
|
||||
if (c->ai_info == nullptr) {
|
||||
buffer += seprintf(buffer, last, " %2i: Human\n", (int)c->index);
|
||||
} else {
|
||||
|
|
|
@ -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. */
|
||||
assert(!_networking);
|
||||
Backup<CompanyID> cur_company2(_current_company, FILE_LINE);
|
||||
Company *c;
|
||||
FOR_ALL_COMPANIES(c) {
|
||||
for (const Company *c : Company::Iterate()) {
|
||||
if (c->index != old_owner) {
|
||||
SetLocalCompany(c->index);
|
||||
break;
|
||||
|
@ -313,11 +312,10 @@ void ChangeOwnershipOfCompanyItems(Owner old_owner, Owner new_owner)
|
|||
assert(old_owner != new_owner);
|
||||
|
||||
{
|
||||
Company *c;
|
||||
uint i;
|
||||
|
||||
/* 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++) {
|
||||
if (c->share_owners[i] == old_owner) {
|
||||
/* 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 */
|
||||
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++) {
|
||||
cur_company2.Change(c->share_owners[i]);
|
||||
if (_current_company != INVALID_OWNER) {
|
||||
|
@ -658,8 +656,7 @@ static void CompanyCheckBankrupt(Company *c)
|
|||
static void CompaniesGenStatistics()
|
||||
{
|
||||
/* Check for bankruptcy each month */
|
||||
Company *c;
|
||||
FOR_ALL_COMPANIES(c) {
|
||||
for (Company *c : Company::Iterate()) {
|
||||
CompanyCheckBankrupt(c);
|
||||
}
|
||||
|
||||
|
@ -674,7 +671,7 @@ static void CompaniesGenStatistics()
|
|||
}
|
||||
} else {
|
||||
/* Improved monthly infrastructure costs. */
|
||||
FOR_ALL_COMPANIES(c) {
|
||||
for (const Company *c : Company::Iterate()) {
|
||||
cur_company.Change(c->index);
|
||||
|
||||
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). */
|
||||
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 */
|
||||
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;
|
||||
|
@ -833,10 +830,8 @@ void RecomputePrices()
|
|||
/** Let all companies pay the monthly interest on their loan. */
|
||||
static void CompaniesPayInterest()
|
||||
{
|
||||
const Company *c;
|
||||
|
||||
Backup<CompanyID> cur_company(_current_company, FILE_LINE);
|
||||
FOR_ALL_COMPANIES(c) {
|
||||
for (const Company *c : Company::Iterate()) {
|
||||
cur_company.Change(c->index);
|
||||
|
||||
/* Over a year the paid interest should be "loan * interest percentage",
|
||||
|
|
|
@ -591,7 +591,6 @@ void DrawRailCatenary(const TileInfo *ti)
|
|||
|
||||
bool SettingsDisableElrail(int32 p1)
|
||||
{
|
||||
Company *c;
|
||||
Train *t;
|
||||
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
|
||||
* rails. It may have unintended consequences if that function is ever
|
||||
|
|
|
@ -703,8 +703,7 @@ void StartupEngines()
|
|||
}
|
||||
|
||||
/* Update the bitmasks for the vehicle lists */
|
||||
Company *c;
|
||||
FOR_ALL_COMPANIES(c) {
|
||||
for (Company *c : Company::Iterate()) {
|
||||
c->avail_railtypes = GetCompanyRailtypes(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;
|
||||
|
||||
int32 best_hist = -1;
|
||||
const Company *c;
|
||||
FOR_ALL_COMPANIES(c) {
|
||||
for (const Company *c : Company::Iterate()) {
|
||||
if (c->block_preview == 0 && !HasBit(e->preview_asked, c->index) &&
|
||||
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. */
|
||||
void EnginesDailyLoop()
|
||||
{
|
||||
Company *c;
|
||||
FOR_ALL_COMPANIES(c) {
|
||||
for (Company *c : Company::Iterate()) {
|
||||
c->avail_railtypes = AddDateIntroducedRailTypes(c->avail_railtypes, _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)
|
||||
{
|
||||
Vehicle *v;
|
||||
Company *c;
|
||||
EngineID index = e->index;
|
||||
|
||||
/* In case the company didn't build the vehicle during the intro period,
|
||||
* prevent that company from getting future intro periods for a while. */
|
||||
if (e->flags & ENGINE_EXCLUSIVE_PREVIEW) {
|
||||
FOR_ALL_COMPANIES(c) {
|
||||
for (Company *c : Company::Iterate()) {
|
||||
uint block_preview = c->block_preview;
|
||||
|
||||
if (!HasBit(e->company_avail, c->index)) continue;
|
||||
|
@ -948,11 +944,11 @@ static void NewVehicleAvailable(Engine *e)
|
|||
/* maybe make another rail type available */
|
||||
RailType railtype = e->u.rail.railtype;
|
||||
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) {
|
||||
/* maybe make another road type available */
|
||||
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. */
|
||||
|
|
|
@ -567,8 +567,7 @@ public:
|
|||
}
|
||||
|
||||
byte nums = 0;
|
||||
const Company *c;
|
||||
FOR_ALL_COMPANIES(c) {
|
||||
for (const Company *c : Company::Iterate()) {
|
||||
nums = min(this->num_vert_lines, max(nums, c->num_valid_stat_ent));
|
||||
}
|
||||
|
||||
|
@ -592,7 +591,7 @@ public:
|
|||
|
||||
int numd = 0;
|
||||
for (CompanyID k = COMPANY_FIRST; k < MAX_COMPANIES; k++) {
|
||||
c = Company::GetIfValid(k);
|
||||
const Company *c = Company::GetIfValid(k);
|
||||
if (c != nullptr) {
|
||||
this->colours[numd] = _colour_gradient[c->colour][6];
|
||||
for (int j = this->num_on_x_axis, i = 0; --j >= 0;) {
|
||||
|
@ -1136,8 +1135,7 @@ private:
|
|||
|
||||
this->companies.clear();
|
||||
|
||||
const Company *c;
|
||||
FOR_ALL_COMPANIES(c) {
|
||||
for (const Company *c : Company::Iterate()) {
|
||||
this->companies.push_back(c);
|
||||
}
|
||||
|
||||
|
@ -1219,8 +1217,7 @@ public:
|
|||
this->icon_width = d.width + 2;
|
||||
this->line_height = max<int>(d.height + 2, FONT_HEIGHT_NORMAL);
|
||||
|
||||
const Company *c;
|
||||
FOR_ALL_COMPANIES(c) {
|
||||
for (const Company *c : Company::Iterate()) {
|
||||
SetDParam(0, c->index);
|
||||
SetDParam(1, c->index);
|
||||
SetDParam(2, _performance_titles[widest_title]);
|
||||
|
@ -1299,8 +1296,7 @@ struct PerformanceRatingDetailWindow : Window {
|
|||
{
|
||||
/* Update all company stats with the current data
|
||||
* (this is because _score_info is not saved to a savegame) */
|
||||
Company *c;
|
||||
FOR_ALL_COMPANIES(c) {
|
||||
for (Company *c : Company::Iterate()) {
|
||||
UpdateCompanyRatingAndValue(c, false);
|
||||
}
|
||||
|
||||
|
@ -1497,8 +1493,7 @@ struct PerformanceRatingDetailWindow : Window {
|
|||
}
|
||||
|
||||
if (this->company == INVALID_COMPANY) {
|
||||
const Company *c;
|
||||
FOR_ALL_COMPANIES(c) {
|
||||
for (const Company *c : Company::Iterate()) {
|
||||
this->company = c->index;
|
||||
break;
|
||||
}
|
||||
|
|
|
@ -101,8 +101,7 @@ void GroupStatistics::Clear()
|
|||
/* static */ void GroupStatistics::UpdateAfterLoad()
|
||||
{
|
||||
/* Set up the engine count for all companies */
|
||||
Company *c;
|
||||
FOR_ALL_COMPANIES(c) {
|
||||
for (Company *c : Company::Iterate()) {
|
||||
for (VehicleType type = VEH_BEGIN; type < VEH_COMPANY_END; type++) {
|
||||
c->group_all[type].Clear();
|
||||
c->group_default[type].Clear();
|
||||
|
@ -123,7 +122,7 @@ void GroupStatistics::Clear()
|
|||
if (v->IsPrimaryVehicle()) GroupStatistics::CountVehicle(v, 1);
|
||||
}
|
||||
|
||||
FOR_ALL_COMPANIES(c) {
|
||||
for (const Company *c : Company::Iterate()) {
|
||||
GroupStatistics::UpdateAutoreplace(c->index);
|
||||
}
|
||||
}
|
||||
|
@ -183,8 +182,7 @@ void GroupStatistics::Clear()
|
|||
/* static */ void GroupStatistics::UpdateProfits()
|
||||
{
|
||||
/* Set up the engine count for all companies */
|
||||
Company *c;
|
||||
FOR_ALL_COMPANIES(c) {
|
||||
for (Company *c : Company::Iterate()) {
|
||||
for (VehicleType type = VEH_BEGIN; type < VEH_COMPANY_END; type++) {
|
||||
c->group_all[type].ClearProfits();
|
||||
c->group_default[type].ClearProfits();
|
||||
|
|
|
@ -87,13 +87,12 @@ static bool HighScoreSorter(const Company * const &a, const Company * const &b)
|
|||
*/
|
||||
int8 SaveHighScoreValueNetwork()
|
||||
{
|
||||
const Company *c;
|
||||
const Company *cl[MAX_COMPANIES];
|
||||
uint count = 0;
|
||||
int8 company = -1;
|
||||
|
||||
/* 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);
|
||||
|
||||
|
|
|
@ -399,8 +399,7 @@ NetworkRecvStatus ServerNetworkAdminSocketHandler::SendCompanyRemove(CompanyID c
|
|||
/** Send economic information of all companies. */
|
||||
NetworkRecvStatus ServerNetworkAdminSocketHandler::SendCompanyEconomy()
|
||||
{
|
||||
const Company *company;
|
||||
FOR_ALL_COMPANIES(company) {
|
||||
for (const Company *company : Company::Iterate()) {
|
||||
/* Get the income. */
|
||||
Money income = 0;
|
||||
for (uint i = 0; i < lengthof(company->yearly_expenses[0]); i++) {
|
||||
|
@ -438,10 +437,8 @@ NetworkRecvStatus ServerNetworkAdminSocketHandler::SendCompanyStats()
|
|||
NetworkCompanyStats company_stats[MAX_COMPANIES];
|
||||
NetworkPopulateCompanyStats(company_stats);
|
||||
|
||||
const Company *company;
|
||||
|
||||
/* Go through all the companies. */
|
||||
FOR_ALL_COMPANIES(company) {
|
||||
for (const Company *company : Company::Iterate()) {
|
||||
Packet *p = new Packet(ADMIN_PACKET_SERVER_COMPANY_STATS);
|
||||
|
||||
/* Send the information. */
|
||||
|
@ -748,13 +745,12 @@ NetworkRecvStatus ServerNetworkAdminSocketHandler::Receive_ADMIN_POLL(Packet *p)
|
|||
|
||||
case ADMIN_UPDATE_COMPANY_INFO:
|
||||
/* The admin is asking for company info. */
|
||||
const Company *company;
|
||||
if (d1 == UINT32_MAX) {
|
||||
FOR_ALL_COMPANIES(company) {
|
||||
for (const Company *company : Company::Iterate()) {
|
||||
this->SendCompanyInfo(company);
|
||||
}
|
||||
} else {
|
||||
company = Company::GetIfValid(d1);
|
||||
const Company *company = Company::GetIfValid(d1);
|
||||
if (company != nullptr) this->SendCompanyInfo(company);
|
||||
}
|
||||
break;
|
||||
|
|
|
@ -380,10 +380,9 @@ NetworkRecvStatus ServerNetworkGameSocketHandler::SendCompanyInfo()
|
|||
|
||||
/* Now send the data */
|
||||
|
||||
Company *company;
|
||||
Packet *p;
|
||||
|
||||
FOR_ALL_COMPANIES(company) {
|
||||
for (const Company *company : Company::Iterate()) {
|
||||
p = new Packet(PACKET_SERVER_COMPANY_INFO);
|
||||
|
||||
p->Send_uint8 (NETWORK_COMPANY_INFO_VERSION);
|
||||
|
@ -1619,7 +1618,6 @@ static void NetworkCheckRestartMap()
|
|||
static void NetworkAutoCleanCompanies()
|
||||
{
|
||||
const NetworkClientInfo *ci;
|
||||
const Company *c;
|
||||
bool clients_in_company[MAX_COMPANIES];
|
||||
int vehicles_in_company[MAX_COMPANIES];
|
||||
|
||||
|
@ -1648,7 +1646,7 @@ static void NetworkAutoCleanCompanies()
|
|||
}
|
||||
|
||||
/* Go through all the companies */
|
||||
FOR_ALL_COMPANIES(c) {
|
||||
for (const Company *c : Company::Iterate()) {
|
||||
/* Skip the non-active once */
|
||||
if (c->is_ai) continue;
|
||||
|
||||
|
|
|
@ -198,8 +198,7 @@ void ServerNetworkUDPSocketHandler::Receive_CLIENT_DETAIL_INFO(Packet *p, Networ
|
|||
|
||||
for (;;) {
|
||||
int free = SEND_MTU - packet.size;
|
||||
Company *company;
|
||||
FOR_ALL_COMPANIES(company) {
|
||||
for (const Company *company : Company::Iterate()) {
|
||||
char company_name[NETWORK_COMPANY_NAME_LENGTH];
|
||||
SetDParam(0, company->index);
|
||||
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 */
|
||||
FOR_ALL_COMPANIES(company) {
|
||||
for (const Company *company : Company::Iterate()) {
|
||||
/* Send the information */
|
||||
this->SendCompanyInformation(&packet, company, &company_stats[company->index], max_cname_length);
|
||||
}
|
||||
|
|
|
@ -1207,14 +1207,13 @@ static void CheckCaches()
|
|||
|
||||
/* Check company infrastructure cache. */
|
||||
std::vector<CompanyInfrastructure> old_infrastructure;
|
||||
Company *c;
|
||||
FOR_ALL_COMPANIES(c) old_infrastructure.push_back(c->infrastructure);
|
||||
for (const Company *c : Company::Iterate()) old_infrastructure.push_back(c->infrastructure);
|
||||
|
||||
extern void AfterLoadCompanyStats();
|
||||
AfterLoadCompanyStats();
|
||||
|
||||
i = 0;
|
||||
FOR_ALL_COMPANIES(c) {
|
||||
for (const Company *c : Company::Iterate()) {
|
||||
if (MemCmpT(old_infrastructure.data() + i, &c->infrastructure) != 0) {
|
||||
DEBUG(desync, 2, "infrastructure cache mismatch: company %i", (int)c->index);
|
||||
}
|
||||
|
|
|
@ -243,8 +243,7 @@ static void InitializeWindowsAndCaches()
|
|||
UpdateAllVirtCoords();
|
||||
ResetViewportAfterLoadGame();
|
||||
|
||||
Company *c;
|
||||
FOR_ALL_COMPANIES(c) {
|
||||
for (Company *c : Company::Iterate()) {
|
||||
/* 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,
|
||||
* thus the MIN_YEAR (which is really nothing more than Zero, initialized value) test */
|
||||
|
@ -644,8 +643,7 @@ bool AfterLoadGame()
|
|||
}
|
||||
|
||||
if (IsSavegameVersionBefore(SLV_84)) {
|
||||
Company *c;
|
||||
FOR_ALL_COMPANIES(c) {
|
||||
for (Company *c : Company::Iterate()) {
|
||||
c->name = CopyFromOldName(c->name_1);
|
||||
if (c->name != nullptr) c->name_1 = STR_SV_UNNAMED;
|
||||
c->president_name = CopyFromOldName(c->president_name_1);
|
||||
|
@ -678,8 +676,7 @@ bool AfterLoadGame()
|
|||
}
|
||||
|
||||
/* the same applies to Company::location_of_HQ */
|
||||
Company *c;
|
||||
FOR_ALL_COMPANIES(c) {
|
||||
for (Company *c : Company::Iterate()) {
|
||||
if (c->location_of_HQ == 0 || (IsSavegameVersionBefore(SLV_4) && c->location_of_HQ == 0xFFFF)) {
|
||||
c->location_of_HQ = INVALID_TILE;
|
||||
}
|
||||
|
@ -800,8 +797,7 @@ bool AfterLoadGame()
|
|||
|
||||
/* Make sure there is an AI attached to an AI company */
|
||||
{
|
||||
Company *c;
|
||||
FOR_ALL_COMPANIES(c) {
|
||||
for (const Company *c : Company::Iterate()) {
|
||||
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
|
||||
* of course, we do need to initialize them for older savegames. */
|
||||
if (IsSavegameVersionBefore(SLV_16)) {
|
||||
Company *c;
|
||||
FOR_ALL_COMPANIES(c) {
|
||||
for (Company *c : Company::Iterate()) {
|
||||
c->engine_renew_list = nullptr;
|
||||
c->settings.engine_renew = false;
|
||||
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
|
||||
* companies are 'invalid'.
|
||||
*/
|
||||
c = Company::GetIfValid(COMPANY_FIRST);
|
||||
Company *c = Company::GetIfValid(COMPANY_FIRST);
|
||||
if (!_network_dedicated && c != nullptr) {
|
||||
c->settings = _settings_client.company;
|
||||
}
|
||||
|
@ -1349,8 +1344,7 @@ bool AfterLoadGame()
|
|||
* replaced, shall keep their old length. In all prior versions, just default
|
||||
* to false */
|
||||
if (IsSavegameVersionBefore(SLV_16, 1)) {
|
||||
Company *c;
|
||||
FOR_ALL_COMPANIES(c) c->settings.renew_keep_length = false;
|
||||
for (Company *c : Company::Iterate()) c->settings.renew_keep_length = false;
|
||||
}
|
||||
|
||||
if (IsSavegameVersionBefore(SLV_123)) {
|
||||
|
@ -1413,12 +1407,10 @@ bool AfterLoadGame()
|
|||
YapfNotifyTrackLayoutChange(INVALID_TILE, INVALID_TRACK);
|
||||
|
||||
if (IsSavegameVersionBefore(SLV_34)) {
|
||||
Company *c;
|
||||
FOR_ALL_COMPANIES(c) ResetCompanyLivery(c);
|
||||
for (Company *c : Company::Iterate()) ResetCompanyLivery(c);
|
||||
}
|
||||
|
||||
Company *c;
|
||||
FOR_ALL_COMPANIES(c) {
|
||||
for (Company *c : Company::Iterate()) {
|
||||
c->avail_railtypes = GetCompanyRailtypes(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_WAYPOINTS(wp) wp->build_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_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)) {
|
||||
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())
|
||||
* 2) shares that are owned by inactive companies or self
|
||||
* (caused by cheating clients in earlier revisions) */
|
||||
FOR_ALL_COMPANIES(c) {
|
||||
for (Company *c : Company::Iterate()) {
|
||||
for (uint i = 0; i < 4; i++) {
|
||||
CompanyID company = c->share_owners[i];
|
||||
if (company == INVALID_COMPANY) continue;
|
||||
|
@ -2061,8 +2053,7 @@ bool AfterLoadGame()
|
|||
}
|
||||
|
||||
/* More companies ... */
|
||||
Company *c;
|
||||
FOR_ALL_COMPANIES(c) {
|
||||
for (Company *c : Company::Iterate()) {
|
||||
if (c->bankrupt_asked == 0xFF) c->bankrupt_asked = 0xFFFF;
|
||||
}
|
||||
|
||||
|
@ -2199,8 +2190,7 @@ bool AfterLoadGame()
|
|||
|
||||
if (IsSavegameVersionBefore(SLV_120)) {
|
||||
extern VehicleDefaultSettings _old_vds;
|
||||
Company *c;
|
||||
FOR_ALL_COMPANIES(c) {
|
||||
for (Company *c : Company::Iterate()) {
|
||||
c->settings.vehicle = _old_vds;
|
||||
}
|
||||
}
|
||||
|
@ -2663,8 +2653,7 @@ bool AfterLoadGame()
|
|||
}
|
||||
|
||||
/* Introduced terraform/clear limits. */
|
||||
Company *c;
|
||||
FOR_ALL_COMPANIES(c) {
|
||||
for (Company *c : Company::Iterate()) {
|
||||
c->terraform_limit = _settings_game.construction.terraform_frame_burst << 16;
|
||||
c->clear_limit = _settings_game.construction.clear_frame_burst << 16;
|
||||
}
|
||||
|
@ -2923,8 +2912,7 @@ bool AfterLoadGame()
|
|||
|
||||
if (IsSavegameVersionBefore(SLV_175)) {
|
||||
/* Introduced tree planting limit. */
|
||||
Company *c;
|
||||
FOR_ALL_COMPANIES(c) c->tree_limit = _settings_game.construction.tree_frame_burst << 16;
|
||||
for (Company *c : Company::Iterate()) c->tree_limit = _settings_game.construction.tree_frame_burst << 16;
|
||||
}
|
||||
|
||||
if (IsSavegameVersionBefore(SLV_177)) {
|
||||
|
@ -2933,7 +2921,7 @@ bool AfterLoadGame()
|
|||
if (_economy.inflation_payment > MAX_INFLATION) _economy.inflation_payment = MAX_INFLATION;
|
||||
|
||||
/* 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;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -94,8 +94,7 @@ CompanyManagerFace ConvertFromOldCompanyManagerFace(uint32 face)
|
|||
void AfterLoadCompanyStats()
|
||||
{
|
||||
/* Reset infrastructure statistics to zero. */
|
||||
Company *c;
|
||||
FOR_ALL_COMPANIES(c) MemSetT(&c->infrastructure, 0);
|
||||
for (Company *c : Company::Iterate()) MemSetT(&c->infrastructure, 0);
|
||||
|
||||
/* Collect airport count. */
|
||||
Station *st;
|
||||
|
@ -105,6 +104,7 @@ void AfterLoadCompanyStats()
|
|||
}
|
||||
}
|
||||
|
||||
Company *c;
|
||||
for (TileIndex tile = 0; tile < MapSize(); tile++) {
|
||||
switch (GetTileType(tile)) {
|
||||
case MP_RAILWAY:
|
||||
|
@ -486,8 +486,7 @@ static void SaveLoad_PLYR(Company *c)
|
|||
|
||||
static void Save_PLYR()
|
||||
{
|
||||
Company *c;
|
||||
FOR_ALL_COMPANIES(c) {
|
||||
for (Company *c : Company::Iterate()) {
|
||||
SlSetArrayIndex(c->index);
|
||||
SlAutolength((AutolengthProc*)SaveLoad_PLYR, c);
|
||||
}
|
||||
|
@ -534,8 +533,7 @@ static void Check_PLYR()
|
|||
|
||||
static void Ptrs_PLYR()
|
||||
{
|
||||
Company *c;
|
||||
FOR_ALL_COMPANIES(c) {
|
||||
for (Company *c : Company::Iterate()) {
|
||||
SlObject(c, _company_settings_desc);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -459,8 +459,7 @@ static bool FixTTOEngines()
|
|||
|
||||
static void FixTTOCompanies()
|
||||
{
|
||||
Company *c;
|
||||
FOR_ALL_COMPANIES(c) {
|
||||
for (Company *c : Company::Iterate()) {
|
||||
c->cur_economy.company_value = CalculateCompanyValue(c); // company value history is zeroed
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2816,8 +2816,7 @@ void GenerateDefaultSaveName(char *buf, const char *last)
|
|||
* 'Spectator' as "company" name. */
|
||||
CompanyID cid = _local_company;
|
||||
if (!Company::IsValidID(cid)) {
|
||||
const Company *c;
|
||||
FOR_ALL_COMPANIES(c) {
|
||||
for (const Company *c : Company::Iterate()) {
|
||||
cid = c->index;
|
||||
break;
|
||||
}
|
||||
|
|
|
@ -315,8 +315,7 @@ static bool MakePNGImage(const char *name, ScreenshotCallback *callb, void *user
|
|||
p += seprintf(p, lastof(buf), " %s\n", c->filename);
|
||||
}
|
||||
p = strecpy(p, "\nCompanies:\n", lastof(buf));
|
||||
const Company *c;
|
||||
FOR_ALL_COMPANIES(c) {
|
||||
for (const Company *c : Company::Iterate()) {
|
||||
if (c->ai_info == nullptr) {
|
||||
p += seprintf(p, lastof(buf), "%2i: Human\n", (int)c->index);
|
||||
} else {
|
||||
|
|
|
@ -333,8 +333,7 @@ void BuildOwnerLegend()
|
|||
_legend_land_owners[1].colour = _heightmap_schemes[_settings_client.gui.smallmap_land_colour].default_colour;
|
||||
|
||||
int i = NUM_NO_COMPANY_ENTRIES;
|
||||
const Company *c;
|
||||
FOR_ALL_COMPANIES(c) {
|
||||
for (const Company *c : Company::Iterate()) {
|
||||
_legend_land_owners[i].colour = _colour_gradient[c->colour][5];
|
||||
_legend_land_owners[i].company = c->index;
|
||||
_legend_land_owners[i].show_on_map = true;
|
||||
|
|
|
@ -120,8 +120,7 @@ struct StatusBarWindow : Window {
|
|||
|
||||
case WID_S_RIGHT: {
|
||||
int64 max_money = UINT32_MAX;
|
||||
const Company *c;
|
||||
FOR_ALL_COMPANIES(c) max_money = max<int64>(c->money, max_money);
|
||||
for (const Company *c : Company::Iterate()) max_money = max<int64>(c->money, max_money);
|
||||
SetDParam(0, 100LL * max_money);
|
||||
d = GetStringBoundingBox(STR_COMPANY_MONEY);
|
||||
break;
|
||||
|
|
|
@ -500,8 +500,7 @@ static void ResetLandscapeConfirmationCallback(Window *w, bool confirmed)
|
|||
_generating_world = true;
|
||||
|
||||
/* Delete all companies */
|
||||
Company *c;
|
||||
FOR_ALL_COMPANIES(c) {
|
||||
for (Company *c : Company::Iterate()) {
|
||||
ChangeOwnershipOfCompanyItems(c->index, INVALID_OWNER);
|
||||
delete c;
|
||||
}
|
||||
|
|
|
@ -3294,8 +3294,7 @@ static void ForAllStationsNearTown(Town *t, Func func)
|
|||
static void UpdateTownRating(Town *t)
|
||||
{
|
||||
/* Increase company ratings if they're low */
|
||||
const Company *c;
|
||||
FOR_ALL_COMPANIES(c) {
|
||||
for (const Company *c : Company::Iterate()) {
|
||||
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);
|
||||
}
|
||||
|
@ -3451,9 +3450,7 @@ static void UpdateTownAmounts(Town *t)
|
|||
|
||||
static void UpdateTownUnwanted(Town *t)
|
||||
{
|
||||
const Company *c;
|
||||
|
||||
FOR_ALL_COMPANIES(c) {
|
||||
for (const Company *c : Company::Iterate()) {
|
||||
if (t->unwanted[c->index] > 0) t->unwanted[c->index]--;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -149,8 +149,7 @@ public:
|
|||
uint exclusive_left = rtl ? right - icon_width - exclusive_width - 2 : left + icon_width + 2;
|
||||
|
||||
/* Draw list of companies */
|
||||
const Company *c;
|
||||
FOR_ALL_COMPANIES(c) {
|
||||
for (const Company *c : Company::Iterate()) {
|
||||
if ((HasBit(this->town->have_ratings, c->index) || this->town->exclusivity == c->index)) {
|
||||
DrawCompanyIcon(c->index, icon_left, y + icon_y_offset);
|
||||
|
||||
|
|
Loading…
Reference in New Issue