Skip to content

cargo_util

Source: base/tealdef/gui/main/cargo_util.d.tl

Notes

Functions that collect cargo data for the UI: stock contents of industries, warehouses and town buildings, cargo loaded in vehicles and on lines, cargo type icons, names and colours, and cargo flow counts. All functions read engine state and do not change it. Load it with ug_require "/gui/main/cargo_util.tl".

CargoUtil

record global base/tealdef/gui/main/cargo_util.d.tl:3

global record CargoUtil

Load: local cargo_util = ug_require "/gui/main/cargo_util.tl"

Notes

Read-only helpers for cargo types, stocks and vehicle cargo in the UI.

Details

Cargo type ids (CargoTypeId) are 0-based. Engine arrays indexed by cargo type, such as TransportVehicle.config.capacities, are 1-based Lua arrays, so entry i belongs to cargo type i - 1.

Functions

getCargoTypesCount(producedOnly : boolean) : integer base/tealdef/gui/main/cargo_util.d.tl:4

Call as cargo_util.getCargoTypesCount

producedOnly: only current types in game if true, all available from rep if false

Returns integer

Used in the base game: 2 times in 2 files

base/content/game_mechanics/game_mechanics/finance/finances_cargo_lifetime.tl:265

local maxNumCargoTypes = cargo_util.getCargoTypesCount(false)
base/content/game_mechanics/game_mechanics/finance/account.tl:35
return cargo_util.getCargoTypesCount(true)

getMaxCaroTypeId() : integer base/tealdef/gui/main/cargo_util.d.tl:5

Call as cargo_util.getMaxCaroTypeId

Notes

Returns the highest cargo type id in api.res.cargoTypeRep.getAll(true).

Returns integer

Details

The name is spelled Caro in the game files.

Used in the base game: 3 times in 2 files

base/content/gui/gui/entity_window/town/town.tl:325

return cargo_util.getMaxCaroTypeId() + 1
base/content/gui/gui/entity_window/industry/industry_eow.script.tl:282
return cargo_util.getMaxCaroTypeId() + 1

getPassengerCargoTypeId() : CargoTypeId base/tealdef/gui/main/cargo_util.d.tl:6

Call as cargo_util.getPassengerCargoTypeId

Notes

Returns the cargo type id of passengers (api.res.cargoTypeRep.getPassengerCargoTypeId()).

Returns CargoTypeId

Used in the base game: 42 times in 24 files

base/content/mission/mission/tasks/town_rating/town_rating.tl:58

local passengerCargoTypeId : CargoTypeId = cargo_util.getPassengerCargoTypeId()
base/content/gui/gui/layers/layer_passenger_flow.tl:77
local cargoTypes : {CargoTypeId} = { cargo_util.getPassengerCargoTypeId() }
base/content/gui/gui/layers/layer_cargo_flow.tl:203
if id ~= cargo_util.getPassengerCargoTypeId() or includePassengers then
base/content/gui/gui/layers/layer_public_transport.tl:55
cargoType = cargo_util.getPassengerCargoTypeId(),
base/content/gui/gui/layers/layer_cargo.tl:77
local passengerCargoTypeId: CargoTypeId = cargo_util.getPassengerCargoTypeId()
base/content/gui/gui/debug_panel/make_entity_debug_panel.tl:454
local passengerCargoTypeId : CargoTypeId = cargo_util.getPassengerCargoTypeId()
… and 18 more files.

calculateStockConfigs(entity : Engine.Entity, max? : integer, calculateQuality? : boolean, sortByType? : boolean, showEmpty? : boolean, groupStocks? : boolean, producedOnly? : boolean) : {CargoUtil.StockConfig}, integer, boolean base/tealdef/gui/main/cargo_util.d.tl:21

Call as cargo_util.calculateStockConfigs

Notes

Groups the stocks of a stock list entity and computes stored amount, capacity, tendency and optionally quality per group.

Parameter Type Description
entity Engine.Entity Stock list entity (e.g. Industry.stockList or Warehouse.stockList).
max? integer Maximum number of cargo icons the caller wants to show per row; adjusted and returned as the second result.
calculateQuality? boolean If true, fills quality and numSpoiled.
sortByType? boolean If true, sorts the groups by stock type, then by cargo types.
showEmpty? boolean If false, leaves out empty stocks (default true).
groupStocks? boolean If false, makes one entry per stock instead of grouping stocks by type and cargo types (default true).
producedOnly? boolean If true, only lists cargo types that are produced in the current game.

Returns {CargoUtil.StockConfig}, integer, boolean: 1. List of StockConfig. 2. The adjusted maximum icon count. 3. true if at least one group is not an output stock.

Details

Returns an empty list if the entity does not exist.

Used in the base game: 7 times in 5 files

base/content/mission/mission/tasks/transport_cargo/empty_stocks.tl:75

