From 1ffc950e224990c887badc06d67af4dcb96fc734 Mon Sep 17 00:00:00 2001 From: Rubidium Date: Mon, 10 Feb 2025 17:49:30 +0100 Subject: [PATCH] Codechange: use prefix operator++ for CompanyID iterations --- src/ai/ai_core.cpp | 6 +++--- src/company_cmd.cpp | 2 +- src/graph_gui.cpp | 8 ++++---- src/linkgraph/linkgraph_gui.cpp | 8 ++++---- src/openttd.cpp | 4 ++-- src/saveload/afterload.cpp | 2 +- src/saveload/ai_sl.cpp | 4 ++-- src/saveload/randomizer_sl.cpp | 2 +- src/script/api/script_object.cpp | 2 +- src/script/script_gui.cpp | 2 +- src/settings.cpp | 6 +++--- src/toolbar_gui.cpp | 2 +- 12 files changed, 24 insertions(+), 24 deletions(-) diff --git a/src/ai/ai_core.cpp b/src/ai/ai_core.cpp index 050803b6ab..6827546bcb 100644 --- a/src/ai/ai_core.cpp +++ b/src/ai/ai_core.cpp @@ -190,7 +190,7 @@ AI::scanner_info = nullptr; AI::scanner_library = nullptr; - for (CompanyID c = COMPANY_FIRST; c < MAX_COMPANIES; c++) { + for (CompanyID c = COMPANY_FIRST; c < MAX_COMPANIES; ++c) { if (_settings_game.ai_config[c] != nullptr) { delete _settings_game.ai_config[c]; _settings_game.ai_config[c] = nullptr; @@ -208,7 +208,7 @@ /* Check for both newgame as current game if we can reload the AIInfo inside * the AIConfig. If not, remove the AI from the list (which will assign * a random new AI on reload). */ - for (CompanyID c = COMPANY_FIRST; c < MAX_COMPANIES; c++) { + for (CompanyID c = COMPANY_FIRST; c < MAX_COMPANIES; ++c) { if (_settings_game.ai_config[c] != nullptr && _settings_game.ai_config[c]->HasScript()) { if (!_settings_game.ai_config[c]->ResetInfo(true)) { Debug(script, 0, "After a reload, the AI by the name '{}' was no longer found, and removed from the list.", _settings_game.ai_config[c]->GetName()); @@ -270,7 +270,7 @@ } /* Try to send the event to all AIs */ - for (CompanyID c = COMPANY_FIRST; c < MAX_COMPANIES; c++) { + for (CompanyID c = COMPANY_FIRST; c < MAX_COMPANIES; ++c) { if (c != skip_company) AI::NewEvent(c, event); } } diff --git a/src/company_cmd.cpp b/src/company_cmd.cpp index a38f57125b..395687c024 100644 --- a/src/company_cmd.cpp +++ b/src/company_cmd.cpp @@ -1337,7 +1337,7 @@ CompanyID GetFirstPlayableCompanyID() } if (Company::CanAllocateItem()) { - for (CompanyID c = COMPANY_FIRST; c < MAX_COMPANIES; c++) { + for (CompanyID c = COMPANY_FIRST; c < MAX_COMPANIES; ++c) { if (!Company::IsValidID(c)) { return c; } diff --git a/src/graph_gui.cpp b/src/graph_gui.cpp index 69623cd385..04ed904565 100644 --- a/src/graph_gui.cpp +++ b/src/graph_gui.cpp @@ -54,7 +54,7 @@ struct GraphLegendWindow : Window { { this->InitNested(window_number); - for (CompanyID c = COMPANY_FIRST; c < MAX_COMPANIES; c++) { + for (CompanyID c = COMPANY_FIRST; c < MAX_COMPANIES; ++c) { if (!_legend_excluded_companies.Test(c)) this->LowerWidget(WID_GL_FIRST_COMPANY + c); this->OnInvalidateData(c); @@ -676,7 +676,7 @@ public: CompanyMask excluded_companies = _legend_excluded_companies; /* Exclude the companies which aren't valid */ - for (CompanyID c = COMPANY_FIRST; c < MAX_COMPANIES; c++) { + for (CompanyID c = COMPANY_FIRST; c < MAX_COMPANIES; ++c) { if (!Company::IsValidID(c)) excluded_companies.Set(c); } @@ -704,7 +704,7 @@ public: this->month = mo; this->data.clear(); - for (CompanyID k = COMPANY_FIRST; k < MAX_COMPANIES; k++) { + for (CompanyID k = COMPANY_FIRST; k < MAX_COMPANIES; ++k) { const Company *c = Company::GetIfValid(k); if (c == nullptr) continue; @@ -1460,7 +1460,7 @@ struct PerformanceRatingDetailWindow : Window { { if (!gui_scope) return; /* Disable the companies who are not active */ - for (CompanyID i = COMPANY_FIRST; i < MAX_COMPANIES; i++) { + for (CompanyID i = COMPANY_FIRST; i < MAX_COMPANIES; ++i) { this->SetWidgetDisabledState(WID_PRD_COMPANY_FIRST + i, !Company::IsValidID(i)); } diff --git a/src/linkgraph/linkgraph_gui.cpp b/src/linkgraph/linkgraph_gui.cpp index c40663bbb4..0348bf2496 100644 --- a/src/linkgraph/linkgraph_gui.cpp +++ b/src/linkgraph/linkgraph_gui.cpp @@ -561,7 +561,7 @@ void LinkGraphLegendWindow::SetOverlay(std::shared_ptr overlay { this->overlay = overlay; CompanyMask companies = this->overlay->GetCompanyMask(); - for (CompanyID c = COMPANY_FIRST; c < MAX_COMPANIES; c++) { + for (CompanyID c = COMPANY_FIRST; c < MAX_COMPANIES; ++c) { if (!this->IsWidgetDisabled(WID_LGL_COMPANY_FIRST + c)) { this->SetWidgetLoweredState(WID_LGL_COMPANY_FIRST + c, companies.Test(c)); } @@ -658,7 +658,7 @@ bool LinkGraphLegendWindow::OnTooltip([[maybe_unused]] Point, WidgetID widget, T void LinkGraphLegendWindow::UpdateOverlayCompanies() { CompanyMask mask; - for (CompanyID c = COMPANY_FIRST; c < MAX_COMPANIES; c++) { + for (CompanyID c = COMPANY_FIRST; c < MAX_COMPANIES; ++c) { if (this->IsWidgetDisabled(WID_LGL_COMPANY_FIRST + c)) continue; if (!this->IsWidgetLowered(WID_LGL_COMPANY_FIRST + c)) continue; mask.Set(c); @@ -688,7 +688,7 @@ void LinkGraphLegendWindow::OnClick([[maybe_unused]] Point pt, WidgetID widget, this->UpdateOverlayCompanies(); } } else if (widget == WID_LGL_COMPANIES_ALL || widget == WID_LGL_COMPANIES_NONE) { - for (CompanyID c = COMPANY_FIRST; c < MAX_COMPANIES; c++) { + for (CompanyID c = COMPANY_FIRST; c < MAX_COMPANIES; ++c) { if (this->IsWidgetDisabled(WID_LGL_COMPANY_FIRST + c)) continue; this->SetWidgetLoweredState(WID_LGL_COMPANY_FIRST + c, widget == WID_LGL_COMPANIES_ALL); } @@ -719,7 +719,7 @@ void LinkGraphLegendWindow::OnInvalidateData([[maybe_unused]] int data, [[maybe_ } /* Disable the companies who are not active */ - for (CompanyID i = COMPANY_FIRST; i < MAX_COMPANIES; i++) { + for (CompanyID i = COMPANY_FIRST; i < MAX_COMPANIES; ++i) { this->SetWidgetDisabledState(WID_LGL_COMPANY_FIRST + i, !Company::IsValidID(i)); } } diff --git a/src/openttd.cpp b/src/openttd.cpp index 8099a15147..e23a62d37e 100644 --- a/src/openttd.cpp +++ b/src/openttd.cpp @@ -341,7 +341,7 @@ static void LoadIntroGame(bool load_newgrfs = true) void MakeNewgameSettingsLive() { - for (CompanyID c = COMPANY_FIRST; c < MAX_COMPANIES; c++) { + for (CompanyID c = COMPANY_FIRST; c < MAX_COMPANIES; ++c) { if (_settings_game.ai_config[c] != nullptr) { delete _settings_game.ai_config[c]; } @@ -355,7 +355,7 @@ void MakeNewgameSettingsLive() _settings_game = _settings_newgame; _old_vds = _settings_client.company.vehicle; - for (CompanyID c = COMPANY_FIRST; c < MAX_COMPANIES; c++) { + for (CompanyID c = COMPANY_FIRST; c < MAX_COMPANIES; ++c) { _settings_game.ai_config[c] = nullptr; if (_settings_newgame.ai_config[c] != nullptr) { _settings_game.ai_config[c] = new AIConfig(_settings_newgame.ai_config[c]); diff --git a/src/saveload/afterload.cpp b/src/saveload/afterload.cpp index 2eb538fc42..60d39b2ea0 100644 --- a/src/saveload/afterload.cpp +++ b/src/saveload/afterload.cpp @@ -3416,7 +3416,7 @@ void ReloadNewGRFData() /* Delete news referring to no longer existing entities */ DeleteInvalidEngineNews(); /* Update livery selection windows */ - for (CompanyID i = COMPANY_FIRST; i < MAX_COMPANIES; i++) InvalidateWindowData(WC_COMPANY_COLOUR, i); + for (CompanyID i = COMPANY_FIRST; i < MAX_COMPANIES; ++i) InvalidateWindowData(WC_COMPANY_COLOUR, i); /* Update company infrastructure counts. */ InvalidateWindowClassesData(WC_COMPANY_INFRASTRUCTURE); InvalidateWindowClassesData(WC_BUILD_TOOLBAR); diff --git a/src/saveload/ai_sl.cpp b/src/saveload/ai_sl.cpp index 0d8490f17f..223200e7d1 100644 --- a/src/saveload/ai_sl.cpp +++ b/src/saveload/ai_sl.cpp @@ -80,7 +80,7 @@ struct AIPLChunkHandler : ChunkHandler { const std::vector slt = SlCompatTableHeader(_ai_company_desc, _ai_company_sl_compat); /* Free all current data */ - for (CompanyID c = COMPANY_FIRST; c < MAX_COMPANIES; c++) { + for (CompanyID c = COMPANY_FIRST; c < MAX_COMPANIES; ++c) { AIConfig::GetConfig(c, AIConfig::SSS_FORCE_GAME)->Change(std::nullopt); } @@ -160,7 +160,7 @@ struct AIPLChunkHandler : ChunkHandler { { SlTableHeader(_ai_company_desc); - for (int i = COMPANY_FIRST; i < MAX_COMPANIES; i++) { + for (CompanyID i = COMPANY_FIRST; i < MAX_COMPANIES; ++i) { SlSetArrayIndex(i); SlAutolength(SaveReal_AIPL, i); } diff --git a/src/saveload/randomizer_sl.cpp b/src/saveload/randomizer_sl.cpp index 2c35cf2ada..b5da1428a4 100644 --- a/src/saveload/randomizer_sl.cpp +++ b/src/saveload/randomizer_sl.cpp @@ -26,7 +26,7 @@ struct SRNDChunkHandler : ChunkHandler { { SlTableHeader(_randomizer_desc); - for (Owner owner = OWNER_BEGIN; owner < OWNER_END; owner++) { + for (Owner owner = OWNER_BEGIN; owner < OWNER_END; ++owner) { SlSetArrayIndex(owner); SlObject(&ScriptObject::GetRandomizer(owner), _randomizer_desc); } diff --git a/src/script/api/script_object.cpp b/src/script/api/script_object.cpp index 38e92d9954..507ea47888 100644 --- a/src/script/api/script_object.cpp +++ b/src/script/api/script_object.cpp @@ -357,7 +357,7 @@ Randomizer &ScriptObject::GetRandomizer(Owner owner) void ScriptObject::InitializeRandomizers() { Randomizer random = _random; - for (Owner owner = OWNER_BEGIN; owner < OWNER_END; owner++) { + for (Owner owner = OWNER_BEGIN; owner < OWNER_END; ++owner) { ScriptObject::GetRandomizer(owner).SetSeed(random.Next()); } } diff --git a/src/script/script_gui.cpp b/src/script/script_gui.cpp index 5b0988d59b..3dc5daa069 100644 --- a/src/script/script_gui.cpp +++ b/src/script/script_gui.cpp @@ -977,7 +977,7 @@ struct ScriptDebugWindow : public Window { void UpdateAIButtonsState() { /* Update company buttons */ - for (CompanyID i = COMPANY_FIRST; i < MAX_COMPANIES; i++) { + for (CompanyID i = COMPANY_FIRST; i < MAX_COMPANIES; ++i) { /* Mark dead/paused AIs by setting the background colour. */ bool valid = Company::IsValidAiID(i); bool dead = valid && Company::Get(i)->ai_instance->IsDead(); diff --git a/src/settings.cpp b/src/settings.cpp index 013941f8fd..799a54b7b5 100644 --- a/src/settings.cpp +++ b/src/settings.cpp @@ -960,7 +960,7 @@ static void AILoadConfig(const IniFile &ini, const char *grpname) const IniGroup *group = ini.GetGroup(grpname); /* Clean any configured AI */ - for (CompanyID c = COMPANY_FIRST; c < MAX_COMPANIES; c++) { + for (CompanyID c = COMPANY_FIRST; c < MAX_COMPANIES; ++c) { AIConfig::GetConfig(c, AIConfig::SSS_FORCE_NEWGAME)->Change(std::nullopt); } @@ -979,7 +979,7 @@ static void AILoadConfig(const IniFile &ini, const char *grpname) } } if (item.value.has_value()) config->StringToSettings(*item.value); - c++; + ++c; if (c >= MAX_COMPANIES) break; } } @@ -1173,7 +1173,7 @@ static void AISaveConfig(IniFile &ini, const char *grpname) IniGroup &group = ini.GetOrCreateGroup(grpname); group.Clear(); - for (CompanyID c = COMPANY_FIRST; c < MAX_COMPANIES; c++) { + for (CompanyID c = COMPANY_FIRST; c < MAX_COMPANIES; ++c) { AIConfig *config = AIConfig::GetConfig(c, AIConfig::SSS_FORCE_NEWGAME); std::string name; std::string value = config->SettingsToString(); diff --git a/src/toolbar_gui.cpp b/src/toolbar_gui.cpp index cc55a0c7ef..3cd4a43196 100644 --- a/src/toolbar_gui.cpp +++ b/src/toolbar_gui.cpp @@ -173,7 +173,7 @@ static void PopupMainCompanyToolbMenu(Window *w, WidgetID widget, CompanyMask gr break; } - for (CompanyID c = COMPANY_FIRST; c < MAX_COMPANIES; c++) { + for (CompanyID c = COMPANY_FIRST; c < MAX_COMPANIES; ++c) { if (!Company::IsValidID(c)) continue; list.push_back(std::make_unique(c, grey.Test(c))); }