Difference between revisions of "VariationalAction2/Industries"

From GRFSpecs
Jump to navigationJump to search
m (fix order of sections)
Line 188: Line 188:
   
 
In case 1, you can check variable A7 to find out whether the industry was funded by a player or by the random generator.
 
In case 1, you can check variable A7 to find out whether the industry was funded by a player or by the random generator.
 
==Example==
 

Revision as of 14:28, 22 December 2018

Introduction

Variables

Variable Size Version Description
40..42 Supported by OpenTTD Supported by TTDPatch Waiting cargo. See also variable 6F.
43 Supported by OpenTTD Supported by TTDPatch 2.6 (r1298)2.6 Manhattan distance of closest dry/land tile
44 Supported by OpenTTD Supported by TTDPatch 2.6 (r1594)2.6 Layout number (1-based)
45 Supported by OpenTTD Supported by TTDPatch 2.6 (r1711)2.6 Player info
46 Supported by OpenTTD 0.7 (r13443)0.7 Supported by TTDPatch 2.6 (r2047)2.6 Date when industry was built in days since year 0
60 Supported by OpenTTD Supported by TTDPatch 2.5 (alpha 73)2.5 Get industry tile ID at offset
61 Supported by OpenTTD Supported by TTDPatch 2.5 (alpha 73)2.5 Get random tile bits at offset
62 Supported by OpenTTD Supported by TTDPatch 2.5 (alpha 74)2.5 Land info of nearby tiles
63 Supported by OpenTTD Supported by TTDPatch Animation stage of nearby tiles
64 Supported by OpenTTD Supported by TTDPatch Distance of nearest industry with given type
65 Supported by OpenTTD Supported by TTDPatch Get town zone and Manhattan distance of closest town
66 Supported by OpenTTD Supported by TTDPatch Get square of Euclidean distance of closest town
67 Supported by OpenTTD Supported by TTDPatch Count of industry, distance of closest instance
68 Supported by OpenTTD Supported by TTDPatch Like the above, but with layout filter
69 Supported by OpenTTD 1.9 (e66cec8f)1.9 Not supported by TTDPatch Amount of produced output cargo waiting to be distributed.
6A Supported by OpenTTD 1.9 (e66cec8f)1.9 Not supported by TTDPatch Amount of cargo produced this month (so far).
6B Supported by OpenTTD 1.9 (e66cec8f)1.9 Not supported by TTDPatch Amount of cargo transported this month (so far).
6C Supported by OpenTTD 1.9 (e66cec8f)1.9 Not supported by TTDPatch Amount of cargo produced last month.
6D Supported by OpenTTD 1.9 (e66cec8f)1.9 Not supported by TTDPatch Amount of cargo transported last month.
6E Supported by OpenTTD 1.9 (e66cec8f)1.9 Not supported by TTDPatch Date since cargo was delivered last. (in days since year 0)
6F Supported by OpenTTD 1.9 (e66cec8f)1.9 Not supported by TTDPatch Amount of waiting cargo to be processed.
8A W Supported by OpenTTD Supported by TTDPatch Amount of produced output cargo waiting to be distributed, for the first output cargo. See also variable 69.
8C W Supported by OpenTTD Supported by TTDPatch Amount of produced output cargo waiting to be distributed, for the 2nd output cargo. See also variable 69.
93 B Supported by OpenTTD Supported by TTDPatch Production level. Normally between 4 and 128, default starting level is 16. A level of 0 means imminent closure.
94 W Supported by OpenTTD Supported by TTDPatch Production this month of first output cargo. See also variable 6A.
96 W Supported by OpenTTD Supported by TTDPatch Production this month of 2nd output cargo. See also variable 6A.
98 W Supported by OpenTTD Supported by TTDPatch Amount of cargo transported this month of the first output cargo. See also variable 6B.
9A W Supported by OpenTTD Supported by TTDPatch Amount of cargo transported this month of the 2nd output cargo. See also variable 6B.
9C B Supported by OpenTTD Supported by TTDPatch Fraction of cargo transported last month of the first output cargo
9D B Supported by OpenTTD Supported by TTDPatch Fraction of cargo transported last month of the 2nd output cargo
9E W Supported by OpenTTD Supported by TTDPatch Production last month of the first output cargo. See also variable 6C.
A0 W Supported by OpenTTD Supported by TTDPatch Production last month of the 2nd output cargo. See also variable 6C.
A2 W Supported by OpenTTD Supported by TTDPatch Amount of cargo transported last month of the first output cargo. See also variable 6D.
A4 W Supported by OpenTTD Supported by TTDPatch Amount of cargo transported last month of the 2nd output cargo. See also variable 6D.
A7 B Supported by OpenTTD Supported by TTDPatch 2.5 (alpha 74)2.5 Industry founder information
A8 B Supported by OpenTTD Supported by TTDPatch Random (company) colour, chosen during construction
B0 W Supported by OpenTTD Supported by TTDPatch Date when industry was built in days since 1920
B3 B Supported by OpenTTD Supported by TTDPatch Construction type
B4 W Supported by OpenTTD Supported by TTDPatch 2.6 (r1321)2.6 Date when cargo was last accepted in days since 1920, or 0 if no cargo was ever accepted. See also variable 6E.

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

Waiting cargo (40..42)

If bit 1 or 2 is set in property 21, these variables contain the amount of incoming cargo waiting to be processed. (40 gives the amount of the first type waiting, 41 gives the same for the second type etc.) These variables are capped at FFFFh (65535).

See also variable 6F.

Manhattan distance of closest dry/land tile (43)

