From abdce0b61d0f8cee9ebc100b1879edb06b977c28 Mon Sep 17 00:00:00 2001 From: Marco Hladik Date: Fri, 28 Jan 2022 12:31:24 -0800 Subject: [PATCH] NSMonster: Improve 'seeing', don't target just anything with takedamage set to YES. Add 'AlertNearby()' which is called when a monster sees a new enemy, gets hit or dies. --- src/gs-entbase/shared/NSMonster.h | 3 +++ src/gs-entbase/shared/NSMonster.qc | 38 ++++++++++++++++++++++++++++-- 2 files changed, 39 insertions(+), 2 deletions(-) diff --git a/src/gs-entbase/shared/NSMonster.h b/src/gs-entbase/shared/NSMonster.h index 63fad80c..e4c5ca69 100644 --- a/src/gs-entbase/shared/NSMonster.h +++ b/src/gs-entbase/shared/NSMonster.h @@ -235,6 +235,9 @@ class NSMonster:NSSurfacePropEntity virtual void(void) SeeThink; virtual float(void) SeeFOV; + /* reactions */ + virtual void(void) AlertNearby; + /* movement */ virtual float(void) GetWalkSpeed; virtual float(void) GetChaseSpeed; diff --git a/src/gs-entbase/shared/NSMonster.qc b/src/gs-entbase/shared/NSMonster.qc index 493067ec..c1f27af6 100644 --- a/src/gs-entbase/shared/NSMonster.qc +++ b/src/gs-entbase/shared/NSMonster.qc @@ -116,7 +116,6 @@ NSMonster::IdleNoise(void) int NSMonster::IsFriend(int al) { - if (m_iAlliance == MAL_ROGUE) return (0); else if (al == m_iAlliance) @@ -145,6 +144,27 @@ NSMonster::SeeFOV(void) return 90; } +void +NSMonster::AlertNearby(void) +{ + if (m_eEnemy == __NULL__) + return; + + for (entity w = world; (w = findfloat(w, ::takedamage, DAMAGE_YES));) { + if (!IsFriend(w.m_iAlliance)) + continue; + + /* only bother if within 512 unit radius */ + if (vlen(origin - w.origin) > 512) + continue; + + //dprint(sprintf("Alert! %s get %s\n", w.classname, m_eEnemy.classname)); + NSMonster f = (NSMonster)w; + f.m_eEnemy = m_eEnemy; + } +} + + void NSMonster::SeeThink(void) { @@ -157,12 +177,19 @@ NSMonster::SeeThink(void) m_flSeeTime = time + 0.25f; for (entity w = world; (w = findfloat(w, ::takedamage, DAMAGE_YES));) { + /* prevent them from shooting non-sentient stuff */ + if (!(w.flags & FL_MONSTER) && !(w.flags & FL_CLIENT)) + continue; + + /* if they're our friend... ignore*/ if (IsFriend(w.m_iAlliance)) continue; + /* is the target dead? */ if (w.health <= 0) continue; + /* some monsters will ignore players */ if ((w.flags & FL_CLIENT) && (spawnflags & MSF_IGNOREPLAYER)) continue; @@ -177,8 +204,13 @@ NSMonster::SeeThink(void) other = world; traceline(origin, w.origin, MOVE_OTHERONLY, this); + /* we have line of sight with the player */ if (trace_fraction == 1.0f) { - m_eEnemy = w; + if (m_eEnemy != w) { + m_eEnemy = w; + AlertNearby(); + } + return; } } @@ -589,6 +621,8 @@ NSMonster::Pain(void) { if (!m_eEnemy) m_eEnemy = g_dmg_eAttacker; + + AlertNearby(); } void