Warning untested and probably crashes
This commit is contained in:
parent
5373b3296d
commit
d48e221054
@ -1,6 +1,8 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "common.hpp"
|
#include "common.hpp"
|
||||||
|
#include "micropather.h"
|
||||||
|
#include "pwd.h"
|
||||||
|
|
||||||
namespace nav
|
namespace nav
|
||||||
{
|
{
|
||||||
|
@ -1,6 +1,3 @@
|
|||||||
#include "common.hpp"
|
|
||||||
#include "micropather.h"
|
|
||||||
#include "pwd.h"
|
|
||||||
#include "navparser.hpp"
|
#include "navparser.hpp"
|
||||||
|
|
||||||
namespace nav
|
namespace nav
|
||||||
@ -8,9 +5,11 @@ namespace nav
|
|||||||
static CNavFile navfile(nullptr);
|
static CNavFile navfile(nullptr);
|
||||||
std::vector<CNavArea> areas;
|
std::vector<CNavArea> areas;
|
||||||
// std::vector<CNavArea> SniperAreas;
|
// std::vector<CNavArea> SniperAreas;
|
||||||
bool init = false;
|
bool init = false;
|
||||||
bool pathfinding = true;
|
bool pathfinding = true;
|
||||||
bool ReadyForCommands = false;
|
bool ReadyForCommands = false;
|
||||||
|
std::vector<int> ignores;
|
||||||
|
|
||||||
static settings::Bool enabled{ "misc.pathing", "true" };
|
static settings::Bool enabled{ "misc.pathing", "true" };
|
||||||
|
|
||||||
// Todo fix
|
// Todo fix
|
||||||
@ -25,6 +24,18 @@ int FindInVector(int id)
|
|||||||
|
|
||||||
struct MAP : public micropather::Graph
|
struct MAP : public micropather::Graph
|
||||||
{
|
{
|
||||||
|
std::unique_ptr<micropather::MicroPather> pather;
|
||||||
|
bool IsIgnored(int connectionID)
|
||||||
|
{
|
||||||
|
for (int i = 0; i < ignores.size(); i++)
|
||||||
|
{
|
||||||
|
if (ignores.at(i) == connectionID)
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
Vector GetClosestCornerToArea(CNavArea *CornerOf, CNavArea *Target)
|
Vector GetClosestCornerToArea(CNavArea *CornerOf, CNavArea *Target)
|
||||||
{
|
{
|
||||||
std::array<Vector, 4> corners;
|
std::array<Vector, 4> corners;
|
||||||
@ -87,6 +98,8 @@ struct MAP : public micropather::Graph
|
|||||||
{
|
{
|
||||||
if (GetZBetweenAreas(area, i.area) > 42)
|
if (GetZBetweenAreas(area, i.area) > 42)
|
||||||
continue;
|
continue;
|
||||||
|
if (IsIgnored(i.id))
|
||||||
|
continue;
|
||||||
micropather::StateCost cost;
|
micropather::StateCost cost;
|
||||||
cost.state =
|
cost.state =
|
||||||
static_cast<void *>(&areas.at(FindInVector(i.area->m_id)));
|
static_cast<void *>(&areas.at(FindInVector(i.area->m_id)));
|
||||||
@ -97,8 +110,10 @@ struct MAP : public micropather::Graph
|
|||||||
void PrintStateInfo(void *state)
|
void PrintStateInfo(void *state)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
MAP()
|
MAP(size_t size)
|
||||||
{
|
{
|
||||||
|
pather =
|
||||||
|
std::make_unique<micropather::MicroPather>(this, size, 6, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
~MAP()
|
~MAP()
|
||||||
@ -107,7 +122,6 @@ struct MAP : public micropather::Graph
|
|||||||
};
|
};
|
||||||
|
|
||||||
std::unique_ptr<MAP> TF2MAP;
|
std::unique_ptr<MAP> TF2MAP;
|
||||||
std::unique_ptr<micropather::MicroPather> pather;
|
|
||||||
|
|
||||||
void Init()
|
void Init()
|
||||||
{
|
{
|
||||||
@ -130,7 +144,7 @@ void Init()
|
|||||||
logging::Info("Pathing: Invalid Nav File");
|
logging::Info("Pathing: Invalid Nav File");
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
int size = navfile.m_areas.size();
|
size_t size = navfile.m_areas.size();
|
||||||
logging::Info(
|
logging::Info(
|
||||||
format("Pathing: Number of areas to index:", size).c_str());
|
format("Pathing: Number of areas to index:", size).c_str());
|
||||||
areas.reserve(size);
|
areas.reserve(size);
|
||||||
@ -138,9 +152,7 @@ void Init()
|
|||||||
areas.push_back(i);
|
areas.push_back(i);
|
||||||
if (size > 7000)
|
if (size > 7000)
|
||||||
size = 7000;
|
size = 7000;
|
||||||
TF2MAP = std::make_unique<MAP>();
|
TF2MAP = std::make_unique<MAP>(size);
|
||||||
pather = std::make_unique<micropather::MicroPather>(TF2MAP.get(), size,
|
|
||||||
6, true);
|
|
||||||
}
|
}
|
||||||
pathfinding = true;
|
pathfinding = true;
|
||||||
}
|
}
|
||||||
@ -162,15 +174,24 @@ bool Prepare()
|
|||||||
|
|
||||||
int findClosestNavSquare(Vector vec)
|
int findClosestNavSquare(Vector vec)
|
||||||
{
|
{
|
||||||
float bestDist = FLT_MAX;
|
std::vector<std::pair<int, CNavArea *>> overlapping;
|
||||||
int bestSquare = -1;
|
|
||||||
for (int i = 0; i < areas.size(); i++)
|
for (int i = 0; i < areas.size(); i++)
|
||||||
{
|
{
|
||||||
float dist = areas.at(i).m_center.DistTo(vec);
|
if (areas.at(i).IsOverlapping(vec))
|
||||||
|
{
|
||||||
|
overlapping.push_back({i, &areas.at(i)});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
float bestDist = FLT_MAX;
|
||||||
|
int bestSquare = -1;
|
||||||
|
for (int i = 0; i < overlapping.size(); i++)
|
||||||
|
{
|
||||||
|
float dist = overlapping.at(i).second->m_center.DistTo(vec);
|
||||||
if (dist < bestDist)
|
if (dist < bestDist)
|
||||||
{
|
{
|
||||||
bestDist = dist;
|
bestDist = dist;
|
||||||
bestSquare = i;
|
bestSquare = overlapping.at(i).first;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return bestSquare;
|
return bestSquare;
|
||||||
@ -184,15 +205,13 @@ std::vector<Vector> findPath(Vector loc, Vector dest)
|
|||||||
int id_dest = findClosestNavSquare(dest);
|
int id_dest = findClosestNavSquare(dest);
|
||||||
if (id_loc == -1 || id_dest == -1)
|
if (id_loc == -1 || id_dest == -1)
|
||||||
return std::vector<Vector>(0);
|
return std::vector<Vector>(0);
|
||||||
micropather::MPVector<void *> pathNodes;
|
|
||||||
// MAP TF2MAP;
|
|
||||||
// micropather::MicroPather pather(&TF2MAP, areas.size(), 8, true);
|
|
||||||
float cost;
|
float cost;
|
||||||
int result = pather->Solve(static_cast<void *>(&areas.at(id_loc)),
|
micropather::MPVector<void *> pathNodes;
|
||||||
|
int result = TF2MAP->pather->Solve(static_cast<void *>(&areas.at(id_loc)),
|
||||||
static_cast<void *>(&areas.at(id_dest)),
|
static_cast<void *>(&areas.at(id_dest)),
|
||||||
&pathNodes, &cost);
|
&pathNodes, &cost);
|
||||||
logging::Info(format(result).c_str());
|
logging::Info(format(result).c_str());
|
||||||
if (result)
|
if (result == 1)
|
||||||
return std::vector<Vector>(0);
|
return std::vector<Vector>(0);
|
||||||
std::vector<Vector> path;
|
std::vector<Vector> path;
|
||||||
for (int i = 0; i < pathNodes.size(); i++)
|
for (int i = 0; i < pathNodes.size(); i++)
|
||||||
@ -222,12 +241,55 @@ bool NavTo(Vector dest)
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void ignoreConnection()
|
||||||
|
{
|
||||||
|
if (crumbs.size() < 1)
|
||||||
|
return;
|
||||||
|
|
||||||
|
int closestArea = findClosestNavSquare(g_pLocalPlayer->v_Origin);
|
||||||
|
if (closestArea == -1)
|
||||||
|
return;
|
||||||
|
CNavArea currnode = areas.at(closestArea);
|
||||||
|
|
||||||
|
CNavArea nextnode;
|
||||||
|
for (int i = 0; i < areas.size(); i++)
|
||||||
|
{
|
||||||
|
if (areas.at(i).m_center == crumbs.at(0))
|
||||||
|
{
|
||||||
|
nextnode = areas.at(i);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
for (auto i : currnode.m_connections)
|
||||||
|
{
|
||||||
|
logging::Info(format("1 ", i.area->m_id, " ", nextnode.m_id).c_str());
|
||||||
|
if (i.area->m_id == nextnode.m_id)
|
||||||
|
{
|
||||||
|
ignores.push_back(i.id);
|
||||||
|
TF2MAP->pather->Reset();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Timer ignoreReset{};
|
||||||
|
void clearIgnores()
|
||||||
|
{
|
||||||
|
if (ignoreReset.test_and_set(120000))
|
||||||
|
{
|
||||||
|
ignores.clear();
|
||||||
|
TF2MAP->pather->Reset();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void CreateMove()
|
void CreateMove()
|
||||||
{
|
{
|
||||||
if (!enabled)
|
if (!enabled)
|
||||||
return;
|
return;
|
||||||
if (CE_BAD(LOCAL_E))
|
if (CE_BAD(LOCAL_E))
|
||||||
return;
|
return;
|
||||||
|
clearIgnores();
|
||||||
if (crumbs.empty())
|
if (crumbs.empty())
|
||||||
{
|
{
|
||||||
ReadyForCommands = true;
|
ReadyForCommands = true;
|
||||||
@ -236,7 +298,7 @@ void CreateMove()
|
|||||||
ReadyForCommands = false;
|
ReadyForCommands = false;
|
||||||
if (g_pLocalPlayer->v_Origin.DistTo(crumbs.at(0)) < 30.0f)
|
if (g_pLocalPlayer->v_Origin.DistTo(crumbs.at(0)) < 30.0f)
|
||||||
{
|
{
|
||||||
crumbs.erase(crumbs.begin());
|
crumbs.erase(crumbs.begin());
|
||||||
inactivity.update();
|
inactivity.update();
|
||||||
}
|
}
|
||||||
if (crumbs.empty())
|
if (crumbs.empty())
|
||||||
@ -246,7 +308,8 @@ void CreateMove()
|
|||||||
current_user_cmd->buttons |= IN_JUMP;
|
current_user_cmd->buttons |= IN_JUMP;
|
||||||
if (inactivity.test_and_set(5000))
|
if (inactivity.test_and_set(5000))
|
||||||
{
|
{
|
||||||
logging::Info("NavBot inactive for too long. Canceling tasks...");
|
logging::Info("NavBot inactive for too long. Canceling tasks and ignoring connection...");
|
||||||
|
ignoreConnection();
|
||||||
crumbs.clear();
|
crumbs.clear();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user