This variable works the same way as var. 8B does during callback 28: if your industry is built on water, it gives the distance of the closest dry land tile, otherwise it gives the distance of the closest water tile. However, you can't use this variable during callback 28; you must always use 8B.

PLEASE NOTE: This variable is rather expensive to compute because, in the worst case, it has to check all tiles on the map before it gives up looking for a good tile. Try to avoid it in frequent callbacks such as the production callback, animation callbacks (unless the animation is slow, around 1 frame per game day or slower). It is, however, OK to use it during the production change callbacks.

Layout number (44)

T his variable returns the number of the current layout. The first layout will return 01, the second 02, etc. In other words, this is one larger than what you get in variable 86 during callback 28.

If the industry was created using an earlier version of TTDPatch, or while newindustries was off, the result will be zero.

Player info (45)

As vehicle variable 43, except that the no-player state is indicated by var A7 being 10h.

Date when industry was built in days since year 0 (46)

Exact same behaviour as var B0, but based on year 0, instead of year 1920

In TTDPatch, industry age is limited to 65535 days (approximately 180 years) -- build date is never more than 65535 days ago.

Get industry tile ID at offset (60)

The parameter of this variable is an offset from the northernmost tile of the industry: the high nibble contains the Y offset, the low one the X offset; both are unsigned. The high word of the return value is currently reserved, and the low word can be:

  • 00xxh if the tile is an industry tile and was defined in the current GRF with ID xx.
  • FFxxh if the tile is an industry tile of an old type, and has the ID xx.
  • FFFEh if the tile is an industry tile that was defined in another GRF file
  • FFFFh if the tile isn't an industry tile, or doesn't belong to the current industry

Get random tile bits at offset (61)

The parameter of this variable is an offset from the northernmost tile of the industry: the high nibble contains the Y offset, the low one the X offset; both are unsigned. If there's an industry tile on that offset and it belongs to the current industry, the lowest byte of the return value will contain the random bits of that tile. Otherwise, the lowest byte will be zero.

The other bytes are reserved for future use.

Land info of nearby tiles (62)

The parameter of this variable is an offset from the northernmost tile of the industry: the high nibble contains the Y offset, the low one the X offset; both are unsigned. This variable returns the same values as industry tile variable 60, in the same format, except that bit 0 in the bb part is undefined. The offset should be given relatively to the north corner of the industry.

Animation stage of nearby tiles (63)

The parameter of this variable is an offset from the northernmost tile of the industry: the high nibble contains the Y offset, the low one the X offset; both are unsigned. This variable returns the same values as industry tile variable 61, in the same format. The offset should be given relatively to the north corner of the industry.

Distance of nearest industry with given type (64)

The format of the parameter is the same as for industry property 16: either the ID of a new type with bit 7 set, or the ID of an old type. The returned value is FFFFFFFFh if there are no industries with the given type (not counting the current one, if it has the given type); otherwise, the returned value is the Manhattan distance of the closest industry with the given type.

Get town zone and Manhattan distance of closest town (65)

The parameter gives an offset from the northernmost tile of the industry: the high nibble means the Y offset, the low nibble means the X offset, both signed. The returned value is rrzzdddd, where rr is reserved for future use, zz is the town zone of the selected tile, while dddd is the Manhattan distance of the closest town.

Get square of Euclidean distance of closest town (66)

The parameter works like for var. 65, but the result is the Euclidean distance of the closest town, squared.

Count of industry, distance of closest instance (67, 68)

Variable 67 gets two parameters: the GRFID of the GRF where the industry is defined in register 100h (can be written using operator 0E of VarAction2) and the setID of the industry as the regular parameter. There are two special cases for the GRFID: 00000000h means you're checking for a default TTD industry type, while FFFFFFFFh can be used instead of the GRFID of the current GRF.

The return value has the format rrccdddd, where rr is reserved for future use, cc is the number of instances of the industry type and dddd is the Manhattan distance of the closest instance, of FFFFh if not appliable.

You may note that this variable can be used instead of variable 64. This variable is the preferred way to get this information since it allows you to check industries defined in other GRFs as well. Variable 64 will stay for backward compatibility only.

Variable 68 works like variable 67, except that you can put a layout number in the lowest byte of register 101. (The other bits are reserved for future use, leave them zero for now.) This layout number should be 1-based (the first layout is 01, not 00). Only industries with the given layout are considered for counting and calculating distance. As a special case, if the layout number is 00, all layouts are counted, and so the result is the same as with variable 67.

Since OpenTTD r22434, it is possible to filter by the town of the current industry. If the bit number 8 is set, only industries in the same town than the current one will be considered.

Cargo info variables (69..6F)

Supported by OpenTTD 1.9 (e66cec8f)1.9 Not supported by TTDPatch

These variables allow to query information about accepted and produced cargos. The variables are independent of the number of cargo types and their order. The 60+x parameter specifies the cargo type as index into the cargo translation table.

Industry founder information (A7)

This byte contains the ID of the company that funded the industry, or 10h if the industry was generated randomly. If the industry was built using an earlier TTDPatch than 2.0.1 α74 or with newindustries turned off, this field is 10h.

Construction type (B3)

This byte tells you how the industry got onto the map. The following values are possible:

Value Meaning
0 Unknown - This industry was built with newindustries being off, or in a TTDPatch version prior to TTDPatch 2.0.1 alpha 74
1 Created during normal gameplay, either by a player or the in-game random industry generator
2 Created during random map generation
3 Created in the scenario editor

In case 1, you can check variable A7 to find out whether the industry was funded by a player or by the random generator.