nav: do not switch back to primary weapon, if escaping from bomb

revert: some of thread-workers stuff done previous commits due to stability issues
This commit is contained in:
jeefo 2023-07-02 19:25:18 +03:00
commit bb6117feb0
No known key found for this signature in database
GPG key ID: 927BCA0779BEA8ED
6 changed files with 36 additions and 46 deletions

View file

@ -1623,12 +1623,17 @@ void Bot::overrideConditions () {
}
}
void Bot::updatePredictedIndex () {
void Bot::syncUpdatePredictedIndex () {
auto wipePredict = [this] () {
m_lastPredictIndex = kInvalidNodeIndex;
m_lastPredictLength = kInfiniteDistanceLong;
};
if (!m_predictLock.tryLock ()) {
return; // allow only single instance of search per-bot
}
ScopedUnlock <Mutex> unlock (m_predictLock);
const auto lastEnemyOrigin = m_lastEnemyOrigin;
const auto currentNodeIndex = m_currentNodeIndex;
const auto &botOrigin = pev->origin;
@ -1666,6 +1671,16 @@ void Bot::updatePredictedIndex () {
wipePredict ();
}
void Bot::updatePredictedIndex () {
if (m_lastEnemyOrigin.empty ()) {
return; // do not run task if no last enemy
}
worker.enqueue ([this] () {
syncUpdatePredictedIndex ();
});
}
void Bot::refreshEnemyPredict () {
if (game.isNullEntity (m_enemy) && !game.isNullEntity (m_lastEnemy) && !m_lastEnemyOrigin.empty ()) {
const auto distanceToLastEnemySq = m_lastEnemyOrigin.distanceSq (pev->origin);
@ -1679,6 +1694,10 @@ void Bot::refreshEnemyPredict () {
m_aimFlags |= AimFlags::LastEnemy;
}
}
if (m_aimFlags & AimFlags::PredictPath) {
updatePredictedIndex ();
}
}
void Bot::setConditions () {
@ -3222,7 +3241,10 @@ void Bot::takeDamage (edict_t *inflictor, int damage, int armor, int bits) {
// other player.
m_lastDamageType = bits;
updatePracticeValue (damage);
if (!game.is (GameFlags::CSDM)) {
updatePracticeValue (damage);
}
if (util.isPlayer (inflictor) || (cv_attack_monsters.bool_ () && util.isMonster (inflictor))) {
if (!util.isMonster (inflictor) && cv_tkpunish.bool_ () && game.getTeam (inflictor) == m_team && !util.isFakeClient (inflictor)) {

View file

@ -295,9 +295,6 @@ void BotManager::frame () {
for (const auto &bot : m_bots) {
bot->frame ();
}
// run prediction for bots
updateBotsPredict ();
}
void BotManager::addbot (StringRef name, int difficulty, int personality, int team, int skin, bool manual) {
@ -765,30 +762,6 @@ void BotManager::checkBotModel (edict_t *ent, char *infobuffer) {
}
}
void BotManager::syncUpdateBotsPredict () {
if (m_predictUpdateTime > game.time ()) {
return;
}
// update predicted index for all the bots
for (const auto &bot : m_bots) {
if (!bot.get ()) {
continue;
}
if (bot->m_notKilled && (bot->m_aimFlags & AimFlags::PredictPath)) {
bot->updatePredictedIndex ();
}
}
m_predictUpdateTime = game.time () + 0.1f;
}
void BotManager::updateBotsPredict () {
// push update predict task for all bots to queue
worker.enqueue ([this] {
syncUpdateBotsPredict ();
});
}
void BotManager::setWeaponMode (int selection) {
// this function sets bots weapon mode
@ -1999,7 +1972,6 @@ void BotManager::initRound () {
m_timeBombPlanted = 0.0f;
m_plantSearchUpdateTime = 0.0f;
m_autoKillCheckTime = 0.0f;
m_predictUpdateTime = 0.0f;
m_botsCanPause = false;
resetFilters ();

View file

@ -901,7 +901,7 @@ bool Bot::updateNavigation () {
// pressing the jump button gives the illusion of the bot actual jumping.
if (isOnFloor () || isOnLadder ()) {
if (m_desiredVelocity.length2d () > 0.0f) {
pev->velocity = m_desiredVelocity;
pev->velocity = m_desiredVelocity + m_desiredVelocity * m_frameInterval;
}
else {
auto feet = pev->origin + pev->mins;
@ -943,7 +943,7 @@ bool Bot::updateNavigation () {
}
}
}
else if (!cv_jasonmode.bool_ () && usesKnife () && isOnFloor ()) {
else if (!cv_jasonmode.bool_ () && usesKnife () && isOnFloor () && getCurrentTaskId () != Task::EscapeFromBomb) {
selectBestWeapon ();
}
}

View file

@ -7,7 +7,7 @@
#include <yapb.h>
ConVar cv_max_nodes_for_predict ("yb_max_nodes_for_predict", "20", "Maximum number for path length, to predict the enemy.", true, 15.0f, 256.0f);
ConVar cv_max_nodes_for_predict ("yb_max_nodes_for_predict", "25", "Maximum number for path length, to predict the enemy.", true, 15.0f, 256.0f);
// game console variables
ConVar mp_flashlight ("mp_flashlight", nullptr, Var::GameRef);
@ -19,12 +19,12 @@ float Bot::isInFOV (const Vector &destination) {
// return the absolute value of angle to destination entity
// zero degrees means straight ahead, 45 degrees to the left or
// 45 degrees to the right is the limit of the normal view angle
float absoluteAngle = cr::abs (viewAngle - entityAngle);
const float absAngle = cr::abs (viewAngle - entityAngle);
if (absoluteAngle > 180.0f) {
absoluteAngle = 360.0f - absoluteAngle;
if (absAngle > 180.0f) {
return 360.0f - absAngle;
}
return absoluteAngle;
return absAngle;
}
bool Bot::isInViewCone (const Vector &origin) {
@ -142,18 +142,15 @@ void Bot::updateAimDir () {
int predictNode = m_lastPredictIndex;
auto isPredictedIndexApplicable = [&] () -> bool {
if (predictNode != kInvalidNodeIndex) {
if (!vistab.visible (m_currentNodeIndex, predictNode) || !vistab.visible (m_previousNodes[0], predictNode)) {
predictNode = kInvalidNodeIndex;
pathLength = kInfiniteDistanceLong;
}
if (!vistab.visible (m_currentNodeIndex, predictNode) || !vistab.visible (m_previousNodes[0], predictNode)) {
predictNode = kInvalidNodeIndex;
}
return predictNode != kInvalidNodeIndex && pathLength < cv_max_nodes_for_predict.int_ ();
};
if (changePredictedEnemy) {
if (isPredictedIndexApplicable ()) {
m_lookAtPredict = graph[predictNode].origin;
m_lookAtPredict = graph[m_lastPredictIndex].origin;
m_timeNextTracking = game.time () + rg.get (0.5f, 1.0f);
m_trackingEdict = m_lastEnemy;