From ac3a5c7c3fbcde388aa13ddf7c9621508ceee7f6 Mon Sep 17 00:00:00 2001 From: jeefo Date: Mon, 3 Aug 2015 00:05:27 +0300 Subject: [PATCH] remove of pod-bot-mm msec method fixed weird aiming on low fps machines fixed potential crash bug in weaponn selection code --- include/core.h | 1 - include/corelib.h | 7 ++++++- source/basecode.cpp | 23 +---------------------- source/combat.cpp | 2 +- source/manager.cpp | 6 +++--- source/navigate.cpp | 6 +++--- 6 files changed, 14 insertions(+), 31 deletions(-) diff --git a/include/core.h b/include/core.h index 2cf5536..8a9f2bf 100644 --- a/include/core.h +++ b/include/core.h @@ -905,7 +905,6 @@ private: float m_frameInterval; // bot's frame interval float m_lastCommandTime; // time bot last thinked - float m_msecValRest; // bot's msec value float m_reloadCheckTime; // time to check reloading float m_zoomCheckTime; // time to check zoom again diff --git a/include/corelib.h b/include/corelib.h index 3ed5378..913ed50 100644 --- a/include/corelib.h +++ b/include/corelib.h @@ -225,10 +225,15 @@ namespace Math #endif } - inline float AngleDiff (float destAngle, float srcAngle) + static inline float AngleDiff (float destAngle, float srcAngle) { return AngleNormalize (destAngle - srcAngle); } + + template Type Clamp (Type x, Type a, Type b) + { + return x < a ? a : (x > b ? b : x); + } } // diff --git a/source/basecode.cpp b/source/basecode.cpp index eef58c5..4ce8ffd 100644 --- a/source/basecode.cpp +++ b/source/basecode.cpp @@ -3206,7 +3206,7 @@ void Bot::RunTask_Normal (void) m_moveSpeed = GetWalkSpeed (); // bot hasn't seen anything in a long time and is asking his teammates to report in - if (m_seeEnemyTime + Random.Float (30.0, 80.0) < GetWorldTime () && Random.Long (0, 100) < 70 && g_timeRoundStart + 20.0 < GetWorldTime () && m_askCheckTime + Random.Float (20.0, 30.0) < GetWorldTime ()) + if (m_seeEnemyTime + Random.Float (45.0f, 80.0f) < GetWorldTime () && Random.Long (0, 100) < 30 && g_timeRoundStart + 20.0 < GetWorldTime () && m_askCheckTime + Random.Float (20.0, 30.0) < GetWorldTime ()) { m_askCheckTime = GetWorldTime (); RadioMessage (Radio_ReportTeam); @@ -5695,27 +5695,6 @@ void Bot::MoveToVector (const Vector &to) byte Bot::ThrottledMsec (void) { // estimate msec to use for this command based on time passed from the previous command -#if 0 - float msecVal = (GetWorldTime () - m_lastCommandTime) * 1000.0f; - - int msecRest = 0; - byte newMsec = static_cast (msecVal); - - if (newMsec < 10) - { - msecVal -= static_cast (newMsec) + m_msecValRest; - msecRest = static_cast (msecVal); - - m_msecValRest = msecVal - static_cast (msecRest); - } - newMsec += msecRest; - - // bots are going to be slower than they should if this happens. - if (newMsec > 100) - newMsec = 100; - else if (newMsec < 1) - newMsec = 1; -#endif byte adjustedMsec = static_cast ((GetWorldTime () - m_lastCommandTime) * 1000.0f); diff --git a/source/combat.cpp b/source/combat.cpp index 5f1d539..40995b4 100644 --- a/source/combat.cpp +++ b/source/combat.cpp @@ -1421,7 +1421,7 @@ void Bot::SelectBestWeapon (void) ammoLeft = true; // is no ammo required for this weapon OR enough ammo available to fire - if (g_weaponDefs[id].ammo1 < 0 || m_ammo[g_weaponDefs[id].ammo1] >= selectTab[selectIndex].minPrimaryAmmo) + if (g_weaponDefs[id].ammo1 < 0 || (g_weaponDefs[id].ammo1 < 32 && m_ammo[g_weaponDefs[id].ammo1] >= selectTab[selectIndex].minPrimaryAmmo)) ammoLeft = true; if (ammoLeft) diff --git a/source/manager.cpp b/source/manager.cpp index 5b9edc1..a5579dc 100644 --- a/source/manager.cpp +++ b/source/manager.cpp @@ -837,7 +837,6 @@ Bot::Bot (edict_t *bot, int difficulty, int personality, int team, int member, c m_lastCommandTime = GetWorldTime () - 0.1f; m_frameInterval = GetWorldTime (); - m_msecValRest = 0.0f; m_timePeriodicUpdate = 0.0f; switch (personality) @@ -1089,8 +1088,9 @@ void Bot::NewRound (void) m_isUsingGrenade = false; m_blindButton = 0; - m_blindTime = 0.0; - m_jumpTime = 0.0; + m_blindTime = 0.0f; + m_jumpTime = 0.0f; + m_jumpStateTimer = 0.0f; m_jumpFinished = false; m_isStuck = false; diff --git a/source/navigate.cpp b/source/navigate.cpp index 7e8a61f..7c4f3ee 100644 --- a/source/navigate.cpp +++ b/source/navigate.cpp @@ -3154,7 +3154,7 @@ void Bot::UpdateBodyAngles (void) void Bot::UpdateLookAngles (void) { - const float delta = GetWorldTime () - m_lookUpdateTime; + const float delta = Clamp (GetWorldTime () - m_lookUpdateTime, MATH_EQEPSILON, 0.05f); m_lookUpdateTime = GetWorldTime (); // adjust all body and view angles to face an absolute vector @@ -3188,8 +3188,8 @@ void Bot::UpdateLookAngles (void) m_idealAngles = pev->v_angle; - float angleDiffYaw = AngleNormalize (direction.y - m_idealAngles.y); - float angleDiffPitch = AngleNormalize (direction.x - m_idealAngles.x); + float angleDiffYaw = AngleDiff (direction.y, m_idealAngles.y); + float angleDiffPitch = AngleDiff (direction.x, m_idealAngles.x); if (angleDiffYaw < 1.0f && angleDiffYaw > -1.0f) {