CBaseNPC: Add ::StartleAllies() and ::TalkPanic() methods. Which handle

behaviour related to the MONSTER_FEAR flag.
This commit is contained in:
Marco Cawthorne 2021-03-06 17:43:08 +01:00
parent 8b4cd6b8c7
commit f13754a8c3
2 changed files with 34 additions and 19 deletions

View File

@ -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;

View File

@ -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