From 78a5dd50a18741559a186aa592af5a3b3c8d1a7f Mon Sep 17 00:00:00 2001 From: jeefo Date: Sat, 10 Feb 2024 21:20:25 +0300 Subject: [PATCH] revert: some changes that are broke behavior nav: fix: can strafe left is doing wrong things --- src/combat.cpp | 4 ++-- src/navigate.cpp | 49 +++++++++++++++++++++++++++++++++++++++++++----- 2 files changed, 46 insertions(+), 7 deletions(-) diff --git a/src/combat.cpp b/src/combat.cpp index 531861d..d177fd8 100644 --- a/src/combat.cpp +++ b/src/combat.cpp @@ -1355,8 +1355,8 @@ void Bot::attackMovement () { if (m_difficulty >= Difficulty::Normal && isOnFloor () && m_duckTime < game.time ()) { if (distance < 768.0f) { - if (pev->velocity.length2d () > 150.0f && isInViewCone (m_enemy->v.origin)) { - m_jumpTime = game.time () + m_frameInterval * 2.0f; + if (rg.get (0, 1000) < rg.get (5, 10) && pev->velocity.length2d () > 150.0f && isInViewCone (m_enemy->v.origin)) { + pev->button |= IN_JUMP; } } else { diff --git a/src/navigate.cpp b/src/navigate.cpp index 9c78ad5..5b9a6c1 100644 --- a/src/navigate.cpp +++ b/src/navigate.cpp @@ -599,26 +599,65 @@ void Bot::checkTerrain (float movedDistance, const Vector &dirNormal) { state[i] = 0; state[i + 1] = 0; - if (canStrafeLeft (&tr)) { + // to start strafing, we have to first figure out if the target is on the left side or right side + Vector right {}, forward {}; + m_moveAngles.angleVectors (&forward, &right, nullptr); + + const Vector &dirToPoint = (pev->origin - m_destOrigin).normalize2d_apx (); + const Vector &rightSide = right.normalize2d_apx (); + + bool dirRight = false; + bool dirLeft = false; + bool blockedLeft = false; + bool blockedRight = false; + + if ((dirToPoint | rightSide) > 0.0f) { + dirRight = true; + } + else { + dirLeft = true; + } + const auto &testDir = m_moveSpeed > 0.0f ? forward : -forward; + constexpr float kBlockDistance = 42.0f; + + // now check which side is blocked + src = pev->origin + right * kBlockDistance; + dst = src + testDir * kBlockDistance; + + game.testHull (src, dst, TraceIgnore::Monsters, head_hull, ent (), &tr); + + if (!cr::fequal (tr.flFraction, 1.0f)) { + blockedRight = true; + } + src = pev->origin - right * kBlockDistance; + dst = src + testDir * kBlockDistance; + + game.testHull (src, dst, TraceIgnore::Monsters, head_hull, ent (), &tr); + + if (!cr::fequal (tr.flFraction, 1.0f)) { + blockedLeft = true; + } + + if (dirLeft) { state[i] += 5; } else { state[i] -= 5; } - if (isBlockedLeft ()) { + if (blockedLeft) { state[i] -= 5; } ++i; - if (canStrafeRight (&tr)) { + if (dirRight) { state[i] += 5; } else { state[i] -= 5; } - if (isBlockedRight ()) { + if (blockedRight) { state[i] -= 5; } } @@ -2429,7 +2468,7 @@ bool Bot::canStrafeLeft (TraceResult *tr) { pev->v_angle.angleVectors (&forward, &right, nullptr); Vector src = pev->origin; - Vector dest = src - right * -40.0f; + Vector dest = src - right * 40.0f; // trace from the bot's waist straight left... game.testLine (src, dest, TraceIgnore::Monsters, ent (), tr);