updated enemy body part decetion

updated friend alarm notification
removed shaky aiming thru walls
This commit is contained in:
jeefo 2016-02-11 23:07:43 +03:00
commit 6d257e5375
3 changed files with 58 additions and 86 deletions

View file

@ -6011,11 +6011,6 @@ void Bot::ReactOnSound (void)
m_states |= STATE_SEEING_ENEMY; m_states |= STATE_SEEING_ENEMY;
m_seeEnemyTime = GetWorldTime (); m_seeEnemyTime = GetWorldTime ();
} }
else if (!m_lastEnemyOrigin.IsZero () && m_lastEnemy == player && m_seeEnemyTime + 3.0f > GetWorldTime () && yb_shoots_thru_walls.GetBool () && IsShootableThruObstacle (m_lastEnemyOrigin))
{
m_states |= STATE_SEEING_ENEMY;
m_seeEnemyTime = GetWorldTime ();
}
} }
} }

View file

@ -100,31 +100,33 @@ bool Bot::CheckVisibility (edict_t *target, Vector *origin, byte *bodyPart)
return false; return false;
} }
TraceResult result;
const Vector &botHead = EyePosition (); Vector eyes = EyePosition ();
TraceResult tr; Vector spot = target->v.origin;
*bodyPart = 0; *bodyPart = 0;
// check for the body TraceLine (eyes, spot, true, true, pev->pContainingEntity, &result);
TraceLine (botHead, target->v.origin, true, true, GetEntity (), &tr);
if (tr.flFraction >= 1.0f) if (result.flFraction >= 1.0f)
{ {
*bodyPart |= VISIBLE_BODY; *bodyPart |= VISIBLE_BODY;
*origin = target->v.origin; *origin = result.vecEndPos;
if (m_difficulty == 4) if (m_difficulty > 3)
origin->z += 3.0f; origin->z += 3.0f;
} }
// check for the head // check top of head
TraceLine (botHead, target->v.origin + target->v.view_ofs, true, true, GetEntity (), &tr); spot = spot + Vector (0, 0, 25.0f);
if (tr.flFraction >= 1.0f) TraceLine (eyes, spot, true, true, pev->pContainingEntity, &result);
if (result.flFraction >= 1.0f)
{ {
*bodyPart |= VISIBLE_HEAD; *bodyPart |= VISIBLE_HEAD;
*origin = target->v.origin + target->v.view_ofs; *origin = result.vecEndPos;
if (m_difficulty > 3) if (m_difficulty > 3)
origin->z += 1.0f; origin->z += 1.0f;
@ -133,64 +135,49 @@ bool Bot::CheckVisibility (edict_t *target, Vector *origin, byte *bodyPart)
if (*bodyPart != 0) if (*bodyPart != 0)
return true; return true;
// thanks for this code goes to kwo const float standFeet = 34.0f;
MakeVectors (target->v.angles); const float crouchFeet = 14.0f;
// worst case, choose random position in enemy body if (target->v.flags & FL_DUCKING)
for (int i = 0; i < 6; i++) spot.z = target->v.origin.z - crouchFeet;
else
spot.z = target->v.origin.z - standFeet;
TraceLine (eyes, spot, true, true, pev->pContainingEntity, &result);
if (result.flFraction >= 1.0f)
{ {
Vector pos = target->v.origin;
switch (i)
{
case 0: // left arm
pos.x -= 10.0f * g_pGlobals->v_right.x;
pos.y -= 10.0f * g_pGlobals->v_right.y;
pos.z += 8.0f;
break;
case 1: // right arm
pos.x += 10.0f * g_pGlobals->v_right.x;
pos.y += 10.0f * g_pGlobals->v_right.y;
pos.z += 8.0f;
break;
case 2: // left leg
pos.x -= 10.0f * g_pGlobals->v_right.x;
pos.y -= 10.0f * g_pGlobals->v_right.y;
pos.z -= 12.0f;
break;
case 3: // right leg
pos.x += 10.0f * g_pGlobals->v_right.x;
pos.y += 10.0f * g_pGlobals->v_right.y;
pos.z -= 12.0f;
break;
case 4: // left foot
pos.x -= 10.0f * g_pGlobals->v_right.x;
pos.y -= 10.0f * g_pGlobals->v_right.y;
pos.z -= 24.0f;
break;
case 5: // right foot
pos.x += 10.0f * g_pGlobals->v_right.x;
pos.y += 10.0f * g_pGlobals->v_right.y;
pos.z -= 24.0f;
break;
}
// check direct line to random part of the player body
TraceLine (botHead, pos, true, true, GetEntity (), &tr);
// check if we hit something
if (tr.flFraction >= 1.0f)
{
*origin = tr.vecEndPos;
*bodyPart |= VISIBLE_OTHER; *bodyPart |= VISIBLE_OTHER;
*origin = result.vecEndPos;
return true; return true;
} }
const float edgeOffset = 13.0f;
Vector dir = (target->v.origin - pev->origin).Normalize2D ();
Vector perp (-dir.y, dir.x, 0.0f);
spot = target->v.origin + Vector (perp.x * edgeOffset, perp.y * edgeOffset, 0);
TraceLine (eyes, spot, true, true, pev->pContainingEntity, &result);
if (result.flFraction >= 1.0f)
{
*bodyPart |= VISIBLE_OTHER;
*origin = result.vecEndPos;
return true;
}
spot = target->v.origin - Vector (perp.x * edgeOffset, perp.y * edgeOffset, 0);
TraceLine (eyes, spot, true, true, pev->pContainingEntity, &result);
if (result.flFraction >= 1.0f)
{
*bodyPart |= VISIBLE_OTHER;
*origin = result.vecEndPos;
return true;
} }
return false; return false;
} }
@ -348,6 +335,9 @@ bool Bot::LookupEnemy (void)
// keep track of when we last saw an enemy // keep track of when we last saw an enemy
m_seeEnemyTime = GetWorldTime (); m_seeEnemyTime = GetWorldTime ();
if (!(pev->oldbuttons & IN_ATTACK))
return true;
// 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 // 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 < GetMaxClients (); j++) for (int j = 0; j < GetMaxClients (); j++)
{ {
@ -356,17 +346,13 @@ bool Bot::LookupEnemy (void)
Bot *friendBot = bots.GetBot (g_clients[j].ent); Bot *friendBot = bots.GetBot (g_clients[j].ent);
if (friendBot != NULL) if (friendBot != NULL && friendBot->m_seeEnemyTime + 2.0f < GetWorldTime () && IsEntityNull (friendBot->m_lastEnemy) && IsVisible (pev->origin, ENT (friendBot->pev)) && friendBot->IsInViewCone (pev->origin))
{
if (friendBot->m_seeEnemyTime + 2.0f < GetWorldTime () || IsEntityNull (friendBot->m_lastEnemy))
{
if (IsVisible (pev->origin, ENT (friendBot->pev)))
{ {
friendBot->m_lastEnemy = newEnemy; friendBot->m_lastEnemy = newEnemy;
friendBot->m_lastEnemyOrigin = m_lastEnemyOrigin; friendBot->m_lastEnemyOrigin = m_lastEnemyOrigin;
friendBot->m_seeEnemyTime = GetWorldTime (); friendBot->m_seeEnemyTime = GetWorldTime ();
} friendBot->m_states |= (STATE_SUSPECT_ENEMY | STATE_HEARING_ENEMY);
} friendBot->m_aimFlags |= AIM_LAST_ENEMY;
} }
} }
return true; return true;
@ -387,7 +373,7 @@ bool Bot::LookupEnemy (void)
if (!UsesSniper ()) if (!UsesSniper ())
{ {
m_shootAtDeadTime = GetWorldTime () + 0.4f; m_shootAtDeadTime = GetWorldTime () + 0.4f;
m_actualReactionTime = 0.0; m_actualReactionTime = 0.0f;
m_states |= STATE_SUSPECT_ENEMY; m_states |= STATE_SUSPECT_ENEMY;
return true; return true;
@ -1164,16 +1150,7 @@ void Bot::CombatFight (void)
} }
else if (m_fightStyle == 1) else if (m_fightStyle == 1)
{ {
bool shouldDuck = true; // should duck if (!(m_visibility & (VISIBLE_HEAD | VISIBLE_BODY)) && GetTaskId () != TASK_SEEKCOVER && GetTaskId () != TASK_HUNTENEMY && (m_visibility & VISIBLE_BODY) && !(m_visibility & VISIBLE_OTHER) && waypoints.IsDuckVisible (m_currentWaypointIndex, waypoints.FindNearest (m_enemy->v.origin)))
// check the enemy height
float enemyHalfHeight = ((m_enemy->v.flags & FL_DUCKING) == FL_DUCKING ? 36.0f : 72.0f) * 0.5f;
// check center/feet
if (!IsVisible (m_enemy->v.origin, GetEntity ()) && !IsVisible (m_enemy->v.origin + Vector (0.0f, 0.0f, -enemyHalfHeight), GetEntity ()))
shouldDuck = false;
if (shouldDuck && GetTaskId () != TASK_SEEKCOVER && GetTaskId () != TASK_HUNTENEMY && (m_visibility & VISIBLE_BODY) && !(m_visibility & VISIBLE_OTHER) && waypoints.IsDuckVisible (m_currentWaypointIndex, waypoints.FindNearest (m_enemy->v.origin)))
m_duckTime = GetWorldTime () + 0.5f; m_duckTime = GetWorldTime () + 0.5f;
m_moveSpeed = 0.0f; m_moveSpeed = 0.0f;

View file

@ -289,7 +289,7 @@ void NetworkMsg::Execute (void *p)
{ {
Bot *bot = bots.GetBot (i); Bot *bot = bots.GetBot (i);
if (bot != NULL && IsAlive (bot->GetEntity ()) && GetTeam (bot->GetEntity ()) == GetTeam (victim) && IsVisible (killer->v.origin, bot->GetEntity ()) && IsEntityNull (bot->m_enemy) && GetTeam (killer) != GetTeam (victim)) if (bot != NULL && bot->m_seeEnemyTime + 2.0f < GetWorldTime () && IsAlive (bot->GetEntity ()) && GetTeam (bot->GetEntity ()) == GetTeam (victim) && IsVisible (killer->v.origin, bot->GetEntity ()) && IsEntityNull (bot->m_enemy) && GetTeam (killer) != GetTeam (victim))
{ {
bot->m_actualReactionTime = 0.0f; bot->m_actualReactionTime = 0.0f;
bot->m_seeEnemyTime = GetWorldTime (); bot->m_seeEnemyTime = GetWorldTime ();