From d965d7677f7ee367176c91c9036d0ba279f64561 Mon Sep 17 00:00:00 2001 From: jeefo Date: Mon, 17 Feb 2025 15:03:38 +0300 Subject: [PATCH] bot: some tweaks for zombie mode (ref #664) --- inc/yapb.h | 1 + src/botlib.cpp | 34 ++++++++++++++++++++++++++++++++-- src/combat.cpp | 4 +++- src/manager.cpp | 1 + src/navigate.cpp | 8 +++++++- src/tasks.cpp | 2 +- 6 files changed, 45 insertions(+), 5 deletions(-) diff --git a/inc/yapb.h b/inc/yapb.h index 3af0f22..bbdf087 100644 --- a/inc/yapb.h +++ b/inc/yapb.h @@ -288,6 +288,7 @@ private: float m_timeDebugUpdateTime {}; // time to update last debug timestamp float m_lastVictimTime {}; // time when bot killed an enemy float m_killsInterval {}; // interval between kills + float m_lastDamageTimestamp {}; // last damage from take damage fn bool m_moveToGoal {}; // bot currently moving to goal?? bool m_isStuck {}; // bot is stuck diff --git a/src/botlib.cpp b/src/botlib.cpp index 87d94d8..e3c03ad 100644 --- a/src/botlib.cpp +++ b/src/botlib.cpp @@ -1722,7 +1722,11 @@ void Bot::overrideConditions () { } } else { - if (distanceSq2d <= kReachEnemyWikKnifeDistanceSq && (m_states & Sense::SeeingEnemy) && tid == Task::MoveToPosition) { + if (!m_isCreature + && distanceSq2d <= kReachEnemyWikKnifeDistanceSq + && (m_states & Sense::SeeingEnemy) + && tid == Task::MoveToPosition) { + clearTask (Task::MoveToPosition); // remove any move tasks } } @@ -1828,6 +1832,10 @@ void Bot::updatePredictedIndex () { } void Bot::refreshEnemyPredict () { + if (m_isCreature) { + return; + } + if (game.isNullEntity (m_enemy) && !game.isNullEntity (m_lastEnemy) && !m_lastEnemyOrigin.empty ()) { const auto distanceToLastEnemySq = m_lastEnemyOrigin.distanceSq (pev->origin); @@ -2130,7 +2138,7 @@ void Bot::filterTasks () { } // zombie bots has more hunt desire - if (m_isCreature && huntEnemyDesire > 25.0f) { + if (m_isCreature && huntEnemyDesire > 16.0f) { huntEnemyDesire = TaskPri::Attack; } @@ -2352,6 +2360,17 @@ bool Bot::reactOnEnemy () { return false; } + // special case for creatures + if (m_isCreature && !game.isNullEntity (m_enemy)) { + m_isEnemyReachable = false; + + if (pev->origin.distanceSq (m_enemy->v.origin) < cr::sqrf (128.0f)) { + m_navTimeset = game.time (); + m_isEnemyReachable = true; + } + return m_isEnemyReachable; + } + if (m_enemyReachableTimer < game.time ()) { const auto lineDist = m_enemy->v.origin.distance (pev->origin); @@ -3588,9 +3607,20 @@ void Bot::takeDamage (edict_t *inflictor, int damage, int armor, int bits) { m_lastDamageType = bits; + if (m_isCreature) { + if (util.isPlayer (inflictor) && game.isNullEntity (m_enemy)) { + if (seesEnemy (inflictor)) { + m_enemy = inflictor; + m_enemyOrigin = inflictor->v.origin; + } + } + return; + } + if (!game.is (GameFlags::CSDM)) { updatePracticeValue (damage); } + m_lastDamageTimestamp = game.time (); if (util.isPlayer (inflictor) || (cv_attack_monsters && util.isMonster (inflictor))) { const auto inflictorTeam = game.getTeam (inflictor); diff --git a/src/combat.cpp b/src/combat.cpp index 3f75158..91aef65 100644 --- a/src/combat.cpp +++ b/src/combat.cpp @@ -1243,7 +1243,9 @@ void Bot::fireWeapons () { } // use knife if near and good difficulty (l33t dude!) - if (cv_stab_close_enemies && m_difficulty >= Difficulty::Normal + if (!game.is (GameFlags::ZombieMod) + && cv_stab_close_enemies + && m_difficulty >= Difficulty::Normal && m_healthValue > 80.0f && !game.isNullEntity (m_enemy) && distance < 100.0f diff --git a/src/manager.cpp b/src/manager.cpp index d91b707..ec8a7a5 100644 --- a/src/manager.cpp +++ b/src/manager.cpp @@ -1456,6 +1456,7 @@ void Bot::newRound () { m_duckDefuse = false; m_duckDefuseCheckTime = 0.0f; m_timeDebugUpdateTime = 0.0f; + m_lastDamageTimestamp = 0.0f; m_numFriendsLeft = 0; m_numEnemiesLeft = 0; diff --git a/src/navigate.cpp b/src/navigate.cpp index 0b6d806..170af60 100644 --- a/src/navigate.cpp +++ b/src/navigate.cpp @@ -581,8 +581,14 @@ void Bot::checkTerrain (float movedDistance, const Vector &dirNormal) { && m_lastCollTime < game.time () && tid != Task::Attack && tid != Task::Camp) { + + // special case for creatures + if (m_lastDamageTimestamp >= game.time () && m_isCreature) { + m_lastCollTime = m_lastDamageTimestamp + 0.2f; + m_firstCollideTime = 0.0f; + } // didn't we move enough previously? - if (movedDistance < kMinMovedDistance && m_prevSpeed > 20.0f) { + else if (movedDistance < kMinMovedDistance && m_prevSpeed > 20.0f) { m_prevTime = game.time (); // then consider being stuck m_isStuck = true; diff --git a/src/tasks.cpp b/src/tasks.cpp index 2b5fa86..a54412d 100644 --- a/src/tasks.cpp +++ b/src/tasks.cpp @@ -828,7 +828,7 @@ void Bot::moveToPos_ () { getTask ()->data = destIndex; ensureCurrentNodeIndex (); - findPath (m_currentNodeIndex, destIndex, m_pathType); + findPath (m_currentNodeIndex, destIndex, m_isCreature ? FindPath::Fast : m_pathType); } else { completeTask ();