fix: crash bug introduced in latest commit (resolves #630)

fix: unnecessary assignments here and there
This commit is contained in:
jeefo 2024-10-20 17:31:45 +03:00
commit 3d84b96534
No known key found for this signature in database
GPG key ID: D696786B81B667C8
3 changed files with 7 additions and 12 deletions

View file

@ -135,7 +135,7 @@ bool Bot::isEnemyInDarkArea (edict_t *enemy) {
const auto scolor = illum.getSkyColor ();
// check if node near the enemy have a degraded light level
const auto enemyNodeIndex = graph.getNearest (m_enemy->v.origin);
const auto enemyNodeIndex = graph.getNearest (enemy->v.origin);
if (!graph.exists (enemyNodeIndex)) {
return false;
@ -273,12 +273,12 @@ bool Bot::checkBodyPartsWithHitboxes (edict_t *target) {
const auto hitsTarget = [&] () -> bool {
return result.flFraction >= 1.0f || result.pHit == target;
};
m_enemyParts = Visibility::None;
// creatures can't hurt behind anything
const auto ignoreFlags = m_isCreature ? TraceIgnore::None : TraceIgnore::Everything;
// get the stomach hitbox
m_enemyParts = Visibility::None;
game.testLine (eyes, m_hitboxEnumerator->get (target, PlayerPart::Stomach, refresh), ignoreFlags, self, &result);
if (hitsTarget ()) {
@ -287,7 +287,6 @@ bool Bot::checkBodyPartsWithHitboxes (edict_t *target) {
}
// get the stomach hitbox
m_enemyParts = Visibility::None;
game.testLine (eyes, m_hitboxEnumerator->get (target, PlayerPart::Head, refresh), ignoreFlags, self, &result);
if (hitsTarget ()) {
@ -300,7 +299,6 @@ bool Bot::checkBodyPartsWithHitboxes (edict_t *target) {
}
// get the left hitbox
m_enemyParts = Visibility::None;
game.testLine (eyes, m_hitboxEnumerator->get (target, PlayerPart::LeftArm, refresh), ignoreFlags, self, &result);
if (hitsTarget ()) {
@ -311,7 +309,6 @@ bool Bot::checkBodyPartsWithHitboxes (edict_t *target) {
}
// get the right hitbox
m_enemyParts = Visibility::None;
game.testLine (eyes, m_hitboxEnumerator->get (target, PlayerPart::RightArm, refresh), ignoreFlags, self, &result);
if (hitsTarget ()) {
@ -322,7 +319,6 @@ bool Bot::checkBodyPartsWithHitboxes (edict_t *target) {
}
// get the feet spot
m_enemyParts = Visibility::None;
game.testLine (eyes, m_hitboxEnumerator->get (target, PlayerPart::Feet, refresh), ignoreFlags, self, &result);
if (hitsTarget ()) {

View file

@ -1496,27 +1496,25 @@ void PlayerHitboxEnumerator::update (edict_t *ent) {
parts->head.z += bboxset[hitbox].bbmax.z;
parts->head = { ent->v.origin.x, ent->v.origin.y, parts->head.z };
}
hitbox = kInvalidHitbox;
// get the body (stomach)
hitbox = getHitbox (studiohdr, bboxset, PlayerPart::Stomach);
if (hitbox != kInfiniteDistance) {
if (hitbox != kInvalidHitbox) {
engfuncs.pfnGetBonePosition (ent, bboxset[hitbox].bone, parts->stomach, nullptr);
}
hitbox = kInvalidHitbox;
// get the left (arm)
hitbox = getHitbox (studiohdr, bboxset, PlayerPart::LeftArm);
if (hitbox != kInfiniteDistance) {
if (hitbox != kInvalidHitbox) {
engfuncs.pfnGetBonePosition (ent, bboxset[hitbox].bone, parts->left, nullptr);
}
// get the right (arm)
hitbox = getHitbox (studiohdr, bboxset, PlayerPart::RightArm);
if (hitbox != kInfiniteDistance) {
if (hitbox != kInvalidHitbox) {
engfuncs.pfnGetBonePosition (ent, bboxset[hitbox].bone, parts->right, nullptr);
}
return;

View file

@ -286,7 +286,6 @@ void Bot::updateLookAnglesNewbie (const Vector &direction, float delta) {
const float offsetDelay = 1.2f;
Vector stiffness {};
Vector randomize {};
m_idealAngles = direction.get2d ();
m_idealAngles.clampAngles ();
@ -303,6 +302,8 @@ void Bot::updateLookAnglesNewbie (const Vector &direction, float delta) {
&& ((pev->velocity.length () > 1.0f
&& m_angularDeviation.length () < 5.0f) || m_angularDeviation.length () < 1.0f)) {
Vector randomize {};
// is the bot standing still ?
if (pev->velocity.length () < 1.0f) {
randomize = randomization * 0.2f; // randomize less