mirror of
https://github.com/ZDoom/qzdoom.git
synced 2024-11-12 23:54:35 +00:00
- moved the kickback code in P_DamageMobj into a subfunction.
This is a first attempt to reduce the complexity of that 600+ lines monstrosity, and also a good first target for scriptification.
This commit is contained in:
parent
ae27acb944
commit
e856e3c830
1 changed files with 75 additions and 68 deletions
|
@ -908,6 +908,80 @@ void P_AutoUseStrifeHealth (player_t *player)
|
||||||
==================
|
==================
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
void ApplyKickback(AActor *target, AActor *inflictor, AActor *source, int damage, DAngle angle, FName mod, int flags)
|
||||||
|
{
|
||||||
|
DAngle ang;
|
||||||
|
int kickback;
|
||||||
|
double thrust;
|
||||||
|
|
||||||
|
if (inflictor && inflictor->projectileKickback)
|
||||||
|
kickback = inflictor->projectileKickback;
|
||||||
|
else if (!source || !source->player || !source->player->ReadyWeapon)
|
||||||
|
kickback = gameinfo.defKickback;
|
||||||
|
else
|
||||||
|
kickback = source->player->ReadyWeapon->Kickback;
|
||||||
|
|
||||||
|
kickback = int(kickback * G_SkillProperty(SKILLP_KickbackFactor));
|
||||||
|
if (kickback)
|
||||||
|
{
|
||||||
|
AActor *origin = (source && (flags & DMG_INFLICTOR_IS_PUFF)) ? source : inflictor;
|
||||||
|
|
||||||
|
if (flags & DMG_USEANGLE)
|
||||||
|
{
|
||||||
|
ang = angle;
|
||||||
|
}
|
||||||
|
else if (origin->X() == target->X() && origin->Y() == target->Y())
|
||||||
|
{
|
||||||
|
// If the origin and target are in exactly the same spot, choose a random direction.
|
||||||
|
// (Most likely cause is from telefragging somebody during spawning because they
|
||||||
|
// haven't moved from their spawn spot at all.)
|
||||||
|
ang = pr_kickbackdir.GenRand_Real2() * 360.;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
ang = origin->AngleTo(target);
|
||||||
|
}
|
||||||
|
|
||||||
|
thrust = mod == NAME_MDK ? 10 : 32;
|
||||||
|
if (target->Mass > 0)
|
||||||
|
{
|
||||||
|
thrust = clamp((damage * 0.125 * kickback) / target->Mass, 0., thrust);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Don't apply ultra-small damage thrust
|
||||||
|
if (thrust < 0.01) thrust = 0;
|
||||||
|
|
||||||
|
// make fall forwards sometimes
|
||||||
|
if ((damage < 40) && (damage > target->health)
|
||||||
|
&& (target->Z() - origin->Z() > 64)
|
||||||
|
&& (pr_damagemobj() & 1)
|
||||||
|
// [RH] But only if not too fast and not flying
|
||||||
|
&& thrust < 10
|
||||||
|
&& !(target->flags & MF_NOGRAVITY)
|
||||||
|
&& (inflictor == NULL || !(inflictor->flags5 & MF5_NOFORWARDFALL))
|
||||||
|
)
|
||||||
|
{
|
||||||
|
ang += 180.;
|
||||||
|
thrust *= 4;
|
||||||
|
}
|
||||||
|
if (source && source->player && (flags & DMG_INFLICTOR_IS_PUFF)
|
||||||
|
&& source->player->ReadyWeapon != NULL &&
|
||||||
|
(source->player->ReadyWeapon->WeaponFlags & WIF_STAFF2_KICKBACK))
|
||||||
|
{
|
||||||
|
// Staff power level 2
|
||||||
|
target->Thrust(ang, 10);
|
||||||
|
if (!(target->flags & MF_NOGRAVITY))
|
||||||
|
{
|
||||||
|
target->Vel.Z += 5.;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
target->Thrust(ang, thrust);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
static inline bool MustForcePain(AActor *target, AActor *inflictor)
|
static inline bool MustForcePain(AActor *target, AActor *inflictor)
|
||||||
{
|
{
|
||||||
return (inflictor && (inflictor->flags6 & MF6_FORCEPAIN));
|
return (inflictor && (inflictor->flags6 & MF6_FORCEPAIN));
|
||||||
|
@ -1188,74 +1262,7 @@ static int DamageMobj (AActor *target, AActor *inflictor, AActor *source, int da
|
||||||
&& !(target->flags7 & MF7_DONTTHRUST)
|
&& !(target->flags7 & MF7_DONTTHRUST)
|
||||||
&& (source == NULL || source->player == NULL || !(source->flags2 & MF2_NODMGTHRUST)))
|
&& (source == NULL || source->player == NULL || !(source->flags2 & MF2_NODMGTHRUST)))
|
||||||
{
|
{
|
||||||
int kickback;
|
ApplyKickback(target, inflictor, source, damage, angle, mod, flags);
|
||||||
|
|
||||||
if (inflictor && inflictor->projectileKickback)
|
|
||||||
kickback = inflictor->projectileKickback;
|
|
||||||
else if (!source || !source->player || !source->player->ReadyWeapon)
|
|
||||||
kickback = gameinfo.defKickback;
|
|
||||||
else
|
|
||||||
kickback = source->player->ReadyWeapon->Kickback;
|
|
||||||
|
|
||||||
kickback = int(kickback * G_SkillProperty(SKILLP_KickbackFactor));
|
|
||||||
if (kickback)
|
|
||||||
{
|
|
||||||
AActor *origin = (source && (flags & DMG_INFLICTOR_IS_PUFF))? source : inflictor;
|
|
||||||
|
|
||||||
if (flags & DMG_USEANGLE)
|
|
||||||
{
|
|
||||||
ang = angle;
|
|
||||||
}
|
|
||||||
else if (origin->X() == target->X() && origin->Y() == target->Y())
|
|
||||||
{
|
|
||||||
// If the origin and target are in exactly the same spot, choose a random direction.
|
|
||||||
// (Most likely cause is from telefragging somebody during spawning because they
|
|
||||||
// haven't moved from their spawn spot at all.)
|
|
||||||
ang = pr_kickbackdir.GenRand_Real2() * 360.;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
ang = origin->AngleTo(target);
|
|
||||||
}
|
|
||||||
|
|
||||||
thrust = mod == NAME_MDK ? 10 : 32;
|
|
||||||
if (target->Mass > 0)
|
|
||||||
{
|
|
||||||
thrust = clamp((damage * 0.125 * kickback) / target->Mass, 0., thrust);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Don't apply ultra-small damage thrust
|
|
||||||
if (thrust < 0.01) thrust = 0;
|
|
||||||
|
|
||||||
// make fall forwards sometimes
|
|
||||||
if ((damage < 40) && (damage > target->health)
|
|
||||||
&& (target->Z() - origin->Z() > 64)
|
|
||||||
&& (pr_damagemobj()&1)
|
|
||||||
// [RH] But only if not too fast and not flying
|
|
||||||
&& thrust < 10
|
|
||||||
&& !(target->flags & MF_NOGRAVITY)
|
|
||||||
&& (inflictor == NULL || !(inflictor->flags5 & MF5_NOFORWARDFALL))
|
|
||||||
)
|
|
||||||
{
|
|
||||||
ang += 180.;
|
|
||||||
thrust *= 4;
|
|
||||||
}
|
|
||||||
if (source && source->player && (flags & DMG_INFLICTOR_IS_PUFF)
|
|
||||||
&& source->player->ReadyWeapon != NULL &&
|
|
||||||
(source->player->ReadyWeapon->WeaponFlags & WIF_STAFF2_KICKBACK))
|
|
||||||
{
|
|
||||||
// Staff power level 2
|
|
||||||
target->Thrust(ang, 10);
|
|
||||||
if (!(target->flags & MF_NOGRAVITY))
|
|
||||||
{
|
|
||||||
target->Vel.Z += 5.;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
target->Thrust(ang, thrust);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// [RH] Avoid friendly fire if enabled
|
// [RH] Avoid friendly fire if enabled
|
||||||
|
|
Loading…
Reference in a new issue