1
0
Fork 0

Codechange: Rename override manager variables.

pull/10415/head
Peter Nelson 2023-01-22 17:20:23 +00:00 committed by Michael Lutz
parent bcc53c5ad5
commit ede1201b6a
5 changed files with 44 additions and 44 deletions

View File

@ -175,7 +175,7 @@ void AirportOverrideManager::SetEntitySpec(AirportSpec *as)
{ {
byte airport_id = this->AddEntityID(as->grf_prop.local_id, as->grf_prop.grffile->grfid, as->grf_prop.subst_id); byte airport_id = this->AddEntityID(as->grf_prop.local_id, as->grf_prop.grffile->grfid, as->grf_prop.subst_id);
if (airport_id == this->invalid_ID) { if (airport_id == this->invalid_id) {
grfmsg(1, "Airport.SetEntitySpec: Too many airports allocated. Ignoring."); grfmsg(1, "Airport.SetEntitySpec: Too many airports allocated. Ignoring.");
return; return;
} }
@ -190,7 +190,7 @@ void AirportOverrideManager::SetEntitySpec(AirportSpec *as)
overridden_as->grf_prop.override = airport_id; overridden_as->grf_prop.override = airport_id;
overridden_as->enabled = false; overridden_as->enabled = false;
this->entity_overrides[i] = this->invalid_ID; this->entity_overrides[i] = this->invalid_id;
this->grfid_overrides[i] = 0; this->grfid_overrides[i] = 0;
} }
} }

View File

@ -67,7 +67,7 @@ void AirportTileOverrideManager::SetEntitySpec(const AirportTileSpec *airpts)
{ {
StationGfx airpt_id = this->AddEntityID(airpts->grf_prop.local_id, airpts->grf_prop.grffile->grfid, airpts->grf_prop.subst_id); StationGfx airpt_id = this->AddEntityID(airpts->grf_prop.local_id, airpts->grf_prop.grffile->grfid, airpts->grf_prop.subst_id);
if (airpt_id == this->invalid_ID) { if (airpt_id == this->invalid_id) {
grfmsg(1, "AirportTile.SetEntitySpec: Too many airport tiles allocated. Ignoring."); grfmsg(1, "AirportTile.SetEntitySpec: Too many airport tiles allocated. Ignoring.");
return; return;
} }
@ -82,7 +82,7 @@ void AirportTileOverrideManager::SetEntitySpec(const AirportTileSpec *airpts)
overridden_airpts->grf_prop.override = airpt_id; overridden_airpts->grf_prop.override = airpt_id;
overridden_airpts->enabled = false; overridden_airpts->enabled = false;
this->entity_overrides[i] = this->invalid_ID; this->entity_overrides[i] = this->invalid_id;
this->grfid_overrides[i] = 0; this->grfid_overrides[i] = 0;
} }
} }

View File

