mirror of https://github.com/OpenTTD/OpenTTD
Codechange: use prefix operator++ for CompanyID iterations
parent
b0eb8fe4db
commit
1ffc950e22
|
@ -190,7 +190,7 @@
|
||||||
AI::scanner_info = nullptr;
|
AI::scanner_info = nullptr;
|
||||||
AI::scanner_library = 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) {
|
if (_settings_game.ai_config[c] != nullptr) {
|
||||||
delete _settings_game.ai_config[c];
|
delete _settings_game.ai_config[c];
|
||||||
_settings_game.ai_config[c] = nullptr;
|
_settings_game.ai_config[c] = nullptr;
|
||||||
|
@ -208,7 +208,7 @@
|
||||||
/* Check for both newgame as current game if we can reload the AIInfo inside
|
/* 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
|
* the AIConfig. If not, remove the AI from the list (which will assign
|
||||||
* a random new AI on reload). */
|
* 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] != nullptr && _settings_game.ai_config[c]->HasScript()) {
|
||||||
if (!_settings_game.ai_config[c]->ResetInfo(true)) {
|
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());
|
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 */
|
/* 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);
|
if (c != skip_company) AI::NewEvent(c, event);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1337,7 +1337,7 @@ CompanyID GetFirstPlayableCompanyID()
|
||||||
}
|
}
|
||||||
|
|
||||||
if (Company::CanAllocateItem()) {
|
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)) {
|
if (!Company::IsValidID(c)) {
|
||||||
return c;
|
return c;
|
||||||
}
|
}
|
||||||
|
|
|
@ -54,7 +54,7 @@ struct GraphLegendWindow : Window {
|
||||||
{
|
{
|
||||||
this->InitNested(window_number);
|
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);
|
if (!_legend_excluded_companies.Test(c)) this->LowerWidget(WID_GL_FIRST_COMPANY + c);
|
||||||
|
|
||||||
this->OnInvalidateData(c);
|
this->OnInvalidateData(c);
|
||||||
|
@ -676,7 +676,7 @@ public:
|
||||||
CompanyMask excluded_companies = _legend_excluded_companies;
|
CompanyMask excluded_companies = _legend_excluded_companies;
|
||||||
|
|
||||||
/* Exclude the companies which aren't valid */
|
/* 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);
|
if (!Company::IsValidID(c)) excluded_companies.Set(c);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -704,7 +704,7 @@ public:
|
||||||
this->month = mo;
|
this->month = mo;
|
||||||
|
|
||||||
this->data.clear();
|
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);
|
const Company *c = Company::GetIfValid(k);
|
||||||
if (c == nullptr) continue;
|
if (c == nullptr) continue;
|
||||||
|
|
||||||
|
@ -1460,7 +1460,7 @@ struct PerformanceRatingDetailWindow : Window {
|
||||||
{
|
{
|
||||||
if (!gui_scope) return;
|
if (!gui_scope) return;
|
||||||
/* Disable the companies who are not active */
|
/* 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));
|
this->SetWidgetDisabledState(WID_PRD_COMPANY_FIRST + i, !Company::IsValidID(i));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -561,7 +561,7 @@ void LinkGraphLegendWindow::SetOverlay(std::shared_ptr<LinkGraphOverlay> overlay
|
||||||
{
|
{
|
||||||
this->overlay = overlay;
|
this->overlay = overlay;
|
||||||
CompanyMask companies = this->overlay->GetCompanyMask();
|
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)) {
|
if (!this->IsWidgetDisabled(WID_LGL_COMPANY_FIRST + c)) {
|
||||||
this->SetWidgetLoweredState(WID_LGL_COMPANY_FIRST + c, companies.Test(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()
|
void LinkGraphLegendWindow::UpdateOverlayCompanies()
|
||||||
{
|
{
|
||||||
CompanyMask mask;
|
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->IsWidgetDisabled(WID_LGL_COMPANY_FIRST + c)) continue;
|
||||||
if (!this->IsWidgetLowered(WID_LGL_COMPANY_FIRST + c)) continue;
|
if (!this->IsWidgetLowered(WID_LGL_COMPANY_FIRST + c)) continue;
|
||||||
mask.Set(c);
|
mask.Set(c);
|
||||||
|
@ -688,7 +688,7 @@ void LinkGraphLegendWindow::OnClick([[maybe_unused]] Point pt, WidgetID widget,
|
||||||
this->UpdateOverlayCompanies();
|
this->UpdateOverlayCompanies();
|
||||||
}
|
}
|
||||||
} else if (widget == WID_LGL_COMPANIES_ALL || widget == WID_LGL_COMPANIES_NONE) {
|
} 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;
|
if (this->IsWidgetDisabled(WID_LGL_COMPANY_FIRST + c)) continue;
|
||||||
this->SetWidgetLoweredState(WID_LGL_COMPANY_FIRST + c, widget == WID_LGL_COMPANIES_ALL);
|
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 */
|
/* 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));
|
this->SetWidgetDisabledState(WID_LGL_COMPANY_FIRST + i, !Company::IsValidID(i));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -341,7 +341,7 @@ static void LoadIntroGame(bool load_newgrfs = true)
|
||||||
|
|
||||||
void MakeNewgameSettingsLive()
|
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) {
|
if (_settings_game.ai_config[c] != nullptr) {
|
||||||
delete _settings_game.ai_config[c];
|
delete _settings_game.ai_config[c];
|
||||||
}
|
}
|
||||||
|
@ -355,7 +355,7 @@ void MakeNewgameSettingsLive()
|
||||||
_settings_game = _settings_newgame;
|
_settings_game = _settings_newgame;
|
||||||
_old_vds = _settings_client.company.vehicle;
|
_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;
|
_settings_game.ai_config[c] = nullptr;
|
||||||
if (_settings_newgame.ai_config[c] != nullptr) {
|
if (_settings_newgame.ai_config[c] != nullptr) {
|
||||||
_settings_game.ai_config[c] = new AIConfig(_settings_newgame.ai_config[c]);
|
_settings_game.ai_config[c] = new AIConfig(_settings_newgame.ai_config[c]);
|
||||||
|
|
|
@ -3416,7 +3416,7 @@ void ReloadNewGRFData()
|
||||||
/* Delete news referring to no longer existing entities */
|
/* Delete news referring to no longer existing entities */
|
||||||
DeleteInvalidEngineNews();
|
DeleteInvalidEngineNews();
|
||||||
/* Update livery selection windows */
|
/* 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. */
|
/* Update company infrastructure counts. */
|
||||||
InvalidateWindowClassesData(WC_COMPANY_INFRASTRUCTURE);
|
InvalidateWindowClassesData(WC_COMPANY_INFRASTRUCTURE);
|
||||||
InvalidateWindowClassesData(WC_BUILD_TOOLBAR);
|
InvalidateWindowClassesData(WC_BUILD_TOOLBAR);
|
||||||
|
|
|
@ -80,7 +80,7 @@ struct AIPLChunkHandler : ChunkHandler {
|
||||||
const std::vector<SaveLoad> slt = SlCompatTableHeader(_ai_company_desc, _ai_company_sl_compat);
|
const std::vector<SaveLoad> slt = SlCompatTableHeader(_ai_company_desc, _ai_company_sl_compat);
|
||||||
|
|
||||||
/* Free all current data */
|
/* 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);
|
AIConfig::GetConfig(c, AIConfig::SSS_FORCE_GAME)->Change(std::nullopt);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -160,7 +160,7 @@ struct AIPLChunkHandler : ChunkHandler {
|
||||||
{
|
{
|
||||||
SlTableHeader(_ai_company_desc);
|
SlTableHeader(_ai_company_desc);
|
||||||
|
|
||||||
for (int i = COMPANY_FIRST; i < MAX_COMPANIES; i++) {
|
for (CompanyID i = COMPANY_FIRST; i < MAX_COMPANIES; ++i) {
|
||||||
SlSetArrayIndex(i);
|
SlSetArrayIndex(i);
|
||||||
SlAutolength(SaveReal_AIPL, i);
|
SlAutolength(SaveReal_AIPL, i);
|
||||||
}
|
}
|
||||||
|
|
|
@ -26,7 +26,7 @@ struct SRNDChunkHandler : ChunkHandler {
|
||||||
{
|
{
|
||||||
SlTableHeader(_randomizer_desc);
|
SlTableHeader(_randomizer_desc);
|
||||||
|
|
||||||
for (Owner owner = OWNER_BEGIN; owner < OWNER_END; owner++) {
|
for (Owner owner = OWNER_BEGIN; owner < OWNER_END; ++owner) {
|
||||||
SlSetArrayIndex(owner);
|
SlSetArrayIndex(owner);
|
||||||
SlObject(&ScriptObject::GetRandomizer(owner), _randomizer_desc);
|
SlObject(&ScriptObject::GetRandomizer(owner), _randomizer_desc);
|
||||||
}
|
}
|
||||||
|
|
|
@ -357,7 +357,7 @@ Randomizer &ScriptObject::GetRandomizer(Owner owner)
|
||||||
void ScriptObject::InitializeRandomizers()
|
void ScriptObject::InitializeRandomizers()
|
||||||
{
|
{
|
||||||
Randomizer random = _random;
|
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());
|
ScriptObject::GetRandomizer(owner).SetSeed(random.Next());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -977,7 +977,7 @@ struct ScriptDebugWindow : public Window {
|
||||||
void UpdateAIButtonsState()
|
void UpdateAIButtonsState()
|
||||||
{
|
{
|
||||||
/* Update company buttons */
|
/* 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. */
|
/* Mark dead/paused AIs by setting the background colour. */
|
||||||
bool valid = Company::IsValidAiID(i);
|
bool valid = Company::IsValidAiID(i);
|
||||||
bool dead = valid && Company::Get(i)->ai_instance->IsDead();
|
bool dead = valid && Company::Get(i)->ai_instance->IsDead();
|
||||||
|
|
|
@ -960,7 +960,7 @@ static void AILoadConfig(const IniFile &ini, const char *grpname)
|
||||||
const IniGroup *group = ini.GetGroup(grpname);
|
const IniGroup *group = ini.GetGroup(grpname);
|
||||||
|
|
||||||
/* Clean any configured AI */
|
/* 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);
|
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);
|
if (item.value.has_value()) config->StringToSettings(*item.value);
|
||||||
c++;
|
++c;
|
||||||
if (c >= MAX_COMPANIES) break;
|
if (c >= MAX_COMPANIES) break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1173,7 +1173,7 @@ static void AISaveConfig(IniFile &ini, const char *grpname)
|
||||||
IniGroup &group = ini.GetOrCreateGroup(grpname);
|
IniGroup &group = ini.GetOrCreateGroup(grpname);
|
||||||
group.Clear();
|
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);
|
AIConfig *config = AIConfig::GetConfig(c, AIConfig::SSS_FORCE_NEWGAME);
|
||||||
std::string name;
|
std::string name;
|
||||||
std::string value = config->SettingsToString();
|
std::string value = config->SettingsToString();
|
||||||
|
|
|
@ -173,7 +173,7 @@ static void PopupMainCompanyToolbMenu(Window *w, WidgetID widget, CompanyMask gr
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (CompanyID c = COMPANY_FIRST; c < MAX_COMPANIES; c++) {
|
for (CompanyID c = COMPANY_FIRST; c < MAX_COMPANIES; ++c) {
|
||||||
if (!Company::IsValidID(c)) continue;
|
if (!Company::IsValidID(c)) continue;
|
||||||
list.push_back(std::make_unique<DropDownListCompanyItem>(c, grey.Test(c)));
|
list.push_back(std::make_unique<DropDownListCompanyItem>(c, grey.Test(c)));
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue