Thursday, February 02, 2006

Wesnoth terrain

How are maps created? How are terrains organized? These questions are no way different from asking how GNU/Linux works. The brief explanation is, it is very complicated!


Conceptually it works like this:


Terrains are defined in terrain.cfg. They get assigned ID, name, char, etc.


A snippet of terrain.cfg



# Terrain configuration file. Defines how the terrain _work_ in the game. How
# the terrains _look_ is defined in terrain_graphics.cfg .

# NOTE: terrain id's are used implicitly by the in-game help:
# each "[terrain] id=some_id" corresponds to "[section] id=terrain_some_id"
# or "[topic] id=terrain_some_id" identifying its description in [help]

[terrain]
symbol_image=void
id=shroud
name= _ "Shroud"
char=" "
[/terrain]

[terrain]
symbol_image=fog
id=fog
name= _ "Fog"
char="~"
[/terrain]

[terrain]
symbol_image=ocean
id=deep_water
name= _ "Deep Water"
char=s
submerge=0.5
unit_height_adjust=-3
[/terrain]

[terrain]
symbol_image=coast
id=shallow_water
name= _ "Shallow Water"
char=c
submerge=0.4
unit_height_adjust=-4
[/terrain]

--snip--

In terrain-graphics.cfg the char gets assigned to the actual gfx files and given rules for how it is to be placed, layered, transitioned, etc. A normal type terrain gets a base image assigned and optionally several alternative tiles which will be distributed according to a given percentage. Then, it will be fed into the macro responsible for layering and transitioning against other terrains. Multihex terrains use their own custom macros to be assembled and placed (either on top of other terrains or with no background). Castles have their own macros, some terrains are also drawn using the castle macro.


A snippet of terrain-graphics.cfg



# The following flags are defined to have a meaning
#
# * base : the corresponding tile has already graphics for the terrain
# base. No other one should be added.
# * transition-$direction : the corresponding tile already has the transition
# in the given direction (or should not have one). No other one should be
# added.
# * keep-of-$castle : castle being a tile letter. The corresponding tile is the
# keep correspoding to the given castle tile

# The following should be kept on top of the file {terrain-graphics}
#-----------------------------------------------------------------
# Forest< ->Castle|Encampment special cases
#-----------------------------------------------------------------

#define FORESTADJCASTLEA FID ID PROB TILE
[terrain_graphics]
map="
1
* 1
2
* *
*"

[tile]
pos=1
type={ID}
[/tile]

[tile]
pos=2
type={FID}
no_flag="overlay"
set_flag="overlay"
[/tile]

probability={PROB}
rotations=n,ne,se,s,sw,nw

[image]
name={TILE}
position=vertical
base=90,144
[/image]

[/terrain_graphics]
#enddef

--snip--

All sorts of stuff like rotation, precedence, mutual-exclusiveness, ordering, layering, positioning, etc. are the macro’s area of responsibility. You have total control of the game’s interface using the right macro. Ayin made a very powerfull and flexible system, but very complex indeed!


Thanks to freim for the help.

No comments: