Skip to content

vehicle_util

Source: base/tealdef/gui/line_vehicle_mgmt/vehicle_util.d.tl

Notes

Small helpers for vehicles and depots - lifespan and age, condition text and icons, carrier of a depot, vehicle type, capacity checks and the year-dependent value ranges used to scale the store's progress bars.

VehicleUtil

record global base/tealdef/gui/line_vehicle_mgmt/vehicle_util.d.tl:3

global record VehicleUtil

Load: local vehicle_util = ug_require "/gui/line_vehicle_mgmt/vehicle_util.tl"

Notes

Small helpers for vehicles and depots.

Fields

Name Type Description
ConditionLevels {string} Translated condition names, worst to best - Very Bad, Bad, Mediocre, Good, Very Good.
MaintenanceLevels {string} Declared, but not assigned by the base-game implementation (nil at runtime).

Functions

makePart(modelId : integer, forward : boolean, color : Vec3f) : TransportVehiclePart base/tealdef/gui/line_vehicle_mgmt/vehicle_util.d.tl:11

Call as vehicle_util.makePart

Notes

Creates a TransportVehiclePart for a model, with load config 0 for every compartment.

Parameter Type Description
modelId integer Model id of a vehicle.
forward boolean False to reverse the part.
color Vec3f Optional part colour.

Returns TransportVehiclePart

Used in the base game: 5 times in 2 files

base/content/mission/mission/tasks/vehicle_util/replace_vehicles.tl:41

local vehiclePartsList = { vehicle_util.makePart(modelId, true, nil) }
base/content/gui/gui/line_vehicle_mgmt/vehicle_store_window.tl:4042
local part = vehicle_util.makePart(modelId, true, color)

getLifespan(integer) : integer base/tealdef/gui/line_vehicle_mgmt/vehicle_util.d.tl:12

Call as vehicle_util.getLifespan

Notes

Lifespan of a vehicle model.

Returns integer: maintenance.lifespan times 1000; compared with part purchase times in game time.

getMinPurchaseTimeAndLifespan(Engine.Component.TransportVehicle) : {integer, integer} base/tealdef/gui/line_vehicle_mgmt/vehicle_util.d.tl:13

Call as vehicle_util.getMinPurchaseTimeAndLifespan

Notes

Purchase time and lifespan of the oldest part of a transport vehicle (shortest lifespan on ties).

Returns {integer, integer}: {purchaseTime, lifespan}.

Used in the base game: 2 times in 1 file

base/content/gui/gui/entity_window/line/line_eow.script.tl:126

return vehicle_util.getMinPurchaseTimeAndLifespan(transportVehicle)

getDepotCarriers(Engine.Entity) : {Carrier} base/tealdef/gui/line_vehicle_mgmt/vehicle_util.d.tl:14

Call as vehicle_util.getDepotCarriers

Notes

Carriers of the transport modes enabled in a vehicle depot.

Returns {Carrier}

Used in the base game: 3 times in 2 files

base/content/gui/gui/line_vehicle_mgmt/manager_hud_util.tl:1260

local depotCarriers = vehicle_util.getDepotCarriers(hudIconParam.entity)
base/content/gui/gui/construction/constructionHudIconMaster.tl:84
carriers = vehicle_util.getDepotCarriers(param.entity)

getDepotCarrier(Engine.Entity) : Carrier base/tealdef/gui/line_vehicle_mgmt/vehicle_util.d.tl:15

Call as vehicle_util.getDepotCarrier

Notes

The single carrier of a vehicle depot.

Returns Carrier: The carrier, or nil (with a warning in the log) if the depot has none or several.

Used in the base game: 1 time in 1 file

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

carrier = vehicle_util.getDepotCarrier(depotEntity),

getDepotTransportModes(Engine.Entity) : {TransportMode : boolean} base/tealdef/gui/line_vehicle_mgmt/vehicle_util.d.tl:16

Call as vehicle_util.getDepotTransportModes

Notes

Transport modes of a vehicle depot.

Returns {TransportMode : boolean}: The depot's transportModes, or an empty table if the depot has no in or out nodes.

Used in the base game: 3 times in 3 files

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

transportModes = vehicle_util.getDepotTransportModes(depotEntity),
base/content/gui/gui/line_vehicle_mgmt/line_react_util.tl:425
local transportModeMap = vehicle_util.getDepotTransportModes(depotEntity)
base/content/game_mechanics/game_mechanics/notifications/types/availability.script.tl:99
local depotTransportModes = vehicle_util.getDepotTransportModes(e)

