Five WML questions

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.
Post Reply
User avatar
Bob_The_Mighty
Posts: 839
Joined: July 13th, 2006, 1:15 pm

Five WML questions

Post by Bob_The_Mighty »

I have a number of WML questions, regarding a new project I am working on. It is for 1.4.3. Any help would be great.

1. Filtering on teams

I have an event which I want to trigger only when an enemy unit passes the filter.
I've tried this...

[not]
[wml_filter]
team_name=$unit.team_name
[/wml_filter]
[/not]


But it doesn't seem to work. At the moment, it triggers for allies too. Is there a way to do this using a standard unit filter or a wml_filter?

2. Facing for fake units

When using a [move_unit_fake] I cannot figure out how to make the fake unit face in the direction it moving. Do I need a standing animation or a movement animation? And do I need six images for all the directions, or does it flip it automatically like it does with projectiles? I've tried several combinations with no luck.

3. Preventing a unit from moving into village tiles

I want to make a unit that is unable to enter villages. I can do this fine for grassland villages (by setting movecosts to village=99 in the unit .cfg), but my unit can still enter water/swamp/hill/mountain/cave villages since these tiles are aliased with terrain that it can move on. Is there a way around this? I tried inventing a key to set swamp_village=99 but it did nothing.

4. Floating labels

If a unit is stored, is there a way to show the floating labels without unstoring it? Or, if not, could I do this: store1/store2/unstore2/unstore1? (*2 being purely for labels). Does this make sense?

5. Working out chance-to-hit using variables

Is there some way to access what defence a unit has at any given time, so as to work out the chance of it getting hit. I guess it might be possible to run through every terrain type and match it with the movetype, but that seems very tedious. Any ideas?
My current projects:
MP pirate campaign: The Altaz Mariners
RPG sequel: Return to Trent
MP stealth campaign: Den of Thieves
User avatar
zookeeper
WML Wizard
Posts: 9742
Joined: September 11th, 2004, 10:40 pm
Location: Finland

Re: Five WML questions

Post by zookeeper »

Bob_The_Mighty wrote:I have a number of WML questions, regarding a new project I am working on. It is for 1.4.3. Any help would be great.

1. Filtering on teams

I have an event which I want to trigger only when an enemy unit passes the filter.
I've tried this...

[not]
[wml_filter]
team_name=$unit.team_name
[/wml_filter]
[/not]


But it doesn't seem to work. At the moment, it triggers for allies too. Is there a way to do this using a standard unit filter or a wml_filter?
Units don't have a team_name stored in them. What I've done in another project was to use your above way of filtering, but set those team_name values for each unit manually. Meaning basically start and recruit events which make sure that any unit entering the game will have the correct team_name stored into it.
musketaquid
Art Contributor
Posts: 117
Joined: July 18th, 2006, 12:23 am

Re: Five WML questions

Post by musketaquid »

1. Filtering on teams

...
team_name belongs to the [side] tag.
Try this.

Code: Select all

    [event]
        name=moveto
        first_time_only=no
        [filter]
            x,y=10,6
        [/filter]

        [store_side]
            side=$side_number
            variable=temp
        [/store_side]

        [if]
            [variable]
                name=temp.team_name
                not_equals=north
            [/variable]
        [then]
        ...
        [/then]
        [/if]

        {CLEAR_VARIABLE temp}
    [/event]
User avatar
Ken_Oh
Moderator Emeritus
Posts: 2176
Joined: February 6th, 2006, 4:03 am
Location: Baltimore, Maryland, USA

Re: Five WML questions

Post by Ken_Oh »

Bob_The_Mighty wrote:3. Preventing a unit from moving into village tiles
The only idea I can throw at you is to change the terrain up a little bit, which is probably not going to be optimal in any setting. I'm thinking WML should be made to be flexible on terrain to the point where a designer can state {VARIABLE unit.movement_costs.Gg 100}. I'll take this to the ideas forum if no one else has a better solution for you.


Bob_The_Mighty wrote:4. Floating labels

If a unit is stored, is there a way to show the floating labels without unstoring it? Or, if not, could I do this: store1/store2/unstore2/unstore1? (*2 being purely for labels). Does this make sense?
Sounds to me like that would work just fine.
Bob_The_Mighty wrote:5. Working out chance-to-hit using variables

Is there some way to access what defence a unit has at any given time, so as to work out the chance of it getting hit. I guess it might be possible to run through every terrain type and match it with the movetype, but that seems very tedious. Any ideas?
I think the best idea is to store the unit, store the location, pass the terrain letters through a [switch] to see which defense it corresponds to and then storing unit.defense.[the found defense] to a variable is the best idea. If that's what you meant by the tedious way, then AFAIK that's what you have to use.
User avatar
Bob_The_Mighty
Posts: 839
Joined: July 13th, 2006, 1:15 pm

Re: Five WML questions

Post by Bob_The_Mighty »

Thanks Ken Oh. I haven't heard of [switch] before, but I'll look into it.

And zookeeper, your idea of setting the teams in a recruit event is a good one. I have been doing that for some other stuff, so I'll do it for this too, don't know why I didn't think of it.

The entering villages problem is probably unsovleable, so I might forget that.

Which only leave the fake unit facing question... can anyone make it 4/5? :)
Last edited by Bob_The_Mighty on August 20th, 2008, 12:51 am, edited 1 time in total.
My current projects:
MP pirate campaign: The Altaz Mariners
RPG sequel: Return to Trent
MP stealth campaign: Den of Thieves
musketaquid
Art Contributor
Posts: 117
Joined: July 18th, 2006, 12:23 am

Re: Five WML questions

Post by musketaquid »

