From ed46e3238d64e68e115aa871c2eebc6d6e7744ba Mon Sep 17 00:00:00 2001 From: Hedgehog Fog Date: Wed, 9 Dec 2020 19:00:43 +0200 Subject: [PATCH] =?UTF-8?q?Improved=20monsters=20targeting=F0=9F=91=BE=20(?= =?UTF-8?q?#203)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Improved monsters targeting Fixed aim offset for monsters --- inc/yapb.h | 1 + src/combat.cpp | 28 +++++++++++++++++++++------- 2 files changed, 22 insertions(+), 7 deletions(-) diff --git a/inc/yapb.h b/inc/yapb.h index e3c8855..62340b0 100644 --- a/inc/yapb.h +++ b/inc/yapb.h @@ -765,6 +765,7 @@ private: float isInFOV (const Vector &dest); float getShiftSpeed (); float getEnemyBodyOffsetCorrection (float distance); + float calculateScaleFactor (edict_t *ent); bool canReplaceWeapon (); bool canDuckUnder (const Vector &normal); diff --git a/src/combat.cpp b/src/combat.cpp index 69d09fa..b9037dd 100644 --- a/src/combat.cpp +++ b/src/combat.cpp @@ -133,12 +133,14 @@ bool Bot::checkBodyParts (edict_t *target) { } // check top of head - spot.z += 25.0f; - game.testLine (eyes, spot, TraceIgnore::Everything, self, &result); + if (util.isPlayer (target)) { + spot.z += 25.0f; + game.testLine (eyes, spot, TraceIgnore::Everything, self, &result); - if (result.flFraction >= 1.0f) { - m_enemyParts |= Visibility::Head; - m_enemyOrigin = result.vecEndPos; + if (result.flFraction >= 1.0f) { + m_enemyParts |= Visibility::Head; + m_enemyOrigin = result.vecEndPos; + } } if (m_enemyParts != 0) { @@ -270,7 +272,9 @@ bool Bot::lookupEnemies () { // see if bot can see the monster... if (seesEnemy (intresting)) { - float distance = (intresting->v.origin - pev->origin).lengthSq (); + // higher priority for big monsters + float scaleFactor = (1.0f / calculateScaleFactor (intresting)); + float distance = (intresting->v.origin - pev->origin).lengthSq () * scaleFactor; if (distance * 0.7f < nearestDistance) { nearestDistance = distance; @@ -499,7 +503,7 @@ const Vector &Bot::getEnemyBodyOffset () { if (!m_enemyParts && (m_states & Sense::SuspectEnemy)) { aimPos += getBodyOffsetError (distance); } - else { + else if (util.isPlayer (m_enemy)) { const float highOffset = m_difficulty > Difficulty::Normal ? 3.5f : 0.0f; // now take in account different parts of enemy body @@ -1650,3 +1654,13 @@ void Bot::checkReload () { } } } + +float Bot::calculateScaleFactor (edict_t *ent) { + Vector entSize = ent->v.maxs - ent->v.mins; + float entArea = 2 * (entSize.x * entSize.y + entSize.y * entSize.z + entSize.x * entSize.z); + + Vector botSize = pev->maxs - pev->mins; + float botArea = 2 * (botSize.x * botSize.y + botSize.y * botSize.z + botSize.x * botSize.z); + + return entArea / botArea; +}