bot: some tweaks for zombie mode (ref #664)

This commit is contained in:
jeefo 2025-02-17 15:03:38 +03:00
commit d965d7677f
No known key found for this signature in database
GPG key ID: D696786B81B667C8
6 changed files with 45 additions and 5 deletions

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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