From f13754a8c3c014686cc8850388c923d821f5244a Mon Sep 17 00:00:00 2001 From: Marco Hladik Date: Sat, 6 Mar 2021 17:43:08 +0100 Subject: [PATCH] CBaseNPC: Add ::StartleAllies() and ::TalkPanic() methods. Which handle behaviour related to the MONSTER_FEAR flag. --- src/gs-entbase/server/basenpc.h | 3 ++ src/gs-entbase/server/basenpc.qc | 50 ++++++++++++++++++++------------ 2 files changed, 34 insertions(+), 19 deletions(-) diff --git a/src/gs-entbase/server/basenpc.h b/src/gs-entbase/server/basenpc.h index 354925ab..42916786 100644 --- a/src/gs-entbase/server/basenpc.h +++ b/src/gs-entbase/server/basenpc.h @@ -47,6 +47,7 @@ class CBaseNPC:CBaseMonster string m_talkAllyShot; /* asks to not shoot an ally further */ string m_talkGreet; /* greet other NPCs */ string m_talkIdle; /* idle chatter */ + string m_talkPanic; /* panic screams */ string m_talkHearing; /* what did we just hear? */ string m_talkSmelling; /* is something smelling bad? */ string m_talkStare; /* when NPC is being stared at */ @@ -68,6 +69,7 @@ class CBaseNPC:CBaseMonster virtual void(string) Speak; virtual void(string) Sentence; virtual void(void) WarnAllies; + virtual void(void) StartleAllies; virtual void(void) FollowPlayer; virtual void(void) FollowChain; virtual void(void) Physics; @@ -86,6 +88,7 @@ class CBaseNPC:CBaseMonster virtual void(void) TalkStare; virtual void(void) TalkSurvived; virtual void(void) TalkWounded;*/ + virtual void(void) TalkPanic; virtual void(void) TalkPlayerAsk; virtual void(void) TalkPlayerGreet; virtual void(void) TalkPlayerIdle; diff --git a/src/gs-entbase/server/basenpc.qc b/src/gs-entbase/server/basenpc.qc index 03251ab3..3376c547 100644 --- a/src/gs-entbase/server/basenpc.qc +++ b/src/gs-entbase/server/basenpc.qc @@ -26,6 +26,18 @@ CBaseNPC::WarnAllies(void) } } } +void +CBaseNPC::StartleAllies(void) +{ + for (entity b = world; (b = find(b, ::classname, classname));) { + if (vlen(b.origin - origin) < PLAYER_DETECT_RADIUS) { + CBaseNPC w = (CBaseNPC)b; + w.m_iFlags |= MONSTER_FEAR; + w.m_eFollowing = world; + w.m_eFollowingChain = world; + } + } +} void CBaseNPC::Sentence(string sentence) @@ -218,6 +230,17 @@ CBaseNPC::TalkPlayerWounded3(void) } } +void +CBaseNPC::TalkPanic(void) +{ + if (m_iSequenceState != SEQUENCESTATE_NONE) + return; + + Sentence(m_talkPanic); + m_flNextSentence = time + 2.5; +} + + void CBaseNPC::TalkUnfollow(void) { @@ -306,27 +329,16 @@ CBaseNPC::PanicFrame(void) } if (m_flChangePath < time) { - float add; - vector pos; - - pos = origin + [0,0,-18]; - if (random() < 0.5) { - add = 45; - } else { - add = -45; - } - - /* test every 45 degrees */ - for (int i = 0; i < 8; i++) { - v_angle[1] = Math_FixDelta(v_angle[1] + add); - makevectors(v_angle); - traceline(pos, pos + (v_forward * 64), FALSE, this); - if (trace_fraction >= 1.0f) { - break; - } - } + v_angle[1] -= 180 + ((random() - 0.5) * 90); + v_angle[1] = Math_FixDelta(v_angle[1]); m_flChangePath = time + floor(random(2,10)); + angles = input_angles = v_angle; } + + if (m_flNextSentence > time) + return; + + TalkPanic(); } void