local stockConfigs, __, __ = cargo_util.calculateStockConfigs(stockListEntity, maxIconsInput, calculateQuality, sortByType)
base/content/gui/gui/main/hud_icon_toolbox.tl:207
stockConfigs, dummyA, dummyB = cargo_util.calculateStockConfigs(params.entity, nil, true, true, true)
base/content/gui/gui/main/cargo_react_util.tl:624
local stockCargos = cargo_util.calculateStockConfigs(entity, 10, true, true, nil, true, true)
base/content/gui/gui/statistics/statistic_warehouses.tl:54
stockConfigs, dummyA, dummyB = cargo_util.calculateStockConfigs(entity)
base/content/gui/gui/entity_window/entity_window_util.tl:508
configs, maxIcons, invert = cargo_util.calculateStockConfigs(

sortConfigsByStockType({CargoUtil.StockConfig}, boolean) : {CargoUtil.StockConfig} base/tealdef/gui/main/cargo_util.d.tl:23

Call as cargo_util.sortConfigsByStockType

input-, output-, storage stock

Returns {CargoUtil.StockConfig}

Used in the base game: 2 times in 1 file

base/content/gui/gui/entity_window/entity_window_util.tl:741

stockConfigs = cargo_util.sortConfigsByStockType(stockConfigs, false)

calculateStockCargoCount(Engine.Entity, ?boolean, ?{StockId}, ?boolean) : {StockCargoCount} base/tealdef/gui/main/cargo_util.d.tl:37

Call as cargo_util.calculateStockCargoCount

entity: id of entity holding the according stock, eg. industry, warehouse... sortByCargoType: [optional] if true, we sort by cargo type otherwise by cargo count, default is false stock ids: [optional] must be stocks of given industry/warehouse entity, if given count is calculated only for those, otherwise for all stocks of given industry/warehouse calculateQuality : [optional] if true, quality is calculated

Returns {StockCargoCount}

Used in the base game: 3 times in 3 files

base/content/gui/gui/main/hud_icon_toolbox.tl:62

local stockCargoCount = cargo_util.calculateStockCargoCount(param.entity, false, stockConfig.ids)
base/content/gui/gui/statistics/statistic_warehouses.tl:379
local stockCargos : {CargoUtil.StockCargoCount} = cargo_util.calculateStockCargoCount(key, false)
base/content/gui/gui/entity_window/entity_window_util.tl:1760
local stockCargoCount = cargo_util.calculateStockCargoCount(entity, false, stockConfig.ids)

calculateSortedVehicleCargoInfo(Engine.Entity, calculateQuality? : boolean) : {VehicleCargo} base/tealdef/gui/main/cargo_util.d.tl:47

Call as cargo_util.calculateSortedVehicleCargoInfo

Notes

Lists the cargo capacities of a vehicle, sorted by capacity (highest first), then by cargo type.

Parameter Type Description
#1 Engine.Entity Vehicle entity with a TRANSPORT_VEHICLE component.
calculateQuality? boolean If true, fills hasGoodCargo and hasBadCargo.

Returns {VehicleCargo}

Used in the base game: 1 time in 1 file

base/content/gui/gui/statistics/statistic_vehicles.tl:453

local cargoInfo : {CargoUtil.VehicleCargo} = cargo_util.calculateSortedVehicleCargoInfo(key)

calculateSortedVehicleCargoInfoCompareValue(Engine.Entity) : {{CargoTypeId, integer, integer}} base/tealdef/gui/main/cargo_util.d.tl:50

Call as cargo_util.calculateSortedVehicleCargoInfoCompareValue

get value usable to for sorting (so that cargoType is most significant)

Returns {{CargoTypeId, integer, integer}}

Used in the base game: 1 time in 1 file

base/content/gui/gui/statistics/statistic_vehicles.tl:363

{ name = _("Cargo"), recipe = VehicleCargoTypesCell, getCompareValue = cargo_util.calculateSortedVehicleCargoInfoCompareValue, weight = 2.4, },

calculateSortedLineCargoInfo(lineEntity : Engine.Entity, calculateQuality? : boolean) : {CargoUtil.VehicleCargo} base/tealdef/gui/main/cargo_util.d.tl:52

Call as cargo_util.calculateSortedLineCargoInfo

Notes

Like calculateSortedVehicleCargoInfo, summed over all vehicles of a line.

Parameter Type Description
lineEntity Engine.Entity Line entity.
calculateQuality? boolean If true, fills hasGoodCargo and hasBadCargo.

Returns {CargoUtil.VehicleCargo}

Used in the base game: 2 times in 2 files

base/content/gui/gui/line_vehicle_mgmt/manager_window.tl:2556

local cargoInfo : {CargoUtil.VehicleCargo} = cargo_util.calculateSortedLineCargoInfo(key)
base/content/gui/gui/statistics/statistic_lines.tl:333
local cargoInfo : {CargoUtil.VehicleCargo} = cargo_util.calculateSortedLineCargoInfo(key)

calculateSortedLineCargoInfoCompareValue(lineEntity : Engine.Entity) : {{CargoTypeId, integer, integer}} base/tealdef/gui/main/cargo_util.d.tl:53

Call as cargo_util.calculateSortedLineCargoInfoCompareValue

Notes

Returns {cargoType, fill, capacity} for each cargo type of a line's vehicles, in the same order as calculateSortedLineCargoInfo. Used as a sort key.

Returns {{CargoTypeId, integer, integer}}

Used in the base game: 1 time in 1 file

base/content/gui/gui/statistics/statistic_lines.tl:407

{ name = _("Cargo"), recipe = LineCargoTypesCell, getCompareValue = cargo_util.calculateSortedLineCargoInfoCompareValue, weight = 2 },

hasLineVehicleWithCapacity(lineEntity : Engine.Entity, cargoTypeId : CargoTypeId) : boolean base/tealdef/gui/main/cargo_util.d.tl:54

Call as cargo_util.hasLineVehicleWithCapacity

Notes

Tells whether any vehicle of a line can carry the cargo type, based on TransportVehicle.config.allCaps.

Returns boolean

Used in the base game: 1 time in 1 file

base/content/game_mechanics/game_mechanics/subventions/deliver_passengers/deliver_passengers.script.tl:75

if cargo_util.hasLineVehicleWithCapacity(lineEntity, passengerCargoTypeId) then

calculateVehicleCargoFill({Engine.Entity}, integer) : integer base/tealdef/gui/main/cargo_util.d.tl:56

Call as cargo_util.calculateVehicleCargoFill

Notes

Returns the number of loaded items of one cargo type summed over the given vehicles.

Parameter Type Description
#1 {Engine.Entity} Vehicle entities.
#2 integer Cargo type id.

Returns integer

getSortedProducedCargoTypes(locationParams : CargoLocationParams, sortOrder : CargoListSortOrder, passengersFirst? : boolean, cargoTypeFilter? : (function(CargoTypeId) : boolean), allLineCapacities? : boolean) : {CargoTypeId} base/tealdef/gui/main/cargo_util.d.tl:104

Call as cargo_util.getSortedProducedCargoTypes

Notes

Lists the cargo types present at a location, limited to cargo types produced in the current game, sorted by the given order.

Parameter Type Description
locationParams CargoLocationParams Locations to count.
sortOrder CargoListSortOrder Sort order.
passengersFirst? boolean If true, moves passengers to the front.
cargoTypeFilter? (function(CargoTypeId) : boolean) Function that returns true for cargo types to keep.
allLineCapacities? boolean Passed to api.engine.util.line.getLineCapacityUsages for line locations.

Returns {CargoTypeId}

Details

In the game's implementation cargoTypeFilter only takes effect in the shortcut case (only vehicleEntity set, showEmpty off, sort order CAPACITY); in all other cases the list is returned unfiltered.

Used in the base game: 7 times in 6 files

base/content/gui/gui/line_vehicle_mgmt/line_react_util.tl:689

sortedCargoTypes = cargo_util.getSortedProducedCargoTypes(locationParams, "CAPACITY", nil, nil, true)
base/content/gui/gui/main/cargo_react_util.tl:401
local cargoTypes = cargo_util.getSortedProducedCargoTypes(overriddenParams, params.sortOrder, true, params.cargoTypeFilter)
base/content/gui/gui/statistics/statistic_lines.tl:67
return cargo_util.getSortedProducedCargoTypes(locationParams, "CAPACITY", nil, nil, true)
base/content/gui/gui/statistics/statistics_react_util.tl:236
local cargoTypes = cargo_util.getSortedProducedCargoTypes(locationParams, "CAPACITY")
base/content/gui/gui/statistics/statistic_vehicles.tl:78
return cargo_util.getSortedProducedCargoTypes(locationParams, "CAPACITY")
base/content/gui/gui/entity_window/entity_window_util.tl:2205
local cargoTypes =  cargo_util.getSortedProducedCargoTypes(locationParams, sortOrder, true, nil)

getConfiguredStopCargoTypes(stopParams : CargoStopParams, passengersFirst? : boolean) : {CargoTypeId} base/tealdef/gui/main/cargo_util.d.tl:111

Call as cargo_util.getConfiguredStopCargoTypes

Notes

Lists the cargo types set to load at a line stop (stopConfig.load).

Parameter Type Description
stopParams CargoStopParams Line and stop.
passengersFirst? boolean If true, moves passengers to the front.

Returns {CargoTypeId}: Cargo type ids, or an empty list if the stop does not exist.

Used in the base game: 1 time in 1 file

base/content/gui/gui/line_vehicle_mgmt/line_react_util.tl:681

sortedCargoTypes = cargo_util.getConfiguredStopCargoTypes(stopParams, true)

getNumberOfCargoInStock(stockListOwnerEntity : Engine.Entity) : integer base/tealdef/gui/main/cargo_util.d.tl:115

Call as cargo_util.getNumberOfCargoInStock

Notes

Returns the total number of cargo items in the stock list of an industry, warehouse or town building.

Returns integer: Item count, 0 if the entity has no stock list.

Used in the base game: 1 time in 1 file

base/content/gui/gui/statistics/statistics.tl:79

local storedCargoCount = cargo_util.getNumberOfCargoInStock(params.entity)

getCargoTypeInfo(CargoTypeId, CargoLocationParams) : CargoTypeInfo base/tealdef/gui/main/cargo_util.d.tl:116

Call as cargo_util.getCargoTypeInfo

Notes

Collects amount, capacity, quality and, for vehicles, loading state of one cargo type at the given locations.

Parameter Type Description
#1 CargoTypeId Cargo type id.
#2 CargoLocationParams Locations to count; the values of all set locations are added up.

Returns CargoTypeInfo

Used in the base game: 4 times in 3 files

base/content/gui/gui/main/cargo_react_util.tl:405

local info = cargo_util.getCargoTypeInfo(cargoType, overriddenParams)
base/content/gui/gui/statistics/statistics_react_util.tl:239
cargoTypeInfos[#cargoTypeInfos + 1] = cargo_util.getCargoTypeInfo(cargoTypeId, locationParams)
base/content/gui/gui/entity_window/entity_window_util.tl:2212
local info : CargoUtil.CargoTypeInfo = cargo_util.getCargoTypeInfo(cargoType, locationParams)

getSpecializationClasses(stockListEntity : Engine.Entity) : {string} base/tealdef/gui/main/cargo_util.d.tl:117

Call as cargo_util.getSpecializationClasses

Notes

Returns the cargo class names a stock list is specialized for.

Returns {string}

Details

Collects the included cargo classes of storage stocks that only filter by included cargo classes (no excluded classes, no included cargo types).

getCargoClassesOfType(CargoTypeId) : {CargoClassId} base/tealdef/gui/main/cargo_util.d.tl:119

Call as cargo_util.getCargoClassesOfType

Notes

Returns the ids of the cargo classes of a cargo type. Unknown class tags are skipped.

Returns {CargoClassId}

Used in the base game: 1 time in 1 file

base/content/gui/gui/main/cargo_react_util.tl:38

local cargoClassIds = cargo_util.getCargoClassesOfType(cargoTypeId)

getWarehouseCountIndicatorTexture(integer) : string base/tealdef/gui/main/cargo_util.d.tl:121

Call as cargo_util.getWarehouseCountIndicatorTexture

Notes

Returns the arrow icon for a stock tendency value.

Parameter Type Description
#1 integer Tendency from -3 to 3; values beyond are clamped.

Returns string: Image path, e.g. ::/gui/entity_window/icons/stock_increasing2.tga; stock_stagnating.tga for 0.

Used in the base game: 1 time in 1 file

base/content/gui/gui/main/cargo_react_util.tl:197

local indicatorIconPath = params.tendency ~= nil and cargo_util.getWarehouseCountIndicatorTexture(params.tendency) or nil

getCargoColorById(CargoTypeId) : Vec4f base/tealdef/gui/main/cargo_util.d.tl:122

Call as cargo_util.getCargoColorById

Notes

Returns the colour of a cargo type with alpha 1.

Returns Vec4f

Used in the base game: 1 time in 1 file

base/content/game_mechanics/game_mechanics/finance/finances_assets.tl:338

local col = cargo_util.getCargoColorById(cargoTypeId)

getCargoColorByType(string) : Vec4f base/tealdef/gui/main/cargo_util.d.tl:123

Call as cargo_util.getCargoColorByType

Notes

Returns the colour of a cargo type given by its name in the cargo type repository.

Returns Vec4f

Details

Returns the darkest neutral colour of default_colors.gres for nil.

getCargoIconById(CargoTypeId) : string base/tealdef/gui/main/cargo_util.d.tl:124

Call as cargo_util.getCargoIconById

Notes

Returns the icon path of a cargo type.

Returns string

Used in the base game: 20 times in 15 files

base/content/gui/gui/line_vehicle_mgmt/vehicle_store_window.tl:160

local iconPath = cargo_util.getCargoIconById(id)
base/content/gui/gui/line_vehicle_mgmt/manager_hud_util.tl:239
--  path = cargo_util.getCargoIconById(cargoTypeId),
base/content/gui/gui/construction/construction_desc_react_util.tl:431
icon = cargo_util.getCargoIconById(cargoAndAmount.cargoType),
base/content/gui/gui/construction/construction.tl:3150
local iconPath = cargo_util.getCargoIconById(id.cargoType)
base/content/gui/gui/construction/construction_react_util.tl:1609
icon = exploration.icon or cargo_util.getCargoIconById(cargoTypeId),
base/content/gui/gui/main/hud_icon_toolbox.tl:66
iconPath = cargo_util.getCargoIconById(cargoCount.cargoType),
… and 9 more files.

getCargoIconByType(string) : string base/tealdef/gui/main/cargo_util.d.tl:125

Call as cargo_util.getCargoIconByType

Notes

Returns the icon path of a cargo type given by its name in the cargo type repository; "" for nil.

Returns string

getCargoClassIconById(CargoClassId) : string base/tealdef/gui/main/cargo_util.d.tl:126

Call as cargo_util.getCargoClassIconById

Notes

Returns the icon path of a cargo class.

Returns string

Used in the base game: 1 time in 1 file

base/content/gui/gui/main/cargo_react_util.tl:41

children[#children + 1] = cargo_react_util.makeIcon(class and class or "", cargo_util.getCargoClassIconById(cargoClassId), cargoClass.name)

getMixedCargoIcon() : string base/tealdef/gui/main/cargo_util.d.tl:127

Call as cargo_util.getMixedCargoIcon

Notes

Returns the icon for mixed or any cargo (::/cargos/icons/cargo_mixed.tga).

Returns string

Used in the base game: 6 times in 5 files

base/content/gui/gui/line_vehicle_mgmt/vehicle_store_util.tl:1145

path = cargo_util.getMixedCargoIcon(),
base/content/gui/gui/construction/construction.tl:3359
path = cargo_util.getMixedCargoIcon(),
base/content/gui/gui/main/cargo_react_util.tl:507
path = cargo_util.getMixedCargoIcon(),
base/content/gui/gui/statistics/statistic_warehouses.tl:96
path = cargo_util.getMixedCargoIcon()}
base/content/gui/gui/entity_window/entity_window_util.tl:314
path = cargo_util.getMixedCargoIcon(),

getPassengerCargoIcon() : string base/tealdef/gui/main/cargo_util.d.tl:128

Call as cargo_util.getPassengerCargoIcon

Notes

Returns the passenger icon (::/cargos/passengers/passengers.tga).

Returns string

Used in the base game: 3 times in 3 files

base/content/gui/gui/construction/construction.tl:3356

path = cargo_util.getPassengerCargoIcon(),
base/content/gui/gui/main/hud_icon_toolbox.tl:130
iconPath = cargo_util.getPassengerCargoIcon(),
base/content/gui/gui/entity_window/station_group/station_group.tl:135
path = cargo_util.getPassengerCargoIcon(),

getCargoNameById(CargoTypeId) : string base/tealdef/gui/main/cargo_util.d.tl:129

Call as cargo_util.getCargoNameById

Notes

Returns the display name of a cargo type.

Returns string

Used in the base game: 17 times in 13 files

base/content/gui/gui/debug_panel/make_entity_debug_panel.tl:448

local cargoName = cargo_util.getCargoNameById(cargoTypeId)
base/content/gui/gui/line_vehicle_mgmt/vehicle_store_window.tl:165
tooltip = cargo_util.getCargoNameById(id),
base/content/gui/gui/line_vehicle_mgmt/manager_window.tl:2558
local cargoName = cargo_util.getCargoNameById(info.cargoType)
base/content/gui/gui/statistics/statistic_warehouses.tl:386
local cargoName = cargo_util.getCargoNameById(cargo.cargoType)
base/content/gui/gui/statistics/statistic_lines.tl:335
local cargoName = cargo_util.getCargoNameById(info.cargoType)
base/content/gui/gui/statistics/statistic_industries.tl:461
local cargoName = cargo_util.getCargoNameById(cargoId)
… and 7 more files.

getCargoNameByType(string) : string base/tealdef/gui/main/cargo_util.d.tl:130

Call as cargo_util.getCargoNameByType

Notes

Returns the display name of a cargo type given by its name in the cargo type repository; "" for nil.

Returns string

getStockListEntityFromOwner(stockListOwnerEntity : Engine.Entity) : Engine.Entity base/tealdef/gui/main/cargo_util.d.tl:132

Call as cargo_util.getStockListEntityFromOwner

Notes

Returns the stock list entity of a town building, industry or warehouse.

Returns Engine.Entity: The stockList of the owner's TOWN_BUILDING, INDUSTRY or WAREHOUSE component, or nil.

Used in the base game: 1 time in 1 file

base/content/gui/gui/main/cargo_react_util.tl:365

local stockListEntity = cargo_util.getStockListEntityFromOwner(params.stockListOwnerEntity)

getInputOutputStocksForStation(stationEntity : Engine.Entity, skipStorage? : boolean) : {CargoTypeId : boolean}, integer, {CargoTypeId : boolean}, integer base/tealdef/gui/main/cargo_util.d.tl:134

Call as cargo_util.getInputOutputStocksForStation

Notes

Collects the input and output cargo types of all stock lists in a station's catchment area.

Parameter Type Description
stationEntity Engine.Entity Station entity.
skipStorage? boolean See getInputOutputStocksForStockList.

Returns {CargoTypeId : boolean}, integer, {CargoTypeId : boolean}, integer: 1. Set of input cargo types. 2. Number of input entries (one per stock and cargo type, summed over all stock lists). 3. Set of output cargo types. 4. Number of output entries.

Used in the base game: 5 times in 2 files

base/content/gui/gui/line_vehicle_mgmt/cargofilter_window.tl:346

local inputCargoTypes, inputCount, outputCargoTypes, _outputCount = cargo_util.getInputOutputStocksForStation(stationGroup.stations[stop.station + 1])
base/content/gui/gui/line_vehicle_mgmt/line_util.tl:553
local inputCargoTypes, __, outputCargoTypes, __ = cargo_util.getInputOutputStocksForStation(station, true)

getInputOutputStocksForStockList(stationEntity : Engine.Entity, skipStorage? : boolean) : {CargoTypeId : boolean}, integer, {CargoTypeId : boolean}, integer base/tealdef/gui/main/cargo_util.d.tl:136

Call as cargo_util.getInputOutputStocksForStockList

Notes

Collects the input and output cargo types of one stock list.

Parameter Type Description
stationEntity Engine.Entity Stock list entity (the parameter name is misleading).
skipStorage? boolean If true, only input and output stocks count. Otherwise storage stocks count as both input and output.

Returns {CargoTypeId : boolean}, integer, {CargoTypeId : boolean}, integer: 1. Set of input cargo types. 2. Number of input entries (one per stock and cargo type). 3. Set of output cargo types. 4. Number of output entries.

getCargoTypesForStockList(stationEntity : Engine.Entity) : {CargoTypeId : CargoUtil.StockProperties} base/tealdef/gui/main/cargo_util.d.tl:144

Call as cargo_util.getCargoTypesForStockList

Notes

Returns input, output and booster properties per cargo type of a stock list.

Parameter Type Description
stationEntity Engine.Entity Stock list entity (the parameter name is misleading).

Returns {CargoTypeId : CargoUtil.StockProperties}

Used in the base game: 5 times in 5 files

base/content/gui/gui/entity_window/entity_window_hud.tl:43

local industryCargoItems = cargo_util.getCargoTypesForStockList(industry.stockList)
base/content/gui/gui/entity_window/town_building/town_building.tl:264
cargoTypes = cargo_util.getCargoTypesForStockList(entityId)
base/content/gui/gui/entity_window/perk/perk.tl:83
result.cargoTypes = cargo_util.getCargoTypesForStockList(subconEntity)
base/content/gui/gui/entity_window/industry/industry.tl:254
cargoTypes =  cargo_util.getCargoTypesForStockList(entityId),
base/content/game_mechanics/game_mechanics/emission/pollution_cleanup_facility_hud.script.tl:60
result.cargoTypes = cargo_util.getCargoTypesForStockList(subCon)

getVehicleUnsetCapacities(vehicleEntity : Engine.Entity) : CargoUtil.VehicleUnsetCapacities base/tealdef/gui/main/cargo_util.d.tl:146

Call as cargo_util.getVehicleUnsetCapacities

Notes

Returns the capacities of a vehicle whose cargo type is not decided yet, split into single-type and multi-type capacities.

Returns CargoUtil.VehicleUnsetCapacities

Details

Only cargo types produced in the current game are considered. LocationCargoList uses this to show empty vehicles in entity windows.

Used in the base game: 3 times in 3 files

base/content/gui/gui/main/cargo_react_util.tl:395

local unsetCapacities = cargo_util.getVehicleUnsetCapacities(params.locationParams.vehicleEntity)
base/content/gui/gui/statistics/statistics_react_util.tl:228
local unsetCapacities = cargo_util.getVehicleUnsetCapacities(vehicleEntity)
base/content/gui/gui/statistics/statistic_vehicles.tl:70
local unsetCapacities = cargo_util.getVehicleUnsetCapacities(entity)

getCargoFlowCount(entityFrom : Engine.Entity, entityTo : Engine.Entity, cargoType : CargoTypeId, toIsTown : boolean) : integer base/tealdef/gui/main/cargo_util.d.tl:154

Call as cargo_util.getCargoFlowCount

Notes

Returns how many items of a cargo type were transported per year from one entity to another.

Parameter Type Description
entityFrom Engine.Entity Source entity.
entityTo Engine.Entity Target entity.
cargoType CargoTypeId Cargo type id.
toIsTown boolean If true, the log is read on entityTo instead of entityFrom.

Returns integer: Items per year from api.engine.util.stock.getCargoLogPerYearForTarget(..., "itemsTransported", cargoType).

Used in the base game: 6 times in 2 files

base/content/gui/gui/entity_window/industry/industry_eow.script.tl:319

curr.entity2SupplyCount[otherEntity] = cargo_util.getCargoFlowCount(
base/content/gui/gui/entity_window/industry/industry.tl:211
local count = cargo_util.getCargoFlowCount(entity, entityId, cargoType, town)

CargoUtil.StockConfig

record base/tealdef/gui/main/cargo_util.d.tl:8

record StockConfig

Notes

One group of stocks of a stock list, as returned by calculateStockConfigs.

Used in the base game: 36 times in 4 files

base/content/gui/gui/main/hud_icon_toolbox.tl:51

stockConfigs : {CargoUtil.StockConfig}
base/content/gui/gui/main/cargo_util.tl:30
sortByType : boolean, showEmpty : boolean, groupStocks : boolean, producedOnly : boolean) : {CargoUtil.StockConfig}, integer, boolean
base/content/gui/gui/statistics/statistic_warehouses.tl:28
local compareStockConfigs = function(a : CargoUtil.StockConfig, b : CargoUtil.StockConfig) : integer
base/content/gui/gui/entity_window/entity_window_util.tl:246
local makeStockContentBarText = function(config : CargoUtil.StockConfig) : string

Fields

Name Type Description
ids {StockId} Stock ids (0-based) in this group.
stored integer Number of cargo items stored in the group.
capacity integer Sum of the capacities of the stocks in the group.
cargoTypesSorted {CargoTypeId} Cargo types the group accepts.
allCargoTypes boolean true if the group accepts all cargo types but one (#cargoTypesSorted == getCargoTypesCount(false) - 1).
tendency integer Change of the stock per year.
stockType StockListType Type of the stocks in the group (input, output or storage).
quality integer Average cargo quality in percent (0-100). Only set when calculateQuality was requested and the group holds cargo.
numSpoiled integer Number of spoiled (bad quality) cargo items. Only counted when calculateQuality was requested.
canPinCargoType boolean true if the group is a storage stock with cargo type filters for which a single cargo type can be pinned.
pinnedCargoType boolean true if the stocks have a pinned cargo type (stock.cargoType >= 0). nil when not determined.

CargoUtil.StockCargoCount

record base/tealdef/gui/main/cargo_util.d.tl:25

record StockCargoCount

Notes

Amount of one cargo type in a stock list, as returned by calculateStockCargoCount.

Used in the base game: 8 times in 2 files

base/content/gui/gui/main/cargo_util.tl:207

cargo_util.calculateStockCargoCount = function(entity : Engine.Entity, sortByCargoType? : boolean, stockIds? : {StockId}, calculateQuality? : boolean) : {CargoU
base/content/gui/gui/statistics/statistic_warehouses.tl:379
local stockCargos : {CargoUtil.StockCargoCount} = cargo_util.calculateStockCargoCount(key, false)

Fields

Name Type Description
cargoType CargoTypeId Cargo type id.
count integer Number of items of this cargo type in the counted stocks.
spoiledCount integer Number of spoiled items. Only set when quality was requested.
tendency integer Trend of the stock from -3 (strongly falling) to 3 (strongly rising).
quality number Average quality of this cargo type in the whole stock list. Only set when quality was requested.

CargoUtil.VehicleCargo

record base/tealdef/gui/main/cargo_util.d.tl:39

record VehicleCargo

Notes

Capacity and load of one cargo type summed over one or more vehicles.

Used in the base game: 10 times in 4 files

base/content/gui/gui/line_vehicle_mgmt/manager_window.tl:2556

local cargoInfo : {CargoUtil.VehicleCargo} = cargo_util.calculateSortedLineCargoInfo(key)
base/content/gui/gui/main/cargo_util.tl:283
local calculateSortedVehicleCargoInfo = function(vehicleEntities : {Engine.Entity}, calculateQuality? : boolean, calculateFill? : boolean) : {CargoUtil.VehicleC
base/content/gui/gui/statistics/statistic_lines.tl:333
local cargoInfo : {CargoUtil.VehicleCargo} = cargo_util.calculateSortedLineCargoInfo(key)
base/content/gui/gui/statistics/statistic_vehicles.tl:453
local cargoInfo : {CargoUtil.VehicleCargo} = cargo_util.calculateSortedVehicleCargoInfo(key)

Fields

Name Type Description
cargoType CargoTypeId Cargo type id.
capacity integer Total capacity for this cargo type over all vehicles.
vehicleEntities {Engine.Entity} Vehicles that have capacity for this cargo type.
fill integer Number of loaded items. Only filled for the compare-value functions.
hasGoodCargo boolean true if a vehicle carries items of this type that are not spoiled. Only set with calculateQuality.
hasBadCargo boolean true if a vehicle carries spoiled items of this type (never set for passengers). Only set with calculateQuality.

CargoUtil.CargoListSortOrder

enum base/tealdef/gui/main/cargo_util.d.tl:58

enum CargoListSortOrder

Notes

Sort order of getSortedProducedCargoTypes. Ties are sorted by cargo type id.

Used in the base game: 2 times in 2 files

base/content/gui/gui/main/cargo_util.tl:843

sortOrder : CargoUtil.CargoListSortOrder,
base/content/gui/gui/entity_window/entity_window_util.tl:2204
local sortOrder : CargoUtil.CargoListSortOrder = "CAPACITY"

Value Description
"CAPACITY" Sort by capacity, ascending.
"COUNT" Sort by the number of items, ascending.
"ID" Sort by cargo type id.

CargoUtil.CargoLocationParams

record base/tealdef/gui/main/cargo_util.d.tl:64

record CargoLocationParams

Notes

Where to collect cargo for getSortedProducedCargoTypes and getCargoTypeInfo. Set one or more of the entity fields; the results of all set locations are added up.

Used in the base game: 11 times in 6 files

base/content/gui/gui/line_vehicle_mgmt/line_react_util.tl:684

local locationParams : CargoUtil.CargoLocationParams = {
base/content/gui/gui/main/cargo_util.tl:584
local getCargoTypeInfoForCargoStockList = function(result : CargoUtil.CargoTypeInfo, cargoTypeId : CargoTypeId, locationParams : CargoUtil.CargoLocationParams)
base/content/gui/gui/statistics/statistic_lines.tl:62
local locationParams : CargoUtil.CargoLocationParams = {
base/content/gui/gui/statistics/statistics_react_util.tl:229
local locationParams : CargoUtil.CargoLocationParams = {
base/content/gui/gui/statistics/statistic_vehicles.tl:72
local locationParams : CargoUtil.CargoLocationParams = {
base/content/gui/gui/entity_window/entity_window_util.tl:2199
local locationParams : CargoUtil.CargoLocationParams = {

Fields

Name Type Description
vehicleEntity Engine.Entity Vehicle whose load and capacity are counted.
stockListOwnerEntity Engine.Entity Industry, warehouse or town building whose stock list is counted (see getStockListEntityFromOwner).
lineEntity Engine.Entity Line whose capacity usage is counted.
stopIndex1 integer
getTendency boolean If true, getCargoTypeInfo computes the stock tendency (only for stockListOwnerEntity).
showEmpty boolean If true, also lists cargo types with no items.
extraCapacity {CargoTypeId : integer} Capacity added per cargo type on top of the counted locations.

CargoUtil.CargoStopParams

record base/tealdef/gui/main/cargo_util.d.tl:78

record CargoStopParams

Notes

Line stop for getConfiguredStopCargoTypes.

Used in the base game: 2 times in 2 files

base/content/gui/gui/line_vehicle_mgmt/line_react_util.tl:675

local stopParams : CargoUtil.CargoStopParams = {
base/content/gui/gui/main/cargo_util.tl:820
stopParams : CargoUtil.CargoStopParams,

Fields

Name Type Description
lineEntity Engine.Entity Line entity.
stopIndex1 integer 1-based index of the stop in Line.stops.
getTendency boolean
showEmpty boolean

CargoUtil.CargoTypeInfo

record base/tealdef/gui/main/cargo_util.d.tl:86

record CargoTypeInfo

Notes

Amount, capacity and quality of one cargo type at a location, as returned by getCargoTypeInfo.

Used in the base game: 16 times in 4 files

base/content/gui/gui/main/cargo_react_util.tl:104

local makeCargoTypeIcons = function(params : CargoUtil.CargoTypeInfo, mode : GuiReactUtil.LabelMode, shippingState : GuiReactUtil.ShippingState, showLoadingIndi
base/content/gui/gui/main/cargo_util.tl:584
local getCargoTypeInfoForCargoStockList = function(result : CargoUtil.CargoTypeInfo, cargoTypeId : CargoTypeId, locationParams : CargoUtil.CargoLocationParams)
base/content/gui/gui/statistics/statistics_react_util.tl:194
statistics_react_util.calculateCargoColumnData = function(cargoTypeInfos : {cargo_util.CargoTypeInfo}) : StatisticsReactUtil.CargoColumnData
base/content/gui/gui/entity_window/entity_window_util.tl:2212
local info : CargoUtil.CargoTypeInfo = cargo_util.getCargoTypeInfo(cargoType, locationParams)

Fields

Name Type Description
cargoType CargoTypeId Cargo type id. -1 for an entry that stands for several cargo types (see cargoTypes).
cargoTypes {CargoTypeId} Cargo types that share one capacity. Only set by getVehicleUnsetCapacities.
capacity integer Capacity for this cargo type.
count integer Number of items.
tendency integer Stock trend from -3 to 3 (see StockCargoCount.tendency). Only set with getTendency.
spoiledCount integer Number of spoiled items (or unhappy passengers).
averageQuality number Average quality (0-1) of the items; for passengers their happiness.
loadSpeedModifiers Engine.Component.TransportVehicle.LoadSpeedModifiers Load speed modifiers of the vehicle for this cargo type. Only set while the vehicle is at a terminal.
loadState Engine.Component.TransportVehicle.LoadState Loading state of the vehicle. Only set while the vehicle is at a terminal.
gameSpeed number Current game speed-up factor (GameSpeed.speedup). Set for vehicles; used for the loading animation speed.

CargoUtil.VehicleUnsetCapacities

record base/tealdef/gui/main/cargo_util.d.tl:99

record VehicleUnsetCapacities

Notes

Capacities of a vehicle that are not bound to a cargo type yet, as returned by getVehicleUnsetCapacities.

Used in the base game: 1 time in 1 file

base/content/gui/gui/main/cargo_util.tl:941

cargo_util.getVehicleUnsetCapacities = function(vehicleEntity : Engine.Entity) : CargoUtil.VehicleUnsetCapacities

Fields

Name Type Description
multiTypes {CargoUtil.CargoTypeInfo} Capacities that can take one of several cargo types, one CargoTypeInfo each with cargoType = -1 and the possible types in cargoTypes.
singleCapacities {CargoTypeId : integer} Capacities that can take only one cargo type, by cargo type id.

CargoUtil.StockProperties

record base/tealdef/gui/main/cargo_util.d.tl:139

record StockProperties

Notes

How a stock list uses a cargo type, as returned by getCargoTypesForStockList.

Used in the base game: 21 times in 10 files

base/content/gui/gui/main/cargo_util.tl:471

cargo_util.getCargoTypesForStockList = function(stockListEntity : Engine.Entity) : {CargoTypeId : CargoUtil.StockProperties}
base/content/gui/gui/entity_window/entity_window_hud.tl:23
local function isProducerMatchingConsumer(producer : {CargoTypeId : CargoUtil.StockProperties}, consumer : {CargoTypeId : CargoUtil.StockProperties}, bidirectio
base/content/gui/gui/entity_window/town/town.tl:828
cargoNeeds : {CargoTypeId : CargoUtil.StockProperties}
base/content/gui/gui/entity_window/town_building/town_building.tl:249
cargoTypes : {CargoTypeId : CargoUtil.StockProperties}
base/content/game_mechanics/game_mechanics/emission/pollution_cleanup_facility_hud.script.tl:49
cargoTypes : {CargoTypeId : CargoUtil.StockProperties}
base/content/game_mechanics/game_mechanics/subventions/deliver_cargo/deliver_cargo.script.tl:273
getRelevantEntities = function(state : Subvention<DeliverCargoState>) : {Engine.Entity}, {CargoTypeId : CargoUtil.StockProperties}
… and 4 more files.

Fields

Name Type Description
booster boolean true if the cargo type is an input of a booster rule.
input boolean true if the cargo type is an input (storage stocks count as input).
output boolean true if the cargo type is an output (storage stocks count as output).

CargoUtil.CargoFlowData

record base/tealdef/gui/main/cargo_util.d.tl:148

record CargoFlowData

Notes

One supplier or consumer of a cargo flow, as built by the industry and town entity windows.

Used in the base game: 5 times in 2 files

base/content/gui/gui/entity_window/town/town.tl:865

suppliers : {CargoUtil.CargoFlowData}
base/content/gui/gui/entity_window/industry/industry.tl:205
local supplierData : {CargoUtil.CargoFlowData} = {}

Fields

Name Type Description
position Vec3f Position of the supplier or consumer entity.
cargoType CargoTypeId Cargo type of the flow.
cargoCount integer Items transported per year (from getCargoFlowCount).