NavBot fixes!

This commit is contained in:
LightCat 2018-08-20 15:53:38 +02:00
parent 9cb761abbe
commit e8f9133764
3 changed files with 52 additions and 26 deletions

View File

@ -1,6 +1,7 @@
//
// Created by bencat07 on 17.08.18.
//
#include <hacks/Backtrack.hpp>
#include "common.hpp"
#include "navparser.hpp"
#include "FollowBot.hpp"
@ -120,12 +121,13 @@ CachedEntity *nearestAmmo()
}
return bestent;
}
int last_tar = -1;
CachedEntity *NearestEnemy()
{
if (last_tar == -1 || nav::ReadyForCommands) {
float bestscr = FLT_MAX;
CachedEntity *bestent = nullptr;
for (int i = 0; i < g_IEngine->GetMaxClients(); i++)
{
for (int i = 0; i < g_IEngine->GetMaxClients(); i++) {
CachedEntity *ent = ENTITY(i);
if (CE_BAD(ent) || ent->m_Type() != ENTITY_PLAYER)
continue;
@ -137,14 +139,21 @@ CachedEntity *NearestEnemy()
scr *= 5.0f;
if (g_pPlayerResource->GetClass(ent) == tf_pyro)
scr *= 7.0f;
if (scr < bestscr)
{
if (scr < bestscr) {
bestscr = scr;
bestent = ent;
}
}
if (!bestent)
last_tar = -1;
else
last_tar = bestent->m_IDX;
return bestent;
}
if (CE_GOOD(ENTITY(last_tar)))
return ENTITY(last_tar);
return nullptr;
}
Timer cdr{};
Timer cd2{};
Timer cd3{};
@ -215,6 +224,8 @@ void CreateMove()
nav::NavTo(ammo->m_vecOrigin(), true, true, 6);
}
}
if ((!HasLowHealth() && nav::priority == 7) || (!HasLowAmmo() && nav::priority == 6))
nav::clearInstructions();
if (enable)
{
if (!nav::ReadyForCommands && !spy_mode && !heavy_mode)
@ -236,10 +247,10 @@ void CreateMove()
if (random_spot.z)
nav::NavTo(random_spot, true, true);
}
else if (cdr.check(5000))
else
{
CachedEntity *tar = NearestEnemy();
if (CE_BAD(tar))
if (CE_BAD(tar) && last_tar == -1 && nav::ReadyForCommands)
{
Vector random_spot;
if (cd2.test_and_set(5000))
@ -252,7 +263,21 @@ void CreateMove()
nav::NavTo(random_spot, false);
return;
}
if (CE_GOOD(tar))
{
if (!spy_mode || !hacks::shared::backtrack::isBacktrackEnabled)
nav::NavTo(tar->m_vecOrigin(), false);
else
{
for (auto i : hacks::shared::backtrack::headPositions[tar->m_IDX])
{
if (!hacks::shared::backtrack::ValidTick(i, tar))
continue;
nav::NavTo(i.entorigin, false, false);
break;
}
}
}
}
}
}

View File

@ -115,7 +115,8 @@ void CreateMove()
CachedEntity *ent = FindEntInSight(EffectiveTargetingRange());
// Check if can backtrack, shoot if we can
if (!CanBacktrack() || hacks::shared::backtrack::isBacktrackEnabled)
if (hacks::shared::backtrack::isBacktrackEnabled)
if (!CanBacktrack())
return;
// Check if dormant or null to prevent crashes

View File

@ -437,7 +437,7 @@ void Draw()
draw::WorldToScreen(crumbs[i + 1], wts2))
{
glez::draw::line(wts1.x, wts1.y, wts2.x - wts1.x, wts2.y - wts1.y,
colors::white, 0.1f);
colors::white, 0.3f);
}
}
Vector wts;