diff --git a/include/navparser.hpp b/include/navparser.hpp index efd3b794..afa010e9 100644 --- a/include/navparser.hpp +++ b/include/navparser.hpp @@ -33,7 +33,8 @@ class inactivityTracker std::unordered_map, std::pair, boost::hash>> inactives; - std::vector sentryAreas; + std::unordered_map sentryAreas; + std::vector sentries; bool vischeckConnection(std::pair &connection) { @@ -89,36 +90,52 @@ public: i.second.second = 0; } } + 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; + return true; + } + return false; + } void updateSentries() { - logging::Info("1"); sentryAreas.clear(); - + sentries.clear(); for (int i = 0; i < HIGHEST_ENTITY; i++) { CachedEntity *ent = ENTITY(i); - if (CE_BAD(ent) || ent->m_iClassID() != CL_CLASS(CObjectSentrygun)) + 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); for (auto i : areas) { Vector area = i.m_center; - area.z += 30.0f; + area.z += 83.0f; if (area.DistTo(sentryloc) > 1100.0f) continue; if (!IsVectorVisible(area, sentryloc, true)) continue; - logging::Info("5"); - sentryAreas.push_back(i.m_id); + sentryAreas[i.m_id] = true; } } } bool IsIgnored(std::pair connection) { - if (inactives.find(connection) == inactives.end()) + if (sentryAreas[connection.first] || + sentryAreas[connection.second]) { - return false; + logging::Info("Ignored a connection due to sentry gun coverage"); + return true; } + if (inactives.find(connection) == inactives.end()) + return false; auto &pair = inactives.at(connection); if (pair.second >= 5000) { @@ -131,14 +148,6 @@ 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; } diff --git a/include/trace.hpp b/include/trace.hpp index bc3f47b2..5bdb9b0d 100644 --- a/include/trace.hpp +++ b/include/trace.hpp @@ -42,6 +42,19 @@ public: virtual TraceType_t GetTraceType() const; }; +class FilterNoEntity : public ITraceFilter +{ +public: + IClientEntity *m_pSelf; + +public: + virtual ~FilterNoEntity(); + FilterNoEntity(); + virtual bool ShouldHitEntity(IHandleEntity *entity, int mask); + void SetSelf(IClientEntity *self); + virtual TraceType_t GetTraceType() const; +}; + class FilterPenetration : public ITraceFilter { public: @@ -59,5 +72,6 @@ public: extern FilterDefault filter_default; extern FilterNoPlayer filter_no_player; +extern FilterNoEntity filter_no_entity; extern FilterPenetration filter_penetration; } // namespace trace diff --git a/src/helpers.cpp b/src/helpers.cpp index 11e808b6..63a9bf4b 100644 --- a/src/helpers.cpp +++ b/src/helpers.cpp @@ -1107,19 +1107,29 @@ netvar.iHealth)); bool IsVectorVisible(Vector origin, Vector target, bool enviroment_only) { - trace_t trace_visible; - Ray_t ray; - trace::filter_no_player.SetSelf(RAW_ENT(g_pLocalPlayer->entity)); - ray.Init(origin, target); if (!enviroment_only) + { + trace_t trace_visible; + Ray_t ray; + + trace::filter_no_player.SetSelf(RAW_ENT(g_pLocalPlayer->entity)); + ray.Init(origin, target); g_ITrace->TraceRay(ray, MASK_SHOT_HULL, &trace::filter_no_player, &trace_visible); + return (trace_visible.fraction == 1.0f); + } else - g_ITrace->TraceRay(ray, 0x4200400B, &trace::filter_no_player, - &trace_visible); + { + trace_t trace_visible; + Ray_t ray; - return (trace_visible.fraction == 1.0f); + trace::filter_no_entity.SetSelf(RAW_ENT(g_pLocalPlayer->entity)); + ray.Init(origin, target); + g_ITrace->TraceRay(ray, MASK_SHOT_HULL, &trace::filter_no_entity, + &trace_visible); + return (trace_visible.fraction == 1.0f); + } } void WhatIAmLookingAt(int *result_eindex, Vector *result_pos) diff --git a/src/navparser.cpp b/src/navparser.cpp index c2676055..46a38e97 100644 --- a/src/navparser.cpp +++ b/src/navparser.cpp @@ -243,6 +243,7 @@ void clearInstructions() static Timer ignoreReset{}; static Timer patherReset{}; static Timer sentryUpdate{}; +static Timer sentryCheck{}; // Function for removing ignores void ignoreManagerCM() { @@ -252,8 +253,8 @@ void ignoreManagerCM() TF2MAP->inactiveTracker.reset(); if (patherReset.test_and_set(30000)) TF2MAP->pather->Reset(); - if(sentryUpdate.test_and_set(2000)) - TF2MAP->inactiveTracker.updateSentries(); + if(sentryUpdate.test_and_set(1000)) + TF2MAP->inactiveTracker.updateSentries(); } void Repath() @@ -265,6 +266,7 @@ void Repath() // Throwaway int int i1, i2; // Find a new path + TF2MAP->pather->Reset(); crumbs = findPath(g_pLocalPlayer->v_Origin, crumbs.back(), i1, i2); } else @@ -273,6 +275,7 @@ void Repath() "Pathing: NavBot inactive for too long. Canceling tasks and " "ignoring connection..."); // Wait for new instructions + TF2MAP->pather->Reset(); crumbs.clear(); } } @@ -325,6 +328,13 @@ void CreateMove() inactivity.update(); return; } + // Check for new sentries + if (sentryCheck.test_and_set(1000) && TF2MAP->inactiveTracker.ShouldCancelPath(crumbs)) + { + logging::Info("Pathing: New Sentry found!"); + TF2MAP->pather->Reset(); + Repath(); + } // If inactive for too long if (inactivity.check(5000)) { diff --git a/src/trace.cpp b/src/trace.cpp index 3100dfe7..384d7e69 100755 --- a/src/trace.cpp +++ b/src/trace.cpp @@ -110,7 +110,34 @@ TraceType_t trace::FilterNoPlayer::GetTraceType() const { return TRACE_EVERYTHING; } +/* No-Entity filter */ +trace::FilterNoEntity::FilterNoEntity() +{ + m_pSelf = nullptr; +} + +trace::FilterNoEntity::~FilterNoEntity(){}; + +void trace::FilterNoEntity::SetSelf(IClientEntity *self) +{ + if (self == nullptr) + { + logging::Info("nullptr in FilterNoPlayer::SetSelf"); + return; + } + m_pSelf = self; +} + +bool trace::FilterNoEntity::ShouldHitEntity(IHandleEntity *handle, int mask) +{ + return false; +} + +TraceType_t trace::FilterNoEntity::GetTraceType() const +{ + return TRACE_EVERYTHING; +} /* Penetration Filter */ trace::FilterPenetration::FilterPenetration() @@ -172,4 +199,5 @@ void trace::FilterPenetration::Reset() trace::FilterDefault trace::filter_default{}; trace::FilterNoPlayer trace::filter_no_player{}; +trace::FilterNoEntity trace::filter_no_entity{}; trace::FilterPenetration trace::filter_penetration{};