How to make one unit stop striking during an attack

The place to post your WML questions and answers.

Moderators: Forum Moderators, Developers

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.

Re: How to make one unit stop striking during an attack

Postby Celtic_Minstrel » January 16th, 2018, 2:18 am

Based on the wiki, you could likely copy the implementation of [store_unit_defense] into your addon and use it even on 1.12. I can't guarantee 100% that it will work, but I think there's a very good chance.
Author of The Black Cross of Aleron campaign and Default++ era.
Maintainer of Steelhive.
User avatar
Celtic_Minstrel
Developer
 
Posts: 919
Joined: August 3rd, 2012, 11:26 pm

Re: How to make one unit stop striking during an attack

Postby WhiteWolf » January 16th, 2018, 11:05 pm

I'll try that, thanks :)
Author of the Underness Series, consisting of V parts: The Desolation of Karlag, The Blind Sentinel, The Stone of the North, The Invasion Of The Western Cavalry, Fingerbone of Destiny
Standalone works: The Ravagers - now published!
User avatar
WhiteWolf
Forum Regular
 
Posts: 363
Joined: September 22nd, 2009, 7:48 pm
Location: Hungary

Re: How to make one unit stop striking during an attack

Postby Sapient » January 17th, 2018, 3:35 pm

Yeah, that's still not a total solution though, because it ignores things like leadership and weapon specials.
:?
I think there really needs to be an easier way to do this: either harm_unit needs enhancements so that it can completely emulate a normal strike, or there should be a new tag to do it.

Probably a new tag would be best... one can check defense, fires hit/miss/death events, apply damage, grant exp, and trigger all the relevant animations with ease.
http://www.wesnoth.org/wiki/User:Sapient... "Looks like your skills saved us again. Uh, well at least, they saved Soarin's apple pie."
User avatar
Sapient
Developer
 
Posts: 4396
Joined: November 26th, 2005, 7:41 am

Re: How to make one unit stop striking during an attack

Postby skeptical_troll » January 17th, 2018, 3:59 pm

hmm, I was curious about this and did some experiment myself. If instead of using the [modify_unit] tag I do manually the store-unstore business in an 'attack' event and set
Code: Select all
stored_unit_variable.attack[0].number=0
it does what you want. Am I missing something? :hmm: Of course, you need to take care of choosing the right attack to disable and to restore the right number at the end of the event, but I'm confident that should be pretty doable.

I tried this because I already noticed in the past that [modify_unit] doesn't work exactly as doing things manually, or using the {MODIFY_UNIT} macro.

EDIT: I see now that you want 'attacker_hits' and indeed it doesn't work. :augh: I'll leave this here anyway, it's weird that the behaviour is different for the two events.
User avatar
skeptical_troll
 
Posts: 326
Joined: August 31st, 2015, 11:06 pm

Re: How to make one unit stop striking during an attack

Postby octalot » January 17th, 2018, 5:02 pm

If you accepted the unit striking, but doing no damage, it could work like the EoMa Cyclops' growing fury special. In that special, each successful hit means that the following strikes do more damage, with adjustments for resistance and slows.

https://github.com/ProditorMagnus/Agele ... g-fury.cfg

But, I'm trying it today with a local game (1.12 in multiplayer mode), and the special works. I was hosting a game last night where another player had a cyclops, we didn't have any OOS reports, the other player reported it working and watching the replay I see the special working; however during the game itself the damage displayed to me when he hit enemies didn't change. So possibly the correct damage is only shown to the active player. The pre-fight damage calculations show it wrongly.

http://replays.wesnoth.org/1.12/2018011 ... _53_(92991).bz2

And, seeing as it might do what you want, you are now debugging it not me, kthxbye :lol:
octalot
 
Posts: 92
Joined: July 17th, 2010, 7:40 pm

Re: How to make one unit stop striking during an attack

Postby WhiteWolf » January 17th, 2018, 7:40 pm

Sapient wrote:Probably a new tag would be best... one can check defense, fires hit/miss/death events, apply damage, grant exp, and trigger all the relevant animations with ease.


Code: Select all
[simulate_attack]
    [filter]
        # attacker
    [/filter]
    [filter_second]
        # defender
    [/filter_second]
    [filter_weapon]
        # primary attack, if omitted, decided by attack_weight
    [/filter_weapon]
    [filter_second_weapon]
       # defense weapon, if omitted, decided by defense_weight
    [/filter_second_weapon]

    reduce_attacks = # if specified, subtracted from the attack numbers, defaults to 0
    # couple of booleans, like in [harm_unit]:
    kill, experience, fire_event, etc. = yes=/no
