- made CheckMeleeRange a normal function again.

This way it can be directly used as a native ZScript export.
Like SuggestMissileAttack the change to a method was for virtual overrides that have been turned into flags since then.
This commit is contained in:
Christoph Oelckers 2021-08-21 12:44:36 +02:00
parent ac48518abc
commit 854e11a9de
4 changed files with 20 additions and 23 deletions

View File

@ -693,9 +693,6 @@ public:
int AbsorbDamage(int damage, FName dmgtype, AActor *inflictor, AActor *source, int flags); int AbsorbDamage(int damage, FName dmgtype, AActor *inflictor, AActor *source, int flags);
void AlterWeaponSprite(visstyle_t *vis); void AlterWeaponSprite(visstyle_t *vis);
// Returns true if this actor is within melee range of its target
bool CheckMeleeRange(double range = -1);
bool CheckNoDelay(); bool CheckNoDelay();
virtual void BeginPlay(); // Called immediately after the actor is created virtual void BeginPlay(); // Called immediately after the actor is created

View File

@ -1073,7 +1073,7 @@ DEFINE_ACTION_FUNCTION(AActor, A_CustomMeleeAttack)
return 0; return 0;
A_FaceTarget (self); A_FaceTarget (self);
if (self->CheckMeleeRange ()) if (P_CheckMeleeRange(self))
{ {
if (meleesound) if (meleesound)
S_Sound (self, CHAN_WEAPON, 0, meleesound, 1, ATTN_NORM); S_Sound (self, CHAN_WEAPON, 0, meleesound, 1, ATTN_NORM);
@ -1108,7 +1108,7 @@ DEFINE_ACTION_FUNCTION(AActor, A_CustomComboAttack)
return 0; return 0;
A_FaceTarget (self); A_FaceTarget (self);
if (self->CheckMeleeRange()) if (P_CheckMeleeRange(self))
{ {
if (damagetype == NAME_None) if (damagetype == NAME_None)
damagetype = NAME_Melee; // Melee is the default type damagetype = NAME_Melee; // Melee is the default type

View File

@ -262,49 +262,49 @@ void P_NoiseAlert (AActor *emitter, AActor *target, bool splash, double maxdist)
// //
//---------------------------------------------------------------------------- //----------------------------------------------------------------------------
bool AActor::CheckMeleeRange (double range) int P_CheckMeleeRange (AActor* actor, double range)
{ {
AActor *pl = target; AActor *pl = actor->target;
double dist; double dist;
if (!pl || (Sector->Flags & SECF_NOATTACK)) if (!pl || (actor->Sector->Flags & SECF_NOATTACK))
return false; return false;
dist = Distance2D (pl); dist = actor->Distance2D (pl);
if (range < 0) range = meleerange; if (range < 0) range = actor->meleerange;
if (dist >= range + pl->radius) if (dist >= range + pl->radius)
return false; return false;
// [RH] If moving toward goal, then we've reached it. // [RH] If moving toward goal, then we've reached it.
if (pl == goal) if (pl == actor->goal)
return true; return true;
// [RH] Don't melee things too far above or below actor. // [RH] Don't melee things too far above or below actor.
if (!(flags5 & MF5_NOVERTICALMELEERANGE)) if (!(actor->flags5 & MF5_NOVERTICALMELEERANGE))
{ {
if (pl->Z() > Top()) if (pl->Z() > actor->Top())
return false; return false;
if (pl->Top() < Z()) if (pl->Top() < actor->Z())
return false; return false;
} }
// killough 7/18/98: friendly monsters don't attack other friends // killough 7/18/98: friendly monsters don't attack other friends
if (IsFriend(pl)) if (actor->IsFriend(pl))
return false; return false;
if (!P_CheckSight (this, pl, 0)) if (!P_CheckSight (actor, pl, 0))
return false; return false;
return true; return true;
} }
DEFINE_ACTION_FUNCTION(AActor, CheckMeleeRange) DEFINE_ACTION_FUNCTION_NATIVE(AActor, CheckMeleeRange, P_CheckMeleeRange)
{ {
PARAM_SELF_PROLOGUE(AActor); PARAM_SELF_PROLOGUE(AActor);
PARAM_FLOAT(range); PARAM_FLOAT(range);
ACTION_RETURN_INT(self->CheckMeleeRange(range)); ACTION_RETURN_INT(P_CheckMeleeRange(self, range));
} }
//============================================================================= //=============================================================================
@ -313,7 +313,7 @@ DEFINE_ACTION_FUNCTION(AActor, CheckMeleeRange)
// //
//============================================================================= //=============================================================================
bool P_CheckMissileRange (AActor *actor) static int P_CheckMissileRange (AActor *actor)
{ {
double dist; double dist;
@ -2434,7 +2434,7 @@ void A_DoChase (AActor *actor, bool fastchase, FState *meleestate, FState *missi
{ {
AActor * savedtarget = actor->target; AActor * savedtarget = actor->target;
actor->target = actor->goal; actor->target = actor->goal;
bool result = actor->CheckMeleeRange(); bool result = P_CheckMeleeRange(actor);
actor->target = savedtarget; actor->target = savedtarget;
if (result) if (result)
@ -2518,7 +2518,7 @@ void A_DoChase (AActor *actor, bool fastchase, FState *meleestate, FState *missi
pr_scaredycat() < 43) pr_scaredycat() < 43)
{ {
// check for melee attack // check for melee attack
if (meleestate && actor->CheckMeleeRange ()) if (meleestate && P_CheckMeleeRange(actor))
{ {
if (actor->AttackSound) if (actor->AttackSound)
S_Sound (actor, CHAN_WEAPON, 0, actor->AttackSound, 1, ATTN_NORM); S_Sound (actor, CHAN_WEAPON, 0, actor->AttackSound, 1, ATTN_NORM);

View File

@ -47,7 +47,8 @@ struct FLookExParams
}; };
int P_HitFriend (AActor *self); int P_HitFriend (AActor *self);
void P_NoiseAlert (AActor *emmiter, AActor *target, bool splash=false, double maxdist=0); void P_NoiseAlert (AActor *emitter, AActor *target, bool splash=false, double maxdist=0);
int P_CheckMeleeRange(AActor* actor, double range = -1);
bool P_CheckMeleeRange2 (AActor *actor); bool P_CheckMeleeRange2 (AActor *actor);
int P_SmartMove (AActor *actor); int P_SmartMove (AActor *actor);
@ -76,7 +77,6 @@ class FSoundID;
int CheckBossDeath (AActor *); int CheckBossDeath (AActor *);
int P_Massacre (bool baddies = false, PClassActor *cls = nullptr); int P_Massacre (bool baddies = false, PClassActor *cls = nullptr);
bool P_CheckMissileRange (AActor *actor);
#define SKULLSPEED (20.) #define SKULLSPEED (20.)
void A_SkullAttack(AActor *self, double speed); void A_SkullAttack(AActor *self, double speed);