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"
|
|
|
|
|
|
|
|
// Used to update view angles to stay on a ladder
|
2015-09-16 23:19:21 +03:00
|
|
|
float StayOnLadderLine(CCSBot *me, const CNavLadder *ladder)
|
|
|
|
{
|
|
|
|
// determine our facing
|
|
|
|
NavDirType faceDir = AngleToDirection(me->pev->v_angle.y);
|
|
|
|
const float stiffness = 1.0f;
|
|
|
|
|
|
|
|
// move toward ladder mount point
|
|
|
|
switch (faceDir)
|
|
|
|
{
|
2015-08-20 13:35:01 +03:00
|
|
|
case NORTH:
|
2016-01-19 14:54:31 +03:00
|
|
|
return (stiffness * (ladder->m_top.x - me->pev->origin.x));
|
2015-08-20 13:35:01 +03:00
|
|
|
case EAST:
|
2016-01-19 14:54:31 +03:00
|
|
|
return (stiffness * (ladder->m_top.y - me->pev->origin.y));
|
2015-08-20 13:35:01 +03:00
|
|
|
case SOUTH:
|
2016-01-19 14:54:31 +03:00
|
|
|
return (-stiffness * (ladder->m_top.x - me->pev->origin.x));
|
2015-08-20 13:35:01 +03:00
|
|
|
case WEST:
|
2016-01-19 14:54:31 +03:00
|
|
|
return (-stiffness * (ladder->m_top.y - me->pev->origin.y));
|
2015-09-16 23:19:21 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
return 0.0f;
|
2015-06-30 12:46:07 +03:00
|
|
|
}
|
2015-09-16 23:19:21 +03:00
|
|
|
|
2016-01-19 14:54:31 +03:00
|
|
|
// Move actual view angles towards desired ones.
|
|
|
|
// This is the only place v_angle is altered.
|
|
|
|
// TODO: Make stiffness and turn rate constants timestep invariant.
|
2016-02-04 03:18:26 +03:00
|
|
|
void CCSBot::UpdateLookAngles()
|
2015-09-16 23:19:21 +03:00
|
|
|
{
|
2016-01-19 14:54:31 +03:00
|
|
|
const float deltaT = g_flBotCommandInterval;
|
|
|
|
float maxAccel;
|
|
|
|
float stiffness;
|
|
|
|
float damping;
|
|
|
|
|
|
|
|
// springs are stiffer when attacking, so we can track and move between targets better
|
|
|
|
if (IsAttacking())
|
2015-09-16 23:19:21 +03:00
|
|
|
{
|
2016-01-19 14:54:31 +03:00
|
|
|
stiffness = 300.0f;
|
|
|
|
damping = 30.0f;
|
|
|
|
maxAccel = 3000.0f;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
stiffness = 200.0f;
|
|
|
|
damping = 25.0f;
|
|
|
|
maxAccel = 3000.0f;
|
|
|
|
}
|
|
|
|
|
|
|
|
// these may be overridden by ladder logic
|
|
|
|
float useYaw = m_lookYaw;
|
|
|
|
float usePitch = m_lookPitch;
|
|
|
|
|
|
|
|
// Ladders require precise movement, therefore we need to look at the
|
|
|
|
// ladder as we approach and ascend/descend it.
|
|
|
|
// If we are on a ladder, we need to look up or down to traverse it - override pitch in this case.
|
|
|
|
// If we're trying to break something, though, we actually need to look at it before we can
|
|
|
|
// look at the ladder
|
|
|
|
if (IsUsingLadder())
|
|
|
|
{
|
|
|
|
// set yaw to aim at ladder
|
|
|
|
Vector to = m_pathLadder->m_top - pev->origin;
|
|
|
|
float idealYaw = UTIL_VecToYaw(to);
|
|
|
|
|
|
|
|
NavDirType faceDir = m_pathLadder->m_dir;
|
|
|
|
|
|
|
|
if (m_pathLadderFaceIn)
|
|
|
|
{
|
|
|
|
faceDir = OppositeDirection(faceDir);
|
|
|
|
}
|
|
|
|
|
|
|
|
const float lookAlongLadderRange = 100.0f;
|
|
|
|
const float ladderPitch = 60.0f;
|
|
|
|
|
|
|
|
// adjust pitch to look up/down ladder as we ascend/descend
|
|
|
|
switch (m_pathLadderState)
|
|
|
|
{
|
2017-11-01 18:01:24 +03:00
|
|
|
case APPROACH_ASCENDING_LADDER:
|
|
|
|
{
|
|
|
|
Vector to = m_goalPosition - pev->origin;
|
|
|
|
useYaw = idealYaw;
|
|
|
|
|
|
|
|
if (to.IsLengthLessThan(lookAlongLadderRange))
|
2016-01-19 14:54:31 +03:00
|
|
|
usePitch = -ladderPitch;
|
2017-11-01 18:01:24 +03:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case APPROACH_DESCENDING_LADDER:
|
|
|
|
{
|
|
|
|
Vector to = m_goalPosition - pev->origin;
|
|
|
|
useYaw = idealYaw;
|
|
|
|
|
|
|
|
if (to.IsLengthLessThan(lookAlongLadderRange))
|
2016-01-19 14:54:31 +03:00
|
|
|
usePitch = ladderPitch;
|
2017-11-01 18:01:24 +03:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case FACE_ASCENDING_LADDER:
|
|
|
|
{
|
|
|
|
useYaw = idealYaw;
|
|
|
|
usePitch = -ladderPitch;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case FACE_DESCENDING_LADDER:
|
|
|
|
{
|
|
|
|
useYaw = idealYaw;
|
|
|
|
usePitch = ladderPitch;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case MOUNT_ASCENDING_LADDER:
|
|
|
|
case ASCEND_LADDER:
|
|
|
|
{
|
|
|
|
useYaw = DirectionToAngle(faceDir) + StayOnLadderLine(this, m_pathLadder);
|
|
|
|
usePitch = -ladderPitch;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case MOUNT_DESCENDING_LADDER:
|
|
|
|
case DESCEND_LADDER:
|
|
|
|
{
|
|
|
|
useYaw = DirectionToAngle(faceDir) + StayOnLadderLine(this, m_pathLadder);
|
|
|
|
usePitch = ladderPitch;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case DISMOUNT_ASCENDING_LADDER:
|
|
|
|
case DISMOUNT_DESCENDING_LADDER:
|
|
|
|
{
|
|
|
|
useYaw = DirectionToAngle(faceDir);
|
|
|
|
break;
|
|
|
|
}
|
2016-01-19 14:54:31 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Yaw
|
|
|
|
float angleDiff = NormalizeAngle(useYaw - pev->v_angle.y);
|
|
|
|
|
|
|
|
// if almost at target angle, snap to it
|
|
|
|
const float onTargetTolerance = 1.0f;
|
|
|
|
if (angleDiff < onTargetTolerance && angleDiff > -onTargetTolerance)
|
|
|
|
{
|
|
|
|
m_lookYawVel = 0.0f;
|
|
|
|
pev->v_angle.y = useYaw;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// simple angular spring/damper
|
|
|
|
float accel = stiffness * angleDiff - damping * m_lookYawVel;
|
|
|
|
|
|
|
|
// limit rate
|
|
|
|
if (accel > maxAccel)
|
|
|
|
accel = maxAccel;
|
|
|
|
|
|
|
|
else if (accel < -maxAccel)
|
|
|
|
accel = -maxAccel;
|
|
|
|
|
|
|
|
m_lookYawVel += deltaT * accel;
|
|
|
|
pev->v_angle.y += deltaT * m_lookYawVel;
|
2015-09-16 23:19:21 +03:00
|
|
|
}
|
|
|
|
|
2016-01-19 14:54:31 +03:00
|
|
|
// Pitch
|
|
|
|
// Actually, this is negative pitch.
|
|
|
|
angleDiff = usePitch - pev->v_angle.x;
|
|
|
|
|
|
|
|
angleDiff = NormalizeAngle(angleDiff);
|
|
|
|
|
|
|
|
if (false && angleDiff < onTargetTolerance && angleDiff > -onTargetTolerance)
|
|
|
|
{
|
|
|
|
m_lookPitchVel = 0.0f;
|
|
|
|
pev->v_angle.x = usePitch;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// simple angular spring/damper
|
|
|
|
// double the stiffness since pitch is only +/- 90 and yaw is +/- 180
|
|
|
|
float accel = 2.0f * stiffness * angleDiff - damping * m_lookPitchVel;
|
|
|
|
|
|
|
|
// limit rate
|
|
|
|
if (accel > maxAccel)
|
|
|
|
accel = maxAccel;
|
|
|
|
|
|
|
|
else if (accel < -maxAccel)
|
|
|
|
accel = -maxAccel;
|
|
|
|
|
|
|
|
m_lookPitchVel += deltaT * accel;
|
|
|
|
pev->v_angle.x += deltaT * m_lookPitchVel;
|
|
|
|
}
|
|
|
|
|
|
|
|
// limit range - avoid gimbal lock
|
|
|
|
if (pev->v_angle.x < -89.0f)
|
|
|
|
pev->v_angle.x = -89.0f;
|
|
|
|
else if (pev->v_angle.x > 89.0f)
|
|
|
|
pev->v_angle.x = 89.0f;
|
|
|
|
|
|
|
|
pev->v_angle.z = 0.0f;
|
2015-06-30 12:46:07 +03:00
|
|
|
}
|
2016-01-19 14:54:31 +03:00
|
|
|
|
|
|
|
// Return true if we can see the point
|
2017-07-01 23:40:10 +03:00
|
|
|
bool CCSBot::IsVisible(const Vector *pos, bool testFOV) const
|
2015-09-16 23:19:21 +03:00
|
|
|
{
|
2016-01-19 14:54:31 +03:00
|
|
|
// we can't see anything if we're blind
|
|
|
|
if (IsBlind())
|
|
|
|
return false;
|
|
|
|
|
|
|
|
// is it in my general viewcone?
|
|
|
|
if (testFOV && !(const_cast<CCSBot *>(this)->FInViewCone(pos)))
|
|
|
|
return false;
|
|
|
|
|
|
|
|
// check line of sight against smoke
|
|
|
|
if (TheCSBots()->IsLineBlockedBySmoke(&GetEyePosition(), pos))
|
|
|
|
return false;
|
|
|
|
|
|
|
|
// check line of sight
|
|
|
|
// Must include CONTENTS_MONSTER to pick up all non-brush objects like barrels
|
|
|
|
TraceResult result;
|
|
|
|
UTIL_TraceLine(GetEyePosition(), *pos, ignore_monsters, ignore_glass, ENT(pev), &result);
|
|
|
|
|
|
|
|
if (result.flFraction != 1.0f)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
return true;
|
2015-06-30 12:46:07 +03:00
|
|
|
}
|
|
|
|
|
2016-01-19 14:54:31 +03:00
|
|
|
// Return true if we can see any part of the player
|
|
|
|
// Check parts in order of importance. Return the first part seen in "visParts" if it is non-NULL.
|
2017-11-22 20:27:55 +03:00
|
|
|
bool CCSBot::IsVisible(CBasePlayer *pPlayer, bool testFOV, unsigned char *visParts) const
|
2015-09-16 23:19:21 +03:00
|
|
|
{
|
2017-11-22 20:27:55 +03:00
|
|
|
Vector spot = pPlayer->pev->origin;
|
2017-10-12 17:50:56 +03:00
|
|
|
unsigned char testVisParts = NONE;
|
2016-01-19 14:54:31 +03:00
|
|
|
|
|
|
|
// finish chest check
|
|
|
|
if (IsVisible(&spot, testFOV))
|
|
|
|
testVisParts |= CHEST;
|
|
|
|
|
|
|
|
// check top of head
|
|
|
|
spot = spot + Vector(0, 0, 25.0f);
|
|
|
|
|
|
|
|
if (IsVisible(&spot, testFOV))
|
|
|
|
testVisParts |= HEAD;
|
|
|
|
|
|
|
|
// check feet
|
|
|
|
const float standFeet = 34.0f;
|
|
|
|
const float crouchFeet = 14.0f;
|
|
|
|
|
2017-11-22 20:27:55 +03:00
|
|
|
if (pPlayer->pev->flags & FL_DUCKING)
|
|
|
|
spot.z = pPlayer->pev->origin.z - crouchFeet;
|
2016-01-19 14:54:31 +03:00
|
|
|
else
|
2017-11-22 20:27:55 +03:00
|
|
|
spot.z = pPlayer->pev->origin.z - standFeet;
|
2016-01-19 14:54:31 +03:00
|
|
|
|
|
|
|
// check feet
|
|
|
|
if (IsVisible(&spot, testFOV))
|
|
|
|
testVisParts |= FEET;
|
|
|
|
|
|
|
|
// check "edges"
|
|
|
|
const float edgeOffset = 13.0f;
|
2017-11-22 20:27:55 +03:00
|
|
|
Vector2D dir = (pPlayer->pev->origin - pev->origin).Make2D();
|
2016-01-19 14:54:31 +03:00
|
|
|
dir.NormalizeInPlace();
|
|
|
|
|
|
|
|
Vector2D perp(-dir.y, dir.x);
|
|
|
|
|
2017-11-22 20:27:55 +03:00
|
|
|
spot = pPlayer->pev->origin + Vector(perp.x * edgeOffset, perp.y * edgeOffset, 0);
|
2016-01-19 14:54:31 +03:00
|
|
|
|
|
|
|
if (IsVisible(&spot, testFOV))
|
|
|
|
testVisParts |= LEFT_SIDE;
|
|
|
|
|
2017-11-22 20:27:55 +03:00
|
|
|
spot = pPlayer->pev->origin - Vector(perp.x * edgeOffset, perp.y * edgeOffset, 0);
|
2016-01-19 14:54:31 +03:00
|
|
|
|
|
|
|
if (IsVisible(&spot, testFOV))
|
|
|
|
testVisParts |= RIGHT_SIDE;
|
|
|
|
|
2017-10-12 17:50:56 +03:00
|
|
|
if (visParts)
|
2016-01-19 14:54:31 +03:00
|
|
|
*visParts = testVisParts;
|
|
|
|
|
|
|
|
if (testVisParts != NONE)
|
|
|
|
return true;
|
|
|
|
|
|
|
|
return false;
|
2015-06-30 12:46:07 +03:00
|
|
|
}
|
|
|
|
|
2017-07-01 23:40:10 +03:00
|
|
|
bool CCSBot::IsEnemyPartVisible(VisiblePartType part) const
|
2015-09-16 23:19:21 +03:00
|
|
|
{
|
|
|
|
if (!IsEnemyVisible())
|
|
|
|
return false;
|
|
|
|
|
|
|
|
return (m_visibleEnemyParts & part) != 0;
|
2015-06-30 12:46:07 +03:00
|
|
|
}
|
|
|
|
|
2016-02-04 03:18:26 +03:00
|
|
|
void CCSBot::UpdateLookAt()
|
2015-06-30 12:46:07 +03:00
|
|
|
{
|
|
|
|
Vector to = m_lookAtSpot - EyePosition();
|
2015-09-16 23:19:21 +03:00
|
|
|
Vector idealAngle = UTIL_VecToAngles(to);
|
2015-06-30 12:46:07 +03:00
|
|
|
idealAngle.x = 360.0f - idealAngle.x;
|
|
|
|
|
2015-09-16 23:19:21 +03:00
|
|
|
SetLookAngles(idealAngle.y, idealAngle.x);
|
2015-06-30 12:46:07 +03:00
|
|
|
}
|
|
|
|
|
2016-01-19 14:54:31 +03:00
|
|
|
// Look at the given point in space for the given duration (-1 means forever)
|
2015-09-16 23:19:21 +03:00
|
|
|
void CCSBot::SetLookAt(const char *desc, const Vector *pos, PriorityType pri, float duration, bool clearIfClose, float angleTolerance)
|
|
|
|
{
|
2017-10-12 17:50:56 +03:00
|
|
|
if (!pos)
|
2015-09-16 23:19:21 +03:00
|
|
|
return;
|
|
|
|
|
|
|
|
// if currently looking at a point in space with higher priority, ignore this request
|
|
|
|
if (m_lookAtSpotState != NOT_LOOKING_AT_SPOT && m_lookAtSpotPriority > pri)
|
|
|
|
return;
|
|
|
|
|
|
|
|
// if already looking at this spot, just extend the time
|
|
|
|
const float tolerance = 10.0f;
|
|
|
|
if (m_lookAtSpotState != NOT_LOOKING_AT_SPOT && VectorsAreEqual(pos, &m_lookAtSpot, tolerance))
|
|
|
|
{
|
|
|
|
m_lookAtSpotDuration = duration;
|
|
|
|
|
|
|
|
if (m_lookAtSpotPriority < pri)
|
|
|
|
m_lookAtSpotPriority = pri;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// look at new spot
|
|
|
|
m_lookAtSpot = *pos;
|
|
|
|
m_lookAtSpotState = LOOK_TOWARDS_SPOT;
|
|
|
|
m_lookAtSpotDuration = duration;
|
|
|
|
m_lookAtSpotPriority = pri;
|
|
|
|
}
|
|
|
|
|
|
|
|
m_lookAtSpotAngleTolerance = angleTolerance;
|
|
|
|
m_lookAtSpotClearIfClose = clearIfClose;
|
|
|
|
m_lookAtDesc = desc;
|
2015-06-30 12:46:07 +03:00
|
|
|
}
|
|
|
|
|
2016-01-19 14:54:31 +03:00
|
|
|
// Block all "look at" and "look around" behavior for given duration - just look ahead
|
|
|
|
void CCSBot::InhibitLookAround(float duration)
|
2015-09-16 23:19:21 +03:00
|
|
|
{
|
2016-01-19 14:54:31 +03:00
|
|
|
m_inhibitLookAroundTimestamp = gpGlobals->time + duration;
|
2015-06-30 12:46:07 +03:00
|
|
|
}
|
|
|
|
|
2016-01-19 14:54:31 +03:00
|
|
|
// Update enounter spot timestamps, etc
|
2016-02-04 03:18:26 +03:00
|
|
|
void CCSBot::UpdatePeripheralVision()
|
2015-09-16 23:19:21 +03:00
|
|
|
{
|
2016-01-19 14:54:31 +03:00
|
|
|
// if we update at 10Hz, this ensures we test once every three
|
|
|
|
const float peripheralUpdateInterval = 0.29f;
|
|
|
|
if (gpGlobals->time - m_peripheralTimestamp < peripheralUpdateInterval)
|
|
|
|
return;
|
|
|
|
|
|
|
|
m_peripheralTimestamp = gpGlobals->time;
|
|
|
|
|
|
|
|
if (m_spotEncounter)
|
|
|
|
{
|
|
|
|
// check LOS to all spots in case we see them with our "peripheral vision"
|
|
|
|
Vector pos;
|
2017-10-12 17:50:56 +03:00
|
|
|
for (auto &spotOrder : m_spotEncounter->spotList)
|
2016-01-19 14:54:31 +03:00
|
|
|
{
|
2017-10-12 17:50:56 +03:00
|
|
|
const Vector *spotPos = spotOrder.spot->GetPosition();
|
2016-01-19 14:54:31 +03:00
|
|
|
|
|
|
|
pos.x = spotPos->x;
|
|
|
|
pos.y = spotPos->y;
|
|
|
|
pos.z = spotPos->z + HalfHumanHeight;
|
|
|
|
|
|
|
|
if (!IsVisible(&pos, CHECK_FOV))
|
|
|
|
continue;
|
|
|
|
|
|
|
|
// can see hiding spot, remember when we saw it last
|
2017-10-12 17:50:56 +03:00
|
|
|
SetHidingSpotCheckTimestamp(spotOrder.spot);
|
2016-01-19 14:54:31 +03:00
|
|
|
}
|
|
|
|
}
|
2015-09-16 23:19:21 +03:00
|
|
|
}
|
|
|
|
|
2016-01-19 14:54:31 +03:00
|
|
|
// Update the "looking around" behavior.
|
|
|
|
void CCSBot::UpdateLookAround(bool updateNow)
|
2015-09-16 23:19:21 +03:00
|
|
|
{
|
2016-01-19 14:54:31 +03:00
|
|
|
// check if looking around has been inhibited
|
|
|
|
// Moved inhibit to allow high priority enemy lookats to still occur
|
|
|
|
if (gpGlobals->time < m_inhibitLookAroundTimestamp)
|
|
|
|
return;
|
|
|
|
|
|
|
|
const float recentThreatTime = 0.25f; // 1.0f;
|
|
|
|
|
|
|
|
// Unless we can hear them moving, in which case look towards the noise
|
|
|
|
if (!IsEnemyVisible())
|
|
|
|
{
|
|
|
|
const float noiseStartleRange = 1000.0f;
|
|
|
|
if (CanHearNearbyEnemyGunfire(noiseStartleRange))
|
|
|
|
{
|
|
|
|
Vector spot = m_noisePosition;
|
|
|
|
spot.z += HalfHumanHeight;
|
|
|
|
|
|
|
|
SetLookAt("Check dangerous noise", &spot, PRIORITY_HIGH, recentThreatTime);
|
|
|
|
InhibitLookAround(RANDOM_FLOAT(2.0f, 4.0f));
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// If we recently saw an enemy, look towards where we last saw them
|
|
|
|
if (!IsLookingAtSpot(PRIORITY_MEDIUM) && gpGlobals->time - m_lastSawEnemyTimestamp < recentThreatTime)
|
|
|
|
{
|
|
|
|
ClearLookAt();
|
|
|
|
|
|
|
|
Vector spot = m_lastEnemyPosition;
|
|
|
|
|
|
|
|
// find enemy position on the ground
|
|
|
|
if (GetSimpleGroundHeight(&m_lastEnemyPosition, &spot.z))
|
|
|
|
{
|
|
|
|
spot.z += HalfHumanHeight;
|
|
|
|
SetLookAt("Last Enemy Position", &spot, PRIORITY_MEDIUM, RANDOM_FLOAT(2.0f, 3.0f), true);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Look at nearby enemy noises
|
|
|
|
if (UpdateLookAtNoise())
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (IsNotMoving())
|
|
|
|
{
|
|
|
|
// if we're sniping, zoom in to watch our approach points
|
|
|
|
if (IsUsingSniperRifle())
|
|
|
|
{
|
|
|
|
// low skill bots don't pre-zoom
|
|
|
|
if (GetProfile()->GetSkill() > 0.4f)
|
|
|
|
{
|
|
|
|
if (!IsViewMoving())
|
|
|
|
{
|
|
|
|
float range = ComputeWeaponSightRange();
|
|
|
|
AdjustZoom(range);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// zoom out
|
|
|
|
if (GetZoomLevel() != NO_ZOOM)
|
|
|
|
SecondaryAttack();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-10-12 17:50:56 +03:00
|
|
|
if (!m_lastKnownArea)
|
2016-01-19 14:54:31 +03:00
|
|
|
return;
|
|
|
|
|
|
|
|
if (gpGlobals->time < m_lookAroundStateTimestamp)
|
|
|
|
return;
|
|
|
|
|
|
|
|
// if we're sniping, switch look-at spots less often
|
|
|
|
if (IsUsingSniperRifle())
|
|
|
|
m_lookAroundStateTimestamp = gpGlobals->time + RANDOM_FLOAT(5.0f, 10.0f);
|
|
|
|
else
|
|
|
|
m_lookAroundStateTimestamp = gpGlobals->time + RANDOM_FLOAT(1.0f, 2.0f);
|
|
|
|
|
|
|
|
if (m_approachPointCount == 0)
|
|
|
|
{
|
|
|
|
ClearLookAt();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
int which = RANDOM_LONG(0, m_approachPointCount - 1);
|
2017-10-12 17:50:56 +03:00
|
|
|
Vector spot = m_approachPoint[which];
|
2016-01-19 14:54:31 +03:00
|
|
|
|
|
|
|
// don't look at the floor, look roughly at chest level
|
|
|
|
// TODO: If this approach point is very near, this will cause us to aim up in the air if were crouching
|
|
|
|
spot.z += HalfHumanHeight;
|
|
|
|
SetLookAt("Approach Point (Hiding)", &spot, PRIORITY_LOW);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Glance at "encouter spots" as we move past them
|
|
|
|
if (m_spotEncounter)
|
|
|
|
{
|
|
|
|
// Check encounter spots
|
|
|
|
if (!IsSafe() && !IsLookingAtSpot(PRIORITY_LOW))
|
|
|
|
{
|
|
|
|
// allow a short time to look where we're going
|
|
|
|
if (gpGlobals->time < m_spotCheckTimestamp)
|
|
|
|
return;
|
|
|
|
|
|
|
|
// TODO: Use skill parameter instead of accuracy
|
|
|
|
|
|
|
|
// lower skills have exponentially longer delays
|
2017-11-22 20:27:55 +03:00
|
|
|
real_t asleep = (1.0f - GetProfile()->GetSkill());
|
2016-01-19 14:54:31 +03:00
|
|
|
asleep *= asleep;
|
|
|
|
asleep *= asleep;
|
|
|
|
|
|
|
|
m_spotCheckTimestamp = gpGlobals->time + asleep * RANDOM_FLOAT(10.0f, 30.0f);
|
|
|
|
|
|
|
|
// figure out how far along the path segment we are
|
|
|
|
Vector delta = m_spotEncounter->path.to - m_spotEncounter->path.from;
|
2017-11-22 20:27:55 +03:00
|
|
|
real_t length = delta.Length();
|
|
|
|
|
2017-11-07 17:27:54 +03:00
|
|
|
#ifdef REGAMEDLL_FIXES
|
|
|
|
float adx = Q_abs(delta.x);
|
|
|
|
float ady = Q_abs(delta.y);
|
|
|
|
#else
|
2016-02-23 02:13:52 +03:00
|
|
|
float adx = float(Q_abs(int64(delta.x)));
|
|
|
|
float ady = float(Q_abs(int64(delta.y)));
|
2017-11-07 17:27:54 +03:00
|
|
|
#endif
|
2017-11-22 20:27:55 +03:00
|
|
|
real_t t;
|
2016-01-19 14:54:31 +03:00
|
|
|
|
|
|
|
if (adx > ady)
|
|
|
|
t = (pev->origin.x - m_spotEncounter->path.from.x) / delta.x;
|
|
|
|
else
|
|
|
|
t = (pev->origin.y - m_spotEncounter->path.from.y) / delta.y;
|
|
|
|
|
|
|
|
// advance parameter a bit so we "lead" our checks
|
|
|
|
const float leadCheckRange = 50.0f;
|
|
|
|
t += leadCheckRange / length;
|
|
|
|
|
|
|
|
if (t < 0.0f)
|
|
|
|
t = 0.0f;
|
|
|
|
else if (t > 1.0f)
|
|
|
|
t = 1.0f;
|
|
|
|
|
|
|
|
// collect the unchecked spots so far
|
2016-02-23 02:13:52 +03:00
|
|
|
const int MAX_DANGER_SPOTS = 8;
|
2016-01-19 14:54:31 +03:00
|
|
|
HidingSpot *dangerSpot[MAX_DANGER_SPOTS];
|
|
|
|
int dangerSpotCount = 0;
|
|
|
|
int dangerIndex = 0;
|
|
|
|
|
|
|
|
const float checkTime = 10.0f;
|
|
|
|
|
2017-10-12 17:50:56 +03:00
|
|
|
for (auto &spotOrder : m_spotEncounter->spotList)
|
2016-01-19 14:54:31 +03:00
|
|
|
{
|
|
|
|
// if we have seen this spot recently, we don't need to look at it
|
2017-10-12 17:50:56 +03:00
|
|
|
if (gpGlobals->time - GetHidingSpotCheckTimestamp(spotOrder.spot) <= checkTime)
|
2016-01-19 14:54:31 +03:00
|
|
|
continue;
|
|
|
|
|
2017-10-12 17:50:56 +03:00
|
|
|
if (spotOrder.t > t)
|
2016-01-19 14:54:31 +03:00
|
|
|
break;
|
|
|
|
|
2017-10-12 17:50:56 +03:00
|
|
|
dangerSpot[dangerIndex++] = spotOrder.spot;
|
2016-01-19 14:54:31 +03:00
|
|
|
if (dangerIndex >= MAX_DANGER_SPOTS)
|
|
|
|
dangerIndex = 0;
|
2017-10-12 17:50:56 +03:00
|
|
|
|
2016-01-19 14:54:31 +03:00
|
|
|
if (dangerSpotCount < MAX_DANGER_SPOTS)
|
2017-10-12 17:50:56 +03:00
|
|
|
dangerSpotCount++;
|
2016-01-19 14:54:31 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
if (dangerSpotCount)
|
|
|
|
{
|
|
|
|
// pick one of the spots at random
|
|
|
|
int which = RANDOM_LONG(0, dangerSpotCount - 1);
|
|
|
|
|
2017-10-12 17:50:56 +03:00
|
|
|
const Vector *checkSpot = dangerSpot[which]->GetPosition();
|
2016-01-19 14:54:31 +03:00
|
|
|
|
|
|
|
Vector pos = *checkSpot;
|
|
|
|
pos.z += HalfHumanHeight;
|
|
|
|
|
|
|
|
// glance at the spot for minimum time
|
|
|
|
SetLookAt("Encounter Spot", &pos, PRIORITY_LOW, 0, true, 10.0f);
|
|
|
|
|
|
|
|
// immediately mark it as "checked", so we don't check it again
|
|
|
|
// if we get distracted before we check it - that's the way it goes
|
|
|
|
SetHidingSpotCheckTimestamp(dangerSpot[which]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2015-09-16 23:19:21 +03:00
|
|
|
}
|
|
|
|
|
2016-01-19 14:54:31 +03:00
|
|
|
// "Bend" our line of sight around corners until we can "see" the point.
|
|
|
|
bool CCSBot::BendLineOfSight(const Vector *eye, const Vector *point, Vector *bend) const
|
2015-09-16 23:19:21 +03:00
|
|
|
{
|
2016-01-19 14:54:31 +03:00
|
|
|
// if we can directly see the point, use it
|
|
|
|
TraceResult result;
|
|
|
|
UTIL_TraceLine(*eye, *point + Vector(0, 0, HalfHumanHeight), ignore_monsters, ENT(pev), &result);
|
|
|
|
|
|
|
|
if (result.flFraction == 1.0f && !result.fStartSolid)
|
|
|
|
{
|
|
|
|
// can directly see point, no bending needed
|
|
|
|
*bend = *point;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
// "bend" our line of sight until we can see the approach point
|
|
|
|
Vector v = *point - *eye;
|
|
|
|
float startAngle = UTIL_VecToYaw(v);
|
|
|
|
float length = v.Length2D();
|
|
|
|
v.NormalizeInPlace();
|
|
|
|
|
|
|
|
float angleInc = 10.0f;
|
|
|
|
for (float angle = angleInc; angle <= 135.0f; angle += angleInc)
|
|
|
|
{
|
|
|
|
// check both sides at this angle offset
|
2017-10-12 17:50:56 +03:00
|
|
|
for (int side = 0; side < 2; side++)
|
2016-01-19 14:54:31 +03:00
|
|
|
{
|
2017-10-12 17:50:56 +03:00
|
|
|
float actualAngle = side ? (startAngle + angle) : (startAngle - angle);
|
2016-01-19 14:54:31 +03:00
|
|
|
|
|
|
|
float dx = BotCOS(actualAngle);
|
|
|
|
float dy = BotSIN(actualAngle);
|
|
|
|
|
|
|
|
// compute rotated point ray endpoint
|
|
|
|
Vector rotPoint(eye->x + length * dx, eye->y + length * dy, point->z);
|
|
|
|
|
|
|
|
TraceResult result;
|
|
|
|
UTIL_TraceLine(*eye, rotPoint + Vector(0, 0, HalfHumanHeight), ignore_monsters, ENT(pev), &result);
|
|
|
|
|
|
|
|
// if this ray started in an obstacle, skip it
|
|
|
|
if (result.fStartSolid)
|
|
|
|
{
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
Vector ray = rotPoint - *eye;
|
|
|
|
float rayLength = ray.NormalizeInPlace();
|
|
|
|
float visibleLength = rayLength * result.flFraction;
|
|
|
|
|
|
|
|
// step along ray, checking if point is visible from ray point
|
|
|
|
const float bendStepSize = 50.0f;
|
|
|
|
for (float bendLength = bendStepSize; bendLength <= visibleLength; bendLength += bendStepSize)
|
|
|
|
{
|
|
|
|
// compute point along ray
|
|
|
|
Vector rayPoint = *eye + bendLength * ray;
|
|
|
|
|
|
|
|
// check if we can see approach point from this bend point
|
|
|
|
UTIL_TraceLine(rayPoint, *point + Vector(0, 0, HalfHumanHeight), ignore_monsters, ENT(pev), &result);
|
|
|
|
|
|
|
|
if (result.flFraction == 1.0f && !result.fStartSolid)
|
|
|
|
{
|
|
|
|
// target is visible from this bend point on the ray - use this point on the ray as our point
|
|
|
|
|
|
|
|
// keep "bent" point at correct height along line of sight
|
|
|
|
if (!GetGroundHeight(&rayPoint, &rayPoint.z))
|
|
|
|
{
|
|
|
|
rayPoint.z = point->z;
|
|
|
|
}
|
|
|
|
|
|
|
|
*bend = rayPoint;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
*bend = *point;
|
|
|
|
|
|
|
|
// bending rays didn't help - still can't see the point
|
|
|
|
return false;
|
2015-06-30 12:46:07 +03:00
|
|
|
}
|
|
|
|
|
2016-02-04 03:18:26 +03:00
|
|
|
CBasePlayer *CCSBot::FindMostDangerousThreat()
|
2015-09-16 23:19:21 +03:00
|
|
|
{
|
2016-01-19 14:54:31 +03:00
|
|
|
// maximum number of simulataneously attendable threats
|
2017-10-12 17:50:56 +03:00
|
|
|
#ifdef REGAMEDLL_FIXES
|
|
|
|
const int MAX_THREATS = MAX_CLIENTS;
|
|
|
|
#else
|
|
|
|
const int MAX_THREATS = 16;
|
|
|
|
#endif
|
|
|
|
|
2016-01-19 14:54:31 +03:00
|
|
|
struct CloseInfo
|
|
|
|
{
|
|
|
|
CBasePlayer *enemy;
|
|
|
|
float range;
|
2017-10-12 17:50:56 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
CloseInfo threat[MAX_THREATS];
|
2016-01-19 14:54:31 +03:00
|
|
|
int threatCount = 0;
|
|
|
|
|
2017-10-12 17:50:56 +03:00
|
|
|
#ifdef REGAMEDLL_ADD
|
|
|
|
int prevIndex = m_enemyQueueIndex - 1;
|
|
|
|
if (prevIndex < 0)
|
|
|
|
prevIndex = MAX_ENEMY_QUEUE - 1;
|
2016-01-19 14:54:31 +03:00
|
|
|
|
2017-10-19 20:12:02 +03:00
|
|
|
CBasePlayer *currentThreat = m_enemyQueue[prevIndex].player;
|
2017-10-12 17:50:56 +03:00
|
|
|
#endif
|
|
|
|
|
|
|
|
m_bomber = nullptr;
|
|
|
|
m_closestVisibleFriend = nullptr;
|
|
|
|
m_closestVisibleHumanFriend = nullptr;
|
2016-01-19 14:54:31 +03:00
|
|
|
|
2017-10-12 17:50:56 +03:00
|
|
|
float closeFriendRange = 99999999999.9f;
|
2016-01-19 14:54:31 +03:00
|
|
|
float closeHumanFriendRange = 99999999999.9f;
|
|
|
|
|
|
|
|
int i;
|
|
|
|
|
|
|
|
{
|
2017-10-12 17:50:56 +03:00
|
|
|
for (i = 1; i <= gpGlobals->maxClients; i++)
|
2016-01-19 14:54:31 +03:00
|
|
|
{
|
2017-11-22 20:27:55 +03:00
|
|
|
CBasePlayer *pPlayer = UTIL_PlayerByIndex(i);
|
2016-01-19 14:54:31 +03:00
|
|
|
|
2017-11-22 20:27:55 +03:00
|
|
|
if (!pPlayer)
|
2016-01-19 14:54:31 +03:00
|
|
|
continue;
|
|
|
|
|
2017-11-22 20:27:55 +03:00
|
|
|
if (FNullEnt(pPlayer->pev))
|
2016-01-19 14:54:31 +03:00
|
|
|
continue;
|
|
|
|
|
|
|
|
// is it a player?
|
2017-11-22 20:27:55 +03:00
|
|
|
if (!pPlayer->IsPlayer())
|
2016-01-19 14:54:31 +03:00
|
|
|
continue;
|
|
|
|
|
|
|
|
// ignore self
|
2017-11-22 20:27:55 +03:00
|
|
|
if (pPlayer->entindex() == entindex())
|
2016-01-19 14:54:31 +03:00
|
|
|
continue;
|
|
|
|
|
|
|
|
// is it alive?
|
2017-11-22 20:27:55 +03:00
|
|
|
if (!pPlayer->IsAlive())
|
2016-01-19 14:54:31 +03:00
|
|
|
continue;
|
|
|
|
|
|
|
|
// is it an enemy?
|
2017-11-22 20:27:55 +03:00
|
|
|
if (BotRelationship(pPlayer) == BOT_TEAMMATE)
|
2016-01-19 14:54:31 +03:00
|
|
|
{
|
|
|
|
TraceResult result;
|
2017-11-22 20:27:55 +03:00
|
|
|
UTIL_TraceLine(GetEyePosition(), pPlayer->pev->origin, ignore_monsters, ignore_glass, edict(), &result);
|
2016-01-19 14:54:31 +03:00
|
|
|
if (result.flFraction == 1.0f)
|
|
|
|
{
|
|
|
|
// update watch timestamp
|
2017-11-22 20:27:55 +03:00
|
|
|
int idx = pPlayer->entindex() - 1;
|
2016-01-19 14:54:31 +03:00
|
|
|
m_watchInfo[idx].timestamp = gpGlobals->time;
|
|
|
|
m_watchInfo[idx].isEnemy = false;
|
|
|
|
|
|
|
|
// keep track of our closest friend
|
2017-11-22 20:27:55 +03:00
|
|
|
Vector to = pev->origin - pPlayer->pev->origin;
|
2016-01-19 14:54:31 +03:00
|
|
|
float rangeSq = to.LengthSquared();
|
|
|
|
if (rangeSq < closeFriendRange)
|
|
|
|
{
|
2017-11-22 20:27:55 +03:00
|
|
|
m_closestVisibleFriend = pPlayer;
|
2016-01-19 14:54:31 +03:00
|
|
|
closeFriendRange = rangeSq;
|
|
|
|
}
|
|
|
|
|
|
|
|
// keep track of our closest human friend
|
2017-11-22 20:27:55 +03:00
|
|
|
if (!pPlayer->IsBot() && rangeSq < closeHumanFriendRange)
|
2016-01-19 14:54:31 +03:00
|
|
|
{
|
2017-11-22 20:27:55 +03:00
|
|
|
m_closestVisibleHumanFriend = pPlayer;
|
2016-01-19 14:54:31 +03:00
|
|
|
closeHumanFriendRange = rangeSq;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
// check if this enemy is fully
|
2017-10-12 17:50:56 +03:00
|
|
|
unsigned char visParts;
|
2017-11-22 20:27:55 +03:00
|
|
|
if (!IsVisible(pPlayer, CHECK_FOV, &visParts))
|
2016-01-19 14:54:31 +03:00
|
|
|
continue;
|
|
|
|
|
2017-10-12 17:50:56 +03:00
|
|
|
#ifdef REGAMEDLL_ADD
|
|
|
|
// do we notice this enemy? (always notice current enemy)
|
2017-11-22 20:27:55 +03:00
|
|
|
if (pPlayer != currentThreat)
|
2017-10-12 17:50:56 +03:00
|
|
|
{
|
2017-11-22 20:27:55 +03:00
|
|
|
if (!IsNoticable(pPlayer, visParts))
|
2017-10-12 17:50:56 +03:00
|
|
|
{
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2016-01-19 14:54:31 +03:00
|
|
|
// update watch timestamp
|
2017-11-22 20:27:55 +03:00
|
|
|
int idx = pPlayer->entindex() - 1;
|
2016-01-19 14:54:31 +03:00
|
|
|
m_watchInfo[idx].timestamp = gpGlobals->time;
|
|
|
|
m_watchInfo[idx].isEnemy = true;
|
|
|
|
|
|
|
|
// note if we see the bomber
|
2017-11-22 20:27:55 +03:00
|
|
|
if (pPlayer->IsBombGuy())
|
2016-01-19 14:54:31 +03:00
|
|
|
{
|
2017-11-22 20:27:55 +03:00
|
|
|
m_bomber = pPlayer;
|
2016-01-19 14:54:31 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
// keep track of all visible threats
|
2017-11-22 20:27:55 +03:00
|
|
|
Vector d = pev->origin - pPlayer->pev->origin;
|
2016-01-19 14:54:31 +03:00
|
|
|
float distSq = d.LengthSquared();
|
|
|
|
|
|
|
|
// maintain set of visible threats, sorted by increasing distance
|
|
|
|
if (threatCount == 0)
|
|
|
|
{
|
2017-11-22 20:27:55 +03:00
|
|
|
threat[0].enemy = pPlayer;
|
2016-01-19 14:54:31 +03:00
|
|
|
threat[0].range = distSq;
|
|
|
|
threatCount = 1;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// find insertion point
|
|
|
|
int j;
|
2017-10-12 17:50:56 +03:00
|
|
|
for (j = 0; j < threatCount; j++)
|
2016-01-19 14:54:31 +03:00
|
|
|
{
|
|
|
|
if (distSq < threat[j].range)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
// shift lower half down a notch
|
2017-11-22 20:27:55 +03:00
|
|
|
for (int k = threatCount - 1; k >= j; k--)
|
2016-01-19 14:54:31 +03:00
|
|
|
threat[k + 1] = threat[k];
|
|
|
|
|
|
|
|
// insert threat into sorted list
|
2017-11-22 20:27:55 +03:00
|
|
|
threat[j].enemy = pPlayer;
|
2016-01-19 14:54:31 +03:00
|
|
|
threat[j].range = distSq;
|
|
|
|
|
|
|
|
if (threatCount < MAX_THREATS)
|
2017-10-12 17:50:56 +03:00
|
|
|
threatCount++;
|
2016-01-19 14:54:31 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
{
|
|
|
|
// track the maximum enemy and friend counts we've seen recently
|
|
|
|
int prevEnemies = m_nearbyEnemyCount;
|
|
|
|
int prevFriends = m_nearbyFriendCount;
|
|
|
|
m_nearbyEnemyCount = 0;
|
|
|
|
m_nearbyFriendCount = 0;
|
|
|
|
|
2017-10-12 17:50:56 +03:00
|
|
|
for (i = 0; i < MAX_CLIENTS; i++)
|
2016-01-19 14:54:31 +03:00
|
|
|
{
|
|
|
|
if (m_watchInfo[i].timestamp <= 0.0f)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
const float recentTime = 3.0f;
|
|
|
|
if (gpGlobals->time - m_watchInfo[i].timestamp < recentTime)
|
|
|
|
{
|
|
|
|
if (m_watchInfo[i].isEnemy)
|
2017-10-12 17:50:56 +03:00
|
|
|
m_nearbyEnemyCount++;
|
2016-01-19 14:54:31 +03:00
|
|
|
else
|
2017-10-12 17:50:56 +03:00
|
|
|
m_nearbyFriendCount++;
|
2016-01-19 14:54:31 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// note when we saw this batch of enemies
|
|
|
|
if (prevEnemies == 0 && m_nearbyEnemyCount > 0)
|
|
|
|
{
|
|
|
|
m_firstSawEnemyTimestamp = gpGlobals->time;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (prevEnemies != m_nearbyEnemyCount || prevFriends != m_nearbyFriendCount)
|
|
|
|
{
|
|
|
|
PrintIfWatched("Nearby friends = %d, enemies = %d\n", m_nearbyFriendCount, m_nearbyEnemyCount);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
{
|
|
|
|
// Track the place where we saw most of our enemies
|
|
|
|
struct PlaceRank
|
|
|
|
{
|
|
|
|
unsigned int place;
|
|
|
|
int count;
|
|
|
|
};
|
2017-10-12 17:50:56 +03:00
|
|
|
static PlaceRank placeRank[MAX_PLACES_PER_MAP];
|
2016-01-19 14:54:31 +03:00
|
|
|
int locCount = 0;
|
|
|
|
|
|
|
|
PlaceRank common;
|
|
|
|
common.place = 0;
|
|
|
|
common.count = 0;
|
|
|
|
|
2017-10-12 17:50:56 +03:00
|
|
|
for (i = 0; i < threatCount; i++)
|
2016-01-19 14:54:31 +03:00
|
|
|
{
|
|
|
|
// find the area the player/bot is standing on
|
|
|
|
CNavArea *area;
|
2017-11-22 20:27:55 +03:00
|
|
|
CCSBot *pBot = static_cast<CCSBot *>(threat[i].enemy);
|
2016-06-14 01:13:13 +03:00
|
|
|
|
2017-11-22 20:27:55 +03:00
|
|
|
if (pBot->IsBot())
|
2016-01-19 14:54:31 +03:00
|
|
|
{
|
2017-11-22 20:27:55 +03:00
|
|
|
area = pBot->GetLastKnownArea();
|
2016-01-19 14:54:31 +03:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
area = TheNavAreaGrid.GetNearestNavArea(&threat[i].enemy->pev->origin);
|
|
|
|
}
|
|
|
|
|
2017-10-12 17:50:56 +03:00
|
|
|
if (!area)
|
2016-01-19 14:54:31 +03:00
|
|
|
continue;
|
|
|
|
|
|
|
|
unsigned int threatLoc = area->GetPlace();
|
|
|
|
if (!threatLoc)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
// if place is already in set, increment count
|
|
|
|
int j;
|
2017-10-12 17:50:56 +03:00
|
|
|
for (j = 0; j < locCount; j++)
|
2016-01-19 14:54:31 +03:00
|
|
|
{
|
|
|
|
if (placeRank[j].place == threatLoc)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (j == locCount)
|
|
|
|
{
|
|
|
|
// new place
|
|
|
|
if (locCount < MAX_PLACES_PER_MAP)
|
|
|
|
{
|
2017-10-12 17:50:56 +03:00
|
|
|
placeRank[locCount].place = threatLoc;
|
|
|
|
placeRank[locCount].count = 1;
|
2016-01-19 14:54:31 +03:00
|
|
|
|
|
|
|
if (common.count == 0)
|
|
|
|
common = placeRank[locCount];
|
|
|
|
|
2017-10-12 17:50:56 +03:00
|
|
|
locCount++;
|
2016-01-19 14:54:31 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// others are in that place, increment
|
2017-10-12 17:50:56 +03:00
|
|
|
placeRank[j].count++;
|
2016-01-19 14:54:31 +03:00
|
|
|
|
|
|
|
// keep track of the most common place
|
|
|
|
if (placeRank[j].count > common.count)
|
|
|
|
common = placeRank[j];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// remember most common place
|
|
|
|
m_enemyPlace = common.place;
|
|
|
|
}
|
|
|
|
|
|
|
|
{
|
|
|
|
if (threatCount == 0)
|
2017-10-12 17:50:56 +03:00
|
|
|
return nullptr;
|
2016-01-19 14:54:31 +03:00
|
|
|
|
|
|
|
int t;
|
2017-10-12 17:50:56 +03:00
|
|
|
|
|
|
|
#ifdef REGAMEDLL_ADD
|
|
|
|
bool sawCloserThreat = false;
|
|
|
|
bool sawCurrentThreat = false;
|
|
|
|
for (t = 0; t < threatCount; t++)
|
|
|
|
{
|
|
|
|
if (threat[t].enemy == currentThreat)
|
|
|
|
{
|
|
|
|
sawCurrentThreat = true;
|
|
|
|
}
|
|
|
|
else if (threat[t].enemy != currentThreat && IsSignificantlyCloser(threat[t].enemy, currentThreat))
|
|
|
|
{
|
|
|
|
sawCloserThreat = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (sawCurrentThreat && !sawCloserThreat)
|
|
|
|
{
|
|
|
|
return currentThreat;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
// otherwise, find the closest threat that without using shield
|
|
|
|
for (t = 0; t < threatCount; t++)
|
2016-01-19 14:54:31 +03:00
|
|
|
{
|
|
|
|
if (!threat[t].enemy->IsProtectedByShield())
|
|
|
|
{
|
|
|
|
return threat[t].enemy;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// return closest threat
|
|
|
|
return threat[0].enemy;
|
2015-06-30 12:46:07 +03:00
|
|
|
}
|
|
|
|
|
2016-01-19 14:54:31 +03:00
|
|
|
// Update our reaction time queue
|
2016-02-04 03:18:26 +03:00
|
|
|
void CCSBot::UpdateReactionQueue()
|
2015-09-16 23:19:21 +03:00
|
|
|
{
|
2016-01-19 14:54:31 +03:00
|
|
|
// zombies dont see any threats
|
|
|
|
if (cv_bot_zombie.value > 0.0f)
|
|
|
|
return;
|
|
|
|
|
|
|
|
// find biggest threat at this instant
|
|
|
|
CBasePlayer *threat = FindMostDangerousThreat();
|
|
|
|
|
|
|
|
int now = m_enemyQueueIndex;
|
|
|
|
|
2017-10-12 17:50:56 +03:00
|
|
|
#ifdef REGAMEDLL_ADD
|
|
|
|
// reset timer
|
|
|
|
m_attentionInterval.Start();
|
|
|
|
#endif
|
|
|
|
|
2016-01-19 14:54:31 +03:00
|
|
|
// store a snapshot of its state at the end of the reaction time queue
|
2017-10-12 17:50:56 +03:00
|
|
|
if (threat)
|
2016-01-19 14:54:31 +03:00
|
|
|
{
|
2017-10-12 17:50:56 +03:00
|
|
|
m_enemyQueue[now].player = threat;
|
|
|
|
m_enemyQueue[now].isReloading = threat->IsReloading();
|
|
|
|
m_enemyQueue[now].isProtectedByShield = threat->IsProtectedByShield();
|
2016-01-19 14:54:31 +03:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2017-10-12 17:50:56 +03:00
|
|
|
m_enemyQueue[now].player = nullptr;
|
|
|
|
m_enemyQueue[now].isReloading = false;
|
|
|
|
m_enemyQueue[now].isProtectedByShield = false;
|
2016-01-19 14:54:31 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
// queue is round-robin
|
2016-02-23 02:13:52 +03:00
|
|
|
if (++m_enemyQueueIndex >= MAX_ENEMY_QUEUE)
|
2016-01-19 14:54:31 +03:00
|
|
|
m_enemyQueueIndex = 0;
|
|
|
|
|
|
|
|
if (m_enemyQueueCount < MAX_ENEMY_QUEUE)
|
2017-10-12 17:50:56 +03:00
|
|
|
m_enemyQueueCount++;
|
2016-01-19 14:54:31 +03:00
|
|
|
|
|
|
|
// clamp reaction time to enemy queue size
|
|
|
|
float reactionTime = GetProfile()->GetReactionTime();
|
|
|
|
float maxReactionTime = (MAX_ENEMY_QUEUE * g_flBotFullThinkInterval) - 0.01f;
|
|
|
|
if (reactionTime > maxReactionTime)
|
|
|
|
reactionTime = maxReactionTime;
|
|
|
|
|
|
|
|
// "rewind" time back to our reaction time
|
2016-02-23 02:13:52 +03:00
|
|
|
int reactionTimeSteps = int((reactionTime / g_flBotFullThinkInterval) + 0.5f);
|
2016-01-19 14:54:31 +03:00
|
|
|
|
|
|
|
int i = now - reactionTimeSteps;
|
|
|
|
if (i < 0)
|
|
|
|
i += MAX_ENEMY_QUEUE;
|
|
|
|
|
2016-02-23 02:13:52 +03:00
|
|
|
m_enemyQueueAttendIndex = byte(i);
|
2015-06-30 12:46:07 +03:00
|
|
|
}
|
|
|
|
|
2016-01-19 14:54:31 +03:00
|
|
|
// Return the most dangerous threat we are "conscious" of
|
2016-02-04 03:18:26 +03:00
|
|
|
CBasePlayer *CCSBot::GetRecognizedEnemy()
|
2015-09-16 23:19:21 +03:00
|
|
|
{
|
|
|
|
if (m_enemyQueueAttendIndex >= m_enemyQueueCount)
|
2017-10-12 17:50:56 +03:00
|
|
|
return nullptr;
|
2015-09-16 23:19:21 +03:00
|
|
|
|
2017-10-12 17:50:56 +03:00
|
|
|
return m_enemyQueue[m_enemyQueueAttendIndex].player;
|
2015-06-30 12:46:07 +03:00
|
|
|
}
|
|
|
|
|
2016-01-19 14:54:31 +03:00
|
|
|
// Return true if the enemy we are "conscious" of is reloading
|
2016-02-04 03:18:26 +03:00
|
|
|
bool CCSBot::IsRecognizedEnemyReloading()
|
2015-09-16 23:19:21 +03:00
|
|
|
{
|
2016-01-19 14:54:31 +03:00
|
|
|
if (m_enemyQueueAttendIndex >= m_enemyQueueCount)
|
|
|
|
return false;
|
|
|
|
|
2017-10-12 17:50:56 +03:00
|
|
|
return m_enemyQueue[m_enemyQueueAttendIndex].isReloading;
|
2015-06-30 12:46:07 +03:00
|
|
|
}
|
2015-09-16 23:19:21 +03:00
|
|
|
|
2016-01-19 14:54:31 +03:00
|
|
|
// Return true if the enemy we are "conscious" of is hiding behind a shield
|
2016-02-04 03:18:26 +03:00
|
|
|
bool CCSBot::IsRecognizedEnemyProtectedByShield()
|
2015-09-16 23:19:21 +03:00
|
|
|
{
|
2016-01-19 14:54:31 +03:00
|
|
|
if (m_enemyQueueAttendIndex >= m_enemyQueueCount)
|
|
|
|
return false;
|
|
|
|
|
2017-10-12 17:50:56 +03:00
|
|
|
return m_enemyQueue[m_enemyQueueAttendIndex].isProtectedByShield;
|
2015-06-30 12:46:07 +03:00
|
|
|
}
|
|
|
|
|
2016-01-19 14:54:31 +03:00
|
|
|
// Return distance to closest enemy we are "conscious" of
|
2016-02-04 03:18:26 +03:00
|
|
|
float CCSBot::GetRangeToNearestRecognizedEnemy()
|
2015-09-16 23:19:21 +03:00
|
|
|
{
|
2017-10-12 17:50:56 +03:00
|
|
|
const CBasePlayer *pEnemy = GetRecognizedEnemy();
|
2016-01-19 14:54:31 +03:00
|
|
|
|
2017-10-12 17:50:56 +03:00
|
|
|
if (pEnemy)
|
2016-01-19 14:54:31 +03:00
|
|
|
{
|
2017-10-12 17:50:56 +03:00
|
|
|
return (pev->origin - pEnemy->pev->origin).Length();
|
2016-01-19 14:54:31 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
return 99999999.9f;
|
2015-06-30 12:46:07 +03:00
|
|
|
}
|
2015-09-16 23:19:21 +03:00
|
|
|
|
2016-01-19 14:54:31 +03:00
|
|
|
// Blind the bot for the given duration
|
2017-07-01 23:40:10 +03:00
|
|
|
void CCSBot::Blind(float duration, float holdTime, float fadeTime, int alpha)
|
2015-09-16 23:19:21 +03:00
|
|
|
{
|
2016-01-19 14:54:31 +03:00
|
|
|
// extend
|
|
|
|
CBasePlayer::Blind(duration, holdTime, fadeTime, alpha);
|
|
|
|
|
|
|
|
PrintIfWatched("I'm blind!\n");
|
|
|
|
|
|
|
|
if (RANDOM_FLOAT(0.0f, 100.0f) < 33.3f)
|
|
|
|
{
|
|
|
|
GetChatter()->Say("Blinded", 1.0f);
|
|
|
|
}
|
|
|
|
|
|
|
|
// decide which way to move while blind
|
|
|
|
m_blindMoveDir = static_cast<NavRelativeDirType>(RANDOM_LONG(1, NUM_RELATIVE_DIRECTIONS - 1));
|
|
|
|
|
|
|
|
// if blinded while in combat - then spray and pray!
|
|
|
|
m_blindFire = (RANDOM_FLOAT(0.0f, 100.0f) < 10.0f) != 0;
|
|
|
|
|
|
|
|
// no longer safe
|
|
|
|
AdjustSafeTime();
|
2015-06-30 12:46:07 +03:00
|
|
|
}
|
2017-10-12 17:50:56 +03:00
|
|
|
|
|
|
|
#ifdef REGAMEDLL_ADD
|
2017-11-22 20:27:55 +03:00
|
|
|
bool CCSBot::IsNoticable(const CBasePlayer *pPlayer, unsigned char visibleParts) const
|
2017-10-12 17:50:56 +03:00
|
|
|
{
|
|
|
|
float deltaT = m_attentionInterval.GetElapsedTime();
|
|
|
|
|
|
|
|
// all chances are specified in terms of a standard "quantum" of time
|
|
|
|
// in which a normal person would notice something
|
|
|
|
const float noticeQuantum = 0.25f;
|
|
|
|
|
|
|
|
// determine percentage of player that is visible
|
|
|
|
float coverRatio = 0.0f;
|
|
|
|
|
|
|
|
if (visibleParts & CHEST)
|
|
|
|
{
|
|
|
|
const float chance = 40.0f;
|
|
|
|
coverRatio += chance;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (visibleParts & HEAD)
|
|
|
|
{
|
|
|
|
const float chance = 10.0f;
|
|
|
|
coverRatio += chance;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (visibleParts & LEFT_SIDE)
|
|
|
|
{
|
|
|
|
const float chance = 20.0f;
|
|
|
|
coverRatio += chance;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (visibleParts & RIGHT_SIDE)
|
|
|
|
{
|
|
|
|
const float chance = 20.0f;
|
|
|
|
coverRatio += chance;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (visibleParts & FEET)
|
|
|
|
{
|
|
|
|
const float chance = 10.0f;
|
|
|
|
coverRatio += chance;
|
|
|
|
}
|
|
|
|
|
|
|
|
// compute range modifier - farther away players are harder to notice, depeding on what they are doing
|
2017-11-22 20:27:55 +03:00
|
|
|
float range = (pPlayer->pev->origin - pev->origin).Length();
|
2017-10-12 17:50:56 +03:00
|
|
|
const float closeRange = 300.0f;
|
|
|
|
const float farRange = 1000.0f;
|
|
|
|
|
|
|
|
float rangeModifier;
|
|
|
|
if (range < closeRange)
|
|
|
|
{
|
|
|
|
rangeModifier = 0.0f;
|
|
|
|
}
|
|
|
|
else if (range > farRange)
|
|
|
|
{
|
|
|
|
rangeModifier = 1.0f;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
rangeModifier = (range - closeRange) / (farRange - closeRange);
|
|
|
|
}
|
|
|
|
|
|
|
|
// harder to notice when crouched
|
2017-11-22 20:27:55 +03:00
|
|
|
bool isCrouching = (pPlayer->pev->flags & FL_DUCKING) == FL_DUCKING;
|
2017-10-12 17:50:56 +03:00
|
|
|
// moving players are easier to spot
|
2017-11-22 20:27:55 +03:00
|
|
|
float playerSpeedSq = pPlayer->pev->velocity.LengthSquared();
|
2017-10-12 17:50:56 +03:00
|
|
|
const float runSpeed = 200.0f;
|
|
|
|
const float walkSpeed = 30.0f;
|
|
|
|
float farChance, closeChance;
|
|
|
|
if (playerSpeedSq > runSpeed * runSpeed)
|
|
|
|
{
|
|
|
|
// running players are always easy to spot (must be standing to run)
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
else if (playerSpeedSq > walkSpeed * walkSpeed)
|
|
|
|
{
|
|
|
|
// walking players are less noticable far away
|
|
|
|
if (isCrouching)
|
|
|
|
{
|
|
|
|
closeChance = 90.0f;
|
|
|
|
farChance = 60.0f;
|
|
|
|
}
|
|
|
|
// standing
|
|
|
|
else
|
|
|
|
{
|
|
|
|
closeChance = 100.0f;
|
|
|
|
farChance = 75.0f;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// motionless players are hard to notice
|
|
|
|
if (isCrouching)
|
|
|
|
{
|
|
|
|
// crouching and motionless - very tough to notice
|
|
|
|
closeChance = 80.0f;
|
|
|
|
farChance = 5.0f; // takes about three seconds to notice (50% chance)
|
|
|
|
}
|
|
|
|
// standing
|
|
|
|
else
|
|
|
|
{
|
|
|
|
closeChance = 100.0f;
|
|
|
|
farChance = 10.0f;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// combine posture, speed, and range chances
|
|
|
|
float dispositionChance = closeChance + (farChance - closeChance) * rangeModifier;
|
|
|
|
|
|
|
|
// determine actual chance of noticing player
|
|
|
|
float noticeChance = dispositionChance * coverRatio/100.0f;
|
|
|
|
|
|
|
|
// scale by skill level
|
|
|
|
noticeChance *= (0.5f + 0.5f * GetProfile()->GetSkill());
|
|
|
|
|
|
|
|
// if we are alert, our chance of noticing is much higher
|
|
|
|
//if (IsAlert())
|
|
|
|
//{
|
|
|
|
// const float alertBonus = 50.0f;
|
|
|
|
// noticeChance += alertBonus;
|
|
|
|
//}
|
|
|
|
|
|
|
|
// scale by time quantum
|
|
|
|
noticeChance *= deltaT / noticeQuantum;
|
|
|
|
|
|
|
|
// there must always be a chance of detecting the enemy
|
|
|
|
const float minChance = 0.1f;
|
|
|
|
if (noticeChance < minChance)
|
|
|
|
{
|
|
|
|
noticeChance = minChance;
|
|
|
|
}
|
|
|
|
|
|
|
|
//PrintIfWatched("Notice chance = %3.2f\n", noticeChance);
|
|
|
|
return (RANDOM_FLOAT(0.0f, 100.0f) < noticeChance);
|
|
|
|
}
|
|
|
|
#endif
|