tweaked antistuck code

This commit is contained in:
jeefo 2015-07-20 21:26:20 +03:00
commit 2ca5002e45
6 changed files with 106 additions and 104 deletions

View file

@ -1052,6 +1052,7 @@ private:
bool RateGroundWeapon (edict_t *ent);
bool ReactOnEnemy (void);
void ResetCollideState (void);
void IgnoreCollisionShortly (void);
void SetConditions (void);
void UpdateEmotions (void);
void SetStrafeSpeed (const Vector &moveDir, float strafeSpeed);

View file

@ -2088,7 +2088,7 @@ void Bot::PushTask (TaskID id, float desire, int data, float time, bool resume)
m_tasks.Push (item);
DeleteSearchNodes ();
m_lastCollTime = GetWorldTime () + 0.5;
IgnoreCollisionShortly ();
// leader bot?
if (m_isLeader && GetTaskId () == TASK_SEEKCOVER)
@ -2833,7 +2833,7 @@ void Bot::ChooseAimDirection (void)
if (changePredictedEnemy)
{
m_lookAt = waypoint->GetPath (GetAimingWaypoint (m_lastEnemyOrigin))->origin + pev->view_ofs;
m_lookAt = waypoint->GetPath (GetAimingWaypoint (m_lastEnemyOrigin))->origin;
m_camp = m_lookAt;
m_timeNextTracking = GetWorldTime () + 2.0f;
@ -2855,12 +2855,12 @@ void Bot::ChooseAimDirection (void)
if (m_team == TEAM_TF)
{
if ((g_experienceData + (index * g_numWaypoints) + index)->team0DangerIndex != -1)
m_lookAt = waypoint->GetPath ((g_experienceData + (index * g_numWaypoints) + index)->team0DangerIndex)->origin + pev->view_ofs;
m_lookAt = waypoint->GetPath ((g_experienceData + (index * g_numWaypoints) + index)->team0DangerIndex)->origin;
}
else
{
if ((g_experienceData + (index * g_numWaypoints) + index)->team1DangerIndex != -1)
m_lookAt = waypoint->GetPath ((g_experienceData + (index * g_numWaypoints) + index)->team1DangerIndex)->origin + pev->view_ofs;
m_lookAt = waypoint->GetPath ((g_experienceData + (index * g_numWaypoints) + index)->team1DangerIndex)->origin;
}
}
}
@ -3257,8 +3257,7 @@ void Bot::RunTask_Spray (void)
m_moveSpeed = 0.0f;
m_strafeSpeed = 0.0f;
m_isStuck = false;
m_lastCollTime = GetWorldTime () + 0.5f;
IgnoreCollisionShortly ();
}
void Bot::RunTask_HuntEnemy (void)
@ -3423,8 +3422,7 @@ void Bot::RunTask_Attack (void)
if (!IsEntityNull (m_enemy))
{
ResetCollideState ();
m_lastCollTime = GetWorldTime () + 0.5f;
IgnoreCollisionShortly ();
if (IsOnLadder ())
{
@ -4050,7 +4048,9 @@ void Bot::RunTask_Throw_HE (void)
m_isUsingGrenade = true;
m_checkTerrain = false;
if ((pev->origin - dest).GetLengthSquared () < 400 * 400)
IgnoreCollisionShortly ();
if ((pev->origin - dest).GetLengthSquared () < GET_SQUARE (400.0f))
{
// heck, I don't wanna blow up myself
m_grenadeCheckTime = GetWorldTime () + MAX_GRENADE_TIMER;
@ -4124,6 +4124,8 @@ void Bot::RunTask_Throw_FL (void)
m_isUsingGrenade = true;
m_checkTerrain = false;
IgnoreCollisionShortly ();
m_grenade = CheckThrow (EyePosition (), dest);
if (m_grenade.GetLengthSquared () < 100)
@ -4183,6 +4185,8 @@ void Bot::RunTask_Throw_SG (void)
m_checkTerrain = false;
m_isUsingGrenade = true;
IgnoreCollisionShortly ();
Vector src = m_lastEnemyOrigin - pev->velocity;
// predict where the enemy is in 0.5 secs
@ -4525,7 +4529,7 @@ void Bot::RunTask_PickupItem ()
}
}
}
m_lastCollTime = GetWorldTime () + 0.1; // also don't consider being stuck
IgnoreCollisionShortly (); // also don't consider being stuck
}
break;
@ -5227,9 +5231,9 @@ void Bot::TakeDamage (edict_t *inflictor, int damage, int armor, int bits)
m_lastDamageType = bits;
CollectGoalExperience (damage, m_team);
if (m_seeEnemyTime + 4.0f < GetWorldTime () && IsValidPlayer (inflictor))
if (IsValidPlayer (inflictor))
{
if (GetTeam (inflictor) == m_team && yb_tkpunish.GetBool () && !botMgr->GetBot (inflictor))
if (m_seeEnemyTime + 4.0f < GetWorldTime () && yb_tkpunish.GetBool () && GetTeam (inflictor) == m_team && !botMgr->GetBot (inflictor))
{
// alright, die you teamkiller!!!
m_actualReactionTime = 0.0f;

View file

@ -1249,9 +1249,7 @@ void Bot::CombatFight (void)
pev->button &= ~IN_JUMP;
}
}
m_isStuck = false;
m_lastCollTime = GetWorldTime () + 0.5f;
IgnoreCollisionShortly ();
}
bool Bot::HasPrimaryWeapon (void)

