WIP: Pathfinding Nr. 7
This commit is contained in:
parent
0e78958bcc
commit
59c16357c2
@ -5,8 +5,9 @@
|
|||||||
namespace nav
|
namespace nav
|
||||||
{
|
{
|
||||||
extern bool init;
|
extern bool init;
|
||||||
extern bool pathfinding;
|
extern std::vector<CNavArea> areas;
|
||||||
std::vector<Vector> findPath(Vector loc, Vector dest);
|
std::vector<Vector> findPath(Vector loc, Vector dest);
|
||||||
|
bool NavTo(Vector dest);
|
||||||
bool Prepare();
|
bool Prepare();
|
||||||
void CreateMove();
|
void CreateMove();
|
||||||
}
|
}
|
||||||
|
@ -5,14 +5,12 @@
|
|||||||
namespace nav
|
namespace nav
|
||||||
{
|
{
|
||||||
static CNavFile navfile(nullptr);
|
static CNavFile navfile(nullptr);
|
||||||
// Todo: CNavArea* to navfile
|
std::vector<CNavArea> areas;
|
||||||
static std::vector<CNavArea> areas;
|
|
||||||
// std::vector<CNavArea> SniperAreas;
|
// std::vector<CNavArea> SniperAreas;
|
||||||
bool init = false;
|
bool init = false;
|
||||||
bool pathfinding = true;
|
bool pathfinding = true;
|
||||||
static settings::Bool enabled{ "misc.pathing", "true" };
|
static settings::Bool enabled{ "misc.pathing", "true" };
|
||||||
|
|
||||||
|
|
||||||
// Todo fix
|
// Todo fix
|
||||||
int FindInVector(int id)
|
int FindInVector(int id)
|
||||||
{
|
{
|
||||||
@ -122,7 +120,7 @@ void Init()
|
|||||||
lvldir.append("/.steam/steam/steamapps/common/Team Fortress 2/tf/");
|
lvldir.append("/.steam/steam/steamapps/common/Team Fortress 2/tf/");
|
||||||
lvldir.append(lvlname);
|
lvldir.append(lvlname);
|
||||||
lvldir.append(".nav");
|
lvldir.append(".nav");
|
||||||
logging::Info(format("Pathing: Nav File location: ",lvldir).c_str());
|
logging::Info(format("Pathing: Nav File location: ", lvldir).c_str());
|
||||||
|
|
||||||
areas.empty();
|
areas.empty();
|
||||||
navfile = CNavFile(lvldir.c_str());
|
navfile = CNavFile(lvldir.c_str());
|
||||||
@ -131,14 +129,16 @@ void Init()
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
int size = navfile.m_areas.size();
|
int size = navfile.m_areas.size();
|
||||||
logging::Info(format("Pathing: Number of areas to index:", size).c_str());
|
logging::Info(
|
||||||
|
format("Pathing: Number of areas to index:", size).c_str());
|
||||||
areas.reserve(size);
|
areas.reserve(size);
|
||||||
for (auto i : navfile.m_areas)
|
for (auto i : navfile.m_areas)
|
||||||
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>();
|
||||||
pather = std::make_unique<micropather::MicroPather>(TF2MAP.get(), size, 6, true);
|
pather = std::make_unique<micropather::MicroPather>(TF2MAP.get(), size,
|
||||||
|
6, true);
|
||||||
}
|
}
|
||||||
pathfinding = true;
|
pathfinding = true;
|
||||||
}
|
}
|
||||||
@ -165,6 +165,7 @@ int findClosestNavSquare(Vector vec)
|
|||||||
if (areas.at(i).Contains(vec))
|
if (areas.at(i).Contains(vec))
|
||||||
return i;
|
return i;
|
||||||
}
|
}
|
||||||
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::vector<Vector> findPath(Vector loc, Vector dest)
|
std::vector<Vector> findPath(Vector loc, Vector dest)
|
||||||
@ -176,15 +177,15 @@ std::vector<Vector> findPath(Vector loc, Vector 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;
|
micropather::MPVector<void *> pathNodes;
|
||||||
//MAP TF2MAP;
|
// MAP TF2MAP;
|
||||||
//micropather::MicroPather pather(&TF2MAP, areas.size(), 8, true);
|
// micropather::MicroPather pather(&TF2MAP, areas.size(), 8, true);
|
||||||
float cost;
|
float cost;
|
||||||
int result = pather->Solve(static_cast<void *>(&areas.at(id_loc)),
|
int result = 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());
|
||||||
if (result)
|
if (result)
|
||||||
return std::vector<Vector>(0);
|
return std::vector<Vector>(0);
|
||||||
logging::Info(format(result).c_str());
|
|
||||||
std::vector<Vector> path;
|
std::vector<Vector> path;
|
||||||
for (int i = 0; i < pathNodes.size(); i++)
|
for (int i = 0; i < pathNodes.size(); i++)
|
||||||
{
|
{
|
||||||
@ -218,7 +219,8 @@ void CreateMove()
|
|||||||
return;
|
return;
|
||||||
if (CE_BAD(LOCAL_E))
|
if (CE_BAD(LOCAL_E))
|
||||||
return;
|
return;
|
||||||
if (!crumbs.empty() && g_pLocalPlayer->v_Origin.DistTo(crumbs.at(0)) < 20.0f)
|
if (!crumbs.empty() &&
|
||||||
|
g_pLocalPlayer->v_Origin.DistTo(crumbs.at(0)) < 20.0f)
|
||||||
{
|
{
|
||||||
crumbs.erase(crumbs.begin());
|
crumbs.erase(crumbs.begin());
|
||||||
inactivity.update();
|
inactivity.update();
|
||||||
|
Reference in New Issue
Block a user