From 5177709fe8ec5f7a40e7c9f0d2a38feb47b06f52 Mon Sep 17 00:00:00 2001 From: TotallyNotElite <1yourexperiment@protonmail.com> Date: Thu, 23 Aug 2018 17:14:29 +0200 Subject: [PATCH] Wot why does this not work --- include/navparser.hpp | 47 +++++++++++++++++++++++++++++++++++++++---- src/navparser.cpp | 7 +++++-- 2 files changed, 48 insertions(+), 6 deletions(-) diff --git a/include/navparser.hpp b/include/navparser.hpp index 00dc8743..efd3b794 100644 --- a/include/navparser.hpp +++ b/include/navparser.hpp @@ -4,6 +4,7 @@ #include "micropather.h" #include "pwd.h" #include +#include #if ENABLE_VISUALS #include #endif @@ -29,7 +30,11 @@ size_t FindInVector(size_t id); class inactivityTracker { // Map for storing inactivity per connection - std::map, std::pair> inactives; + std::unordered_map, std::pair, + boost::hash>> + inactives; + std::vector sentryAreas; + bool vischeckConnection(std::pair &connection) { Vector begin = areas.at(FindInVector(connection.first)).m_center; @@ -39,6 +44,7 @@ class inactivityTracker bool result = IsVectorVisible(begin, end, false); return result; } + std::pair VectorToId(std::pair &connection) { CNavArea *currnode = nullptr; @@ -83,6 +89,30 @@ public: i.second.second = 0; } } + void updateSentries() + { + logging::Info("1"); + sentryAreas.clear(); + + for (int i = 0; i < HIGHEST_ENTITY; i++) + { + CachedEntity *ent = ENTITY(i); + if (CE_BAD(ent) || ent->m_iClassID() != CL_CLASS(CObjectSentrygun)) + continue; + Vector sentryloc = GetBuildingPosition(ent); + for (auto i : areas) + { + Vector area = i.m_center; + area.z += 30.0f; + if (area.DistTo(sentryloc) > 1100.0f) + continue; + if (!IsVectorVisible(area, sentryloc, true)) + continue; + logging::Info("5"); + sentryAreas.push_back(i.m_id); + } + } + } bool IsIgnored(std::pair connection) { if (inactives.find(connection) == inactives.end()) @@ -101,6 +131,14 @@ public: "Ignored a connection due to type 2 connection type."); return true; } + if (std::find(sentryAreas.begin(), sentryAreas.end(), + connection.first) != sentryAreas.end() || + std::find(sentryAreas.begin(), sentryAreas.end(), + connection.second) != sentryAreas.end()) + { + logging::Info("Ignored a connection due to sentry gun coverage"); + return true; + } return false; } @@ -113,9 +151,10 @@ public: } auto &pair = inactives.at(connection); - unsigned int newTime = std::chrono::duration_cast( - std::chrono::system_clock::now() - timer.last) - .count(); + unsigned int newTime = + std::chrono::duration_cast( + std::chrono::system_clock::now() - timer.last) + .count(); if (pair.first == 2 && !vischeckConnection(connection)) newTime = (newTime > 2500 ? 2500 : newTime); pair.second = pair.second + newTime; diff --git a/src/navparser.cpp b/src/navparser.cpp index 9872bfc8..c2676055 100644 --- a/src/navparser.cpp +++ b/src/navparser.cpp @@ -242,8 +242,9 @@ void clearInstructions() static Timer ignoreReset{}; static Timer patherReset{}; +static Timer sentryUpdate{}; // Function for removing ignores -void clearIgnores() +void ignoreManagerCM() { if (!TF2MAP || !TF2MAP->pather) return; @@ -251,6 +252,8 @@ void clearIgnores() TF2MAP->inactiveTracker.reset(); if (patherReset.test_and_set(30000)) TF2MAP->pather->Reset(); + if(sentryUpdate.test_and_set(2000)) + TF2MAP->inactiveTracker.updateSentries(); } void Repath() @@ -287,7 +290,7 @@ void CreateMove() crumbs.clear(); return; } - clearIgnores(); + ignoreManagerCM(); // Crumbs empty, prepare for next instruction if (crumbs.empty()) {