How to make leadership apply only to mages

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
Alex_Stargazer
Posts: 7
Joined: December 19th, 2022, 8:42 pm

How to make leadership apply only to mages

Post by Alex_Stargazer »

Hi everyone,

I am trying to make an leadership ability where the damage bonus only applies to adjacent mages of a lower level. However, it doesn’t work; no unit gets a damage bonus, regardless of whether that unit is a mage or not. Would anyone be able to help?

Code: Select all

#define ABILITY_MAGICAL_LEADERSHIP
[leadership]
id=magical_leadership
name=_"magical leadership"
description=_"This unit provides a damage bonus to adjacent lower-level units that are mages."
affect_self=no
value="(25 * (level - other.level))"
[filter_student]
    [filter_weapon]
        special_id=magical
    [/filter_weapon]
[/filter_student]
[/leadership]
#enddef
User avatar
Ravana
Forum Moderator
Posts: 3017
Joined: January 29th, 2012, 12:49 am
Location: Estonia
Contact:

Re: How to make leadership apply only to mages

Post by Ravana »

[filter_weapon] is not recognized tag of https://wiki.wesnoth.org/StandardUnitFilter. Perhaps you mean [has_attack].
Alex_Stargazer
Posts: 7
Joined: December 19th, 2022, 8:42 pm

Re: How to make leadership apply only to mages

Post by Alex_Stargazer »

Ravana wrote: February 10th, 2023, 10:43 am [filter_weapon] is not recognized tag of https://wiki.wesnoth.org/StandardUnitFilter. Perhaps you mean [has_attack].
Well-spotted. But changing it to [has_attack] does not fix the problem unfortunately. I noticed that in Wesnoth's code, the leadership macro uses [affect_adjacent] so I tried that. Without affect_adjacent, it does nothing. With affect_adjacent, it works just like normal leadership (no filtering is applied) so I am guessing something is wrong with the filtering code?

EDIT: so the [filter_student] filter does not work. Either this is a bug or I am just using it wrong. It works fine when using the standard [filter] tag.

This does not work:

Code: Select all

#define ABILITY_MAGICAL_LEADERSHIP
[leadership]
id=magical_leadership
name=_"magical leadership"
description=_"This unit provides a damage bonus to adjacent lower-level units that are mages."
affect_self=no
value="(25 * (level - other.level))"
[affect_adjacent]
    [filter_student]
        [has_attack]
            special_id=magical
        [/has_attack]
    [/filter_student]
[/affect_adjacent]
[/leadership]
#enddef
But this does:

Code: Select all

#define ABILITY_MAGICAL_LEADERSHIP
[leadership]
id=magical_leadership
name=_"magical leadership"
description=_"This unit provides a damage bonus to adjacent lower-level units that are mages."
affect_self=no
value="(25 * (level - other.level))"
[affect_adjacent]
    [filter]
        [has_attack]
            special_id=magical
        [/has_attack]
    [/filter]
[/affect_adjacent]
[/leadership]
#enddef
User avatar
Spannerbag
Posts: 539
Joined: December 18th, 2016, 6:14 pm
Location: Yes

Re: How to make leadership apply only to mages

Post by Spannerbag »

Alex_Stargazer wrote: February 10th, 2023, 11:55 am EDIT: so the [filter_student] filter does not work. Either this is a bug or I am just using it wrong. It works fine when using the standard [filter] tag.
Weird.

I have this macro that works:

Code: Select all

#define ABILITY_PEASANT_LEADER
[leadership]
  id=peasant_leader
  value="(25 * level)"
  cumulative=no
  name= _ "peasant leader"
  female_name= _ "female^peasant leader"
  description= _ "This unit has significant military experience and by using encouragment and practical advice raises the morale of adjacent untrained combatants (peasantry) of the same side so they inflict more damage."
  special_note=_"This unit inspires adjacent zero level units of the same side to deal more damage in combat."
  affect_self=yes
  [affect_adjacent]
    [filter_student]
#      type=Peasant
      level=0
    [/filter_student]
  [/affect_adjacent]
[/leadership]#enddef
Screen dumps:
Leader
PL.png
Leader not adjacent
PL1.png
Leader adjacent
PL2.png
Leader correctly adds +50% damage (leader is L2).

I can only guess that as I don't use other.level (peasants are L0) then maybe with the student filter you need student.level?

EDIT: I know the wiki says otherwise but it might be worth trying anyway?

Just a thought, hope it helps.

Cheers!
-- Spannerbag
SP Campaigns: After EI (v1.14) Leafsea Burning (v1.17, v1.16)
I suspect the universe is simpler than we think and stranger than we can know.
Also, I fear that beyond a certain point more intelligence does not necessarily benefit a species...
Alex_Stargazer
Posts: 7
Joined: December 19th, 2022, 8:42 pm

Re: How to make leadership apply only to mages

Post by Alex_Stargazer »

Spannerbag wrote: February 10th, 2023, 12:32 pm
Alex_Stargazer wrote: February 10th, 2023, 11:55 am EDIT: so the [filter_student] filter does not work. Either this is a bug or I am just using it wrong. It works fine when using the standard [filter] tag.
Weird.

I have this macro that works:

Code: Select all

#define ABILITY_PEASANT_LEADER
[leadership]
  id=peasant_leader
  value="(25 * level)"
  cumulative=no
  name= _ "peasant leader"
  female_name= _ "female^peasant leader"
  description= _ "This unit has significant military experience and by using encouragment and practical advice raises the morale of adjacent untrained combatants (peasantry) of the same side so they inflict more damage."
  special_note=_"This unit inspires adjacent zero level units of the same side to deal more damage in combat."
  affect_self=yes
  [affect_adjacent]
    [filter_student]
