|
|
|
@ -41,12 +41,12 @@
|
|
|
|
|
OverrideManagerBase::OverrideManagerBase(uint16 offset, uint16 maximum, uint16 invalid)
|
|
|
|
|
{
|
|
|
|
|
this->max_offset = offset;
|
|
|
|
|
this->max_new_entities = maximum;
|
|
|
|
|
this->invalid_ID = invalid;
|
|
|
|
|
this->max_entities = maximum;
|
|
|
|
|
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);
|
|
|
|
|
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);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -62,7 +62,7 @@ void OverrideManagerBase::Add(uint8 local_id, uint32 grfid, uint entity_type)
|
|
|
|
|
{
|
|
|
|
|
assert(entity_type < this->max_offset);
|
|
|
|
|
/* 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->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 */
|
|
|
|
|
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 */
|
|
|
|
|
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());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -88,14 +88,14 @@ void OverrideManagerBase::ResetOverride()
|
|
|
|
|
*/
|
|
|
|
|
uint16 OverrideManagerBase::GetID(uint8 grf_local_id, uint32 grfid) const
|
|
|
|
|
{
|
|
|
|
|
for (uint16 id = 0; id < this->max_new_entities; id++) {
|
|
|
|
|
const EntityIDMapping *map = &this->mapping_ID[id];
|
|
|
|
|
for (uint16 id = 0; id < this->max_entities; id++) {
|
|
|
|
|
const EntityIDMapping *map = &this->mappings[id];
|
|
|
|
|
if (map->entity_id == grf_local_id && map->grfid == grfid) {
|
|
|
|
|
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
|
|
|
|
|
* 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. */
|
|
|
|
|
for (id = this->max_offset; id < this->max_new_entities; id++) {
|
|
|
|
|
EntityIDMapping *map = &this->mapping_ID[id];
|
|
|
|
|
for (id = this->max_offset; id < this->max_entities; id++) {
|
|
|
|
|
EntityIDMapping *map = &this->mappings[id];
|
|
|
|
|
|
|
|
|
|
if (CheckValidNewID(id) && map->entity_id == 0 && map->grfid == 0) {
|
|
|
|
|
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
|
|
|
|
|
{
|
|
|
|
|
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
|
|
|
|
|
{
|
|
|
|
|
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);
|
|
|
|
|
|
|
|
|
|
if (house_id == this->invalid_ID) {
|
|
|
|
|
if (house_id == this->invalid_id) {
|
|
|
|
|
grfmsg(1, "House.SetEntitySpec: Too many houses allocated. Ignoring.");
|
|
|
|
|
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;
|
|
|
|
|
|
|
|
|
|
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;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
@ -187,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 != this->invalid_ID) return id;
|
|
|
|
|
if (id != this->invalid_id) return id;
|
|
|
|
|
|
|
|
|
|
/* No mapping found, try the overrides */
|
|
|
|
|
for (id = 0; id < this->max_offset; 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)
|
|
|
|
|
{
|
|
|
|
|
/* 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 */
|
|
|
|
|
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 */
|
|
|
|
|
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).
|
|
|
|
|
* So reserve this slot here, as it is the chosen one */
|
|
|
|
|
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) {
|
|
|
|
|
/* 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. */
|
|
|
|
|
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.
|
|
|
|
|
* 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 = 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.");
|
|
|
|
|
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);
|
|
|
|
|
|
|
|
|
|
if (indt_id == this->invalid_ID) {
|
|
|
|
|
if (indt_id == this->invalid_id) {
|
|
|
|
|
grfmsg(1, "IndustryTile.SetEntitySpec: Too many industry tiles allocated. Ignoring.");
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
@ -283,7 +283,7 @@ void IndustryTileOverrideManager::SetEntitySpec(const IndustryTileSpec *its)
|
|
|
|
|
|
|
|
|
|
overridden_its->grf_prop.override = indt_id;
|
|
|
|
|
overridden_its->enabled = false;
|
|
|
|
|
this->entity_overrides[i] = this->invalid_ID;
|
|
|
|
|
this->entity_overrides[i] = this->invalid_id;
|
|
|
|
|
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. */
|
|
|
|
|
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.
|
|
|
|
|
* Or it has already been overridden, so you've lost your place.
|
|
|
|
|
* 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);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (type == this->invalid_ID) {
|
|
|
|
|
if (type == this->invalid_id) {
|
|
|
|
|
grfmsg(1, "Object.SetEntitySpec: Too many objects allocated. Ignoring.");
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|