a little cleanup of code
This commit is contained in:
parent
016c91f61a
commit
c4d6ce3c45
14 changed files with 430 additions and 343 deletions
|
|
@ -22,10 +22,12 @@ int Bot::GetNearbyFriendsNearPosition(const Vector &origin, float radius)
|
|||
|
||||
for (int i = 0; i < engine.MaxClients (); i++)
|
||||
{
|
||||
if (!(g_clients[i].flags & CF_USED) || !(g_clients[i].flags & CF_ALIVE) || g_clients[i].team != m_team || g_clients[i].ent == GetEntity ())
|
||||
const Client &client = g_clients[i];
|
||||
|
||||
if (!(client.flags & CF_USED) || !(client.flags & CF_ALIVE) || client.team != m_team || client.ent == GetEntity ())
|
||||
continue;
|
||||
|
||||
if ((g_clients[i].origin - origin).GetLengthSquared () < GET_SQUARE (radius))
|
||||
if ((client.origin - origin).GetLengthSquared () < GET_SQUARE (radius))
|
||||
count++;
|
||||
}
|
||||
return count;
|
||||
|
|
@ -37,10 +39,12 @@ int Bot::GetNearbyEnemiesNearPosition(const Vector &origin, float radius)
|
|||
|
||||
for (int i = 0; i < engine.MaxClients (); i++)
|
||||
{
|
||||
if (!(g_clients[i].flags & CF_USED) || !(g_clients[i].flags & CF_ALIVE) || g_clients[i].team == m_team)
|
||||
const Client &client = g_clients[i];
|
||||
|
||||
if (!(client.flags & CF_USED) || !(client.flags & CF_ALIVE) || client.team == m_team)
|
||||
continue;
|
||||
|
||||
if ((g_clients[i].origin - origin).GetLengthSquared () < GET_SQUARE (radius))
|
||||
if ((client.origin - origin).GetLengthSquared () < GET_SQUARE (radius))
|
||||
count++;
|
||||
}
|
||||
return count;
|
||||
|
|
@ -246,10 +250,12 @@ bool Bot::LookupEnemy (void)
|
|||
// search the world for players...
|
||||
for (int i = 0; i < engine.MaxClients (); i++)
|
||||
{
|
||||
if (!(g_clients[i].flags & CF_USED) || !(g_clients[i].flags & CF_ALIVE) || g_clients[i].team == m_team || g_clients[i].ent == GetEntity ())
|
||||
const Client &client = g_clients[i];
|
||||
|
||||
if (!(client.flags & CF_USED) || !(client.flags & CF_ALIVE) || client.team == m_team || client.ent == GetEntity ())
|
||||
continue;
|
||||
|
||||
player = g_clients[i].ent;
|
||||
player = client.ent;
|
||||
|
||||
// let the engine check if this player is potentially visible
|
||||
if (!ENGINE_CHECK_VISIBILITY (player, pvs))
|
||||
|
|
@ -340,18 +346,20 @@ bool Bot::LookupEnemy (void)
|
|||
// now alarm all teammates who see this bot & don't have an actual enemy of the bots enemy should simulate human players seeing a teammate firing
|
||||
for (int j = 0; j < engine.MaxClients (); j++)
|
||||
{
|
||||
if (!(g_clients[j].flags & CF_USED) || !(g_clients[j].flags & CF_ALIVE) || g_clients[j].team != m_team || g_clients[j].ent == GetEntity ())
|
||||
const Client &client = g_clients[j];
|
||||
|
||||
if (!(client.flags & CF_USED) || !(client.flags & CF_ALIVE) || client.team != m_team || client.ent == GetEntity ())
|
||||
continue;
|
||||
|
||||
Bot *friendBot = bots.GetBot (g_clients[j].ent);
|
||||
Bot *other = bots.GetBot (client.ent);
|
||||
|
||||
if (friendBot != NULL && friendBot->m_seeEnemyTime + 2.0f < engine.Time () && engine.IsNullEntity (friendBot->m_lastEnemy) && IsVisible (pev->origin, friendBot->GetEntity ()) && friendBot->IsInViewCone (pev->origin))
|
||||
if (other != NULL && other->m_seeEnemyTime + 2.0f < engine.Time () && engine.IsNullEntity (other->m_lastEnemy) && IsVisible (pev->origin, other->GetEntity ()) && other->IsInViewCone (pev->origin))
|
||||
{
|
||||
friendBot->m_lastEnemy = newEnemy;
|
||||
friendBot->m_lastEnemyOrigin = m_lastEnemyOrigin;
|
||||
friendBot->m_seeEnemyTime = engine.Time ();
|
||||
friendBot->m_states |= (STATE_SUSPECT_ENEMY | STATE_HEARING_ENEMY);
|
||||
friendBot->m_aimFlags |= AIM_LAST_ENEMY;
|
||||
other->m_lastEnemy = newEnemy;
|
||||
other->m_lastEnemyOrigin = m_lastEnemyOrigin;
|
||||
other->m_seeEnemyTime = engine.Time ();
|
||||
other->m_states |= (STATE_SUSPECT_ENEMY | STATE_HEARING_ENEMY);
|
||||
other->m_aimFlags |= AIM_LAST_ENEMY;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
|
|
@ -572,10 +580,12 @@ bool Bot::IsFriendInLineOfFire (float distance)
|
|||
// search the world for players
|
||||
for (int i = 0; i < engine.MaxClients (); i++)
|
||||
{
|
||||
if (!(g_clients[i].flags & CF_USED) || !(g_clients[i].flags & CF_ALIVE) || g_clients[i].team != m_team || g_clients[i].ent == GetEntity ())
|
||||
const Client &client = g_clients[i];
|
||||
|
||||
if (!(client.flags & CF_USED) || !(client.flags & CF_ALIVE) || client.team != m_team || client.ent == GetEntity ())
|
||||
continue;
|
||||
|
||||
edict_t *ent = g_clients[i].ent;
|
||||
edict_t *ent = client.ent;
|
||||
|
||||
float friendDistance = (ent->v.origin - pev->origin).GetLength ();
|
||||
float squareDistance = sqrtf (1089.0f + (friendDistance * friendDistance));
|
||||
|
|
@ -1429,22 +1439,24 @@ void Bot::SelectWeaponbyNumber (int num)
|
|||
void Bot::AttachToUser (void)
|
||||
{
|
||||
// this function forces bot to follow user
|
||||
Array <edict_t *> foundUsers;
|
||||
Array <edict_t *> users;
|
||||
|
||||
// search friends near us
|
||||
for (int i = 0; i < engine.MaxClients (); i++)
|
||||
{
|
||||
if (!(g_clients[i].flags & CF_USED) || !(g_clients[i].flags & CF_ALIVE) || g_clients[i].team != m_team || g_clients[i].ent == GetEntity ())
|
||||
const Client &client = g_clients[i];
|
||||
|
||||
if (!(client.flags & CF_USED) || !(client.flags & CF_ALIVE) || client.team != m_team || client.ent == GetEntity ())
|
||||
continue;
|
||||
|
||||
if (EntityIsVisible (g_clients[i].origin) && !IsValidBot (g_clients[i].ent))
|
||||
foundUsers.Push (g_clients[i].ent);
|
||||
if (EntityIsVisible (client.origin) && !IsValidBot (client.ent))
|
||||
users.Push (client.ent);
|
||||
}
|
||||
|
||||
if (foundUsers.IsEmpty ())
|
||||
if (users.IsEmpty ())
|
||||
return;
|
||||
|
||||
m_targetEntity = foundUsers.GetRandomElement ();
|
||||
m_targetEntity = users.GetRandomElement ();
|
||||
|
||||
ChatterMessage (Chatter_LeadOnSir);
|
||||
PushTask (TASK_FOLLOWUSER, TASKPRI_FOLLOWUSER, -1, 0.0f, true);
|
||||
|
|
@ -1462,12 +1474,14 @@ void Bot::CommandTeam (void)
|
|||
// search teammates seen by this bot
|
||||
for (int i = 0; i < engine.MaxClients (); i++)
|
||||
{
|
||||
if (!(g_clients[i].flags & CF_USED) || !(g_clients[i].flags & CF_ALIVE) || g_clients[i].team != m_team || g_clients[i].ent == GetEntity ())
|
||||
const Client &client = g_clients[i];
|
||||
|
||||
if (!(client.flags & CF_USED) || !(client.flags & CF_ALIVE) || client.team != m_team || client.ent == GetEntity ())
|
||||
continue;
|
||||
|
||||
memberExists = true;
|
||||
|
||||
if (EntityIsVisible (g_clients[i].origin))
|
||||
if (EntityIsVisible (client.origin))
|
||||
{
|
||||
memberNear = true;
|
||||
break;
|
||||
|
|
@ -1496,13 +1510,15 @@ bool Bot::IsGroupOfEnemies (const Vector &location, int numEnemies, int radius)
|
|||
// search the world for enemy players...
|
||||
for (int i = 0; i < engine.MaxClients (); i++)
|
||||
{
|
||||
if (!(g_clients[i].flags & CF_USED) || !(g_clients[i].flags & CF_ALIVE) || g_clients[i].ent == GetEntity ())
|
||||
const Client &client = g_clients[i];
|
||||
|
||||
if (!(client.flags & CF_USED) || !(client.flags & CF_ALIVE) || client.ent == GetEntity ())
|
||||
continue;
|
||||
|
||||
if ((g_clients[i].ent->v.origin - location).GetLengthSquared () < GET_SQUARE (radius))
|
||||
if ((client.ent->v.origin - location).GetLengthSquared () < GET_SQUARE (radius))
|
||||
{
|
||||
// don't target our teammates...
|
||||
if (g_clients[i].team == m_team)
|
||||
if (client.team == m_team)
|
||||
return false;
|
||||
|
||||
if (numPlayers++ > numEnemies)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue