From 618f6961a8107fc46b20267cc7867a299dc02f9b Mon Sep 17 00:00:00 2001 From: TotallyNotElite <1yourexperiment@protonmail.com> Date: Sat, 25 Aug 2018 00:29:09 +0200 Subject: [PATCH] Untested navbot changes + gui free mouse --- include/navparser.hpp | 46 +++++++++++++++++++++----------- src/navparser.cpp | 6 ++--- src/visual/menu/GuiInterface.cpp | 10 +++++++ 3 files changed, 44 insertions(+), 18 deletions(-) diff --git a/include/navparser.hpp b/include/navparser.hpp index 28951982..0ce9f71c 100644 --- a/include/navparser.hpp +++ b/include/navparser.hpp @@ -46,7 +46,7 @@ class inactivityTracker return result; } - std::pair VectorToId(std::pair &connection) + std::pair VectorsToId(std::pair &connection) { CNavArea *currnode = nullptr; for (size_t i = 0; i < areas.size(); i++) @@ -81,6 +81,22 @@ class inactivityTracker } } + int VectorToID(Vector vec) + { + CNavArea *currnode = nullptr; + for (size_t i = 0; i < areas.size(); i++) + { + if (areas.at(i).m_center == vec) + { + currnode = &areas.at(i); + break; + } + } + if (!currnode) + return -1; + return currnode->m_id; + } + public: void reset() { @@ -92,16 +108,15 @@ public: } bool ShouldCancelPath(std::vector crumbs) { - for (auto sentry : sentries) - for (auto crumb : crumbs) - { - if (crumb.DistTo(sentry) > 1100) - continue; - if (!IsVectorVisible(crumb, sentry, true)) - continue; + for (auto crumb : crumbs) + { + int id = VectorToID(crumb); + if (id == -1) + continue; + if (sentryAreas[id]) return true; - } - return false; + } + return false; } void updateSentries() { @@ -110,7 +125,9 @@ public: for (int i = 0; i < HIGHEST_ENTITY; i++) { CachedEntity *ent = ENTITY(i); - if (CE_BAD(ent) || ent->m_iClassID() != CL_CLASS(CObjectSentrygun) || ent->m_iTeam() == LOCAL_E->m_iTeam()) + if (CE_BAD(ent) || + ent->m_iClassID() != CL_CLASS(CObjectSentrygun) /*|| + ent->m_iTeam() == LOCAL_E->m_iTeam()*/) continue; Vector sentryloc = GetBuildingPosition(ent); sentries.push_back(sentryloc); @@ -128,8 +145,7 @@ public: } bool IsIgnored(std::pair connection) { - if (sentryAreas[connection.first] || - sentryAreas[connection.second]) + if (sentryAreas[connection.first] || sentryAreas[connection.second]) { logging::Info("Ignored a connection due to sentry gun coverage"); return true; @@ -173,7 +189,7 @@ public: void AddTime(std::pair connection, Timer &timer, bool &resetPather) { - auto pair = VectorToId(connection); + auto pair = VectorsToId(connection); if (pair.first == -1 || pair.second == -1) return; AddTime(pair, timer, resetPather); @@ -201,7 +217,7 @@ public: } bool CheckType2(std::pair connection) { - auto pair = VectorToId(connection); + auto pair = VectorsToId(connection); if (pair.first == -1 || pair.second == -1) return false; return CheckType2(pair); diff --git a/src/navparser.cpp b/src/navparser.cpp index 2f5686c8..f9739f5f 100644 --- a/src/navparser.cpp +++ b/src/navparser.cpp @@ -211,7 +211,7 @@ bool NavTo(Vector dest, bool navToLocalCenter, bool persistent, // Only allow instructions to overwrite others if their priority is higher if (instructionPriority < priority) return false; - int locNav, tarNav; + int locNav = 0, tarNav = 0; auto path = findPath(g_pLocalPlayer->v_Origin, dest, locNav, tarNav); if (path.empty()) return false; @@ -266,7 +266,7 @@ void Repath() logging::Info("Pathing: NavBot inactive for too long. Ignoring " "connection and finding another path..."); // Throwaway int - int i1, i2; + int i1 = 0, i2 = 0; // Find a new path TF2MAP->pather->Reset(); crumbs = findPath(g_pLocalPlayer->v_Origin, crumbs.back(), i1, i2); @@ -402,7 +402,7 @@ CatCommand navprint("nav_print", "Debug nav print", [](const CCommand &args) { }); CatCommand navfind("nav_find", "Debug nav find", [](const CCommand &args) { - int i1, i2; + int i1 = 0, i2 = 0; std::vector path = findPath(g_pLocalPlayer->v_Origin, loc, i1, i2); if (path.empty()) { diff --git a/src/visual/menu/GuiInterface.cpp b/src/visual/menu/GuiInterface.cpp index 3f18372d..2cc1e177 100755 --- a/src/visual/menu/GuiInterface.cpp +++ b/src/visual/menu/GuiInterface.cpp @@ -156,6 +156,16 @@ bool gui::handleSdlEvent(SDL_Event *event) logging::Info("GUI open button pressed"); zerokernel::Menu::instance->setInGame( !zerokernel::Menu::instance->isInGame()); + if (!zerokernel::Menu::instance->isInGame()) + { + g_ISurface->UnlockCursor(); + g_ISurface->SetCursorAlwaysVisible(true); + } + else + { + g_ISurface->LockCursor(); + g_ISurface->SetCursorAlwaysVisible(false); + } return true; } }