From 854e11a9de37a1cddf9662ca49f3a068995d19e5 Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Sat, 21 Aug 2021 12:44:36 +0200 Subject: [PATCH] - 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. --- src/playsim/actor.h | 3 --- src/playsim/p_actionfunctions.cpp | 4 ++-- src/playsim/p_enemy.cpp | 32 +++++++++++++++---------------- src/playsim/p_enemy.h | 4 ++-- 4 files changed, 20 insertions(+), 23 deletions(-) diff --git a/src/playsim/actor.h b/src/playsim/actor.h index 51cf4308da..61b65b593b 100644 --- a/src/playsim/actor.h +++ b/src/playsim/actor.h @@ -693,9 +693,6 @@ public: int AbsorbDamage(int damage, FName dmgtype, AActor *inflictor, AActor *source, int flags); void AlterWeaponSprite(visstyle_t *vis); - // Returns true if this actor is within melee range of its target - bool CheckMeleeRange(double range = -1); - bool CheckNoDelay(); virtual void BeginPlay(); // Called immediately after the actor is created diff --git a/src/playsim/p_actionfunctions.cpp b/src/playsim/p_actionfunctions.cpp index df3849a7b3..af1c07e01b 100644 --- a/src/playsim/p_actionfunctions.cpp +++ b/src/playsim/p_actionfunctions.cpp @@ -1073,7 +1073,7 @@ DEFINE_ACTION_FUNCTION(AActor, A_CustomMeleeAttack) return 0; A_FaceTarget (self); - if (self->CheckMeleeRange ()) + if (P_CheckMeleeRange(self)) { if (meleesound) S_Sound (self, CHAN_WEAPON, 0, meleesound, 1, ATTN_NORM); @@ -1108,7 +1108,7 @@ DEFINE_ACTION_FUNCTION(AActor, A_CustomComboAttack) return 0; A_FaceTarget (self); - if (self->CheckMeleeRange()) + if (P_CheckMeleeRange(self)) { if (damagetype == NAME_None) damagetype = NAME_Melee; // Melee is the default type diff --git a/src/playsim/p_enemy.cpp b/src/playsim/p_enemy.cpp index fc032a2a88..1432fa67df 100644 --- a/src/playsim/p_enemy.cpp +++ b/src/playsim/p_enemy.cpp @@ -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; - if (!pl || (Sector->Flags & SECF_NOATTACK)) + if (!pl || (actor->Sector->Flags & SECF_NOATTACK)) return false; - dist = Distance2D (pl); - if (range < 0) range = meleerange; + dist = actor->Distance2D (pl); + if (range < 0) range = actor->meleerange; if (dist >= range + pl->radius) return false; // [RH] If moving toward goal, then we've reached it. - if (pl == goal) + if (pl == actor->goal) return true; // [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; - if (pl->Top() < Z()) + if (pl->Top() < actor->Z()) return false; } // killough 7/18/98: friendly monsters don't attack other friends - if (IsFriend(pl)) + if (actor->IsFriend(pl)) return false; - if (!P_CheckSight (this, pl, 0)) + if (!P_CheckSight (actor, pl, 0)) return false; return true; } -DEFINE_ACTION_FUNCTION(AActor, CheckMeleeRange) +DEFINE_ACTION_FUNCTION_NATIVE(AActor, CheckMeleeRange, P_CheckMeleeRange) { PARAM_SELF_PROLOGUE(AActor); 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; @@ -2434,7 +2434,7 @@ void A_DoChase (AActor *actor, bool fastchase, FState *meleestate, FState *missi { AActor * savedtarget = actor->target; actor->target = actor->goal; - bool result = actor->CheckMeleeRange(); + bool result = P_CheckMeleeRange(actor); actor->target = savedtarget; if (result) @@ -2518,7 +2518,7 @@ void A_DoChase (AActor *actor, bool fastchase, FState *meleestate, FState *missi pr_scaredycat() < 43) { // check for melee attack - if (meleestate && actor->CheckMeleeRange ()) + if (meleestate && P_CheckMeleeRange(actor)) { if (actor->AttackSound) S_Sound (actor, CHAN_WEAPON, 0, actor->AttackSound, 1, ATTN_NORM); diff --git a/src/playsim/p_enemy.h b/src/playsim/p_enemy.h index 282760e5e6..dd38c3bf09 100644 --- a/src/playsim/p_enemy.h +++ b/src/playsim/p_enemy.h @@ -47,7 +47,8 @@ struct FLookExParams }; 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); int P_SmartMove (AActor *actor); @@ -76,7 +77,6 @@ class FSoundID; int CheckBossDeath (AActor *); int P_Massacre (bool baddies = false, PClassActor *cls = nullptr); -bool P_CheckMissileRange (AActor *actor); #define SKULLSPEED (20.) void A_SkullAttack(AActor *self, double speed);