From ed8a6267662ad0878dc88e339921362dd2f54c01 Mon Sep 17 00:00:00 2001 From: BenCat07 Date: Fri, 22 May 2020 16:32:45 +0200 Subject: [PATCH] Address some PR issues and improve engineer navbot Also fixes an issue with ipc + party --- include/helpers.hpp | 2 +- include/trace.hpp | 3 --- src/hacks/NavBot.cpp | 53 +++++++++++++++++++++++++++++++++++--------- src/helpers.cpp | 3 +-- src/navparser.cpp | 12 ++++------ src/playerlist.cpp | 2 +- src/trace.cpp | 15 +------------ 7 files changed, 51 insertions(+), 39 deletions(-) diff --git a/include/helpers.hpp b/include/helpers.hpp index 8f4ef78f..accacc3b 100644 --- a/include/helpers.hpp +++ b/include/helpers.hpp @@ -114,7 +114,7 @@ void fClampAngle(Vector &qaAng); bool GetProjectileData(CachedEntity *weapon, float &speed, float &gravity); bool IsVectorVisible(Vector a, Vector b, bool enviroment_only = false, CachedEntity *self = LOCAL_E, unsigned int mask = MASK_SHOT_HULL); // A Special function for navparser to check if a Vector is visible. -bool IsVectorVisibleNavigation(Vector a, Vector b, CachedEntity *self = LOCAL_E, unsigned int mask = MASK_SHOT_HULL); +bool IsVectorVisibleNavigation(Vector a, Vector b, unsigned int mask = MASK_SHOT_HULL); Vector GetForwardVector(Vector origin, Vector viewangles, float distance); Vector GetForwardVector(float distance); CachedEntity *getClosestEntity(Vector vec); diff --git a/include/trace.hpp b/include/trace.hpp index ab8c4a59..53d418de 100644 --- a/include/trace.hpp +++ b/include/trace.hpp @@ -43,14 +43,11 @@ public: }; class FilterNavigation : public ITraceFilter { -public: - IClientEntity *m_pSelf; public: virtual ~FilterNavigation(); FilterNavigation(); virtual bool ShouldHitEntity(IHandleEntity *entity, int mask); - void SetSelf(IClientEntity *self); virtual TraceType_t GetTraceType() const; }; diff --git a/src/hacks/NavBot.cpp b/src/hacks/NavBot.cpp index 61546752..0e4664f1 100644 --- a/src/hacks/NavBot.cpp +++ b/src/hacks/NavBot.cpp @@ -102,7 +102,7 @@ constexpr bot_class_config DIST_SNIPER{ 1000.0f, 1500.0f, 3000.0f }; constexpr bot_class_config DIST_ENGINEER{ 600.0f, 1000.0f, 2500.0f }; // Gunslinger Engineers really don't care at all -constexpr bot_class_config DIST_GUNSLINGER_ENGINEER{ 100.0f, 300.0f, 500.0f }; +constexpr bot_class_config DIST_GUNSLINGER_ENGINEER{ 50.0f, 200.0f, 900.0f }; inline bool HasGunslinger(CachedEntity *ent) { @@ -122,7 +122,7 @@ static void CreateMove() else current_task = task::none; // Check if we should path at all - if (!blocking) + if (!blocking || task::current_task == task::engineer) { round_states round_state = g_pTeamRoundTimer->GetRoundState(); // Still in setuptime, if on fitting team, then do not path yet @@ -481,7 +481,7 @@ static success_build buildBuilding() build_attempts++; // Put building in hand if not already if (hacks::shared::misc::getCarriedBuilding() == -1 && build_command_timer.test_and_set(50)) - g_IEngine->ClientCmd_Unrestricted(format("build ", building).c_str()); + g_IEngine->ClientCmd_Unrestricted(("build " + std::to_string(building)).c_str()); } else if (rotation_timer.check(200)) { @@ -555,9 +555,47 @@ static bool engineerLogic() return true; } - // Let's terrify some people (gunslinger engineer) + // Gunslinger engineer should run at people, given their building isn't too far away if (HasGunslinger(LOCAL_E)) + { + // Deconstruct too far away buildings + for (auto &building : local_buildings) + { + // Too far away, destroy it + if (building->m_vecOrigin().DistTo(LOCAL_E->m_vecOrigin()) >= 1800.0f) + { + Building building_type = None; + switch (building->m_iClassID()) + { + case CL_CLASS(CObjectDispenser): + { + building_type = Dispenser; + break; + } + case CL_CLASS(CObjectTeleporter): + { + // We cannot reliably detect entrance and exit, so just destruct both but mark as "Entrance" + building_type = TP_Entrace; + break; + } + case CL_CLASS(CObjectSentrygun): + { + building_type = Sentry; + break; + } + } + // If we have a valid building + if (building_type != None) + { + // Destroy exit too because we have no idea what is what + if (building_type == TP_Entrace) + g_IEngine->ClientCmd_Unrestricted("destroy 3"); + g_IEngine->ClientCmd_Unrestricted(("destroy " + std::to_string(building_type)).c_str()); + } + } + } stayNearEngineer(); + } else if (selectBuilding() != None) { @@ -657,10 +695,7 @@ static bool engineerLogic() else if (engineer_recheck.test_and_set(15000)) { if (navToBuildingSpot()) - { - engineer_recheck.update(); return true; - } } break; } @@ -918,10 +953,8 @@ static bool stayNearEngineer() } static Timer wait_until_stay_near{}; - if (current_task == task::engineer_task::staynear_engineer) - { + if (current_engineer_task == task::engineer_task::staynear_engineer) return true; - } else if (wait_until_stay_near.test_and_set(4000)) { // We're doing nothing? Do something! diff --git a/src/helpers.cpp b/src/helpers.cpp index de017c63..541be58a 100644 --- a/src/helpers.cpp +++ b/src/helpers.cpp @@ -1362,12 +1362,11 @@ bool IsVectorVisible(Vector origin, Vector target, bool enviroment_only, CachedE } } -bool IsVectorVisibleNavigation(Vector origin, Vector target, CachedEntity *self, unsigned int mask) +bool IsVectorVisibleNavigation(Vector origin, Vector target, unsigned int mask) { trace_t trace_visible; Ray_t ray; - trace::filter_no_entity.SetSelf(RAW_ENT(self)); ray.Init(origin, target); PROF_SECTION(IEVV_TraceRay); g_ITrace->TraceRay(ray, mask, &trace::filter_navigation, &trace_visible); diff --git a/src/navparser.cpp b/src/navparser.cpp index a1a46085..5969f2de 100644 --- a/src/navparser.cpp +++ b/src/navparser.cpp @@ -104,7 +104,7 @@ static ignore_status vischeck(CNavArea *begin, CNavArea *end) first.z += 70; second.z += 70; // Is world blocking it? - if (IsVectorVisibleNavigation(first, second, LOCAL_E, MASK_PLAYERSOLID)) + if (IsVectorVisibleNavigation(first, second, MASK_PLAYERSOLID)) { // Is something else blocking it? if (!IsVectorVisible(first, second, true, LOCAL_E, MASK_PLAYERSOLID)) @@ -418,11 +418,7 @@ struct Graph : public micropather::Graph continue; float distance = center->m_center.DistTo(i.area->m_center); if (isIgnored == 1) - { - if (*vischeckBlock) - continue; - distance += 50000; - } + distance += 1000; adjacent->emplace_back(micropather::StateCost{ reinterpret_cast(neighbour), distance }); } } @@ -528,7 +524,7 @@ CNavArea *findClosestNavSquare(const Vector &vec) bestSquare = &i; } // Check if we are within x and y bounds of an area - if (ovBestDist >= dist || !i.IsOverlapping(vec) || !IsVectorVisibleNavigation(vec, i.m_center, LOCAL_E, MASK_PLAYERSOLID)) + if (ovBestDist >= dist || !i.IsOverlapping(vec) || !IsVectorVisibleNavigation(vec, i.m_center, MASK_PLAYERSOLID)) { continue; } @@ -708,7 +704,7 @@ static void cm() // Update jump timer now if (flip_action) - last_jump.test_and_set(200); + last_jump.update(); flip_action = !flip_action; } } diff --git a/src/playerlist.cpp b/src/playerlist.cpp index e490490e..7ecbe002 100644 --- a/src/playerlist.cpp +++ b/src/playerlist.cpp @@ -199,7 +199,7 @@ bool ChangeState(unsigned int steamid, k_EState state, bool force) else return false; case k_EState::PARTY: - if (state == k_EState::TEXTMODE || state == k_EState::FRIEND) + if (state == k_EState::FRIEND) { ChangeState(steamid, state, true); return true; diff --git a/src/trace.cpp b/src/trace.cpp index d514537a..6fc2cf01 100644 --- a/src/trace.cpp +++ b/src/trace.cpp @@ -111,23 +111,10 @@ TraceType_t trace::FilterNoPlayer::GetTraceType() const /* Navigation filter */ -trace::FilterNavigation::FilterNavigation() -{ - m_pSelf = nullptr; -} +trace::FilterNavigation::FilterNavigation(){}; trace::FilterNavigation::~FilterNavigation(){}; -void trace::FilterNavigation::SetSelf(IClientEntity *self) -{ - if (self == nullptr) - { - logging::Info("nullptr in FilterNavigation::SetSelf"); - return; - } - m_pSelf = self; -} - #define MOVEMENT_COLLISION_GROUP 8 #define RED_CONTENTS_MASK 0x800 #define BLU_CONTENTS_MASK 0x1000