industry_util¶
Source: base/tealdef/gui/main/industry_util.d.tl
Notes
Helpers for the industry UI: production boosts (worker boost and booster rules), input and
output data per rule, production numbers, satellite slots, connection checks, removing
industries, and finding suppliers and consumers. Load it with
ug_require "/gui/main/industry_util.tl".
IndustryUtil¶
record global base/tealdef/gui/main/industry_util.d.tl:3
global record IndustryUtil
Load: local industry_util = ug_require "/gui/main/industry_util.tl"
Notes
Helpers that read industry stock lists and rules for the UI.
Functions
getPersonCapacityBoostProgress(entity : Engine.Entity) : number base/tealdef/gui/main/industry_util.d.tl:4
Call as industry_util.getPersonCapacityBoostProgress
Notes
Returns how close an industry is to the worker boost, from 0 to 1.
Returns number: Occupied workplaces divided by capacity, mapped from 0..RequiredWorkersFractionForBoost to 0..1; 0 without a PERSON_CAPACITY component.
Used in the base game: 2 times in 2 files
base/content/game_mechanics/game_mechanics/subventions/deliver_workers/deliver_workers.script.tl:258
value = not entity_util.entityChanged0(data.to) and industry_util.getPersonCapacityBoostProgress(data.to.entity) or 0.0,
mods/release/urbangames_campaign_mission_06/content/subventions/subventions/deliver_visitors/deliver_visitors.script.tl:270
isPersonCapacityBoosted(entity : Engine.Entity) : boolean base/tealdef/gui/main/industry_util.d.tl:5
Call as industry_util.isPersonCapacityBoosted
Notes
Tells whether an industry has enough workers for the worker boost (industry_productivity_util.isIndustryWorkersBoosted).
Returns boolean
Used in the base game: 5 times in 3 files
base/content/mission/mission/tasks/transport_cargo/industry_boosted.tl:32
base/content/game_mechanics/game_mechanics/subventions/deliver_workers/deliver_workers.script.tl:125
if not industry_util.isPersonCapacityBoosted(entity) and industry_util.isIndustryConnected(entity) then
mods/release/urbangames_campaign_mission_06/content/subventions/subventions/deliver_visitors/deliver_visitors.script.tl:126
getPersonCapacityBoost(entity : Engine.Entity) : number base/tealdef/gui/main/industry_util.d.tl:6
Call as industry_util.getPersonCapacityBoost
Notes
Returns the productivity factor of an industry from its workers (industry_productivity_util.getIndustryProductivity).
Returns number
isEntityBoosted(boosterIndex : integer, entity : Engine.Entity, excludePersons? : boolean) : boolean base/tealdef/gui/main/industry_util.d.tl:8
Call as industry_util.isEntityBoosted
Notes
Tells whether the n-th booster rule of an industry is active.
| Parameter | Type | Description |
|---|---|---|
boosterIndex |
integer |
1-based index among the booster rules of the stock list. |
entity |
Engine.Entity |
Entity with a STOCK_LIST component. |
excludePersons? |
boolean |
If true, returns false when there is no such booster rule; otherwise falls back to isPersonCapacityBoosted. |
Returns boolean
Used in the base game: 2 times in 2 files
base/content/mission/mission/tasks/transport_cargo/industry_boosted.tl:27
base/content/gui/gui/entity_window/industry/industry_eow.script.tl:558
getIndustryBoost(Engine.Entity, boolean, ?integer) : IndustryBoost base/tealdef/gui/main/industry_util.d.tl:18
Call as industry_util.getIndustryBoost
Notes
Computes the production boost of an industry from its booster rules and optionally its workers.
| Parameter | Type | Description |
|---|---|---|
#1 |
Engine.Entity |
Entity with a STOCK_LIST component. |
#2 |
boolean |
If true, starts from the worker productivity factor instead of 1. |
#3 |
?integer |
If set, only rules up to this index are checked. |
Returns IndustryBoost
getStockListInputOutputData(Engine.Entity, boolean, boolean, integer) : {StockListCargoData} base/tealdef/gui/main/industry_util.d.tl:29
Call as industry_util.getStockListInputOutputData
Notes
Lists the input or output cargo types of a stock list with the rules that use them.
| Parameter | Type | Description |
|---|---|---|
#1 |
Engine.Entity |
Entity with a STOCK_LIST component. |
#2 |
boolean |
true for inputs, false for outputs. |
#3 |
boolean |
true for booster rules only, false for normal rules only, nil for both. |
#4 |
integer |
Maximum number of cargo types to return; 0 for no limit. |
Returns {StockListCargoData}
getIndustryProductionData(entity : Engine.Entity, input : boolean, booster : boolean, index : integer, isIndustry : boolean) : ProductionData base/tealdef/gui/main/industry_util.d.tl:36
Call as industry_util.getIndustryProductionData
Notes
Returns current and maximum consumption or production per year for one input or output cargo type.
| Parameter | Type | Description |
|---|---|---|
entity |
Engine.Entity |
Entity with a STOCK_LIST component. |
input |
boolean |
true for an input, false for an output. |
booster |
boolean |
Rule selection as in getStockListInputOutputData. |
index |
integer |
1-based index of the cargo type in the result of getStockListInputOutputData. |
isIndustry |
boolean |
If true, applies api.res.getBaseConfig().locations.industry.industryProductivity. |
Returns ProductionData: The production data, or nil if there is no cargo type at index.
Used in the base game: 3 times in 3 files
base/content/gui/gui/statistics/statistic_industries.tl:197
local prodData = industry_util.getIndustryProductionData(entity, isInput, isBooster, inputOutputData.adjustedIndex, true)
base/content/gui/gui/entity_window/industry_react_util.tl:306
ret.productionData = industry_util.getIndustryProductionData(params.entity, params.isInput, false, ret.inputOutputData.adjustedIndex, params.isIndustry)
base/content/gui/gui/entity_window/industry/industry_eow.script.tl:65
getSatellitesNumAndMax(Engine.Entity) : SatellitesNumAndMax base/tealdef/gui/main/industry_util.d.tl:42
Call as industry_util.getSatellitesNumAndMax
Notes
Returns the filled and total auto-fill slots of the construction that contains the entity.
Returns SatellitesNumAndMax
createInputOutputData(RuleInputOutputCargoParams) : RuleInputOutputData base/tealdef/gui/main/industry_util.d.tl:60
Call as industry_util.createInputOutputData
Notes
Returns the content of one input or output slot of an industry rule for display.
Returns RuleInputOutputData
Details
For normal rules of constructions with satellite slots, input slot 1 is the satellite
count. For booster rules, output slot 1 is the boost percentage. The other slots are
shifted by one in these cases. Only the first input set of a rule is used.
Used in the base game: 4 times in 3 files
base/content/gui/gui/statistics/statistic_industries.tl:189
base/content/gui/gui/entity_window/industry_react_util.tl:304
base/content/gui/gui/entity_window/industry/industry_eow.script.tl:62
getNumCargosOfRule(Engine.Entity, integer, boolean) : integer base/tealdef/gui/main/industry_util.d.tl:62
Call as industry_util.getNumCargosOfRule
Notes
Returns the number of input or output slots of a rule, including the satellite input or boost output slot.
| Parameter | Type | Description |
|---|---|---|
#1 |
Engine.Entity |
Entity with a STOCK_LIST component. |
#2 |
integer |
1-based rule index. |
#3 |
boolean |
true to count inputs, false to count outputs. |
Returns integer: Slot count, at least 1.
Used in the base game: 4 times in 2 files
base/content/gui/gui/statistics/statistic_industries.tl:187
base/content/gui/gui/entity_window/industry_react_util.tl:216
getSortedOutputCargoTypes(entity : Engine.Entity) : {CargoTypeId} base/tealdef/gui/main/industry_util.d.tl:64
Call as industry_util.getSortedOutputCargoTypes
Notes
Returns the output cargo types of all rules of an industry, sorted by id.
| Parameter | Type | Description |
|---|---|---|
entity |
Engine.Entity |
Industry entity (with an INDUSTRY component). |
Returns {CargoTypeId}
Used in the base game: 4 times in 2 files
base/content/gui/gui/statistics/statistic_industries.tl:153
base/content/gui/gui/entity_window/town/town.tl:392
calcAnnualShipment(entity : Engine.Entity) : integer base/tealdef/gui/main/industry_util.d.tl:66
Call as industry_util.calcAnnualShipment
Notes
Returns the cargo shipped per year from an industry's stock list.
| Parameter | Type | Description |
|---|---|---|
entity |
Engine.Entity |
Industry entity. |
Returns integer: Items per year, or nil if the industry has no rules.
Used in the base game: 9 times in 5 files
base/content/mission/mission/tutorial/tutorial_story_branch_b.tl:526
base/content/mission/mission/tutorial/tutorial_story_branch_a.tl:428
base/content/gui/gui/statistics/statistic_industries.tl:330
mods/release/urbangames_campaign_mission_01/content/mission/mission/mission_story.tl:1126
mods/release/urbangames_campaign_mission_04/content/mission/mission/mission_story.tl:251
isIndustryConnected(entity : Engine.Entity) : boolean base/tealdef/gui/main/industry_util.d.tl:68
Call as industry_util.isIndustryConnected
Notes
Tells whether an industry ships cargo, based on api.engine.util.stock.getCargoShippedPerYear of its stock list.
| Parameter | Type | Description |
|---|---|---|
entity |
Engine.Entity |
Industry entity. |
Returns boolean
Details
Delivered cargo (getCargoDeliveredPerYear) is only checked for rules whose output is
nil.
removeIndustries(industriesToRemove : {Engine.Entity}, followupFn : function(success : boolean), doDust : boolean) base/tealdef/gui/main/industry_util.d.tl:70
Call as industry_util.removeIndustries
Notes
Removes industries by sending build proposals that remove their constructions, then removes the street segments that belong to them.
| Parameter | Type | Description |
|---|---|---|
industriesToRemove |
{Engine.Entity} |
Industry entities. |
followupFn |
function(success : boolean) |
Called with the success of the last command, or with true at once if there is nothing to remove. |
doDust |
boolean |
Passed to api.cmd.makeWorldBuildProposalCmd (show demolition dust). |
Used in the base game: 2 times in 2 files
base/content/gui/gui/map_editor/map_editor.tl:787
base/content/game_mechanics/game_mechanics/industries/industries.script.tl:189
forEachMatchingStocklist(stockList : Engine.Component.StockList, stockListType : StockListType, callback : function(Engine.Entity, CargoTypeId)) : {CargoTypeId : boolean} base/tealdef/gui/main/industry_util.d.tl:73
Call as industry_util.forEachMatchingStocklist
return input/output cargo types (depending on argument stockListType)
Notes
Calls callback for every industry that has a stock of the counterpart type for one of the given stock list's cargo types.
| Parameter | Type | Description |
|---|---|---|
stockList |
Engine.Component.StockList |
Stock list component of the industry to look at. |
stockListType |
StockListType |
InputStock finds suppliers (industries with a matching output stock); OutputStock finds consumers (industries with a matching input stock). |
callback |
function(Engine.Entity, CargoTypeId) |
Called with the found industry entity and the cargo type. |
Returns {CargoTypeId : boolean}: Set of the input or output cargo types of stockList.
Used in the base game: 5 times in 3 files
base/content/gui/gui/entity_window/industry/industry_eow.script.tl:297
base/content/gui/gui/entity_window/industry/industry.tl:228
base/content/game_mechanics/game_mechanics/subventions/deliver_cargo/deliver_cargo.script.tl:406
getFailedExpansionTriangles(proposal : Proposal, collidingSubconstructions : {integer}) : {{Vec2f, Vec2f, Vec2f}} base/tealdef/gui/main/industry_util.d.tl:77
Call as industry_util.getFailedExpansionTriangles
Notes
Returns ground triangles (x/y) of the colliding subconstructions of a construction proposal, for drawing where an expansion failed.
| Parameter | Type | Description |
|---|---|---|
proposal |
Proposal |
Proposal whose first added construction is checked. |
collidingSubconstructions |
{integer} |
0-based indices of the colliding subconstructions. |
Returns {{Vec2f, Vec2f, Vec2f}}
Details
Uses quad point-cloud and box colliders of the subconstruction; if none are found, the lot triangles of the subconstruction.
forEachTownSupplier(townEntity : Engine.Entity, callback : function(Engine.Entity, CargoTypeId)) base/tealdef/gui/main/industry_util.d.tl:79
Call as industry_util.forEachTownSupplier
Notes
Calls callback for every industry output stock whose cargo type the town has a supply limit for.
| Parameter | Type | Description |
|---|---|---|
townEntity |
Engine.Entity |
Town entity. |
callback |
function(Engine.Entity, CargoTypeId) |
Called with the industry entity and the cargo type. |
Used in the base game: 3 times in 2 files
base/content/gui/gui/entity_window/town/town.tl:338
industry_util.forEachTownSupplier(param.entity, function(industryEntity : Engine.Entity, cargoType : CargoTypeId)
base/content/game_mechanics/game_mechanics/subventions/deliver_cargo_town/deliver_cargo_town.script.tl:499
IndustryUtil.IndustryBoost¶
record base/tealdef/gui/main/industry_util.d.tl:10
record IndustryBoost
Notes
Production boost of an industry, as returned by getIndustryBoost.
Used in the base game: 2 times in 1 file
base/content/gui/gui/main/industry_util.tl:42
Fields
| Name | Type | Description |
|---|---|---|
boost |
number |
Total production factor (worker boost if requested, multiplied by 1 + boostFactor of every active booster rule). |
ruleBoosts |
{integer : RuleBoost} |
Booster rule states by rule index (1-based). Non-booster rules have no entry. |
IndustryUtil.IndustryBoost.RuleBoost¶
record base/tealdef/gui/main/industry_util.d.tl:11
record RuleBoost
Notes
State of one booster rule.
Used in the base game: 2 times in 1 file
base/content/gui/gui/main/industry_util.tl:49
Fields
IndustryUtil.StockListCargoData¶
record base/tealdef/gui/main/industry_util.d.tl:20
record StockListCargoData
Notes
One input or output cargo type of a stock list with the rules that use it, as returned by getStockListInputOutputData.
Used in the base game: 2 times in 1 file
base/content/gui/gui/main/industry_util.tl:170
Fields
| Name | Type | Description |
|---|---|---|
cargoType |
CargoTypeId |
Cargo type id. |
rulesData |
{RuleInputOutputIndex} |
Rules that use the cargo type. |
IndustryUtil.StockListCargoData.RuleInputOutputIndex¶
record base/tealdef/gui/main/industry_util.d.tl:21
record RuleInputOutputIndex
Notes
Reference to a rule that uses the cargo type.
Fields
IndustryUtil.ProductionData¶
record base/tealdef/gui/main/industry_util.d.tl:31
record ProductionData
Notes
Production or consumption of one cargo type, as returned by getIndustryProductionData.
Used in the base game: 4 times in 3 files
base/content/gui/gui/main/industry_util.tl:310
industry_util.getIndustryProductionData = function(entity : Engine.Entity, input : boolean, booster : boolean, index : integer, isIndustry : boolean) : Industry
base/content/gui/gui/entity_window/industry_react_util.tl:298
base/content/gui/gui/entity_window/industry/industry_eow.script.tl:59
Fields
| Name | Type | Description |
|---|---|---|
cargoTypeId |
CargoTypeId |
Cargo type id. |
actual |
number |
Current consumption or production frequency per year. nil when the output is split between rules that produce without inputs. |
total |
number |
Maximum consumption or production per year, including boosts and the base config's industry productivity. |
IndustryUtil.SatellitesNumAndMax¶
record base/tealdef/gui/main/industry_util.d.tl:38
record SatellitesNumAndMax
Notes
Filled and total auto-fill slots (satellites) of an industry's construction.
Used in the base game: 1 time in 1 file
base/content/gui/gui/main/industry_util.tl:381
Fields
| Name | Type | Description |
|---|---|---|
numSatellites |
integer |
Number of filled slots. |
maxSatellites |
integer |
Total number of slots. |
IndustryUtil.RuleInputOutputCargoParams¶
record base/tealdef/gui/main/industry_util.d.tl:44
record RuleInputOutputCargoParams
Notes
Parameters of createInputOutputData.
Used in the base game: 4 times in 3 files
base/content/gui/gui/main/industry_util.tl:410
industry_util.createInputOutputData = function(params : IndustryUtil.RuleInputOutputCargoParams) : IndustryUtil.RuleInputOutputData
base/content/gui/gui/entity_window/industry_react_util.tl:295
local ProductionRuleInputOutputWidget = react.RegisterRecipe("ProductionRuleInputOutputWidget", function(params : IndustryUtil.RuleInputOutputCargoParams) : Tre
base/content/gui/gui/entity_window/industry/industry_eow.script.tl:56
Fields
| Name | Type | Description |
|---|---|---|
entity |
Engine.Entity |
Entity with a STOCK_LIST component. |
ruleNumber |
integer |
1-based index of the rule. |
isInput |
boolean |
true for an input slot of the rule, false for an output slot. |
index |
integer |
1-based slot index, counted as in getNumCargosOfRule. |
isIndustry |
boolean |
|
onlyOneProductionLine |
boolean |
IndustryUtil.RuleInputOutputData¶
record base/tealdef/gui/main/industry_util.d.tl:52
record RuleInputOutputData
Notes
Content of one input or output slot of a rule, as returned by createInputOutputData.
Used in the base game: 3 times in 3 files
base/content/gui/gui/main/industry_util.tl:410
industry_util.createInputOutputData = function(params : IndustryUtil.RuleInputOutputCargoParams) : IndustryUtil.RuleInputOutputData
base/content/gui/gui/entity_window/industry_react_util.tl:297
base/content/gui/gui/entity_window/industry/industry_eow.script.tl:58
Fields
| Name | Type | Description |
|---|---|---|
plotsInput |
boolean |
true if the slot is the satellite (plot) input; then count is the number of filled satellites. |
cargoType |
CargoTypeId |
Cargo type id of the slot. |
count |
integer |
Amount of the cargo type per rule run, or the number of filled satellites for the plot input. |
boostFractionOutputText |
string |
Set for the first output slot of a booster rule, the boost as text, e.g. "+20%". |
adjustedIndex |
integer |
Slot index after skipping the plot input or boost slot. |
fraction |
number |
Progress (0..1) of the current rule run for inputs; nil if the rule is not running. |