From a0202efc409f7a0bfb70f68cf26de73184a57052 Mon Sep 17 00:00:00 2001 From: ds Date: Fri, 6 Nov 2020 10:27:19 +0300 Subject: [PATCH] api: allow getting current bot goal. api: do not use buckets for nearest node search. --- ext/crlib/cr-alloc.h | 6 ++++++ ext/crlib/cr-lambda.h | 4 +--- inc/module.h | 3 +++ src/botlib.cpp | 8 +++----- src/module.cpp | 14 +++++++++++++- 5 files changed, 26 insertions(+), 9 deletions(-) diff --git a/ext/crlib/cr-alloc.h b/ext/crlib/cr-alloc.h index d7335d4..b3da32b 100644 --- a/ext/crlib/cr-alloc.h +++ b/ext/crlib/cr-alloc.h @@ -84,4 +84,10 @@ template T &Singleton ::instance () { return *instance_; } +// declare destructor for pure-virtual classes +#define CR_DECLARE_DESTRUCTOR() \ + void operator delete (void *ptr) { \ + alloc.deallocate (ptr); \ + } \ + CR_NAMESPACE_END diff --git a/ext/crlib/cr-lambda.h b/ext/crlib/cr-lambda.h index d2a86e0..a684cf2 100644 --- a/ext/crlib/cr-lambda.h +++ b/ext/crlib/cr-lambda.h @@ -33,9 +33,7 @@ private: virtual UniquePtr clone () const = 0; public: - void operator delete (void *ptr) { - alloc.deallocate (ptr); - } + CR_DECLARE_DESTRUCTOR (); }; template class LambdaFunctor : public LambdaFunctorWrapper { diff --git a/inc/module.h b/inc/module.h index ada9c1e..4220000 100644 --- a/inc/module.h +++ b/inc/module.h @@ -40,6 +40,9 @@ public: // force bot to go to the selected node virtual void setBotGoal (int entity, int node) = 0; + // get's the bot current goal node + virtual int getBotGoal (int entity) = 0; + // force bot to go to selected origin virtual void setBotGoalOrigin (int entity, float *origin) = 0; diff --git a/src/botlib.cpp b/src/botlib.cpp index 562c127..a860c3f 100644 --- a/src/botlib.cpp +++ b/src/botlib.cpp @@ -5309,14 +5309,12 @@ void Bot::startDoubleJump (edict_t *ent) { } void Bot::sendBotToOrigin (const Vector &origin) { - clearSearchNodes (); - clearTask (Task::MoveToPosition); // remove any move tasks - m_position = origin; - startTask (Task::MoveToPosition, TaskPri::MoveToPosition, kInvalidNodeIndex, 0.0f, true); + m_chosenGoalIndex = graph.getNearestNoBuckets (origin); - m_chosenGoalIndex = graph.getNearest (origin); getTask ()->data = m_chosenGoalIndex; + + startTask (Task::MoveToPosition, TaskPri::Hide, m_chosenGoalIndex, 0.0f, true); } void Bot::resetDoubleJump () { diff --git a/src/module.cpp b/src/module.cpp index 1fa203c..c6b0e2c 100644 --- a/src/module.cpp +++ b/src/module.cpp @@ -12,6 +12,9 @@ class YaPBModule : public IYaPBModule { public: virtual ~YaPBModule () override = default; +public: + CR_DECLARE_DESTRUCTOR (); + private: Bot *getBot (int index) { if (index < 1) { @@ -39,7 +42,7 @@ public: // gets the node nearest to origin virtual int getNearestNode (float *origin) override { if (graph.length () > 0) { - return graph.getNearest (origin); + return graph.getNearestNoBuckets (origin); } return kInvalidNodeIndex; } @@ -79,6 +82,15 @@ public: } } + virtual int getBotGoal (int entity) override { + auto bot = getBot (entity); + + if (bot) { + return bot->m_chosenGoalIndex == kInvalidNodeIndex ? bot->getTask ()->data : bot->m_chosenGoalIndex; + } + return kInvalidNodeIndex; + } + // force bot to go to selected origin virtual void setBotGoalOrigin (int entity, float *origin) override { auto bot = getBot (entity);