[/simulate_attack]

Here's what I'd call a total solution :)

skeptical_troll wrote: I see now that you want 'attacker_hits' and indeed it doesn't work. :augh:

Yeah :( A couple of posts back, I was guessing for an interpretation, attack event works because it's before the "fight is loaded", in attacker hits, modification can only take place after the fight.

octalot wrote:If you accepted the unit striking, but doing no damage, it could work like the EoMa Cyclops' growing fury special. In that special, each successful hit means that the following strikes do more damage, with adjustments for resistance and slows.

I think that's far from what is intended here :( It's not the damage that needs to be altered or anything.
Author of the Underness Series, consisting of V parts: The Desolation of Karlag, The Blind Sentinel, The Stone of the North, The Invasion Of The Western Cavalry, Fingerbone of Destiny
Standalone works: The Ravagers - now published!
User avatar
WhiteWolf
Forum Regular
 
Posts: 363
Joined: September 22nd, 2009, 7:48 pm
Location: Hungary

Re: How to make one unit stop striking during an attack

Postby octalot » January 17th, 2018, 9:12 pm

WhiteWolf wrote:
octalot wrote:If you accepted the unit striking, but doing no damage, it could work like the EoMa Cyclops' growing fury special. In that special, each successful hit means that the following strikes do more damage, with adjustments for resistance and slows.

I think that's far from what is intended here :( It's not the damage that needs to be altered or anything.
Although the animation would look different, I don't understand how "stops doing damage" is functionally different from "stops striking". Please would you explain, as it might help someone think of a way to do what you want.

My idea would be to modify the growing fury code to fit a description like this:

Trainer's Sabre: A duellist may wish to avoid the killing blow, allowing the opponent to fight a little longer. On the practise ground, where training should not be fatal, on the parade ground, where a fatal blow would be undiplomatic, or on the battlefield, to give a trainee the experience of the kill. Special notes: this attack hits normally when the opponent has enough hp to survive the blow, but does no damage if it would be the killing blow.
octalot
 
Posts: 92
Joined: July 17th, 2010, 7:40 pm

Re: How to make one unit stop striking during an attack

Postby WhiteWolf » January 17th, 2018, 9:33 pm

Sorry, I was a little ignorant here. Yes, it would make the desired result, but I discarded this solution at the very beginning, because of the animation issue. In my opinion, for the case where I'd like this effect, the unit that's supposed to stop the fight, would look weird and out of context, keeping hitting, just doing 0 damage.
I'm thinking now about ways to somehow hide the attack animations that happen there. Not sure if this is possible, somehow with [hide_unit] or, by removing temporarily the attack animations, I'll try and experiment with this :)
Author of the Underness Series, consisting of V parts: The Desolation of Karlag, The Blind Sentinel, The Stone of the North, The Invasion Of The Western Cavalry, Fingerbone of Destiny
Standalone works: The Ravagers - now published!
User avatar
WhiteWolf
Forum Regular
 
Posts: 363
Joined: September 22nd, 2009, 7:48 pm
Location: Hungary

Re: How to make one unit stop striking during an attack

Postby Celtic_Minstrel » January 18th, 2018, 1:25 am

Simulate attack is something that already exists (though only in Lua). So that tag you suggested might be able to be implemented even in 1.12.
Author of The Black Cross of Aleron campaign and Default++ era.
Maintainer of Steelhive.
User avatar
Celtic_Minstrel
Developer
 
Posts: 919
Joined: August 3rd, 2012, 11:26 pm

Re: How to make one unit stop striking during an attack

Postby Sapient » January 19th, 2018, 1:38 am

Celtic_Minstrel wrote:Simulate attack is something that already exists (though only in Lua). So that tag you suggested might be able to be implemented even in 1.12.


well, that’s pretty close. but it doesn’t take care of animating, damaging, granting kill exp. I still think it needs an official WML tag.

ideally when these C++ hooks are being added to Lua there should be a WML-only way of getting similar information committed at around the same time, for the benefit of those who don’t grok Lua.
http://www.wesnoth.org/wiki/User:Sapient... "Looks like your skills saved us again. Uh, well at least, they saved Soarin's apple pie."
User avatar
Sapient
Developer
 
