From a06418b3b347f3b15f06fd3d4bbe7a40aca8fdca Mon Sep 17 00:00:00 2001 From: commandcobra7 <91374215+commandcobra7@users.noreply.github.com> Date: Thu, 27 Jul 2023 01:19:19 +0300 Subject: [PATCH] aim: now looks at next node while navigating (#472) --- inc/yapb.h | 4 ++++ src/botlib.cpp | 2 +- src/tasks.cpp | 2 +- src/vision.cpp | 8 ++++++-- 4 files changed, 12 insertions(+), 4 deletions(-) diff --git a/inc/yapb.h b/inc/yapb.h index 5764d82..887f0cb 100644 --- a/inc/yapb.h +++ b/inc/yapb.h @@ -154,6 +154,10 @@ public: ~PathWalk () = default; public: + int32_t &doubleNext () { + return at (2); + } + int32_t &next () { return at (1); } diff --git a/src/botlib.cpp b/src/botlib.cpp index 54606b6..17ac677 100644 --- a/src/botlib.cpp +++ b/src/botlib.cpp @@ -3841,7 +3841,7 @@ bool Bot::isBombDefusing (const Vector &bombOrigin) { } float Bot::getShiftSpeed () { - if (getCurrentTaskId () == Task::SeekCover || isDucking () || (pev->button & IN_DUCK) || (m_oldButtons & IN_DUCK) || (m_currentTravelFlags & PathFlag::Jump) || (m_pathFlags & NodeFlag::Ladder) || isOnLadder () || isInWater () || m_isStuck) { + if (getCurrentTaskId () == Task::SeekCover || (m_aimFlags & AimFlags::Enemy) || isDucking () || (pev->button & IN_DUCK) || (m_oldButtons & IN_DUCK) || (m_currentTravelFlags & PathFlag::Jump) || (m_pathFlags & NodeFlag::Ladder) || isOnLadder () || isInWater () || m_isStuck) { return pev->maxspeed; } return pev->maxspeed * 0.4f; diff --git a/src/tasks.cpp b/src/tasks.cpp index 1073ff4..46c14ae 100644 --- a/src/tasks.cpp +++ b/src/tasks.cpp @@ -221,7 +221,7 @@ void Bot::normal_ () { } const float shiftSpeed = getShiftSpeed (); - if (!m_isStuck && (!cr::fzero (m_moveSpeed) && m_moveSpeed > shiftSpeed) && (cv_walking_allowed.bool_ () && mp_footsteps.bool_ ()) && m_difficulty >= Difficulty::Normal && !(m_aimFlags & AimFlags::Enemy) && (m_heardSoundTime + 6.0f >= game.time () || (m_states & Sense::SuspectEnemy)) && numEnemiesNear (pev->origin, 768.0f) >= 1 && !isKnifeMode () && !bots.isBombPlanted ()) { + if ((!cr::fzero (m_moveSpeed) && m_moveSpeed > shiftSpeed) && (cv_walking_allowed.bool_ () && mp_footsteps.bool_ ()) && m_difficulty >= Difficulty::Normal && (m_heardSoundTime + 6.0f >= game.time () || (m_states & Sense::HearingEnemy)) && pev->origin.distanceSq (m_lastEnemyOrigin) < cr::sqrf (768.0f) && !isKnifeMode () && !bots.isBombPlanted ()) { m_moveSpeed = shiftSpeed; } diff --git a/src/vision.cpp b/src/vision.cpp index 348cbce..2f26737 100644 --- a/src/vision.cpp +++ b/src/vision.cpp @@ -146,7 +146,7 @@ void Bot::updateAimDir () { predictNode = kInvalidNodeIndex; pathLength = kInfiniteDistanceLong; } - return predictNode != kInvalidNodeIndex && pathLength < cv_max_nodes_for_predict.int_ (); + return graph.exists (predictNode) && pathLength < cv_max_nodes_for_predict.int_ (); }; if (changePredictedEnemy) { @@ -183,8 +183,12 @@ void Bot::updateAimDir () { if (m_moveToGoal && m_seeEnemyTime + 4.0f < game.time () && !m_isStuck && m_moveSpeed > getShiftSpeed () && !(pev->button & IN_DUCK) && m_currentNodeIndex != kInvalidNodeIndex && !(m_pathFlags & (NodeFlag::Ladder | NodeFlag::Crouch)) && m_pathWalk.hasNext () && pev->origin.distanceSq (m_destOrigin) < cr::sqrf (512.0f)) { const auto nextPathIndex = m_pathWalk.next (); + const auto doubleNextPath = m_pathWalk.doubleNext (); - if (vistab.visible (m_currentNodeIndex, nextPathIndex)) { + if (vistab.visible (m_currentNodeIndex, doubleNextPath)) { + m_lookAt = graph[doubleNextPath].origin + pev->view_ofs; + } + else if (vistab.visible (m_currentNodeIndex, nextPathIndex)) { m_lookAt = graph[nextPathIndex].origin + pev->view_ofs; } else {