Difference between revisions of "VariationalAction2/Industries"

From GRFSpecs
Jump to navigationJump to search
m (Bot: Automated text replacement (-variational action 2 +VarAction2))
(→‎Variables: add version icons)
Line 4: Line 4:
   
 
{| |-
 
{| |-
!Variable !!Version !![[GRFActionsDetailed|Size]] !! Description
+
!Variable !![[GRFActionsDetailed|Size]] !!Version !! Description
 
|-
 
|-
|40..42||||||Waiting cargo
+
|40..42||||{{ottdp| |}}||Waiting cargo
 
|-
 
|-
|43||||||Manhattan distance of closest dry/land tile
+
|43||||{{ottdp| |2.6|ttdprev=r1298}}||Manhattan distance of closest dry/land tile
 
|-
 
|-
|44||||||Layout number (1-based)
+
|44||||{{ottdp| |2.6|ttdprev=r1594}}||Layout number (1-based)
 
|-
 
|-
|45||||||Player info
+
|45||||{{ottdp| |2.6|ttdprev=r1711}}||Player info
 
|-
 
|-
|46||||||Date when industry was built in days since year 0
+
|46||||{{ottdp|0.7|2.6|ttdprev=r2047|ottdrev=r13443}}||Date when industry was built in days since year 0
 
|-
 
|-
|60||||||Get industry tile ID at offset
+
|60||||{{ottdp| |2.5|ttdprev=alpha 73}}||Get industry tile ID at offset
 
|-
 
|-
|61||||||Get random tile bits at offset
+
|61||||{{ottdp| |2.5|ttdprev=alpha 73}}||Get random tile bits at offset
 
|-
 
|-
|62||||||Land info of nearby tiles
+
|62||||{{ottdp| |2.5|ttdprev=alpha 74}}||Land info of nearby tiles
 
|-
 
|-
|63||||||Animation stage of nearby tiles
+
|63||||{{ottdp| |}}||Animation stage of nearby tiles
 
|-
 
|-
|64||||||Distance of nearest industry with given type
+
|64||||{{ottdp| |}}||Distance of nearest industry with given type
 
|-
 
|-
|65||||||Get [[TownZones|town zone]] and Manhattan distance of closest town
+
|65||||{{ottdp| |}}||Get [[TownZones|town zone]] and Manhattan distance of closest town
 
|-
 
|-
|66||||||Get square of Euclidean distance of closest town
+
|66||||{{ottdp| |}}||Get square of Euclidean distance of closest town
 
|-
 
|-
|67||||||Count of industry, distance of closest instance
+
|67||||{{ottdp| |}}||Count of industry, distance of closest instance
 
|-
 
|-
|68||||||Like the above, but with layout filter
+
|68||||{{ottdp| |}}||Like the above, but with layout filter
 
|-
 
|-
|A7||||||Industry founder information
+
|A7||||{{ottdp| |2.5|ttdprev=alpha 74}}||Industry founder information
 
|-
 
|-
|B0||||||Date when industry was built in days since 1920
+
|B0||||{{ottdp| |}}||Date when industry was built in days since 1920
 
|-
 
|-
|B3||||||Construction type
+
|B3||||{{ottdp| |}}||Construction type
 
|-
 
|-
|B4||||||Date when cargo was last accepted in days since 1920, or 0 if no cargo was ever accepted (available since TTDPatch 2.6 r1321)
+
|B4||||{{ottdp| |2.6|ttdprev=r1321}}||Date when cargo was last accepted in days since 1920, or 0 if no cargo was ever accepted
 
|}
 
|}
   
Line 50: Line 50:
   
 
=== Manhattan distance of closest dry/land tile (43) ===
 
=== Manhattan distance of closest dry/land tile (43) ===
 
(from r1298)
 
   
 
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.
 
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.
Line 58: Line 56:
   
 
=== Layout number (44) ===
 
=== Layout number (44) ===
  +
T
 
If the industry was created running TTDPatch 2.6 r1594 or later, this 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.
+
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.
 
If the industry was created using an earlier version of TTDPatch, or while newindustries was off, the result will be zero.
   
 
=== Player info (45) ===
 
=== Player info (45) ===
 
(From TTDPatch 2.6 r1711)
 
   
 
As [[VarAction2Vehicles#Player info 43|vehicle variable 43]], except that the no-player state is indicated by var A7 being 10h.
 
As [[VarAction2Vehicles#Player info 43|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) ===
 
=== Date when industry was built in days since year 0 (46) ===
 
(From OpenTTD r13443, TTDPatch 2.6 r2047)
 
   
 
Exact same behaviour as var B0, but based on year 0, instead of year 1920
 
Exact same behaviour as var B0, but based on year 0, instead of year 1920
Line 78: Line 72:
   
 
=== Get industry tile ID at offset (60) ===
 
=== Get industry tile ID at offset (60) ===
 
(from TTDPatch 2.0.1 alpha 73 and above only)
 
   
 
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:
 
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:
Line 88: Line 80:
   
 
=== Get random tile bits at offset (61) ===
 
=== Get random tile bits at offset (61) ===
 
(from TTDPatch 2.0.1 alpha 73 and above only)
 
   
 
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 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.
Line 96: Line 86:
   
 
=== Land info of nearby tiles (62) ===
 
=== Land info of nearby tiles (62) ===
 
(from TTDPatch 2.0.1 alpha 74 and above only)
 
   
 
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 [[VarAction2IndustryTiles#Land info of nearby tiles 60|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.
 
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 [[VarAction2IndustryTiles#Land info of nearby tiles 60|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.
Line 131: Line 119:
 
=== Industry founder information (A7) ===
 
=== Industry founder information (A7) ===
   
Since TTDPatch 2.0.1 alpha 74, 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 version or with newindustries turned off, this field is 10h.
+
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) ===
 
=== Construction type (B3) ===

Revision as of 12:27, 23 July 2011

Introduction

Variables

Variable Size Version Description
40..42 Supported by OpenTTD Supported by TTDPatch Waiting cargo
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
A7 Supported by OpenTTD Supported by TTDPatch 2.5 (alpha 74)2.5 Industry founder information
B0 Supported by OpenTTD Supported by TTDPatch Date when industry was built in days since 1920
B3 Supported by OpenTTD Supported by TTDPatch Construction type
B4 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

For other 80+x variables confer the 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).

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.

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.

Example