VariationalAction2/Industries

From GRFSpecs
< VariationalAction2
Revision as of 06:36, 21 January 2007 by dmccoy (talk)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigationJump to search

Variational Action 2 Variables for Industries

Variational Action 2 Variables for Industries

||Variable|Content

40..42|Waiting cargo

43|Manhattan distance of closest dry/land tile

60|Get industry tile ID at offset

61|Get random tile bits at offset

62|Land info of nearby tiles

63|Animation stage of nearby tiles

64|Distance of nearest industry with given type

65|Get town zone and Manhattan distance of closest town

66|Get square of Euclidean distance of closest town

67|Count of industry, distance of closest instance

A7|Industry founder information

B0|Date when industry was built in days since 1920

B3|Construction type

B4|Date when cargo was last accepted in days since 1920, or 0 if no cargo was ever accepted (available since 2.6 r1321)||

For other 80+x variables confer the industry structure.

Waiting cargo (40..42)

If bit 1 or 2 is set in property 21, the 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 7FFF (32767).

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.

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.

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:

  • 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)

(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 other bytes are reserved for future use.

Land info of nearby tiles (62)

(from TTDPatch 2.0.1 alpha 74 and above only)

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)

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)

This variable gets two parameters: the GRFID of the GRF where the industry is defined in register 100h (can be written using operator 0E of variational action 2) 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.

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.

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