Change the last commit by turning this into an NSMonster specific function instead.

This commit is contained in:
Marco Cawthorne 2022-06-08 17:41:02 -07:00
parent 80099317cb
commit a7d7dcd9ee
Signed by: eukara
GPG Key ID: CE2032F0A2882A22
3 changed files with 26 additions and 6 deletions

View File

@ -289,4 +289,5 @@ string Sentences_GetSamples(string);
string Sentences_ProcessSample(string); string Sentences_ProcessSample(string);
#else #else
void NSMonster_AlertEnemyAlliance(vector pos, float radius, int alliance); void NSMonster_AlertEnemyAlliance(vector pos, float radius, int alliance);
#endif entity NSMonster_FindClosestPlayer(entity);
#endif

View File

@ -182,7 +182,7 @@ NSMonster::SeeThink(void)
/* a horse type monster always knows where the nearest player is */ /* a horse type monster always knows where the nearest player is */
if (m_iFlags & MSF_HORDE) { if (m_iFlags & MSF_HORDE) {
m_eEnemy = Entity_FindClosest(this, "player"); m_eEnemy = NSMonster_FindClosestPlayer(this);
if (m_eEnemy) if (m_eEnemy)
NewRoute(m_eEnemy.origin); NewRoute(m_eEnemy.origin);
@ -1121,4 +1121,27 @@ NSMonster_AlertEnemyAlliance(vector pos, float radius, int alliance)
g_monsteralert_timer = time + 0.5f; g_monsteralert_timer = time + 0.5f;
} }
entity NSMonster_FindClosestPlayer(entity target) {
entity best = world;
float bestdist;
float dist;
bestdist = 9999999;
for (entity e = world; (e = find(e, classname, "player"));) {
/* hack: don't ever return dead players. they're invisible. */
if (e.health <= 0)
continue;
dist = vlen(target.origin - e.origin);
if (dist < bestdist) {
bestdist = dist;
best = e;
}
}
return best;
}
#endif #endif

View File

@ -62,10 +62,6 @@ entity Entity_FindClosest(entity target, string cname) {
bestdist = 9999999; bestdist = 9999999;
for (entity e = world; (e = find(e, classname, cname));) { for (entity e = world; (e = find(e, classname, cname));) {
/* hack: don't ever return dead players. they're invisible. */
if (cname == "player" && e.health <= 0)
continue;
dist = vlen(target.origin - e.origin); dist = vlen(target.origin - e.origin);
if (dist < bestdist) { if (dist < bestdist) {