1
0
Fork 0

Codechange: use prefix operator++ for CompanyID iterations

pull/13582/head
Rubidium 2025-02-10 17:49:30 +01:00 committed by rubidium42
parent b0eb8fe4db
commit 1ffc950e22
12 changed files with 24 additions and 24 deletions

View File

@ -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);
}
}

View File

@ -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;
}

View File

@ -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));
}

View File

@ -561,7 +561,7 @@ void LinkGraphLegendWindow::SetOverlay(std::shared_ptr<LinkGraphOverlay> 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));
}
}

View File

@ -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]);

View File

@ -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);

View File

@ -80,7 +80,7 @@ struct AIPLChunkHandler : ChunkHandler {
const std::vector<SaveLoad> 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);
}

View File

@ -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);
}

View File

@ -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());
}
}

View File

@ -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();

View File

@ -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();

View File

@ -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<DropDownListCompanyItem>(c, grey.Test(c)));
}