Page MenuHomeWildfire Games

Delayed damage with projectile hit animation
ClosedPublic

Authored by Mate-86 on Jul 16 2017, 9:46 PM.

Details

Reviewers
fatherbushido
Group Reviewers
Restricted Owners Package(Owns No Changed Paths)
Commits
rP20204: Delayed damage. When a projectile hits the ground, it makes its damage (or its…
Trac Tickets
#1909
#1911
Summary

I. Business logic

  • The projectile hits the target or the ground and then cause damage after some delay (like a grenade).
  • Projectile hit sound (explosion sound) is played as delayed in a separate ticket: #4779
  • Projectile hit animation will be implemented in a separate ticket: #1909

II. Technical consideration

  • Mandatory "Delay" property to be added to Attack component as a child of Ranged element (plus updating all the relevant templates with Delay=0).
Test Plan
  • Not sure if it makes sense to write a unit test for the delayed damage (this can slow down the test execution)
  • Testing in real game with the rock thrower where delay and projectile hit animations are set. (Test data from that template can be removed when merging the patch)

Diff Detail

Lint
Lint Skipped
Unit
Unit Tests Skipped

Event Timeline

Mate-86 created this revision.Jul 16 2017, 9:46 PM
Mate-86 updated this revision to Diff 2916.Jul 16 2017, 9:50 PM
leper added reviewers: fatherbushido, Restricted Owners Package.Jul 17 2017, 7:04 PM
leper added a subscriber: leper.

I'd probably make the delay (which currently can already be 0) non-optional, so you don't have to worry about it not being there.

fatherbushido edited edge metadata.Aug 3 2017, 4:46 PM

(It would be easy to merge with D451.)

fatherbushido added a comment.EditedAug 10 2017, 7:07 PM

@Mate-86:

I think you should do the work only in the damage component (it's perhaps time to add splash for melee attack too).
It seems also we can include #1910 in that one: a delay time and a repeat time?

I wonder also if we couldn't do them for single target too (as something like poisoning)?

I will look at the graphical thing.

edit: I will think at that again...

In D748#29339, @leper wrote:

I'd probably make the delay (which currently can already be 0) non-optional, so you don't have to worry about it not being there.

If I remove optional on delay then I get errors: "RelaxNGValidator: Validation error: (null):0: Extra element in interleave ..."

@Mate-86:

I think you should do the work only in the damage component (it's perhaps time to add splash for melee attack too).

That's fine but do you mean the graphical part can be done solely in Damage component or do you mean excluding the graphical part from this ticket?

It seems also we can include #1910 in that one: a delay time and a repeat time?

#1910 is DeathDamage and already merged. Don't you mean including #1912 which is "Continuous damage after hit detection"?

I wonder also if we couldn't do them for single target too (as something like poisoning)?

Doing the delayed damage for a single target can be done but this must be well specified. Are those units affected which present when the projectile hits the ground (eg. poisoned and suffer later) or those which are present only after a delayed time (eg. grenade exploding delayed)?

I will look at the graphical thing.

edit: I will think at that again...

That would be great. The delayed damage without the delayed animation looks a bit lame.

Stan added a subscriber: Stan.Aug 13 2017, 7:09 PM

Did you update the xml templates accordingly after making the tag non optional ?

In D748#31188, @Stan wrote:

Did you update the xml templates accordingly after making the tag non optional ?

Nope. Do you think I should update all the occurrences for existing unit templates (I've found 5 so far)?

Stan added a comment.Aug 20 2017, 9:52 PM

If you make a field non optional you have to put it in every template

Back to this.

I was a bit confused with the design and what was really wanted.
So to sum up, the use case would be "Grenade". So the projectile hit the target or the ground and then cause damage after some delay.

The usecase makes me feel it should indeed be an area (splash) damage.

In the current diff, we launch the graphical animation, then call the collision detection with the delay.
So:

  • we can't do a damage then do a delayed damage.
  • if we let value for the not slash damage, that thing will be done also with a delayed damage.

I am fine with that design (there are other possibilities). In that case, there is no need to let the delay value in the splash schema (you can put it one level higher). And making it mandatory as leper said.

For the animation (#1909) I would suggest to split that. It's the complicated part.
We can just focus on the sound right now.
Btw, I notice a defect about that. We call the impact sound with the ent which is perhaps dead meanwhile.
That should perhaps be rethink. (Like parsing the sound name and calling the SoundManager component instead of Sound component.)
The other possibility could be to add an impact sound to the target entity. (There is the same question for the impact animation).
Though that's not exactly a good idea as in the delayed case we want to have an explosion sound even if we don't hit anything.

So except fixing the no sound when attacker is dead issue, I think we should add an attack_explosion or attack_delayed sound group which will be call at the same place than cmpProjectileManager->PlayProjectileHitAnimation(data.attacker, data.position); or even just at the start of MissileHit.

binaries/data/mods/public/globalscripts/Templates.js
169 ↗(On Diff #2916)

In our coding convention , we use

if (condition)
{
}
binaries/data/mods/public/simulation/components/Damage.js
118 ↗(On Diff #2916)

Sounds good. Leting that todo will help, see leper to know if it's a good practise or not.
We can perhaps consider putting that at line 90.

Mate-86 retitled this revision from Delayed damage with projectile hit animation [Work in progress] to Delayed damage with projectile hit animation.Aug 27 2017, 5:30 PM
Mate-86 edited the summary of this revision. (Show Details)

@Stan @fatherbushido Thanks for the comments! I've updated the ticket description, please have a look! I'm checking the sound change and uploading a new diff soon.

Mate-86 updated this revision to Diff 3339.Aug 27 2017, 7:27 PM

The latest diff contains:

  • making Delay as a mandatory child of Ranged element
  • adding sound to missileHit (temporarily hardcoded the building destruction but can be defined in the template later)
Stan added a comment.Aug 27 2017, 7:30 PM

I'm wondering if you can't reduce that diff by using template inheritance for some of them.

Mate-86 updated this revision to Diff 3345.Aug 27 2017, 8:14 PM

diff reduced by using template inheritance

I am fine with your implementation.
(We have to know that:

  • it will do splash damage if enabled then it will try to hit a single unit if hit (So it's basically adding a delay to the hit detection to our current system.)
  • we can't do damage before the delay

Just for the sum up)
We will keep the 0 delay for the onager (catapult) in the game, I guess we expect immediate damage for it. I don't really see any usecase in the public mod. Though we could think of some easter egg.

There is still the sound part to rework.

(I will also open a ticket for the attack_impact bug)

binaries/data/mods/public/simulation/components/Damage.js
118 ↗(On Diff #3345)

That would fail (no sound) if the attacker is dead (or even garrisoned) which is annoying in that usecase.
I have no real idea on how to fix that exactly without adding something to the sound manager.

Take care that currently, we'll always have this sound :)

Stan added inline comments.Aug 28 2017, 11:51 AM
binaries/data/mods/public/simulation/components/Attack.js
144

Shouldn't there be line breaks here for consistency ?

529

Any reason for that temp variable ?

fatherbushido added inline comments.Aug 28 2017, 12:01 PM
binaries/data/mods/public/simulation/components/Attack.js
144

It's at least consistent with the entry above, isn't it?

529

(sure he will inline that)

:-X

Stan added inline comments.Aug 28 2017, 12:03 PM
binaries/data/mods/public/simulation/components/Attack.js
144

Yes you're right

Mate-86 edited the summary of this revision. (Show Details)Aug 28 2017, 8:27 PM
Mate-86 edited the test plan for this revision. (Show Details)
Mate-86 marked an inline comment as done.
Mate-86 added inline comments.
binaries/data/mods/public/simulation/components/Attack.js
529

next patch will fixed that :)

binaries/data/mods/public/simulation/components/Damage.js
118 ↗(On Diff #3345)

How about introducing a new component for Projectile to make such features independent from the attacker or the target. Would it be a big performance overhead? How about creating the projectile for the special attack (eg. delayed damage, continuous damage)? Using the attacker entity seems to be a problem because the sound is played on the wrong position.

118 ↗(On Diff #3345)

Take care that currently, we'll always have this sound :)

How about adding the sound to the template of the attacker? eg.
Sound/SoundGroups/missile_hit? (attack_impact is already used to play the sound when the projectile causes damage to the target.)

fatherbushido added inline comments.Aug 28 2017, 10:12 PM
binaries/data/mods/public/simulation/components/Damage.js
118 ↗(On Diff #3345)

For the second remark, sure we should add such a sound to the soundgroup.
We'll need to grab the name of the sound while we are in attack component and add that name to that object parsed to the damage component.
(In fact we should do the same for the attack_impact sound -> that could/should be done too in another diff).

118 ↗(On Diff #3345)

For that first remark, if you mean adding a projectile entity, that sounds a bad idea.
For the graphical point of view, we have no problem imo.
For the sound, the SoundManager is a system entity so it should be ok, but it needs the entity to grab a position for displaying the sound. It seems we should add another method (just giving a position and not doing that job in SoundManager).

Mate-86 updated this revision to Diff 3377.Aug 29 2017, 9:39 PM
Mate-86 marked 11 inline comments as done.Aug 29 2017, 9:47 PM
Mate-86 added inline comments.
binaries/data/mods/public/simulation/components/Damage.js
118 ↗(On Diff #3345)

I meant adding the projectile as an entity with it's own update cycle so that the more complex logic (animation, delay, continuous damage, etc.) can be handled there. I'm fine to these features via Damage component but it's getting hacky over time.

Shall I implement the cpp function as part of this patch? If yes I'll have some futher questions.

118 ↗(On Diff #3345)

Done in the latest patch. The missile hit sound is only played if it's defined in the unit template.

add that name to that object parsed to the damage component

Did you mean "the object passed (as argument) to the damage component"?

Stan added inline comments.Aug 29 2017, 9:51 PM
binaries/data/mods/public/simulation/components/Damage.js
118 ↗(On Diff #3345)

Would be cool, so we could have particles effects on projectiles, on throw, while flying, and when hitting. Would be useful for gun units

Mate-86 marked 2 inline comments as done.Aug 29 2017, 10:00 PM
Mate-86 added inline comments.
binaries/data/mods/public/simulation/components/Damage.js
118 ↗(On Diff #3345)

I meant the cpp function using the position instead of the entity for playing a soundGroup. :)
Implementing visuals should go to separate ticket: #1909

(That sound thing is a bit annoying)
Don t hesitate to suggest other design.

binaries/data/mods/public/simulation/components/Attack.js
519

soundGroupName is perhaps too generic? We should perhaps parse the attack_impact sound name too.

binaries/data/mods/public/simulation/components/Damage.js
118 ↗(On Diff #3345)

yes,that's it. Nice.

118 ↗(On Diff #3345)

I am not really for proj entity. Some system entity should handle damage and manage those projectiles. We should try to not be hacky while adding those features.

Imo keep the cpp sound function for nother diff (with also the attack_impact issue)

(That sound thing is a bit annoying)
Don t hesitate to suggest other design.

OK, shall I raise a ticket for implementing this new cpp function to play sound based on the position (and pass attack_impact sound name to damage component too)? It's enough to create the Differential ticket and no need for new Trac ticket right?

binaries/data/mods/public/simulation/components/Attack.js
519

How about missileHitSound or missileHitSoundGroupName or any better idea?

fatherbushido resigned from this revision.Aug 30 2017, 11:27 PM

I won t finish reviewing. But that s a good work.

(Well, I fixed some stuff sooner than expected)

! In D748#33385, @Mate-86 wrote:
OK, shall I raise a ticket for implementing this new cpp function to play sound based on the position (and pass attack_impact sound name to damage component too)? It's enough to create the Differential ticket and no need for new Trac ticket right?

Yes, let's keep that for another diff, you can open a ticket if you don't have time to work on it (or idea to fix it).

binaries/data/mods/public/simulation/components/Attack.js
519

Finally, I wonder that missile explosion sound could be the attack_impact one? Or do we need two different sounds?

Else such a name (the shortest one) is ok.

Mate-86 added inline comments.Sep 17 2017, 11:05 AM
binaries/data/mods/public/simulation/components/Attack.js
519

Imagine the case when the grenade hits the ground and a sound is played for the hit but after the delay another sound is used for the explosion.

missileHitSound and attackImpactSound are easy to mix up so that I'd use smg like explosionSound instead of missileHitSound. What do you think?

fatherbushido added inline comments.Sep 17 2017, 11:09 AM
binaries/data/mods/public/simulation/components/Attack.js
519

Uhm you are right.
Perhaps you can choose the easy way to do all the sound things in another diff :=)

Mate-86 added inline comments.Sep 17 2017, 11:15 AM
binaries/data/mods/public/simulation/components/Attack.js
519

Well, anything else to solve as part of this diff? :)
I'm happy to continue the work in the other diff (sound renaming, new cpp function etc.)

fatherbushido added inline comments.Sep 17 2017, 12:15 PM
binaries/data/mods/public/simulation/components/Attack.js
519

Well I precise what I meant in that other inline comment.
We can also just remove all the sound thing of that diff so I could (restest and) commit it.

binaries/data/mods/public/simulation/components/Damage.js
272 ↗(On Diff #3377)

In case, I wasn't clear enough, that thing is to fix too.

Despite that, what I meant previously is:
with current state of the patch, it's a bit confusing to have (for ranged attack):
missile_hit -> always sent
attack_impact -> sent when units are damaged

Mate-86 updated this revision to Diff 3700.Sep 17 2017, 10:02 PM

The updated diff should contain the delay feature related change. Changes related to the sound and animation will come in later diffs.

Mate-86 edited the summary of this revision. (Show Details)Sep 17 2017, 10:31 PM
This revision is now accepted and ready to land.Sep 18 2017, 6:51 PM
This revision was automatically updated to reflect the committed changes.

Thx for the patch and for the incoming ones.

LOL nice test evidence video! :D