Skip to content

company_util

Source: base/tealdef/game_mechanics/company/company_util.d.tl

Notes

Permit counting, disable reasons and state access of the company.

CompanyUtil

record global base/tealdef/game_mechanics/company/company_util.d.tl:3

global record CompanyUtil

Load: local company_util = ug_require "/game_mechanics/company/company_util.tl"

Notes

Permit counting, disable reasons and state access of the company.

Fields

Name Type Description
prospectionTimeMs number Maximum length of a prospection, six game months in ms. used 2× in the base game
prospectionIntervalTimeMs number Time between spawn attempts of a prospection, one game month in ms.
prospectionStartChance number Chance of the first spawn attempt (0.2).
prospectionEndChance number Chance of the last spawn attempt (0.6); the chance rises linearly in between.

Functions

getActualPermitKey(constructionRes : ResName, metadata : ConstructionDescMetadata) : ResName base/tealdef/game_mechanics/company/company_util.d.tl:9

Call as company_util.getActualPermitKey

Notes

Returns the permit key of a construction. It is the permitKey, or the construction file if the metadata has rankAndPermits or companyRank.

Parameter Type Description
constructionRes ResName Construction file.
metadata ConstructionDescMetadata Metadata of the construction resource.

Returns ResName: Permit key, or nil if the construction needs no permit.

Used in the base game: 1 time in 1 file

base/content/game_mechanics/game_mechanics/company/company_react_util.tl:14

local actualPermitKey = company_util.getActualPermitKey(constructionFile, perk.metadata)

getMaximumNumberOfPermits(companyProgress : CompaniesGrowthState.CompanyData, actualPermitKey : ResName, metadata : ConstructionDescMetadata) : integer, boolean base/tealdef/game_mechanics/company/company_util.d.tl:10

Call as company_util.getMaximumNumberOfPermits

Notes

Returns how many permits of a key the company has, from the construction's rankAndPermits up to its rank plus the extra permits of the key.

Parameter Type Description
companyProgress CompaniesGrowthState.CompanyData Progression of the company.
actualPermitKey ResName Permit key.
metadata ConstructionDescMetadata Metadata of the construction resource.

Returns integer, boolean: Number of permits, and true if the metadata mixes rankAndPermits with permitKey.

getNumberOfPermitsForRank(companyProgress : CompaniesGrowthState.CompanyData, metadata : ConstructionDescMetadata) : integer, boolean base/tealdef/game_mechanics/company/company_util.d.tl:11

Call as company_util.getNumberOfPermitsForRank

Notes

Returns the permits a construction gains at exactly the company's rank.

Parameter Type Description
companyProgress CompaniesGrowthState.CompanyData Progression (only level is read).
metadata ConstructionDescMetadata Metadata of the construction resource.

Returns integer, boolean: Number of permits, and the mixed-metadata warning flag.

Used in the base game: 1 time in 1 file

base/content/game_mechanics/game_mechanics/company/company_react_util.tl:51

permits = company_util.getNumberOfPermitsForRank({level = rank.level}, perk.metadata)

getConstructionDisableCacheData(allDefs : {{ResName, ConstructionDescMetadata, string}}) : ConstructionDisableCacheData base/tealdef/game_mechanics/company/company_util.d.tl:36

Call as company_util.getConstructionDisableCacheData

Notes

Computes rank, permits, consumed permits, cooldowns and build counts of the player for a list of constructions.

Parameter Type Description
allDefs {{ResName, ConstructionDescMetadata, string}} List of {construction file, metadata, name}.

Returns ConstructionDisableCacheData: Cache data.

Used in the base game: 1 time in 1 file

base/content/gui/gui/construction/construction_react_util.tl:1171

cache.company = company_util.getConstructionDisableCacheData(allDefs)

getConstructionDisableReason(constructionRes : ResName, metadata : ConstructionDescMetadata, cache : ConstructionDisableCacheData) : ItemDisableReason base/tealdef/game_mechanics/company/company_util.d.tl:37

Call as company_util.getConstructionDisableReason

Notes

Tells why a construction cannot be built (rank, cooldown, no permits left).

Parameter Type Description
constructionRes ResName Construction file.
metadata ConstructionDescMetadata Metadata of the construction resource.
cache ConstructionDisableCacheData Result of getConstructionDisableCacheData.

Returns ItemDisableReason: Reason with remaining permits, or nil if the construction has no company limits.

Used in the base game: 2 times in 1 file

base/content/gui/gui/construction/construction_react_util.tl:1176

local companyReason = company_util.getConstructionDisableReason(def.resName, def.metadata, cache.company)

findStateIndex(CompaniesState, EntityUtil.EntityAndRevision) : integer base/tealdef/game_mechanics/company/company_util.d.tl:39

Call as company_util.findStateIndex

Notes

Finds the index of a company in the state.

