Need help with terrain macro

The place to post your WML questions and answers.

Moderator: Forum Moderators

Forum rules
  • Please use [code] BBCode tags in your posts for embedding WML snippets.
  • To keep your code readable so that others can easily help you, make sure to indent it following our conventions.
Wussel
Posts: 624
Joined: July 28th, 2012, 5:58 am

Need help with terrain macro

Post by Wussel »

After tiling the graveyard fence from the Secret of the Ancient campaign I decided to go for a massive wall. The idea is to make the hidden field unwalkable or a new terrain type (climber/hide in walls). The wall is huge as it is supposed to be an obstacle like a city wall or so.

I had to copy the NEW:FENCE macro to add more fields and change the base. The most annoying error is a stacking error which I believe comes some how from the "1" and "2" in the orders for the se,nw/sw,ne straight tiles.

Please help.
wall-issues.PNG

Code: Select all

#define NEW:BIGFENCE TERRAINLIST IMAGESTEM
    [terrain_graphics]
        map="
,  *
2,   2
,  1
2,   2
,  *"
        [tile]
            pos=1
            type={TERRAINLIST}
            no_flag=fence
            set_flag=fence,fence-[ne,se,sw,nw]
        [/tile]

        [tile]
            pos=2
            type={TERRAINLIST}
        [/tile]

        [image]
            name={IMAGESTEM}-ne-se-sw-nw.png
            layer=0
            base=90,216
            center=90,144
        [/image]
    [/terrain_graphics]

    [terrain_graphics]
        map="
,  *
2,   2
,  1
*,   2
,  *"
        [tile]
            pos=1
            type={TERRAINLIST}
            no_flag=fence
            set_flag=fence,fence-[ne,se,nw]
        [/tile]

        [tile]
            pos=2
            type={TERRAINLIST}
        [/tile]

        [image]
            name={IMAGESTEM}-ne-se-nw.png
            layer=0
            base=90,216
            center=90,144
        [/image]
    [/terrain_graphics]

    [terrain_graphics]
        map="
,  *
2,   *
,  1
2,   2
,  *"
        [tile]
            pos=1
            type={TERRAINLIST}
            no_flag=fence
            set_flag=fence,fence-[se,sw,nw]
        [/tile]

        [tile]
            pos=2
            type={TERRAINLIST}
        [/tile]

        [image]
            name={IMAGESTEM}-se-sw-nw.png
            layer=0
            base=90,216
            center=90,144
        [/image]
    [/terrain_graphics]

    [terrain_graphics]
        map="
,  *
*,   2
,  1
2,   2
,  *"
        [tile]
            pos=1
            type={TERRAINLIST}
            no_flag=fence
            set_flag=fence,fence-[ne,se,sw]
        [/tile]

        [tile]
            pos=2
            type={TERRAINLIST}
        [/tile]

        [image]
            name={IMAGESTEM}-ne-se-sw.png
            layer=0
            base=90,216
            center=90,144
        [/image]
    [/terrain_graphics]

    [terrain_graphics]
        map="
,  *
2,   2
,  1
2,   *
,  *"
        [tile]
            pos=1
            type={TERRAINLIST}
            no_flag=fence
            set_flag=fence,fence-[ne,sw,nw]
        [/tile]

        [tile]
            pos=2
            type={TERRAINLIST}
        [/tile]

        [image]
            name={IMAGESTEM}-ne-sw-nw.png
            layer=0
            base=90,216
            center=90,144
        [/image]
    [/terrain_graphics]

    [terrain_graphics]
        map="
,  *
*,   2
,  1
*,   2
,  *"
        [tile]
            pos=1
            type={TERRAINLIST}
            no_flag=fence
            set_flag=fence,fence-[ne,se]
        [/tile]

        [tile]
            pos=2
            type={TERRAINLIST}
        [/tile]

        [image]
            name={IMAGESTEM}-ne-se.png
            layer=0
            base=90,216
            center=90,144
        [/image]
    [/terrain_graphics]

    [terrain_graphics]
        map="
,  *
2,   *
,  1
2,   *
,  *"
        [tile]
            pos=1
            type={TERRAINLIST}
            no_flag=fence
            set_flag=fence,fence-[sw,nw]
        [/tile]

        [tile]
            pos=2
            type={TERRAINLIST}
        [/tile]

        [image]
            name={IMAGESTEM}-sw-nw.png
            layer=0
            base=90,216
            center=90,144
        [/image]
    [/terrain_graphics]

    [terrain_graphics]
        map="
