Codechange: Use std::vector for GRFConfig lists. (#10835)

This replaces the C-style custom managed linked-list and allows use of iterators etc.
This commit is contained in:
Peter Nelson
2025-01-31 17:09:09 +00:00
committed by GitHub
parent 40aeedeade
commit 5664b1e2f6
23 changed files with 248 additions and 384 deletions

View File

@@ -91,11 +91,11 @@ struct NGRFChunkHandler : ChunkHandler {
int index = 0;
for (GRFConfig *c = _grfconfig; c != nullptr; c = c->next) {
for (const auto &c : _grfconfig) {
if (HasBit(c->flags, GCF_STATIC) || HasBit(c->flags, GCF_INIT_ONLY)) continue;
this->SaveParameters(*c);
SlSetArrayIndex(index++);
SlObject(c, description);
SlObject(c.get(), description);
}
}
@@ -112,11 +112,11 @@ struct NGRFChunkHandler : ChunkHandler {
ClearGRFConfigList(grfconfig);
while (SlIterateArray() != -1) {
GRFConfig *c = new GRFConfig();
SlObject(c, slt);
auto c = std::make_unique<GRFConfig>();
SlObject(c.get(), slt);
if (IsSavegameVersionBefore(SLV_101)) c->SetSuitablePalette();
this->LoadParameters(*c);
AppendToGRFConfigList(grfconfig, c);
AppendToGRFConfigList(grfconfig, std::move(c));
}
}
@@ -126,7 +126,7 @@ struct NGRFChunkHandler : ChunkHandler {
if (_game_mode == GM_MENU) {
/* Intro game must not have NewGRF. */
if (_grfconfig != nullptr) SlErrorCorrupt("The intro game must not use NewGRF");
if (!_grfconfig.empty()) SlErrorCorrupt("The intro game must not use NewGRF");
/* Activate intro NewGRFs (townnames) */
ResetGRFConfig(false);