Followbot changes tm?

This commit is contained in:
TotallyNotElite 2018-12-29 16:07:32 +01:00
parent 022f41d901
commit d11b73c66b
6 changed files with 90 additions and 62 deletions

View File

@ -13,5 +13,5 @@ namespace hacks::shared::followbot
int ClassPriority(CachedEntity *ent);
bool isEnabled();
int getTarget();
extern int follow_target;
} // namespace hacks::shared::followbot

View File

@ -12,8 +12,10 @@ enum task : uint8_t
sniper_spot,
stay_near,
health,
ammo
ammo,
followbot
};
extern task current_task;
}
struct bot_class_config
{

View File

@ -472,7 +472,7 @@ int HealingPriority(int idx)
#if ENABLE_IPC
if (ipc::peer)
{
if (hacks::shared::followbot::isEnabled() && hacks::shared::followbot::getTarget() == idx)
if (hacks::shared::followbot::isEnabled() && hacks::shared::followbot::follow_target == idx)
{
priority *= 6.0f;
}

View File

@ -12,6 +12,7 @@
#endif
#include <settings/Bool.hpp>
#include "navparser.hpp"
#include "NavBot.hpp"
static settings::Bool enable{ "follow-bot.enable", "false" };
static settings::Bool roambot{ "follow-bot.roaming", "true" };
@ -30,6 +31,8 @@ static settings::Bool corneractivate{ "follow-bot.corners", "true" };
static settings::Int steam_var{ "follow-bot.steamid", "0" };
namespace hacks::shared::followbot
{
namespace nb = hacks::tf2::NavBot;
static Timer navBotInterval{};
unsigned steamid = 0x0;
@ -62,13 +65,13 @@ CatCommand steam_debug("debug_steamid", "Print steamids", []() {
// Something to store breadcrumbs created by followed players
static std::vector<Vector> breadcrumbs;
static const int crumb_limit = 64; // limit
static constexpr int crumb_limit = 64; // limit
static bool followcart{ false };
// Followed entity, externed for highlight color
int follow_target = 0;
static bool inited;
static bool inited = false;
Timer lastTaunt{}; // time since taunt was last executed, used to avoid kicks
Timer lastJump{};
@ -193,6 +196,8 @@ static void cm()
if (!enable)
{
follow_target = 0;
if (nb::task::current_task == nb::task::followbot)
nb::task::current_task = nb::task::none;
return;
}
if (!inited)
@ -200,6 +205,13 @@ static void cm()
// We need a local player to control
if (CE_BAD(LOCAL_E) || !LOCAL_E->m_bAlivePlayer() || CE_BAD(LOCAL_W))
{
follow_target = 0;
if (nb::task::current_task == nb::task::followbot)
nb::task::current_task = nb::task::none;
return;
}
if (nb::task::current_task == nb::task::health || nb::task::current_task == nb::task::ammo)
{
follow_target = 0;
return;
@ -208,33 +220,6 @@ static void cm()
if (afk)
checkAFK();
// Naving
static bool isnaving = false;
static Timer navtime{};
static Timer navtimeout{};
if (isnaving)
{
if (!follow_target)
{
isnaving = false;
return;
}
if (CE_GOOD(ENTITY(follow_target)) && navtime.test_and_set(500))
{
if (nav::navTo(ENTITY(follow_target)->m_vecOrigin(), 8, true, false))
{
navtimeout.update();
}
}
if (navtimeout.check(15000) || nav::curr_priority == 0)
{
isnaving = false;
nav::clearInstructions();
}
return;
}
// Still good check
if (follow_target)
{
@ -250,6 +235,8 @@ static void cm()
breadcrumbs.clear(); // no target == no path
bool isNavBotCM = navBotInterval.test_and_set(3000);
static Timer navinactivity{};
static int navtarget = 0;
// Target Selection
{
@ -301,12 +288,14 @@ static void cm()
if (VisCheckEntFromEnt(LOCAL_E, entity))
found = true;
}
if (isNavBotCM && !found)
if (!found && isNavBotCM)
{
if (!nav::navTo(entity->m_vecOrigin()))
continue;
navtimeout.update();
found = true;
if (nav::navTo(entity->m_vecOrigin(), 8, true, false))
{
navtarget = i;
navinactivity.update();
break;
}
}
if (!found)
continue;
@ -393,12 +382,14 @@ static void cm()
if (VisCheckEntFromEnt(LOCAL_E, entity))
found = true;
}
if (isNavBotCM && !found)
if (!found && isNavBotCM)
{
if (!nav::navTo(entity->m_vecOrigin()))
continue;
navtimeout.update();
found = true;
if (nav::navTo(entity->m_vecOrigin(), 8, true, false))
{
navtarget = i;
navinactivity.update();
break;
}
}
if (!found)
continue;
@ -411,9 +402,37 @@ static void cm()
lastent++;
if (lastent > g_IEngine->GetMaxClients())
lastent = 0;
if (navtarget)
{
if (follow_target)
navtarget = 0;
breadcrumbs.clear();
auto ent = ENTITY(navtarget);
static Timer navtimer{};
if (CE_GOOD(ent) && navtimer.test_and_set(800))
{
if (nav::navTo(ent->m_vecOrigin(), 8, true, false))
navinactivity.update();
}
if (navinactivity.check(15000))
navtarget = 0;
nb::task::current_task = nb::task::followbot;
return;
}
if (!navtarget && follow_target)
{
nav::clearInstructions();
}
// last check for entity before we continue
if (!follow_target)
{
if (nb::task::current_task == nb::task::followbot)
nb::task::current_task = nb::task::none;
return;
}
nb::task::current_task = nb::task::followbot;
CachedEntity *followtar = ENTITY(follow_target);
// wtf is this needed
@ -582,20 +601,6 @@ static void draw()
}
#endif
static InitRoutine runinit([]() {
#if ENABLE_IPC
EC::Register(EC::CreateMove, cm, "cm_followbot", EC::average);
#endif
#if ENABLE_VISUALS
EC::Register(EC::Draw, draw, "draw_followbot", EC::average);
#endif
});
int getTarget()
{
return follow_target;
}
bool isEnabled()
{
return *enable;
@ -641,5 +646,14 @@ void rvarCallback(settings::VariableBase<int> &var, int after)
return;
steamid = after;
}
static InitRoutine Init([]() { steam_var.installChangeCallback(rvarCallback); });
static InitRoutine runinit([]() {
#if ENABLE_IPC
EC::Register(EC::CreateMove, cm, "cm_followbot", EC::average);
#endif
#if ENABLE_VISUALS
EC::Register(EC::Draw, draw, "draw_followbot", EC::average);
#endif
steam_var.installChangeCallback(rvarCallback);
});
} // namespace hacks::shared::followbot

View File

@ -3,6 +3,7 @@
#include "NavBot.hpp"
#include "PlayerTools.hpp"
#include "Aimbot.hpp"
#include "FollowBot.hpp"
namespace hacks::tf2::NavBot
{
@ -22,13 +23,16 @@ static bool stayNear();
static bool getHealthAndAmmo();
static void autoJump();
static void updateSlot();
using task::current_task;
// -Variables-
static std::vector<std::pair<CNavArea *, Vector>> sniper_spots;
// How long should the bot wait until pathing again?
static Timer wait_until_path{};
// What is the bot currently doing
static task::task current_task;
namespace task {
task current_task;
}
constexpr bot_class_config DIST_OTHER{ 100.0f, 200.0f, 300.0f };
constexpr bot_class_config DIST_SNIPER{ 1000.0f, 1500.0f, 3000.0f };
@ -38,7 +42,7 @@ static void CreateMove()
return;
if (!init(false))
return;
if (!nav::ReadyForCommands)
if (!nav::ReadyForCommands || current_task == task::followbot)
wait_until_path.update();
else
current_task = task::none;
@ -52,7 +56,7 @@ static void CreateMove()
if (getHealthAndAmmo())
return;
// Try to stay near enemies to increase efficiency
if (stay_near || heavy_mode)
if ((stay_near || heavy_mode) && current_task != task::followbot)
if (stayNear())
return;
// We don't have anything else to do. Just nav to sniper spots.
@ -88,7 +92,7 @@ bool init(bool first_cm)
static bool navToSniperSpot()
{
// Don't path if you already have commands. But also don't error out.
if (!nav::ReadyForCommands)
if (!nav::ReadyForCommands || current_task != task::none)
return true;
// Wait arround a bit before pathing again
if (!wait_until_path.check(2000))
@ -327,6 +331,8 @@ static bool getHealthAndAmmo()
static Timer health_ammo_timer{};
if (!health_ammo_timer.check(3000))
return false;
if (current_task == task::health && static_cast<float>(LOCAL_E->m_iHealth()) / LOCAL_E->m_iMaxHealth() >= 0.64f)
current_task = task::none;
if (current_task == task::health)
return true;
@ -353,6 +359,8 @@ static bool getHealthAndAmmo()
}
}
if (current_task == task::ammo && !hasLowAmmo())
current_task = task::none;
if (current_task == task::ammo)
return true;
if (hasLowAmmo())
@ -405,6 +413,8 @@ static int GetBestSlot()
return primary;
case tf_heavy:
return primary;
case tf_medic:
return secondary;
default:
{
float nearest_dist = getNearestPlayerDistance().second;

View File

@ -30,6 +30,8 @@ CatCommand get_state("mm_state", "Get party state", []() {
logging::Info("State: %d", re::CTFParty::state_(party));
});
static CatCommand mm_stop_queue("mm_stop_queue", "Stop current TF2 MM queue", []() { tfmm::leaveQueue(); });
namespace tfmm
{
int queuecount = 0;