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);
#else
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 */
if (m_iFlags & MSF_HORDE) {
m_eEnemy = Entity_FindClosest(this, "player");
m_eEnemy = NSMonster_FindClosestPlayer(this);
if (m_eEnemy)
NewRoute(m_eEnemy.origin);
@ -1121,4 +1121,27 @@ NSMonster_AlertEnemyAlliance(vector pos, float radius, int alliance)
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

View File

@ -62,10 +62,6 @@ entity Entity_FindClosest(entity target, string cname) {
bestdist = 9999999;
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);
if (dist < bestdist) {