Difference between revisions of "NML:Vehicles"
Andythenorth (talk | contribs) (→Variables without parameter: - note that current_railtype is basically of no use) |
Andythenorth (talk | contribs) |
||
Line 1,070: | Line 1,070: | ||
|- |
|- |
||
| tile_powers_railtype |
| tile_powers_railtype |
||
+ | | tile_powers_roadtype |
||
⚫ | |||
+ | | tile_powers_tramtype |
||
⚫ | |||
| [0 <nowiki>|</nowiki> 1] |
| [0 <nowiki>|</nowiki> 1] |
||
| No |
| No |
||
− | | Vehicles of the |
+ | | Vehicles of the type label used as parameter are powered on the track on the current tile. Example: <code style="color:darkgreen">tile_powers_railtype(ELRL)</code> |
|- |
|- |
||
| tile_is_railtype |
| tile_is_railtype |
Revision as of 19:04, 17 April 2021
Vehicles, Stations, Canals, Bridges, Towns, Houses, Industries (Tiles), Cargos, Airports+Tiles, Objects, Railtypes, Roadtypes, Tramtypes, Terrain
- common props | vars | CBs
- train | roadveh | ship | aircr props
- common variables
- industry props | vars | CBs
- tile props | vars | CBs
- airport props | vars | CBs
- tile props | vars | CBs
Properties common to all vehicle types
property | value range | available for articulated vehicle |
comment |
---|---|---|---|
name
|
(string) | yes | for example string(STR_NAME_HEREFORD_TRAM)
|
climates_available
|
bitmask(CLIMATE_XXX, CLIMATE_YYY, ...) | set to NO_CLIMATE
|
To make a vehicle available in all climates except toyland you could use: |
introduction_date
|
date (yyyy,mm,dd)
|
no | Valid range for yyyy is 0 ... 5000000. In TTDPatch, dates after 2044 will be limited to 2044. Unless the engine is introduced within two years after game-start (always 1920 in TTDPatch), a random number of days between 0 and 511 will be added to this. |
model_life
|
0 ... 254 (years) or VEHICLE_NEVER_EXPIRES
|
no |
Number of years a model is "supported" by the manufacturer, see below. |
retire_early
|
-128 ... 127 (years) | no |
Retire the vehicle (make it unavailable in the purchase menu) this many years before reliability starts dropping, see below. May be negative. |
vehicle_life
|
0 ... 255 (years) | no | Life length of an individual vehicle, before it is considered too old and in need of replacement. |
reliability_decay
|
0 ... 255 | no | Default vehicles use 20. The higher the value the faster reliability decays, the more frequent service is needed. 0 means reliability never decreases if the vehicle is not too old |
refittable_cargo_classes
|
bit set of cargo classes |
yes | for example: bitmask(CC_BULK, CC_COVERED)
|
non_refittable_cargo_classes
|
bit set of cargo classes |
yes | for example: bitmask(CC_OVERSIZED, CC_SPECIAL)
|
refittable_cargo_types
|
bit mask of entries into the cargo translation table | yes | As of NML 0.3, do not use this. Use cargo_[dis]allow_refit (see below) instead. |
cargo_allow_refit
|
Array of cargo labels from the cargotable | Yes | 1.2 A list of cargo types to allow refitting to, irrespective of cargo classes. Example: [COAL, IORE]
|
cargo_disallow_refit
|
Array of cargo labels from the cargotable | Yes | 1.2 A list of cargo types to disallow refitting to, irrespective of cargo classes. Example: [MAIL]
|
loading_speed
|
0 ... 255 (cargo units) | yes | Units of cargo loaded per time unit. Default vehicles use 5 for trains and road vehicles, 10 for ships and 20 for aircraft. This amount of cargo is loaded to or unloaded from the vehicle every 40 ticks for trains, every 20 ticks for road vehicles and aircraft and every 10 ticks for ships. |
cost_factor
|
0 ... 255 | Set to 0 | multiplier to the base purchase cost |
running_cost_factor
|
0 ... 255 | Set to 0 | multiplier to the base running costs |
cargo_age_period
|
0 ... 65535 | yes |
1.2 This property specifies after how many ticks cargo is aged. Default value is 185. 74 ticks is equal to 1 day. If set to 0, cargo does not age. |
Refittability
To determine whether your vehicle can be refitted to a certain cargo, OpenTTD uses the following table
Cargo matches refittable_cargo_classes | Cargo matches non_refittable_cargo_classes | Cargo in cargo_allow_refit | Cargo in cargo_disallow_refit | Result |
---|---|---|---|---|
Yes | No | Doesn't matter | No | Refittable |
No | Doesn't matter | No | Doesn't matter | Not refittable |
Doesn't matter | Doesn't matter | Yes | No | Refittable |
Doesn't matter | Doesn't matter | Doesn't matter | Yes | Not refittable |
For those that prefer boolean logic, the formula is as follows:
refittable = ((cargo classes in refittable_cargo_classes AND NOT cargo classes in non_refittable_cargo_classes) OR cargo in cargo_allow_refit) AND NOT (cargo in cargo_disallow_refit)
In general, you should use refittable_cargo_classes and non_refittable_cargo_classes to decide to which cargos your vehicle is refittable, and only then use cargo_allow_refit and cargo_disallow_refit to allow/disallow specific cargos.
Engine life cycle
The life cycle of a vehicle model consists of three phases, as outlined in the following table. When starting a new game, a random amount between 31 months and 17 years is added to the model life as well.
phase | duration | reliability |
---|---|---|
1 | 7 to 38 months | increases from 48-73% to 75-100% |
2 | model_life - 8 years
|
stays constant at peak, 75-100% |
3 | 10 to 20.5 years | decreases from peak to 25-50% |
If model_life
is set to VEHICLE_NEVER_EXPIRES
, the engine remains in phase 2 forever.
Normally, the vehicle is removed from the purchase menu at the and of phase 3. However if you set the retire_early
property, it will be retired this many years before (or after, if the value is negative) the end of phase 2.
Train properties
property | value range | available for articulated vehicle |
comment |
---|---|---|---|
sprite_id
|
SPRITE_ID_NEW_TRAIN
|
yes | Set this property to enable new graphics |
speed
|
0 ... 65000 (float, speed units) | no | Max speed for engines, speed limit for wagons |
misc_flags
|
bitmask(TRAIN_FLAG_XXX, ...) | FLIP should not be set, TILT and MU TO the same value as the 1st part |
|
refit_cost
|
0 ... 255 | yes | in 50% units of the purchase price cost base |
callback_flags
|
bitmask(VEH_CBF_XXX, ...) | yes |
Do not set this, unless you use old-style callbacks. |
track_type
|
item from railtypetable | must be the same as front | Default railtype table: RAIL, MONO, MGLV. If you install a railtypetable yourself you'll always get the railtype you specified. If you want a vehicle to run on electric rail and you don't have a railtypetable, set track_type to RAIL and make sure that you set engine_class to ENGINE_CLASS_ELECTRIC .
|
ai_special_flag
|
[AI_FLAG_PASSENGER | AI_FLAG_CARGO ]
|
no |
|
power
|
0 ... 65000 hp (float, power units) | Set to 0 | |
running_cost_base
|
RUNNING_COST_XXX | Set to RUNNING_COST_NONE |
|
dual_headed
|
[0 | 1] | Set to 0 for all parts of an articulated vehicle | 1 = dual_headed, otherwise normal engine |
default_cargo_type
|
An identifier from the cargo table, or DEFAULT_CARGO_FIRST_REFITTABLE | Yes | If the vehicle is refittable to at least one cargo, but the chosen default cargo is not available or is set to DEFAULT_CARGO_FIRST_REFITTABLE, then the first refittable cargo is used. The first refittable is chosen according to the order in your cargo table. If this property is set to a valid cargo but the vehicle cannot refit to any cargo type, then the vehicle will be able to carry only this cargo, but it cannot be refitted (like e.g. the default train wagons). |
cargo_capacity
|
0 .. 255 | yes | By default, passenger capacity is 4x, and mail/goods capacity 2x larger than capacity for other cargoes. The capacity set here is used for the default (i.e. first refittable) cargo. Use the cargo_capacity callback to avoid this effect.
|
weight
|
0 .. 1279 ton (float, mass units) | Set to 0 | |
ai_engine_rank
|
0 ... 255 | no | TTDPatch only: Higher values make the engine for the TTDPatch AI more attractive |
engine_class
|
ENGINE_CLASS_XXX | no |
Defines which livery colour settings apply to the vehicle. It also sets the corresponding sound effect of the engine, and if visual_effect_and_powered is not set, the visual effect as well.
|
extra_power_per_wagon
|
0 ... 65000 hp (float, power units) | Set to 0 | Only wagons with a livery override for this engine will add power |
tractive_effort_coefficient
|
0 ... 1 (float) | Set to 0 | Fraction of the vehicle weight that is available as tractive effort. Tractive effort (in kN) is calculated as (TE coefficient) * 10 * weight (in tons), with 10 being an approximation of the acceleration of gravity (9.81 m/s). A good value for rail tracks is 0.3. |
air_drag_coefficient
|
0 ... 1 (float) | Set to 0 | Coefficient of the relative air drag, in arbitrary units. The default value is approximately (8 / max_speed), with max_speed in km/h, clamped to the range 0.004 .. 0.75. |
length
|
1 ... 8 | yes | Length of the vehicle in arbitrary units. Use a value of 8 (equal to the predefined constant VEHICLE_LENGTH) for a full-length vehicle. |
visual_effect_and_powered
|
visual_effect_and_powered (VISUAL_EFFECT_XXX, offset, ENABLE_WAGON_POWER or DISABLE_WAGON_POWER )
|
yes |
There are two methods to set the visual effect of a vehicle:
For each vehicle you have to decide for the method. You cannot use them both for the same vehicle 'item'. Set the type of visual effect for the vehicle and its positional offset with respect to the vehicle. An offset of 0 is default, negative values mean more to the front and positive values are backwards. Minimum offset is -8, maximum is 7.
|
effect_spawn_model_and_powered
|
EFFECT_SPAWN_MODEL_XXX or EFFECT_SPAWN_MODEL_XXX | ENABLE_WAGON_POWER
|
yes |
There are two methods to set the visual effect of a vehicle:
For each vehicle you have to decide for the method. You cannot use them both for the same vehicle 'item'. 1.5 Set the spawning model of visual effects for the vehicle, that is when the vehicle emits visual effects. The visual appearance itself is defined by the callback 'create_effect'.
|
extra_weight_per_wagon
|
0 ... 255 ton (float, mass units) | Set to 0 | Adds extra weight for powered wagons, see extra_power_per_wagon
|
bitmask_vehicle_info
|
8-bit bitmask | yes |
Used for obtaining |
Road vehicle properties
property | value range | available for articulated vehicle |
comment |
---|---|---|---|
sprite_id | SPRITE_ID_NEW_ROADVEH | yes | Set this property to enable new graphics |
speed | 0 ... 511km/h (float, speed units) | no | |
road_type or tram_type | item from roadtypetable or tramtypetable | must be the same as front | Only one of these properties may be set.
If If not set, road vehicles will default to ROAD and tram vehicles will default to RAIL (this does not overlap with railtype RAIL). |
misc_flags | bitmask(ROADVEH_FLAG_XXX, ...) | partly; tram flag must the same |
|
refit_cost | 0 ... 255 | yes | in 25% units of the purchase price cost base |
callback_flags | bitmask(VEH_CBF_XXX, ...) | yes |
Do not set this, unless you use old-style callbacks. |
running_cost_base | RUNNING_COST_XXX | set to RUNNING_COST_NONE |
|
power | 0 ... 2550hp (float, power units) | Set to 0 | |
weight | 0 ... 63.75ton (float, mass units) | Set to 0 | |
tractive_effort_coefficient | 0 ... 1 (float) | Set to 0 | Fraction of the vehicle weight that is available as tractive effort. Tractive effort (in kN) is calculated as (TE coefficient) * 10 * weight (in tons), with 10 being an approximation of the acceleration of gravity (9.81 m/s). Default value is 0.3. |
air_drag_coefficient | 0 ... 1 (float) | Set to 0 | Coefficient of the relative air drag, in arbitrary units. The default value is approximately (8 / max_speed), with max_speed in km/h, clamped to the range 0.004 .. 0.75. |
default_cargo_type
|
An identifier from the cargo table, or DEFAULT_CARGO_FIRST_REFITTABLE | Yes | If the vehicle is refittable to at least one cargo, but the chosen default cargo is not available or is set to DEFAULT_CARGO_FIRST_REFITTABLE, then the first refittable cargo is used. The first refittable is chosen according to the order in your cargo table. If this property is set to a valid cargo but the vehicle cannot refit to any cargo type, then the vehicle will be able to carry only this cargo, but it cannot be refitted (like e.g. the default train wagons). |
cargo_capacity | 0 ... 255 | yes | By default, passenger capacity is 4x, and mail/goods capacity 2x larger than capacity for other cargoes. The capacity set here is used for the default (i.e. first refittable) cargo. Use the cargo_capacity callback to avoid this effect.
|
sound_effect | SOUND_XXX | no |
See available sound effects.
|
visual_effect | visual_effect( VISUAL_EFFECT_XXX, offset) | yes |
There are two methods to set the visual effect of a vehicle:
For each vehicle you have to decide for the method. You cannot use them both for the same vehicle 'item'. Set the type of visual effect for the vehicle and its positional offset with respect to the vehicle. An offset of 0 is default, negative values mean more to the front and positive values are backwards. Minimum offset is -8, maximum is 7.
|
effect_spawn_model
|
EFFECT_SPAWN_MODEL_XXX
|
yes |
There are two methods to set the visual effect of a vehicle:
For each vehicle you have to decide for the method. You cannot use them both for the same vehicle 'item'. 1.5 Set the spawning model of visual effects for the vehicle, that is when the vehicle emits visual effects. The visual appearance itself is defined by the callback 'create_effect'.
|
length | 1 ... 8 | yes | Length of the vehicle in arbitrary units. Use a value of 8 (equal to the predefined constant VEHICLE_LENGTH) for a full-length vehicle. |
Ship properties
property | value range | comment |
---|---|---|
sprite_id | SPRITE_ID_NEW_SHIP | Set this property to enable new graphics |
speed | 0 ... 127 km/h (float, speed units) | |
misc_flags | bitmask(SHIP_FLAG_XXX) | Bitmask with to possible flags, set to 0 to disable all.
|
refit_cost | 0 ... 255 | in 1/32 of the default refit cost base |
callback_flags | bitmask(VEH_CBF_XXX, ...) |
Do not set this, unless you use old-style callbacks. |
is_refittable | [0 | 1] | 0=false, 1=true. Note: if you do not set this property to 1, then refittable_cargo_classes / non_refittable_cargo_classes have no effect. |
default_cargo_type
|
An identifier from the cargo table, or DEFAULT_CARGO_FIRST_REFITTABLE | If the vehicle is refittable to at least one cargo, but the chosen default cargo is not available or is set to DEFAULT_CARGO_FIRST_REFITTABLE, then the first refittable cargo is used. The first refittable is chosen according to the order in your cargo table. If this property is set to a valid cargo but the vehicle cannot refit to any cargo type, then the vehicle will be able to carry only this cargo, but it cannot be refitted (like e.g. the default train wagons). |
cargo_capacity | 0 ... 255 | For ships (unlike other vehicle types) the capacity set here is not affected by the cargo type. |
sound_effect | SOUND_XXX |
See available sound effects.
|
ocean_speed_fraction | 0 ... 1 (float) | |
canal_speed_fraction | 0 ... 1 (float) | |
visual_effect | visual_effect(VISUAL_EFFECT_XXX, offset) |
There are two methods to set the visual effect of a vehicle:
For each vehicle you have to decide for the method. You cannot use them both for the same vehicle 'item'. XXX=[DEFAULT | STEAM | DIESEL | ELECTRIC | DISABLE], it is the type of the visual effect you want for this ship. Default means no effect. Offset is the position of the effect. 0 is default, negative values mean more to the front and positive values are backwards. Minimum offset is -8, maximum is 7. |
effect_spawn_model
|
EFFECT_SPAWN_MODEL_XXX
|
There are two methods to set the visual effect of a vehicle:
For each vehicle you have to decide for the method. You cannot use them both for the same vehicle 'item'. 1.5 Set the spawning model of visual effects for the vehicle, that is when the vehicle emits visual effects. The visual appearance itself is defined by the callback 'create_effect'.
|
Aircraft properties
property | value range | comment |
---|---|---|
sprite_id | SPRITE_ID_NEW_AIRCRAFT | Set this property to enable new graphics |
speed | 0 .. 3280 km/h (float, speed units) | |
range | 0 .. 2894 | NML 0.3 1.2 Maximum (euclidean) distance the aircraft can cover between two airports. Set to 0 for unlimited range. |
misc_flags | bitmask(AIRCRAFT_FLAG_2CC, AIRCRAFT_FLAG_AUTOREFIT) | Bitmask with to possible flags, set to 0 to disable all.
|
refit_cost | 0 ... 255 | in 1/32 of default refit cost base |
callback_flags | bitmask(VEH_CBF_XXX, ...) |
Do not set this, unless you use old-style callbacks. |
aircraft_type | AIRCRAFT_TYPE_XXX |
|
acceleration | 1.3.1 0 ... 255 <1.3.1 0 ... 19 |
1.3.1 Default aircraft use values in the range 18 to 50 (= 6.75 to 18.75 mph/tick = 499.5 to 1387.5 mph/day), which is generally considered quite fast. <1.3.1 In older OpenTTD, aircraft provided by NewGRF accelerate 166% faster than intended. |
passenger_capacity | 0 ... 65536 | Capacity for the passenger compartment. See also the notes at mail_capacity below.
|
mail_capacity | 0 ... 255 | Capacity for the mail compartment, if refitted to a cargo in the CC_PASSENGERS class. When refitted to other cargoes, this capacity is added to the passenger capacity to determine the base capacity. The actual capacity is set to this base capacity divided by 1 for mail, 2 for goods and 4 for all other cargoes. To override this effect, use the passenger_capacity and mail_capacity callbacks.
|
sound_effect | SOUND_XXX |
See available sound effects.
|
Vehicle variables
Below an overview of all vehicle-specific variables. Note that in the purchase list, the vehicle is not built yet and as such many variables are not available. All general variables are available, refer to the table for info on vehicle-specific variables. Trying to access a non-available variable invokes undefined behaviour. Please note that while all variables are available for all vehicles types, some of them only make sense for one or more vehicle types. For example checking current_railtype for a non-rail vehicle doesn't make sense at all, similarly checking current_roadtype for a tram won't return a useful result.
Variables without parameter
name | value range | available in purchase list? |
comment |
---|---|---|---|
position_in_consist | 0 ... 255 | No | The position of the current vehicle-part from the start of the vehicle. The engine will get value 0, the first wagon (or second engine) gets value 1, etc. |
position_in_consist_from_end | 0 ... 255 | No | Same as position_in_consist but counted from the end. The last wagon will get value 0. |
num_vehs_in_consist | 1 ... 256 | No | The total number of vehicles-parts in this vehicle. For aircraft this will include the shadow and the rotor. |
position_in_vehid_chain | 0 ... 255 | No | See position_in_consist, but not of the complete vehicle but only all consecutive parts with the same id. |
position_in_vehid_chain_from_end | 0 ... 255 | No | See position_in_consist_from_end, but not of the complete vehicle but only all consecutive parts with the same id. |
num_vehs_in_vehid_chain | 1 ... 256 | No | See num_vehs_in_consist, but not of the complete vehicle but only all consecutive parts with the same id. |
position_in_articulated_veh | 0 ... 255 | No | NML 0.3 1.4 The position of the current articulated vehicle from the start of the vehicle. The first will get value 0, the second one gets value 1, etc. |
position_in_articulated_veh_from_end | 0 ... 255 | No | NML 0.3 1.4 The position of the current articulated vehicle from the end of the vehicle. The last will get value 0, the second last one gets value 1, etc. |
cargo_classes_in_consist | Bitmask of CC_XXX | No | |
most_common_cargo_type | No | The most common cargo type in the consist. Prior to nml r2320 this was known as most_common_refit, and didn't work, and was also incorrectly documented :) | |
most_common_cargo_subtype | 0 ... 255 | No | The most common cargo subtype for most_common_cargo_type |
bitmask_consist_info | Bitmask 8 bit | No |
Binary OR of the values of bitmask_vehicle_info of all vehicles (engines, wagons) in the consist. Only available for rail vehicles. |
company_num | 0 ... 14 | Yes | company number of the vehicle owner. TTDPatch only supports up to 8 companies (0 ... 7) |
company_type | PLAYERTYPE_XX | Yes |
OpenTTD only uses PLAYERTYPE_HUMAN and PLAYERTYPE_AI. If you cheat yourself to be part of an AI company OpenTTD will still report PLAYERTYPE_AI for the company with yourself and the AI and it'll report PLAYERTYPE_HUMAN for the now uncontrolled company. |
company_colour1 | COLOUR_XXX | Yes |
Refer to the table here for possible values. |
company_colour2 | COLOUR_XXX | Yes |
Same as company_colour1, if no 2nd company colour is chosen. Refer to the table here for possible values. |
aircraft_height | 0 ... 255 | No | Height difference between the aircraft and its shadow. 8 Units are equivalent to one height level on the map. |
airport_type | AIRPORTTYPE_XX | No |
|
curv_info_prev_cur | -2 ... 2 | No | Difference in direction between the previous (towards engine) vehicle and this vehicle. Curvature to the right is positive. 1 unit is 45 degrees. |
curv_info_cur_next | -2 ... 2 | No | Difference in direction between this vehicle and the next (towards rear end) vehicle. Curvature to the right is positive. 1 unit is 45 degrees. |
curv_info_prev_next | -4 ... 4 | No | Difference in direction between the previous (towards engine) and next (towards rear end) vehicle. Curvature to the right is positive. 1 unit is 45 degrees. Equal to curve_invo_prev_cur + curv_info_cur_next .
|
curv_info | vehicle_curv_info(prev_cur, cur_next)' | No |
Returns a magic number that represents the curvature state of the prev-cur-next vehicle triplet. Do not try to make sense of this magic number, use the builtin function |
motion_counter | 0 ... 0xFFFFFF | Yes, always 0 | Is increased every time the vehicle moves a single step on the map. Useful for driving animations.
For that, make the animation use a number of frames, which is a power of two, i.e. 2, 4, 8, 16, 32, ... frames, and then use the lower n bits of motion_counter. |
cargo_type_in_veh | entry in cargo translation table | Yes, for the default cargo | 0xFF if not present in the table |
cargo_unit_weight | weight per unit in 1/16t | Yes, for the default cargo | |
cargo_classes | Bitmask of cargo class | Yes, for the default cargo | class of the currently transported cargo |
vehicle_is_available | [0 | 1] | Yes | Value is 1 if the vehicle is available on the open market |
vehicle_is_testing | [0 | 1] | Yes | Value is 1 if the vehicle is currently being tested |
vehicle_is_offered | [0 | 1] | Yes | Value is 1 if the vehicle is currently being offered for exclusive preview |
build_year | 0 ... 5000000 | Yes | 0-based year when the vehicle was built, current year if the vehicle is not built yet |
direction | DIRECTION_XX | No |
See here for an overview of possible values and their meaning. |
cargo_capacity | 0 ... 65535 | No | Cargo capacity (number of units) of the vehicle |
cargo_count | 0 ... 65535 | No | Number of cargo units of cargo in the vehicle |
cargo_subtype | 0 ... 255 | Yes, always 0 | Cargo subtype, used to provide more than one refit option for the same cargo type. See also the cargo_subtype_text callback.
|
vehicle_is_powered | [0 | 1] | No | Vehicle provides power and is on the correct track type |
vehicle_is_not_powered | [0 | 1] | No | Vehicle is either on a wrong track type or it doesn't provide power at all |
vehicle_is_potentially_powered | [0 | 1] | No | Vehicle provides power, if it is on a suitable track type |
vehicle_is_flipped | [0 | 1] | No | Value is 1 if the sprite is reversed via flip-vehicle-in-depot (trains only) |
vehicle_is_reversed | [0 | 1] | No | Value is 1 if the vehicle has reversed an odd number of times |
built_during_preview | [0 | 1] | No | Value is 1 if the vehicle was built during the exclusive preview stage |
current_railtype | No | Entry from railtype translation table or 0xFF | This variable is useless due to equivalent railtypes, use tile_xxx_railtype instead. If you do use this variable, it will not work as expected unless you've defined a railtype translation table. If the train is running on a railtype that is not listed in your railtype translation table this variable will contain 0xFF. |
current_roadtype | No | Entry from current_roadtype translation table or 0xFF | NML 0.5 1.10 Don't use this variable unless you've defined a roadtype translation table. If the road vehicle is running on a roadtype that is not listed in your roadtype translation table this variable will contain 0xFF. Checking this for a tram is not supported and will not return a useful result. |
current_tramtype | No | Entry from tramtype translation table or 0xFF | NML 0.5 1.10 Don't use this variable unless you've defined a tramtype translation table. If the road vehicle is running on a tramtype that is not listed in your tramtype translation table this variable will contain 0xFF. Checking this for a road vehicle that is not a tram is not supported and will not return a useful result. |
waiting_triggers | No |
Random triggers waiting to be matched. (see Random switch) | |
random_bits | 0 ... 255 | No |
Random data that can be used to randomize certain descisions. (see Random switch) |
grfid | 0 ... 0xFFFFFFFF | No |
GRFID that defined the graphics-block for this vehicle. To compare this with other grfids, use the builtin function |
vehicle_type_id | 0 ... 65535 or a name defined in item block | No | GRF-local ID of the vehicle, equal to the item ID. Note that vehicles from other NewGRFs may have the same ID, so you'll generally have to check the grfid as well.
|
vehicle_is_hidden | [0 | 1] | No | Value is 1 if the vehicle is hidden in a depot or tunnel. |
vehicle_is_stopped | [0 | 1] | No | Value is 1 if the vehicle is stopped, or if it is braking for a stop (trains only). |
vehicle_is_crashed | [0 | 1] | No | Value is 1 if the vehicle has crashed. |
vehicle_is_broken | [0 | 1] | No | Value is 1 if the vehicle is broken down. |
date_of_last_service | date(year, month, day) | No | |
breakdowns_since_last_service | 0 ... 255 | No | Number of breakdowns since the last service |
reliability | 0 ... 100 | No | Reliability (percentage) |
age_in_days | 0 ... 65535 | No | Vehicle age in days. |
max_age_in_days | 0 ... 65535 | No | Maximum vehicle age in days. |
current_speed | (speed units) | No | The current speed of the vehicle in m/s |
max_speed | (speed units) | No | The maximum speed of the vehicle in m/s |
current_max_speed | (speed units) | No | NML 0.3 1.3 Current maximum speed of the vehicle in m/s. This includes e.g. track or timetable limits. Only valid for front vehicle. |
vehicle_is_in_depot | [0 | 1] | No | Value is 1 if the vehicle is inside a depot |
vehicle_is_unloading | [0 | 1] | No | 1.5 2.5 Value is 1 if the vehicle is unloading at a station and has not yet started loading new cargo. |
Variables that require an argument
name | Argument | value range | available in purchase list? |
comment | ||
---|---|---|---|---|---|---|
count_veh_id | The vehicle ID to look for. | 0..255 | No | The number of vehicles in the current consist that have the given ID. | ||
other_veh_curv_info | Offset in the chain from the current vehicle.[1] | -4..4 | No | Difference in direction between the other vehicle and this vehicle. Curvature to the right is positive. 1 unit is 45 degrees. | ||
other_veh_is_hidden | Offset in the chain from the current vehicle.[1] | [0 | 1] | No | 1 the other vehicle is hidden in a depot or tunnel, 0 otherwise | ||
other_veh_x_offset | Offset in the chain from the current vehicle.[1] | -128..127 | No | Signed difference in X-position (top-right to bottom-left) between the other vehicle and this vehicle. | ||
other_veh_y_offset | Offset in the chain from the current vehicle.[1] | -128..127 | No | Signed difference in Y-position (top-left to bottom-right) between the other vehicle and this vehicle. | ||
other_veh_z_offset | Offset in the chain from the current vehicle.[1] | -128..127 | No | Signed difference in Z-position (upwards) between the other vehicle and this vehicle. | ||
tile_supports_railtype | Entry from railtype translation table | [0 | 1] | No | Vehicles of the railtype used as parameter are compatible with the track on the current tile. Example: tile_supports_railtype(ELRL)
| ||
tile_powers_railtype | tile_powers_roadtype | tile_powers_tramtype | Entry from rail/road/tram translation table | [0 | 1] | No | Vehicles of the type label used as parameter are powered on the track on the current tile. Example: tile_powers_railtype(ELRL)
|
tile_is_railtype | Entry from railtype translation table | [0 | 1] | No | The railtype used as parameter is identical or equivalent (listed as alternate label in rail-/road-/tram-type property 1D) to the track on the current tile. Example: tile_is_railtype(ELRL)
|
Vehicle callbacks
The following table contains a list of available vehicle callbacks. Additionally, it's possible to provide cargo-specific graphics, using the identifier from the cargo table as callback name. These callbacks will be used if the vehicle is refitted to the corresponding cargo type. If no cargo-specific graphics match the cargo that the vehicle is carrying, the default
callback is used instead. Cargo-specific graphics callbacks are never called from the purchase menu, refer to the purchase
callback below instead.
Note that the above affects graphics only, other callbacks are unaffected.
Name | Available for | In purchase menu? | value range | comment |
---|---|---|---|---|
default | All | Yes, unless purchase is set separately
|
Sprite group | 'Normal' vehicle graphics, if no cargo-specific graphics apply. See also the section on GUI sprites. |
purchase | All | Yes, only | Sprite group | Graphics to show in the buy menu (only the horizontal view is needed, except for dual-headed trains. With the dual_headed property set, special rules for the purchase menu sprite apply: two sprites are drawn (for front and back) as if the vehicle is normally constructed. If you supply one purchase menu sprite, it will be used for both vehicle parts in the purchase menu. Provide a set of 8 sprites, and the 7th resp. 3rd sprite will be drawn; provide a set of 8 blank sprites except the 7th if you want to fully control a single purchase menu sprite for a dual-headed engine. ) See also the section on GUI sprites.
|
rotor | Aircraft (helicopters) | No | Sprite group | Graphics for the helicopter rotor (4 sprites; 1 stopped and 3 moving) |
random_trigger | All | No | N/A | See random switch for more information. |
cargo_subtype_text | All | No | String, or CB_RESULT_NO_TEXT | With this callback, you can display extra text after the cargo in the vehicle information window. This callback is called during refitting, with succesively increased values of the cargo_subtype variable, until the callback returns CB_RESULT_NO_TEXT. All returned strings are then displayed as refit options. The chosen refit option is saved in the cargo_subtype variable, so it can be used later for other things. In the HEQS grf for example, this mechanism is used to let the user choose between different capacities of the same vehicle.
|
additional_text | All | Yes, only | String | Additional text to show in the purchase list. |
colour_mapping | All | Yes, unless purchase_colour_mapping is set separately
|
Recolour sprite number |
With this callback, you can use a different recolour sprite instead of the standard 1cc / 2cc company colour remappings. See here for a list of default palettes. See the builtin function |
start_stop | All | No | String or CB_RESULT_NO_TEXT | Called when starting or stopping a vehicle. Mainly useful to prevent vehicles from leaving the depot unless a certain condition is met. Return CB_RESULT_NO_TEXT to allow or a string (containing an error message) to disallow starting/stopping. |
every_32_days | All | No | bitmask(CB_RESULT_32_DAYS_XXX, ...) | Called every 32 days. Set CB_RESULT_32_DAYS_TRIGGER in the bitmask to trigger TRIGGER_VEHICLE_32_CALLBACK. Set CB_RESULT_32_DAYS_COLOUR_MAPPING in the bitmask to update the colour mapping by re-running the colour_mapping callback.
|
sound_effect | All | No | SOUND_XXX, sound("sound.wav"), import_sound(grfid, number) or CB_RESULT_NO_SOUND |
Called to play various vehicle sounds.
Return SOUND_XXX (see here) to return a default sound. |
articulated_part | Trains, Road Vehicles | Yes (no separate callback) | Vehicle ID, or CB_RESULT_NO_MORE_ARTICULATED_PARTS | With this callback, you can add articulated parts (e.g. tenders) to your vehicle. Called repeatedly, until CB_RESULT_NO_MORE_ARTICULATED_PARTS is returned. After each call, the returned vehicleID is added to your vehicle.
Note that callback may be called from the purchase list, using vehicle variables is not possible. Or CB_RESULT_REVERSED_VEHICLE to the returned vehicle ID to display the vehicle backwards. For NML 0.2 and lower the vehicle ID of the articulated part must be in the range 0 .. 127. |
can_attach_wagon | Trains | No | String or CB_RESULT_ATTACH_XXX | Called when a wagon is being attached, to allow or disallow attaching. If a wagon is inserted in the middle, all wagons are removed and attached one-by-one in the new order. This callback has to be defined at the engine. The scopes behave different than usual though:
Return a string to disallow with the string as error message. Return CB_RESULT_ATTACH_DISALLOW to disallow with standard message ("incompatible railtypes"), CB_RESULT_ATTACH_ALLOW to allow or CB_RESULT_ATTACH_ALLOW_IF_RAILTYPES to allow if the railtypes match (default). |
refit_cost | 1.2 All | Yes | -8192 .. 8191 as refit cost. Add CB_RESULT_AUTOREFIT if you want to allow autorefit.
|
When returning a negative value, encode the cost as (cost & CB_RESULT_REFIT_COST_MASK ) before (possibly) adding CB_RESULT_AUTOREFIT . To allow autorefitting, the corresponding bit in the misc_flags must be set as well.
Note that this callback may also be called when the vehicle does not exist yet, so the available variables are limited. |
create_effect | 1.5 Trains, Road Vehicles, Ships | No | 0 .. 3 for number of effects. Optionally add CB_RESULT_CREATE_EFFECT_CENTER and/or CB_RESULT_CREATE_EFFECT_NO_ROTATION
|
Called when a effect spawning model is defined via effect_spawn_model resp. effect_spawn_model_and_powered .
The result specifies how many effects shall be created. The position and appearance of the individual effects is returned via registers 0x100 to 0x103: switch (FEAT_XXX, SELF, switch_name, [ STORE_TEMP(create_effect(EFFECT_SPRITE_XXX, 8, -3, 10), 0x100), // first effect, STORE_TEMP(create_effect(EFFECT_SPRITE_YYY, 8, 3, 10), 0x101) // second effect, ... ]) { return 2; // number of effects } The register values are created using the
Additional to the number of effects, the callback result may specify these flags:
|
The following callbacks all have an equivalent property. The property description applies here also, except where otherwise noted.
Name | Available for | In purchase menu? | comment |
---|---|---|---|
loading_speed | All | No | |
speed | All | Yes, unless purchase_speed is set separately
|
Units are not (yet) available |
cost_factor | All | Yes, only | |
running_cost_factor | All | Yes, unless purchase_running_cost_factor is set separately
|
|
cargo_age_period | All | No | |
cargo_capacity | All except aircraft | Yes, unless purchase_cargo_capacity is set separately
|
|
passenger_capacity | Aircraft | Yes, unless purchase_passenger_capacity is set separately
|
|
mail_capacity | Aircraft | Yes, unless purchase_mail_capacity is set separately
|
|
range | Aircraft | Yes, unless purchase_range is set separately
|
|
visual_effect_and_powered | Trains | No | |
visual_effect | Road Vehicles, Ships | No | |
effect_spawn_model_and_powered | Trains | No | |
effect_spawn_model | Road Vehicles, Ships | No | |
power | Trains, Road Vehicles | Yes, unless purchase_power is set separately
|
Units are not (yet) available |
weight | Trains, Road Vehicles | Yes, unless purchase_weight is set separately
|
Units are not (yet) available |
length | Trains, Road vehicles | No | |
tractive_effort_coefficient | Trains, Road Vehicles | Yes, unless purchase_tractive_effort_coefficient is set separately
|
Value range is 0 .. 255 instead of 0 .. 1. |
bitmask_vehicle_info | Trains | No |
Sprites in GUI
1.2 Since OpenTTD r23080 you can use variable getbits(extra_callback_info1, 0, 8)
to display different sprites in the GUI and on the map. Currently these cases are available:
getbits(extra_callback_info1, 0, 8) | Meaning |
---|---|
0x00 | Vehicle is drawn in a viewport, i.e. on the map. |
0x01..0x0F | reserved |
0x10 | Vehicle is drawn in the depot GUI. [1] |
0x11 | Vehicle is drawn in the vehicle details GUI. (This includes the refit GUI.) |
0x12 | Vehicle is drawn in the vehicle list. |
0x13..0x1F | reserved for other future GUIs. |
0x20 | Vehicle is drawn in the purchase list. (This includes the autoreplace GUI.) |
0x21 | Vehicle is drawn in the exclusive preview GUI or in the advertisement news. |
0x22..0x2F | reserved for other future GUIs with non-purchased vehicles. |
0x30..0xFF | reserved |
- ↑ OpenTTD also uses this value with the purchase-list chain (cargotype FF) to determine the gridsize in ship and aircraft depots.
The cases 0x20..0x2F are called using the purchase
-callback, the other cases are called for the default
- or cargo-specific callbacks. Exception is the the special depot-gridsize call, which uses the purchase
-callback.
Composing vehicles from multiple sprites
1.7 Since OpenTTD r27668 you can draw vehicles by drawing multiple sprites on top of each other.
- The sprites can use different recolouring.
- When using 32bpp sprites, the sprites can use the alpha channel to blend with the other sprites. In particular you can use this to alpha-blend company colours over other sprites.
To enable this, you need to set XXX_FLAG_SPRITE_STACK
in the misc_flags
property.
When enabled, sprites are resolved multiple times while incrementing an iteration number, that can be read via
getbits(extra_callback_info1, 8, 8)
Currently this is limited to at most 4 sprites per articulated part.
In addition you need to set register 100 as additional result:
STORE_TEMP(CB_FLAG_MORE_SPRITES | recolouring, 0x100)
if there are more sprites to draw.STORE_TEMP(recolouring, 0x100)
if there are no more sprites to draw.
"recolouring" can be:
PALETTE_USE_DEFAULT
to use the default vehicle recolouring.PALETTE_IDENTITY
to use no recolouring- Any other default or custom recolouring sprite.
Sound events
Event | Description |
---|---|
SOUND_EVENT_START | Vehicle leaves station or depot, plane takes off |
SOUND_EVENT_TUNNEL | Vehicle enters tunnel |
SOUND_EVENT_BREAKDOWN | Vehicle breaks down (not for planes) |
SOUND_EVENT_RUNNING | Once per engine tick, but no more than once per vehicle motion |
SOUND_EVENT_TOUCHDOWN | Aircraft touches down |
SOUND_EVENT_VISUAL_EFFECT | Visual effect is generated (steam plume, diesel smoke, electric spark) |
SOUND_EVENT_RUNNING_16 | Every 16 engine ticks if in motion |
SOUND_EVENT_STOPPED | Every 16 engine ticks if stopped |
SOUND_EVENT_LOAD_UNLOAD | Consist loads or unloads cargo |
Vehicle IDs
Picking an item ID requires keeping two cases in mind: OpenTTD with the engine pool enabled and OpenTTD with engine pool disabled / TTDPatch. The status of the engine pool may be checked with the global variable dynamic_engines.
Note that while vehicle ID affects the order in which vehicles appear in the purchase menu, this can be overridden using the sort block.
Engine pool enabled
With the engine pool enabled, each NewGRF has its own ID range, NewGRFs don't influence each other. IDs may freely be chosen between 0 and 65535. If the chosen ID belongs to an existing vehicle, this vehicle is overridden by your vehicle. If another NewGRF is already overriding that vehicle, a new vehicle will be allocated, but all the properties will be copied from the old vehicle. If you define an ID for which no original vehicle exists, a new (blank) vehicle is allocated.
This behaviour can be modified using an engine_override, this allows changing the properties of vehicles defined in other NewGRFs instead of allocating a new vehicle.
TTDPatch / Engine pool disabled
Each new vehicle has to replace an existing vehicle. If multiple NewGRFs try to replace the same vehicle, the last NewGRF loaded 'wins'. This page contains a list of valid vehicle IDs for each vehicle type, look in the 'NML ID' column. Note that IDs are not bound to a specific sort of vehicle (e.g. monorail wagons) but to a feature (e.g. trains, road vehicles).
In general, you should take the following steps:
- If your NewGRF is intended as a complete replacement for the default vehicles, disable the relevant default vehicles using disable_item.
- Re-use IDs of existing vehicles as much as possible.
- If your NewGRF uses IDs outside of the normal range (for example, because you there are more vehicles than slots available), let your code check if dynamic_engies is enabled. If not, skip the vehicles outside the normal range (using an if-statement) and make sure that the remaining vehicles allow for reasonable gameplay. It is recommended to issue a warning to the user about this. Alternatively, it is also possible to disable your entire NewGRF. If you don't do this check and dynamic_engines is off, OpenTTD may disable your NewGRF with the somewhat cryptic message 'Attempt to use invalid ID', which will likely lead to bug reports about your NewGRF and/or your OpenTTD.