,  *
*,   *
,  1
2,   2
,  *"
        [tile]
            pos=1
            type={TERRAINLIST}
            no_flag=fence
            set_flag=fence,fence-[se,sw]
        [/tile]

        [tile]
            pos=2
            type={TERRAINLIST}
        [/tile]

        [image]
            name={IMAGESTEM}-se-sw.png
            layer=0
            base=90,216
            center=90,144
        [/image]
    [/terrain_graphics]

    [terrain_graphics]
        map="
,  *
2,   2
,  1
*,   *
,  *"
        [tile]
            pos=1
            type={TERRAINLIST}
            no_flag=fence
            set_flag=fence,fence-[ne,nw]
        [/tile]

        [tile]
            pos=2
            type={TERRAINLIST}
        [/tile]

        [image]
            name={IMAGESTEM}-ne-nw.png
            layer=0
            base=90,216
            center=90,144
        [/image]
    [/terrain_graphics]

    [terrain_graphics]
        map="
,  *
*,   2
,  1
*,   *
,  *"
        [tile]
            pos=1
            type={TERRAINLIST}
            no_flag=fence
            set_flag=fence,fence-@R4
        [/tile]

        [tile]
            pos=2
            type={TERRAINLIST}
            has_flag=fence-@R4
        [/tile]

        rotations=n,ne,se,s,sw,nw

        [image]
            # wmlscope: start ignoring
            name={IMAGESTEM}-@R1-@R4-@V.png
            # wmlscope: stop ignoring
            variations="01;02"
            layer=0
            base=90,216
            center=90,144
        [/image]
    [/terrain_graphics]

    [terrain_graphics]
        map="
,  *
*,   2
,  1
*,   *
,  *"
        [tile]
            pos=1
            type={TERRAINLIST}
            no_flag=fence
            set_flag=fence,fence-@R4
        [/tile]

        [tile]
            pos=2
            type={TERRAINLIST}
        [/tile]

        rotations=n,ne,se,s,sw,nw

        [image]
            # wmlscope: start ignoring
            name={IMAGESTEM}-@R1-@R4-@V.png
            # wmlscope: stop ignoring
            variations="01;02"
            layer=0
            base=90,216
            center=90,144
        [/image]
    [/terrain_graphics]

    [terrain_graphics]
        map="
,  *
2,   2
,  1
2,   2
,  *"
        [tile]
            pos=1
            type={TERRAINLIST}
            no_flag=fence
            set_flag=fence,fence-[ne,se,sw,nw]
        [/tile]

        [tile]
            pos=2
            type=!,{TERRAINLIST}
        [/tile]

        [image]
            name={IMAGESTEM}-ne-se-sw-nw.png
            layer=0
            base=90,216
            center=90,144
        [/image]
    [/terrain_graphics]

    [terrain_graphics]
        map="
,  *
*,   2
,  1
*,   *
,  *"
        [tile]
            pos=1
            type=!,{TERRAINLIST}
        [/tile]

        [tile]
            pos=2
            type={TERRAINLIST}
            has_flag=fence-@R4
        [/tile]

        rotations=n,ne,se,s,sw,nw

        [image]
            # wmlscope: start ignoring
            name={IMAGESTEM}-@R1.png
            # wmlscope: stop ignoring
            layer=0
            base=90,216
            center=90,144
        [/image]
    [/terrain_graphics]
#enddef
User avatar
zookeeper
WML Wizard
Posts: 9742
Joined: September 11th, 2004, 10:40 pm
Location: Finland

Re: Need help with terrain macro

Post by zookeeper »

Well you're not saying which rule is responsible, how the images are cut and which hexes are the wall hexes, etc.

That said, those rules were not designed for images like that, and you might need to do a lot more than just edit some base coordinates to make something like that work.
Wussel
Posts: 624
Joined: July 28th, 2012, 5:58 am

Re: Need help with terrain macro

Post by Wussel »

lol. It is working. tiles are cut in strips of 54 pixel each as this is easiest. The rotational code for the straight middle part is my candidate for trouble. It is a clone of the fence macro. Thus the png files are clones of fence pngs. They are just bigger. Is there anybody into terrain macros?
wall-with-shade.png
These 2 thingies are related to the stacking error:

Code: Select all

    [terrain_graphics]
        map="
,  *
*,   2
,  1
*,   *
,  *"
        [tile]
            pos=1
            type={TERRAINLIST}
            no_flag=fence
            set_flag=fence,fence-@R4
        [/tile]

        [tile]
            pos=2
            type={TERRAINLIST}
            has_flag=fence-@R4
        [/tile]

        rotations=n,ne,se,s,sw,nw

        [image]
            # wmlscope: start ignoring
            name={IMAGESTEM}-@R1-@R4-@V.png
            # wmlscope: stop ignoring
            variations="01;02"
            layer=0
            base=90,216
            center=90,144
        [/image]
    [/terrain_graphics]

    [terrain_graphics]
        map="
