TerrainGraphicsWML

From The Battle for Wesnoth Wiki
Revision as of 13:09, 14 August 2005 by Sanna (talk | contribs)

The toplevel [terrain_graphics] tag

For information about the multi-hex tiling system, see MultiHexTutorial

In terrain graphics, all images are assumed to be .png and relative to images/terrain/. For example, writing 'image=grassland' means that the image file is images/terrain/grassland.png.

The multi-hex tiling system adds a new top-level element to WML, [terrain_graphics]. A building rule is used to specify images to place when terrains are in a certain formation. When a building rule is applied to a map, it is applied once to each coordinate on the map; when it is applied to a coordinate then that coordinate is considered the base. All locations in [terrain_graphics] are relative to the base.

The following keys/tags are recognized:

  • [tile] whenever a building rule is applied, each [tile] tag corresponds to a tile on the map. The corresponding tile must match each condition contained in [tile] for the [tile] tag to match. All [tile] tags must match in order for a rule to match. If the rule for a [tile] tag is applied, each action within [tile] will be executed on the tile corresponding to that [tile] tag
    • x,y standard coordinates - the location of the corresponding tile relative to the base.
    • pos a shortcut to specifying coordinates. Used in combination with map
    • Conditions for [tile]:
      • type a string of characters. Each character is the letter of a terrain (See TerrainWML, data/terrain.cfg). In order for a tile to match this condition, it must be one of the terrains specified. However, if the string is preceded by "!", the terrain must not be listed in order to match. If the string is '*', or if it is empty, any tile matches.
      • has_flag a string. Matches if a flag named after the given string is attached to the corresponding tile. Flags are attached using the set_flag key.
      • no_flag a string. Matches if no flag named after the given string has been attached to the corresponding tile. Flags are attached using the set_flag key.
    • Actions for [tile]:
      • set_flag Followed by a string of characters. Attaches a flag named after the given string to the corresponding tile if the rule matches. The only difference a flag makes is being detected by has_flag and no_flag in [tile]. This is determined by the order of the [terrain_graphics] tags; a tag after another one cannot influence it. See also has_flag, no_flag
  • [image]
    • layer an integer, usually negative. The more negative it is, the earlier it is drawn, and thus the farther "back" it is when compositing the terrain images together.
    • name the image to apply on this tile if appropriate
  • probability the percent probability for each position that if the position matches, then the rule will be applied. Default is 100(%)
  • rotations 6 comma(,) separated input strings. A rule that contains this key is not actually checked against the terrain; it instead is used as a template to create 6 new rules, each corresponding to a rotated version of the current rule. Whenever a rotated version is applied, instances of @(at-sign)R0, @R1, ... @R6 in attributes in the [terrain_graphics] tag will be adjusted by the corresponding amount and replaced with the letters specified by that numbered rotation in the rotations list. Each value corresponds to the rotated version that is -Pi/3 (60° clockwise) from the previous version; the first value corresponds to the unrotated version.
    For example, if rotations=n,ne,se,s,sw,nw and it is being rotated 120°, then "@R0"->"@R2"->"se", "@R1"->"@R3"->"s", ... "@R6"->"@R1"->"ne".
    Basically the important thing is that this lets the rule be applied in any of the six hex-directions, allowing you to adjust the name of the image files automatically.
  • set_flag,has_flag, no_flag shortcuts to putting these in the [tile] subtags; unbound attributes will apply to all [tile] subtags.
  • map a shortcut for defining [tile] tags with type conditions. Inputs a multi-line string value visually describing the map. The lines are cut into words of 4 characters, which correspond to [tile] tags. The line types alternate between lines corresponding to relatively even-abciss tiles and lines preceded by two spaces corresponding to relatively odd-abciss tiles. Every two lines represent 1 row on the map.

Words

A word is a 4-character shortcut to a [tile] tag. There are different types of words:

  • Usually a word is interpreted as being the input to the type key of the corresponding [tile]. That is, it creates a [tile] with the attribute type=word.
  • A word can also be a digit followed by 3 spaces. In this case, it is a shortcut to the [tile] with the attribute pos=word. This is called anchoring.


Examples

To define a north-south 2-tile mountain, the following syntax can be used:

[terrain_graphics]
    [tile]
        x=0
        y=0
        type=m
    [/tile]
    [tile]
        x=0
        y=1
        type=m
    [/tile]
    no_flag="mountain-tile"
    set_flag="mountain-tile"
    image_background="mountain-n-s"
[/terrain_graphics]


This represents a tile T, and its 6 adjacent tiles A, in the map notation.

.   .   .   .
  .   A   .   .
.   A   A   .
  .   T   .   .
.   A   A   .
  .   A   .   .

(to be continued)

For example, the following notations are equivalent:

map="
1
  1
*"

[tile] pos=1 type=CK [/tile]

=

map="
CK
  CK
*"

=

[tile]
    x=0
    y=0
    type=CK
[/tile]
[tile]
    x=1
    y=0
    type=CK
[/tile]
[tile]
    x=0
    y=1
    type=*
[/tile]


As an example, here are the map representation of rule that would consist on a mountain hex, and 2 grass hexes, all aligned.


.   g    m   .    m    .   m    g   .    g
  g        g             g        g
m   .    .   g    g    g   .    .   m    g
                  g                      m

See Also