OpenTTD Source: OverrideManagerBase Class Reference

OpenTTD Source 15.0-RC2

Public Member Functions | Data Fields | Protected Member Functions | Protected Attributes
OverrideManagerBase Class Reference
Inheritance diagram for OverrideManagerBase:

## Public Member Functions
| OverrideManagerBase (uint16_t offset, uint16_t maximum, uint16_t invalid)
| Constructor of generic class.
void | ResetOverride ()
| Resets the override, which is used while initializing game.
void | ResetMapping ()
| Resets the mapping, which is used while initializing game.
void | Add (uint16_t local_id, uint32_t grfid, uint entity_type)
| Since the entity IDs defined by the GRF file does not necessarily correlate to those used by the game, the IDs used for overriding old entities must be translated when the entity spec is set.
virtual uint16_t | AddEntityID (uint16_t grf_local_id, uint32_t grfid, uint16_t substitute_id)
| Reserves a place in the mapping array for an entity to be installed.
uint32_t | GetGRFID (uint16_t entity_id) const
| Gives the GRFID of the file the entity belongs to.
uint16_t | GetSubstituteID (uint16_t entity_id) const
| Gives the substitute of the entity, as specified by the grf file.
virtual uint16_t | GetID (uint16_t grf_local_id, uint32_t grfid) const
| Return the ID (if ever available) of a previously inserted entity.
uint16_t | GetMaxMapping () const
uint16_t | GetMaxOffset () const

## Data Fields
std::vector< EntityIDMapping > | mappings
| mapping of ids from grf files. Public out of convenience

## Protected Member Functions
virtual bool | CheckValidNewID (uint16_t testid)

## Protected Attributes
std::vector< uint16_t > | entity_overrides
std::vector< uint32_t > | grfid_overrides
uint16_t | max_offset
| what is the length of the original entity's array of specs
uint16_t | max_entities
| what is the amount of entities, old and new summed
uint16_t | invalid_id
| ID used to detected invalid entities.

## Detailed Description

Definition at line 198 of file newgrf_commons.h.

## Constructor & Destructor Documentation

## ◆ OverrideManagerBase()

OverrideManagerBase::OverrideManagerBase | ( | uint16_t | offset,
|  | uint16_t | maximum,
|  | uint16_t | invalid
| ) |  |

Constructor of generic class.

Parameters

  offset | end of original data for this entity. i.e: houses = 110
  maximum | of entities this manager can deal with. i.e: houses = 512
  invalid | is the ID used to identify an invalid entity id

Definition at line 43 of file newgrf_commons.cpp.

References invalid_id, mappings, max_entities, and max_offset.

## Member Function Documentation

## ◆ Add()

void OverrideManagerBase::Add | ( | uint16_t | local_id,
|  | uint32_t | grfid,
|  | uint | entity_type
| ) |  |

Since the entity IDs defined by the GRF file does not necessarily correlate to those used by the game, the IDs used for overriding old entities must be translated when the entity spec is set.

Parameters

  local_id | ID in grf file
  grfid | ID of the grf file
  entity_type | original entity type

Definition at line 63 of file newgrf_commons.cpp.

References invalid_id, and max_offset.

Referenced by AirportChangeInfo(), IndustriesChangeInfo(), IndustrytilesChangeInfo(), and TownHouseChangeInfo().

## ◆ AddEntityID()

uint16_t OverrideManagerBase::AddEntityID | ( | uint16_t | grf_local_id,
|  | uint32_t | grfid,
|  | uint16_t | substitute_id
| ) |  |
| virtual

Reserves a place in the mapping array for an entity to be installed.

Parameters

  grf_local_id | is an arbitrary id given by the grf's author. Also known as setid
  grfid | is the id of the grf file itself
  substitute_id | is the original entity from which data is copied for the new one

Returns
  the proper usable slot id, or invalid marker if none is found

Reimplemented in IndustryOverrideManager.

Definition at line 110 of file newgrf_commons.cpp.

References EntityIDMapping::entity_id, GetID(), EntityIDMapping::grfid, invalid_id, mappings, max_entities, max_offset, and EntityIDMapping::substitute_id.

Referenced by IndustrytilesChangeInfo(), HouseOverrideManager::SetEntitySpec(), and ObjectOverrideManager::SetEntitySpec().

## ◆ CheckValidNewID()

virtual bool OverrideManagerBase::CheckValidNewID | ( | uint16_t | testid | ) |
| inlineprotectedvirtual

Definition at line 207 of file newgrf_commons.h.

## ◆ GetGRFID()

uint32_t OverrideManagerBase::GetGRFID | ( | uint16_t | entity_id | ) | const

Gives the GRFID of the file the entity belongs to.

