api: allow getting current bot goal.

api: do not use buckets for nearest node search.
This commit is contained in:
ds 2020-11-06 10:27:19 +03:00
commit a0202efc40
5 changed files with 26 additions and 9 deletions

View file

@ -84,4 +84,10 @@ template <typename T> T &Singleton <T>::instance () {
return *instance_;
}
// declare destructor for pure-virtual classes
#define CR_DECLARE_DESTRUCTOR() \
void operator delete (void *ptr) { \
alloc.deallocate (ptr); \
} \
CR_NAMESPACE_END

View file

@ -33,9 +33,7 @@ private:
virtual UniquePtr <LambdaFunctorWrapper> clone () const = 0;
public:
void operator delete (void *ptr) {
alloc.deallocate (ptr);
}
CR_DECLARE_DESTRUCTOR ();
};
template <typename T> class LambdaFunctor : public LambdaFunctorWrapper {

View file

@ -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;

View file

@ -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 () {

View file

@ -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);