how to deal halved damage on every strike that misses?

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
lea
Posts: 300
Joined: October 1st, 2016, 7:25 pm

how to deal halved damage on every strike that misses?

Post by lea »

I want all units to deal half their usual damage when they miss and full damage when they hit

damage can be inflicted with [harm] but need to know how much to inflict, taking into account all applicable abilities, weapon specials, traits, resistances etc
doing it manually is very error-prone
one possible shortcut is to find out the value of the WML variable damage_inflicted (https://wiki.wesnoth.org/EventWML#attacker_hits) before the strike happens (in attack event and in attacker hits / attacker misses events but for upcoming strike instead of the one that just happened and caused then event to fire)

another possible way to achieve that is to "roll the dice" for chance to hit in code to determine if upcoming strike should be a hit and if not then apply -50% damage by means of hidden [leadership] ability, also apply -100% opponent's defense to make it a sure hit
this forum topic contains a lua code that reads unit's defense for given terrain but seems to ignore other bonuses/penalties that can change resulting chance to hit:
viewtopic.php?t=45553

is the any way to get upcoming damage or current chance to hit from WML or lua?
author of: Altered Era/Ruleset (AKA "Altera"), latest version is on add-ons servers for BfW 1.16 and 1.14, latest version also still supports BfW 1.12 and 1.10, 1.10 server is stuck with older buggy version)
User avatar
beetlenaut
Developer
Posts: 2814
Joined: December 8th, 2007, 3:21 am
Location: Washington State
Contact:

Re: how to deal halved damage on every strike that misses?

Post by beetlenaut »

lea wrote: January 19th, 2022, 3:49 pm is the any way to get...current chance to hit from WML or lua?
There is a "defense" key in the standard unit filter. It sounds like it does what you need though I haven't tried it myself.
lea wrote: January 19th, 2022, 3:49 pmone possible shortcut is to find out the value of the WML variable damage_inflicted before the strike happens
You can't find that value in advance, but you could add some hitpoints back during an attacker_hits event. It is fired before any die event.
Campaigns: Dead Water,
The Founding of Borstep,
Secrets of the Ancients,
and WML Guide
User avatar
Jarom
Posts: 110
Joined: January 4th, 2015, 8:23 pm
Location: Green Isle, Irdya or Poland, Earth - I'm not quite sure

Re: how to deal halved damage on every strike that misses?

Post by Jarom »

I'd give up on accuracy and just use [harm_unit]. Attacker misses event automatically stores weapon and unit data, which you can use to fill in fields like damage type and alignment in [harm_unit], so the only thing you should account for IIRC would be weapon specials, in case of def charge and backstab. It's not perfect, but it's relatively easy to make.

Another imperfect solution would be a hack that ensures that first attack hits, then stores that value for later calculations. Both might find some obscure applications.
lea
Posts: 300
Joined: October 1st, 2016, 7:25 pm

Re: how to deal halved damage on every strike that misses?

Post by lea »

beetlenaut wrote: January 19th, 2022, 7:52 pmThere is a "defense" key in the standard unit filter. It sounds like it does what you need though I haven't tried it myself.
it would if it could be assigned to variable...
beetlenaut wrote: January 19th, 2022, 7:52 pmYou can't find that value in advance, but you could add some hitpoints back during an attacker_hits event. It is fired before any die event.
still have to increase to-hit chance to 100%, otherwise there is a chance that all strikes miss and damage inflicted will not be assigned during given combat encounter
Jarom wrote: January 19th, 2022, 9:04 pmI'd give up on accuracy and just use [harm_unit].
too many weapon specials to manually account for
also [leadership] ability can change damage
Last edited by lea on April 4th, 2022, 12:52 pm, edited 1 time in total.
author of: Altered Era/Ruleset (AKA "Altera"), latest version is on add-ons servers for BfW 1.16 and 1.14, latest version also still supports BfW 1.12 and 1.10, 1.10 server is stuck with older buggy version)
User avatar
beetlenaut
Developer
Posts: 2814
Joined: December 8th, 2007, 3:21 am
Location: Washington State
Contact:

Re: how to deal halved damage on every strike that misses?

Post by beetlenaut »

Yes, you use a 100% chance to hit because the enemy is always damaged by some amount. I don't think you need to store the defense value in a variable:
In an attacker_hits event, you choose a random number between 1 and 100. If it is below the enemy unit's defense (check with the filter in [have_unit]), then the enemy got hit, and you don't do anything else. Otherwise, you call it a "miss" and give back half of the damage_inflicted. Would that not do what you want?
Campaigns: Dead Water,
The Founding of Borstep,
Secrets of the Ancients,
and WML Guide
lea
Posts: 300
Joined: October 1st, 2016, 7:25 pm

Re: how to deal halved damage on every strike that misses?

Post by lea »

Ravana wrote: January 21st, 2022, 10:48 pm Example to store defense https://github.com/ProditorMagnus/Agele ... er.cfg#L76
beetlenaut wrote: January 19th, 2022, 7:52 pmThere is a "defense" key in the standard unit filter. It sounds like it does what you need though I haven't tried it myself.
both of these methods seem to yield unit's base defense (terrain-based component of defense) without adjustments for attack specials
got to take them into account manually
author of: Altered Era/Ruleset (AKA "Altera"), latest version is on add-ons servers for BfW 1.16 and 1.14, latest version also still supports BfW 1.12 and 1.10, 1.10 server is stuck with older buggy version)
Post Reply