#      type=Peasant
      level=0
    [/filter_student]
  [/affect_adjacent]
[/leadership]#enddef
Screen dumps:
LeaderPL.png

Leader not adjacent
PL1.png

Leader adjacent
PL2.png

Leader correctly adds +50% damage (leader is L2).

I can only guess that as I don't use other.level (peasants are L0) then maybe with the student filter you need student.level?

EDIT: I know the wiki says otherwise but it might be worth trying anyway?

Just a thought, hope it helps.

Cheers!
-- Spannerbag
It’s nice to see a working example. The difference between my code and your code is that I am using [has_attack] which for some reason does not work with [filter_student] but does work with the standard [filter]. I guess filter_student is not a StandardUnitFilter but something else. Anyway, I was able to get it working with just the normal filter, but thanks for the input!
User avatar
Celtic_Minstrel
Developer
Posts: 2238
Joined: August 3rd, 2012, 11:26 pm
Location: Canada
Contact:

Re: How to make leadership apply only to mages

Post by Celtic_Minstrel »

Yes, [filter_student] is not part of StandardUnitFilter. It's something only supported in a leadership-like ability, which means it can't be placed in [affect_adjacent] but can be placed beside [affect_adjacent].
Author of The Black Cross of Aleron campaign and Default++ era.
Former maintainer of Steelhive.
newfrenchy83
Code Contributor
Posts: 172
Joined: October 6th, 2017, 12:57 pm

Re: How to make leadership apply only to mages

Post by newfrenchy83 »

try that:

Code: Select all

#define ABILITY_MAGICAL_LEADERSHIP
[leadership]
id=magical_leadership
name=_"magical leadership"
description=_"This unit provides a damage bonus to adjacent lower-level units that are mages."
affect_self=no
value="(25 * (level - other.level))"
    [filter_weapon]
        special_id_active=magical
    [/filter_weapon]
    [affect_adjacent]
    [/affect_adjacent]
[/leadership]
#enddef
[filter_student] replace [filter_self] from weaponspecials when they are encoded in [abilities] tag but for [leadership] or [resistance] you must use directly [filter_weapon] or [filter_second_weapon]
newfrenchy83
Code Contributor
Posts: 172
Joined: October 6th, 2017, 12:57 pm

Re: How to make leadership apply only to mages

Post by newfrenchy83 »

and for peasant his is

Code: Select all

#define ABILITY_PEASANT_LEADER
[leadership]
  id=peasant_leader
  value="(25 * level)"
  cumulative=no
  name= _ "peasant leader"
  female_name= _ "female^peasant leader"
  description= _ "This unit has significant military experience and by using encouragment and practical advice raises the morale of adjacent untrained combatants (peasantry) of the same side so they inflict more damage."
  special_note=_"This unit inspires adjacent zero level units of the same side to deal more damage in combat."
  affect_self=yes
  [affect_adjacent]
    [filter]
#      type=Peasant
      level=0
    [/filter]
  [/affect_adjacent]
[/leadership]
#enddef
User avatar
Heindal
Posts: 1360
Joined: August 11th, 2011, 9:25 pm
Location: Germany, Karlsruhe
Contact:

Re: How to make leadership apply only to mages

Post by Heindal »

This is cool, I'm always stunned what I ideas there are out there for new abilities. Really cool.
@newfrenchy83

One question about your code:

[filter_weapon]
special_id_active=magical
[/filter_weapon]
[affect_adjacent]
[/affect_adjacent]

As far as I understand this code will not effect adjacent units, but all units with the special-id?
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
User avatar
Toranks
Translator
Posts: 168
Joined: October 21st, 2022, 8:59 pm
Location: Sevilla
Contact:

Re: How to make leadership apply only to mages

Post by Toranks »

[filter_weapon]: If present, the leadership ability only takes effect when the owner of the ability uses a matching weapon.
And

Code: Select all

 [affect_adjacent]
[/affect_adjacent]
Is the same as:

Code: Select all

 [affect_adjacent]
    adjacent=n,ne,se,s,sw,nw
[/affect_adjacent]
Which means it affects all adjacent units. So that if you want not to affect any, simply do not use any tag [affect_adjacent]

So I think the error is in [filter_weapon] It should be: [affect_adjacent] [filter] [has_attack] special_id_active=magical instead
newfrenchy83
Code Contributor
Posts: 172
Joined: October 6th, 2017, 12:57 pm

Re: How to make leadership apply only to mages

Post by newfrenchy83 »

the abilities affect all adjacent units of same side of owner who use weapon with special magical active, if you want affect all allies addd affect_allies=yes and affect_enemies =yes for enemies
newfrenchy83
Code Contributor
Posts: 172
Joined: October 6th, 2017, 12:57 pm

Re: How to make leadership apply only to mages

Post by newfrenchy83 »

if you want aplied to mage same when use non magical attack then filter_weapon not good idea, if you want applied to magical attack only, yes.
User avatar
Toranks
Translator
Posts: 168
Joined: October 21st, 2022, 8:59 pm
Location: Sevilla
Contact:

Re: How to make leadership apply only to mages

Post by Toranks »

newfrenchy83 wrote: February 14th, 2023, 6:46 pm if you want aplied to mage same when use non magical attack then filter_weapon not good idea, if you want applied to magical attack only, yes.
Doesn't special_id_active already do the work, which only matches if the weapon uses magical ability?
newfrenchy83
Code Contributor
Posts: 172
Joined: October 6th, 2017, 12:57 pm

Re: How to make leadership apply only to mages

Post by newfrenchy83 »

i want said special_id_active in [filter_weapon], and yes, only if weapn use special_ability(somespecial don't ever active)
Post Reply