,  *
*,   2
,  1
*,   *
,  *"
        [tile]
            pos=1
            type={TERRAINLIST}
            no_flag=fence
            set_flag=fence,fence-@R4
        [/tile]

        [tile]
            pos=2
            type={TERRAINLIST}
        [/tile]

        rotations=n,ne,se,s,sw,nw

        [image]
            # wmlscope: start ignoring
            name={IMAGESTEM}-@R1-@R4-@V.png
            # wmlscope: stop ignoring
            variations="01;02"
            layer=0
            base=90,216
            center=90,144
        [/image]
    [/terrain_graphics]
User avatar
Heindal
Posts: 1344
Joined: August 11th, 2011, 9:25 pm
Location: Germany, Karlsruhe
Contact:

Re: Need help with terrain macro

Post by Heindal »

Well, I've never worked with the fence macro, I can just provide a workaround. But its a lot of handish work.

You can of course define single parts of terrain as an overlay and than use them in the map editor.

You have to define a terrain_type in the terrain.cfg ...

Code: Select all

[terrain_type]
    symbol_image=fence/fence-se-sw
    id=fence-se-sw
    name= _ "fence-se-sw
    string=^Ys92
    aliasof=_bas, Gg
    mvt_alias=-,_bas,Gg
    editor_group=Trader
[/terrain_type]
and after that define it as an overlay in Terrain_graphics.cfg:

Code: Select all

{OVERLAY             *^Ys92                        fence/fence-se-sw}
So you can manually place the walls in the editor after selecting your editor_group. I admit I've did that with your fence :oops:, instead of using the fence macro.
Remember to use a terrain shortcut like above. e.g. Yw (w stand for wussel could be used ^^)
The future belongs to those, who believe in the beauty of their dreams.
Developer of: Trapped, Five Fates, Strange Legacy, Epical, UR Epic Era
Dungeonmasters of Wesnoth, Wild Peasants vs Devouring Corpses, Dwarf Dwarfson Dwarvenminer
Wussel
Posts: 624
Joined: July 28th, 2012, 5:58 am

Re: Need help with terrain macro

Post by Wussel »

The graveyard fence from beattlenut is working with the fence macro. Even the regular looks ok. The Bigfence version brings a few missing pixel for the corners.

The terrainmacro (custom) has to be called in the main.cfg for editor and campaign. That is all the secret. Maybe I need to learn what the "2" is actually meaning code wise? I learned ".", "*" and "1" already. Should not be so hard.

I use g for the graveyard and w for the wall. Was it ^efg and ^efw? Any terrain experts still around???


Here are the graphic files for all who like to play with it. I include no shade versions in a sub folder, just in case some body wants to try out different types of shading by himself.
wall.rar
(428.84 KiB) Downloaded 247 times
User avatar
zookeeper
WML Wizard
Posts: 9742
Joined: September 11th, 2004, 10:40 pm
Location: Finland

Re: Need help with terrain macro

Post by zookeeper »

Wussel wrote:Maybe I need to learn what the "2" is actually meaning code wise? I learned ".", "*" and "1" already. Should not be so hard.
"1" corresponds with the [tile] that has pos=1 and "2" corresponds with the [tile] that has pos=2 and so on. The rule only matches if all [tile]s and their constraints match.

For example...

Code: Select all

[terrain_graphics]
        map="
,  *
2,   2
,  1
2,   2
,  *"
        [tile]
            pos=1
            type={TERRAINLIST}
            no_flag=fence
            set_flag=fence,fence-[ne,se,sw,nw]
        [/tile]

        [tile]
            pos=2
            type={TERRAINLIST}
        [/tile]

        [image]
            name={IMAGESTEM}-ne-se-sw-nw.png
            layer=0
            base=90,216
            center=90,144
        [/image]
    [/terrain_graphics]
How that reads is more or less (angle brackets for clarity):

Find all instances of <a fence hex which has not yet been flagged as a fence hex> which have <a fence hex adjacent to them in all directions except n and s>, and then <place the image {IMAGESTEM}-ne-se-sw-nw.png in the center of that 7-hex area> and also <flag the center hex with the flags fence, fence-ne, fence-se, fence-sw and fence-nw>.

The rule matches if and when the two [tile]s and their constraints (in this case, type and no_flag) match the map. If and only if the rule matches are the flags set and any images placed.

