nav: minor change in ladder use.
aim: slight improvement in enemy prediction node recruitment.
This commit is contained in:
parent
d1d379d266
commit
1d60f19402
16 changed files with 151 additions and 145 deletions
|
|
@ -97,7 +97,6 @@ void Bot::avoidGrenades () {
|
|||
auto model = pent->v.model.str (9);
|
||||
|
||||
if (m_preventFlashing < game.time ()
|
||||
&& m_personality == Personality::Rusher
|
||||
&& cv_whose_your_daddy
|
||||
&& model == kFlashbangModelName) {
|
||||
|
||||
|
|
@ -209,15 +208,15 @@ void Bot::checkBreakablesAround () {
|
|||
}
|
||||
|
||||
const auto &origin = game.getEntityOrigin (breakable);
|
||||
const auto lengthToObstacleSq = origin.distanceSq (pev->origin);
|
||||
const auto distanceToObstacleSq = origin.distanceSq (pev->origin);
|
||||
|
||||
// too far, skip it
|
||||
if (lengthToObstacleSq > cr::sqrf (radius)) {
|
||||
if (distanceToObstacleSq > cr::sqrf (radius)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
// too close, skip it
|
||||
if (lengthToObstacleSq < cr::sqrf (100.0f)) {
|
||||
if (distanceToObstacleSq < cr::sqrf (100.0f)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
|
|
@ -343,7 +342,7 @@ void Bot::updatePickups () {
|
|||
}
|
||||
|
||||
const auto &interesting = bots.getInterestingEntities ();
|
||||
const float radius = cr::sqrf (cv_object_pickup_radius.as <float> ());
|
||||
const float radiusSq = cr::sqrf (cv_object_pickup_radius.as <float> ());
|
||||
|
||||
if (!game.isNullEntity (m_pickupItem)) {
|
||||
bool itemExists = false;
|
||||
|
|
@ -358,7 +357,7 @@ void Bot::updatePickups () {
|
|||
const Vector &origin = game.getEntityOrigin (ent);
|
||||
|
||||
// too far from us ?
|
||||
if (pev->origin.distanceSq (origin) > radius) {
|
||||
if (pev->origin.distanceSq (origin) > radiusSq) {
|
||||
continue;
|
||||
}
|
||||
|
||||
|
|
@ -397,7 +396,7 @@ void Bot::updatePickups () {
|
|||
}
|
||||
|
||||
// too far from us ?
|
||||
if (pev->origin.distanceSq (origin) > radius) {
|
||||
if (pev->origin.distanceSq (origin) > radiusSq) {
|
||||
continue;
|
||||
}
|
||||
|
||||
|
|
@ -1705,6 +1704,7 @@ void Bot::overrideConditions () {
|
|||
// special handling for sniping
|
||||
if (usesSniper () && (m_states & (Sense::SeeingEnemy | Sense::SuspectEnemy))
|
||||
&& m_shootTime - 0.4f <= game.time ()
|
||||
&& m_shootTime + 0.1f > game.time ()
|
||||
&& m_sniperStopTime > game.time ()) {
|
||||
|
||||
ignoreCollision ();
|
||||
|
|
@ -1751,7 +1751,7 @@ void Bot::syncUpdatePredictedIndex () {
|
|||
}
|
||||
ScopedUnlock <Mutex> unlock (m_predictLock);
|
||||
|
||||
const auto lastEnemyOrigin = m_lastEnemyOrigin;
|
||||
const auto &lastEnemyOrigin = m_lastEnemyOrigin;
|
||||
const auto currentNodeIndex = m_currentNodeIndex;
|
||||
const auto &botOrigin = pev->origin;
|
||||
|
||||
|
|
@ -1760,8 +1760,8 @@ void Bot::syncUpdatePredictedIndex () {
|
|||
return;
|
||||
}
|
||||
|
||||
int destIndex = graph.getNearest (lastEnemyOrigin);
|
||||
int bestIndex = kInvalidNodeIndex;
|
||||
const int destIndex = graph.getNearest (lastEnemyOrigin);
|
||||
int bestIndex = m_currentNodeIndex;
|
||||
|
||||
if (destIndex == kInvalidNodeIndex) {
|
||||
wipePredict ();
|
||||
|
|
@ -1769,7 +1769,7 @@ void Bot::syncUpdatePredictedIndex () {
|
|||
}
|
||||
int pathLength = 0;
|
||||
|
||||
auto result = planner.find (destIndex, currentNodeIndex, [&] (int index) {
|
||||
planner.find (destIndex, currentNodeIndex, [&] (int index) {
|
||||
++pathLength;
|
||||
|
||||
if (vistab.visible (currentNodeIndex, index) && botOrigin.distanceSq (graph[index].origin) < cr::sqrf (2048.0f)) {
|
||||
|
|
@ -1779,13 +1779,12 @@ void Bot::syncUpdatePredictedIndex () {
|
|||
return true;
|
||||
});
|
||||
|
||||
if (result && bestIndex != kInvalidNodeIndex) {
|
||||
if (bestIndex != currentNodeIndex) {
|
||||
m_lastPredictIndex = bestIndex;
|
||||
m_lastPredictLength = pathLength;
|
||||
|
||||
return;
|
||||
}
|
||||
wipePredict ();
|
||||
}
|
||||
|
||||
void Bot::updatePredictedIndex () {
|
||||
|
|
@ -1947,7 +1946,7 @@ void Bot::setConditions () {
|
|||
if (!m_lastEnemyOrigin.empty ()) {
|
||||
const auto distanceSq = pev->origin.distanceSq (m_lastEnemyOrigin);
|
||||
|
||||
if (distanceSq > cr::sqrf (2048.0f) || (game.isNullEntity (m_enemy) && m_seeEnemyTime + 10.0f < game.time ())) {
|
||||
if (distanceSq >= cr::sqrf (2048.0f) || (game.isNullEntity (m_enemy) && m_seeEnemyTime + 10.0f < game.time ())) {
|
||||
m_lastEnemyOrigin.clear ();
|
||||
m_lastEnemy = nullptr;
|
||||
|
||||
|
|
@ -2057,9 +2056,6 @@ void Bot::filterTasks () {
|
|||
else if (m_isVIP || m_isReloading || (sniping && usesSniper ())) {
|
||||
ratio *= 3.0f; // triple the seek cover desire if bot is VIP or reloading
|
||||
}
|
||||
else if (m_lastEnemyOrigin.distanceSq2d (pev->origin) < cr::sqrf (256.0f)) {
|
||||
ratio *= 3.0f;
|
||||
}
|
||||
else if (game.is (GameFlags::CSDM)) {
|
||||
ratio = 0.0f;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1433,7 +1433,7 @@ void Bot::attackMovement () {
|
|||
if ((m_states & Sense::SeeingEnemy)
|
||||
&& approach < 30
|
||||
&& !bots.isBombPlanted ()
|
||||
&& (isInViewCone (m_enemy->v.origin) || m_isVIP)) {
|
||||
&& (isInViewCone (m_enemy->v.origin) || m_isVIP || m_isReloading)) {
|
||||
|
||||
if (m_retreatTime < game.time ()) {
|
||||
startTask (Task::SeekCover, TaskPri::SeekCover, kInvalidNodeIndex, 0.0f, true);
|
||||
|
|
@ -1453,7 +1453,10 @@ void Bot::attackMovement () {
|
|||
const bool isFullView = !!(m_enemyParts & (Visibility::Head | Visibility::Body));
|
||||
|
||||
if (m_lastFightStyleCheck < game.time ()) {
|
||||
if (usesSniper ()) {
|
||||
if (usesSniper ()
|
||||
&& m_shootTime - 0.4f <= game.time ()
|
||||
&& m_shootTime + 0.1f > game.time ()
|
||||
&& m_sniperStopTime > game.time ()) {
|
||||
m_fightStyle = Fight::Stay;
|
||||
}
|
||||
else if (usesRifle () || usesSubmachine () || usesHeavy ()) {
|
||||
|
|
|
|||
|
|
@ -1518,6 +1518,8 @@ void Bot::newRound () {
|
|||
m_trackingEdict = nullptr;
|
||||
m_enemyBodyPartSet = nullptr;
|
||||
m_timeNextTracking = 0.0f;
|
||||
m_lastPredictIndex = kInvalidNodeIndex;
|
||||
m_lastPredictLength = kInfiniteDistanceLong;
|
||||
|
||||
m_buttonPushTime = 0.0f;
|
||||
m_enemyUpdateTime = 0.0f;
|
||||
|
|
|
|||
|
|
@ -573,8 +573,14 @@ void Bot::checkTerrain (float movedDistance, const Vector &dirNormal) {
|
|||
}
|
||||
// not stuck yet
|
||||
else {
|
||||
bool isOnLadderPath = false;
|
||||
|
||||
if ((m_pathFlags & NodeFlag::Ladder) && isPreviousLadder ()) {
|
||||
isOnLadderPath = true;
|
||||
}
|
||||
|
||||
// test if there's something ahead blocking the way
|
||||
if (!isOnLadderPath () && !isOnLadder () && isBlockedForward (dirNormal, &tr)) {
|
||||
if (!isOnLadderPath && !isOnLadder () && isBlockedForward (dirNormal, &tr)) {
|
||||
if (cr::fzero (m_firstCollideTime)) {
|
||||
m_firstCollideTime = game.time () + 0.2f;
|
||||
}
|
||||
|
|
@ -874,10 +880,10 @@ void Bot::checkFall () {
|
|||
else if (pev->origin.z + 128.0f < m_checkFallPoint[1].z && pev->origin.z + 128.0f < m_checkFallPoint[0].z) {
|
||||
fixFall = true;
|
||||
}
|
||||
else if (m_currentNodeIndex != kInvalidNodeIndex) {
|
||||
if (pev->origin.distanceSq (m_checkFallPoint[1]) <= cr::sqrf (32.0f) && pev->origin.z + 64.0f < m_checkFallPoint[1].z) {
|
||||
fixFall = true;
|
||||
}
|
||||
else if (m_currentNodeIndex != kInvalidNodeIndex
|
||||
&& nowDistanceSq <= cr::sqrf (32.0f)
|
||||
&& pev->origin.z + 64.0f < m_checkFallPoint[1].z) {
|
||||
fixFall = true;
|
||||
}
|
||||
|
||||
if (fixFall) {
|
||||
|
|
@ -1052,27 +1058,15 @@ bool Bot::updateNavigation () {
|
|||
const auto prevNodeIndex = m_previousNodes[0];
|
||||
const float ladderDistance = pev->origin.distance (m_pathOrigin);
|
||||
|
||||
if (graph.exists (prevNodeIndex) && !(graph[prevNodeIndex].flags & NodeFlag::Ladder)) {
|
||||
// do a precise movement when very near
|
||||
if (graph.exists (prevNodeIndex) && !(graph[prevNodeIndex].flags & NodeFlag::Ladder) && ladderDistance < 64.0f) {
|
||||
if (m_pathOrigin.z >= pev->origin.z + 16.0f) {
|
||||
m_pathOrigin = m_path->origin + kLadderOffset;
|
||||
}
|
||||
else if (m_pathOrigin.z < pev->origin.z - 16.0f) {
|
||||
m_pathOrigin = m_path->origin - kLadderOffset;
|
||||
}
|
||||
}
|
||||
else if (m_pathOrigin.z < pev->origin.z + 16.0f && !isOnLadder () && isOnFloor () && !isDucking ()) {
|
||||
m_moveSpeed = ladderDistance;
|
||||
|
||||
if (m_moveSpeed < 150.0f) {
|
||||
m_moveSpeed = 150.0f;
|
||||
}
|
||||
else if (m_moveSpeed > pev->maxspeed) {
|
||||
m_moveSpeed = pev->maxspeed;
|
||||
}
|
||||
}
|
||||
|
||||
// do a precise movement when very near
|
||||
if (graph.exists (prevNodeIndex) && !(graph[prevNodeIndex].flags & NodeFlag::Ladder) && ladderDistance < 64.0f) {
|
||||
if (!isDucking ()) {
|
||||
m_moveSpeed = pev->maxspeed * 0.4f;
|
||||
}
|
||||
|
|
@ -1084,36 +1078,41 @@ bool Bot::updateNavigation () {
|
|||
m_approachingLadderTimer.start (m_frameInterval * 4.0f);
|
||||
}
|
||||
|
||||
if (m_pathOrigin.z < pev->origin.z + 16.0f && !isOnLadder () && isOnFloor () && !isDucking ()) {
|
||||
m_moveSpeed = ladderDistance;
|
||||
|
||||
if (m_moveSpeed < 150.0f) {
|
||||
m_moveSpeed = 150.0f;
|
||||
}
|
||||
else if (m_moveSpeed > pev->maxspeed) {
|
||||
m_moveSpeed = pev->maxspeed;
|
||||
}
|
||||
}
|
||||
|
||||
// special detection if someone is using the ladder (to prevent to have bots-towers on ladders)
|
||||
for (const auto &client : util.getClients ()) {
|
||||
if (!(client.flags & ClientFlags::Used)
|
||||
|| !(client.flags & ClientFlags::Alive)
|
||||
|| client.team != m_team
|
||||
|| client.ent == ent ()) {
|
||||
|| client.ent == ent ()
|
||||
|| !(client.ent->v.movetype == MOVETYPE_FLY)) {
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
if (client.ent->v.origin.distanceSq (m_pathOrigin) > cr::sqrf (64.0f)) {
|
||||
continue;
|
||||
}
|
||||
bool foundGround = false;
|
||||
int previousNode = 0;
|
||||
|
||||
// someone is above or below us and is using the ladder already
|
||||
if (cr::abs (pev->origin.z - client.ent->v.origin.z) > 15.0f && (client.ent->v.movetype == MOVETYPE_FLY)) {
|
||||
const auto numPreviousNode = rg (0, 2);
|
||||
|
||||
for (int i = 0; i < numPreviousNode; ++i) {
|
||||
if (graph.exists (prevNodeIndex) && (graph[prevNodeIndex].flags & NodeFlag::Ladder)) {
|
||||
if (cr::abs (pev->origin.z - client.ent->v.origin.z) > 15.0f) {
|
||||
if (isPreviousLadder ()) {
|
||||
if (client.ent->v.origin.distanceSq (pev->origin) < cr::sqrf (64.0f)) {
|
||||
foundGround = true;
|
||||
previousNode = m_previousNodes[i];
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (foundGround) {
|
||||
findPath (m_previousNodes[0], previousNode, m_pathType);
|
||||
}
|
||||
}
|
||||
|
||||
if (foundGround) {
|
||||
clearSearchNodes ();
|
||||
findNextBestNode ();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -2345,6 +2344,11 @@ bool Bot::selectBestNextNode () {
|
|||
continue;
|
||||
}
|
||||
|
||||
// skip isn't visible links
|
||||
if (!vistab.visible (link.index, nextNodeIndex) || !vistab.visible (link.index, prevNodeIndex)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
// don't use ladder nodes as alternative
|
||||
if (graph[link.index].flags & (NodeFlag::Ladder | NodeFlag::Camp | PathFlag::Jump)) {
|
||||
continue;
|
||||
|
|
@ -3298,13 +3302,11 @@ bool Bot::isReachableNode (int index) {
|
|||
return tr.flFraction >= 1.0f;
|
||||
}
|
||||
|
||||
bool Bot::isOnLadderPath () {
|
||||
bool Bot::isPreviousLadder () {
|
||||
const auto prevNodeIndex = m_previousNodes[0];
|
||||
|
||||
// bot entered ladder path
|
||||
return (m_pathFlags & NodeFlag::Ladder)
|
||||
&& graph.exists (prevNodeIndex)
|
||||
&& (graph[prevNodeIndex].flags & NodeFlag::Ladder);
|
||||
return graph.exists (prevNodeIndex) && (graph[prevNodeIndex].flags & NodeFlag::Ladder);
|
||||
}
|
||||
|
||||
void Bot::findShortestPath (int srcIndex, int destIndex) {
|
||||
|
|
|
|||
|
|
@ -1398,7 +1398,10 @@ void Bot::escapeFromBomb_ () {
|
|||
pev->button |= IN_ATTACK2;
|
||||
}
|
||||
|
||||
if (!usesKnife () && m_numEnemiesLeft == 0) {
|
||||
if (!usesKnife ()
|
||||
&& m_lastEnemyOrigin.empty ()
|
||||
&& !(m_states & Sense::SeeingEnemy)
|
||||
&& !util.isAlive (m_lastEnemy)) {
|
||||
selectWeaponById (Weapon::Knife);
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue