apply_to=max_attacks negative increase 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.
Post Reply
User avatar
lhybrideur
Posts: 355
Joined: July 9th, 2019, 1:46 pm

apply_to=max_attacks negative increase not working?

Post by lhybrideur »

Hi everyone,
I want to create an unit that cannot attack but can defend.
To do so, I apply a modification

Code: Select all

	[modifications]
            [object]
                [effect]
                    apply_to=max_attacks
                    increase=-1
                [/effect]
            [/object]
        [/modifications]
This does not work, although the wiki says it should.
However, if I change -1 to 1, it works and the unit has two attacks.
I cannot simply modify the unit, because I want the leveled up unit to still have no attack.

Any idea?
User avatar
Pentarctagon
Project Manager
Posts: 5496
Joined: March 22nd, 2009, 10:50 pm
Location: Earth (occasionally)

Re: apply_to=max_attacks negative increase not working?

Post by Pentarctagon »

I believe it's possible to have an attack that's enabled on offense and disabled for defense, rather than setting max_attacks to 0 when defending? I'm like 98% sure I've seen that done, but I can't remember how or where at the moment.
99 little bugs in the code, 99 little bugs
take one down, patch it around
-2,147,483,648 little bugs in the code
dwarftough
Posts: 478
Joined: August 4th, 2019, 5:27 pm

Re: apply_to=max_attacks negative increase not working?

Post by dwarftough »

Can use this kind of weapon special

Code: Select all

    [disable]
        id=steppe_attack_only
        name=_"attack-only"
        description=_"This attack can only be used offensively."
        active_on=defense
    [/disable]
    
Co-founder and current maintainer of IsarFoundation, Afterlife Rated and overall Wesnoth Autohost Project
Developer and maintainer of my fork of World Conquest, Invincibles Conquest II
User avatar
Lord-Knightmare
Discord Moderator
Posts: 2337
Joined: May 24th, 2010, 5:26 pm
Location: Somewhere in the depths of Irdya, gathering my army to eventually destroy the known world.
Contact:

Re: apply_to=max_attacks negative increase not working?

Post by Lord-Knightmare »

I want to create an unit that cannot attack but can defend.
Steppe Shieldbearer. Steppe Orcs. Extended Era.
Creator of "War of Legends"
Creator of the Isle of Mists survival scenario.
Maintainer of Forward They Cried
User:Knyghtmare | My Medium
User avatar
lhybrideur
Posts: 355
Joined: July 9th, 2019, 1:46 pm

Re: apply_to=max_attacks negative increase not working?

Post by lhybrideur »

Yes but this is a standard unit (White Mage), who is coming with the hero for its own reasons. He do not want to get involved, so I do not want it to be able to attack.
I solved the problem with a standard max_attacks=0 in the [unit] and in a post advance event.

However, I think the code I posted in the initial message is supposed to work. Otherwise it should be written in the wiki that this cannot reduce max_attacks to 0.
dwarftough
Posts: 478
Joined: August 4th, 2019, 5:27 pm

Re: apply_to=max_attacks negative increase not working?

Post by dwarftough »

lhybrideur wrote: September 24th, 2022, 3:06 pm Yes but this is a standard unit (White Mage), who is coming with the hero for its own reasons. He do not want to get involved, so I do not want it to be able to attack.
I think in that case of a standard unit the best would be

Code: Select all

        [modifications]
            [object]
                [effect]
                    apply_to=attack
                    [set_specials]
                         mode=append
                         [disable]
                             name=_"attack-only"
                             description=_"This attack can only be used offensively."
                             active_on=defense
                         [/disable]
                    [/set_specials]
                [/effect]
            [/object]
        [/modifications]
