- consolidated the common portion of the 6 different A_Damage* functions into a subfunction.

This commit is contained in:
Christoph Oelckers 2014-09-27 08:48:36 +02:00
parent 0735cb9550
commit afaa88a460

View file

@ -3610,156 +3610,6 @@ DEFINE_ACTION_FUNCTION_PARAMS(AActor, A_JumpIfInTargetLOS)
ACTION_JUMP(jump);
}
enum DMSS
{
DMSS_FOILINVUL = 1,
DMSS_AFFECTARMOR = 2,
DMSS_KILL = 4,
};
//===========================================================================
//
// A_DamageMaster (int amount, str damagetype, int flags)
// Damages the master of this child by the specified amount. Negative values heal.
//
//===========================================================================
DEFINE_ACTION_FUNCTION_PARAMS(AActor, A_DamageMaster)
{
ACTION_PARAM_START(3);
ACTION_PARAM_INT(amount, 0);
ACTION_PARAM_NAME(DamageType, 1);
ACTION_PARAM_INT(flags, 2);
if (self->master != NULL)
{
if ((amount > 0) || (flags & DMSS_KILL))
{
if (!(self->master->flags2 & MF2_INVULNERABLE) || (flags & DMSS_FOILINVUL))
{
if (flags & DMSS_KILL)
{
P_DamageMobj(self->master, self, self, self->master->health, DamageType, DMG_NO_FACTOR | DMG_NO_ARMOR | DMG_FOILINVUL);
}
if (flags & DMSS_AFFECTARMOR)
{
P_DamageMobj(self->master, self, self, amount, DamageType, DMG_FOILINVUL);
}
else
{
P_DamageMobj(self->master, self, self, amount, DamageType, DMG_FOILINVUL | DMG_NO_ARMOR);
}
}
}
else if (amount < 0)
{
amount = -amount;
P_GiveBody(self->master, amount);
}
}
}
//===========================================================================
//
// A_DamageChildren (amount, str damagetype, int flags)
// Damages the children of this master by the specified amount. Negative values heal.
//
//===========================================================================
DEFINE_ACTION_FUNCTION_PARAMS(AActor, A_DamageChildren)
{
TThinkerIterator<AActor> it;
AActor * mo;
ACTION_PARAM_START(3);
ACTION_PARAM_INT(amount, 0);
ACTION_PARAM_NAME(DamageType, 1);
ACTION_PARAM_INT(flags, 2);
while ( (mo = it.Next()) )
{
if (mo->master == self)
{
if ((amount > 0) || (flags & DMSS_KILL)) //Bypass if kill flag is present; it won't matter. It intends to kill them.
{
if (!(mo->flags2 & MF2_INVULNERABLE) || (flags & DMSS_FOILINVUL))
{
if (flags & DMSS_KILL)
{
P_DamageMobj(mo, self, self, mo->health, DamageType, DMG_NO_FACTOR | DMG_NO_ARMOR | DMG_FOILINVUL);
}
if (flags & DMSS_AFFECTARMOR)
{
P_DamageMobj(mo, self, self, amount, DamageType, DMG_FOILINVUL);
}
else
{
P_DamageMobj(mo, self, self, amount, DamageType, DMG_FOILINVUL | DMG_NO_ARMOR);
}
}
}
else if (amount < 0)
{
amount = -amount;
P_GiveBody(mo, amount);
}
}
}
}
// [KS] *** End of my modifications ***
//===========================================================================
//
// A_DamageSiblings (int amount, str damagetype, int flags)
// Damages the siblings of this master by the specified amount. Negative values heal.
//
//===========================================================================
DEFINE_ACTION_FUNCTION_PARAMS(AActor, A_DamageSiblings)
{
TThinkerIterator<AActor> it;
AActor * mo;
ACTION_PARAM_START(3);
ACTION_PARAM_INT(amount, 0);
ACTION_PARAM_NAME(DamageType, 1);
ACTION_PARAM_INT(flags, 2);
if (self->master != NULL)
{
while ((mo = it.Next()))
{
if (mo->master == self->master && mo != self)
{
if ((amount > 0) || (flags & DMSS_KILL))
{
if (!(mo->flags2 & MF2_INVULNERABLE) || (flags & DMSS_FOILINVUL))
{
if (flags & DMSS_KILL)
{
P_DamageMobj(mo, self, self, mo->health, DamageType, DMG_NO_FACTOR | DMG_NO_ARMOR | DMG_FOILINVUL);
}
if (flags & DMSS_AFFECTARMOR)
{
P_DamageMobj(mo, self, self, amount, DamageType, DMG_FOILINVUL);
}
else
{
P_DamageMobj(mo, self, self, amount, DamageType, DMG_FOILINVUL | DMG_NO_ARMOR);
}
}
else if (amount < 0)
{
amount = -amount;
P_GiveBody(mo, amount);
}
}
}
}
}
}
//===========================================================================
//
// Modified code pointer from Skulltag
@ -5131,8 +4981,51 @@ DEFINE_ACTION_FUNCTION_PARAMS(AActor, A_SetSpeed)
//===========================================================================
//
// A_DamageSelf (int amount, str damagetype, int flags)
// Damages the calling actor by the specified amount. Negative values heal.
// Common A_Damage handler
//
// A_Damage* (int amount, str damagetype, int flags)
// Damages the specified actor by the specified amount. Negative values heal.
//
//===========================================================================
enum DMSS
{
DMSS_FOILINVUL = 1,
DMSS_AFFECTARMOR = 2,
DMSS_KILL = 4,
};
static void DoDamage(AActor *dmgtarget, AActor *self, int amount, FName DamageType, int flags)
{
if ((amount > 0) || (flags & DMSS_KILL))
{
if (!(dmgtarget->flags2 & MF2_INVULNERABLE) || (flags & DMSS_FOILINVUL))
{
if (flags & DMSS_KILL)
{
P_DamageMobj(dmgtarget, self, self, dmgtarget->health, DamageType, DMG_NO_FACTOR | DMG_NO_ARMOR | DMG_FOILINVUL);
}
if (flags & DMSS_AFFECTARMOR)
{
P_DamageMobj(dmgtarget, self, self, amount, DamageType, DMG_FOILINVUL);
}
else
{
//[MC] DMG_FOILINVUL is needed for making the damage occur on the actor.
P_DamageMobj(dmgtarget, self, self, amount, DamageType, DMG_FOILINVUL | DMG_NO_ARMOR);
}
}
}
else if (amount < 0)
{
amount = -amount;
P_GiveBody(dmgtarget, amount);
}
}
//===========================================================================
//
//
//
//===========================================================================
DEFINE_ACTION_FUNCTION_PARAMS(AActor, A_DamageSelf)
@ -5142,36 +5035,12 @@ DEFINE_ACTION_FUNCTION_PARAMS(AActor, A_DamageSelf)
ACTION_PARAM_NAME(DamageType, 1);
ACTION_PARAM_INT(flags, 2);
if ((amount > 0) || (flags & DMSS_KILL))
{
if (!(self->flags2 & MF2_INVULNERABLE) || (flags & DMSS_FOILINVUL))
{
if (flags & DMSS_KILL)
{
P_DamageMobj(self, self, self, self->health, DamageType, DMG_NO_FACTOR | DMG_NO_ARMOR | DMG_FOILINVUL);
}
if (flags & DMSS_AFFECTARMOR)
{
P_DamageMobj(self, self, self, amount, DamageType, DMG_FOILINVUL);
}
else
{
//[MC] DMG_FOILINVUL is needed for making the damage occur on the actor.
P_DamageMobj(self, self, self, amount, DamageType, DMG_FOILINVUL | DMG_NO_ARMOR);
}
}
}
else if (amount < 0)
{
amount = -amount;
P_GiveBody(self, amount);
}
DoDamage(self, self, amount, DamageType, flags);
}
//===========================================================================
//
// A_DamageTarget (int amount, str damagetype, int flags)
// Damages the target of the actor by the specified amount. Negative values heal.
//
//
//===========================================================================
DEFINE_ACTION_FUNCTION_PARAMS(AActor, A_DamageTarget)
@ -5181,38 +5050,12 @@ DEFINE_ACTION_FUNCTION_PARAMS(AActor, A_DamageTarget)
ACTION_PARAM_NAME(DamageType, 1);
ACTION_PARAM_INT(flags, 2);
if (self->target != NULL)
{
if ((amount > 0) || (flags & DMSS_KILL))
{
if (!(self->target->flags2 & MF2_INVULNERABLE) || (flags & DMSS_FOILINVUL))
{
if (flags & DMSS_KILL)
{
P_DamageMobj(self->target, self, self, self->target->health, DamageType, DMG_NO_FACTOR | DMG_NO_ARMOR | DMG_FOILINVUL);
}
if (flags & DMSS_AFFECTARMOR)
{
P_DamageMobj(self->target, self, self, amount, DamageType, DMG_FOILINVUL);
}
else
{
P_DamageMobj(self->target, self, self, amount, DamageType, DMG_FOILINVUL | DMG_NO_ARMOR);
}
}
}
else if (amount < 0)
{
amount = -amount;
P_GiveBody(self->target, amount);
}
}
if (self->target != NULL) DoDamage(self->target, self, amount, DamageType, flags);
}
//===========================================================================
//
// A_DamageTracer (int amount, str damagetype, int flags)
// Damages the tracer of the actor by the specified amount. Negative values heal.
//
//
//===========================================================================
DEFINE_ACTION_FUNCTION_PARAMS(AActor, A_DamageTracer)
@ -5222,31 +5065,65 @@ DEFINE_ACTION_FUNCTION_PARAMS(AActor, A_DamageTracer)
ACTION_PARAM_NAME(DamageType, 1);
ACTION_PARAM_INT(flags, 2);
if (self->target != NULL)
{
if (self->tracer != NULL) DoDamage(self->tracer, self, amount, DamageType, flags);
}
if ((amount > 0) || (flags & DMSS_KILL))
//===========================================================================
//
//
//
//===========================================================================
DEFINE_ACTION_FUNCTION_PARAMS(AActor, A_DamageMaster)
{
if (!(self->tracer->flags2 & MF2_INVULNERABLE) || (flags & DMSS_FOILINVUL))
{
if (flags & DMSS_KILL)
{
P_DamageMobj(self->tracer, self, self, self->tracer->health, DamageType, DMG_NO_FACTOR | DMG_NO_ARMOR | DMG_FOILINVUL);
ACTION_PARAM_START(3);
ACTION_PARAM_INT(amount, 0);
ACTION_PARAM_NAME(DamageType, 1);
ACTION_PARAM_INT(flags, 2);
if (self->master != NULL) DoDamage(self->master, self, amount, DamageType, flags);
}
if (flags & DMSS_AFFECTARMOR)
//===========================================================================
//
//
//
//===========================================================================
DEFINE_ACTION_FUNCTION_PARAMS(AActor, A_DamageChildren)
{
P_DamageMobj(self->tracer, self, self, amount, DamageType, DMG_FOILINVUL);
}
else
ACTION_PARAM_START(3);
ACTION_PARAM_INT(amount, 0);
ACTION_PARAM_NAME(DamageType, 1);
ACTION_PARAM_INT(flags, 2);
TThinkerIterator<AActor> it;
AActor * mo;
while ( (mo = it.Next()) )
{
P_DamageMobj(self->tracer, self, self, amount, DamageType, DMG_FOILINVUL | DMG_NO_ARMOR);
if (mo->master == self) DoDamage(mo, self, amount, DamageType, flags);
}
}
}
else if (amount < 0)
//===========================================================================
//
//
//
//===========================================================================
DEFINE_ACTION_FUNCTION_PARAMS(AActor, A_DamageSiblings)
{
amount = -amount;
P_GiveBody(self->tracer, amount);
ACTION_PARAM_START(3);
ACTION_PARAM_INT(amount, 0);
ACTION_PARAM_NAME(DamageType, 1);
ACTION_PARAM_INT(flags, 2);
TThinkerIterator<AActor> it;
AActor * mo;
if (self->master != NULL)
{
while ((mo = it.Next()))
{
if (mo->master == self->master && mo != self) DoDamage(mo, self, amount, DamageType, flags);
}
}
}