Codechange: Add missing `this->` in override manager.

Variable scope is also tweaked in a couple of cases reducing line count.
This commit is contained in:
Peter Nelson 2023-01-22 17:03:48 +00:00 committed by Michael Lutz
parent eedb786872
commit bcc53c5ad5
4 changed files with 51 additions and 56 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);
if (airport_id == invalid_ID) {
if (airport_id == this->invalid_ID) {
grfmsg(1, "Airport.SetEntitySpec: Too many airports allocated. Ignoring.");
return;
}
@ -183,15 +183,15 @@ void AirportOverrideManager::SetEntitySpec(AirportSpec *as)
memcpy(AirportSpec::GetWithoutOverride(airport_id), as, sizeof(*as));
/* Now add the overrides. */
for (int i = 0; i < max_offset; i++) {
for (int i = 0; i < this->max_offset; i++) {
AirportSpec *overridden_as = AirportSpec::GetWithoutOverride(i);
if (entity_overrides[i] != as->grf_prop.local_id || grfid_overrides[i] != as->grf_prop.grffile->grfid) continue;
if (this->entity_overrides[i] != as->grf_prop.local_id || this->grfid_overrides[i] != as->grf_prop.grffile->grfid) continue;
overridden_as->grf_prop.override = airport_id;
overridden_as->enabled = false;
entity_overrides[i] = invalid_ID;
grfid_overrides[i] = 0;
this->entity_overrides[i] = this->invalid_ID;
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);
if (airpt_id == invalid_ID) {
if (airpt_id == this->invalid_ID) {
grfmsg(1, "AirportTile.SetEntitySpec: Too many airport tiles allocated. Ignoring.");
return;
}
@ -75,15 +75,15 @@ void AirportTileOverrideManager::SetEntitySpec(const AirportTileSpec *airpts)
memcpy(&AirportTileSpec::tiles[airpt_id], airpts, sizeof(*airpts));
/* Now add the overrides. */
for (int i = 0; i < max_offset; i++) {
for (int i = 0; i < this->max_offset; i++) {
AirportTileSpec *overridden_airpts = &AirportTileSpec::tiles[i];
if (entity_overrides[i] != airpts->grf_prop.local_id || grfid_overrides[i] != airpts->grf_prop.grffile->grfid) continue;
if (this->entity_overrides[i] != airpts->grf_prop.local_id || this->grfid_overrides[i] != airpts->grf_prop.grffile->grfid) continue;
overridden_airpts->grf_prop.override = airpt_id;
overridden_airpts->enabled = false;
entity_overrides[i] = invalid_ID;
grfid_overrides[i] = 0;
this->entity_overrides[i] = this->invalid_ID;
this->grfid_overrides[i] = 0;
}
}

View File

@ -40,9 +40,9 @@
*/
OverrideManagerBase::OverrideManagerBase(uint16 offset, uint16 maximum, uint16 invalid)
{
max_offset = offset;
max_new_entities = maximum;
invalid_ID = invalid;
this->max_offset = offset;
this->max_new_entities = maximum;
this->invalid_ID = invalid;
this->mapping_ID.resize(this->max_new_entities);
this->entity_overrides.resize(this->max_offset);
@ -60,11 +60,11 @@ OverrideManagerBase::OverrideManagerBase(uint16 offset, uint16 maximum, uint16 i
*/
void OverrideManagerBase::Add(uint8 local_id, uint32 grfid, uint entity_type)
{
assert(entity_type < max_offset);
assert(entity_type < this->max_offset);
/* An override can be set only once */
if (entity_overrides[entity_type] != invalid_ID) return;
entity_overrides[entity_type] = local_id;
grfid_overrides[entity_type] = grfid;
if (this->entity_overrides[entity_type] != this->invalid_ID) return;
this->entity_overrides[entity_type] = local_id;
this->grfid_overrides[entity_type] = grfid;
}
/** Resets the mapping, which is used while initializing game */
@ -88,16 +88,14 @@ void OverrideManagerBase::ResetOverride()
*/
uint16 OverrideManagerBase::GetID(uint8 grf_local_id, uint32 grfid) const
{
const EntityIDMapping *map;
for (uint16 id = 0; id < max_new_entities; id++) {
map = &mapping_ID[id];
for (uint16 id = 0; id < this->max_new_entities; id++) {
const EntityIDMapping *map = &this->mapping_ID[id];
if (map->entity_id == grf_local_id && map->grfid == grfid) {
return id;
}
}
return invalid_ID;
return this->invalid_ID;
}
/**
@ -110,19 +108,16 @@ uint16 OverrideManagerBase::GetID(uint8 grf_local_id, uint32 grfid) const
uint16 OverrideManagerBase::AddEntityID(byte grf_local_id, uint32 grfid, byte substitute_id)
{
uint16 id = this->GetID(grf_local_id, grfid);
EntityIDMapping *map;
/* Look to see if this entity has already been added. This is done
* separately from the loop below in case a GRF has been deleted, and there
* are any gaps in the array.
*/
if (id != invalid_ID) {
return id;
}
if (id != this->invalid_ID) return id;
/* This entity hasn't been defined before, so give it an ID now. */
for (id = max_offset; id < max_new_entities; id++) {
map = &mapping_ID[id];
for (id = this->max_offset; id < this->max_new_entities; id++) {
EntityIDMapping *map = &this->mapping_ID[id];
if (CheckValidNewID(id) && map->entity_id == 0 && map->grfid == 0) {
map->entity_id = grf_local_id;
@ -132,7 +127,7 @@ uint16 OverrideManagerBase::AddEntityID(byte grf_local_id, uint32 grfid, byte su
}
}
return invalid_ID;
return this->invalid_ID;
}
/**
@ -142,7 +137,7 @@ uint16 OverrideManagerBase::AddEntityID(byte grf_local_id, uint32 grfid, byte su
*/
uint32 OverrideManagerBase::GetGRFID(uint16 entity_id) const
{
return mapping_ID[entity_id].grfid;
return this->mapping_ID[entity_id].grfid;
}
/**
@ -152,7 +147,7 @@ uint32 OverrideManagerBase::GetGRFID(uint16 entity_id) const
*/
uint16 OverrideManagerBase::GetSubstituteID(uint16 entity_id) const
{
return mapping_ID[entity_id].substitute_id;
return this->mapping_ID[entity_id].substitute_id;
}
/**
@ -164,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);
if (house_id == invalid_ID) {
if (house_id == this->invalid_ID) {
grfmsg(1, "House.SetEntitySpec: Too many houses allocated. Ignoring.");
return;
}
@ -172,14 +167,14 @@ void HouseOverrideManager::SetEntitySpec(const HouseSpec *hs)
MemCpyT(HouseSpec::Get(house_id), hs);
/* Now add the overrides. */
for (int i = 0; i != max_offset; i++) {
for (int i = 0; i < this->max_offset; i++) {
HouseSpec *overridden_hs = HouseSpec::Get(i);
if (entity_overrides[i] != hs->grf_prop.local_id || 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;
entity_overrides[i] = invalid_ID;
grfid_overrides[i] = 0;
this->entity_overrides[i] = this->invalid_ID;
this->grfid_overrides[i] = 0;
}
}
@ -192,14 +187,14 @@ void HouseOverrideManager::SetEntitySpec(const HouseSpec *hs)
uint16 IndustryOverrideManager::GetID(uint8 grf_local_id, uint32 grfid) const
{
uint16 id = OverrideManagerBase::GetID(grf_local_id, grfid);
if (id != invalid_ID) return id;
if (id != this->invalid_ID) return id;
/* No mapping found, try the overrides */
for (id = 0; id < max_offset; id++) {
if (entity_overrides[id] == grf_local_id && grfid_overrides[id] == grfid) return id;
for (id = 0; id < this->max_offset; id++) {
if (this->entity_overrides[id] == grf_local_id && this->grfid_overrides[id] == grfid) return id;
}
return invalid_ID;
return this->invalid_ID;
}
/**
@ -212,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)
{
/* This entity hasn't been defined before, so give it an ID now. */
for (uint16 id = 0; id < max_new_entities; id++) {
for (uint16 id = 0; id < this->max_new_entities; id++) {
/* Skip overridden industries */
if (id < max_offset && entity_overrides[id] != invalid_ID) continue;
if (id < this->max_offset && this->entity_overrides[id] != this->invalid_ID) continue;
/* Get the real live industry */
const IndustrySpec *inds = GetIndustrySpec(id);
@ -223,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).
* So reserve this slot here, as it is the chosen one */
if (!inds->enabled && inds->grf_prop.grffile == nullptr) {
EntityIDMapping *map = &mapping_ID[id];
EntityIDMapping *map = &this->mapping_ID[id];
if (map->entity_id == 0 && map->grfid == 0) {
/* winning slot, mark it as been used */
@ -235,7 +230,7 @@ uint16 IndustryOverrideManager::AddEntityID(byte grf_local_id, uint32 grfid, byt
}
}
return invalid_ID;
return this->invalid_ID;
}
/**
@ -249,16 +244,16 @@ void IndustryOverrideManager::SetEntitySpec(IndustrySpec *inds)
/* 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);
if (ind_id == invalid_ID) {
if (ind_id == this->invalid_ID) {
/* Not found.
* Or it has already been overridden, so you've lost your place.
* Or it is a simple substitute.
* 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);
inds->grf_prop.override = 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 == invalid_ID) {
if (ind_id == this->invalid_ID) {
grfmsg(1, "Industry.SetEntitySpec: Too many industries allocated. Ignoring.");
return;
}
@ -273,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);
if (indt_id == invalid_ID) {
if (indt_id == this->invalid_ID) {
grfmsg(1, "IndustryTile.SetEntitySpec: Too many industry tiles allocated. Ignoring.");
return;
}
@ -281,15 +276,15 @@ void IndustryTileOverrideManager::SetEntitySpec(const IndustryTileSpec *its)
memcpy(&_industry_tile_specs[indt_id], its, sizeof(*its));
/* Now add the overrides. */
for (int i = 0; i < max_offset; i++) {
for (int i = 0; i < this->max_offset; i++) {
IndustryTileSpec *overridden_its = &_industry_tile_specs[i];
if (entity_overrides[i] != its->grf_prop.local_id || grfid_overrides[i] != its->grf_prop.grffile->grfid) continue;
if (this->entity_overrides[i] != its->grf_prop.local_id || this->grfid_overrides[i] != its->grf_prop.grffile->grfid) continue;
overridden_its->grf_prop.override = indt_id;
overridden_its->enabled = false;
entity_overrides[i] = invalid_ID;
grfid_overrides[i] = 0;
this->entity_overrides[i] = this->invalid_ID;
this->grfid_overrides[i] = 0;
}
}
@ -304,7 +299,7 @@ void ObjectOverrideManager::SetEntitySpec(ObjectSpec *spec)
/* 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);
if (type == invalid_ID) {
if (type == this->invalid_ID) {
/* Not found.
* Or it has already been overridden, so you've lost your place.
* Or it is a simple substitute.
@ -312,7 +307,7 @@ void ObjectOverrideManager::SetEntitySpec(ObjectSpec *spec)
type = this->AddEntityID(spec->grf_prop.local_id, spec->grf_prop.grffile->grfid, OBJECT_TRANSMITTER);
}
if (type == invalid_ID) {
if (type == this->invalid_ID) {
grfmsg(1, "Object.SetEntitySpec: Too many objects allocated. Ignoring.");
return;
}

View File

@ -216,8 +216,8 @@ public:
uint16 GetSubstituteID(uint16 entity_id) const;
virtual uint16 GetID(uint8 grf_local_id, uint32 grfid) const;
inline uint16 GetMaxMapping() const { return max_new_entities; }
inline uint16 GetMaxOffset() const { return max_offset; }
inline uint16 GetMaxMapping() const { return this->max_new_entities; }
inline uint16 GetMaxOffset() const { return this->max_offset; }
};