WIP: Pathfinding Nr. 8: Add ReadyForCommands

This commit is contained in:
TotallyNotElite 2018-08-17 15:55:03 +02:00
parent 59c16357c2
commit 26291c5879
2 changed files with 19 additions and 10 deletions

View File

@ -5,6 +5,7 @@
namespace nav namespace nav
{ {
extern bool init; extern bool init;
extern bool ReadyForCommands;
extern std::vector<CNavArea> areas; 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 NavTo(Vector dest);

View File

@ -9,6 +9,7 @@ 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;
static settings::Bool enabled{ "misc.pathing", "true" }; static settings::Bool enabled{ "misc.pathing", "true" };
// Todo fix // Todo fix
@ -83,7 +84,7 @@ struct MAP : public micropather::Graph
auto &neighbours = area->m_connections; auto &neighbours = area->m_connections;
for (auto i : neighbours) for (auto i : neighbours)
{ {
if (GetZBetweenAreas(area, i.area) > 40) if (GetZBetweenAreas(area, i.area) > 30)
continue; continue;
micropather::StateCost cost; micropather::StateCost cost;
cost.state = cost.state =
@ -160,12 +161,18 @@ bool Prepare()
int findClosestNavSquare(Vector vec) int findClosestNavSquare(Vector vec)
{ {
float bestDist = FLT_MAX;
int bestSquare = -1;
for (int i = 0; i < areas.size(); i++) for (int i = 0; i < areas.size(); i++)
{ {
if (areas.at(i).Contains(vec)) float dist = areas.at(i).m_center.DistTo(vec);
return i; if (dist < bestDist)
{
bestDist = dist;
bestSquare = i;
}
} }
return -1; return bestSquare;
} }
std::vector<Vector> findPath(Vector loc, Vector dest) std::vector<Vector> findPath(Vector loc, Vector dest)
@ -219,18 +226,19 @@ void CreateMove()
return; return;
if (CE_BAD(LOCAL_E)) if (CE_BAD(LOCAL_E))
return; return;
if (!crumbs.empty() && if (crumbs.empty())
g_pLocalPlayer->v_Origin.DistTo(crumbs.at(0)) < 20.0f) {
ReadyForCommands = true;
return;
}
ReadyForCommands = false;
if(g_pLocalPlayer->v_Origin.DistTo(crumbs.at(0)) < 20.0f)
{ {
crumbs.erase(crumbs.begin()); crumbs.erase(crumbs.begin());
inactivity.update(); inactivity.update();
} }
if (crumbs.empty()) if (crumbs.empty())
return; return;
if (inactivity.check(2000) && lastJump.test_and_set(1000))
{
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...");