From 40dc1267facb34d0469fdcf028588e0501534b39 Mon Sep 17 00:00:00 2001 From: Marco Cawthorne Date: Fri, 2 Jun 2023 19:25:49 -0700 Subject: [PATCH] NSMonster: Add FramegroupForAct() and ActPlay() methods, deprecate Anim* methods. --- src/shared/NSMonster.h | 15 ++++++++------- src/shared/NSMonster.qc | 37 ++++++++++++++++++------------------- 2 files changed, 26 insertions(+), 26 deletions(-) diff --git a/src/shared/NSMonster.h b/src/shared/NSMonster.h index 3ce56bfd..c13c5996 100644 --- a/src/shared/NSMonster.h +++ b/src/shared/NSMonster.h @@ -331,16 +331,16 @@ public: nonvirtual bool InSequence(void); /* animation cycles */ - /** Overridable: Called when we need to play a fresh idle framegroup. */ + /** DEPRECATED, Overridable: Called when we need to play a fresh idle framegroup. */ virtual int AnimIdle(void); - /** Overridable: Called when we need to play a fresh walking framegroup. */ + /** DEPRECATED, Overridable: Called when we need to play a fresh walking framegroup. */ virtual int AnimWalk(void); - /** Overridable: Called when we need to play a fresh running framegroup. */ + /** DEPRECATED, Overridable: Called when we need to play a fresh running framegroup. */ virtual int AnimRun(void); - /** Overridable: Called when we need to play a left turning animation. */ - virtual int AnimTurnLeft(void); - /** Overridable: Called when we need to play a right turning animation. */ - virtual int AnimTurnRight(void); + /** Overridable: Returns which framegroup to play for a given ACT. */ + virtual float FramegroupForAct(float); + /** Call to play an ACT on the given NSMonster. */ + nonvirtual void ActPlay(float); /** Call to play a single animation onto it, which cannot be interrupted by movement. */ virtual void AnimPlay(float); /** Internal use only. Run every frame to update animation parameters. */ @@ -424,6 +424,7 @@ private: bool m_bTurning; nonvirtual void _LerpTurnToEnemy(void); + nonvirtual void _LerpTurnToPos(vector); nonvirtual void _LerpTurnToYaw(vector); virtual void _Alerted(void); #endif diff --git a/src/shared/NSMonster.qc b/src/shared/NSMonster.qc index 11bdd71e..741a8942 100644 --- a/src/shared/NSMonster.qc +++ b/src/shared/NSMonster.qc @@ -188,32 +188,33 @@ NSMonster::Restore(string strKey, string strValue) int NSMonster::AnimIdle(void) { - return frameforaction(modelindex, ACT_IDLE); + return FramegroupForAct(ACT_IDLE); } int NSMonster::AnimWalk(void) { - return frameforaction(modelindex, ACT_WALK); + return FramegroupForAct(ACT_WALK); } int NSMonster::AnimRun(void) { - float runAnim = frameforaction(modelindex, ACT_RUN); + float runAnim = FramegroupForAct(ACT_RUN); return (runAnim == -1) ? AnimWalk() : runAnim; } -int -NSMonster::AnimTurnLeft(void) +float +NSMonster::FramegroupForAct(float actName) { - return frameforaction(modelindex, ACT_TURN_LEFT); + float frameGroup = frameforaction(modelindex, actName); + return frameGroup; } -int -NSMonster::AnimTurnRight(void) +void +NSMonster::ActPlay(float actName) { - return frameforaction(modelindex, ACT_TURN_RIGHT); + AnimPlay(FramegroupForAct(actName)); } void @@ -438,21 +439,21 @@ var float autocvar_ai_stepSize = 128; float NSMonster::GetWalkSpeed(void) { - float speed = autocvar_ai_stepSize / frameduration(modelindex, AnimWalk()); + float speed = autocvar_ai_stepSize / frameduration(modelindex, FramegroupForAct(ACT_WALK)); return speed; } float NSMonster::GetChaseSpeed(void) { - float speed = autocvar_ai_stepSize / frameduration(modelindex, AnimRun()); + float speed = autocvar_ai_stepSize / frameduration(modelindex, FramegroupForAct(ACT_RUN)); return speed; } float NSMonster::GetRunSpeed(void) { - float speed = autocvar_ai_stepSize / frameduration(modelindex, AnimRun()); + float speed = autocvar_ai_stepSize / frameduration(modelindex, FramegroupForAct(ACT_RUN)); return speed; } @@ -478,9 +479,9 @@ NSMonster::_LerpTurnToYaw(vector turnYaw) if (m_bTurning == false) if (yawDiff < 0) { - SetFrame(AnimTurnRight()); + SetFrame(FramegroupForAct(ACT_TURN_RIGHT)); } else { - SetFrame(AnimTurnLeft()); + SetFrame(FramegroupForAct(ACT_TURN_LEFT)); } m_bTurning = true; @@ -518,15 +519,15 @@ NSMonster::_LerpTurnToPos(vector turnPos) void NSMonster::_LerpTurnToEnemy(void) { + if (!m_eEnemy) + return; + /* only continue if we're in one of the three states. */ if (GetState() != MONSTER_AIMING) if (GetState() != MONSTER_CHASING) if (GetState() != MONSTER_FOLLOWING) return; - if (!m_eEnemy) - return; - _LerpTurnToPos(m_eEnemy.origin); } @@ -688,8 +689,6 @@ NSMonster::RouteEnded(void) void NSMonster::WalkRoute(void) { - vector wishAngles; - /* we're busy shooting at something, don't walk */ if (GetState() == MONSTER_AIMING && m_eEnemy) { input_angles = vectoangles(m_eEnemy.origin - origin);