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
This commit is contained in:
jeefo 2024-03-09 22:41:48 +03:00
commit 1736bd9c8a
No known key found for this signature in database
GPG key ID: 927BCA0779BEA8ED
3 changed files with 11 additions and 1 deletions

View file

@ -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

View file

@ -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;

View file

@ -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;