View file

@ -795,15 +795,8 @@ Bot::Bot (edict_t *bot, int difficulty, int personality, int team, int member, c
m_lastCommandTime = GetWorldTime () - 0.1f;
m_frameInterval = GetWorldTime ();
m_msecValRest = 0.0f;
m_timePeriodicUpdate = 0.0f;
bot->v.idealpitch = bot->v.v_angle.x;
bot->v.ideal_yaw = bot->v.v_angle.y;
bot->v.yaw_speed = Random.Float (m_difficulty * 40, m_difficulty * 45);
bot->v.pitch_speed = Random.Float (m_difficulty * 40, m_difficulty * 45);
switch (personality)
{
case 1:
@ -1098,7 +1091,6 @@ void Bot::NewRound (void)
m_timeLogoSpray = GetWorldTime () + Random.Float (0.5, 2.0);
m_spawnTime = GetWorldTime ();
m_lastChatTime = GetWorldTime ();
pev->v_angle.y = pev->ideal_yaw;
m_timeCamping = 0;
m_campDirection = 0;

View file

@ -294,15 +294,22 @@ void Bot::ResetCollideState (void)
m_collisionState = COLLISION_NOTDECICED;
m_collStateIndex = 0;
m_isStuck = false;
for (int i = 0; i < MAX_COLLIDE_MOVES; i++)
m_collideMoves[i] = 0;
}
void Bot::IgnoreCollisionShortly (void)
{
ResetCollideState ();
m_lastCollTime = GetWorldTime () + 0.35f;
m_isStuck = false;
m_checkTerrain = false;
}
void Bot::CheckCloseAvoidance (const Vector &dirNormal)
{
if (m_seeEnemyTime + 1.0f < GetWorldTime () || g_timeRoundStart + 10.0f < GetWorldTime ())
if (m_seeEnemyTime + 1.5f < GetWorldTime ())
return;
edict_t *nearest = NULL;
@ -327,7 +334,7 @@ void Bot::CheckCloseAvoidance (const Vector &dirNormal)
}
}
if (playerCount < 3 && IsValidPlayer (nearest))
if (playerCount < 4 && IsValidPlayer (nearest))
{
MakeVectors (m_moveAngles); // use our movement angles
@ -343,16 +350,14 @@ void Bot::CheckCloseAvoidance (const Vector &dirNormal)
if ((nearest->v.origin - moved).GetLength2D () <= 48.0 || (nearestDistance <= 56.0 && nextFrameDistance < nearestDistance))
{
// to start strafing, we have to first figure out if the target is on the left side or right side
Vector dirToPoint = (pev->origin - nearest->v.origin).Get2D ();
const Vector &dirToPoint = (pev->origin - nearest->v.origin).Get2D ();
if ((dirToPoint | g_pGlobals->v_right.Get2D ()) > 0.0)
if ((dirToPoint | g_pGlobals->v_right.Get2D ()) > 0.0f)
SetStrafeSpeed (dirNormal, pev->maxspeed);
else
SetStrafeSpeed (dirNormal, -pev->maxspeed);
ResetCollideState ();
if (nearestDistance < 56.0 && (dirToPoint | g_pGlobals->v_forward.Get2D ()) < 0.0)
if (nearestDistance < 56.0 && (dirToPoint | g_pGlobals->v_forward.Get2D ()) < 0.0f)
m_moveSpeed = -pev->maxspeed;
}
}
@ -371,18 +376,18 @@ void Bot::CheckTerrain (float movedDistance, const Vector &dirNormal)
// Standing still, no need to check?
// FIXME: doesn't care for ladder movement (handled separately) should be included in some way
if ((m_moveSpeed >= 10 || m_strafeSpeed >= 10) && m_lastCollTime < GetWorldTime ())
if ((m_moveSpeed >= 10 || m_strafeSpeed >= 10) && m_lastCollTime < GetWorldTime () && m_seeEnemyTime + 0.8f < GetWorldTime () && GetTaskId () != TASK_ATTACK)
{
bool cantMoveForward = false;
if (movedDistance < 2.0 && m_prevSpeed >= 1.0) // didn't we move enough previously?
if (movedDistance < 2.0f && m_prevSpeed >= 20.0f) // didn't we move enough previously?
{
// Then consider being stuck
m_prevTime = GetWorldTime ();
m_isStuck = true;
if (m_firstCollideTime == 0.0)
m_firstCollideTime = GetWorldTime () + 0.2;
m_firstCollideTime = GetWorldTime () + 0.2f;
}
else // not stuck yet
{
@ -390,7 +395,7 @@ void Bot::CheckTerrain (float movedDistance, const Vector &dirNormal)
if ((cantMoveForward = CantMoveForward (dirNormal, &tr)) && !IsOnLadder ())
{
if (m_firstCollideTime == 0.0)
m_firstCollideTime = GetWorldTime () + 0.2;
m_firstCollideTime = GetWorldTime () + 0.2f;
else if (m_firstCollideTime <= GetWorldTime ())
m_isStuck = true;
@ -423,7 +428,7 @@ void Bot::CheckTerrain (float movedDistance, const Vector &dirNormal)
else if (IsInWater ())
bits |= (PROBE_JUMP | PROBE_STRAFE);
else
bits |= ((Random.Long (0, 20) > (cantMoveForward ? 10 : 7) ? PROBE_JUMP : 0) | PROBE_STRAFE | PROBE_DUCK);
bits |= (PROBE_STRAFE | (Random.Long (0, 20) > (cantMoveForward ? 8 : 5) ? PROBE_JUMP : 0) | Random.Long (0, 100) > (cantMoveForward ? 20 : 5) ? PROBE_DUCK : 0));
// collision check allowed if not flying through the air
if (IsOnFloor () || IsOnLadder () || IsInWater ())
@ -432,70 +437,10 @@ void Bot::CheckTerrain (float movedDistance, const Vector &dirNormal)
int i = 0;
// first 4 entries hold the possible collision states
state[i++] = COLLISION_JUMP;
state[i++] = COLLISION_DUCK;
state[i++] = COLLISION_STRAFELEFT;
state[i++] = COLLISION_STRAFERIGHT;
// now weight all possible states
if (bits & PROBE_JUMP)
{
state[i] = 0;
if (CanJumpUp (dirNormal))
state[i] += 10;
if (m_destOrigin.z >= pev->origin.z + 18.0)
state[i] += 5;
if (EntityIsVisible (m_destOrigin))
{
MakeVectors (m_moveAngles);
src = EyePosition ();
src = src + g_pGlobals->v_right * 15;
TraceLine (src, m_destOrigin, true, true, GetEntity (), &tr);
if (tr.flFraction >= 1.0)
{
src = EyePosition ();
src = src - g_pGlobals->v_right * 15;
TraceLine (src, m_destOrigin, true, true, GetEntity (), &tr);
if (tr.flFraction >= 1.0)
state[i] += 5;
}
}
if (pev->flags & FL_DUCKING)
src = pev->origin;
else
src = pev->origin + Vector (0, 0, -17);
dst = src + dirNormal * 30;
TraceLine (src, dst, true, true, GetEntity (), &tr);
if (tr.flFraction != 1.0)
state[i] += 10;
}
else
state[i] = 0;
i++;
if (bits & PROBE_DUCK)
{
state[i] = 0;
if (CanDuckUnder (dirNormal))
state[i] += 10;
if ((m_destOrigin.z + 36.0 <= pev->origin.z) && EntityIsVisible (m_destOrigin))
state[i] += 5;
}
else
state[i] = 0;
i++;
state[i++] = COLLISION_JUMP;
state[i++] = COLLISION_DUCK;
if (bits & PROBE_STRAFE)
{
@ -556,6 +501,65 @@ void Bot::CheckTerrain (float movedDistance, const Vector &dirNormal)
state[i] -= 5;
}
// now weight all possible states
if (bits & PROBE_JUMP)
{
state[i] = 0;
if (CanJumpUp (dirNormal))
state[i] += 10;
if (m_destOrigin.z >= pev->origin.z + 18.0)
state[i] += 5;
if (EntityIsVisible (m_destOrigin))
{
MakeVectors (m_moveAngles);
src = EyePosition ();
src = src + g_pGlobals->v_right * 15;
TraceLine (src, m_destOrigin, true, true, GetEntity (), &tr);
if (tr.flFraction >= 1.0)
{
src = EyePosition ();
src = src - g_pGlobals->v_right * 15;
TraceLine (src, m_destOrigin, true, true, GetEntity (), &tr);
if (tr.flFraction >= 1.0)
state[i] += 5;
}
}
if (pev->flags & FL_DUCKING)
src = pev->origin;
else
src = pev->origin + Vector (0, 0, -17);
dst = src + dirNormal * 30;
TraceLine (src, dst, true, true, GetEntity (), &tr);
if (tr.flFraction != 1.0)
state[i] += 10;
}
else
state[i] = 0;
i++;
if (bits & PROBE_DUCK)
{
state[i] = 0;
if (CanDuckUnder (dirNormal))
state[i] += 10;
if ((m_destOrigin.z + 36.0 <= pev->origin.z) && EntityIsVisible (m_destOrigin))
state[i] += 5;
}
else
state[i] = 0;
i++;
// weighted all possible moves, now sort them to start with most probable
bool isSorting = false;
@ -1096,7 +1100,7 @@ bool Bot::DoWaypointNav (void)
// if the door is near enough...
if ((GetEntityOrigin (tr.pHit) - pev->origin).GetLengthSquared () < 2500)
{
m_lastCollTime = GetWorldTime () + 0.5; // don't consider being stuck
IgnoreCollisionShortly (); // don't consider being stuck
if (Random.Long (1, 100) < 50)
MDLL_Use (tr.pHit, GetEntity ()); // also 'use' the door randomly
@ -3277,7 +3281,10 @@ bool Bot::IsPointOccupied (int index)
{
int occupyId = GetShootingConeDeviation (bot->GetEntity (), &pev->origin) >= 0.7f ? bot->m_prevWptIndex[0] : m_currentWaypointIndex;
if (occupyId == index || bot->GetTask ()->data == index || (waypoint->GetPath (occupyId)->origin - waypoint->GetPath (index)->origin).GetLengthSquared () < 4096.0f)
// length check
float length = (waypoint->GetPath (occupyId)->origin - waypoint->GetPath (index)->origin).GetLength ();
if (occupyId == index || bot->GetTask ()->data == index || length < 96.0f || length < waypoint->GetPath (occupyId)->radius * 0.5f)
return true;
}
}

View file

@ -953,7 +953,7 @@ void Waypoint::InitExperienceTab (void)
delete [] experienceLoad;
}
else
AddLogEntry (true, LL_ERROR, "Experience data damaged (wrong version, or not for this map)");
AddLogEntry (true, LL_WARNING, "Experience data damaged (wrong version, or not for this map)");
}
}
}
@ -1018,7 +1018,7 @@ void Waypoint::InitVisibilityTab (void)
m_visibilityIndex = 0;
m_redoneVisibility = true;
AddLogEntry (true, LL_WARNING, "Vistable damaged (wrong version, or not for this map), vistable will be rebuilded.");
AddLogEntry (true, LL_WARNING, "Visibility table damaged (wrong version, or not for this map), vistable will be rebuilded.");
fp.Close ();
return;
@ -2160,7 +2160,7 @@ bool Waypoint::LoadPathMatrix (void)
if (num != g_numWaypoints)
{
AddLogEntry (true, LL_DEFAULT, "Wrong number of points (pmt:%d/cur:%d). Matrix will be rebuilded", num, g_numWaypoints);
AddLogEntry (true, LL_WARNING, "Pathmatrix damaged (wrong version, or not for this map). Pathmatrix will be rebuilt.");
fp.Close ();
return false;