From e22b0ffeea69ce80dac0a48982300e5ad9853d41 Mon Sep 17 00:00:00 2001 From: jeefo Date: Sat, 23 Aug 2025 18:17:32 +0300 Subject: [PATCH] fix: commands execution order --- inc/yapb.h | 1 + src/botlib.cpp | 90 ++++++++++++++++++++++++++----------------------- src/combat.cpp | 4 +-- src/manager.cpp | 2 +- 4 files changed, 52 insertions(+), 45 deletions(-) diff --git a/inc/yapb.h b/inc/yapb.h index 7c5cf45..a56826d 100644 --- a/inc/yapb.h +++ b/inc/yapb.h @@ -533,6 +533,7 @@ private: void donateC4ToHuman (); void clearAmmoInfo (); void handleChatterTaskChange (Task tid); + void executeChatterFrameEvents (); void completeTask (); void executeTasks (); diff --git a/src/botlib.cpp b/src/botlib.cpp index 29e5192..dbebde1 100644 --- a/src/botlib.cpp +++ b/src/botlib.cpp @@ -2455,6 +2455,49 @@ void Bot::handleChatterTaskChange (Task tid) { } } +void Bot::executeChatterFrameEvents () { + if (cv_radio_mode.as () != 2) { + return; + } + + // some stuff required by by chatter engine + if ((m_states & Sense::SeeingEnemy) && !game.isNullEntity (m_enemy)) { + int hasFriendNearby = numFriendsNear (pev->origin, 512.0f); + + if (!hasFriendNearby && rg.chance (45) && (m_enemy->v.weapons & cr::bit (Weapon::C4))) { + pushChatterMessage (Chatter::SpotTheBomber); + } + else if (!hasFriendNearby && rg.chance (45) && m_team == Team::Terrorist && util.isPlayerVIP (m_enemy)) { + pushChatterMessage (Chatter::VIPSpotted); + } + else if (!hasFriendNearby + && rg.chance (50) + && game.getTeam (m_enemy) != m_team + && isGroupOfEnemies (m_enemy->v.origin)) { + + pushChatterMessage (Chatter::ScaredEmotion); + } + else if (!hasFriendNearby + && rg.chance (40) + && (m_enemy->v.weapons & kSniperWeaponMask)) { + + pushChatterMessage (Chatter::SniperWarning); + } + + // if bot is trapped under shield yell for help ! + if (getCurrentTaskId () == Task::Camp && hasShield () && isShieldDrawn () && hasFriendNearby >= 2) { + pushChatterMessage (Chatter::PinnedDown); + } + } + + // if bomb planted warn players ! + if (bots.hasBombSay (BombPlantedSay::Chatter) && bots.isBombPlanted () && m_team == Team::CT) { + pushChatterMessage (Chatter::GottaFindC4); + bots.clearBombSay (BombPlantedSay::Chatter); + } + +} + void Bot::checkRadioQueue () { // this function handling radio and reacting to it @@ -3010,14 +3053,12 @@ void Bot::frame () { if (m_thinkTimer.time < game.time ()) { m_thinkTimer.time = game.time () + m_thinkTimer.interval; - upkeep (); - if (m_fullThinkTimer.time < game.time ()) { m_fullThinkTimer.time = game.time () + m_fullThinkTimer.interval; update (); } - runMovement (); + upkeep (); } if (m_slowFrameTimestamp > game.time ()) { @@ -3335,44 +3376,7 @@ void Bot::logic () { else if (!game.isNullEntity (m_enemy)) { trackEnemies (); } - - // some stuff required by by chatter engine - if (cv_radio_mode.as () == 2) { - if ((m_states & Sense::SeeingEnemy) && !game.isNullEntity (m_enemy)) { - int hasFriendNearby = numFriendsNear (pev->origin, 512.0f); - - if (!hasFriendNearby && rg.chance (45) && (m_enemy->v.weapons & cr::bit (Weapon::C4))) { - pushChatterMessage (Chatter::SpotTheBomber); - } - else if (!hasFriendNearby && rg.chance (45) && m_team == Team::Terrorist && util.isPlayerVIP (m_enemy)) { - pushChatterMessage (Chatter::VIPSpotted); - } - else if (!hasFriendNearby - && rg.chance (50) - && game.getTeam (m_enemy) != m_team - && isGroupOfEnemies (m_enemy->v.origin)) { - - pushChatterMessage (Chatter::ScaredEmotion); - } - else if (!hasFriendNearby - && rg.chance (40) - && (m_enemy->v.weapons & kSniperWeaponMask)) { - - pushChatterMessage (Chatter::SniperWarning); - } - - // if bot is trapped under shield yell for help ! - if (getCurrentTaskId () == Task::Camp && hasShield () && isShieldDrawn () && hasFriendNearby >= 2) { - pushChatterMessage (Chatter::PinnedDown); - } - } - - // if bomb planted warn players ! - if (bots.hasBombSay (BombPlantedSay::Chatter) && bots.isBombPlanted () && m_team == Team::CT) { - pushChatterMessage (Chatter::GottaFindC4); - bots.clearBombSay (BombPlantedSay::Chatter); - } - } + executeChatterFrameEvents (); m_checkTerrain = true; m_moveToGoal = true; @@ -3469,8 +3473,10 @@ void Bot::logic () { void Bot::upkeep () { setAimDirection (); - updateLookAngles (); doFireWeapons (); + + updateLookAngles (); + runMovement (); } void Bot::spawned () { diff --git a/src/combat.cpp b/src/combat.cpp index e57bb25..2983f6f 100644 --- a/src/combat.cpp +++ b/src/combat.cpp @@ -1564,8 +1564,8 @@ void Bot::attackMovement () { m_strafeSetTime = strafeUpdateTime (); } - const bool wallOnRight = checkWallOnRight (96.0f); - const bool wallOnLeft = checkWallOnLeft (96.0f); + const bool wallOnRight = checkWallOnRight (134.0f); + const bool wallOnLeft = checkWallOnLeft (134.0f); if (m_dodgeStrafeDir == Dodge::Left) { if (!wallOnLeft) { diff --git a/src/manager.cpp b/src/manager.cpp index 8c36718..6de0625 100644 --- a/src/manager.cpp +++ b/src/manager.cpp @@ -1739,7 +1739,7 @@ void Bot::newRound () { thinkInterval = 1.0f / 50.0f; // xash3d works acceptable at 50fps } } - auto fullThinkInterval = 1.0f / 10.0f; + auto fullThinkInterval = 1.0f / (thinkFps * 0.5f); // legacy games behaves strange, when this enabled, disable for xash3d as well if requested if (bots.isFrameSkipDisabled ()) {