Leadership value based on resistance?

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
Mathel
Posts: 39
Joined: May 26th, 2017, 1:34 pm

Leadership value based on resistance?

Post by Mathel »

I tried to make an ability that inhibits opponents' attacks based on how succeptible they are to arcane damage.
I tried both

Code: Select all

value=-$other.resistance.arcane
and

Code: Select all

value=-other.resistance.arcane
and neither of them does anything. I tested the rest of the ability by putting a constant instead (-35) and that worked, so I am pretty sure it is because of the value formula, but I can't determine what is wrong.
User avatar
Celtic_Minstrel
Developer
Posts: 2207
Joined: August 3rd, 2012, 11:26 pm
Location: Canada
Contact:

Re: Leadership value based on resistance?

Post by Celtic_Minstrel »

You're mixing up Wesnoth Formula Language and variable substitution. You don't need to use $ when it's a formula. So, that's why your first example doesn't work.

Your second formula doesn't work because resistance isn't what you appear to think it is. It doesn't contain resistance values like what's shown in the UI. It contains a percentage that all damage of that type is multiplied by. So, for example, if the secondary unit has 20% arcane resistance, then other.resistance.arcane evaluates to 80 – all arcane damage is multiplied by 80% (0.8). Or if the secondary unit has 10% arcane vulnerability, then other.resistance.arcane evaluates to 110 – all arcane damage is multiplied by 110% (1.1). So if you want the resistance value as shown in the UI, you need to subtract from 100: 100 - other.resistance.arcane.

Additionally, other.resistance.arcane is not the unit's actual resistance. It's the base resistance, which can then be modified by abilities (for example, the dwarven steadfast ability). If you want to use the real resistance value, then you need to use a function call:

Code: Select all

value="resistance_on(other, other.loc, 'arcane', 1)"
What that actually does is return the resistance the unit should have to arcane when attacking from its current location. If you change the 1 to a 0, it yields the resistance it would have if defending from an enemy attack. This calculation takes into effect all abilities, including buffs from adjacent units (similar to leadership). The value is as shown in the UI, not the multiplier stored in the raw data.
Author of The Black Cross of Aleron campaign and Default++ era.
Former maintainer of Steelhive.
User avatar
beetlenaut
Developer
Posts: 2825
Joined: December 8th, 2007, 3:21 am
Location: Washington State
Contact:

Re: Leadership value based on resistance?

Post by beetlenaut »

Never mind. Celtic_Minstrel's answer is more complete.
Campaigns: Dead Water,
The Founding of Borstep,
Secrets of the Ancients,
and WML Guide
Mathel
Posts: 39
Joined: May 26th, 2017, 1:34 pm

Re: Leadership value based on resistance?

Post by Mathel »

Code: Select all

value="resistance_on(other, other.loc, 'arcane', 1)"
also does nothing. I just tested that.
Celtic_Minstrel wrote: March 15th, 2023, 6:01 pm Your second formula doesn't work because resistance isn't what you appear to think it is. It doesn't contain resistance values like what's shown in the UI. It contains a percentage that all damage of that type is multiplied by. So, for example, if the secondary unit has 20% arcane resistance, then other.resistance.arcane evaluates to 80 – all arcane damage is multiplied by 80% (0.8). Or if the secondary unit has 10% arcane vulnerability, then other.resistance.arcane evaluates to 110 – all arcane damage is multiplied by 110% (1.1). So if you want the resistance value as shown in the UI, you need to subtract from 100: 100 - other.resistance.arcane.
I know what [resistance] tag does and I do want it to work how I wrote it. That is, a unit with 100% resistance (arcane=0) would not be affected, while a unit with 0 (arcane=100) or lower resistance would deal 0 damage. I even wrote that it is supposed to be based on succeptible they are.
Celtic_Minstrel wrote: March 15th, 2023, 6:01 pm Additionally, other.resistance.arcane is not the unit's actual resistance. It's the base resistance, which can then be modified by abilities (for example, the dwarven steadfast ability). If you want to use the real resistance value, then you need to use a function call:
I do think it should be affected by such effects as steadfast, which indeed the way I wrote would not do.
User avatar
Celtic_Minstrel
Developer
Posts: 2207
Joined: August 3rd, 2012, 11:26 pm
Location: Canada
Contact:

Re: Leadership value based on resistance?

Post by Celtic_Minstrel »

Mathel wrote: March 15th, 2023, 7:52 pm

Code: Select all

value="resistance_on(other, other.loc, 'arcane', 1)"
also does nothing. I just tested that.
I think the issue here is that I forgot an extra set of parentheses is needed to signal to the engine that it should be interpreted as a formula instead of a number. Try this:

Code: Select all

value="(100 - resistance_on(other, other.loc, 'arcane', 1))"
That also transforms the resistance value back to the format used in the tag, like you wanted, by subtracting it from 100.
Author of The Black Cross of Aleron campaign and Default++ era.
Former maintainer of Steelhive.
User avatar
Toranks
Translator
Posts: 168
Joined: October 21st, 2022, 8:59 pm
Location: Sevilla
Contact:

Re: Leadership value based on resistance?

Post by Toranks »

Why are you using value="formula" instead of value="$(formula)"? value= supports formula directly on abilities?
gnombat
Posts: 706
Joined: June 10th, 2010, 8:49 pm

Re: Leadership value based on resistance?

Post by gnombat »

Toranks wrote: March 16th, 2023, 9:29 am Why are you using value="formula" instead of value="$(formula)"? value= supports formula directly on abilities?
A formula can be used if it's in parentheses (see the previous comment).

From the wiki:
https://wiki.wesnoth.org/AbilitiesWML#Common_keys_and_tags_for_every_ability wrote:All keys inside any ability that expects a numeric value will also accept formulas using Wesnoth Formula Language. In order to use a formula in these keys, you must enclose it in parentheses. However, do not precede those parentheses with a dollar sign like $(...), since that will erase the self variable.
Mathel
Posts: 39
Joined: May 26th, 2017, 1:34 pm

Re: Leadership value based on resistance?

Post by Mathel »

Celtic_Minstrel wrote: March 16th, 2023, 12:15 am
Mathel wrote: March 15th, 2023, 7:52 pm

Code: Select all

value="resistance_on(other, other.loc, 'arcane', 1)"
also does nothing. I just tested that.
I think the issue here is that I forgot an extra set of parentheses is needed to signal to the engine that it should be interpreted as a formula instead of a number. Try this:

Code: Select all

value="(100 - resistance_on(other, other.loc, 'arcane', 1))"
That also transforms the resistance value back to the format used in the tag, like you wanted, by subtracting it from 100.
As it turns out, paretheses were the problem with my writing as well, though I will use your format, since it takes current circumstances into account.

Also, as it turns out,

Code: Select all

-other.resistance.arcane
uses the base resistance as shown to the player, not what is in the tag. When I got that to work with correct parentheses and tested it on a Dwarvish Lord, his attack was reduced by 10%, rather than 90%.

Anyway, once I got it to do something, getting it to do the correct thing was pretty easy. The final formula is

Code: Select all

value="(- 100 + resistance_on(other, other.loc, 'arcane', 0))"
with the affected unit being considered a defender against this ability.

So, thank you for your help.
Post Reply