Difference between revisions of "VariationalAction2/Vehicles"

From GRFSpecs
Jump to navigationJump to search
(→‎Variables: references and version info beautified)
m (→‎Variables: partially broken link)
Line 57: Line 57:
 
<references />
 
<references />
   
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.

Revision as of 10:27, 1 August 2011

Introduction

Variables

Variable Version Size Description Available in purchase list
40 D Supported by OpenTTD Supported by TTDPatch Position in consist and length of consist no
41 D Supported by OpenTTD Supported by TTDPatch Position in and length of chain of consecutive vehicles with same ID no
42 D Supported by OpenTTD Supported by TTDPatch Cargo types transported by consist no
43 D Supported by OpenTTD 0.60.6 Player info Supported by OpenTTD 0.6 (r4611)0.6 Supported by TTDPatch 2.5 (beta 2)2.5
44 D Supported by OpenTTD Supported by TTDPatch Aircraft info no
45 D Supported by OpenTTD Supported by TTDPatch Curvature info no
46 D Supported by OpenTTD Supported by TTDPatch Motion counter no
47 D Supported by OpenTTD Supported by TTDPatch 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 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 rail type for trains no
60 D Supported by OpenTTD Supported by TTDPatch Count Veh.ID occurence no
97 B Supported by OpenTTD Supported by TTDPatch Tick counter, increased every engine tick no
B4 W Supported by OpenTTD Supported by TTDPatch Current speed. Note, units differ for each vehicle type[3] no
B9 B Supported by OpenTTD Supported by TTDPatch Cargo type (type B from the list at CargoTypes; climate dependent) no
C0 W Supported by OpenTTD Supported by TTDPatch Vehicle age in days (not valid for wagons bought before alpha 61) no
C4 B Supported by OpenTTD 0.60.6 Supported by TTDPatch Year built (counted from 1920), note this is modified when Cht: Year is used Supported by OpenTTD 0.6 (r4611)0.6 Supported by TTDPatch[2]
C6 W Supported by OpenTTD Supported by TTDPatch Vehicle type ID (useful for Callback 1D) no
C8 B Supported by OpenTTD Supported by TTDPatch Sprite type; FD for trains forward, FE or FF when reversed no
C9 B Supported by OpenTTD Supported by TTDPatch Day counter; increased daily no
DA W Supported by OpenTTD Supported by TTDPatch Next wagon index, FFFF if last wagon (use shift-num=08 and check for FF) no
F2 B Supported by OpenTTD Supported by TTDPatch 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 Supported by TTDPatch Modflags no
FF B Supported by OpenTTD Supported by TTDPatch 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 This is the current date
  3. See train property 09, road vehicle property 08 (not 15, even when using realistic acceleration), ship property 0B and aircraft property 0C.

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 minus one (i.e. a train with engine and three wagons has nn=3), including shadow and rotor for aircraft.

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

Note that even if the grf file has installed a cargo translation table, the value in "cc" 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.

If used with VarAction2 type 81 (vehicle) it returns only cargo from this vehicle on, with type 82 (engine) that of the whole consist.

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 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 Player is a human managing an AI company
3 Player is human player's original company, now temporarily AI controlled

This variable is available in the purchase list as well (since TTDPatch 2.5 beta 2).

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

(available from TTDPatch 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 "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

(available from TTDPatch 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:

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

(available from TTDPatch 2.0.1 alpha 59)

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.

This variable is available in the purchase list as well (since TTDPatch 2.5 beta 2).

Information about current rail type for trains (4A)

Format: xxxxFFrr

(available from OpenTTD r20165)

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 next byte (FF) contains the following flags:

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)

All other bits are undefined.

All other bytes and the result for non-rail vehicles are undefined.

Count Veh.ID occurence (60)

Format: xxxxxxnn

(available from TTDPatch 2.0.1 alpha 57)

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.

Modflags (FE and FF)

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

Bit Value of the bit
5 Vehicle is powered (engine or powered wagon, mainly useful for the latter)
6 Vehicle would be powered (engine or powered wagon) if there were suitable track. (E.g. electric train in mixed train on normal track)
8 * This bit is flipped every time the train reverses direction
10 Vehicle was built during the exclusive preview (since TTDPatch 2.5 r1334)

* 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.

Examples