Difference between revisions of "VariationalAction2/Vehicles"

From GRFSpecs
Jump to navigationJump to search
(Fix style and format.)
m (Position within articulated vehicle section was labelled with incorrect variable number 4B, instead of 4D)
 
(46 intermediate revisions by 9 users not shown)
Line 1: Line 1:
  +
<div style="float:right; padding-left:12px; background:none;">{{NFONavVehicles}}</div>
  +
 
==Introduction==
 
==Introduction==
   
==List of variables==
+
== Variables ==
   
 
{|
 
{|
  +
!Variable!![[GRFActionsDetailed|Size]]!!Version!!Description!!Available in purchase list
|Variable
 
  +
|-
|[[GRFActionsDetailed|'''Size''']]||Content||Available in purchase list
 
  +
|10||D||{{ottdp|1.2|no|ottdrev=r23080}}||Pick sprites for different GUI windows - See [[Action2/Vehicles]].||{{ottdp|1.2|no|ottdrev=r23080}}
|+
 
  +
|-
|40||D||Position in consist and length of consist||no
 
  +
|40||D||{{ottdp|0.6|2.5}}||Position in consist and length of consist||no
|+
 
  +
|-
|41||D||Position in and length of chain of consecutive vehicles with same ID||no
 
  +
|41||D||{{ottdp|0.6|2.5}}||Position in and length of chain of consecutive vehicles with same ID||no
|+
 
  +
|-
|42||D||Cargo types transported by consist||no
 
  +
|42||D||{{ottdp|0.6|2.5}}||Cargo types transported by consist||no
|+
 
  +
|-
|43||D||Player info||TTDP 2.5 beta 2, OTTD r4611
 
  +
|43||D||{{ottdp|0.6|2.5}}||Player info||{{ottdp|0.6|2.5|ottdrev=r4611|ttdprev=beta 2}}
|+
 
  +
|-
|44||D||Aircraft info||no
 
  +
|44||D||{{ottdp|0.6|2.5|ttdprev=2.0.1 alpha 48}}||Aircraft info||no
|+
 
  +
|-
|45||D||Curvature info||no
 
  +
|45||D||{{ottdp|0.6|2.5|ttdprev=2.0.1 alpha 58}}||Curvature info||no
|+
 
  +
|-
|46||D||Motion counter||no
 
  +
|46||D||{{ottdp|0.6|2.5|ttdprev=2.0.1 alpha 59}}||Motion counter||no
|+
 
  +
|-
|47||D||Vehicle cargo info||(b) OTTD r15542
 
  +
|47||D||{{ottdp|0.6|2.5}}||Vehicle cargo info||{{ottdp|0.7|no|ottdrev=r15542}} <ref name="var47">Variable 47 refers to the default cargo of the vehicle, when in purchase list. This differs from the cargo used in Action 3, which is 0xFF in purchase list. The "refit cycle" (F2) is currently always zero in the purchase list.</ref>
|+
 
  +
|-
|48||D||Vehicle type information||TTDP 2.5 beta 2, OTTD r5338
 
  +
|48||D||{{ottdp|0.6|2.5}}||Vehicle type information||{{ottdp|0.6|2.5|ottdrev=r5338|ttdprev=beta 2}}
|+
 
  +
|-
|49 (a)||D||Year of construction (long format, 0 based)||(c) OTTD r13376
 
  +
|49||D||{{ottdp|0.7|2.6|ottdrev=r13376|ttdprev=r2216}}||Year of construction (long format, 0 based)||{{ottdp|0.7|no|ottdrev=r13376}} <ref name="date">This is the current date</ref>
|+
 
  +
|-
|4A (d)||D||Info about current rail type for trains||no
 
  +
|4A||D||{{ottdp|1.1|no|ottdrev=r20165}}||Info about current railtype/roadtype/tramtype||no
|+
 
  +
|-
|60||D||Count Veh.ID occurence||no
 
  +
|4B||D||{{ottdp|1.2|no|ottdrev=r23068}}||Long date of last servicing||{{ottdp|1.2|no|ottdrev=r23068}} <ref name="date" />
|+
 
  +
|-
|97||B||Tick counter, increased every engine tick||no
 
  +
|4C||D||{{ottdp|1.3|no|ottdrev=r24246}}||Current max speed including e.g track or timetable speed limits. Only valid for front vehicle. Note, units differ for each vehicle type<ref name="speed">See [[Action0Trains#Speed 09|train property 09]], [[Action0RoadVehicles|road vehicle property 08]] (not 15, even when using realistic acceleration), [[Action0Ships|ship property 0B]] and [[Action0Planes|aircraft property 0C]].</ref>||no
|+
 
  +
|-
|B4||W||Current speed. Note, units differ for each vehicle type (e).||no
 
  +
|4D||D||{{ottdp|1.4|no|ottdrev=r26157}}||Position within articulated vehicle||no
|+
 
  +
|-
|B9||B||Cargo type (type B from the list at [[CargoTypes]]; climate dependent)||no
 
  +
|60||D||{{ottdp|0.6|2.5|ttdprev=2.0.1 alpha 57}}||Count Veh.ID occurence||no
|+
 
  +
|-
|C0||W||Vehicle age in days (not valid for wagons bought before alpha 61)||no
 
  +
|61||-<ref>The size of the result matches the size of the queried variable.</ref>||{{ottdp|1.2|no|ottdrev=r22997}}||Query variable of n-th vehicle in chain||no
|+
 
  +
|-
|C4||B||Year built (counted from 1920), note this is modified when Cht: Year is used||(c) OpenTTD r4611
 
  +
|62||D||{{ottdp|1.2|no|ottdrev=r22998}}||Curvature/position difference for n-th vehicle in chain||no
|+
 
  +
|-
|C6||W||Vehicle type ID (useful for [[Callbacks#Can_wagon_be_attached_1D_|Callback 1D]])||no
 
  +
|63||D||{{ottdp|1.11|no|ottdrev=g868d84bbf}}||Test track-type of tile against another track-type||no
|+
 
  +
|-
|C8||B||Sprite type; FD for trains forward, FE or FF when reversed||no
 
  +
|97||B||{{ottdp|0.6|2.0}}||Tick counter, increased every engine tick||no
|+
 
  +
|-
|C9||B||Day counter; increased daily||no
 
  +
|B2||W||||Vehicle status: bit0 = vehicle invisible (in tunnel/depot), bit1 = stopped, bit7 = crashed||no
|+
 
  +
|-
|DA||W||Next wagon index, FFFF if last wagon (use shift-num=08 and check for FF)||no
 
  +
|B4||W||{{ottdp|0.6|2.0}}||Current speed. Note, units differ for each vehicle type<ref name="speed" />||no
|+
 
  +
|-
|F2||B||Refit cycle, how many times refitted to the same cargo type||(b) OpenTTD r15542
 
  +
|B9||B||{{ottdp|0.6|2.0}}||Cargo type (type B from the list at [[CargoTypes]]; climate dependent)||no
|+
 
  +
|-
|FE||W||Modflags||no
 
  +
|C0||W||{{ottdp|0.6|2.0}}||Engine age in days<br/>{{ottdp|1.2|2.5|ottdrev=r22816|ttdprev=alpha 61}} Valid for wagons and articulated parts as well.||no
|+
 
  +
|-
|FF||B||Modflags||no
 
  +
|C4||B||{{ottdp|0.6|2.0}}||Year built (counted from 1920), note this is modified when Cht: Year is used||{{ottdp|0.6|no|ottdrev=r4611}} <ref name="date" />
  +
|-
  +
|C6||W||{{ottdp|0.6|2.0}}||Vehicle type ID <ref>{{ottdp|0.7|no}} In OpenTTD 0.7 and newer this is the GRF-local ID of the vehicle. Earlier versions of OpenTTD and TTDPatch report the [[VehicleIDs|TTD ID]]. For trains this is the same; for other vehicle types they differ.</ref> (useful for [[Callbacks#Can wagon be attached (1D)|Callback 1D]])||no
  +
|-
  +
|C8||B||{{ottdp|0.6|2.0}}||Sprite type; FD for trains forward, FE or FF when reversed||no
  +
|-
  +
|C9||B||{{ottdp|0.6|2.0}}||Day counter; increased daily||no
  +
|-
  +
|DA||W||{{ottdp|0.6|2.0}}||Next wagon index, FFFF if last wagon (use shift-num=08 and check for FF)||no
  +
|-
  +
|F2||B||{{ottdp|0.6|2.5}}||Refit cycle, how many times refitted to the same cargo type||{{ottdp|0.7|no|ottdrev=r15542}} <ref name="var47" />
  +
|-
  +
|FE||W||{{ottdp|0.6|2.5}}||Modflags||no
  +
|-
  +
|FF||B||{{ottdp|0.6|2.5}}||Modflags||no
 
|}
 
|}
   
  +
<references />
(a) OpenTTD r13376, TTDPatch r2216
 
 
(b) Variable 47 refers to the default cargo of the vehicle, when in purchase list. This differs from the cargo used in Action 3, which is 0xFF in purchase list. The &quot;refit cycle&quot; (F2) is currently always zero in the purchase list.
 
 
(c) This is the current date.
 
 
(d) OpenTTD r20165.
 
 
(e) See [[Action0Trains#Speed_09_|train property 09]], [[Action0RoadVehicles|road vehicle property 08]] (not 15, even when using realistic acceleration), [[Action0Ships|ship property 0B]] and [[Action0Planes|aircraft property 0C]].
 
   
For other 80+x variables confer the [http://marcin.ttdpatch.net/sv1codec/TTD-locations.html#_VehicleArray|TTD vehicle structure].
+
For other 80+x variables confer the [http://marcin.ttdpatch.net/sv1codec/TTD-locations.html#_VehicleArray TTD vehicle structure].
   
 
Variables 40, 41, 42 and 43 are cached. This means that while they are in principle computationally expensive, they can be used without impacting performance. Variables 45 and 60 are also computationally expensive but cannot be cached, and should therefore be used sparingly. If possible 80+x variables are to be preferred.
 
Variables 40, 41, 42 and 43 are cached. This means that while they are in principle computationally expensive, they can be used without impacting performance. Variables 45 and 60 are also computationally expensive but cannot be cached, and should therefore be used sparingly. If possible 80+x variables are to be preferred.
Line 74: Line 83:
 
In the purchase list only a few variables are available. Especially the front vehicle (related object) cannot be accessed, nor other articulated parts.
 
In the purchase list only a few variables are available. Especially the front vehicle (related object) cannot be accessed, nor other articulated parts.
   
==Description==
+
== Description ==
===Position and length (40, 41)===
+
=== Position and length (40, 41) ===
   
 
'''Format:''' 00nnbbff
 
'''Format:''' 00nnbbff
Line 86: Line 95:
 
|bb||same as ff, but counted from the end, i.e. the last wagon has bb=0, the next-to-last wagon has bb=1 etc.
 
|bb||same as ff, but counted from the end, i.e. the last wagon has bb=0, the next-to-last wagon has bb=1 etc.
 
|-
 
|-
|nn||total number of vehicles in the consist minus one (i.e. a train with engine and three wagons has nn=3), including shadow and rotor for aircraft.
+
|nn||Total number of vehicles in the consist, including shadow and rotor for aircraft.
  +
* In var 40 this is zero-based. That is, the value returned is one less than the actual number of vehicles. A train with engine and three wagons has nn=3.
  +
* In var 41 this is one-based. That is, the value returned is the actual number of vehicles.
 
|}
 
|}
   
 
For variable 40, these numbers refer to the whole consist, but for variable 41, they only refer to the chain of consecutive vehicles with the same ID as the current wagon (including itself, but possibly excluding the engine):
 
For variable 40, these numbers refer to the whole consist, but for variable 41, they only refer to the chain of consecutive vehicles with the same ID as the current wagon (including itself, but possibly excluding the engine):
   
  +
[[File:vehicle_var40_41.png]]
Note however, that accessing the &quot;related&quot; object (i.e. the locomotive) doesn&acute;t make much sense for vars 40/41, except for var40 when in a [[Callbacks#Can_wagon_be_attached_1D_|callback 1D]] chain.
 
   
  +
Note however, that accessing the "related" object (i.e. the locomotive) doesn´t make much sense for vars 40/41, except for var40 when in a [[Callbacks#Can wagon be attached 1D|callback 1D]] chain.
===Consist cargo (42)===
 
  +
  +
=== Consist cargo (42) ===
   
 
'''Format:''' uuiicctt
 
'''Format:''' uuiicctt
Line 100: Line 113:
 
!Variable!!Value
 
!Variable!!Value
 
|-
 
|-
|tt||a bit mask of all [[Action0Cargos#Cargo_classes_16_|cargo classes]] transported by the consist
+
|tt||a bit mask of all [[Action0Cargos#Cargo classes 16|cargo classes]] transported by the consist
 
|-
 
|-
 
|cc||the most common [[CargoTypes|cargo type]] (from the column for type A)
 
|cc||the most common [[CargoTypes|cargo type]] (from the column for type A)
Line 109: Line 122:
 
|}
 
|}
   
  +
If used with VarAction2 type 81 (vehicle) it returns only cargo from this vehicle on, with type 82 (engine) that of the whole consist.
Note that even if the grf file has installed a [[Action0GeneralVariables#Cargo+translation+table+%2809%29|cargo translation table]], the value in &quot;cc&quot; is the actual bit number of that cargo. The reason for this is that it cannot be translated in general, because different vehicles can be from different .grf files and have different translation tables. Use variable 47 if you want the translated cargo type.
 
  +
See also variable 47 for more details on the cargo carried by a vehicle.
   
  +
{{grfTill|7}} For GRF versions 7 and before "cc" is the untranslated bit number from [[Action0/Cargos#Bit_number_for_bitmasks_.2808.29|cargo property 8]].
If used with variational action 2 type 81 (vehicle) it returns only cargo from this vehicle on, with type 82 (engine) that of the whole consist.
 
   
  +
{{grfFrom|8}} With GRF version 8 the meaning of "cc" changes. If the grf file has installed a [[Action0/Global_Settings#Cargo_translation_table_.2809.29|cargo translation table]], the value in "cc" is the index of the cargo in that table; or FF if the cargo is not present in the table.
===Player info (43)===
 
  +
  +
=== Player info (43) ===
   
 
'''Format:''' Ccttmmnn
 
'''Format:''' Ccttmmnn
Line 128: Line 144:
 
|c||the primary player colour
 
|c||the primary player colour
 
|-
 
|-
|C||the secondary player colour, equal to c if none (since r1405)
+
|C||{{ottdp|0.6|2.5|ttdprev=r1405}} the secondary player colour, equal to c if none (since r1405)
 
|}
 
|}
   
Line 139: Line 155:
 
|1||Player is AI player (not managed)
 
|1||Player is AI player (not managed)
 
|-
 
|-
|2||Player is a human managing an AI company
+
|2||{{ottdp|no|2.5}} Player is a human managing an AI company
 
|-
 
|-
|3||Player is human player's original company, now temporarily AI controlled
+
|3||{{ottdp|no|2.5}} Player is human player's original company, now temporarily AI controlled
 
|}
 
|}
   
  +
{{ottdp|0.6|2.5|ttdprev=r1497}} Since r1497, when the vehicle sprite is being displayed in an exclusive offer window or new vehicle news message, or in other circumstances when no player is associated with the vehicle, nn will be FF.
This variable is available in the purchase list as well (since 2.5 beta 2).
 
   
  +
=== Aircraft info (44) ===
Since r1497, when the vehicle sprite is being displayed in an exclusive offer window or new vehicle news message, or in other circumstances when no player is associated with the vehicle, nn will be FF.
 
 
===Aircraft info (44)===
 
   
 
'''Format:''' xxxxhhtt
 
'''Format:''' xxxxhhtt
   
  +
hh is the height of the aircraft above ground, or more properly above the height of its shadow. Buildings, including the heliport, don't count as "ground", i.e. to get the height above a heliport, you have to subtract the heliport height from hh.
(available from 2.0.1 alpha 48)
 
 
hh is the height of the aircraft above ground, or more properly above the height of its shadow. Buildings, including the heliport, don't count as &quot;ground&quot;, i.e. to get the height above a heliport, you have to subtract the heliport height from hh.
 
   
 
tt is the type of the current airport: 0=small, 1=large, 2=heliport, 3=oil rig. The current airport is the target airport for aircraft that have finished the ascent and are in flight.
 
tt is the type of the current airport: 0=small, 1=large, 2=heliport, 3=oil rig. The current airport is the target airport for aircraft that have finished the ascent and are in flight.
   
===Curvature info (45)===
+
=== Curvature info (45) ===
   
 
'''Format:''' xxxTxBxF
 
'''Format:''' xxxTxBxF
 
(available from 2.0.1 alpha 58)
 
   
 
This returns the amount of curvature between the adjacent wagon pairs. It is useful for train vehicles that normally tilt in curves. The curvature is the difference in direction between the surrounding vehicles:
 
This returns the amount of curvature between the adjacent wagon pairs. It is useful for train vehicles that normally tilt in curves. The curvature is the difference in direction between the surrounding vehicles:
Line 177: Line 187:
 
!Decimal!!Hex!!Meaning
 
!Decimal!!Hex!!Meaning
 
|-
 
|-
|-4||C||180&deg; curve left (T only)
+
| -4||C||180° curve left (T only)
 
|-
 
|-
|-3||D||135&deg; curve left (T only)
+
| -3||D||135° curve left (T only)
 
|-
 
|-
|-2||E||90&deg; curve left
+
| -2||E||90° curve left
 
|-
 
|-
|-1||F||45&deg; curve left
+
| -1||F||45° curve left
 
|-
 
|-
 
|0||0||no curve
 
|0||0||no curve
 
|-
 
|-
|1||1||45&deg; curve right
+
|1||1||45° curve right
 
|-
 
|-
|2||2||90&deg; curve right
+
|2||2||90° curve right
 
|-
 
|-
|3||3||135&deg; curve right (T only)
+
|3||3||135° curve right (T only)
 
|-
 
|-
|4||4||180&deg; curve right (T only)
+
|4||4||180° curve right (T only)
 
|}
 
|}
   
===Motion counter (46)===
+
=== Motion counter (46) ===
   
 
'''Format:''' 32-bit value
 
'''Format:''' 32-bit value
   
  +
This variable counts the amount of motion that a vehicle has done. &nbsp;It is only valid for the first vehicle in a consist (i.e. use VarAction2 type 82!). &nbsp;Its value is in units of 1/4096 of a tile. &nbsp;A vehicle actually moves visibly every time the motion counter increases by 256, and since a tile consists of 16 such subunits, 16*256=4096 motion units mean motion across one tile.
(available from 2.0.1 alpha 59)
 
 
This variable counts the amount of motion that a vehicle has done. &nbsp;It is only valid for the first vehicle in a consist (i.e. use var.action 2 type 82!). &nbsp;Its value is in units of 1/4096 of a tile. &nbsp;A vehicle actually moves visibly every time the motion counter increases by 256, and since a tile consists of 16 such subunits, 16*256=4096 motion units mean motion across one tile.
 
   
 
The most useful way to access it is probably with &lt;shiftnum&gt;=08 and an appropriate &lt;andmask&gt;. &nbsp;For example, to achieve an animation with one frame per vehicle motion and 16 frames in total for motion across an entire tile, you would use &lt;shiftnum&gt;=08 and &lt;andmask&gt;=0F. &nbsp;For an animation with one frame every two vehicle motions and 4 frames total, use &lt;shiftnum&gt;=09 and &lt;andmask&gt;=03.
 
The most useful way to access it is probably with &lt;shiftnum&gt;=08 and an appropriate &lt;andmask&gt;. &nbsp;For example, to achieve an animation with one frame per vehicle motion and 16 frames in total for motion across an entire tile, you would use &lt;shiftnum&gt;=08 and &lt;andmask&gt;=0F. &nbsp;For an animation with one frame every two vehicle motions and 4 frames total, use &lt;shiftnum&gt;=09 and &lt;andmask&gt;=03.
Line 210: Line 218:
 
Note that vehicle graphics are only updated every time the vehicle actually moves, so checking the lower byte is probably pointless, and only needed internally to achieve sufficient precision.
 
Note that vehicle graphics are only updated every time the vehicle actually moves, so checking the lower byte is probably pointless, and only needed internally to achieve sufficient precision.
   
===Vehicle cargo info (47)===
+
=== Vehicle cargo info (47) ===
   
 
'''Format:''' ccccwwtt
 
'''Format:''' ccccwwtt
Line 219: Line 227:
 
|tt||the [[CargoTypes|cargo type]] transported by the vehicle (from the column for type A); translated if a translation table has been installed
 
|tt||the [[CargoTypes|cargo type]] transported by the vehicle (from the column for type A); translated if a translation table has been installed
 
|-
 
|-
|ww||cargo unit weight in 1/16 tons, same as [[Action0Cargos#Weight_of_one_unit_of_the_cargo_0F_|cargo prop. 0F]]
+
|ww||cargo unit weight in 1/16 tons, same as [[Action0Cargos#Weight of one unit of the cargo 0F|cargo prop. 0F]]
 
|-
 
|-
|cccc||the [[Action0Cargos#Cargo_classes_16_|cargo class]] value of the cargo transported by the vehicle
+
|cccc||the [[Action0Cargos#Cargo classes 16|cargo class]] value of the cargo transported by the vehicle
 
|}
 
|}
  +
|-
 
|Note that if the grf has installed a [[Action0GeneralVariables#Cargo_translation_table_09_|cargo translation table]], the value in &quot;tt&quot; is the slot number in that table, irrespective of which actual slot or bit the cargo is using in the game. If a table has been installed, but the current cargo is not listed there, &quot;tt&quot; will be set to FF.
+
Note that if the grf has installed a [[Action0/Global_Settings#Cargo_translation_table_.2809.29|cargo translation table]], the value in "tt" is the slot number in that table, irrespective of which actual slot or bit the cargo is using in the game. If a table has been installed, but the current cargo is not listed there, "tt" will be set to FF.
   
 
Unlike variable 42, this variable returns the info of the current vehicle only, not the consist.
 
Unlike variable 42, this variable returns the info of the current vehicle only, not the consist.
   
===Vehicle type information (48)===
+
=== Vehicle type information (48) ===
   
 
'''Format:''' xxxxxxff
 
'''Format:''' xxxxxxff
Line 246: Line 254:
 
All other bits in ff are undefined and must be masked out.
 
All other bits in ff are undefined and must be masked out.
   
  +
=== Information about current railtype/roadtype/tramtype (4A) ===
This variable is available in the purchase list as well (since 2.5 beta 2).
 
 
===Information about current rail type for trains (4A)===
 
   
 
'''Format:''' xxxxFFrr
 
'''Format:''' xxxxFFrr
   
  +
The lower byte (rr) contains the (translated) railtype/roadtype/tramtype the vehicle is currently driving on.
(available from OpenTTD r20165)
 
  +
If the railtype/roadtype/tramtype has no entry in the railtype/roadtype/tramtype translation table of the GRF, this value will be 0xFF.
  +
If no translation table is present, the raw value will be returned.
  +
Note: only exact matches of rail-/road-/-tram-types are reported. If the translation table of the GRF does not contain the exact track-type 0xFF is returned, even if the translation table contains equivalent track-types (according to rail-/road-/tram-type property 1D). Use variable 63 to test for compatibility/poweredness/equivalency with track-types known to both the vehicle and the track-type NewGRF.
   
The lower byte (rr) contains the (translated) rail type the train vehicle is currently driving on. If the rail type has no entry in the rail type translation table of the GRF, this value will be 0xFF. If no translation table is present, the raw value will be returned.
+
The variable only reports about the tracks the vehicle is using: on a level crossing with rail, road and tram tracks, the vehicle (train, road vehicle, tram) can only query the track type it belongs to.
   
The next byte (FF) contains the following flags:
+
The second byte (FF) contains the following flags:
   
 
{| |-
 
{| |-
 
!Bit!!Value!!Meaning
 
!Bit!!Value!!Meaning
 
|-
 
|-
|0||1||The vehicle is/would be powered on the current rail type (this is independent from powered/non-powered wagon or anything)
+
|0||1||The vehicle is/would be powered on the current railtype (this is independent from powered/non-powered wagon or anything)
  +
|-
  +
|1||2||{{ottdp|1.11|no|ottdrev=gf1bc4d840}} Set, if the track-type has catenary. This is independent of the vehicle: a NewGRF can define an engine as powered on non-electrified track (bit 0), and show a raised pantograph (bit 1) to look like a dual-powered engine. This bit is a simplified as it only checks for "some catenary". To distinguish different types of catenaries, AC and DC voltages, ... use variable 63 instead.
 
|}
 
|}
   
All other bits are undefined.
+
All other bits are reserved, and must be masked.
   
All other bytes and the result for non-rail vehicles are undefined.
+
All other bytes are reserved, and must be masked.
   
===Count Veh.ID occurence (60)===
+
=== Position within articulated vehicle (4D) ===
  +
  +
'''Format:''' xxxxbbff
  +
  +
{| |-
  +
!Variable!!Value
  +
|-
  +
|ff||Position of vehicle (articulated part) within the articulated vehicle, counted from the first part, starting with 0.
  +
|-
  +
|bb||Position of vehicle (articulated part) within the articulated vehicle, counted from the last part, starting with 0.
  +
|-
  +
|xx||Reserved, do not access.
  +
|}
  +
  +
The total number of articulated parts of a vehicle equals ff + 1 + bb.
  +
  +
For road vehicles "ff" and "bb" currently equal var 40, since there are no road vehicle wagons yet.
  +
  +
=== Count Veh.ID occurence (60) ===
   
 
'''Format:''' xxxxxxnn
 
'''Format:''' xxxxxxnn
   
  +
The 60+x parameter is the vehicle ID to look for, and the returned nn is the number of vehicles in the consist that have this ID. If used with VarAction2 type 81, only the current vehicle and onwards will be check, with VarAction2 type 82, all vehicles in the consist will be counted.
(available from 2.0.1 alpha 57)
 
   
  +
=== Query variable of n-th vehicle in chain (61) ===
The 60+x parameter is the vehicle ID to look for, and the returned nn is the number of vehicles in the consist that have this ID. If used with var.action 2 type 81, only the current vehicle and onwards will be check, with var.action 2 type 82, all vehicles in the consist will be counted.
 
   
  +
This is a special variable to get the contents of another variable of a different vehicle in the vehicle chain. It is only supported for trains and road vehicles. It is not supported during a callback that is used to modify vehicle properties to avoid circular dependencies, which currently limits this variable to callbacks 1D, 2D, 31 and 32 plus outside callback scope.
===Modflags (FE and FF)===
 
   
  +
Temporary register 10F is interpreted as a signed integer and specifies the offset in the chain from the current vehicle. Positive values are interpreted as towards the end, negative values as towards the front. If the offset is outside the vehicle chain, the result value will be 0.
The bits in FE mostly relate to gradualloading. &nbsp;A few useful bits for grf authors are;
 
   
  +
The 60+x parameter specifies the variable to access and temporary register 10E is passed as the new 60+x parameter. Passing 61 as the variable is not allowed. Currently only vehicle specific variables listed on this page plus global variable 25 and {{ottdp|1.3|no|ottdrev=r24527}} 5F are accessible through var 61.
  +
  +
The resulting value will have the size of whatever variable is queried.
  +
  +
=== Curvature/position difference for n-th vehicle in chain (62) ===
  +
  +
'''Format:''' zzyyxxFD
  +
  +
This variable is only supported for trains and road vehicles.
  +
  +
The 60+x parameter is interpreted as a signed integer and specifies the offset in the chain from the current vehicle. Positive values are interpreted as towards the end, negative values as towards the front. If the offset is outside the vehicle chain, the result value will be 0.
  +
  +
The lowest nibble (D) contains the direction difference between the selected vehicle and this vehicle, the possible values are identical to those of [[#Curvature_info_.2845.29|variable 45]].
  +
  +
The next nibble (F) has the following meaning:
 
{| |-
 
{| |-
!Bit!!Value of the bit
+
!Bit!!Value!!Meaning
 
|-
 
|-
  +
|3||8||The vehicle is currently hidden
|5||Vehicle is powered (engine or powered wagon, mainly useful for the latter)
 
  +
|}
  +
  +
The upper three bytes contain the signed difference of the X/Y/Z position between the selected vehicle and this vehicle.
  +
  +
=== Track-type test against another track-type (63) ===
  +
  +
{{ottdp|1.11|no|ottdrev=g868d84bbf}}
  +
  +
'''Format:''' xxxxxxFF
  +
  +
This variable is only supported for trains and road vehicles.
  +
  +
The 60+x parameter is an index into the rail-/road-/tram-type translation table.
  +
The result value reports how vehicles of this type would behave on the current tile.
  +
This allows vehicles to behave or look differently on various track-types independent of their own track-type.
  +
  +
The lower byte (FF) contains some flags:
  +
{|
 
|-
 
|-
  +
!Bit!!Value!!Meaning
|6||Vehicle would be powered (engine or powered wagon) if there were suitable track. (E.g. electric train in mixed train on normal track)
 
 
|-
 
|-
  +
|0||1||The track-type from the 60+x parameter is known. If unset, all other flags are unset as well, no information can be given.
|8 *||This bit is flipped every time the train reverses direction
 
 
|-
 
|-
  +
|1||2||Vehicles with type from the 60+x parameter are compatible with the track on the current tile.
|10||Vehicle was built during the exclusive preview (since 2.5 r1334)
 
  +
|-
  +
|2||4||Vehicles with type from the 60+x parameter are powered on the track of the current tile.
  +
|-
  +
|3||8||The track-type from the 60+x parameter is identical or equivalent (listed as alternate label in rail-/road-/tram-type property 1D) to the track-type of the current tile.
 
|}
 
|}
   
  +
The remaining bytes are reserved, and must be masked.
<nowiki>*</nowiki> This bit is only accurate for the first vehicle in the consist.
 
  +
  +
=== Modflags (FE and FF) ===
  +
  +
The bits in FE mostly relate to gradualloading. &nbsp;A few useful bits for grf authors are;
  +
  +
{| |-
  +
!Bit!!Version!!Value of the bit
  +
|-
  +
|1||{{ottdp|1.5|2.5|ottdrev=r26430}}||Vehicle is still unloading and has not yet started loading new cargo at the current station.
  +
|-
  +
|5||{{ottdp|0.6|2.5}}||Vehicle is powered (engine or powered wagon, mainly useful for the latter)
  +
|-
  +
|6||{{ottdp|0.6|2.5}}||Vehicle would be powered (engine or powered wagon) if there were suitable track. (E.g. electric train in mixed train on normal track)
  +
|-
  +
|8 <ref>This bit is only accurate for the first vehicle in the consist.</ref>||{{ottdp|0.6|2.5}}||This bit is flipped every time the train reverses direction
  +
|-
  +
|10||{{ottdp|0.6|2.5|ttdprev=r1334}}||Vehicle was built during the exclusive preview
  +
|}
  +
<references/>
   
 
variable FF is actually the high byte of variable FE, so FE bit 8 is the same as FF bit 0.
 
variable FF is actually the high byte of variable FE, so FE bit 8 is the same as FF bit 0.
  +
  +
Other bits are reserved; most are actually used for TTDPatch internal states.
   
 
==Examples==
 
==Examples==

Latest revision as of 18:37, 1 September 2021

Introduction

Variables

Variable Size Version Description Available in purchase list
10 D Supported by OpenTTD 1.2 (r23080)1.2 Not supported by TTDPatch Pick sprites for different GUI windows - See Action2/Vehicles. Supported by OpenTTD 1.2 (r23080)1.2 Not supported by TTDPatch
40 D Supported by OpenTTD 0.60.6 Supported by TTDPatch 2.52.5 Position in consist and length of consist no
41 D Supported by OpenTTD 0.60.6 Supported by TTDPatch 2.52.5 Position in and length of chain of consecutive vehicles with same ID no
42 D Supported by OpenTTD 0.60.6 Supported by TTDPatch 2.52.5 Cargo types transported by consist no
43 D Supported by OpenTTD 0.60.6 Supported by TTDPatch 2.52.5 Player info Supported by OpenTTD 0.6 (r4611)0.6 Supported by TTDPatch 2.5 (beta 2)2.5
44 D Supported by OpenTTD 0.60.6 Supported by TTDPatch 2.5 (2.0.1 alpha 48)2.5 Aircraft info no
45 D Supported by OpenTTD 0.60.6 Supported by TTDPatch 2.5 (2.0.1 alpha 58)2.5 Curvature info no
46 D Supported by OpenTTD 0.60.6 Supported by TTDPatch 2.5 (2.0.1 alpha 59)2.5 Motion counter no
47 D Supported by OpenTTD 0.60.6 Supported by TTDPatch 2.52.5 Vehicle cargo info Supported by OpenTTD 0.7 (r15542)0.7 Not supported by TTDPatch [1]
48 D Supported by OpenTTD 0.60.6 Supported by TTDPatch 2.52.5 Vehicle type information Supported by OpenTTD 0.6 (r5338)0.6 Supported by TTDPatch 2.5 (beta 2)2.5
49 D Supported by OpenTTD 0.7 (r13376)0.7 Supported by TTDPatch 2.6 (r2216)2.6 Year of construction (long format, 0 based) Supported by OpenTTD 0.7 (r13376)0.7 Not supported by TTDPatch [2]
4A D Supported by OpenTTD 1.1 (r20165)1.1 Not supported by TTDPatch Info about current railtype/roadtype/tramtype no
4B D Supported by OpenTTD 1.2 (r23068)1.2 Not supported by TTDPatch Long date of last servicing Supported by OpenTTD 1.2 (r23068)1.2 Not supported by TTDPatch [2]
4C D Supported by OpenTTD 1.3 (r24246)1.3 Not supported by TTDPatch Current max speed including e.g track or timetable speed limits. Only valid for front vehicle. Note, units differ for each vehicle type[3] no
4D D Supported by OpenTTD 1.4 (r26157)1.4 Not supported by TTDPatch Position within articulated vehicle no
60 D Supported by OpenTTD 0.60.6 Supported by TTDPatch 2.5 (2.0.1 alpha 57)2.5 Count Veh.ID occurence no
61 -[4] Supported by OpenTTD 1.2 (r22997)1.2 Not supported by TTDPatch Query variable of n-th vehicle in chain no
62 D Supported by OpenTTD 1.2 (r22998)1.2 Not supported by TTDPatch Curvature/position difference for n-th vehicle in chain no
63 D Supported by OpenTTD 1.11 (g868d84bbf)1.11 Not supported by TTDPatch Test track-type of tile against another track-type no
97 B Supported by OpenTTD 0.60.6 Supported by TTDPatch 2.02.0 Tick counter, increased every engine tick no
B2 W Vehicle status: bit0 = vehicle invisible (in tunnel/depot), bit1 = stopped, bit7 = crashed no
B4 W Supported by OpenTTD 0.60.6 Supported by TTDPatch 2.02.0 Current speed. Note, units differ for each vehicle type[3] no
B9 B Supported by OpenTTD 0.60.6 Supported by TTDPatch 2.02.0 Cargo type (type B from the list at CargoTypes; climate dependent) no
C0 W Supported by OpenTTD 0.60.6 Supported by TTDPatch 2.02.0 Engine age in days
Supported by OpenTTD 1.2 (r22816)1.2 Supported by TTDPatch 2.5 (alpha 61)2.5 Valid for wagons and articulated parts as well.
no
C4 B Supported by OpenTTD 0.60.6 Supported by TTDPatch 2.02.0 Year built (counted from 1920), note this is modified when Cht: Year is used Supported by OpenTTD 0.6 (r4611)0.6 Not supported by TTDPatch [2]
C6 W Supported by OpenTTD 0.60.6 Supported by TTDPatch 2.02.0 Vehicle type ID [5] (useful for Callback 1D) no
C8 B Supported by OpenTTD 0.60.6 Supported by TTDPatch 2.02.0 Sprite type; FD for trains forward, FE or FF when reversed no
C9 B Supported by OpenTTD 0.60.6 Supported by TTDPatch 2.02.0 Day counter; increased daily no
DA W Supported by OpenTTD 0.60.6 Supported by TTDPatch 2.02.0 Next wagon index, FFFF if last wagon (use shift-num=08 and check for FF) no
F2 B Supported by OpenTTD 0.60.6 Supported by TTDPatch 2.52.5 Refit cycle, how many times refitted to the same cargo type Supported by OpenTTD 0.7 (r15542)0.7 Not supported by TTDPatch [1]
FE W Supported by OpenTTD 0.60.6 Supported by TTDPatch 2.52.5 Modflags no
FF B Supported by OpenTTD 0.60.6 Supported by TTDPatch 2.52.5 Modflags no
  1. 1.0 1.1 Variable 47 refers to the default cargo of the vehicle, when in purchase list. This differs from the cargo used in Action 3, which is 0xFF in purchase list. The "refit cycle" (F2) is currently always zero in the purchase list.
  2. 2.0 2.1 2.2 This is the current date
  3. 3.0 3.1 See train property 09, road vehicle property 08 (not 15, even when using realistic acceleration), ship property 0B and aircraft property 0C.
  4. The size of the result matches the size of the queried variable.
  5. Supported by OpenTTD 0.70.7 Not supported by TTDPatch In OpenTTD 0.7 and newer this is the GRF-local ID of the vehicle. Earlier versions of OpenTTD and TTDPatch report the TTD ID. For trains this is the same; for other vehicle types they differ.

For other 80+x variables confer the TTD vehicle structure.

Variables 40, 41, 42 and 43 are cached. This means that while they are in principle computationally expensive, they can be used without impacting performance. Variables 45 and 60 are also computationally expensive but cannot be cached, and should therefore be used sparingly. If possible 80+x variables are to be preferred.

Cached variables are updated when the game is loaded, when the consist enters or is rearranged in a depot, and when the train reverses.

In the purchase list only a few variables are available. Especially the front vehicle (related object) cannot be accessed, nor other articulated parts.

Description

Position and length (40, 41)

Format: 00nnbbff

Variable Value
ff position of vehicle within the consist counted from the engine (front), e.g. the engine would have ff=0, the 1st wagon or mail compartment of planes would have ff=1, the 2nd wagon or the rotor of helicopters would have ff=2, the 3rd wagon would have ff=3 etc
bb same as ff, but counted from the end, i.e. the last wagon has bb=0, the next-to-last wagon has bb=1 etc.
nn Total number of vehicles in the consist, including shadow and rotor for aircraft.
  • In var 40 this is zero-based. That is, the value returned is one less than the actual number of vehicles. A train with engine and three wagons has nn=3.
  • In var 41 this is one-based. That is, the value returned is the actual number of vehicles.

For variable 40, these numbers refer to the whole consist, but for variable 41, they only refer to the chain of consecutive vehicles with the same ID as the current wagon (including itself, but possibly excluding the engine):

Vehicle var40 41.png

Note however, that accessing the "related" object (i.e. the locomotive) doesn´t make much sense for vars 40/41, except for var40 when in a callback 1D chain.

Consist cargo (42)

Format: uuiicctt

Variable Value
tt a bit mask of all cargo classes transported by the consist
cc the most common cargo type (from the column for type A)
ii the most common refit cycle (var. F2) of cargo type cc
uu the result of ORing the bits of prop. 25 from all vehicles in the train

If used with VarAction2 type 81 (vehicle) it returns only cargo from this vehicle on, with type 82 (engine) that of the whole consist. See also variable 47 for more details on the cargo carried by a vehicle.

GRFv≤7 For GRF versions 7 and before "cc" is the untranslated bit number from cargo property 8.

GRFv≥8 With GRF version 8 the meaning of "cc" changes. If the grf file has installed a cargo translation table, the value in "cc" is the index of the cargo in that table; or FF if the cargo is not present in the table.

Player info (43)

Format: Ccttmmnn

Variable Value
nn the number of the current player from 0 to 7 (up to E (14) in OpenTTD since r14735)
mm the multiplayer player number with the host player (or the single player) being 0 and the client player being 1
tt the player type, see below for possible values
c the primary player colour
C Supported by OpenTTD 0.60.6 Supported by TTDPatch 2.5 (r1405)2.5 the secondary player colour, equal to c if none (since r1405)


tt value Meaning
0 Player is human player (permanent company)
1 Player is AI player (not managed)
2 Not supported by OpenTTD Supported by TTDPatch 2.52.5 Player is a human managing an AI company
3 Not supported by OpenTTD Supported by TTDPatch 2.52.5 Player is human player's original company, now temporarily AI controlled

Supported by OpenTTD 0.60.6 Supported by TTDPatch 2.5 (r1497)2.5 Since r1497, when the vehicle sprite is being displayed in an exclusive offer window or new vehicle news message, or in other circumstances when no player is associated with the vehicle, nn will be FF.

Aircraft info (44)

Format: xxxxhhtt

hh is the height of the aircraft above ground, or more properly above the height of its shadow. Buildings, including the heliport, don't count as "ground", i.e. to get the height above a heliport, you have to subtract the heliport height from hh.

tt is the type of the current airport: 0=small, 1=large, 2=heliport, 3=oil rig. The current airport is the target airport for aircraft that have finished the ascent and are in flight.

Curvature info (45)

Format: xxxTxBxF

This returns the amount of curvature between the adjacent wagon pairs. It is useful for train vehicles that normally tilt in curves. The curvature is the difference in direction between the surrounding vehicles:

F = for the front pair (previous wagon to current wagon, 0 if vehicle is first)

B = for the back pair (current wagon to next wagon, 0 if wagon is last)

T = for the triplet (previous wagon to next wagon; is zero in an S-bend)

Possible values:

Decimal Hex Meaning
-4 C 180° curve left (T only)
-3 D 135° curve left (T only)
-2 E 90° curve left
-1 F 45° curve left
0 0 no curve
1 1 45° curve right
2 2 90° curve right
3 3 135° curve right (T only)
4 4 180° curve right (T only)

Motion counter (46)

Format: 32-bit value

This variable counts the amount of motion that a vehicle has done.  It is only valid for the first vehicle in a consist (i.e. use VarAction2 type 82!).  Its value is in units of 1/4096 of a tile.  A vehicle actually moves visibly every time the motion counter increases by 256, and since a tile consists of 16 such subunits, 16*256=4096 motion units mean motion across one tile.

The most useful way to access it is probably with <shiftnum>=08 and an appropriate <andmask>.  For example, to achieve an animation with one frame per vehicle motion and 16 frames in total for motion across an entire tile, you would use <shiftnum>=08 and <andmask>=0F.  For an animation with one frame every two vehicle motions and 4 frames total, use <shiftnum>=09 and <andmask>=03.

If the vehicle is going very fast (>160 mph for trains), it may move by several 1/16ths of a tile at once, and thus some frames may be skipped, but the animation will still remain in sync with the motion.

Note that vehicle graphics are only updated every time the vehicle actually moves, so checking the lower byte is probably pointless, and only needed internally to achieve sufficient precision.

Vehicle cargo info (47)

Format: ccccwwtt

Variable Value
tt the cargo type transported by the vehicle (from the column for type A); translated if a translation table has been installed
ww cargo unit weight in 1/16 tons, same as cargo prop. 0F
cccc the cargo class value of the cargo transported by the vehicle

Note that if the grf has installed a cargo translation table, the value in "tt" is the slot number in that table, irrespective of which actual slot or bit the cargo is using in the game. If a table has been installed, but the current cargo is not listed there, "tt" will be set to FF.

Unlike variable 42, this variable returns the info of the current vehicle only, not the consist.

Vehicle type information (48)

Format: xxxxxxff

The bits of ff are:

Bit Value Meaning
0 1 Vehicle type is available on the market
1 2 Vehicle type is in the testing phase
2 4 Exclusive testing offer for a human player active

All other bits in ff are undefined and must be masked out.

Information about current railtype/roadtype/tramtype (4A)

Format: xxxxFFrr

The lower byte (rr) contains the (translated) railtype/roadtype/tramtype the vehicle is currently driving on. If the railtype/roadtype/tramtype has no entry in the railtype/roadtype/tramtype translation table of the GRF, this value will be 0xFF. If no translation table is present, the raw value will be returned. Note: only exact matches of rail-/road-/-tram-types are reported. If the translation table of the GRF does not contain the exact track-type 0xFF is returned, even if the translation table contains equivalent track-types (according to rail-/road-/tram-type property 1D). Use variable 63 to test for compatibility/poweredness/equivalency with track-types known to both the vehicle and the track-type NewGRF.

The variable only reports about the tracks the vehicle is using: on a level crossing with rail, road and tram tracks, the vehicle (train, road vehicle, tram) can only query the track type it belongs to.

The second byte (FF) contains the following flags:

Bit Value Meaning
0 1 The vehicle is/would be powered on the current railtype (this is independent from powered/non-powered wagon or anything)
1 2 Supported by OpenTTD 1.11 (gf1bc4d840)1.11 Not supported by TTDPatch Set, if the track-type has catenary. This is independent of the vehicle: a NewGRF can define an engine as powered on non-electrified track (bit 0), and show a raised pantograph (bit 1) to look like a dual-powered engine. This bit is a simplified as it only checks for "some catenary". To distinguish different types of catenaries, AC and DC voltages, ... use variable 63 instead.

All other bits are reserved, and must be masked.

All other bytes are reserved, and must be masked.

Position within articulated vehicle (4D)

Format: xxxxbbff

Variable Value
ff Position of vehicle (articulated part) within the articulated vehicle, counted from the first part, starting with 0.
bb Position of vehicle (articulated part) within the articulated vehicle, counted from the last part, starting with 0.
xx Reserved, do not access.

The total number of articulated parts of a vehicle equals ff + 1 + bb.

For road vehicles "ff" and "bb" currently equal var 40, since there are no road vehicle wagons yet.

Count Veh.ID occurence (60)

Format: xxxxxxnn

The 60+x parameter is the vehicle ID to look for, and the returned nn is the number of vehicles in the consist that have this ID. If used with VarAction2 type 81, only the current vehicle and onwards will be check, with VarAction2 type 82, all vehicles in the consist will be counted.

Query variable of n-th vehicle in chain (61)

This is a special variable to get the contents of another variable of a different vehicle in the vehicle chain. It is only supported for trains and road vehicles. It is not supported during a callback that is used to modify vehicle properties to avoid circular dependencies, which currently limits this variable to callbacks 1D, 2D, 31 and 32 plus outside callback scope.

Temporary register 10F is interpreted as a signed integer and specifies the offset in the chain from the current vehicle. Positive values are interpreted as towards the end, negative values as towards the front. If the offset is outside the vehicle chain, the result value will be 0.

The 60+x parameter specifies the variable to access and temporary register 10E is passed as the new 60+x parameter. Passing 61 as the variable is not allowed. Currently only vehicle specific variables listed on this page plus global variable 25 and Supported by OpenTTD 1.3 (r24527)1.3 Not supported by TTDPatch 5F are accessible through var 61.

The resulting value will have the size of whatever variable is queried.

Curvature/position difference for n-th vehicle in chain (62)

Format: zzyyxxFD

This variable is only supported for trains and road vehicles.

The 60+x parameter is interpreted as a signed integer and specifies the offset in the chain from the current vehicle. Positive values are interpreted as towards the end, negative values as towards the front. If the offset is outside the vehicle chain, the result value will be 0.

The lowest nibble (D) contains the direction difference between the selected vehicle and this vehicle, the possible values are identical to those of variable 45.

The next nibble (F) has the following meaning:

Bit Value Meaning
3 8 The vehicle is currently hidden

The upper three bytes contain the signed difference of the X/Y/Z position between the selected vehicle and this vehicle.

Track-type test against another track-type (63)

Supported by OpenTTD 1.11 (g868d84bbf)1.11 Not supported by TTDPatch

Format: xxxxxxFF

This variable is only supported for trains and road vehicles.

The 60+x parameter is an index into the rail-/road-/tram-type translation table. The result value reports how vehicles of this type would behave on the current tile. This allows vehicles to behave or look differently on various track-types independent of their own track-type.

The lower byte (FF) contains some flags:

Bit Value Meaning
0 1 The track-type from the 60+x parameter is known. If unset, all other flags are unset as well, no information can be given.
1 2 Vehicles with type from the 60+x parameter are compatible with the track on the current tile.
2 4 Vehicles with type from the 60+x parameter are powered on the track of the current tile.
3 8 The track-type from the 60+x parameter is identical or equivalent (listed as alternate label in rail-/road-/tram-type property 1D) to the track-type of the current tile.

The remaining bytes are reserved, and must be masked.

Modflags (FE and FF)

The bits in FE mostly relate to gradualloading.  A few useful bits for grf authors are;

Bit Version Value of the bit
1 Supported by OpenTTD 1.5 (r26430)1.5 Supported by TTDPatch 2.52.5 Vehicle is still unloading and has not yet started loading new cargo at the current station.
5 Supported by OpenTTD 0.60.6 Supported by TTDPatch 2.52.5 Vehicle is powered (engine or powered wagon, mainly useful for the latter)
6 Supported by OpenTTD 0.60.6 Supported by TTDPatch 2.52.5 Vehicle would be powered (engine or powered wagon) if there were suitable track. (E.g. electric train in mixed train on normal track)
8 [1] Supported by OpenTTD 0.60.6 Supported by TTDPatch 2.52.5 This bit is flipped every time the train reverses direction
10 Supported by OpenTTD 0.60.6 Supported by TTDPatch 2.5 (r1334)2.5 Vehicle was built during the exclusive preview
  1. This bit is only accurate for the first vehicle in the consist.

variable FF is actually the high byte of variable FE, so FE bit 8 is the same as FF bit 0.

Other bits are reserved; most are actually used for TTDPatch internal states.

Examples