entity_util¶
Source: base/tealdef/scripts/entity_util.d.tl
Notes
Types of /scripts/entity_util.tl (EntityUtil): helpers to remember an entity together with its
revision (so a script can detect later that it changed or was removed), and ownership/position lookups.
EntityUtil¶
record global base/tealdef/scripts/entity_util.d.tl:3
global record EntityUtil
Load: local entity_util = ug_require "::/scripts/entity_util.tl" as EntityUtil
Notes
Entity helpers returned by ug_require "/scripts/entity_util.tl".
Functions
makeEntityAndRevision(Engine.Entity) : EntityAndRevision base/tealdef/scripts/entity_util.d.tl:9
Call as entity_util.makeEntityAndRevision(…)
Notes
Records an entity with its full current revision.
Returns EntityAndRevision: The record, or nil if the entity does not exist.
Used in the base game: 54 times in 31 files
base/content/game_mechanics/game_mechanics/company/company.script.tl:151
base/content/game_mechanics/game_mechanics/company/company_util.tl:255
base/content/game_mechanics/game_mechanics/emission/emission_legacy_util.tl:30
base/content/game_mechanics/game_mechanics/emission/emissions.script.tl:187
base/content/game_mechanics/game_mechanics/fun_elements/blimp_util.tl:148
base/content/game_mechanics/game_mechanics/fun_elements/rocket_util.tl:38
… and 25 more files.
makeEntityAndRevision0(Engine.Entity) : EntityAndRevision base/tealdef/scripts/entity_util.d.tl:10
Call as entity_util.makeEntityAndRevision0(…)
Notes
Records an entity with only the first revision number (the other two set to 0).
Returns EntityAndRevision: The record, or nil if the entity does not exist.
Details
Use with entityChanged0, which compares only the first revision number.
Used in the base game: 34 times in 8 files
base/content/game_mechanics/game_mechanics/celebrations/celebrations.script.tl:189
base/content/game_mechanics/game_mechanics/company/company.script.tl:441
base/content/game_mechanics/game_mechanics/company/company_legacy_util.tl:49
base/content/game_mechanics/game_mechanics/notifications/notifications.script.tl:145
base/content/gui/gui/construction/construction_react_util.tl:1469
base/content/mission/mission/tasks/utility/store_entity.tl:8
… and 2 more files.
makeEntityAndRevision0Array({Engine.Entity}) : {EntityUtil.EntityAndRevision} base/tealdef/scripts/entity_util.d.tl:11
Call as entity_util.makeEntityAndRevision0Array(…)
Notes
Applies makeEntityAndRevision0 to each entity and returns the records of those that exist.
Returns {EntityUtil.EntityAndRevision}
Used in the base game: 6 times in 3 files
base/content/game_mechanics/game_mechanics/notifications/notifications.script.tl:206
base/content/gui/gui/line_vehicle_mgmt/vehicle_store_window.tl:4485
return params.vehicleEntities and entity_util.makeEntityAndRevision0Array(params.vehicleEntities) or nil
mods/release/urbangames_campaign_mission_05/content/mission/mission/tasks/drilling/drilling.tl:20
entityEquals(EntityAndRevision, EntityAndRevision) : boolean base/tealdef/scripts/entity_util.d.tl:12
Call as entity_util.entityEquals(…)
Notes
True if both records have the same entity id and the same first revision number.
Returns boolean
Used in the base game: 6 times in 6 files
base/content/game_mechanics/game_mechanics/company/company.script.tl:491
base/content/game_mechanics/game_mechanics/company/company_util.tl:246
base/content/game_mechanics/game_mechanics/emission/emissions.script.tl:189
base/content/game_mechanics/game_mechanics/towns/town_util.tl:209
base/content/gui/gui/entity_window/industry/industry.tl:31
base/content/industries/industry_workers.script.tl:63
entityChanged0(EntityAndRevision) : boolean base/tealdef/scripts/entity_util.d.tl:13
Call as entity_util.entityChanged0(…)
Notes
True if the entity no longer exists or its first revision number has increased since the record was made.
Returns boolean
Used in the base game: 87 times in 43 files
base/content/game_mechanics/game_mechanics/celebrations/celebration_react_util.tl:202
base/content/game_mechanics/game_mechanics/company/company.script.tl:202
proposal = api.engine.util.proposal.makeIndustrySpawnProposal(industryType, (not entity_util.entityChanged0(pending.townEntity)) and pending.townEntity.entity o
base/content/game_mechanics/game_mechanics/company/company_notification_greenify.sim.script.tl:6
if notificationParams.constructionEntity and not entity_util.entityChanged0(notificationParams.constructionEntity) then
base/content/game_mechanics/game_mechanics/company/company_notification_marketing.sim.script.tl:6
if notificationParams.townEntity and not entity_util.entityChanged0(notificationParams.townEntity) then
base/content/game_mechanics/game_mechanics/company/company_notification_prospection.sim.script.tl:5
if notificationParams.townEntity and not entity_util.entityChanged0(notificationParams.townEntity) then
base/content/game_mechanics/game_mechanics/notifications/notification_util.tl:444
… and 37 more files.
entityChanged(EntityAndRevision) : boolean base/tealdef/scripts/entity_util.d.tl:14
Call as entity_util.entityChanged(…)
Notes
True if the entity no longer exists or its first or second revision number has increased since the record was made.
Returns boolean
Used in the base game: 2 times in 2 files
base/content/gui/gui/entity_window/bridge_and_tunnel.tl:199
mods/release/urbangames_campaign_mission_03/content/mission/mission/mission_story.tl:90
getPosition(Engine.Entity) : Vec3f base/tealdef/scripts/entity_util.d.tl:15
Call as entity_util.getPosition(…)
Notes
Centre of the entity's bounding box (BOUNDING_VOLUME component).
Returns Vec3f: The centre position, or nil if the entity has no bounding volume.
Used in the base game: 54 times in 26 files
base/content/game_mechanics/game_mechanics/achievements/achievements.script.tl:412
base/content/game_mechanics/game_mechanics/fun_elements/blimp_util.tl:128
base/content/game_mechanics/game_mechanics/fun_elements/fireworks.script.tl:152
base/content/game_mechanics/game_mechanics/fun_elements/ufo_util.tl:122
base/content/game_mechanics/game_mechanics/subventions/deliver_cargo/deliver_cargo.script.tl:74
base/content/game_mechanics/game_mechanics/subventions/deliver_cargo_town/deliver_cargo_town.script.tl:115
… and 20 more files.
sameRevision(Engine.Revision, Engine.Revision) : boolean base/tealdef/scripts/entity_util.d.tl:16
Call as entity_util.sameRevision(…)
Notes
True if all three revision numbers are equal.
Returns boolean
getEntityName(Engine.Entity) : string base/tealdef/scripts/entity_util.d.tl:17
Call as entity_util.getEntityName(…)
Notes
Display name of the entity (api.engine.util.getEntityName).
Returns string
Used in the base game: 34 times in 23 files
base/content/game_mechanics/game_mechanics/celebrations/celebration_react_util.tl:31
base/content/game_mechanics/game_mechanics/company/company_notification_greenify.sim.script.tl:7
old.constructionEntityName = entity_util.getEntityName(notificationParams.constructionEntity.entity)
base/content/game_mechanics/game_mechanics/company/company_notification_marketing.sim.script.tl:7
base/content/game_mechanics/game_mechanics/company/company_notification_prospection.sim.script.tl:6
base/content/game_mechanics/game_mechanics/notifications/notification_legacy_util.tl:99
base/content/game_mechanics/game_mechanics/notifications/types/cargo_rtc_warning.sim.script.tl:17
… and 17 more files.
getPlayerOwned(Engine.Entity) : Engine.Component.PlayerOwned base/tealdef/scripts/entity_util.d.tl:18
Call as entity_util.getPlayerOwned(…)
Notes
The entity's PLAYER_OWNED component, or nil if no player owns it.
Returns Engine.Component.PlayerOwned
isOwnedByPlayer(Engine.Entity) : boolean base/tealdef/scripts/entity_util.d.tl:19
Call as entity_util.isOwnedByPlayer(…)
Notes
True if the entity is owned by the current player (api.engine.util.getPlayer()).
Returns boolean
Used in the base game: 30 times in 16 files
base/content/game_mechanics/game_mechanics/achievements/achievements.script.tl:403
base/content/game_mechanics/game_mechanics/notifications/notifications.script.tl:558
base/content/gui/gui/entity_window/entity_window_util.tl:1801
base/content/gui/gui/entity_window/industry/industry.tl:184
base/content/gui/gui/entity_window/maintenance_station/maintenance_station.tl:31
base/content/gui/gui/entity_window/station_group/station_group.tl:623
… and 10 more files.
isOwnedByPlayerOrNotOwned(Engine.Entity) : boolean base/tealdef/scripts/entity_util.d.tl:20
Call as entity_util.isOwnedByPlayerOrNotOwned(…)
Notes
True if the entity is owned by the current player or has no owner.
Returns boolean
Used in the base game: 12 times in 8 files
base/content/game_mechanics/game_mechanics/notifications/notifications.script.tl:522
base/content/gui/gui/entity_window/vehicle/vehicle.tl:377
base/content/gui/gui/entity_window/warehouse/warehouse.tl:38
base/content/gui/gui/line_vehicle_mgmt/line_util.tl:1218
base/content/gui/gui/line_vehicle_mgmt/manager_window.tl:49
base/content/gui/gui/main/hud_icon_toolbox.tl:196
… and 2 more files.
getBoundingVolumePosition(Engine.Component.BoundingVolume) : Vec3f base/tealdef/scripts/entity_util.d.tl:22
Call as entity_util.getBoundingVolumePosition(…)
Notes
Centre of the given bounding volume's box.
Returns Vec3f
EntityUtil.EntityAndRevision¶
record base/tealdef/scripts/entity_util.d.tl:4
record EntityAndRevision
Notes
An entity id stored together with the revision it had when it was recorded. Scripts keep these in
their state and later call entityChanged / entityChanged0 to see whether the entity was modified,
rebuilt or removed in the meantime.
Used in the base game: 101 times in 29 files
base/content/game_mechanics/game_mechanics/celebrations/celebration_react_util.tl:13
base/content/game_mechanics/game_mechanics/celebrations/celebrations.script.tl:15
base/content/game_mechanics/game_mechanics/company/company.script.tl:488
local ecoLevels = emissionsScriptState and emissionsScriptState.ecoLevels as {Engine.Entity : {EntityUtil.EntityAndRevision, integer}} or nil
base/content/game_mechanics/game_mechanics/company/company_util.tl:238
function company_util.findStateIndex(companiesState : CompaniesState, companyEntityAndRevision : EntityUtil.EntityAndRevision) : integer
base/content/game_mechanics/game_mechanics/company/explorations/exploration_plane.script.tl:27
base/content/game_mechanics/game_mechanics/emission/emission_legacy_util.tl:22
… and 23 more files.
Fields
| Name | Type | Description |
|---|---|---|
entity |
Engine.Entity |
The entity id. |
revision |
Engine.Revision |
The revision of the entity at the time it was recorded. |