From 3042325f708d8205934d4cc55e4a0534d9e6af9d Mon Sep 17 00:00:00 2001 From: Dmitry Date: Sun, 7 Jun 2015 23:06:23 +0300 Subject: [PATCH] fixed pathfinding problems (again) --- source/basecode.cpp | 30 +++++++++++++++++++++++------- source/combat.cpp | 3 +-- source/navigate.cpp | 39 ++++++++++++++++++++++++++++++++++++--- source/waypoint.cpp | 23 ++++++++++++----------- 4 files changed, 72 insertions(+), 23 deletions(-) diff --git a/source/basecode.cpp b/source/basecode.cpp index c252d80..c1852f4 100644 --- a/source/basecode.cpp +++ b/source/basecode.cpp @@ -3290,7 +3290,7 @@ void Bot::RunTask (void) MakeVectors (pev->v_angle); - m_timeCamping = GetWorldTime () + g_randGen.Float (0.3f, 0.6f); + m_timeCamping = GetWorldTime () + g_randGen.Float (10.0f, 30.0f); StartTask (TASK_CAMP, TASKPRI_CAMP, -1, m_timeCamping, true); m_camp = Vector (m_currentPath->campStartX, m_currentPath->campStartY, 0.0f); @@ -4198,7 +4198,7 @@ void Bot::RunTask (void) destIndex = newIndex; } - if (destIndex >= 0 && destIndex < g_numWaypoints && destIndex != m_currentWaypointIndex) + if (destIndex >= 0 && destIndex < g_numWaypoints && destIndex != m_currentWaypointIndex && m_currentWaypointIndex >= 0 && m_currentWaypointIndex < g_numWaypoints) { m_prevGoalIndex = destIndex; GetTask ()->data = destIndex; @@ -4921,10 +4921,6 @@ void Bot::BotAI (void) m_moveAngles.ClampAngles (); m_moveAngles.x *= -1.0; // invert for engine -#if 0 // get rid of ugly hack - if (yb_hardcore_mode && GetTaskId () == TASK_NORMAL && ((m_aimFlags & AIM_ENEMY) || (m_states & STATE_SEEING_ENEMY)) && !IsOnLadder ()) - CombatFight (); - if (m_difficulty == 4 && ((m_aimFlags & AIM_ENEMY) || (m_states & (STATE_SEEING_ENEMY | STATE_SUSPECT_ENEMY)) || (GetTaskId () == TASK_SEEKCOVER && (m_isReloading || m_isVIP))) && !yb_jasonmode.GetBool () && GetTaskId () != TASK_CAMP && !IsOnLadder ()) { m_moveToGoal = false; // don't move to goal @@ -4933,7 +4929,6 @@ void Bot::BotAI (void) if (IsValidPlayer (m_enemy)) CombatFight (); } -#endif // check if we need to escape from bomb if ((g_mapType & MAP_DE) && g_bombPlanted && m_notKilled && GetTaskId () != TASK_ESCAPEFROMBOMB && GetTaskId () != TASK_CAMP && OutOfBombTimer ()) @@ -6075,6 +6070,27 @@ void Bot::ReactOnSound (void) return; } } + extern ConVar yb_shoots_thru_walls; + + // check if heard enemy can be seen + if (CheckVisibility (VARS (player), &m_lastEnemyOrigin, &m_visibility)) + { + m_enemy = player; + m_lastEnemy = player; + m_enemyOrigin = m_lastEnemyOrigin; + + m_states |= STATE_SEEING_ENEMY; + m_seeEnemyTime = GetWorldTime (); + } + else if (m_lastEnemy == player && m_seeEnemyTime + 1.0 > GetWorldTime () && yb_shoots_thru_walls.GetBool () && IsShootableThruObstacle (player->v.origin)) + { + m_enemy = player; + m_lastEnemy = player; + m_lastEnemyOrigin = player->v.origin; + + m_states |= STATE_SEEING_ENEMY; + m_seeEnemyTime = GetWorldTime (); + } } } diff --git a/source/combat.cpp b/source/combat.cpp index 5fafeb8..b981f86 100644 --- a/source/combat.cpp +++ b/source/combat.cpp @@ -962,7 +962,7 @@ void Bot::CombatFight (void) float distance = enemyOrigin.GetLength (); // how far away is the enemy scum? - if (m_timeWaypointMove + m_frameInterval < GetWorldTime ()) + if (m_timeWaypointMove + m_frameInterval + 0.5f < GetWorldTime ()) { int approach; @@ -980,7 +980,6 @@ void Bot::CombatFight (void) approach = 49; } - if (UsesPistol() && !((m_enemy->v.weapons & WEAPON_SECONDARY) || (m_enemy->v.weapons & (1 << WEAPON_SG550))) && !g_bombPlanted) { m_fearLevel += 0.5; diff --git a/source/navigate.cpp b/source/navigate.cpp index 6cd99f3..b390933 100644 --- a/source/navigate.cpp +++ b/source/navigate.cpp @@ -1525,11 +1525,22 @@ float hfunctionSquareDist (int index, int, int goalIndex) Path *start = g_waypoint->GetPath (index); Path *goal = g_waypoint->GetPath (goalIndex); +#if 0 float deltaX = fabsf (start->origin.x - goal->origin.x); float deltaY = fabsf (start->origin.y - goal->origin.y); float deltaZ = fabsf (start->origin.z - goal->origin.z); return static_cast (deltaX + deltaY + deltaZ); +#else + float xDist = fabsf (start->origin.x - goal->origin.x); + float yDist = fabsf (start->origin.y - goal->origin.y); + float zDist = fabsf (start->origin.z - goal->origin.z); + + if (xDist > yDist) + return 1.4 * yDist + (xDist - yDist) + zDist; + + return 1.4 * xDist + (yDist - xDist) + zDist; +#endif } float hfunctionSquareDistWithHostage (int index, int startIndex, int goalIndex) @@ -1834,6 +1845,7 @@ bool Bot::FindWaypoint (void) reachDistances[j] = distance; } } + DebugMsg ("got some waypoints..."); } // now pick random one from choosen @@ -1856,10 +1868,31 @@ bool Bot::FindWaypoint (void) i = 0; Array found; - g_waypoint->FindInRadius (found, 1024.0f, pev->origin); + g_waypoint->FindInRadius (found, 256.0f, pev->origin); + + DebugMsg ("doing worst case"); if (!found.IsEmpty ()) - waypointIndeces[i] = found.GetRandomElement (); + { + bool gotId = false; + int random = found.GetRandomElement ();; + + while (!found.IsEmpty ()) + { + int index = found.Pop (); + + if (!g_waypoint->Reachable (this, index)) + continue; + + waypointIndeces[i] = index; + gotId = true; + + break; + } + + if (!gotId) + waypointIndeces[i] = random; + } else waypointIndeces[i] = g_randGen.Long (0, g_numWaypoints - 1); } @@ -3275,7 +3308,7 @@ bool Bot::IsPointOccupied (int index) continue; // check if this waypoint is already used - if (IsAlive (bot->GetEntity ()) && (bot->m_currentWaypointIndex == index || bot->GetTask ()->data == index || (g_waypoint->GetPath (index)->origin - bot->pev->origin).GetLength2D () < 180.0)) + if (IsAlive (bot->GetEntity ()) && (bot->m_currentWaypointIndex == index || bot->GetTask ()->data == index || (g_waypoint->GetPath (index)->origin - bot->pev->origin).GetLength2D () < 120.0f)) return true; } return false; diff --git a/source/waypoint.cpp b/source/waypoint.cpp index 2183662..bfdad74 100644 --- a/source/waypoint.cpp +++ b/source/waypoint.cpp @@ -1254,25 +1254,26 @@ bool Waypoint::Reachable (Bot *bot, int index) float distance = (dest - src).GetLength (); // check is destination is close to us enoguh - if (distance >= 201) // Default: 201 + if (distance >= 150.0f) return false; - if (bot->pev->waterlevel == 2 || bot->pev->waterlevel == 3) - { - float distance2D = (dest - src).GetLength2D (); - - // is destination waypoint higher that source (45 is max jump height), or destination waypoint higher that source - if ((dest.z > src.z + 40.0 || dest.z < src.z - 75.0) && (!(m_paths[index]->flags & FLAG_LADDER) || distance2D >= 16.0)) - return false; // unable to reach this one - } - TraceResult tr; TraceLine (src, dest, true, bot->GetEntity (), &tr); // if waypoint is visible from current position (even behind head)... if (tr.flFraction >= 1.0) - return true; + { + if (bot->pev->waterlevel == 2 || bot->pev->waterlevel == 3) + return true; + float distance2D = (dest - src).GetLength2D (); + + // is destination waypoint higher that source (62 is max jump height), or destination waypoint higher that source + if (((dest.z > src.z + 62.0 || dest.z < src.z - 100.0f) && (!(m_paths[index]->flags & FLAG_LADDER))) || distance2D >= 120.0f) + return false; // unable to reach this one + + return true; + } return false; }