The "*"'s indicate that the rule doesn't care what those hexes are, same with ".". So while they're identical for rule-matching purposes, the difference is that "*" hexes can still have images on them (for example if fence-ne-se-sw-nw.png was a larger, multi-hex image) whereas "." hexes will always be blank.
Wussel
Posts: 624
Joined: July 28th, 2012, 5:58 am

Re: Need help with terrain macro

Post by Wussel »

After contemplating on the explanation I came to an answer. Unfortunately it is a question.

Who actually did make the fence macro? Is the person still around? Would it be possible to ask a few specific question?

There is a lot of things about the order of the things inside the fence macro. There is another less obvious stacking error too.

The good thing: all this things do not matter with the graveyard fence! The graveyard fence just needs a * above the corner stones and that is it, as there are just a few black pixel missing.

The wall however needs proper attention. I promise to make a wooden palisade if the coding gets solved.
User avatar
zookeeper
WML Wizard
Posts: 9742
Joined: September 11th, 2004, 10:40 pm
Location: Finland

Re: Need help with terrain macro

Post by zookeeper »

Wussel wrote:After contemplating on the explanation I came to an answer. Unfortunately it is a question.

Who actually did make the fence macro? Is the person still around? Would it be possible to ask a few specific question?
I did, so ask away. :mrgreen:

If you wrap your terrain into convenient add-on form, I can try to tinker with the rules a bit to figure out what options there are.
Wussel
Posts: 624
Joined: July 28th, 2012, 5:58 am

Re: Need help with terrain macro

Post by Wussel »

What I found most exotic is the 4 end thingy which is called twice. In the beginning and almost at the end again.

Than there is the 2 end straight thingy which is looking exotic. It basically lacks a 2 at the opposite side. If I change that once, the version coming from the south get used more. The stacking issue moves to the other side. If i change it twice the thing does not work any more.

Basically the stacking seems to be influenced by the order of the macro. The other thingy not working is the 4 end thingy being put in a row top to down. I believe the endings are there but stacked wrongly.

I assume I can put it in a separate add-on. Right now I have to much stuff in there. Does it work just for the editor? Should not take to long.
User avatar
zookeeper
WML Wizard
Posts: 9742
Joined: September 11th, 2004, 10:40 pm
Location: Finland

Re: Need help with terrain macro

Post by zookeeper »

Yes, it's good enough if it just shows up in the editor (that's where I'd be looking at it), if that's what you're asking.
Wussel
Posts: 624
Joined: July 28th, 2012, 5:58 am

Re: Need help with terrain macro

Post by Wussel »

Here you go. That was easy.

For others: This is only working in editor.

1. Unpack.
2. Put in add-on folder.
3. Open editor.
4. Open editor group wall.
5. Play around.
Attachments
wall.rar
(572.76 KiB) Downloaded 275 times
User avatar
zookeeper
WML Wizard
Posts: 9742
Joined: September 11th, 2004, 10:40 pm
Location: Finland

Re: Need help with terrain macro

Post by zookeeper »

The original macro has base=90,144, whereas yours has base=90,216. Just changing that 216 back to 144 seemed to do the trick for me.
Wussel
Posts: 624
Joined: July 28th, 2012, 5:58 am

Re: Need help with terrain macro

Post by Wussel »

But the purpose of image base is related to stacking. Why does this happen? is the image base rotated somehow? For the wall I would really prefer that base of 216. For the fence 144 would work. The wall center field should be unwalkable to create an obstacle. Maybe a special move type "wall walker" would be fun. Than that unit should hide behind the wall.
User avatar
zookeeper
WML Wizard
Posts: 9742
Joined: September 11th, 2004, 10:40 pm
Location: Finland

Re: Need help with terrain macro

Post by zookeeper »

Wussel wrote:But the purpose of image base is related to stacking. Why does this happen? is the image base rotated somehow?
It's not rotated, but neither do I understand the mechanics of how exactly it works in a complex situation like this.
Wussel wrote:For the wall I would really prefer that base of 216. For the fence 144 would work.
Why? What does that do? I tried the 144 with units too and everything seemed to layer correctly.
Wussel
Posts: 624
Joined: July 28th, 2012, 5:58 am

Re: Need help with terrain macro

Post by Wussel »

Ok. a unit on the wall field should be hidden by the wall. -> base216

A unit on the fence field should be standing in front of the fence.->base144.

There is one more silly test. Check the wall inside forest. On the center piece the forest overlay gets replaced which is good. The surrounding forest overlays should go with sense (behind/behind and front/front). There are some issues with base216. I got the idea that the base command is suffering from the rotate command. This is not complexity. This would just be an error. Solution would be not to use the rotate command and just do the 2 needed direction by hand. It is just a hypothesis, but it has the potential to cure all 3 stacking errors I have encountered, if right.
Post Reply