[Already In] Extend ModifyDamage to have target information

Moderator: GZDoom Developers

Extend ModifyDamage to have target information

Postby SanyaWaffles » Mon Jan 27, 2020 5:07 pm

I was kind of shocked to see ModifyDamage in the Powerups section didn't have any information about the enemy you are damaging... I had an idea for a powerup that won't QuadDamage any enemies with the +Boss flag. Problem is right now it seems there's no easy way to get this info.

I'm sure there's a way to do this without this, but this would be more convenient. I dunno how it'd be extended though.
User avatar
SanyaWaffles
Navy Did Nothing Wrong
Global Moderator
 
Joined: 25 Apr 2013
Location: Eastern Ohio
Discord: SanyaWaffles#5095
Twitch ID: sanyawaffles
Operating System: Windows 10/8.1/8 64-bit
OS Test Version: No (Using Stable Public Version)
Graphics Processor: nVidia with Vulkan support

Re: Extend ModifyDamage to have target information

Postby Major Cooke » Mon Jan 27, 2020 5:11 pm

This has been in for a while now. Includes the inflictor, source, and damage flags.

Code: Select allExpand view
virtual void ModifyDamage(int damage, Name damageType, out int newdamage, bool passive, Actor inflictor = null, Actor source = null, int flags = 0) {}
User avatar
Major Cooke
d = klabs(wall[wall[wall[sector[dasect].wallptr].point2].point2].x-s->x)...
Global Moderator
 
Joined: 28 Jan 2007

Re: Extend ModifyDamage to have target information

Postby SanyaWaffles » Mon Jan 27, 2020 5:18 pm

Can you explain to me which one I'd need to use to get the +Boss flag from the enemy being attacked? That's what I'm lost on. I don't think either inflictor nor source serve my purpose. I want a field on the thing being attacked, not the attacker.
User avatar
SanyaWaffles
Navy Did Nothing Wrong
Global Moderator
 
Joined: 25 Apr 2013
Location: Eastern Ohio
Discord: SanyaWaffles#5095
Twitch ID: sanyawaffles
Operating System: Windows 10/8.1/8 64-bit
OS Test Version: No (Using Stable Public Version)
Graphics Processor: nVidia with Vulkan support

Re: Extend ModifyDamage to have target information

Postby Major Cooke » Mon Jan 27, 2020 6:25 pm

Source is what you want. And you would do a check to make sure passive is false first.

Here's the relevant code from DamageMobj internally.

Code: Select allExpand view
if (damage > 0 && source != NULL)
{
   damage = int(damage * source->DamageMultiply);

   // Handle active damage modifiers (e.g. PowerDamage)
   if (damage > 0 && !(flags & DMG_NO_ENHANCE))
   {
      damage = source->GetModifiedDamage(mod, damage, false, inflictor, target, flags);
   }
}
// Handle passive damage modifiers (e.g. PowerProtection), provided they are not afflicted with protection penetrating powers.
if (damage > 0 && !(flags & DMG_NO_PROTECT))
{
   damage = target->GetModifiedDamage(mod, damage, true, inflictor, source, flags);
}


Pairing those parameters up to ModifyDamage, you can see that source becomes the actor that's being damaged. There's no point in it being the owner in this case because it'd be redundant when you have the "owner" variable already at your disposal.

So check the source, make sure it isn't null, and then check to see if it has the boss flag. But again, make sure the passive boolean is false.
User avatar
Major Cooke
d = klabs(wall[wall[wall[sector[dasect].wallptr].point2].point2].x-s->x)...
Global Moderator
 
Joined: 28 Jan 2007

Re: Extend ModifyDamage to have target information

Postby SanyaWaffles » Mon Jan 27, 2020 7:34 pm

This is in fact correct. I just tried it.

I guess this can be marked as 'Already In'.

By the way, thanks for explaining this to me a bit more in depth.
User avatar
SanyaWaffles
Navy Did Nothing Wrong
Global Moderator
 
Joined: 25 Apr 2013
Location: Eastern Ohio
Discord: SanyaWaffles#5095
Twitch ID: sanyawaffles
Operating System: Windows 10/8.1/8 64-bit
OS Test Version: No (Using Stable Public Version)
Graphics Processor: nVidia with Vulkan support

Re: Extend ModifyDamage to have target information

Postby Major Cooke » Mon Jan 27, 2020 8:01 pm

No problem. That reminds me though I should add it to AbsorbDamage as well for armor...
User avatar
Major Cooke
d = klabs(wall[wall[wall[sector[dasect].wallptr].point2].point2].x-s->x)...
Global Moderator
 
Joined: 28 Jan 2007


Return to Closed Feature Suggestions

Who is online

Users browsing this forum: DotBot and 1 guest