getVehicleTypeFromModel(model : Model) : VehicleType base/tealdef/gui/line_vehicle_mgmt/vehicle_util.d.tl:28

Call as vehicle_util.getVehicleTypeFromModel

Notes

Vehicle type of a model from its transportVehicle.transportModes; Train if nothing matches.

Returns VehicleType

Used in the base game: 2 times in 1 file

base/content/game_mechanics/game_mechanics/notifications/types/availability.script.tl:118

vehicleType = vehicle_util.getVehicleTypeFromModel(model)

getVehicleTypeFromEntity(ent : Engine.Entity) : VehicleType base/tealdef/gui/line_vehicle_mgmt/vehicle_util.d.tl:29

Call as vehicle_util.getVehicleTypeFromEntity

Notes

Vehicle type of a vehicle entity from its carrier (bus vs. truck from the transport modes, helicopter vs. airplane from the first part's model).

Returns VehicleType

Used in the base game: 2 times in 2 files

base/content/game_mechanics/game_mechanics/notifications/types/vehicle_warning.sim.script.tl:14

old.typeMapping[entityAndRev.entity] = vehicle_util.getVehicleTypeFromEntity(entityAndRev.entity)
base/content/game_mechanics/game_mechanics/notifications/types/vehiclecondition.sim.script.tl:14
old.typeMapping[entityAndRev.entity] = vehicle_util.getVehicleTypeFromEntity(entityAndRev.entity)

getConditionText(number) : string base/tealdef/gui/line_vehicle_mgmt/vehicle_util.d.tl:32

Call as vehicle_util.getConditionText

Notes

Condition name for a maintenance state from 0 to 1 (split into five equal steps).

Returns string

Used in the base game: 6 times in 4 files

base/content/gui/gui/line_vehicle_mgmt/vehicle_react_util.tl:42

return vehicle_util.getConditionText(condition)
base/content/gui/gui/statistics/statistic_vehicles.tl:228
text = vehicle_util.getConditionText(maintenanceState:old()),
base/content/gui/gui/entity_window/entity_window_util.tl:1996
text = vehicle_util.getConditionText(state:old()[1]),
base/content/gui/gui/entity_window/vehicle/vehicle_eow.script.tl:1115
ratingText = vehicle_util.getConditionText(vehicleMaintenanceState:old().maintenanceState),

getConditionIcon(number) : string base/tealdef/gui/line_vehicle_mgmt/vehicle_util.d.tl:33

Call as vehicle_util.getConditionIcon

Notes

Condition icon path (::/gui/line_vehicle_mgmt/icons/condition_*.tga) for a maintenance state from 0 to 1.

Returns string

Used in the base game: 1 time in 1 file

base/content/gui/gui/line_vehicle_mgmt/vehicle_react_util.tl:54

return {vehicle_util.getConditionIcon(condition), vehicle_util.getConditionText(condition)}

getNoise01(emissions : number, carrier : Carrier) : number base/tealdef/gui/line_vehicle_mgmt/vehicle_util.d.tl:37

Call as vehicle_util.getNoise01

Notes

Maps a noise emission value to 0 to 1, by carrier (0 to 200 for rail, 0 to 300 for air, 0 to 100 otherwise).

Returns number

getPollution01(emissions : number, carrier : Carrier) : number base/tealdef/gui/line_vehicle_mgmt/vehicle_util.d.tl:38

Call as vehicle_util.getPollution01

Notes

Maps a pollution emission value to 0 to 1, by carrier (0 to 200 for rail, 0 to 300 for air, 0 to 100 otherwise).

Returns number

isAbleToLoadCargo(tv : Engine.Component.TransportVehicle) : boolean base/tealdef/gui/line_vehicle_mgmt/vehicle_util.d.tl:40

Call as vehicle_util.isAbleToLoadCargo

Notes

True if the transport vehicle has capacity for any cargo other than passengers.

Returns boolean

isAbleToLoadPassenger(tv : Engine.Component.TransportVehicle) : boolean base/tealdef/gui/line_vehicle_mgmt/vehicle_util.d.tl:41

Call as vehicle_util.isAbleToLoadPassenger

Notes

True if the transport vehicle has passenger capacity (any load config).

Returns boolean

Used in the base game: 1 time in 1 file

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

if vehicle_util.isAbleToLoadPassenger(tv) then

getRanges(carrier : Carrier, onlyPassengers : boolean, year : integer) : Ranges base/tealdef/gui/line_vehicle_mgmt/vehicle_util.d.tl:57

Call as vehicle_util.getRanges

Notes

Value ranges for a carrier and game year.

Parameter Type Description
carrier Carrier Vehicle carrier.
onlyPassengers boolean True for vehicles that carry only passengers.
year integer Current game year.

Returns Ranges

Used in the base game: 3 times in 3 files

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

return vehicle_util.getRanges(carrier, onlyPassengers, year)
base/content/gui/gui/entity_window/vehicle/vehicle_eow.script.tl:502
return vehicle_util.getRanges(param.carrier, onlyPassengers, date.year)
base/content/game_mechanics/game_mechanics/subventions/subvention_util.tl:487
local maxSpeed = vehicle_util.getRanges(api.type["enum"].Carrier.RAIL, true, api.engine.util.getYear()).maxSpeed

getAvgMaintenanceState(Engine.Entity) : number, number base/tealdef/gui/line_vehicle_mgmt/vehicle_util.d.tl:59

Call as vehicle_util.getAvgMaintenanceState

Notes

Average maintenance state of all parts of a vehicle.

Returns number, number: Average state (1.0 if the vehicle has no parts) and average maintenance change.

Used in the base game: 11 times in 6 files

base/content/gui/gui/line_vehicle_mgmt/vehicle_react_util.tl:41

local condition, __ = vehicle_util.getAvgMaintenanceState(vehicleEntity)
base/content/gui/gui/statistics/statistic_vehicles.tl:218
local condition, __ = vehicle_util.getAvgMaintenanceState(entity)
base/content/gui/gui/entity_window/entity_window_util.tl:1987
local state, change = vehicle_util.getAvgMaintenanceState(params.entityId)
base/content/gui/gui/entity_window/maintenance_station/maintenance_station_eow.script.tl:209
local aCondition, __ = vehicle_util.getAvgMaintenanceState(a)
base/content/gui/gui/entity_window/vehicle/vehicle_eow.script.tl:686
local maintenanceState, __ = vehicle_util.getAvgMaintenanceState(params.vehicleEntity)
mods/release/urbangames_campaign_mission_03/content/mission/mission/tasks/fatal_maintenance/fatal_maintenance.tl:42
maintenanceState, maintenanceChange = vehicle_util.getAvgMaintenanceState(vehicleEntityId)

getAge(Engine.Entity) : AgeInfo base/tealdef/gui/line_vehicle_mgmt/vehicle_util.d.tl:68

Call as vehicle_util.getAge

Notes

Age information of a vehicle, based on its oldest part and the current game time.

Returns AgeInfo

Used in the base game: 2 times in 1 file

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

return vehicle_util.getAge(entity)

GetVehicleModelIds(Engine.Entity) : {integer} base/tealdef/gui/line_vehicle_mgmt/vehicle_util.d.tl:70

Call as vehicle_util.GetVehicleModelIds

Notes

Model ids of all parts of a vehicle, in consist order.

Returns {integer}

Used in the base game: 4 times in 4 files

base/content/gui/gui/line_vehicle_mgmt/vehicle_list_react_util.tl:560

return vehicle_util.GetVehicleModelIds(rowKey)
base/content/gui/gui/statistics/statistic_depots.tl:135
local ids1 = vehicle_util.GetVehicleModelIds(vehicles[i])
base/content/gui/gui/statistics/statistic_lines.tl:268
local ids1 = vehicle_util.GetVehicleModelIds(vehicles[i])
base/content/gui/gui/statistics/statistic_vehicles.tl:361
{ name = _("Vehicle"), recipe = VehicleImageCell, getCompareValue = vehicle_util.GetVehicleModelIds, weight = 2.8, },

getPowerRatingTextAndToolTip(weight : number, power : number, tractiveEffort : number, topSpeed : number, rollingFriction : number) : {string, string, number} base/tealdef/gui/line_vehicle_mgmt/vehicle_util.d.tl:72

Call as vehicle_util.getPowerRatingTextAndToolTip

Notes

Power rating of a land vehicle (Poor, Mediocre, Good, Excellent) with a tooltip listing the top speed reachable on flat, medium and high slopes.

Parameter Type Description
weight number Vehicle weight.
power number Engine power.
tractiveEffort number Tractive effort.
topSpeed number Top speed.
rollingFriction number Rolling friction.

Returns {string, string, number}: {ratingText, tooltip, rating01}, or nil if the acceleration integration fails.

Used in the base game: 1 time in 1 file

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

local textAndTooltipAndValue = vehicle_util.getPowerRatingTextAndToolTip(

isCurrentlyAbleToHoldPassengers(vehicleEntity : Engine.Entity) : boolean base/tealdef/gui/line_vehicle_mgmt/vehicle_util.d.tl:75

Call as vehicle_util.isCurrentlyAbleToHoldPassengers

Notes

True if the vehicle's current configuration has passenger capacity.

Returns boolean

Used in the base game: 2 times in 2 files

base/content/gui/gui/layers/layer_passenger_flow.tl:52

if not vehicleUtil.isCurrentlyAbleToHoldPassengers(params.entity) then
base/content/gui/gui/layers/layer_public_transport.tl:97
if vehicle and vehicleUtil.isCurrentlyAbleToHoldPassengers(params.entity) then

VehicleUtil.AgeInfo

record base/tealdef/gui/line_vehicle_mgmt/vehicle_util.d.tl:4

record AgeInfo

Notes

Age information of a vehicle, from getAge.

Used in the base game: 2 times in 2 files

base/content/gui/gui/line_vehicle_mgmt/vehicle_util.tl:297

vehicle_util.getAge = function(vehicleEntity : Engine.Entity) : VehicleUtil.AgeInfo
base/content/gui/gui/statistics/statistic_vehicles.tl:236
local makeState = function() : VehicleUtil.AgeInfo

Fields

Name Type Description
age string Formatted age since the oldest part was bought.
purchaseTime integer Game time at which the oldest part was bought.
agePercent number Age as rounded percentage of the lifespan (may exceed 100).
timeRemaining string | nil Formatted time until the end of the lifespan, or nil if it is over.

VehicleUtil.VehicleType

enum base/tealdef/gui/line_vehicle_mgmt/vehicle_util.d.tl:18

enum VehicleType

Notes

Coarse vehicle type, derived from transport modes or carrier.

Used in the base game: 11 times in 4 files

base/content/gui/gui/line_vehicle_mgmt/vehicle_util.tl:84

vehicle_util.getVehicleTypeFromModel = function(model : Model) : VehicleUtil.VehicleType
base/content/game_mechanics/game_mechanics/notifications/types/vehicle_warning.script.tl:81
local makeTypeState = function() : VehicleUtil.VehicleType
base/content/game_mechanics/game_mechanics/notifications/types/vehiclecondition.script.tl:23
local makeTypeState = function() : VehicleUtil.VehicleType
base/content/game_mechanics/game_mechanics/notifications/types/availability.script.tl:115
local vehicleType : VehicleUtil.VehicleType

Value Description
"Train" Train (also the fallback).
"Tram" Tram.
"Bus" Bus.
"Truck" Truck.
"Ship" Ship (large or small).
"Airplane" Aircraft (large or small).
"Helicopter" Helicopter.

VehicleUtil.Ranges

record base/tealdef/gui/line_vehicle_mgmt/vehicle_util.d.tl:43

record Ranges

Notes

Value ranges used by the vehicle store and vehicle window to scale property bars, from getRanges.

Details

The base game keeps a small table per carrier with entries for certain years (e.g. rail 1900, 1921, 1941, 1981); the last entry whose year is reached wins.

Used in the base game: 7 times in 4 files

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

ranges : VehicleUtil.Ranges
base/content/gui/gui/line_vehicle_mgmt/vehicle_util.tl:210
local carrierToYearToRange : {Carrier : {VehicleUtil.Ranges}} = {
base/content/gui/gui/line_vehicle_mgmt/vehicle_store_util.tl:412
) : VehicleUtil.Ranges
base/content/gui/gui/entity_window/vehicle/vehicle_eow.script.tl:420
ranges : VehicleUtil.Ranges,

Fields

Name Type Description
year integer First year the entry applies to.
onlyPassengers boolean | nil If set, the entry only applies to passenger-only (true) or other (false) vehicles.
minSpeed number Lower end of the speed bar, in m/s.
maxSpeed number Upper end of the speed bar, in m/s (default 200 km/h).
maxPower number Upper end of the power bar (default 15000).
maxThrust number Upper end of the thrust bar (default 500000).
maxRunningCosts number Upper end of the running-cost bar (1000000).
pollutionScoreRange {number, number} {min, max} of the pollution bar.
noiseScoreRange {number, number} {min, max} of the noise bar.
comfortScoreRange {number, number} {min, max} of the comfort bar.
loadSpeedScoreRange {number, number} {min, max} of the loading-speed bar.

VehicleUtil.Emissions

record base/tealdef/gui/line_vehicle_mgmt/vehicle_util.d.tl:61

record Emissions

Notes

Declared record; not used by base-game code.

Fields

Name Type Description
score integer
currentBase integer
currentExtra integer
conditionIndex integer