revert: some changes that are broke behavior

nav: fix: can strafe left is doing wrong things
This commit is contained in:
jeefo 2024-02-10 21:20:25 +03:00
commit 78a5dd50a1
No known key found for this signature in database
GPG key ID: 927BCA0779BEA8ED
2 changed files with 46 additions and 7 deletions

View file

@ -1355,8 +1355,8 @@ void Bot::attackMovement () {
if (m_difficulty >= Difficulty::Normal && isOnFloor () && m_duckTime < game.time ()) { if (m_difficulty >= Difficulty::Normal && isOnFloor () && m_duckTime < game.time ()) {
if (distance < 768.0f) { if (distance < 768.0f) {
if (pev->velocity.length2d () > 150.0f && isInViewCone (m_enemy->v.origin)) { if (rg.get (0, 1000) < rg.get (5, 10) && pev->velocity.length2d () > 150.0f && isInViewCone (m_enemy->v.origin)) {
m_jumpTime = game.time () + m_frameInterval * 2.0f; pev->button |= IN_JUMP;
} }
} }
else { else {

View file

@ -599,26 +599,65 @@ void Bot::checkTerrain (float movedDistance, const Vector &dirNormal) {
state[i] = 0; state[i] = 0;
state[i + 1] = 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; state[i] += 5;
} }
else { else {
state[i] -= 5; state[i] -= 5;
} }
if (isBlockedLeft ()) { if (blockedLeft) {
state[i] -= 5; state[i] -= 5;
} }
++i; ++i;
if (canStrafeRight (&tr)) { if (dirRight) {
state[i] += 5; state[i] += 5;
} }
else { else {
state[i] -= 5; state[i] -= 5;
} }
if (isBlockedRight ()) { if (blockedRight) {
state[i] -= 5; state[i] -= 5;
} }
} }
@ -2429,7 +2468,7 @@ bool Bot::canStrafeLeft (TraceResult *tr) {
pev->v_angle.angleVectors (&forward, &right, nullptr); pev->v_angle.angleVectors (&forward, &right, nullptr);
Vector src = pev->origin; Vector src = pev->origin;
Vector dest = src - right * -40.0f; Vector dest = src - right * 40.0f;
// trace from the bot's waist straight left... // trace from the bot's waist straight left...
game.testLine (src, dest, TraceIgnore::Monsters, ent (), tr); game.testLine (src, dest, TraceIgnore::Monsters, ent (), tr);