Just add this weapon special to the unit, it should be sufficient without extra events (it won't reset when level up)
Co-founder and current maintainer of IsarFoundation, Afterlife Rated and overall Wesnoth Autohost Project
Developer and maintainer of my fork of World Conquest, Invincibles Conquest II
User avatar
Ravana
Forum Moderator
Posts: 2934
Joined: January 29th, 2012, 12:49 am
Location: Estonia
Contact:

Re: apply_to=max_attacks negative increase not working?

Post by Ravana »

lhybrideur wrote: September 24th, 2022, 3:06 pm Yes but this is a standard unit (White Mage), who is coming with the hero for its own reasons. He do not want to get involved, so I do not want it to be able to attack.
I solved the problem with a standard max_attacks=0 in the [unit] and in a post advance event.

However, I think the code I posted in the initial message is supposed to work. Otherwise it should be written in the wiki that this cannot reduce max_attacks to 0.
I think it is useful that it does not go under 1, so I would preserve it in documentation.
User avatar
Celtic_Minstrel
Developer
Posts: 2158
Joined: August 3rd, 2012, 11:26 pm
Location: Canada
Contact:

Re: apply_to=max_attacks negative increase not working?

Post by Celtic_Minstrel »

Did you try set=0 instead of increase=-1? It seems closer to your intention anyway, since the idea is for the unit to be unable to attack at all. Decreasing max attacks by 1 doesn't do that, it just decreases max attacks by 1, so if it was 2, now the unit can attack twice in a turn.

The code you posted should also work, however. There's probably a bug here.
Author of The Black Cross of Aleron campaign and Default++ era.
Former maintainer of Steelhive.
User avatar
beetlenaut
Developer
Posts: 2813
Joined: December 8th, 2007, 3:21 am
Location: Washington State
Contact:

Re: apply_to=max_attacks negative increase not working?

Post by beetlenaut »

Celtic_Minstrel wrote: September 29th, 2022, 4:26 am The code you posted should also work, however. There's probably a bug here.
There is: The attack is never filtered for. It can't match anything, so it can't be applied. ( EffectWML)
Campaigns: Dead Water,
The Founding of Borstep,
Secrets of the Ancients,
and WML Guide
User avatar
lhybrideur
Posts: 355
Joined: July 9th, 2019, 1:46 pm

Re: apply_to=max_attacks negative increase not working?

Post by lhybrideur »

From the wiki, I read:
[effect] uses different keys depending on the value of apply_to. apply_to can take the following values:
  • attack: find an attack and modify it. All tags from the attack filter construct will be used to match the attack; see FilterWML. After that, the following keys and tags can be used to modify the attack. Note: do not use a [filter] tag. Just put the keys you want to filter on inside the [effect] tag.
    • increase_attacks: increases the number of attack strikes. Like increase_damage, it can be positive or negative, or a percentage.
  • max_attacks: (Version 1.13.2 and later only) change the unit's maximum attacks per turn
    • increase: how much to increase by; can be positive or negative, or a percentage
Celtic_Minstrel wrote: September 29th, 2022, 4:26 am Did you try set=0 instead of increase=-1? It seems closer to your intention anyway, since the idea is for the unit to be unable to attack at all. Decreasing max attacks by 1 doesn't do that, it just decreases max attacks by 1, so if it was 2, now the unit can attack twice in a turn.

The code you posted should also work, however. There's probably a bug here.
So there does not seems to be a "set" key for max_attacks
beetlenaut wrote: September 29th, 2022, 7:31 am
Celtic_Minstrel wrote: September 29th, 2022, 4:26 am The code you posted should also work, however. There's probably a bug here.
There is: The attack is never filtered for. It can't match anything, so it can't be applied. ( EffectWML)
max_attacks is a key of effect not of attacks. Do you mean increase_attacks?
User avatar
beetlenaut
Developer
Posts: 2813
Joined: December 8th, 2007, 3:21 am
Location: Washington State
Contact:

Re: apply_to=max_attacks negative increase not working?

Post by beetlenaut »

lhybrideur wrote: September 29th, 2022, 1:15 pm max_attacks is a key of effect not of attacks. Do you mean increase_attacks?
I don't know what you're asking, but I guess I was not clear. The code I was referring to was, "The code you posted...", where "you" is dwarftough. The comments explain where I think the error is:

Code: Select all

       
[modifications]
    [object]
        [effect]
            apply_to=attack
            # When you use "apply_to=attack", you also need weapon filters here like:
          # range=melee
          # type=blade
            [set_specials]
                mode=append
                [disable]
                     name=_"attack-only"
                     description=_"This attack can only be used offensively."
                     active_on=defense
                [/disable]
            [/set_specials]
        [/effect]
    [/object]
[/modifications]
In case this is still relevant for someone.
Campaigns: Dead Water,
The Founding of Borstep,
Secrets of the Ancients,
and WML Guide
User avatar
Straff
Posts: 83
Joined: September 27th, 2020, 2:53 pm

Re: apply_to=max_attacks negative increase not working?

Post by Straff »

Code: Select all

attack_weight: helps the AI to choose which attack to use when attacking, setting it to 0 disables the attack on attack. See the note about weights below.
https://wiki.wesnoth.org/UnitTypeWML#Attacks
User avatar
Celtic_Minstrel
Developer
Posts: 2158
Joined: August 3rd, 2012, 11:26 pm
Location: Canada
Contact:

Re: apply_to=max_attacks negative increase not working?

Post by Celtic_Minstrel »

beetlenaut wrote: September 29th, 2022, 7:31 am
Celtic_Minstrel wrote: September 29th, 2022, 4:26 am The code you posted should also work, however. There's probably a bug here.
There is: The attack is never filtered for. It can't match anything, so it can't be applied. ( EffectWML)
Your words do not seem to apply to this situation in the slightest. There is no attack involved in this modification, and the max_attacks effect does not use a filter. If the code shown in the opening post is placed in a place where it has an effect (in this case, a [unit] tag or possibly [modify_unit]), then it should work.

Although, maybe that's the issue? Where was that code placed?
lhybrideur wrote: September 29th, 2022, 1:15 pm So there does not seems to be a "set" key for max_attacks
Interesting. It could be worth trying anyway in case it exists but is undocumented, though.
beetlenaut wrote: September 29th, 2022, 1:45 pm I don't know what you're asking, but I guess I was not clear. The code I was referring to was, "The code you posted...", where "you" is dwarftough.
Ohhh. I was referring to the code in the opening post. No wonder your response made no sense.
Author of The Black Cross of Aleron campaign and Default++ era.
Former maintainer of Steelhive.
User avatar
lhybrideur
Posts: 355
Joined: July 9th, 2019, 1:46 pm

Re: apply_to=max_attacks negative increase not working?

Post by lhybrideur »

Straff wrote: September 29th, 2022, 2:14 pm

Code: Select all

attack_weight: helps the AI to choose which attack to use when attacking, setting it to 0 disables the attack on attack. See the note about weights below.
https://wiki.wesnoth.org/UnitTypeWML#Attacks
That is really interesting!!! I will try that.

EDIT: I just realized that this would only work with a AI unit, not one controlled by the player, would it?
Celtic_Minstrel wrote: September 30th, 2022, 1:22 amYour words do not seem to apply to this situation in the slightest. There is no attack involved in this modification, and the max_attacks effect does not use a filter. If the code shown in the opening post is placed in a place where it has an effect (in this case, a [unit] tag or possibly [modify_unit]), then it should work.

Although, maybe that's the issue? Where was that code placed?
Yes, it was in an [unit] tag.
Last edited by lhybrideur on October 2nd, 2022, 6:54 pm, edited 1 time in total.
User avatar
Celtic_Minstrel
Developer
Posts: 2158
Joined: August 3rd, 2012, 11:26 pm
Location: Canada
Contact:

Re: apply_to=max_attacks negative increase not working?

Post by Celtic_Minstrel »

Then yes, that should have worked. This sounds like a bug.
Author of The Black Cross of Aleron campaign and Default++ era.
Former maintainer of Steelhive.
Post Reply