Skip to content

Commit

Permalink
Added inflictor, source and flag parameters to GetModifiedDamage on a…
Browse files Browse the repository at this point in the history
…ctors and ModifyDamage on inventory.

- The flags are used by DamageMobj so modders can determine radius damage, for example, by checking for DMG_EXPLOSION.
  • Loading branch information
MajorCooke authored and coelckers committed Feb 8, 2019
1 parent 4496104 commit acc510d
Show file tree
Hide file tree
Showing 7 changed files with 17 additions and 14 deletions.
2 changes: 1 addition & 1 deletion src/actor.h
Expand Up @@ -1422,7 +1422,7 @@ class AActor : public DThinker
}

int ApplyDamageFactor(FName damagetype, int damage) const;
int GetModifiedDamage(FName damagetype, int damage, bool passive);
int GetModifiedDamage(FName damagetype, int damage, bool passive, AActor *inflictor, AActor *source, int flags = 0);
void DeleteAttachedLights();
bool isFrozen();

Expand Down
6 changes: 3 additions & 3 deletions src/p_interaction.cpp
Expand Up @@ -1150,13 +1150,13 @@ static int DamageMobj (AActor *target, AActor *inflictor, AActor *source, int da
// Handle active damage modifiers (e.g. PowerDamage)
if (damage > 0 && !(flags & DMG_NO_ENHANCE))
{
damage = source->GetModifiedDamage(mod, damage, false);
damage = source->GetModifiedDamage(mod, damage, false, inflictor, source, 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);
damage = target->GetModifiedDamage(mod, damage, true, inflictor, source, flags);
}
if (damage > 0 && !(flags & DMG_NO_FACTOR))
{
Expand Down Expand Up @@ -1747,7 +1747,7 @@ void P_PoisonDamage (player_t *player, AActor *source, int damage, bool playPain
// Take half damage in trainer mode
damage = int(damage * G_SkillProperty(SKILLP_DamageFactor) * sv_damagefactorplayer);
// Handle passive damage modifiers (e.g. PowerProtection)
damage = target->GetModifiedDamage(player->poisontype, damage, true);
damage = target->GetModifiedDamage(player->poisontype, damage, true, nullptr, source);
// Modify with damage factors
damage = target->ApplyDamageFactor(player->poisontype, damage);

Expand Down
6 changes: 3 additions & 3 deletions src/p_mobj.cpp
Expand Up @@ -7217,15 +7217,15 @@ void AActor::ClearCounters()
}
}

int AActor::GetModifiedDamage(FName damagetype, int damage, bool passive)
int AActor::GetModifiedDamage(FName damagetype, int damage, bool passive, AActor *inflictor, AActor *source, int flags)
{
auto inv = Inventory;
while (inv != nullptr)
{
IFVIRTUALPTRNAME(inv, NAME_Inventory, ModifyDamage)
{
VMValue params[5] = { (DObject*)inv, damage, int(damagetype), &damage, passive };
VMCall(func, params, 5, nullptr, 0);
VMValue params[8] = { (DObject*)inv, damage, int(damagetype), &damage, passive, inflictor, source, flags };
VMCall(func, params, 8, nullptr, 0);
}
inv = inv->Inventory;
}
Expand Down
9 changes: 6 additions & 3 deletions src/scripting/vmthunks_actors.cpp
Expand Up @@ -799,9 +799,9 @@ DEFINE_ACTION_FUNCTION_NATIVE(AActor, ClearCounters, ClearCounters)
return 0;
}

static int GetModifiedDamage(AActor *self, int type, int damage, bool passive)
static int GetModifiedDamage(AActor *self, int type, int damage, bool passive, AActor *inflictor, AActor *source, int flags)
{
return self->GetModifiedDamage(ENamedName(type), damage, passive);
return self->GetModifiedDamage(ENamedName(type), damage, passive, inflictor, source, flags);
}

DEFINE_ACTION_FUNCTION_NATIVE(AActor, GetModifiedDamage, GetModifiedDamage)
Expand All @@ -810,7 +810,10 @@ DEFINE_ACTION_FUNCTION_NATIVE(AActor, GetModifiedDamage, GetModifiedDamage)
PARAM_NAME(type);
PARAM_INT(damage);
PARAM_BOOL(passive);
ACTION_RETURN_INT(self->GetModifiedDamage(type, damage, passive));
PARAM_OBJECT(inflictor, AActor);
PARAM_OBJECT(source, AActor);
PARAM_INT(flags);
ACTION_RETURN_INT(self->GetModifiedDamage(type, damage, passive, inflictor, source, flags));
}

static int ApplyDamageFactor(AActor *self, int type, int damage)
Expand Down
2 changes: 1 addition & 1 deletion wadsrc/static/zscript/actor.txt
Expand Up @@ -651,7 +651,7 @@ class Actor : Thinker native
native void SpawnTeleportFog(Vector3 pos, bool beforeTele, bool setTarget);
native Actor RoughMonsterSearch(int distance, bool onlyseekable = false, bool frontonly = false);
native int ApplyDamageFactor(Name damagetype, int damage);
native int GetModifiedDamage(Name damagetype, int damage, bool passive);
native int GetModifiedDamage(Name damagetype, int damage, bool passive, Actor inflictor = null, Actor source = null, int flags = 0);
native bool CheckBossDeath();

void A_Light(int extralight) { if (player) player.extralight = clamp(extralight, -20, 20); }
Expand Down
2 changes: 1 addition & 1 deletion wadsrc/static/zscript/inventory/inventory.txt
Expand Up @@ -1002,7 +1002,7 @@ class Inventory : Actor
//
//===========================================================================

virtual void ModifyDamage(int damage, Name damageType, out int newdamage, bool passive) {}
virtual void ModifyDamage(int damage, Name damageType, out int newdamage, bool passive, Actor inflictor = null, Actor source = null, int flags = 0) {}


virtual bool Use (bool pickup) { return false; }
Expand Down
4 changes: 2 additions & 2 deletions wadsrc/static/zscript/inventory/powerups.txt
Expand Up @@ -1655,7 +1655,7 @@ class PowerDamage : Powerup
//
//===========================================================================

override void ModifyDamage(int damage, Name damageType, out int newdamage, bool passive)
override void ModifyDamage(int damage, Name damageType, out int newdamage, bool passive, Actor inflictor, Actor source, int flags)
{
if (!passive && damage > 0)
{
Expand Down Expand Up @@ -1749,7 +1749,7 @@ class PowerProtection : Powerup
//
//===========================================================================

override void ModifyDamage(int damage, Name damageType, out int newdamage, bool passive)
override void ModifyDamage(int damage, Name damageType, out int newdamage, bool passive, Actor inflictor, Actor source, int flags)
{
if (passive && damage > 0)
{
Expand Down

0 comments on commit acc510d

Please sign in to comment.