BotLib now responds to 'alert' flagged sounds as well. Also added a cooldown
timer so we don't call alerts too often.
This commit is contained in:
parent
6fb067eed3
commit
0fc52f726d
5 changed files with 56 additions and 1 deletions
|
@ -79,6 +79,7 @@ class bot:player
|
|||
virtual void(void) SeeThink;
|
||||
virtual void(int, int) BrainThink;
|
||||
virtual void(void) RunAI;
|
||||
virtual void(vector) NewRoute;
|
||||
virtual void(void) CreateObjective;
|
||||
virtual void(void) CheckRoute;
|
||||
virtual void(void) PreFrame;
|
||||
|
|
|
@ -259,6 +259,12 @@ bot::CheckRoute(void)
|
|||
}
|
||||
}
|
||||
|
||||
void
|
||||
bot::NewRoute(vector pos)
|
||||
{
|
||||
route_calculate(this, pos, 0, Bot_RouteCB);
|
||||
}
|
||||
|
||||
void
|
||||
bot::CreateObjective(void)
|
||||
{
|
||||
|
|
|
@ -19,7 +19,7 @@ bot::Pain(void)
|
|||
{
|
||||
CGameRules rules = g_grMode;
|
||||
|
||||
player::Pain();
|
||||
super::Pain();
|
||||
|
||||
if (rules.IsTeamPlay()) {
|
||||
if (g_dmg_eAttacker.flags & FL_CLIENT && g_dmg_eAttacker.team == team) {
|
||||
|
@ -99,3 +99,42 @@ bot::WeaponAttack(void)
|
|||
|
||||
m_iAttackMode = 1 - m_iAttackMode;
|
||||
}
|
||||
|
||||
var float g_botalert_timer;
|
||||
void
|
||||
BotLib_Alert(vector pos, float radius, float t)
|
||||
{
|
||||
CGameRules rules = g_grMode;
|
||||
|
||||
/* sometimes many alert-sounds happen at once... we don't really want that */
|
||||
if (g_botalert_timer > time)
|
||||
return;
|
||||
|
||||
for (entity w = world; (w = find(w, ::targetname, "_nuclide_bot_"));) {
|
||||
/* out of radius */
|
||||
if (vlen(pos - w.origin) > radius)
|
||||
continue;
|
||||
|
||||
bot f = (bot)w;
|
||||
|
||||
/* they already got a target of some kind */
|
||||
if (f.m_eTarget)
|
||||
continue;
|
||||
|
||||
/* if they're our friend... ignore*/
|
||||
if (rules.IsTeamPlay())
|
||||
if (w.team == t)
|
||||
continue;
|
||||
|
||||
/* if the bot is dead... ignore */
|
||||
if (f.health <= 0)
|
||||
continue;
|
||||
|
||||
/* we've heard a noise. investigate the location */
|
||||
print(sprintf("bot alerted by noise at %v\n", pos));
|
||||
f.RouteClear();
|
||||
f.NewRoute(pos);
|
||||
}
|
||||
|
||||
g_botalert_timer = time + 0.5f;
|
||||
}
|
||||
|
|
|
@ -997,9 +997,15 @@ NSMonster_ReadEntity(float new)
|
|||
me.ReceiveEntity(new, readfloat());
|
||||
}
|
||||
#else
|
||||
|
||||
var float g_monsteralert_timer;
|
||||
void
|
||||
NSMonster_AlertEnemyAlliance(vector pos, float radius, int alliance)
|
||||
{
|
||||
/* sometimes many alert-sounds happen at once... we don't really want that */
|
||||
if (g_monsteralert_timer > time)
|
||||
return;
|
||||
|
||||
for (entity w = world; (w = findfloat(w, ::takedamage, DAMAGE_YES));) {
|
||||
/* out of radius */
|
||||
if (vlen(pos - w.origin) > radius)
|
||||
|
@ -1027,5 +1033,7 @@ NSMonster_AlertEnemyAlliance(vector pos, float radius, int alliance)
|
|||
f.NewRoute(pos);
|
||||
f.m_flSequenceSpeed = 140;
|
||||
}
|
||||
|
||||
g_monsteralert_timer = time + 0.5f;
|
||||
}
|
||||
#endif
|
||||
|
|
|
@ -470,6 +470,7 @@ Sound_Play(entity target, int chan, string shader)
|
|||
}
|
||||
if (g_sounds[sample].flags & SNDFL_ALERTS) {
|
||||
NSMonster_AlertEnemyAlliance(target.origin, g_sounds[sample].dist_max, target.m_iAlliance);
|
||||
BotLib_Alert(target.origin, g_sounds[sample].dist_max, target.team);
|
||||
}
|
||||
#endif
|
||||
|
||||
|
|
Loading…
Reference in a new issue