How to get object adjusted net fire resistance of a unit?

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
winkr7
Posts: 53
Joined: May 16th, 2019, 2:09 pm

How to get object adjusted net fire resistance of a unit?

Post by winkr7 »

Hello all;

In a moveto event I don't want my unit to pick up a ring item if its already got 30 in fire resistance.
The unit may have already picked up 3 rings of fire resistance and be over 30, or perhaps it started with 30 naturally.
If terrain or time of day or nearby units adjusts fire resistance I don't want that to effect the [if] but I do want traits added in.
I basically want a "don't pick it up because your fire is already as high as it gets" option in the message.
How do I get the object and trait adjusted fire resistance (or any resistance) from the moveto event?
I want to [if] on the value so perhaps I should load it into a variable first.

thanks for your time
yours
winkr7
User avatar
beetlenaut
Developer
Posts: 2814
Joined: December 8th, 2007, 3:21 am
Location: Washington State
Contact:

Re: How to get object adjusted net fire resistance of a unit?

Post by beetlenaut »

You will have to calculate the adjustments to the resistance because there is no variable that holds the result of those calculations. Most likely, the engine also just recalculates it each time it needs to, which is why it's not stored.

Store the unit, then store the value of unit.resistance.fire in a variable called something like fire_res. (Technically, you need to store 100 minus fire.) Next, do a foreach on the unit.modifications.trait array. In the loop, check each id (of the trait) for something that changes the resistance, and add the appropriate amount to fire_res. Do the same thing for unit.modifications.object, then use fire_res to do your [if].

I hope that was sufficiently clear and detailed.
Campaigns: Dead Water,
The Founding of Borstep,
Secrets of the Ancients,
and WML Guide
User avatar
winkr7
Posts: 53
Joined: May 16th, 2019, 2:09 pm

Re: How to get object adjusted net fire resistance of a unit?

Post by winkr7 »

Thanks beetlenaut.
User avatar
Celtic_Minstrel
Developer
Posts: 2166
Joined: August 3rd, 2012, 11:26 pm
Location: Canada
Contact:

Re: How to get object adjusted net fire resistance of a unit?

Post by Celtic_Minstrel »

I was about ready to point out a [store_unit_resistance] tag, only to realize I was getting confused and the tag I was thinking about was storing defense, not resistance.

That said, you could try installing the Wesnoth Lua Pack. There might be such a tag in there.

Attempting to manually calculate the resistance as beetlenaut described can technically work but is a recipe for errors. I'd definitely recommend the Lua approach instead if you can stomach Lua or if WLP has the tag as an extension, because it does all those calculations for you using the exact code the engine uses, meaning it'll (almost) never be wrong.

(The "almost" is because there are cases where the exact scenario cannot be easily replicated in code, and that would alter the resistance value. For example, if someone had a resistance-leadership ability.)
Author of The Black Cross of Aleron campaign and Default++ era.
Former maintainer of Steelhive.
User avatar
Ravana
Forum Moderator
Posts: 2949
Joined: January 29th, 2012, 12:49 am
Location: Estonia
Contact:

Re: How to get object adjusted net fire resistance of a unit?

Post by Ravana »

If all else fails, store the unit, damage it with fire and see how much damage it took.
User avatar
winkr7
Posts: 53
Joined: May 16th, 2019, 2:09 pm

Re: How to get object adjusted net fire resistance of a unit?

Post by winkr7 »

Thanks for the suggestions Celtic_Minstrel and Ravana. You are correct, even with beetlenaut's helpful advice I found
the task difficult and I have yet to do it. I will probably think of some other way to limit how many fire rings you can use.

But thanks for the help.
yours
winkr7
Post Reply