2017-10-19 20:12:02 +03:00
|
|
|
/*
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify it
|
|
|
|
* under the terms of the GNU General Public License as published by the
|
|
|
|
* Free Software Foundation; either version 2 of the License, or (at
|
|
|
|
* your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful, but
|
|
|
|
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software Foundation,
|
|
|
|
* Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
|
|
*
|
|
|
|
* In addition, as a special exception, the author gives permission to
|
|
|
|
* link the code of this program with the Half-Life Game Engine ("HL
|
|
|
|
* Engine") and Modified Game Libraries ("MODs") developed by Valve,
|
|
|
|
* L.L.C ("Valve"). You must obey the GNU General Public License in all
|
|
|
|
* respects for all of the code used other than the HL Engine and MODs
|
|
|
|
* from Valve. If you modify this file, you may extend this exception
|
|
|
|
* to your version of the file, but you are not obligated to do so. If
|
|
|
|
* you do not wish to do so, delete this exception statement from your
|
|
|
|
* version.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2015-06-30 12:46:07 +03:00
|
|
|
#include "precompiled.h"
|
|
|
|
|
2016-01-19 14:54:31 +03:00
|
|
|
// Lightweight maintenance, invoked frequently
|
2017-07-01 23:40:10 +03:00
|
|
|
void CCSBot::Upkeep()
|
2015-12-09 01:39:54 +03:00
|
|
|
{
|
2016-02-23 02:13:52 +03:00
|
|
|
if (TheCSBots()->IsLearningMap() || !IsAlive())
|
2015-12-09 01:39:54 +03:00
|
|
|
return;
|
|
|
|
|
|
|
|
if (m_isRapidFiring)
|
|
|
|
TogglePrimaryAttack();
|
|
|
|
|
2016-01-19 14:54:31 +03:00
|
|
|
// aiming must be smooth - update often
|
2015-12-09 01:39:54 +03:00
|
|
|
if (IsAimingAtEnemy())
|
|
|
|
{
|
|
|
|
UpdateAimOffset();
|
|
|
|
|
2016-01-19 14:54:31 +03:00
|
|
|
// aim at enemy, if he's still alive
|
2017-10-12 17:50:56 +03:00
|
|
|
if (m_enemy.IsValid())
|
2015-12-09 01:39:54 +03:00
|
|
|
{
|
|
|
|
float feetOffset = pev->origin.z - GetFeetZ();
|
|
|
|
|
|
|
|
if (IsEnemyVisible())
|
|
|
|
{
|
|
|
|
if (GetProfile()->GetSkill() > 0.5f)
|
|
|
|
{
|
|
|
|
const float k = 3.0f;
|
|
|
|
m_aimSpot = (m_enemy->pev->velocity - pev->velocity) * g_flBotCommandInterval * k + m_enemy->pev->origin;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
m_aimSpot = m_enemy->pev->origin;
|
|
|
|
|
|
|
|
bool aimBlocked = false;
|
2016-01-19 14:54:31 +03:00
|
|
|
const float sharpshooter = 0.8f;
|
2015-12-09 01:39:54 +03:00
|
|
|
|
2016-01-19 14:54:31 +03:00
|
|
|
if (IsUsingAWP() || IsUsingShotgun() || IsUsingMachinegun() || GetProfile()->GetSkill() < sharpshooter
|
2015-12-09 01:39:54 +03:00
|
|
|
|| (IsActiveWeaponRecoilHigh() && !IsUsingPistol() && !IsUsingSniperRifle()))
|
|
|
|
{
|
|
|
|
if (IsEnemyPartVisible(CHEST))
|
|
|
|
{
|
2016-01-19 14:54:31 +03:00
|
|
|
// No headshots, go for the chest.
|
2015-12-09 01:39:54 +03:00
|
|
|
aimBlocked = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (aimBlocked)
|
|
|
|
m_aimSpot.z -= feetOffset * 0.25f;
|
|
|
|
|
|
|
|
else if (!IsEnemyPartVisible(HEAD))
|
|
|
|
{
|
|
|
|
if (IsEnemyPartVisible(CHEST))
|
|
|
|
{
|
|
|
|
m_aimSpot.z -= feetOffset * 0.5f;
|
|
|
|
}
|
|
|
|
else if (IsEnemyPartVisible(LEFT_SIDE))
|
|
|
|
{
|
|
|
|
Vector2D to = (m_enemy->pev->origin - pev->origin).Make2D();
|
|
|
|
to.NormalizeInPlace();
|
|
|
|
|
|
|
|
m_aimSpot.x -= to.y * 16.0f;
|
|
|
|
m_aimSpot.y += to.x * 16.0f;
|
|
|
|
m_aimSpot.z -= feetOffset * 0.5f;
|
|
|
|
}
|
|
|
|
else if (IsEnemyPartVisible(RIGHT_SIDE))
|
|
|
|
{
|
|
|
|
Vector2D to = (m_enemy->pev->origin - pev->origin).Make2D();
|
|
|
|
to.NormalizeInPlace();
|
|
|
|
|
|
|
|
m_aimSpot.x += to.y * 16.0f;
|
|
|
|
m_aimSpot.y -= to.x * 16.0f;
|
|
|
|
m_aimSpot.z -= feetOffset * 0.5f;
|
|
|
|
}
|
|
|
|
else // FEET
|
2017-10-12 17:50:56 +03:00
|
|
|
{
|
2015-12-09 01:39:54 +03:00
|
|
|
m_aimSpot.z -= (feetOffset + feetOffset);
|
2017-10-12 17:50:56 +03:00
|
|
|
}
|
2015-12-09 01:39:54 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
2017-10-12 17:50:56 +03:00
|
|
|
{
|
2015-12-09 01:39:54 +03:00
|
|
|
m_aimSpot = m_lastEnemyPosition;
|
2017-10-12 17:50:56 +03:00
|
|
|
}
|
2015-12-09 01:39:54 +03:00
|
|
|
|
|
|
|
// add in aim error
|
|
|
|
m_aimSpot.x += m_aimOffset.x;
|
|
|
|
m_aimSpot.y += m_aimOffset.y;
|
|
|
|
m_aimSpot.z += m_aimOffset.z;
|
|
|
|
|
|
|
|
Vector toEnemy = m_aimSpot - pev->origin;
|
|
|
|
Vector idealAngle = UTIL_VecToAngles(toEnemy);
|
|
|
|
|
|
|
|
idealAngle.x = 360.0 - idealAngle.x;
|
|
|
|
SetLookAngles(idealAngle.y, idealAngle.x);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (m_lookAtSpotClearIfClose)
|
|
|
|
{
|
|
|
|
// dont look at spots just in front of our face - it causes erratic view rotation
|
|
|
|
const float tooCloseRange = 100.0f;
|
|
|
|
if ((m_lookAtSpot - pev->origin).IsLengthLessThan(tooCloseRange))
|
|
|
|
m_lookAtSpotState = NOT_LOOKING_AT_SPOT;
|
|
|
|
}
|
|
|
|
|
|
|
|
switch (m_lookAtSpotState)
|
|
|
|
{
|
2017-11-01 18:01:24 +03:00
|
|
|
case NOT_LOOKING_AT_SPOT:
|
|
|
|
{
|
|
|
|
// look ahead
|
|
|
|
SetLookAngles(m_lookAheadAngle, 0);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case LOOK_TOWARDS_SPOT:
|
|
|
|
{
|
|
|
|
UpdateLookAt();
|
|
|
|
|
|
|
|
if (IsLookingAtPosition(&m_lookAtSpot, m_lookAtSpotAngleTolerance))
|
2015-12-09 01:39:54 +03:00
|
|
|
{
|
2017-11-01 18:01:24 +03:00
|
|
|
m_lookAtSpotState = LOOK_AT_SPOT;
|
|
|
|
m_lookAtSpotTimestamp = gpGlobals->time;
|
2015-12-09 01:39:54 +03:00
|
|
|
}
|
2017-11-01 18:01:24 +03:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case LOOK_AT_SPOT:
|
|
|
|
{
|
|
|
|
UpdateLookAt();
|
2015-12-09 01:39:54 +03:00
|
|
|
|
2017-11-01 18:01:24 +03:00
|
|
|
if (m_lookAtSpotDuration >= 0.0f && gpGlobals->time - m_lookAtSpotTimestamp > m_lookAtSpotDuration)
|
2015-12-09 01:39:54 +03:00
|
|
|
{
|
2017-11-01 18:01:24 +03:00
|
|
|
m_lookAtSpotState = NOT_LOOKING_AT_SPOT;
|
|
|
|
m_lookAtSpotDuration = 0.0f;
|
2015-12-09 01:39:54 +03:00
|
|
|
}
|
2017-11-01 18:01:24 +03:00
|
|
|
break;
|
|
|
|
}
|
2015-12-09 01:39:54 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
float driftAmplitude = 2.0f;
|
|
|
|
|
|
|
|
// have view "drift" very slowly, so view looks "alive"
|
|
|
|
if (IsUsingSniperRifle() && IsUsingScope())
|
2016-01-19 14:54:31 +03:00
|
|
|
{
|
|
|
|
driftAmplitude = 0.5f;
|
|
|
|
}
|
2015-12-09 01:39:54 +03:00
|
|
|
|
|
|
|
m_lookYaw += driftAmplitude * BotCOS(33.0f * gpGlobals->time);
|
|
|
|
m_lookPitch += driftAmplitude * BotSIN(13.0f * gpGlobals->time);
|
|
|
|
}
|
|
|
|
|
|
|
|
// view angles can change quickly
|
|
|
|
UpdateLookAngles();
|
|
|
|
}
|
2015-06-30 12:46:07 +03:00
|
|
|
|
2016-01-25 20:02:57 +03:00
|
|
|
// Heavyweight processing, invoked less often
|
2017-07-01 23:40:10 +03:00
|
|
|
void CCSBot::Update()
|
2015-12-09 01:39:54 +03:00
|
|
|
{
|
2016-02-23 02:13:52 +03:00
|
|
|
if (TheCSBots()->IsAnalysisRequested() && m_processMode == PROCESS_NORMAL)
|
2016-01-25 20:02:57 +03:00
|
|
|
{
|
2016-02-23 02:13:52 +03:00
|
|
|
TheCSBots()->AckAnalysisRequest();
|
2016-01-25 20:02:57 +03:00
|
|
|
StartAnalyzeAlphaProcess();
|
|
|
|
}
|
2015-06-30 12:46:07 +03:00
|
|
|
|
2016-01-25 20:02:57 +03:00
|
|
|
switch (m_processMode)
|
|
|
|
{
|
2017-11-01 18:01:24 +03:00
|
|
|
case PROCESS_LEARN: UpdateLearnProcess(); return;
|
|
|
|
case PROCESS_ANALYZE_ALPHA: UpdateAnalyzeAlphaProcess(); return;
|
|
|
|
case PROCESS_ANALYZE_BETA: UpdateAnalyzeBetaProcess(); return;
|
|
|
|
case PROCESS_SAVE: UpdateSaveProcess(); return;
|
2016-01-25 20:02:57 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
// update our radio chatter
|
|
|
|
// need to allow bots to finish their chatter even if they are dead
|
|
|
|
GetChatter()->Update();
|
|
|
|
|
2016-02-04 03:18:26 +03:00
|
|
|
if (m_voiceFeedbackEndTimestamp != 0.0f
|
2016-01-25 20:02:57 +03:00
|
|
|
&& (m_voiceFeedbackEndTimestamp <= gpGlobals->time || gpGlobals->time < m_voiceFeedbackStartTimestamp))
|
|
|
|
{
|
|
|
|
EndVoiceFeedback(NO_FORCE);
|
|
|
|
}
|
|
|
|
|
|
|
|
// check if we are dead
|
|
|
|
if (!IsAlive())
|
|
|
|
{
|
|
|
|
// remember that we died
|
|
|
|
m_diedLastRound = true;
|
|
|
|
BotDeathThink();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// show line of fire
|
2016-02-23 02:13:52 +03:00
|
|
|
if ((cv_bot_traceview.value == 100.0 && IsLocalPlayerWatchingMe()) || cv_bot_traceview.value == 101.0)
|
2016-01-25 20:02:57 +03:00
|
|
|
{
|
|
|
|
UTIL_MakeVectors(pev->punchangle + pev->v_angle);
|
|
|
|
|
|
|
|
if (!IsFriendInLineOfFire())
|
|
|
|
{
|
|
|
|
Vector vecAiming = gpGlobals->v_forward;
|
|
|
|
Vector vecSrc = GetGunPosition();
|
|
|
|
|
|
|
|
if (m_iTeam == TERRORIST)
|
|
|
|
UTIL_DrawBeamPoints(vecSrc, vecSrc + 2000.0f * vecAiming, 1, 255, 0, 0);
|
|
|
|
else
|
|
|
|
UTIL_DrawBeamPoints(vecSrc, vecSrc + 2000.0f * vecAiming, 1, 0, 50, 255);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-02-23 02:13:52 +03:00
|
|
|
//
|
2016-01-25 20:02:57 +03:00
|
|
|
// Debug beam rendering
|
2016-02-23 02:13:52 +03:00
|
|
|
//
|
|
|
|
|
|
|
|
// show approach points
|
|
|
|
if ((cv_bot_traceview.value == 2.0f && IsLocalPlayerWatchingMe()) || cv_bot_traceview.value == 3.0f)
|
2016-01-25 20:02:57 +03:00
|
|
|
DrawApproachPoints();
|
|
|
|
|
2016-02-23 02:13:52 +03:00
|
|
|
// show encounter spot data
|
|
|
|
if ((cv_bot_traceview.value == 4.0f && IsLocalPlayerWatchingMe()) || cv_bot_traceview.value == 5.0f)
|
2016-01-25 20:02:57 +03:00
|
|
|
{
|
2017-10-12 17:50:56 +03:00
|
|
|
if (m_spotEncounter)
|
2016-02-23 02:13:52 +03:00
|
|
|
{
|
|
|
|
UTIL_DrawBeamPoints(m_spotEncounter->path.from, m_spotEncounter->path.to, 3, 0, 0, 255);
|
|
|
|
|
|
|
|
Vector dir = m_spotEncounter->path.to - m_spotEncounter->path.from;
|
|
|
|
float length = dir.NormalizeInPlace();
|
|
|
|
|
2017-10-12 17:50:56 +03:00
|
|
|
for (auto &order : m_spotEncounter->spotList) {
|
|
|
|
UTIL_DrawBeamPoints(m_spotEncounter->path.from + order.t * length * dir, *order.spot->GetPosition(), 3, 0, 255, 255);
|
2016-02-23 02:13:52 +03:00
|
|
|
}
|
|
|
|
}
|
2016-01-25 20:02:57 +03:00
|
|
|
}
|
|
|
|
|
2016-02-23 02:13:52 +03:00
|
|
|
// show path navigation data
|
2016-01-25 20:02:57 +03:00
|
|
|
if (cv_bot_traceview.value == 1.0f && IsLocalPlayerWatchingMe())
|
|
|
|
{
|
2016-02-23 02:13:52 +03:00
|
|
|
Vector from = GetEyePosition();
|
|
|
|
const float size = 50.0f;
|
|
|
|
|
|
|
|
Vector arrow(size * float(Q_cos(m_lookAheadAngle * M_PI / 180.0f)), size * float(Q_sin(m_lookAheadAngle * M_PI / 180.0f)), 0.0f);
|
|
|
|
UTIL_DrawBeamPoints(from, from + arrow, 1, 0, 255, 255);
|
2016-01-25 20:02:57 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
if (cv_bot_stop.value != 0.0f)
|
|
|
|
return;
|
|
|
|
|
|
|
|
// check if we are stuck
|
|
|
|
StuckCheck();
|
|
|
|
|
|
|
|
// if our current 'noise' was heard a long time ago, forget it
|
|
|
|
const float rememberNoiseDuration = 20.0f;
|
|
|
|
if (m_noiseTimestamp > 0.0f && gpGlobals->time - m_noiseTimestamp > rememberNoiseDuration)
|
|
|
|
{
|
|
|
|
ForgetNoise();
|
|
|
|
}
|
|
|
|
|
|
|
|
// where are we
|
|
|
|
if (!m_currentArea || !m_currentArea->Contains(&pev->origin))
|
|
|
|
{
|
|
|
|
m_currentArea = TheNavAreaGrid.GetNavArea(&pev->origin);
|
|
|
|
}
|
|
|
|
|
|
|
|
// track the last known area we were in
|
2017-10-12 17:50:56 +03:00
|
|
|
if (m_currentArea && m_currentArea != m_lastKnownArea)
|
2016-01-25 20:02:57 +03:00
|
|
|
{
|
|
|
|
m_lastKnownArea = m_currentArea;
|
|
|
|
// assume that we "clear" an area of enemies when we enter it
|
|
|
|
m_currentArea->SetClearedTimestamp(m_iTeam - 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
// update approach points
|
|
|
|
const float recomputeApproachPointTolerance = 50.0f;
|
|
|
|
if ((m_approachPointViewPosition - pev->origin).IsLengthGreaterThan(recomputeApproachPointTolerance))
|
|
|
|
{
|
|
|
|
ComputeApproachPoints();
|
|
|
|
m_approachPointViewPosition = pev->origin;
|
|
|
|
}
|
|
|
|
|
2017-10-12 17:50:56 +03:00
|
|
|
if (cv_bot_show_nav.value > 0.0f && m_lastKnownArea)
|
2016-01-25 20:02:57 +03:00
|
|
|
{
|
|
|
|
m_lastKnownArea->DrawConnectedAreas();
|
|
|
|
}
|
|
|
|
|
|
|
|
// if we're blind, retreat!
|
|
|
|
if (IsBlind())
|
|
|
|
{
|
|
|
|
if (!IsAtHidingSpot())
|
|
|
|
{
|
|
|
|
switch (m_blindMoveDir)
|
|
|
|
{
|
2017-11-01 18:01:24 +03:00
|
|
|
case FORWARD: MoveForward(); break;
|
|
|
|
case RIGHT: StrafeRight(); break;
|
|
|
|
case BACKWARD: MoveBackward(); break;
|
|
|
|
case LEFT: StrafeLeft(); break;
|
|
|
|
default: Crouch(); break;
|
2016-01-25 20:02:57 +03:00
|
|
|
}
|
|
|
|
}
|
2016-02-23 02:13:52 +03:00
|
|
|
|
2016-01-25 20:02:57 +03:00
|
|
|
if (m_blindFire)
|
|
|
|
{
|
|
|
|
PrimaryAttack();
|
|
|
|
}
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Enemy acquisition and attack initiation
|
|
|
|
// take a snapshot and update our reaction time queue
|
|
|
|
UpdateReactionQueue();
|
|
|
|
|
|
|
|
// "threat" may be the same as our current enemy
|
|
|
|
CBasePlayer *threat = GetRecognizedEnemy();
|
2017-10-12 17:50:56 +03:00
|
|
|
if (threat)
|
2016-01-25 20:02:57 +03:00
|
|
|
{
|
|
|
|
// adjust our personal "safe" time
|
|
|
|
AdjustSafeTime();
|
|
|
|
|
2016-02-23 02:13:52 +03:00
|
|
|
if (IsUsingGrenade())
|
2016-01-25 20:02:57 +03:00
|
|
|
{
|
2016-02-23 02:13:52 +03:00
|
|
|
ThrowGrenade(&threat->pev->origin);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// Decide if we should attack
|
|
|
|
bool doAttack = false;
|
2016-01-25 20:02:57 +03:00
|
|
|
switch (GetDisposition())
|
|
|
|
{
|
2017-11-01 18:01:24 +03:00
|
|
|
case IGNORE_ENEMIES:
|
|
|
|
{
|
|
|
|
// never attack
|
|
|
|
doAttack = false;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case SELF_DEFENSE:
|
|
|
|
{
|
|
|
|
// attack if fired on
|
|
|
|
doAttack = IsPlayerLookingAtMe(threat);
|
2016-01-25 20:02:57 +03:00
|
|
|
|
2017-11-01 18:01:24 +03:00
|
|
|
// attack if enemy very close
|
|
|
|
if (!doAttack)
|
2016-01-25 20:02:57 +03:00
|
|
|
{
|
2017-11-01 18:01:24 +03:00
|
|
|
const float selfDefenseRange = 750.0f;
|
|
|
|
doAttack = (pev->origin - threat->pev->origin).IsLengthLessThan(selfDefenseRange);
|
2016-01-25 20:02:57 +03:00
|
|
|
}
|
2017-11-01 18:01:24 +03:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case ENGAGE_AND_INVESTIGATE:
|
|
|
|
case OPPORTUNITY_FIRE:
|
|
|
|
{
|
|
|
|
// normal combat range
|
|
|
|
doAttack = true;
|
|
|
|
break;
|
|
|
|
}
|
2016-01-25 20:02:57 +03:00
|
|
|
}
|
2016-02-23 02:13:52 +03:00
|
|
|
|
|
|
|
if (doAttack)
|
|
|
|
{
|
2017-10-12 17:50:56 +03:00
|
|
|
if (!GetEnemy() || threat != GetEnemy() || !IsAttacking())
|
2016-02-23 02:13:52 +03:00
|
|
|
{
|
|
|
|
if (IsUsingKnife() && IsHiding())
|
|
|
|
{
|
|
|
|
// if hiding with a knife, wait until threat is close
|
|
|
|
const float knifeAttackRange = 250.0f;
|
|
|
|
if ((pev->origin - threat->pev->origin).IsLengthLessThan(knifeAttackRange))
|
|
|
|
{
|
|
|
|
Attack(threat);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
Attack(threat);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// dont attack, but keep track of nearby enemies
|
|
|
|
SetEnemy(threat);
|
|
|
|
m_isEnemyVisible = true;
|
|
|
|
}
|
2016-01-25 20:02:57 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
// if we aren't attacking but we are being attacked, retaliate
|
2016-02-23 02:13:52 +03:00
|
|
|
if (GetDisposition() != IGNORE_ENEMIES && !IsAttacking())
|
2016-01-25 20:02:57 +03:00
|
|
|
{
|
|
|
|
const float recentAttackDuration = 1.0f;
|
|
|
|
if (GetTimeSinceAttacked() < recentAttackDuration)
|
|
|
|
{
|
|
|
|
// we may not be attacking our attacker, but at least we're not just taking it
|
|
|
|
// (since m_attacker isn't reaction-time delayed, we can't directly use it)
|
2016-02-23 02:13:52 +03:00
|
|
|
Attack(threat);
|
2016-01-25 20:02:57 +03:00
|
|
|
PrintIfWatched("Ouch! Retaliating!\n");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-02-23 02:13:52 +03:00
|
|
|
TheCSBots()->SetLastSeenEnemyTimestamp();
|
2016-01-25 20:02:57 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
// Validate existing enemy, if any
|
2017-10-12 17:50:56 +03:00
|
|
|
if (m_enemy.IsValid())
|
2016-01-25 20:02:57 +03:00
|
|
|
{
|
|
|
|
if (IsAwareOfEnemyDeath())
|
|
|
|
{
|
|
|
|
// we have noticed that our enemy has died
|
2017-10-12 17:50:56 +03:00
|
|
|
m_enemy = nullptr;
|
2016-01-25 20:02:57 +03:00
|
|
|
m_isEnemyVisible = false;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2016-02-23 02:13:52 +03:00
|
|
|
const int dada = offsetof(CCSBot, m_visibleEnemyParts);
|
2016-01-25 20:02:57 +03:00
|
|
|
// check LOS to current enemy (chest & head), in case he's dead (GetNearestEnemy() only returns live players)
|
|
|
|
// note we're not checking FOV - once we've acquired an enemy (which does check FOV), assume we know roughly where he is
|
|
|
|
if (IsVisible(m_enemy, false, &m_visibleEnemyParts))
|
|
|
|
{
|
|
|
|
m_isEnemyVisible = true;
|
|
|
|
m_lastSawEnemyTimestamp = gpGlobals->time;
|
|
|
|
m_lastEnemyPosition = m_enemy->pev->origin;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
m_isEnemyVisible = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// check if enemy died
|
|
|
|
if (m_enemy->IsAlive())
|
|
|
|
{
|
|
|
|
m_enemyDeathTimestamp = 0.0f;
|
|
|
|
m_isLastEnemyDead = false;
|
|
|
|
}
|
|
|
|
else if (m_enemyDeathTimestamp == 0.0f)
|
|
|
|
{
|
|
|
|
// note time of death (to allow bots to overshoot for a time)
|
|
|
|
m_enemyDeathTimestamp = gpGlobals->time;
|
|
|
|
m_isLastEnemyDead = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
m_isEnemyVisible = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// if we have seen an enemy recently, keep an eye on him if we can
|
|
|
|
const float seenRecentTime = 3.0f;
|
2017-10-12 17:50:56 +03:00
|
|
|
if (m_enemy.IsValid() && GetTimeSinceLastSawEnemy() < seenRecentTime)
|
2016-01-25 20:02:57 +03:00
|
|
|
{
|
|
|
|
AimAtEnemy();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
StopAiming();
|
|
|
|
}
|
|
|
|
|
|
|
|
// Hack to fire while retreating
|
|
|
|
// TODO: Encapsulate aiming and firing on enemies separately from current task
|
|
|
|
if (GetDisposition() == IGNORE_ENEMIES)
|
|
|
|
{
|
|
|
|
FireWeaponAtEnemy();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (IsEndOfSafeTime() && IsUsingGrenade() && (IsWellPastSafe() || !IsUsingHEGrenade()) && !m_isWaitingToTossGrenade)
|
|
|
|
{
|
|
|
|
Vector target;
|
|
|
|
if (FindGrenadeTossPathTarget(&target))
|
|
|
|
{
|
|
|
|
ThrowGrenade(&target);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (IsUsingGrenade())
|
|
|
|
{
|
|
|
|
bool doToss = (m_isWaitingToTossGrenade && (m_tossGrenadeTimer.IsElapsed() || m_lookAtSpotState == LOOK_AT_SPOT));
|
|
|
|
|
|
|
|
if (doToss)
|
|
|
|
{
|
|
|
|
ClearPrimaryAttack();
|
|
|
|
m_isWaitingToTossGrenade = false;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
PrimaryAttack();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
m_isWaitingToTossGrenade = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (IsHunting() && IsWellPastSafe() && IsUsingGrenade())
|
|
|
|
{
|
|
|
|
EquipBestWeapon(MUST_EQUIP);
|
|
|
|
}
|
|
|
|
|
|
|
|
// check if our weapon is totally out of ammo
|
|
|
|
// or if we no longer feel "safe", equip our weapon
|
|
|
|
if (!IsSafe() && !IsUsingGrenade() && IsActiveWeaponOutOfAmmo())
|
|
|
|
{
|
|
|
|
EquipBestWeapon();
|
|
|
|
}
|
|
|
|
|
|
|
|
// TODO: This doesn't work if we are restricted to just knives and sniper rifles because we cant use the rifle at close range
|
|
|
|
if (!IsSafe() && !IsUsingGrenade() && IsUsingKnife() && !IsEscapingFromBomb())
|
|
|
|
{
|
|
|
|
EquipBestWeapon();
|
|
|
|
}
|
|
|
|
|
|
|
|
// if we haven't seen an enemy in awhile, and we switched to our pistol during combat,
|
|
|
|
// switch back to our primary weapon (if it still has ammo left)
|
|
|
|
const float safeRearmTime = 5.0f;
|
|
|
|
if (!IsActiveWeaponReloading() && IsUsingPistol() && !IsPrimaryWeaponEmpty() && GetTimeSinceLastSawEnemy() > safeRearmTime)
|
|
|
|
{
|
|
|
|
EquipBestWeapon();
|
|
|
|
}
|
|
|
|
|
|
|
|
// reload our weapon if we must
|
|
|
|
ReloadCheck();
|
|
|
|
|
|
|
|
// equip silencer
|
|
|
|
SilencerCheck();
|
|
|
|
|
|
|
|
// listen to the radio
|
|
|
|
RespondToRadioCommands();
|
|
|
|
|
|
|
|
// make way
|
|
|
|
const float avoidTime = 0.33f;
|
2017-10-12 17:50:56 +03:00
|
|
|
if (gpGlobals->time - m_avoidTimestamp < avoidTime && m_avoid)
|
2016-01-25 20:02:57 +03:00
|
|
|
{
|
|
|
|
StrafeAwayFromPosition(&m_avoid->pev->origin);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2017-10-12 17:50:56 +03:00
|
|
|
m_avoid = nullptr;
|
2016-01-25 20:02:57 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
if (m_isJumpCrouching)
|
|
|
|
{
|
|
|
|
const float duration = 0.75f;
|
|
|
|
const float crouchDelayTime = 0.05f;
|
|
|
|
const float standUpTime = 0.6f;
|
|
|
|
float elapsed = gpGlobals->time - m_jumpCrouchTimestamp;
|
|
|
|
|
|
|
|
if (elapsed > crouchDelayTime && elapsed < standUpTime)
|
|
|
|
Crouch();
|
|
|
|
|
|
|
|
if (elapsed >= standUpTime)
|
|
|
|
StandUp();
|
|
|
|
|
|
|
|
if (elapsed > duration)
|
|
|
|
m_isJumpCrouching = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// if we're using a sniper rifle and are no longer attacking, stop looking thru scope
|
|
|
|
if (!IsAtHidingSpot() && !IsAttacking() && IsUsingSniperRifle() && IsUsingScope())
|
|
|
|
{
|
|
|
|
SecondaryAttack();
|
|
|
|
}
|
|
|
|
|
|
|
|
// check encounter spots
|
|
|
|
UpdatePeripheralVision();
|
|
|
|
|
|
|
|
// Update gamestate
|
2017-10-12 17:50:56 +03:00
|
|
|
if (m_bomber)
|
|
|
|
{
|
2016-01-25 20:02:57 +03:00
|
|
|
GetChatter()->SpottedBomber(GetBomber());
|
2017-10-12 17:50:56 +03:00
|
|
|
}
|
2016-01-25 20:02:57 +03:00
|
|
|
|
|
|
|
if (CanSeeLooseBomb())
|
2017-10-12 17:50:56 +03:00
|
|
|
{
|
2016-02-23 02:13:52 +03:00
|
|
|
GetChatter()->SpottedLooseBomb(TheCSBots()->GetLooseBomb());
|
2017-10-12 17:50:56 +03:00
|
|
|
}
|
2016-01-25 20:02:57 +03:00
|
|
|
|
|
|
|
// Scenario interrupts
|
2016-02-23 02:13:52 +03:00
|
|
|
switch (TheCSBots()->GetScenario())
|
2016-01-25 20:02:57 +03:00
|
|
|
{
|
2017-11-01 18:01:24 +03:00
|
|
|
case CCSBotManager::SCENARIO_DEFUSE_BOMB:
|
|
|
|
{
|
|
|
|
// flee if the bomb is ready to blow and we aren't defusing it or attacking and we know where the bomb is
|
|
|
|
// (aggressive players wait until its almost too late)
|
|
|
|
float gonnaBlowTime = 8.0f - (2.0f * GetProfile()->GetAggression());
|
|
|
|
|
|
|
|
// if we have a defuse kit, can wait longer
|
|
|
|
if (m_bHasDefuser)
|
|
|
|
gonnaBlowTime *= 0.66f;
|
|
|
|
|
|
|
|
if (!IsEscapingFromBomb() // we aren't already escaping the bomb
|
|
|
|
&& TheCSBots()->IsBombPlanted() // is the bomb planted
|
|
|
|
&& GetGameState()->IsPlantedBombLocationKnown() // we know where the bomb is
|
|
|
|
&& TheCSBots()->GetBombTimeLeft() < gonnaBlowTime // is the bomb about to explode
|
|
|
|
&& !IsDefusingBomb() // we aren't defusing the bomb
|
|
|
|
&& !IsAttacking()) // we aren't in the midst of a firefight
|
2016-01-25 20:02:57 +03:00
|
|
|
{
|
2017-11-01 18:01:24 +03:00
|
|
|
EscapeFromBomb();
|
2016-01-25 20:02:57 +03:00
|
|
|
break;
|
|
|
|
}
|
2017-11-01 18:01:24 +03:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case CCSBotManager::SCENARIO_RESCUE_HOSTAGES:
|
|
|
|
{
|
|
|
|
if (m_iTeam == CT)
|
2016-01-25 20:02:57 +03:00
|
|
|
{
|
2017-11-01 18:01:24 +03:00
|
|
|
UpdateHostageEscortCount();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// Terrorists have imperfect information on status of hostages
|
|
|
|
CSGameState::ValidateStatusType status = GetGameState()->ValidateHostagePositions();
|
|
|
|
|
|
|
|
if (status & CSGameState::HOSTAGES_ALL_GONE)
|
2016-01-25 20:02:57 +03:00
|
|
|
{
|
2017-11-01 18:01:24 +03:00
|
|
|
GetChatter()->HostagesTaken();
|
|
|
|
Idle();
|
2016-01-25 20:02:57 +03:00
|
|
|
}
|
2017-11-01 18:01:24 +03:00
|
|
|
else if (status & CSGameState::HOSTAGE_GONE)
|
2016-01-25 20:02:57 +03:00
|
|
|
{
|
2017-11-01 18:01:24 +03:00
|
|
|
GetGameState()->HostageWasTaken();
|
|
|
|
Idle();
|
2016-01-25 20:02:57 +03:00
|
|
|
}
|
|
|
|
}
|
2017-11-01 18:01:24 +03:00
|
|
|
break;
|
|
|
|
}
|
2016-01-25 20:02:57 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
// Follow nearby humans if our co-op is high and we have nothing else to do
|
|
|
|
// If we were just following someone, don't auto-follow again for a short while to
|
|
|
|
// give us a chance to do something else.
|
|
|
|
const float earliestAutoFollowTime = 5.0f;
|
|
|
|
const float minAutoFollowTeamwork = 0.4f;
|
2016-02-23 02:13:52 +03:00
|
|
|
if (TheCSBots()->GetElapsedRoundTime() > earliestAutoFollowTime
|
2016-01-25 20:02:57 +03:00
|
|
|
&& GetProfile()->GetTeamwork() > minAutoFollowTeamwork
|
|
|
|
&& CanAutoFollow()
|
|
|
|
&& !IsBusy()
|
|
|
|
&& !IsFollowing()
|
|
|
|
&& !GetGameState()->IsAtPlantedBombsite())
|
|
|
|
{
|
|
|
|
// chance of following is proportional to teamwork attribute
|
|
|
|
if (GetProfile()->GetTeamwork() > RANDOM_FLOAT(0.0f, 1.0f))
|
|
|
|
{
|
|
|
|
CBasePlayer *leader = GetClosestVisibleHumanFriend();
|
2017-10-12 17:50:56 +03:00
|
|
|
if (leader && leader->IsAutoFollowAllowed())
|
2016-01-25 20:02:57 +03:00
|
|
|
{
|
|
|
|
// count how many bots are already following this player
|
|
|
|
const float maxFollowCount = 2;
|
|
|
|
if (GetBotFollowCount(leader) < maxFollowCount)
|
|
|
|
{
|
|
|
|
const float autoFollowRange = 300.0f;
|
|
|
|
if ((leader->pev->origin - pev->origin).IsLengthLessThan(autoFollowRange))
|
|
|
|
{
|
|
|
|
CNavArea *leaderArea = TheNavAreaGrid.GetNavArea(&leader->pev->origin);
|
2017-10-12 17:50:56 +03:00
|
|
|
if (leaderArea)
|
2016-01-25 20:02:57 +03:00
|
|
|
{
|
|
|
|
PathCost cost(this, FASTEST_ROUTE);
|
|
|
|
float travelRange = NavAreaTravelDistance(GetLastKnownArea(), leaderArea, cost);
|
|
|
|
if (/*travelRange >= 0.0f &&*/ travelRange < autoFollowRange)
|
|
|
|
{
|
|
|
|
// follow this human
|
|
|
|
Follow(leader);
|
|
|
|
PrintIfWatched("Auto-Following %s\n", STRING(leader->pev->netname));
|
|
|
|
|
2016-02-23 02:13:52 +03:00
|
|
|
if (CSGameRules()->IsCareer())
|
2016-01-25 20:02:57 +03:00
|
|
|
{
|
|
|
|
GetChatter()->Say("FollowingCommander", 10.0f);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
GetChatter()->Say("FollowingSir", 10.0f);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// we decided not to follow, don't re-check for a duration
|
|
|
|
m_allowAutoFollowTime = gpGlobals->time + 15.0f + (1.0f - GetProfile()->GetTeamwork()) * 30.0f;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (IsFollowing())
|
|
|
|
{
|
|
|
|
// if we are following someone, make sure they are still alive
|
2017-10-12 17:50:56 +03:00
|
|
|
CBaseEntity *pLeader = m_leader;
|
|
|
|
if (!pLeader || !pLeader->IsAlive())
|
2016-01-25 20:02:57 +03:00
|
|
|
{
|
|
|
|
StopFollowing();
|
|
|
|
}
|
|
|
|
|
|
|
|
// decide whether to continue following them
|
|
|
|
const float highTeamwork = 0.85f;
|
|
|
|
if (GetProfile()->GetTeamwork() < highTeamwork)
|
|
|
|
{
|
|
|
|
float minFollowDuration = 15.0f;
|
|
|
|
if (GetFollowDuration() > minFollowDuration + 40.0f * GetProfile()->GetTeamwork())
|
|
|
|
{
|
|
|
|
// we are bored of following our leader
|
|
|
|
StopFollowing();
|
|
|
|
PrintIfWatched("Stopping following - bored\n");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (GetMorale() < NEUTRAL && IsSafe() && GetSafeTimeRemaining() < 2.0f && IsHunting())
|
|
|
|
{
|
|
|
|
if (GetMorale() * -40.0 > RANDOM_FLOAT(0.0f, 100.0f))
|
|
|
|
{
|
2016-02-23 02:13:52 +03:00
|
|
|
if (TheCSBots()->IsOnOffense(this) || !TheCSBots()->IsDefenseRushing())
|
2016-01-25 20:02:57 +03:00
|
|
|
{
|
|
|
|
SetDisposition(OPPORTUNITY_FIRE);
|
|
|
|
Hide(m_lastKnownArea, RANDOM_FLOAT(3.0f, 15.0f));
|
|
|
|
GetChatter()->Say("WaitingHere");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Execute state machine
|
|
|
|
if (m_isAttacking)
|
|
|
|
{
|
|
|
|
m_attackState.OnUpdate(this);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
m_state->OnUpdate(this);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (m_isWaitingToTossGrenade)
|
|
|
|
{
|
|
|
|
ResetStuckMonitor();
|
|
|
|
ClearMovement();
|
|
|
|
}
|
|
|
|
|
|
|
|
// don't move while reloading unless we see an enemy
|
|
|
|
if (IsReloading() && !m_isEnemyVisible)
|
|
|
|
{
|
|
|
|
ResetStuckMonitor();
|
|
|
|
ClearMovement();
|
|
|
|
}
|
|
|
|
|
|
|
|
// if we get too far ahead of the hostages we are escorting, wait for them
|
|
|
|
if (!IsAttacking() && m_inhibitWaitingForHostageTimer.IsElapsed())
|
|
|
|
{
|
|
|
|
const float waitForHostageRange = 500.0f;
|
|
|
|
if (GetTask() == RESCUE_HOSTAGES && GetRangeToFarthestEscortedHostage() > waitForHostageRange)
|
|
|
|
{
|
|
|
|
if (!m_isWaitingForHostage)
|
|
|
|
{
|
|
|
|
// just started waiting
|
|
|
|
m_isWaitingForHostage = true;
|
|
|
|
m_waitForHostageTimer.Start(10.0f);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// we've been waiting
|
|
|
|
if (m_waitForHostageTimer.IsElapsed())
|
|
|
|
{
|
|
|
|
// give up waiting for awhile
|
|
|
|
m_isWaitingForHostage = false;
|
|
|
|
m_inhibitWaitingForHostageTimer.Start(3.0f);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// keep waiting
|
|
|
|
ResetStuckMonitor();
|
|
|
|
ClearMovement();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// remember our prior safe time status
|
|
|
|
m_wasSafe = IsSafe();
|
2016-01-19 14:54:31 +03:00
|
|
|
}
|