From 1736bd9c8ac7b2af165134b6920cdba80210e7b1 Mon Sep 17 00:00:00 2001 From: jeefo Date: Sat, 9 Mar 2024 22:41:48 +0300 Subject: [PATCH] aim: remeber last edict for whom head spot was set ... so the bots will not shake their crosshair between chest and head when fighting acquired/current enemy --- inc/yapb.h | 1 + src/combat.cpp | 10 +++++++++- src/manager.cpp | 1 + 3 files changed, 11 insertions(+), 1 deletion(-) diff --git a/inc/yapb.h b/inc/yapb.h index f991889..01ce7e7 100644 --- a/inc/yapb.h +++ b/inc/yapb.h @@ -659,6 +659,7 @@ public: edict_t *m_doubleJumpEntity {}; // pointer to entity that request double jump edict_t *m_radioEntity {}; // pointer to entity issuing a radio command edict_t *m_enemy {}; // pointer to enemy entity + edict_t *m_enemyBodyPartSet {}; // pointer to last enemy body part was set to head edict_t *m_lastEnemy {}; // pointer to last enemy entity edict_t *m_lastVictim {}; // pointer to killed entity edict_t *m_trackingEdict {}; // pointer to last tracked player when camping/hiding diff --git a/src/combat.cpp b/src/combat.cpp index 3e999be..d3bd3a1 100644 --- a/src/combat.cpp +++ b/src/combat.cpp @@ -240,7 +240,9 @@ void Bot::trackEnemies () { } else { m_states &= ~Sense::SeeingEnemy; + m_enemy = nullptr; + m_enemyBodyPartSet = nullptr; } } @@ -392,6 +394,7 @@ bool Bot::lookupEnemies () { m_actualReactionTime = 0.0f; m_enemy = newEnemy; m_lastEnemy = newEnemy; + m_enemyBodyPartSet = nullptr; m_lastEnemyOrigin = newEnemy->v.origin; m_enemyReachableTimer = 0.0f; @@ -429,6 +432,7 @@ bool Bot::lookupEnemies () { if (!util.isAlive (newEnemy)) { m_enemy = nullptr; + m_enemyBodyPartSet = nullptr; // shoot at dying players if no new enemy to give some more human-like illusion if (m_seeEnemyTime + 0.1f > game.time ()) { @@ -557,8 +561,12 @@ Vector Bot::getEnemyBodyOffset () { const auto headshotPct = conf.getDifficultyTweaks (m_difficulty)->headshotPct; // now check is our skill match to aim at head, else aim at enemy body - if (rg.chance (headshotPct)) { + if (m_enemyBodyPartSet == m_enemy || rg.chance (headshotPct)) { spot = m_enemyOrigin + getCustomHeight (distance); + + // set's the enemy shooting spot to head, if headshot pct allows, and use head for that + // enemy until new enemy is acquired, to prevent too shaky aiming + m_enemyBodyPartSet = m_enemy; } else { spot = m_enemy->v.origin; diff --git a/src/manager.cpp b/src/manager.cpp index 5d7c8c6..852c35e 100644 --- a/src/manager.cpp +++ b/src/manager.cpp @@ -1476,6 +1476,7 @@ void Bot::newRound () { m_lastEnemyOrigin = nullptr; m_lastVictimOrigin = nullptr; m_trackingEdict = nullptr; + m_enemyBodyPartSet = nullptr; m_timeNextTracking = 0.0f; m_buttonPushTime = 0.0f;