Posts: 4396
Joined: November 26th, 2005, 7:41 am

Re: How to make one unit stop striking during an attack

Postby WhiteWolf » January 28th, 2018, 2:09 pm

I had the thing on rest for a while, but I finished experimenting, and the best result i'd say is... set the damage to zero.

Not sure if it's intentional or not, but when damage=0, always the miss animation is played, even when the unit should hit a do 0 damage. Kinda cool for the feature I want out of this, so "stop striking" is degraded to "stop delivering hits", but all effects are the same without compromises.

Here's the full code (now with the combating events passing over weapon info
Spoiler:


The fun thing is, if instead of iterating over the attack array, and finding the weapon with $weapon.name, I wanted to directly modify the unit, it doesn't work.
Code: Select all
[modify_unit]
    [filter]
        x,y=$x1,$y1
   [/filter]
   [attack]
       name=$weapon.name
       damage=0
   [/attack]
[/modify_unit]


What this does, is that it ALWAYS does the effect on the first attack (usually the melee for most units). So if the unit attacks with its attack[0] == sword, it works fine, but if it attacks with f.e. its bow, even though $weapon.name == bow will be correct, this modify_unit will still find and modify attack[0], the sword.
Not sure if this is a WML bug or not, but luckily it can be worked around.
Author of the Underness Series, consisting of V parts: The Desolation of Karlag, The Blind Sentinel, The Stone of the North, The Invasion Of The Western Cavalry, Fingerbone of Destiny
Standalone works: The Ravagers - now published!
User avatar
WhiteWolf
Forum Regular
 
Posts: 363
Joined: September 22nd, 2009, 7:48 pm
Location: Hungary

Re: How to make one unit stop striking during an attack

Postby Sapient » January 28th, 2018, 4:05 pm

WhiteWolf wrote:The fun thing is, if instead of iterating over the attack array, and finding the weapon with $weapon.name, I wanted to directly modify the unit, it doesn't work... What this does, is that it ALWAYS does the effect on the first attack (usually the melee for most units)... Not sure if this is a WML bug or not, but luckily it can be worked around.


That's not a bug. You are in fact modifying both the name and the damage for the first attack. If you want to use modify_unit and avoid writing your own loop, you could do it like this:

Code: Select all
{LOOKUP_INDEX unit.attack name $weapon.name weapon_index}
{SET_VARIABLE modify_attack[$weapon_index].damage 0}
[modify_unit]
   [filter]
       x,y=$x1,$y1
   [/filter]
   [insert_tag]
       name=attack
       variable=modify_attack
   [/insert_tag]
[/modify_unit]
{CLEAR_VARIABLE modify_attack}
http://www.wesnoth.org/wiki/User:Sapient... "Looks like your skills saved us again. Uh, well at least, they saved Soarin's apple pie."
User avatar
Sapient
Developer
 
Posts: 4396
Joined: November 26th, 2005, 7:41 am

Re: How to make one unit stop striking during an attack

Postby WhiteWolf » January 28th, 2018, 5:41 pm

So I see. Another insert_tag example :D Thanks :)
Author of the Underness Series, consisting of V parts: The Desolation of Karlag, The Blind Sentinel, The Stone of the North, The Invasion Of The Western Cavalry, Fingerbone of Destiny
Standalone works: The Ravagers - now published!
User avatar
WhiteWolf
Forum Regular
 
Posts: 363
Joined: September 22nd, 2009, 7:48 pm
Location: Hungary

Re: How to make one unit stop striking during an attack

Postby Celtic_Minstrel » January 29th, 2018, 12:47 am

If I recall correctly, in order to modify an attack other than the first with [modify_unit], you actually need to have empty [attack] tags. For modifying the second attack, you'd need one empty tag; for the third attack, two empty tags, and so on.

Sapient's example works because it takes the attacks as an array, changes the damage on the desired attack, then writes the array into the [modify_unit] tag - effectively overwriting all attacks at the same time.
Author of The Black Cross of Aleron campaign and Default++ era.
Maintainer of Steelhive.
User avatar
Celtic_Minstrel
Developer
 
Posts: 919
Joined: August 3rd, 2012, 11:26 pm

Previous

Return to WML Workshop

Who is online

Users browsing this forum: No registered users and 4 guests