diff --git a/src/gs-entbase/shared/NSMonster.h b/src/gs-entbase/shared/NSMonster.h index d29e12b4..161d6446 100644 --- a/src/gs-entbase/shared/NSMonster.h +++ b/src/gs-entbase/shared/NSMonster.h @@ -149,6 +149,13 @@ typedef enum MAL_ROGUE /* no allies, not even amongst themselves */ } allianceState_t; +typedef enum +{ + MOVESTATE_IDLE, + MOVESTATE_WALK, + MOVESTATE_RUN +} movementState_t; + /* These numerations involve the m_iTriggerCondition attribute. * Basically these conditions are being checked and triggered depending on what * it's set to. If any of those checks are successful, we trigger our target @@ -192,6 +199,7 @@ class NSMonster:NSSurfacePropEntity vector m_vecSequenceAngle; vector m_vecTurnAngle; int m_iSequenceFlags; + movementState_t m_iMoveState; int m_iTriggerCondition; string m_strTriggerTarget; @@ -268,6 +276,7 @@ class NSMonster:NSSurfacePropEntity virtual int(void) AnimWalk; virtual int(void) AnimRun; virtual void(float) AnimPlay; + virtual void(void) AnimationUpdate; /* TriggerTarget/Condition */ virtual int(void) GetTriggerCondition; diff --git a/src/gs-entbase/shared/NSMonster.qc b/src/gs-entbase/shared/NSMonster.qc index bf4d3041..de15fba2 100644 --- a/src/gs-entbase/shared/NSMonster.qc +++ b/src/gs-entbase/shared/NSMonster.qc @@ -64,19 +64,19 @@ NSMonster::Restore(string strKey, string strValue) int NSMonster::AnimIdle(void) { - return frameforaction(modelindex, ACT_IDLE); + return -1; } int NSMonster::AnimWalk(void) { - return frameforaction(modelindex, ACT_WALK); + return -1; } int NSMonster::AnimRun(void) { - return frameforaction(modelindex, ACT_RUN); + return -1; } void @@ -568,6 +568,62 @@ NSMonster::NewRoute(vector destination) } } +void +NSMonster::AnimationUpdate(void) +{ + int frame, act; + + if (style == MONSTER_DEAD) + return; + + float spvel = vlen(velocity); + float midspeed = GetWalkSpeed() + ((GetRunSpeed() - GetWalkSpeed()) * 0.5f); + + if (spvel < 5) { + frame = AnimIdle(); + + if (m_iMoveState != MOVESTATE_IDLE) + m_flAnimTime = 0.0f; + + if (frame == -1) + act = (frameforaction(modelindex, ACT_IDLE)); + + + m_iMoveState = MOVESTATE_IDLE; + } else if (spvel < midspeed) { + frame = AnimWalk(); + + if (m_iMoveState != MOVESTATE_WALK) + m_flAnimTime = 0.0f; + + if (frame == -1) + act = (frameforaction(modelindex, ACT_WALK)); + + + m_iMoveState = MOVESTATE_WALK; + } else { + frame = AnimRun(); + + if (m_iMoveState != MOVESTATE_RUN) + m_flAnimTime = 0.0f; + + if (frame == -1) + act = (frameforaction(modelindex, ACT_RUN)); + + m_iMoveState = MOVESTATE_RUN; + } + + if (m_flAnimTime > 0.0f) { + return; + } + + if (frame == -1) + AnimPlay(act); + else + SetFrame(frame); + +} + const int CONTENTBITS_MONSTER = CONTENTBIT_SOLID|CONTENTBIT_BODY|CONTENTBIT_MONSTERCLIP|CONTENTBIT_BOTCLIP; void PMoveCustom_RunPlayerPhysics(entity target); void PMoveCustom_RunCrouchPhysics(entity target); @@ -602,22 +658,7 @@ NSMonster::Physics(void) IdleNoise(); button8 = input_buttons & INPUT_BUTTON8; // duck - if (style != MONSTER_DEAD) { - if (m_flAnimTime > time) { - input_movevalues = [0,0,0]; - } else { - float spvel = vlen(velocity); - float midspeed = GetWalkSpeed() + ((GetRunSpeed() - GetWalkSpeed()) * 0.5f); - - if (spvel < 5) { - SetFrame(AnimIdle()); - } else if (spvel < midspeed) { - SetFrame(AnimWalk()); - } else { - SetFrame(AnimRun()); - } - } - } + AnimationUpdate(); } if (!(flags & FL_ONGROUND) && velocity[2] < -415) { diff --git a/src/gs-entbase/shared/NSTalkMonster.qc b/src/gs-entbase/shared/NSTalkMonster.qc index 4d75bde4..628e3ac6 100644 --- a/src/gs-entbase/shared/NSTalkMonster.qc +++ b/src/gs-entbase/shared/NSTalkMonster.qc @@ -493,20 +493,7 @@ NSTalkMonster::Physics(void) } } - if (m_flAnimTime > time) { - input_movevalues = [0,0,0]; - } else { - spvel = vlen(velocity); - float midspeed = GetWalkSpeed() + ((GetRunSpeed() - GetWalkSpeed()) * 0.5f); - - if (spvel < 5) { - SetFrame(AnimIdle()); - } else if (spvel < midspeed) { - SetFrame(AnimWalk()); - } else { - SetFrame(AnimRun()); - } - } + AnimationUpdate(); } CheckRoute(); WalkRoute();