Parameters

  entity_id | ID of the entity being queried.

Returns
  GRFID.

Definition at line 140 of file newgrf_commons.cpp.

References mappings.

Referenced by AfterLoadGame(), AirportSpec::Get(), and HouseScopeResolver::GetVariable().

## ◆ GetID()

uint16_t OverrideManagerBase::GetID | ( | uint16_t | grf_local_id,
|  | uint32_t | grfid
| ) |  | const
| virtual

Return the ID (if ever available) of a previously inserted entity.

Parameters

  grf_local_id | ID of this entity within the grfID
  grfid | ID of the grf file

Returns
  the ID of the candidate, of the Invalid flag item ID

Reimplemented in IndustryOverrideManager.

Definition at line 91 of file newgrf_commons.cpp.

References EntityIDMapping::entity_id, EntityIDMapping::grfid, invalid_id, mappings, and max_entities.

Referenced by AddEntityID(), AirportChangeInfo(), GetCountAndDistanceOfClosestInstance(), IndustryOverrideManager::GetID(), HouseScopeResolver::GetVariable(), IndustriesChangeInfo(), and ObjectOverrideManager::SetEntitySpec().

## ◆ GetMaxMapping()

uint16_t OverrideManagerBase::GetMaxMapping | ( |  | ) | const
| inline

Definition at line 225 of file newgrf_commons.h.

## ◆ GetMaxOffset()

uint16_t OverrideManagerBase::GetMaxOffset | ( |  | ) | const
| inline

Definition at line 226 of file newgrf_commons.h.

## ◆ GetSubstituteID()

uint16_t OverrideManagerBase::GetSubstituteID | ( | uint16_t | entity_id | ) | const

Gives the substitute of the entity, as specified by the grf file.

Parameters

  entity_id | of the entity being queried

Returns
  mapped id

Definition at line 150 of file newgrf_commons.cpp.

References mappings.

Referenced by AirportSpec::Get(), and UpdateHousesAndTowns().

## ◆ ResetMapping()

void OverrideManagerBase::ResetMapping | ( |  | ) |

Resets the mapping, which is used while initializing game.

Definition at line 73 of file newgrf_commons.cpp.

References mappings.

Referenced by NewGRFMappingChunkHandler::Load(), and ResetPersistentNewGRFData().

## ◆ ResetOverride()

void OverrideManagerBase::ResetOverride | ( |  | ) |

Resets the override, which is used while initializing game.

Definition at line 79 of file newgrf_commons.cpp.

Referenced by AirportSpec::ResetAirports(), AirportTileSpec::ResetAirportTiles(), and ResetIndustries().

## Field Documentation

## ◆ entity_overrides

std::vector<uint16_t> OverrideManagerBase::entity_overrides
| protected

Definition at line 200 of file newgrf_commons.h.

## ◆ grfid_overrides

std::vector<uint32_t> OverrideManagerBase::grfid_overrides
| protected

Definition at line 201 of file newgrf_commons.h.

## ◆ invalid_id

uint16_t OverrideManagerBase::invalid_id
| protected

ID used to detected invalid entities.

Definition at line 206 of file newgrf_commons.h.

Referenced by Add(), AddEntityID(), IndustryOverrideManager::AddEntityID(), GetID(), IndustryOverrideManager::GetID(), OverrideManagerBase(), HouseOverrideManager::SetEntitySpec(), IndustryOverrideManager::SetEntitySpec(), and ObjectOverrideManager::SetEntitySpec().

## ◆ mappings

std::vector<EntityIDMapping> OverrideManagerBase::mappings

mapping of ids from grf files. Public out of convenience

Definition at line 210 of file newgrf_commons.h.

Referenced by AddEntityID(), IndustryOverrideManager::AddEntityID(), GetGRFID(), GetID(), GetSubstituteID(), NewGRFMappingChunkHandler::Load(), OverrideManagerBase(), ResetMapping(), and NewGRFMappingChunkHandler::Save().

## ◆ max_entities

uint16_t OverrideManagerBase::max_entities
| protected

what is the amount of entities, old and new summed

Definition at line 204 of file newgrf_commons.h.

Referenced by AddEntityID(), IndustryOverrideManager::AddEntityID(), GetID(), and OverrideManagerBase().

## ◆ max_offset

uint16_t OverrideManagerBase::max_offset
| protected

what is the length of the original entity's array of specs

Definition at line 203 of file newgrf_commons.h.

Referenced by Add(), AddEntityID(), IndustryOverrideManager::AddEntityID(), IndustryOverrideManager::GetID(), OverrideManagerBase(), and HouseOverrideManager::SetEntitySpec().

The documentation for this class was generated from the following files:

- src/newgrf_commons.h
- src/newgrf_commons.cpp