fixed UpdateLookAngles is not called at all since last commit :)

This commit is contained in:
jeefo 2015-08-02 20:31:14 +03:00
commit a5c1c0dc7f
6 changed files with 35 additions and 58 deletions

View file

@ -1504,8 +1504,7 @@ public:
int GetFacingIndex (void); int GetFacingIndex (void);
int FindFarest (const Vector &origin, float maxDistance = 32.0); int FindFarest (const Vector &origin, float maxDistance = 32.0);
int FindNearest (const Vector &origin, float minDistance = 9999.0, int flags = -1); 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 <int> &radiusHolder, float radius, const Vector &origin, int maxCount = -1);
void FindInRadius (Array <int> &radiusHolder, float radius, const Vector &origin);
void Add (int flags, const Vector &waypointOrigin = nullvec); void Add (int flags, const Vector &waypointOrigin = nullvec);
void Delete (void); void Delete (void);

View file

@ -176,23 +176,23 @@ void Bot::CheckGrenadeThrow (void)
if (allowThrowing && m_seeEnemyTime + 2.0 < GetWorldTime ()) if (allowThrowing && m_seeEnemyTime + 2.0 < GetWorldTime ())
{ {
const Vector &enemyPredict = ((m_lastEnemy->v.velocity * 0.5).Get2D () + m_lastEnemy->v.origin); 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 (); float searchRadius = m_lastEnemy->v.velocity.GetLength2D ();
// check the search radius // check the search radius
if (searchRadius < 128.0) if (searchRadius < 128.0)
searchRadius = 128.0; searchRadius = 128.0;
// search waypoints Array <int> predictedPoints;
waypoints.FindInRadius (enemyPredict, searchRadius, searchTab, &count);
while (count > 0) // search waypoints
waypoints.FindInRadius (predictedPoints, searchRadius, enemyPredict, 4);
FOR_EACH_AE (predictedPoints, it)
{ {
allowThrowing = true; allowThrowing = true;
// check the throwing // check the throwing
m_throw = waypoints.GetPath (searchTab[count--])->origin; m_throw = waypoints.GetPath (predictedPoints[it])->origin;
Vector src = CheckThrow (EyePosition (), m_throw); Vector src = CheckThrow (EyePosition (), m_throw);
if (src.GetLengthSquared () < 100.0) if (src.GetLengthSquared () < 100.0)
@ -4846,7 +4846,7 @@ void Bot::BotAI (void)
m_moveAngles.ClampAngles (); m_moveAngles.ClampAngles ();
m_moveAngles.x *= -1.0; // invert for engine 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_moveToGoal = false; // don't move to goal
m_navTimeset = GetWorldTime (); m_navTimeset = GetWorldTime ();
@ -5695,6 +5695,7 @@ void Bot::MoveToVector (const Vector &to)
byte Bot::ThrottledMsec (void) byte Bot::ThrottledMsec (void)
{ {
// estimate msec to use for this command based on time passed from the previous command // estimate msec to use for this command based on time passed from the previous command
#if 0
float msecVal = (GetWorldTime () - m_lastCommandTime) * 1000.0f; float msecVal = (GetWorldTime () - m_lastCommandTime) * 1000.0f;
int msecRest = 0; int msecRest = 0;
@ -5714,8 +5715,14 @@ byte Bot::ThrottledMsec (void)
newMsec = 100; newMsec = 100;
else if (newMsec < 1) else if (newMsec < 1)
newMsec = 1; newMsec = 1;
#endif
return newMsec; byte adjustedMsec = static_cast <byte> ((GetWorldTime () - m_lastCommandTime) * 1000.0f);
if (adjustedMsec > 255)
adjustedMsec = 255;
return adjustedMsec;
} }
void Bot::RunPlayerMovement (void) void Bot::RunPlayerMovement (void)

View file

@ -778,7 +778,7 @@ void Bot::FireWeapon (void)
goto WeaponSelectEnd; goto WeaponSelectEnd;
// use knife if near and good difficulty (l33t dude!) // 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; goto WeaponSelectEnd;
// loop through all the weapons until terminator is found... // loop through all the weapons until terminator is found...

View file

@ -165,10 +165,10 @@ TacticChoosen:
FilterGoals (offensiveWpts, goalChoices); FilterGoals (offensiveWpts, goalChoices);
else if (tactic == 3 && !waypoints.m_goalPoints.IsEmpty ()) // map goal waypoint 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 ()) if (m_hasC4 && g_timeRoundStart + 20.0f < GetWorldTime ())
{ {
float minDist = 1024.0f; float minDist = 999999.0f;
int count = 0; int count = 0;
for (int i = 0; i < g_numWaypoints; i++) for (int i = 0; i < g_numWaypoints; i++)
@ -178,7 +178,7 @@ TacticChoosen:
if (!(path->flags & FLAG_GOAL)) if (!(path->flags & FLAG_GOAL))
continue; continue;
float distance = (path->origin - pev->origin).GetLength (); float distance = (path->origin - pev->origin).GetLengthSquared ();
if (distance < minDist) if (distance < minDist)
{ {
@ -3157,10 +3157,6 @@ void Bot::UpdateLookAngles (void)
const float delta = GetWorldTime () - m_lookUpdateTime; const float delta = GetWorldTime () - m_lookUpdateTime;
m_lookUpdateTime = GetWorldTime (); 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 // adjust all body and view angles to face an absolute vector
Vector direction = (m_lookAt - EyePosition ()).ToAngles (); Vector direction = (m_lookAt - EyePosition ()).ToAngles ();
direction.x *= -1.0f; // invert for engine 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°) // 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 * 0.5;
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;
// but don't allow getting below a certain value // but don't allow getting below a certain value
if (stiffnessMultiplier < 0.35) if (stiffnessMultiplier < 0.35)
@ -3305,8 +3296,8 @@ void Bot::UpdateLookAnglesLowSkill (const Vector &direction, const float delta)
m_angularDeviation.ClampAngles (); m_angularDeviation.ClampAngles ();
// spring/damper model aiming // spring/damper model aiming
m_aimSpeed.x = (stiffness.x * m_angularDeviation.x) - (damperCoefficient.x * m_aimSpeed.x); 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.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 // 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) // 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; m_aimSpeed.y += m_aimSpeed.x * influence.x;
// move the aim cursor // 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 (); pev->v_angle.ClampAngles ();
} }

View file

@ -977,10 +977,10 @@ void CheckWelcomeMessage (void)
{ {
// the purpose of this function, is to send quick welcome message, to the listenserver entity. // 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; static float receiveTime = 0.0;
if (isReceived || !yb_listenserver_welcome.GetBool ()) if (alreadyReceived)
return; return;
Array <String> sentences; Array <String> sentences;
@ -1003,10 +1003,10 @@ void CheckWelcomeMessage (void)
sentences.Push ("attention, expect experimental armed hostile presence"); sentences.Push ("attention, expect experimental armed hostile presence");
sentences.Push ("warning, medical attention required"); 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 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 <char *> (sentences.GetRandomElement ().GetBuffer ())); ServerCommand ("speak \"%s\"", const_cast <char *> (sentences.GetRandomElement ().GetBuffer ()));
@ -1034,7 +1034,7 @@ void CheckWelcomeMessage (void)
MESSAGE_END (); MESSAGE_END ();
receiveTime = 0.0; receiveTime = 0.0;
isReceived = true; alreadyReceived = true;
} }
} }

View file

@ -117,9 +117,9 @@ int Waypoint::FindNearest (const Vector &origin, float minDistance, int flags)
if (flags != -1 && !(m_paths[i]->flags & flags)) if (flags != -1 && !(m_paths[i]->flags & flags))
continue; // if flag not -1 and waypoint has no this flag, skip waypoint 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; index = i;
minDistance = distance; minDistance = distance;
@ -128,32 +128,16 @@ int Waypoint::FindNearest (const Vector &origin, float minDistance, int flags)
return index; return index;
} }
void Waypoint::FindInRadius (const Vector &origin, float radius, int *holdTab, int *count) void Waypoint::FindInRadius (Array <int> &radiusHolder, float radius, const Vector &origin, int maxCount)
{ {
// returns all waypoints within radius from position // returns all waypoints within radius from position
int maxCount = *count;
*count = 0;
for (int i = 0; i < g_numWaypoints; i++) for (int i = 0; i < g_numWaypoints; i++)
{ {
if ((m_paths[i]->origin - origin).GetLength () < radius) if (maxCount != -1 && radiusHolder.GetElementNumber () > maxCount)
{
*holdTab++ = i;
*count += 1;
if (*count >= maxCount)
break; break;
}
}
*count -= 1;
}
void Waypoint::FindInRadius (Array <int> &radiusHolder, float radius, const Vector &origin) if ((m_paths[i]->origin - origin).GetLengthSquared () < GET_SQUARE (radius))
{
for (int i = 0; i < g_numWaypoints; i++)
{
if ((m_paths[i]->origin - origin).GetLength () < radius)
radiusHolder.Push (i); radiusHolder.Push (i);
} }
} }