From a5c1c0dc7fb235117db521a9c22ab87ba370977b Mon Sep 17 00:00:00 2001 From: jeefo Date: Sun, 2 Aug 2015 20:31:14 +0300 Subject: [PATCH] fixed UpdateLookAngles is not called at all since last commit :) --- include/core.h | 3 +-- source/basecode.cpp | 23 +++++++++++++++-------- source/combat.cpp | 2 +- source/navigate.cpp | 27 +++++++-------------------- source/support.cpp | 10 +++++----- source/waypoint.cpp | 28 ++++++---------------------- 6 files changed, 35 insertions(+), 58 deletions(-) diff --git a/include/core.h b/include/core.h index b6b91d0..2cf5536 100644 --- a/include/core.h +++ b/include/core.h @@ -1504,8 +1504,7 @@ public: int GetFacingIndex (void); int FindFarest (const Vector &origin, float maxDistance = 32.0); int FindNearest (const Vector &origin, float minDistance = 9999.0, int flags = -1); - void FindInRadius (const Vector &origin, float radius, int *holdTab, int *count); - void FindInRadius (Array &radiusHolder, float radius, const Vector &origin); + void FindInRadius (Array &radiusHolder, float radius, const Vector &origin, int maxCount = -1); void Add (int flags, const Vector &waypointOrigin = nullvec); void Delete (void); diff --git a/source/basecode.cpp b/source/basecode.cpp index 0157a40..eef58c5 100644 --- a/source/basecode.cpp +++ b/source/basecode.cpp @@ -176,23 +176,23 @@ void Bot::CheckGrenadeThrow (void) if (allowThrowing && m_seeEnemyTime + 2.0 < GetWorldTime ()) { const Vector &enemyPredict = ((m_lastEnemy->v.velocity * 0.5).Get2D () + m_lastEnemy->v.origin); - int searchTab[4], count = 4; - float searchRadius = m_lastEnemy->v.velocity.GetLength2D (); // check the search radius if (searchRadius < 128.0) searchRadius = 128.0; - // search waypoints - waypoints.FindInRadius (enemyPredict, searchRadius, searchTab, &count); + Array predictedPoints; - while (count > 0) + // search waypoints + waypoints.FindInRadius (predictedPoints, searchRadius, enemyPredict, 4); + + FOR_EACH_AE (predictedPoints, it) { allowThrowing = true; // check the throwing - m_throw = waypoints.GetPath (searchTab[count--])->origin; + m_throw = waypoints.GetPath (predictedPoints[it])->origin; Vector src = CheckThrow (EyePosition (), m_throw); if (src.GetLengthSquared () < 100.0) @@ -4846,7 +4846,7 @@ void Bot::BotAI (void) m_moveAngles.ClampAngles (); m_moveAngles.x *= -1.0; // invert for engine - if (m_difficulty == 4 && ((m_aimFlags & AIM_ENEMY) || (m_states & (STATE_SEEING_ENEMY | STATE_SUSPECT_ENEMY)) || (GetTaskId () == TASK_SEEKCOVER && (m_isReloading || m_isVIP))) && !yb_jasonmode.GetBool () && GetTaskId () != TASK_CAMP && !IsOnLadder ()) + if (m_difficulty > 3 && ((m_aimFlags & AIM_ENEMY) || (m_states & (STATE_SEEING_ENEMY | STATE_SUSPECT_ENEMY)) || (GetTaskId () == TASK_SEEKCOVER && (m_isReloading || m_isVIP))) && !yb_jasonmode.GetBool () && GetTaskId () != TASK_CAMP && !IsOnLadder ()) { m_moveToGoal = false; // don't move to goal m_navTimeset = GetWorldTime (); @@ -5695,6 +5695,7 @@ 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; @@ -5714,8 +5715,14 @@ byte Bot::ThrottledMsec (void) newMsec = 100; else if (newMsec < 1) newMsec = 1; +#endif - return newMsec; + byte adjustedMsec = static_cast ((GetWorldTime () - m_lastCommandTime) * 1000.0f); + + if (adjustedMsec > 255) + adjustedMsec = 255; + + return adjustedMsec; } void Bot::RunPlayerMovement (void) diff --git a/source/combat.cpp b/source/combat.cpp index a0a59f6..5f1d539 100644 --- a/source/combat.cpp +++ b/source/combat.cpp @@ -778,7 +778,7 @@ void Bot::FireWeapon (void) goto WeaponSelectEnd; // use knife if near and good difficulty (l33t dude!) - if (m_difficulty >= 3 && pev->health > 80 && !IsEntityNull (enemy) && pev->health >= enemy->v.health && distance < 100.0f && !IsGroupOfEnemies (pev->origin)) + if (m_difficulty >= 3 && pev->health > 80 && !IsEntityNull (enemy) && pev->health >= enemy->v.health && distance < 100.0f && !IsOnLadder () && !IsGroupOfEnemies (pev->origin)) goto WeaponSelectEnd; // loop through all the weapons until terminator is found... diff --git a/source/navigate.cpp b/source/navigate.cpp index 3e68046..7e8a61f 100644 --- a/source/navigate.cpp +++ b/source/navigate.cpp @@ -165,10 +165,10 @@ TacticChoosen: FilterGoals (offensiveWpts, goalChoices); else if (tactic == 3 && !waypoints.m_goalPoints.IsEmpty ()) // map goal waypoint { - // forcee bomber to select closest goal, if round-start goal was reset by something + // force bomber to select closest goal, if round-start goal was reset by something if (m_hasC4 && g_timeRoundStart + 20.0f < GetWorldTime ()) { - float minDist = 1024.0f; + float minDist = 999999.0f; int count = 0; for (int i = 0; i < g_numWaypoints; i++) @@ -178,7 +178,7 @@ TacticChoosen: if (!(path->flags & FLAG_GOAL)) continue; - float distance = (path->origin - pev->origin).GetLength (); + float distance = (path->origin - pev->origin).GetLengthSquared (); if (distance < minDist) { @@ -3157,10 +3157,6 @@ void Bot::UpdateLookAngles (void) const float delta = GetWorldTime () - m_lookUpdateTime; m_lookUpdateTime = GetWorldTime (); - // in intermission, do not try to look at something, but update the timer above - if (g_timeRoundStart < GetWorldTime () || !m_buyingFinished) - return; - // adjust all body and view angles to face an absolute vector Vector direction = (m_lookAt - EyePosition ()).ToAngles (); direction.x *= -1.0f; // invert for engine @@ -3287,12 +3283,7 @@ void Bot::UpdateLookAnglesLowSkill (const Vector &direction, const float delta) } // also take in account the remaining deviation (slow down the aiming in the last 10°) - if (m_difficulty < 3 && (m_angularDeviation.GetLength () < 10.0)) - stiffnessMultiplier *= m_angularDeviation.GetLength () * 0.1; - - // slow down even more if we are not moving - if (m_difficulty < 3 && pev->velocity.GetLength () < 1.0 && GetTaskId () != TASK_CAMP && GetTaskId () != TASK_ATTACK) - stiffnessMultiplier *= 0.5; + stiffnessMultiplier *= m_angularDeviation.GetLength () * 0.1 * 0.5; // but don't allow getting below a certain value if (stiffnessMultiplier < 0.35) @@ -3305,8 +3296,8 @@ void Bot::UpdateLookAnglesLowSkill (const Vector &direction, const float delta) m_angularDeviation.ClampAngles (); // spring/damper model aiming - m_aimSpeed.x = (stiffness.x * m_angularDeviation.x) - (damperCoefficient.x * m_aimSpeed.x); - m_aimSpeed.y = (stiffness.y * m_angularDeviation.y) - (damperCoefficient.y * m_aimSpeed.y); + m_aimSpeed.x = stiffness.x * m_angularDeviation.x - damperCoefficient.x * m_aimSpeed.x; + m_aimSpeed.y = stiffness.y * m_angularDeviation.y - damperCoefficient.y * m_aimSpeed.y; // influence of y movement on x axis and vice versa (less influence than x on y since it's // easier and more natural for the bot to "move its mouse" horizontally than vertically) @@ -3314,11 +3305,7 @@ void Bot::UpdateLookAnglesLowSkill (const Vector &direction, const float delta) m_aimSpeed.y += m_aimSpeed.x * influence.x; // move the aim cursor - if (m_difficulty == 4 && (m_aimFlags & AIM_ENEMY) && (m_wantsToFire || UsesSniper ())) - pev->v_angle = direction; - else - pev->v_angle = pev->v_angle + delta * Vector (m_aimSpeed.x, m_aimSpeed.y, 0.0f); - + pev->v_angle = pev->v_angle + delta * Vector (m_aimSpeed.x, m_aimSpeed.y, 0.0f); pev->v_angle.ClampAngles (); } diff --git a/source/support.cpp b/source/support.cpp index 4691a1d..4a2c2ab 100644 --- a/source/support.cpp +++ b/source/support.cpp @@ -977,10 +977,10 @@ void CheckWelcomeMessage (void) { // the purpose of this function, is to send quick welcome message, to the listenserver entity. - static bool isReceived = false; + static bool alreadyReceived = !yb_listenserver_welcome.GetBool (); static float receiveTime = 0.0; - if (isReceived || !yb_listenserver_welcome.GetBool ()) + if (alreadyReceived) return; Array sentences; @@ -1003,10 +1003,10 @@ void CheckWelcomeMessage (void) sentences.Push ("attention, expect experimental armed hostile presence"); sentences.Push ("warning, medical attention required"); - if (IsAlive (g_hostEntity) && !isReceived && receiveTime < 1.0 && (g_numWaypoints > 0 ? g_isCommencing : true)) + if (IsAlive (g_hostEntity) && !alreadyReceived && receiveTime < 1.0 && (g_numWaypoints > 0 ? g_isCommencing : true)) receiveTime = GetWorldTime () + 4.0; // receive welcome message in four seconds after game has commencing - if (receiveTime > 0.0 && receiveTime < GetWorldTime () && !isReceived && (g_numWaypoints > 0 ? g_isCommencing : true)) + if (receiveTime > 0.0 && receiveTime < GetWorldTime () && !alreadyReceived && (g_numWaypoints > 0 ? g_isCommencing : true)) { ServerCommand ("speak \"%s\"", const_cast (sentences.GetRandomElement ().GetBuffer ())); @@ -1034,7 +1034,7 @@ void CheckWelcomeMessage (void) MESSAGE_END (); receiveTime = 0.0; - isReceived = true; + alreadyReceived = true; } } diff --git a/source/waypoint.cpp b/source/waypoint.cpp index 9158a38..01a0ea8 100644 --- a/source/waypoint.cpp +++ b/source/waypoint.cpp @@ -117,9 +117,9 @@ int Waypoint::FindNearest (const Vector &origin, float minDistance, int flags) if (flags != -1 && !(m_paths[i]->flags & flags)) continue; // if flag not -1 and waypoint has no this flag, skip waypoint - float distance = (m_paths[i]->origin - origin).GetLength (); + float distance = (m_paths[i]->origin - origin).GetLengthSquared (); - if (distance < minDistance) + if (distance < GET_SQUARE (minDistance)) { index = i; minDistance = distance; @@ -128,32 +128,16 @@ int Waypoint::FindNearest (const Vector &origin, float minDistance, int flags) return index; } -void Waypoint::FindInRadius (const Vector &origin, float radius, int *holdTab, int *count) +void Waypoint::FindInRadius (Array &radiusHolder, float radius, const Vector &origin, int maxCount) { // returns all waypoints within radius from position - int maxCount = *count; - *count = 0; - for (int i = 0; i < g_numWaypoints; i++) { - if ((m_paths[i]->origin - origin).GetLength () < radius) - { - *holdTab++ = i; - *count += 1; + if (maxCount != -1 && radiusHolder.GetElementNumber () > maxCount) + break; - if (*count >= maxCount) - break; - } - } - *count -= 1; -} - -void Waypoint::FindInRadius (Array &radiusHolder, float radius, const Vector &origin) -{ - for (int i = 0; i < g_numWaypoints; i++) - { - if ((m_paths[i]->origin - origin).GetLength () < radius) + if ((m_paths[i]->origin - origin).GetLengthSquared () < GET_SQUARE (radius)) radiusHolder.Push (i); } }