Is there any way to filter units without ability?

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
Quetzalcoatl
Posts: 207
Joined: March 18th, 2009, 3:26 pm

Is there any way to filter units without ability?

Post by Quetzalcoatl »

Is there any way to filter units without ability? I was looking for it at wiki and forums but didn't find anything.
For example I would like to store units that doesn't have submerge or regeneration.

What I'm trying to do is to heal unit when all other units heals (between turn start and turn refresh).
I thought the best solution would be to modify unit at turn start (give regenerates) and remove this ability at turn refresh.
Ten soldiers wisely led will beat a hundred without a head.
User avatar
Ken_Oh
Moderator Emeritus
Posts: 2178
Joined: February 6th, 2006, 4:03 am
Location: Baltimore, Maryland, USA

Re: Is there any way to filter units without ability?

Post by Ken_Oh »

http://wiki.wesnoth.org/StandardUnitFilter lists ability id as something you can filter. So...

Code: Select all

[filter]
	[not]
		ability=regenerates
	[/not]
[/filter]
User avatar
Sapient
Inactive Developer
Posts: 4453
Joined: November 26th, 2005, 7:41 am
Contact:

Re: Is there any way to filter units without ability?

Post by Sapient »

Code: Select all

[filter]
  [not]
    ability=submerge
    [or]
      ability=regenerates
    [/or]
  [/not]
[/filter]
you can invert matches by using the [not] sub-tag.

edit: Ken beat me to it
http://www.wesnoth.org/wiki/User:Sapient... "Looks like your skills saved us again. Uh, well at least, they saved Soarin's apple pie."
User avatar
Quetzalcoatl
Posts: 207
Joined: March 18th, 2009, 3:26 pm

Re: Is there any way to filter units without ability?

Post by Quetzalcoatl »

Thx :), somehow i missed it :(

Here is the WML that do healing between turn start and turn refresh (that means no problems with labels, healing animations, regeneration and such - maybe it would be useful for somebody else):

Code: Select all

    [event]
        name=side turn
        first_time_only=no
        
        {VARIABLE south_rune_used no}
        [object]
            silent=yes
            [filter]
                side=$side_number
                x,y=9,18
                [not]
                    ability=regenerates
                [/not]
            [/filter]
            [then]
                {VARIABLE south_rune_used yes}
            [/then]
            [effect]
                apply_to=new_ability
                [abilities]
                    {ABILITY_REGENERATES}
                [/abilities]
            [/effect]
        [/object]
    [/event]
    
    [event]
        name=turn refresh
        first_time_only=no
        
        [if]
            [variable]
                name=south_rune_used
                equals=yes
            [/variable]
            [then]
                [object]
                    silent=yes
                    [filter]
                        side=$side_number
                        x,y=9,18
                    [/filter]
                    [effect]
                        apply_to=remove_ability
                        [abilities]
                            {ABILITY_REGENERATES}
                        [/abilities]
                    [/effect]
                [/object]
            [/then]
        [/if]
        {CLEAN_VARIABLE south_rune_used}
    [/event]
This will do healing exactly like village on any x y hex.
Ten soldiers wisely led will beat a hundred without a head.
User avatar
Sapient
Inactive Developer
Posts: 4453
Joined: November 26th, 2005, 7:41 am
Contact:

Re: Is there any way to filter units without ability?

Post by Sapient »

ah, very clever.

you should add this to the Useful WML Snippets page on the wiki
http://www.wesnoth.org/wiki/User:Sapient... "Looks like your skills saved us again. Uh, well at least, they saved Soarin's apple pie."
User avatar
pauxlo
Posts: 1049
Joined: September 19th, 2006, 8:54 pm

Re: Is there any way to filter units without ability?

Post by pauxlo »

Quetzalcoatl wrote:Thx :), somehow i missed it :(

Here is the WML that do healing between turn start and turn refresh (that means no problems with labels, healing animations, regeneration and such - maybe it would be useful for somebody else):

Code: Select all

...
This will do healing exactly like village on any x y hex.
I did not try this, but doesn't this remove the regeneration ability from units that already have them?
User avatar
zookeeper
WML Wizard
Posts: 9742
Joined: September 11th, 2004, 10:40 pm
Location: Finland

Re: Is there any way to filter units without ability?

Post by zookeeper »

pauxlo wrote:
Quetzalcoatl wrote:Thx :), somehow i missed it :(

Here is the WML that do healing between turn start and turn refresh (that means no problems with labels, healing animations, regeneration and such - maybe it would be useful for somebody else):

Code: Select all

...
This will do healing exactly like village on any x y hex.
I did not try this, but doesn't this remove the regeneration ability from units that already have them?
Good point. Something like this should fix that:

Code: Select all

            [effect]
                apply_to=new_ability
                [abilities]
                    {ABILITY_REGENERATES}
                    [+regenerate]
                        id=fakeregenerates
                    [/regenerate]
                [/abilities]
            [/effect]

Code: Select all

                    [effect]
                        apply_to=remove_ability
                        [abilities]
                            id=fakeregenerates
                        [/abilities]
                    [/effect]
User avatar
Quetzalcoatl
Posts: 207
Joined: March 18th, 2009, 3:26 pm

Re: Is there any way to filter units without ability?

Post by Quetzalcoatl »

It doesn't remove any attributes form units that have it already :) Thats why I asked how to filter units without ability ;) However regeneration with fake id its a lot better solution than having temp variables and extra conditions and I wasn't aware before that this can be done that way.

So here is the updated WML (as macro this time):

Code: Select all

#define HEALING_PLACE X Y
    [event]
        name=side turn
        first_time_only=no
        
        [object]
            silent=yes
            [filter]
                side=$side_number
                x,y={X},{Y}
            [/filter]
            [effect]
                apply_to=new_ability
                [abilities]
                    {ABILITY_REGENERATES}
                    [+regenerate]
                        id=fake_regenerates
                    [/regenerate]
                [/abilities]
            [/effect]
        [/object]
    [/event]
    
    [event]
        name=turn refresh
        first_time_only=no
        
        [object]
            silent=yes
            [filter]
                side=$side_number
                x,y={X},{Y}
            [/filter]
            [effect]
                apply_to=remove_ability
                [abilities]
                    [regenerate]
                        id=fake_regenerates
                    [/regenerate]
                [/abilities]
            [/effect]
        [/object]
    [/event]
#enddef
I will try to post this on wiki sometime soon.
Ten soldiers wisely led will beat a hundred without a head.
Post Reply