OpenTTD AI API  20241111-master-gce64d5f5d9
Identifying game object

IDs are used to identify certain objects.

They are only unique within the object type, so for example a vehicle may have VehicleID 2009, while a station has StationID 2009 at the same time. Also IDs are assigned arbitrary, you cannot assume them to be consecutive. Also note that some IDs are static and never change, while others are allocated dynamically and might be reused for other objects once they are released. So be careful, which IDs you store for which purpose and whether they stay valid all the time.

type object acquired released reused
BridgeID bridge type introduction (1) never (1) no (1)
CargoID cargo type game start (1) never (1) no (1)
EngineID engine type introduction, preview (2) engines retires (2) no (2)
GoalID goal creation deletion yes
GroupID vehicle group creation deletion yes
IndustryID industry construction closure yes
IndustryTypeindustry type game start (1) never (1) no
ObjectType NewGRF object type game start (1) never (1) no
ScriptErrorTypeerror message OpenTTD start (3) OpenTTD exit no
SignID sign construction deletion yes
StationID station construction expiration of 'grey' station sign after deletion yes
StringID translatable text OpenTTD start (3) OpenTTD exit no
SubsidyID subsidy offer announcement (offer) expiration yes
StoryPageID story page creation deletion yes
StoryPageElementIDstory page element creation deletion yes
TileIndex tile on map game start never no
TownID town game start never no
VehicleID vehicle construction, autorenew, autoreplace destruction, autorenew, autoreplace yes
Remarks
  • (1) in-game changes of newgrfs may reassign/invalidate IDs (will also cause other trouble though).
  • (2) engine IDs are reassigned/invalidated on changing 'allow multiple newgrf engine sets' (only allowed as long as no vehicles are built).
  • (3) string/error IDs are only valid during a session, and may be reassigned/invalidated when loading savegames (so you cannot store them).