Weapon filter not working

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.
Gibimbius
Posts: 14
Joined: June 3rd, 2018, 11:27 am

Re: Weapon filter not working

Post by Gibimbius »

newfrenchy83 wrote: April 5th, 2020, 3:28 pm try this
It works. Is there a clean way to make the unit reduce 5% to hit for each adjacent friendly unit? For instance, if there are 3 adjacent friendly units, it reduces 15% to hit in total
gfgtdf
Developer
Posts: 1432
Joined: February 10th, 2013, 2:25 pm

Re: Weapon filter not working

Post by gfgtdf »

I think you can you need to use a formula in sub that counts the number of adjacent friendly units, but im not sure of whihc unit it will count hte adjacent units.
Scenario with Robots SP scenario (1.11/1.12), allows you to build your units with components, PYR No preperation turn 1.12 mp-mod that allows you to select your units immideately after the game begins.
User avatar
Celtic_Minstrel
Developer
Posts: 2207
Joined: August 3rd, 2012, 11:26 pm
Location: Canada
Contact:

Re: Weapon filter not working

Post by Celtic_Minstrel »

gfgtdf wrote: April 4th, 2020, 7:33 pm In the general case yes, but if you use special_active and that weapon special itself has a filter, then special_active will only return true for the weapon that is currently used in the combat.
This sounds like a bug… shouldn't special_active return true if the attack has a special that's active? Where "active" means that it will take effect if the weapon were to be used right now… so, for example, you should be able to use it to test whether a rogue is in a valid position for backstabbing.
gfgtdf wrote: April 4th, 2020, 7:33 pm In fact [has_attack] has to be used over [filter_attack] in events that handle wepopn specials, see https://github.com/wesnoth/wesnoth/issues/3317 (this is iirc because [filter_attack] is evalated on a _copy_ of the attack object that was used in combat that has the attack context not set correctly.)
Well, obviously this bug really needs fixing…
gfgtdf wrote: April 5th, 2020, 9:26 pm I think you can you need to use a formula in sub that counts the number of adjacent friendly units, but im not sure of whihc unit it will count hte adjacent units.
WFL uses a function to get adjacent locations, so it would use whatever unit (or location) you tell it to.
Author of The Black Cross of Aleron campaign and Default++ era.
Former maintainer of Steelhive.
gfgtdf
Developer
Posts: 1432
Joined: February 10th, 2013, 2:25 pm

Re: Weapon filter not working

Post by gfgtdf »

Celtic_Minstrel wrote: April 6th, 2020, 1:22 pm
This sounds like a bug… shouldn't special_active return true if the attack has a special that's active? Where "active" means that it will take effect if the weapon were to be used right now… so, for example, you should be able to use it to test whether a rogue is in a valid position for backstabbing.
Hmm, hard to say i guess at least for weapon specials that don't depend on the attack context that would make sense, but if we change that please only do it on 1.15 since 1.14 addons depend on the current behaviour, and not without fixing the other bug before since the dependence on this behviour is a workaround for the other bug.
Celtic_Minstrel wrote: April 6th, 2020, 1:22 pm Well, obviously this bug really needs fixing…
yes
Scenario with Robots SP scenario (1.11/1.12), allows you to build your units with components, PYR No preperation turn 1.12 mp-mod that allows you to select your units immideately after the game begins.
User avatar
lhybrideur
Posts: 369
Joined: July 9th, 2019, 1:46 pm

Re: Weapon filter not working

Post by lhybrideur »

Gibimbius wrote: April 5th, 2020, 7:51 pm
newfrenchy83 wrote: April 5th, 2020, 3:28 pm try this
It works. Is there a clean way to make the unit reduce 5% to hit for each adjacent friendly unit? For instance, if there are 3 adjacent friendly units, it reduces 15% to hit in total
Maybe you could store adjacent units (case 1) or adjacent ally units (case 2) in a variable, then do a foreach over the variable and add one for each ally (case 1) or for each unit (case 2).
But there might be a lighter solution
newfrenchy83
Code Contributor
Posts: 172
Joined: October 6th, 2017, 12:57 pm

Re: Weapon filter not working

Post by newfrenchy83 »

Gibimbius wrote: April 5th, 2020, 7:51 pm
newfrenchy83 wrote: April 5th, 2020, 3:28 pm try this
It works. Is there a clean way to make the unit reduce 5% to hit for each adjacent friendly unit? For instance, if there are 3 adjacent friendly units, it reduces 15% to hit in total

Code: Select all

        [chance_to_hit]
	    id=dformation1
            name= _ ""
            description= _ "makes 5% harder to hit when next to a friend"
	    sub=5
	    apply_to=opponent
	    [filter_self]
	     [filter_adjacent]
	        is_enemy=no
                count=1-5
            [/filter_adjacent]
            [/filter_self]
        [/chance_to_hit]
        [chance_to_hit]
	    id=dformation2
	    sub=5
	    apply_to=opponent
	    [filter_self]
	     [filter_adjacent]
	        is_enemy=no
                count=2-5
            [/filter_adjacent]
            [/filter_self]
        [/chance_to_hit]
        [chance_to_hit]
	    id=dformation3
	    sub=5
	    apply_to=opponent
	    [filter_self]
	     [filter_adjacent]
	        is_enemy=no
                count=3-5
            [/filter_adjacent]
            [/filter_self]
        [/chance_to_hit]
        [chance_to_hit]
	    id=dformation4
	    sub=5
	    apply_to=opponent
	    [filter_self]
	     [filter_adjacent]
	        is_enemy=no
                count=4-5
            [/filter_adjacent]
            [/filter_self]
        [/chance_to_hit]
        [chance_to_hit]
	    id=dformation5
	    sub=5
	    apply_to=opponent
	    [filter_self]
	     [filter_adjacent]
	        is_enemy=no
                count=5
            [/filter_adjacent]
            [/filter_self]
        [/chance_to_hit]
this is similar to UTBS ability 'formation in wesnoth 1.15.2/3
Post Reply