Merge remote-tracking branch 'origin/master'

This commit is contained in:
TotallyNotElite 2018-11-01 15:46:28 +01:00
commit 29fe4c588e
3 changed files with 34 additions and 11 deletions

View File

@ -15,6 +15,7 @@ CachedEntity *nearestAmmo();
std::pair<CachedEntity *, int> nearestEnemy(); std::pair<CachedEntity *, int> nearestEnemy();
CachedEntity *nearestTeleporter(); CachedEntity *nearestTeleporter();
Vector GetClosestValidByDist(CachedEntity *ent, int idx, float mindist, float maxdist, bool near); Vector GetClosestValidByDist(CachedEntity *ent, int idx, float mindist, float maxdist, bool near);
CNavArea *GetNavArea(Vector loc);
void UpdateSlot(); void UpdateSlot();
void Jump(); void Jump();

View File

@ -35,6 +35,7 @@ static Timer teleporter_cooldown{};
static Timer teleporter_find_cooldown{}; static Timer teleporter_find_cooldown{};
static Timer nav_timeout{}; static Timer nav_timeout{};
static Timer stay_near_timeout{}; static Timer stay_near_timeout{};
static Timer near_nav_timer{};
// Vectors // Vectors
static std::vector<Vector *> default_spots{}; static std::vector<Vector *> default_spots{};
@ -106,7 +107,7 @@ static HookedFunction
if (CE_BAD(LOCAL_E) || !LOCAL_E->m_bAlivePlayer()) if (CE_BAD(LOCAL_E) || !LOCAL_E->m_bAlivePlayer())
return; return;
// Health and ammo have highest priority, but the stay near priorities has to be this high to override anything else // Health and ammo have highest priority, but the stay near priorities has to be this high to override anything else
if (nav::curr_priority == 1337 && (HasLowAmmo() || HasLowHealth())) if (nav::curr_priority == 1337 && ((HasLowAmmo() && *path_ammo) || (HasLowHealth() && *path_health)))
nav::clearInstructions(); nav::clearInstructions();
// Get health if low // Get health if low
@ -139,15 +140,15 @@ static HookedFunction
} }
// If Zoning enabled then zone enemy // If Zoning enabled then zone enemy
if (stay_near && nav_to_nearest_enemy_cooldown.test_and_set(100) && !*spy_mode) if (stay_near && nav_to_nearest_enemy_cooldown.test_and_set(*spy_mode ? 100 : 1000) && !*spy_mode)
NavToNearestEnemy(); NavToNearestEnemy();
// Prevent path spam on sniper bots // Prevent path spam on sniper bots
if (CanPath()) if (CanPath())
{ {
if (sniper_mode) if (*sniper_mode)
NavToSniperSpot(5); NavToSniperSpot(5);
else if ((*heavy_mode || scout_mode) && nav_to_nearest_enemy_cooldown.test_and_set(100)) else if ((*heavy_mode || scout_mode) && nav_to_nearest_enemy_cooldown.test_and_set(*spy_mode ? 100 : 1000))
{ {
if (!NavToNearestEnemy() && non_sniper_sniper_nav_cooldown.test_and_set(10000)) if (!NavToNearestEnemy() && non_sniper_sniper_nav_cooldown.test_and_set(10000))
NavToSniperSpot(5); NavToSniperSpot(5);
@ -290,10 +291,10 @@ std::pair<CachedEntity *, int> nearestEnemy()
else else
{ {
CachedEntity *ent = ENTITY(last_target); CachedEntity *ent = ENTITY(last_target);
if ((CE_GOOD(ent) && ent->m_bAlivePlayer()) && (!ent->m_bEnemy() || if (((CE_GOOD(ent) && ent->m_bAlivePlayer()) && (!ent->m_bEnemy() ||
ent == LOCAL_E || ent == LOCAL_E ||
player_tools::shouldTarget(ent) != player_tools::shouldTarget(ent) !=
player_tools::IgnoreReason::DO_NOT_IGNORE)) player_tools::IgnoreReason::DO_NOT_IGNORE)) || (CE_GOOD(ent) && !ent->m_bAlivePlayer()))
{ {
last_target = -1; last_target = -1;
return {nullptr, last_target}; return {nullptr, last_target};
@ -429,6 +430,21 @@ CachedEntity *nearestTeleporter()
// Wtf Call the police // Wtf Call the police
return nullptr; return nullptr;
} }
CNavArea *GetNavArea(Vector loc)
{
float best_scr = FLT_MAX;
CNavArea *to_ret = nullptr;
for (auto &i : nav::navfile->m_areas)
{
float score = i.m_center.DistTo(loc);
if (score < best_scr)
{
best_scr = score;
to_ret = &i;
}
}
return to_ret;
}
// Navigation // Navigation
bool NavToSniperSpot(int priority) bool NavToSniperSpot(int priority)
@ -509,31 +525,35 @@ bool NavToSniperSpot(int priority)
} }
bool CanNavToNearestEnemy() bool CanNavToNearestEnemy()
{ {
if (HasLowAmmo() || HasLowHealth()) if (HasLowAmmo() || HasLowHealth() || near_nav_timer.test_and_set(*spy_mode ? 100 : 1000))
return false; return false;
return true; return true;
} }
bool NavToNearestEnemy() bool NavToNearestEnemy()
{ {
if (!CanNavToNearestEnemy())
return false;
std::pair<CachedEntity *, int> enemy_pair{nullptr, -1}; std::pair<CachedEntity *, int> enemy_pair{nullptr, -1};
enemy_pair = nearestEnemy(); enemy_pair = nearestEnemy();
CachedEntity *ent = enemy_pair.first; CachedEntity *ent = enemy_pair.first;
int ent_idx = enemy_pair.second; int ent_idx = enemy_pair.second;
if (CE_BAD(ent) && ent_idx == -1) if ((CE_BAD(ent) && ent_idx == -1) || (CE_GOOD(ent) && !ent->m_bAlivePlayer()))
return false; return false;
if (nav::curr_priority == 6 || nav::curr_priority == 7 || nav::curr_priority == 4) if (nav::curr_priority == 6 || nav::curr_priority == 7 || nav::curr_priority == 4)
return false; return false;
float min_dist = 800.0f; float min_dist = 800.0f;
float max_dist = 4000.0f; float max_dist = 4000.0f;
bool stay_near = *sniper_mode ? false : true; bool near = *sniper_mode ? false : true;
if (*heavy_mode || *scout_mode) if (*heavy_mode || *scout_mode)
{ {
min_dist = 100.0f; min_dist = 100.0f;
max_dist = 1000.0f; max_dist = 1000.0f;
} }
Vector to_nav = GetClosestValidByDist(ent, ent_idx, min_dist, max_dist, stay_near); Vector to_nav = GetClosestValidByDist(ent, ent_idx, min_dist, max_dist, near);
if (to_nav.z) if (to_nav.z)
return nav::navTo(to_nav, 1337, false, false); return nav::navTo(to_nav, 1337, false, false);
else if (CE_GOOD(ent) && ent->m_bAlivePlayer() && nav::isSafe(GetNavArea(ent->m_vecOrigin())))
return nav::navTo(ent->m_vecOrigin(), 1337, false, false);
return false; return false;
} }

View File

@ -695,6 +695,8 @@ static CatCommand nav_init("nav_init", "Debug nav init", []() {
static CatCommand nav_path("nav_path", "Debug nav path", []() { navTo(loc); }); static CatCommand nav_path("nav_path", "Debug nav path", []() { navTo(loc); });
static CatCommand nav_path_no_local("nav_path_no_local", "Debug nav path", []() { navTo(loc, 5, false, false); });
static CatCommand nav_reset_ignores("nav_reset_ignores", "Reset all ignores.", static CatCommand nav_reset_ignores("nav_reset_ignores", "Reset all ignores.",
[]() { ignoremanager::reset(); }); []() { ignoremanager::reset(); });