Difference between revisions of "VariationalAction2/Industry Tiles"

From GRFSpecs
Jump to navigationJump to search
m (14 revisions)
(Fix style and format)
Line 1: Line 1:
  +
==Introduction==
   
  +
==Variables==
'''''Variational Action 2 Variables for Industry and Airport Tiles'''''
 
   
  +
=Variational Action 2 Variables for Industry and Airport Tiles=
 
  +
{| |-
  +
!Variable!![[GRFActionsDetailed|'''Size''']]!!Content
  +
|-
  +
|40||B||Construction state of the tile: a value between 0 and 3 (only defined for industries)
  +
|-
  +
|41||B||Ground type, the same as variable 81 for [[VarAction2Canals|canals]]
  +
|-
  +
|42||B||Current town zone of the tile in the nearest town
  +
|-
  +
|43||D||Relative position
  +
|-
  +
|44||B||Animation frame. Like [[VarAction2Houses#Current_animation_frame_46_|house variable 46]] but can contain anything 0..FF.
  +
|-
  +
|60||D||Land info of nearby tiles
  +
|-
  +
|61||D||Animation stage of nearby tiles
  +
|-
  +
|62||D||Get industry or airport tile ID at offset
  +
|}
   
 
VarAction2 for airport tiles is only available in OpenTTD r19204 or later
 
VarAction2 for airport tiles is only available in OpenTTD r19204 or later
 
||Variable|[[GRFActionsDetailed|'''Size''']]|Content
 
 
40|B|Construction state of the tile: a value between 0 and 3 (only defined for industries)
 
 
41|B|Ground type, the same as variable 81 for [[VarAction2Canals|canals]]
 
 
42|B|Current town zone of the tile in the nearest town
 
 
43|D|Relative position
 
 
44|B|Animation frame. Like [[VarAction2Houses#Current_animation_frame_46_|house variable 46]] but can contain anything 0..FF.
 
 
60|D|Land info of nearby tiles
 
 
61|D|Animation stage of nearby tiles
 
 
62|D|Get industry or airport tile ID at offset||
 
   
 
No 80+x variables are available (nor will they ever be). Try to access one will crash TTD.
 
No 80+x variables are available (nor will they ever be). Try to access one will crash TTD.
Line 34: Line 36:
 
This is the position of the tile relative to the northernmost tile of the industry or airport.
 
This is the position of the tile relative to the northernmost tile of the industry or airport.
   
Format: 00yxYYXX
+
'''Format:''' 00yxYYXX
   
  +
{| |-
||Variable|Content
 
  +
!Variable!!Content
 
  +
|-
x|the x offset from the northernmost tile
 
  +
|x||the x offset from the northernmost tile
 
  +
|-
XX|same, but stored in a byte instead of a nibble
 
  +
|XX||same, but stored in a byte instead of a nibble
 
  +
|-
y|the y offset from the northernmost tile
 
  +
|y||the y offset from the northernmost tile
 
  +
|-
YY|same, but stored in a byte instead of a nibble||
 
  +
|YY||same, but stored in a byte instead of a nibble
  +
|}
   
 
Because of the fact that y and x are nibbles, they may contain incorrect values if your industry exceeds 16 tiles in either direction. This variable can be used to spare industry or airport tile IDs: the same tile type can choose different representation depending on where exactly it is inside the industry.
 
Because of the fact that y and x are nibbles, they may contain incorrect values if your industry exceeds 16 tiles in either direction. This variable can be used to spare industry or airport tile IDs: the same tile type can choose different representation depending on where exactly it is inside the industry.
Line 50: Line 54:
 
===Land info of nearby tiles (60)===
 
===Land info of nearby tiles (60)===
   
The parameter of this variable is an offset from the position of the current tile. The low nibble contains the signed X offset (that is 0h=0, 1h=+1 ... 7h=+7, 8h=-8, 9h=-7 ... Fh=-1), the high nibble contains the Y offset. Therefore the parameter 00h accesses the current tile itself. The returned doubleword is in the format rczzbbss, where the meaning of the letters is:
+
The parameter of this variable is an offset from the position of the current tile. The low nibble contains the signed X offset (that is 0h=0, 1h=+1 ... 7h=+7, 8h=8, 9h=-7 ... Fh=-1), the high nibble contains the Y offset. Therefore the parameter 00h accesses the current tile itself. The returned doubleword is in the format rczzbbss, where the meaning of the letters is:
 
* '''r''' is reserved for future use
 
* '''r''' is reserved for future use
 
* '''c''' contains the [http://marcin.ttdpatch.net/sv1codec/TTD-locations.html#Landscape|landscape class] of the tile. (only from alpha 72 and above)
 
* '''c''' contains the [http://marcin.ttdpatch.net/sv1codec/TTD-locations.html#Landscape|landscape class] of the tile. (only from alpha 72 and above)
* '''zz''' is the height of the lowest corner of the tile. Always a multiple of 8
+
* '''zz''' is the height of the lowest corner of the tile. Always a multiple of 8|-
* '''bb''' is a bit field, the meaning of the individual bits are: ||Bit|Value|Meaning
+
* '''bb''' is a bit field, the meaning of the individual bits are:
  +
{|Bit||Value||Meaning
  +
|-
  +
|0||1||The tile is an industry tile, and belongs to the same industry as the current one
  +
|-
  +
|1||2||The tile has water on it. This flag is set for coasts as well. If you need a full water tile, check the slope data as well. If it's zero (flat tile), the tile is fully watered.
  +
|-
  +
|2..4|| ||(From alpha 70) 0 - normal tile; 1 - desert; 2 - rainforest; 4 - snowy tile
  +
|-
  +
|other bits|| ||reserved for future use
  +
|}
  +
* '''ss''' contains the slope data of the tile. The meaning of the individual bits is:
  +
{|Bit||Value||Meaning
  +
|-
  +
|0||1||West corner is above the lowest
  +
|-
  +
|1||2||South corner is above the lowest
  +
|-
  +
|2||4||East corner is above the lowest
  +
|-
  +
|3||8||North corner is above the lowest
  +
|-
  +
|4||16||The tile is a steep slope (i.e. the corner opposite to the lowest one is two units higher)
  +
|-
  +
|other bits|| ||always zero
  +
|}
   
  +
The resulting, possible values for this byte are illustrated in this image (from OpenTTD docs):
0|1|The tile is an industry tile, and belongs to the same industry as the current one
 
   
  +
[[File:industrytile_var60.jpg]]
1|2|The tile has water on it. This flag is set for coasts as well. If you need a full water tile, check the slope data as well. If it's zero (flat tile), the tile is fully watered.
 
   
  +
It is sometimes more useful to know the height of the highest corner of the tile. This can be computed with "zz/8 + ((ss+15)/16)", that is: "60 XX 33 1F 00 60 XX 40 FF 0F 10", where XX is the parameter. This returns a number 0..31 instead of 0..248, though.
2..4| |(From alpha 70) 0 - normal tile; 1 - desert; 2 - rainforest; 4 - snowy tile
 
  +
Why this works, and how to adjust for the different value range, are left as exercises for the reader.
   
other bits| |reserved for future use||
 
* '''ss''' contains the slope data of the tile. The meaning of the individual bits is: ||Bit|Value|Meaning
 
   
  +
Be aware that due to the way that TTD generates a random map, the class number of a neighbour tile could be different from what you expect. E.g., when placing a water-based industry adjacent to a coast in a random game, these tiles aren´t adjacent to water anymore after the industry has been generated and therefore you can't reliably check for coast tiles in the industry´s placement callback.
0|1|West corner is above the lowest
 
   
  +
===Animation stage for nearby tiles (61)===
1|2|South corner is above the lowest
 
   
  +
The parameter of this variable is interpreted the same way as for variable 60. The return value is FFFFFFFFh if the given tile doesn't belong to the industry, and the number of the current animation frame of the given tile otherwise. (That is, the value that var 44 would return for the given tile.)
2|4|East corner is above the lowest
 
   
  +
===Get industry tile ID at offset (62)===
3|8|North corner is above the lowest
 
   
  +
(from 2.6 alpha r1270)
4|16|The tile is a steep slope (i.e. the corner opposite to the lowest one is two units higher)
 
  +
Works similarly to industry variable 60, except that the point of reference is the current tile instead of the north tile of the industry, and the offsets are considered to be signed.
 
other bits| |always zero||
 
 
The resulting, possible values for this byte are illustrated in this image (from OpenTTD docs):
 
   
  +
==Example==
It is sometimes more useful to know the height of the highest corner of the tile. This can be computed with "zz/8 +
 

Revision as of 14:03, 14 June 2011

Introduction

Variables

Variable Size Content
40 B Construction state of the tile: a value between 0 and 3 (only defined for industries)
41 B Ground type, the same as variable 81 for canals
42 B Current town zone of the tile in the nearest town
43 D Relative position
44 B Animation frame. Like house variable 46 but can contain anything 0..FF.
60 D Land info of nearby tiles
61 D Animation stage of nearby tiles
62 D Get industry or airport tile ID at offset

VarAction2 for airport tiles is only available in OpenTTD r19204 or later

No 80+x variables are available (nor will they ever be). Try to access one will crash TTD.

Town zone (42)

Town zone where the building is situated (which is not necessarily the founder of the town). Zero if the tile isn't in a town. This is mostly useful for banks and other urban industries.

Relative position (43)

This is the position of the tile relative to the northernmost tile of the industry or airport.

Format: 00yxYYXX

Variable Content
x the x offset from the northernmost tile
XX same, but stored in a byte instead of a nibble
y the y offset from the northernmost tile
YY same, but stored in a byte instead of a nibble

Because of the fact that y and x are nibbles, they may contain incorrect values if your industry exceeds 16 tiles in either direction. This variable can be used to spare industry or airport tile IDs: the same tile type can choose different representation depending on where exactly it is inside the industry.

Land info of nearby tiles (60)

The parameter of this variable is an offset from the position of the current tile. The low nibble contains the signed X offset (that is 0h=0, 1h=+1 ... 7h=+7, 8h=8, 9h=-7 ... Fh=-1), the high nibble contains the Y offset. Therefore the parameter 00h accesses the current tile itself. The returned doubleword is in the format rczzbbss, where the meaning of the letters is:

  • r is reserved for future use
  • c contains the class of the tile. (only from alpha 72 and above)
  • zz is the height of the lowest corner of the tile. Always a multiple of 8|-
  • bb is a bit field, the meaning of the individual bits are:
0 1 The tile is an industry tile, and belongs to the same industry as the current one
1 2 The tile has water on it. This flag is set for coasts as well. If you need a full water tile, check the slope data as well. If it's zero (flat tile), the tile is fully watered.
2..4 (From alpha 70) 0 - normal tile; 1 - desert; 2 - rainforest; 4 - snowy tile
other bits reserved for future use
  • ss contains the slope data of the tile. The meaning of the individual bits is:
0 1 West corner is above the lowest
1 2 South corner is above the lowest
2 4 East corner is above the lowest
3 8 North corner is above the lowest
4 16 The tile is a steep slope (i.e. the corner opposite to the lowest one is two units higher)
other bits always zero

The resulting, possible values for this byte are illustrated in this image (from OpenTTD docs):

File:Industrytile var60.jpg

It is sometimes more useful to know the height of the highest corner of the tile. This can be computed with "zz/8 + ((ss+15)/16)", that is: "60 XX 33 1F 00 60 XX 40 FF 0F 10", where XX is the parameter. This returns a number 0..31 instead of 0..248, though. Why this works, and how to adjust for the different value range, are left as exercises for the reader.


Be aware that due to the way that TTD generates a random map, the class number of a neighbour tile could be different from what you expect. E.g., when placing a water-based industry adjacent to a coast in a random game, these tiles aren´t adjacent to water anymore after the industry has been generated and therefore you can't reliably check for coast tiles in the industry´s placement callback.

Animation stage for nearby tiles (61)

The parameter of this variable is interpreted the same way as for variable 60. The return value is FFFFFFFFh if the given tile doesn't belong to the industry, and the number of the current animation frame of the given tile otherwise. (That is, the value that var 44 would return for the given tile.)

Get industry tile ID at offset (62)

(from 2.6 alpha r1270) Works similarly to industry variable 60, except that the point of reference is the current tile instead of the north tile of the industry, and the offsets are considered to be signed.

Example