Using the [switch] statement might be a problem :(
Because you want to use 1.4.3 as you said here
I have a number of WML questions, regarding a new project I am working on. It is for 1.4.3. Any help would be great.
and you can only use it in the dev branch. Look here:
http://www.wesnoth.org/wiki/InternalActionsWML
User avatar
Ken_Oh
Moderator Emeritus
Posts: 2176
Joined: February 6th, 2006, 4:03 am
Location: Baltimore, Maryland, USA

Re: Five WML questions

Post by Ken_Oh »

Right, sorry. Switch is just an easier way to do if/then for a list of conditions. Forget about it until next stable.
tsr
Posts: 790
Joined: May 24th, 2006, 1:05 pm

Re: Five WML questions

Post by tsr »

Bob_The_Mighty wrote:5. Working out chance-to-hit using variables

Is there some way to access what defence a unit has at any given time, so as to work out the chance of it getting hit. I guess it might be possible to run through every terrain type and match it with the movetype, but that seems very tedious. Any ideas?
Well, there might be code that does something like that on the forums already. I made that tedious work (before sap or zoo showed the way with objects) for my all-wml-no-luck-mod. Search for it and you might find it (I don't really rememeber when it was and I don't really understand what posts went missing in the latest crash).

/tsr
User avatar
Bob_The_Mighty
Posts: 839
Joined: July 13th, 2006, 1:15 pm

Re: Five WML questions

Post by Bob_The_Mighty »

I got your mod tsr, but I couldn't work which part I should look at.

I am expecting I will have to do something like this for every terrain type:

[if]
[have_location]
x,y=$x1,$y1
terrain=Gg,Ggf,Gs,Rd,Re,Rr,Rp,Re^Gvs,Gg^Wm,Wwf
[/have_location]
[then]
{VARIABLE_OP chance_to_hit format $unit.defense.grassland}
[/then]
[/if]


But what about aliased terrains? For instance, I have included river ford (Wwf) under grassland, but what if the unit is a merman?
My current projects:
MP pirate campaign: The Altaz Mariners
RPG sequel: Return to Trent
MP stealth campaign: Den of Thieves
User avatar
Bob_The_Mighty
Posts: 839
Joined: July 13th, 2006, 1:15 pm

Re: Five WML questions

Post by Bob_The_Mighty »

Well I ended up doing it the tedious way, and it seems to work. Here's what i used...

#define MW_TERRAIN_CHECKER TERRAIN LETTERS
[if]
[have_location]
x,y=$x1,$y1
terrain={LETTERS}
[/have_location]
[then]
{VARIABLE_OP chance_to_hit format $unit.defense.{TERRAIN}}
[/then]
[/if]
#enddef

#define MW_TERRAIN_CHECKER_2 TERRAIN_1 TERRAIN_2 LETTERS
[if]
[have_location]
x,y=$x1,$y1
terrain={LETTERS}
[/have_location]
[then]

[if]
{BOB_CONDITION unit.defense.{TERRAIN_1} less_than_equal_to $unit.defense.{TERRAIN_2}}
[then]
{VARIABLE_OP chance_to_hit format $unit.defense.{TERRAIN_1}}
[/then]
[else]
{VARIABLE_OP chance_to_hit format $unit.defense.{TERRAIN_2}}
[/else]
[/if]

[/then]
[/if]
#enddef

#define MW_DEFENSE_CALCULATOR

# Basic Terrain
{MW_TERRAIN_CHECKER deep_water "Wo"}
{MW_TERRAIN_CHECKER shallow_water "Ww,Ww^Vm"}
{MW_TERRAIN_CHECKER swamp_water "Ss,Ss^Vm"}
{MW_TERRAIN_CHECKER grassland "Gg,Ggf,Gs ,Rd,Re,Rr,Rp,Re^Gvs,Gg^Wm"}
{MW_TERRAIN_CHECKER sand "Dd,Ds,Dd^Dc"}
{MW_TERRAIN_CHECKER forest "Gg^Fet,Gs^Fp,Gs^Ft"}
{MW_TERRAIN_CHECKER hills "Dd^Dr,Hh"}
{MW_TERRAIN_CHECKER mountains "Md,Mm"}
{MW_TERRAIN_CHECKER village "Aa^Vea,Gg^Ve,Aa^Vha,Gg^Vh,Gs^Vht"}
{MW_TERRAIN_CHECKER castle "Ce,Ch,Cv,Cud,Chr,Ke,Kh,Kv,Kud,Khr"}
{MW_TERRAIN_CHECKER cave "Uu,Uu^Ii"}
{MW_TERRAIN_CHECKER tundra "Ai,Aa"}
{MW_TERRAIN_CHECKER canyon "Qxu,Ql,Qlf"}
{MW_TERRAIN_CHECKER cavewall "Mm^Xm,Md^Xm,Xu,Xv"}
{MW_TERRAIN_CHECKER fungus "Uu^Uf,Re^Uf"}

# Bridges
{MW_TERRAIN_CHECKER_2 deep_water grassland "Wo^Bw|,Wo^Bw/,Wo^Bw\"}
{MW_TERRAIN_CHECKER_2 shallow_water grassland "Ww^Bw\,Ww^Bw|,Ww^Bw/"}
{MW_TERRAIN_CHECKER_2 swamp_water grassland "Ss^Bw\,Ss^Bw|,Ss^Bw/"}

# Castles
{MW_TERRAIN_CHECKER_2 shallow_water castle "Chw,Khw"}
{MW_TERRAIN_CHECKER_2 swamp_water castle "Chs,Khs"}

# Villages
{MW_TERRAIN_CHECKER_2 swamp_water village "Ss^Vhs"}
{MW_TERRAIN_CHECKER_2 cave village "Uu^Vu,Uu^Vud"}
{MW_TERRAIN_CHECKER_2 hills village "Hh^Vhh,Ha^Vhha"}
{MW_TERRAIN_CHECKER_2 mountains village "Mm^Vhh"}

# Hills - cave,sand,snow
{MW_TERRAIN_CHECKER_2 cave hills "Uh,Uh^Ii"}
{MW_TERRAIN_CHECKER_2 sand hills "Hd"}
{MW_TERRAIN_CHECKER_2 tundra hills "Ha"}

# River-ford
{MW_TERRAIN_CHECKER_2 grassland shallow_water "Wwf"}

# Snow-forest
{MW_TERRAIN_CHECKER_2 tundra forest "Aa^Fpa"}
#enddef
The MW_TERRAIN_CHECKER_2 macro compares a unit's defense on aliased terrain, such as river ford, and sets $chance_to_hit to the lowest number of the two terrains (i.e. whichever is best for the unit).
My current projects:
MP pirate campaign: The Altaz Mariners
RPG sequel: Return to Trent
MP stealth campaign: Den of Thieves
Post Reply