@ -41,12 +41,12 @@
OverrideManagerBase::OverrideManagerBase(uint16 offset, uint16 maximum, uint16 invalid) OverrideManagerBase::OverrideManagerBase(uint16 offset, uint16 maximum, uint16 invalid)
{ {
this->max_offset = offset; this->max_offset = offset;
this->max_new_entities = maximum; this->max_entities = maximum;
this->invalid_ID = invalid; this->invalid_id = invalid;
this->mapping_ID.resize(this->max_new_entities); this->mappings.resize(this->max_entities);
this->entity_overrides.resize(this->max_offset); this->entity_overrides.resize(this->max_offset);
std::fill(this->entity_overrides.begin(), this->entity_overrides.end(), this->invalid_ID); std::fill(this->entity_overrides.begin(), this->entity_overrides.end(), this->invalid_id);
this->grfid_overrides.resize(this->max_offset); this->grfid_overrides.resize(this->max_offset);
} }
@ -62,7 +62,7 @@ void OverrideManagerBase::Add(uint8 local_id, uint32 grfid, uint entity_type)
{ {
assert(entity_type < this->max_offset); assert(entity_type < this->max_offset);
/* An override can be set only once */ /* An override can be set only once */
if (this->entity_overrides[entity_type] != this->invalid_ID) return; if (this->entity_overrides[entity_type] != this->invalid_id) return;
this->entity_overrides[entity_type] = local_id; this->entity_overrides[entity_type] = local_id;
this->grfid_overrides[entity_type] = grfid; this->grfid_overrides[entity_type] = grfid;
} }
@ -70,13 +70,13 @@ void OverrideManagerBase::Add(uint8 local_id, uint32 grfid, uint entity_type)
/** Resets the mapping, which is used while initializing game */ /** Resets the mapping, which is used while initializing game */
void OverrideManagerBase::ResetMapping() void OverrideManagerBase::ResetMapping()
{ {
std::fill(this->mapping_ID.begin(), this->mapping_ID.end(), EntityIDMapping{}); std::fill(this->mappings.begin(), this->mappings.end(), EntityIDMapping{});
} }
/** Resets the override, which is used while initializing game */ /** Resets the override, which is used while initializing game */
void OverrideManagerBase::ResetOverride() void OverrideManagerBase::ResetOverride()
{ {
std::fill(this->entity_overrides.begin(), this->entity_overrides.end(), this->invalid_ID); std::fill(this->entity_overrides.begin(), this->entity_overrides.end(), this->invalid_id);
std::fill(this->grfid_overrides.begin(), this->grfid_overrides.end(), uint32()); std::fill(this->grfid_overrides.begin(), this->grfid_overrides.end(), uint32());
} }
@ -88,14 +88,14 @@ void OverrideManagerBase::ResetOverride()
*/ */
uint16 OverrideManagerBase::GetID(uint8 grf_local_id, uint32 grfid) const uint16 OverrideManagerBase::GetID(uint8 grf_local_id, uint32 grfid) const
{ {
for (uint16 id = 0; id < this->max_new_entities; id++) { for (uint16 id = 0; id < this->max_entities; id++) {
const EntityIDMapping *map = &this->mapping_ID[id]; const EntityIDMapping *map = &this->mappings[id];
if (map->entity_id == grf_local_id && map->grfid == grfid) { if (map->entity_id == grf_local_id && map->grfid == grfid) {
return id; return id;
} }
} }
return this->invalid_ID; return this->invalid_id;
} }
/** /**
@ -113,11 +113,11 @@ uint16 OverrideManagerBase::AddEntityID(byte grf_local_id, uint32 grfid, byte su
* separately from the loop below in case a GRF has been deleted, and there * separately from the loop below in case a GRF has been deleted, and there
* are any gaps in the array. * are any gaps in the array.
*/ */
if (id != this->invalid_ID) return id; if (id != this->invalid_id) return id;
/* This entity hasn't been defined before, so give it an ID now. */ /* This entity hasn't been defined before, so give it an ID now. */
for (id = this->max_offset; id < this->max_new_entities; id++) { for (id = this->max_offset; id < this->max_entities; id++) {
EntityIDMapping *map = &this->mapping_ID[id]; EntityIDMapping *map = &this->mappings[id];
if (CheckValidNewID(id) && map->entity_id == 0 && map->grfid == 0) { if (CheckValidNewID(id) && map->entity_id == 0 && map->grfid == 0) {
map->entity_id = grf_local_id; map->entity_id = grf_local_id;
@ -127,7 +127,7 @@ uint16 OverrideManagerBase::AddEntityID(byte grf_local_id, uint32 grfid, byte su
} }
} }
return this->invalid_ID; return this->invalid_id;
} }
/** /**
@ -137,7 +137,7 @@ uint16 OverrideManagerBase::AddEntityID(byte grf_local_id, uint32 grfid, byte su
*/ */
uint32 OverrideManagerBase::GetGRFID(uint16 entity_id) const uint32 OverrideManagerBase::GetGRFID(uint16 entity_id) const
{ {
return this->mapping_ID[entity_id].grfid; return this->mappings[entity_id].grfid;
} }
/** /**
@ -147,7 +147,7 @@ uint32 OverrideManagerBase::GetGRFID(uint16 entity_id) const
*/ */
uint16 OverrideManagerBase::GetSubstituteID(uint16 entity_id) const uint16 OverrideManagerBase::GetSubstituteID(uint16 entity_id) const
{ {
return this->mapping_ID[entity_id].substitute_id; return this->mappings[entity_id].substitute_id;
} }
/** /**
@ -159,7 +159,7 @@ void HouseOverrideManager::SetEntitySpec(const HouseSpec *hs)
{ {
HouseID house_id = this->AddEntityID(hs->grf_prop.local_id, hs->grf_prop.grffile->grfid, hs->grf_prop.subst_id); HouseID house_id = this->AddEntityID(hs->grf_prop.local_id, hs->grf_prop.grffile->grfid, hs->grf_prop.subst_id);
if (house_id == this->invalid_ID) { if (house_id == this->invalid_id) {
grfmsg(1, "House.SetEntitySpec: Too many houses allocated. Ignoring."); grfmsg(1, "House.SetEntitySpec: Too many houses allocated. Ignoring.");
return; return;
} }
@ -173,7 +173,7 @@ void HouseOverrideManager::SetEntitySpec(const HouseSpec *hs)
if (this->entity_overrides[i] != hs->grf_prop.local_id || this->grfid_overrides[i] != hs->grf_prop.grffile->grfid) continue; if (this->entity_overrides[i] != hs->grf_prop.local_id || this->grfid_overrides[i] != hs->grf_prop.grffile->grfid) continue;
overridden_hs->grf_prop.override = house_id; overridden_hs->grf_prop.override = house_id;
this->entity_overrides[i] = this->invalid_ID; this->entity_overrides[i] = this->invalid_id;
this->grfid_overrides[i] = 0; this->grfid_overrides[i] = 0;
} }
} }
@ -187,14 +187,14 @@ void HouseOverrideManager::SetEntitySpec(const HouseSpec *hs)
uint16 IndustryOverrideManager::GetID(uint8 grf_local_id, uint32 grfid) const uint16 IndustryOverrideManager::GetID(uint8 grf_local_id, uint32 grfid) const
{ {
uint16 id = OverrideManagerBase::GetID(grf_local_id, grfid); uint16 id = OverrideManagerBase::GetID(grf_local_id, grfid);
if (id != this->invalid_ID) return id; if (id != this->invalid_id) return id;
/* No mapping found, try the overrides */ /* No mapping found, try the overrides */
for (id = 0; id < this->max_offset; id++) { for (id = 0; id < this->max_offset; id++) {
if (this->entity_overrides[id] == grf_local_id && this->grfid_overrides[id] == grfid) return id; if (this->entity_overrides[id] == grf_local_id && this->grfid_overrides[id] == grfid) return id;
} }
return this->invalid_ID; return this->invalid_id;
} }
/** /**
@ -207,9 +207,9 @@ uint16 IndustryOverrideManager::GetID(uint8 grf_local_id, uint32 grfid) const
uint16 IndustryOverrideManager::AddEntityID(byte grf_local_id, uint32 grfid, byte substitute_id) uint16 IndustryOverrideManager::AddEntityID(byte grf_local_id, uint32 grfid, byte substitute_id)
{ {
/* This entity hasn't been defined before, so give it an ID now. */ /* This entity hasn't been defined before, so give it an ID now. */
for (uint16 id = 0; id < this->max_new_entities; id++) { for (uint16 id = 0; id < this->max_entities; id++) {
/* Skip overridden industries */ /* Skip overridden industries */
if (id < this->max_offset && this->entity_overrides[id] != this->invalid_ID) continue; if (id < this->max_offset && this->entity_overrides[id] != this->invalid_id) continue;
/* Get the real live industry */ /* Get the real live industry */
const IndustrySpec *inds = GetIndustrySpec(id); const IndustrySpec *inds = GetIndustrySpec(id);
@ -218,7 +218,7 @@ uint16 IndustryOverrideManager::AddEntityID(byte grf_local_id, uint32 grfid, byt
* And it must not already be used by a grf (grffile == nullptr). * And it must not already be used by a grf (grffile == nullptr).
* So reserve this slot here, as it is the chosen one */ * So reserve this slot here, as it is the chosen one */
if (!inds->enabled && inds->grf_prop.grffile == nullptr) { if (!inds->enabled && inds->grf_prop.grffile == nullptr) {
EntityIDMapping *map = &this->mapping_ID[id]; EntityIDMapping *map = &this->mappings[id];
if (map->entity_id == 0 && map->grfid == 0) { if (map->entity_id == 0 && map->grfid == 0) {
/* winning slot, mark it as been used */ /* winning slot, mark it as been used */
@ -230,7 +230,7 @@ uint16 IndustryOverrideManager::AddEntityID(byte grf_local_id, uint32 grfid, byt
} }
} }
return this->invalid_ID; return this->invalid_id;
} }
/** /**
@ -244,16 +244,16 @@ void IndustryOverrideManager::SetEntitySpec(IndustrySpec *inds)
/* First step : We need to find if this industry is already specified in the savegame data. */ /* First step : We need to find if this industry is already specified in the savegame data. */
IndustryType ind_id = this->GetID(inds->grf_prop.local_id, inds->grf_prop.grffile->grfid); IndustryType ind_id = this->GetID(inds->grf_prop.local_id, inds->grf_prop.grffile->grfid);
if (ind_id == this->invalid_ID) { if (ind_id == this->invalid_id) {
/* Not found. /* Not found.
* Or it has already been overridden, so you've lost your place. * Or it has already been overridden, so you've lost your place.
* Or it is a simple substitute. * Or it is a simple substitute.
* We need to find a free available slot */ * We need to find a free available slot */
ind_id = this->AddEntityID(inds->grf_prop.local_id, inds->grf_prop.grffile->grfid, inds->grf_prop.subst_id); ind_id = this->AddEntityID(inds->grf_prop.local_id, inds->grf_prop.grffile->grfid, inds->grf_prop.subst_id);
inds->grf_prop.override = this->invalid_ID; // make sure it will not be detected as overridden inds->grf_prop.override = this->invalid_id; // make sure it will not be detected as overridden
} }
if (ind_id == this->invalid_ID) { if (ind_id == this->invalid_id) {
grfmsg(1, "Industry.SetEntitySpec: Too many industries allocated. Ignoring."); grfmsg(1, "Industry.SetEntitySpec: Too many industries allocated. Ignoring.");
return; return;
} }
@ -268,7 +268,7 @@ void IndustryTileOverrideManager::SetEntitySpec(const IndustryTileSpec *its)
{ {
IndustryGfx indt_id = this->AddEntityID(its->grf_prop.local_id, its->grf_prop.grffile->grfid, its->grf_prop.subst_id); IndustryGfx indt_id = this->AddEntityID(its->grf_prop.local_id, its->grf_prop.grffile->grfid, its->grf_prop.subst_id);
if (indt_id == this->invalid_ID) { if (indt_id == this->invalid_id) {
grfmsg(1, "IndustryTile.SetEntitySpec: Too many industry tiles allocated. Ignoring."); grfmsg(1, "IndustryTile.SetEntitySpec: Too many industry tiles allocated. Ignoring.");
return; return;
} }
@ -283,7 +283,7 @@ void IndustryTileOverrideManager::SetEntitySpec(const IndustryTileSpec *its)
overridden_its->grf_prop.override = indt_id; overridden_its->grf_prop.override = indt_id;
overridden_its->enabled = false; overridden_its->enabled = false;
this->entity_overrides[i] = this->invalid_ID; this->entity_overrides[i] = this->invalid_id;
this->grfid_overrides[i] = 0; this->grfid_overrides[i] = 0;
} }
} }
@ -299,7 +299,7 @@ void ObjectOverrideManager::SetEntitySpec(ObjectSpec *spec)
/* First step : We need to find if this object is already specified in the savegame data. */ /* First step : We need to find if this object is already specified in the savegame data. */
ObjectType type = this->GetID(spec->grf_prop.local_id, spec->grf_prop.grffile->grfid); ObjectType type = this->GetID(spec->grf_prop.local_id, spec->grf_prop.grffile->grfid);
if (type == this->invalid_ID) { if (type == this->invalid_id) {
/* Not found. /* Not found.
* Or it has already been overridden, so you've lost your place. * Or it has already been overridden, so you've lost your place.
* Or it is a simple substitute. * Or it is a simple substitute.
@ -307,7 +307,7 @@ void ObjectOverrideManager::SetEntitySpec(ObjectSpec *spec)
type = this->AddEntityID(spec->grf_prop.local_id, spec->grf_prop.grffile->grfid, OBJECT_TRANSMITTER); type = this->AddEntityID(spec->grf_prop.local_id, spec->grf_prop.grffile->grfid, OBJECT_TRANSMITTER);
} }
if (type == this->invalid_ID) { if (type == this->invalid_id) {
grfmsg(1, "Object.SetEntitySpec: Too many objects allocated. Ignoring."); grfmsg(1, "Object.SetEntitySpec: Too many objects allocated. Ignoring.");
return; return;
} }

View File

@ -194,14 +194,14 @@ protected:
std::vector<uint16> entity_overrides; std::vector<uint16> entity_overrides;
std::vector<uint32> grfid_overrides; std::vector<uint32> grfid_overrides;
uint16 max_offset; ///< what is the length of the original entity's array of specs uint16 max_offset; ///< what is the length of the original entity's array of specs
uint16 max_new_entities; ///< what is the amount of entities, old and new summed uint16 max_entities; ///< what is the amount of entities, old and new summed
uint16 invalid_ID; ///< ID used to detected invalid entities; uint16 invalid_id; ///< ID used to detected invalid entities;
virtual bool CheckValidNewID(uint16 testid) { return true; } virtual bool CheckValidNewID(uint16 testid) { return true; }
public: public:
std::vector<EntityIDMapping> mapping_ID; ///< mapping of ids from grf files. Public out of convenience std::vector<EntityIDMapping> mappings; ///< mapping of ids from grf files. Public out of convenience
OverrideManagerBase(uint16 offset, uint16 maximum, uint16 invalid); OverrideManagerBase(uint16 offset, uint16 maximum, uint16 invalid);
virtual ~OverrideManagerBase() {} virtual ~OverrideManagerBase() {}
@ -216,7 +216,7 @@ public:
uint16 GetSubstituteID(uint16 entity_id) const; uint16 GetSubstituteID(uint16 entity_id) const;
virtual uint16 GetID(uint8 grf_local_id, uint32 grfid) const; virtual uint16 GetID(uint8 grf_local_id, uint32 grfid) const;
inline uint16 GetMaxMapping() const { return this->max_new_entities; } inline uint16 GetMaxMapping() const { return this->max_entities; }
inline uint16 GetMaxOffset() const { return this->max_offset; } inline uint16 GetMaxOffset() const { return this->max_offset; }
}; };

View File

@ -32,10 +32,10 @@ void NewGRFMappingChunkHandler::Save() const
SlTableHeader(_newgrf_mapping_desc); SlTableHeader(_newgrf_mapping_desc);
for (uint i = 0; i < this->mapping.GetMaxMapping(); i++) { for (uint i = 0; i < this->mapping.GetMaxMapping(); i++) {
if (this->mapping.mapping_ID[i].grfid == 0 && if (this->mapping.mappings[i].grfid == 0 &&
this->mapping.mapping_ID[i].entity_id == 0) continue; this->mapping.mappings[i].entity_id == 0) continue;
SlSetArrayIndex(i); SlSetArrayIndex(i);
SlObject(&this->mapping.mapping_ID[i], _newgrf_mapping_desc); SlObject(&this->mapping.mappings[i], _newgrf_mapping_desc);
} }
} }
@ -55,7 +55,7 @@ void NewGRFMappingChunkHandler::Load() const
int index; int index;
while ((index = SlIterateArray()) != -1) { while ((index = SlIterateArray()) != -1) {
if ((uint)index >= max_id) SlErrorCorrupt("Too many NewGRF entity mappings"); if ((uint)index >= max_id) SlErrorCorrupt("Too many NewGRF entity mappings");
SlObject(&this->mapping.mapping_ID[index], slt); SlObject(&this->mapping.mappings[index], slt);
} }
} }