diff --git a/inc/yapb.h b/inc/yapb.h index 8079d3c..d08d0b2 100644 --- a/inc/yapb.h +++ b/inc/yapb.h @@ -519,6 +519,7 @@ private: void findValidNode (); void setPathOrigin (); void fireWeapons (); + void doFireWeapons (); void selectWeapons (float distance, int index, int id, int choosen); void focusEnemy (); void selectBestWeapon (); @@ -727,8 +728,8 @@ public: Deque m_msgQueue {}; Array m_goalHist {}; - FrameDelay m_thinkDelay {}; - FrameDelay m_commandDelay {}; + FrameDelay m_thinkTimer {}; + FrameDelay m_fullThinkTimer {}; public: Bot (edict_t *bot, int difficulty, int personality, int team, int skin); diff --git a/src/botlib.cpp b/src/botlib.cpp index efbe56a..17527c3 100644 --- a/src/botlib.cpp +++ b/src/botlib.cpp @@ -3007,24 +3007,26 @@ void Bot::checkParachute () { } void Bot::frame () { - pev->flags |= FL_CLIENT | FL_FAKECLIENT; // restore fake client bit, just in case + if (m_thinkTimer.time < game.time ()) { + m_thinkTimer.time = game.time () + m_thinkTimer.interval; - const auto timestamp = game.time (); + if (m_aimFlags && AimFlags::Enemy) { + focusEnemy (); + } + doFireWeapons (); + updateLookAngles (); - if (m_thinkDelay.time <= timestamp) { - update (); + pev->flags |= FL_CLIENT | FL_FAKECLIENT; // restore fake client bit, just in case - // delay next execution for thinking - m_thinkDelay.time = timestamp + m_thinkDelay.interval; - } + if (m_fullThinkTimer.time < game.time ()) { + m_fullThinkTimer.time = game.time () + m_fullThinkTimer.interval; - // run bot command on twice speed - if (m_commandDelay.time <= timestamp) { + update (); + } runMovement (); - m_commandDelay.time = timestamp + m_commandDelay.interval; } - if (m_slowFrameTimestamp > timestamp) { + if (m_slowFrameTimestamp > game.time ()) { return; } @@ -3390,11 +3392,7 @@ void Bot::logic () { executeTasks (); // execute current task setAimDirection (); // choose aim direction updateLookAngles (); // and turn to chosen aim direction - - // the bots wants to fire at something? - if (m_shootAtDeadTime > game.time () || (m_wantsToFire && !m_isUsingGrenade && m_shootTime <= game.time ())) { - fireWeapons (); // if bot didn't fire a bullet try again next frame - } + doFireWeapons (); // do weapon firing // check for reloading if (m_reloadCheckTime <= game.time ()) { diff --git a/src/combat.cpp b/src/combat.cpp index 605809b..e57bb25 100644 --- a/src/combat.cpp +++ b/src/combat.cpp @@ -1217,6 +1217,14 @@ void Bot::selectWeapons (float distance, int, int id, int choosen) { } } +void Bot::doFireWeapons () { + // the bots wants to fire at something? + + if (m_shootAtDeadTime > game.time () || (m_wantsToFire && !m_isUsingGrenade && m_shootTime <= game.time ())) { + fireWeapons (); // if bot didn't fire a bullet try again next frame + } +} + void Bot::fireWeapons () { // this function will return true if weapon was fired, false otherwise diff --git a/src/manager.cpp b/src/manager.cpp index e5cf4b5..8c36718 100644 --- a/src/manager.cpp +++ b/src/manager.cpp @@ -1732,23 +1732,22 @@ void Bot::newRound () { pushChatterMessage (Chatter::NewRound); } auto thinkFps = cr::clamp (cv_think_fps.as (), 30.0f, 90.0f); - - auto updateInterval = 1.0f / thinkFps; - auto commandInterval = 1.0f / 60.0f; + auto thinkInterval = 1.0f / thinkFps; if (game.is (GameFlags::Xash3D)) { if (thinkFps < 50) { - updateInterval = 1.0f / 50.0f; // xash3d works acceptable at 50fps + thinkInterval = 1.0f / 50.0f; // xash3d works acceptable at 50fps } } + auto fullThinkInterval = 1.0f / 10.0f; // legacy games behaves strange, when this enabled, disable for xash3d as well if requested if (bots.isFrameSkipDisabled ()) { - updateInterval = 0.0f; - commandInterval = 0.0f; + thinkInterval = 0.0f; + fullThinkInterval = 0.0f; } - m_thinkDelay.interval = updateInterval; - m_commandDelay.interval = commandInterval; + m_thinkTimer.interval = thinkInterval; + m_fullThinkTimer.interval = fullThinkInterval; } void Bot::resetPathSearchType () {