I use a slightly different method.
I use an array that stores a value for each terrain type. This value is a decimal, and it represents what other terrains it can overlap.
A simple example:
My map has 3 terrains, water, grass and sand, represented in the map array as 0,1 and 2 respectively.
My terrain overlap array stores 3 values, 1 for each terrain, and is worked out like this.
Water (bit1) has a value of 1, grass (bit2) is 2 and sand (bit3) is 4. If I want grass to overlap water and sand, it has a value of 5, and if i want sand to overlap water, I give that a value of 1. It follows that water cannot overlap anything, so it has a value of 0. My array therefore is (0,5,1).
Now when drawing a tile, you check the map value of its neighbours ie 8 tiles for a square, 6 for a hex... etc. A simple 3x3 map for example, with grass around the edges and sand in the centre would be ((1,1,1),(1,2,1),(1,1,1)). Say the sand tile is now being drawn, first the basic sand graphic is drawn, then (assuming a square tile) its 8 neighbour tiles are looked up one at a time. Starting with the NE neighbour (doesn't matter what tile you start from), it has a value of 1, so in the overlap array you look up position 1, and see it has a value of 5 (or it overlaps bits 1 and 4). Have you noticed yet with the map data, the tile values correspond to 2^tilevalue=bit value? Take your sand tile (the one currently being drawn) and its value becomes 2^tilevalue or 2^2... its bitvalue is 4. If you then AND the neighbour tile's overlap value with the drawn tile's bitvalue, the result will equal 0 if no overlapping is allowed, or will equal the bitvalue if overlapping is allowed. 5 AND 4 =4, so the NE neighbour forces an overlap in the NE corner of the drawn tile.
This reduces the ammount of graphics needed, you simply have a base graphic, then an overlap graphic for each neighbour possibility (ie 8 for squares), so for each terrain type you only need 9 differnt graphics to represent all possibilities (1 base,4 for edges, 4 for corners). With hex tiles this only needs 7, 1 base and 6 edges (theres no corners produced in a hex map).
Also this method gives you a bit more flexibility, you're not limited to just having a certain terrain overlapping all terrains lower down in the chain. Say grass overlaps water, and water overlaps sand, you get the heirachy grass -> water -> sand, theres no way you can get sand to overlap grass if you wanted it to. However if you use an array to define what terrains can overlap, you can have any combination of overlaps you desire.
If you so wish, you can even go one step further and use the same method on the overlap graphics, giving you some interesting transition possibilities.
|