Parameter Type Description
#1 CompaniesState Companies state.
#2 EntityUtil.EntityAndRevision Company entity and revision.

Returns integer: Index, or -1.

getCompanyState(CompaniesState, Engine.Entity) : CompanyState base/tealdef/game_mechanics/company/company_util.d.tl:40

Call as company_util.getCompanyState

Notes

Returns the state of a company, or a new empty one for a player without state.

Parameter Type Description
#1 CompaniesState Companies state.
#2 Engine.Entity Player entity.

Returns CompanyState: Company state, or nil if the entity is not a player.

Used in the base game: 1 time in 1 file

base/content/game_mechanics/game_mechanics/notifications/notifications.script.tl:326

local companyState : CompanyState = company_util.getCompanyState(company_util.externalGetCompaniesState(), companyEntity)

setCompanyState(CompaniesState, Engine.Entity, CompanyState) : CompanyState base/tealdef/game_mechanics/company/company_util.d.tl:41

Call as company_util.setCompanyState

Notes

Stores the state of a company, adding it if missing.

Parameter Type Description
#1 CompaniesState Companies state.
#2 Engine.Entity Player entity.
#3 CompanyState Company state.

Returns CompanyState

externalGetCompanyState(Engine.Entity) : CompanyState base/tealdef/game_mechanics/company/company_util.d.tl:42

Call as company_util.externalGetCompanyState

Notes

Reads the state of a company from the company game script.

Parameter Type Description
#1 Engine.Entity Player entity.

Returns CompanyState: Company state.

Used in the base game: 3 times in 2 files

base/content/gui/gui/construction/construction_react_util.tl:1468

local companyState = company_util.externalGetCompanyState(api.engine.util.getPlayer())
base/content/game_mechanics/game_mechanics/company/company_react_util.tl:211
local companyState = company_util.externalGetCompanyState(companyEntity)

externalGetCompaniesState() : CompaniesState base/tealdef/game_mechanics/company/company_util.d.tl:43

Call as company_util.externalGetCompaniesState

Notes

Reads the state of the company game script.

Returns CompaniesState: Companies state.

Used in the base game: 1 time in 1 file

base/content/game_mechanics/game_mechanics/notifications/notifications.script.tl:326

local companyState : CompanyState = company_util.getCompanyState(company_util.externalGetCompaniesState(), companyEntity)

getNeededPermitsForProposal(Proposal, ProposalData) : {ResName : integer}, {ResName : ConstructionDescMetadata} base/tealdef/game_mechanics/company/company_util.d.tl:44

Call as company_util.getNeededPermitsForProposal

Notes

Counts the permits that the new constructions of a proposal need (replaced constructions excluded).

Parameter Type Description
#1 Proposal Proposal.
#2 ProposalData Proposal data (unused).

Returns {ResName : integer}, {ResName : ConstructionDescMetadata}: Permit key -> count, and permit key -> metadata.

countUsedConstructionPermits(permitKeys : {ResName : any}) : {ResName : integer} base/tealdef/game_mechanics/company/company_util.d.tl:45

Call as company_util.countUsedConstructionPermits

Notes

Counts the built constructions per permit key.

Parameter Type Description
permitKeys {ResName : any} Unused.

Returns {ResName : integer}: Permit key -> number built.

getCompanyMetadataFromConstructionResource(constructionEntity : Engine.Entity) : CompanyMetadata.ConstructionDesc base/tealdef/game_mechanics/company/company_util.d.tl:47

Call as company_util.getCompanyMetadataFromConstructionResource

Notes

Returns the company metadata of a built construction's resource.

Parameter Type Description
constructionEntity Engine.Entity Construction entity.

Returns CompanyMetadata.ConstructionDesc: Company metadata, or nil.

Used in the base game: 4 times in 3 files

base/content/landmarks/landmark_hud.script.tl:31

local companyMetaFromRes = company_util.getCompanyMetadataFromConstructionResource(entity)
base/content/gui/gui/entity_window/entity_window_hud.tl:199
companyMeta = company_util.getCompanyMetadataFromConstructionResource(owningConstructionEntity)
base/content/game_mechanics/game_mechanics/emission/pollution_cleanup_facility_hud.script.tl:39
local companyMetaFromRes = company_util.getCompanyMetadataFromConstructionResource(entity)

getCurrentCompanyState() : CurrentCompanyState base/tealdef/game_mechanics/company/company_util.d.tl:54

Call as company_util.getCurrentCompanyState

Notes

Returns rank and experience of the player (zeros if unknown).

Returns CurrentCompanyState: Current company state.

Used in the base game: 1 time in 1 file

base/content/game_mechanics/game_mechanics/company/company.tl:677

return company_util.getCurrentCompanyState()

getBasePopulation() : integer base/tealdef/game_mechanics/company/company_util.d.tl:55

Call as company_util.getBasePopulation

note: This will never change during play

Returns integer

Used in the base game: 4 times in 4 files

base/content/gui/gui/game_bar/game_bar.tl:392

local basePopulation = company_util.getBasePopulation()
base/content/game_mechanics/game_mechanics/company/company_react_util.tl:80
local basePopulation = company_util.getBasePopulation()
base/content/game_mechanics/game_mechanics/company/company_growth.script.tl:81
local basePopulation = company_util.getBasePopulation()
base/content/game_mechanics/game_mechanics/subventions/subventions.script.tl:247
local basePopulation = company_util.getBasePopulation()

computeWorldPopulation() : integer base/tealdef/game_mechanics/company/company_util.d.tl:56

Call as company_util.computeWorldPopulation

Notes

Sums the residential capacity of all towns.

Returns integer: World population.

Used in the base game: 1 time in 1 file

base/content/game_mechanics/game_mechanics/company/company_growth.script.tl:86

local numResidents = company_util.computeWorldPopulation()

isConstructionLandmark(constructionEntity : Engine.Entity) : boolean base/tealdef/game_mechanics/company/company_util.d.tl:58

Call as company_util.isConstructionLandmark

Notes

Tells whether a construction's company perk category is LANDMARK.

Parameter Type Description
constructionEntity Engine.Entity Construction entity.

Returns boolean: true for landmarks.

Used in the base game: 2 times in 1 file

mods/release/urbangames_campaign_mission_06/content/subventions/subventions/deliver_visitors/deliver_visitors.script.tl:120

if company_util.isConstructionLandmark(entity) then

CompanyUtil.ItemDisableReason

record base/tealdef/game_mechanics/company/company_util.d.tl:13

record ItemDisableReason

Notes

Why a construction cannot be built (or how many permits remain).

Used in the base game: 1 time in 1 file

base/content/game_mechanics/game_mechanics/company/company_util.tl:171

function company_util.getConstructionDisableReason(constructionRes : ResName, metadata : ConstructionDescMetadata, cache : CompanyUtil.ConstructionDisableCacheD

Fields

Name Type Description
reason string Text such as "Unlocked at Rank", "Cooldown", "Already Built" or "Already Used"; nil if it can be built.
elapsedCooldownFraction number Elapsed part of the cooldown (0 to 1).
category string company-rank when the rank is too low or too high.
numRemaining integer Permits left.

CompanyUtil.ConstructionDisableCacheData

record base/tealdef/game_mechanics/company/company_util.d.tl:19

record ConstructionDisableCacheData

Notes

Precomputed permit data for getConstructionDisableReason.

Used in the base game: 3 times in 1 file

base/content/game_mechanics/game_mechanics/company/company_util.tl:83

function company_util.getConstructionDisableCacheData(allDefs : {{ResName, ConstructionDescMetadata, string}}) : CompanyUtil.ConstructionDisableCacheData

Fields

Name Type Description
companyRank integer Applied company rank.
extraPermits {ResName : integer} Permit key -> extra permits by rank.
maximumPermits {ResName : integer} contains extra permits
consumedPermits {ResName : integer} Permit key -> permits consumed and still in cooldown.
remainingPermitCooldown {ResName : CooldownState} Permit key -> cooldown of the oldest consumed permit.
data {ResName : ItemDisableCacheData} Construction file or permit key -> build count.

CompanyUtil.ConstructionDisableCacheData.CooldownState

record base/tealdef/game_mechanics/company/company_util.d.tl:20

record CooldownState

Notes

Cooldown of a permit key.

Fields

Name Type Description
remainingMs number Remaining cooldown in game time (ms).
elapsedFraction number Elapsed part of the cooldown (0 to 1).

CompanyUtil.ConstructionDisableCacheData.ItemDisableCacheData

record base/tealdef/game_mechanics/company/company_util.d.tl:31

record ItemDisableCacheData

Notes

Build count of a permit key.

Used in the base game: 1 time in 1 file

base/content/game_mechanics/game_mechanics/company/company_util.tl:144

local data : {ResName : CompanyUtil.ConstructionDisableCacheData.ItemDisableCacheData} = {}

Fields

Name Type Description
numBuilt integer Constructions built with this file or permit key.

CompanyUtil.CurrentCompanyState

record base/tealdef/game_mechanics/company/company_util.d.tl:49

record CurrentCompanyState

Notes

Rank and experience of the player.

Used in the base game: 6 times in 2 files

base/content/game_mechanics/game_mechanics/company/company.tl:20

companyState : CompanyUtil.CurrentCompanyState
base/content/game_mechanics/game_mechanics/company/company_util.tl:373
function company_util.getCurrentCompanyState() : CompanyUtil.CurrentCompanyState

Fields

Name Type Description
level integer Applied rank.
potentialLevel integer Rank reached by experience.
experience integer Experience points.