api: allow getting current bot goal.
api: do not use buckets for nearest node search.
This commit is contained in:
parent
ca94e31472
commit
a0202efc40
5 changed files with 26 additions and 9 deletions
|
|
@ -84,4 +84,10 @@ template <typename T> T &Singleton <T>::instance () {
|
||||||
return *instance_;
|
return *instance_;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// declare destructor for pure-virtual classes
|
||||||
|
#define CR_DECLARE_DESTRUCTOR() \
|
||||||
|
void operator delete (void *ptr) { \
|
||||||
|
alloc.deallocate (ptr); \
|
||||||
|
} \
|
||||||
|
|
||||||
CR_NAMESPACE_END
|
CR_NAMESPACE_END
|
||||||
|
|
|
||||||
|
|
@ -33,9 +33,7 @@ private:
|
||||||
virtual UniquePtr <LambdaFunctorWrapper> clone () const = 0;
|
virtual UniquePtr <LambdaFunctorWrapper> clone () const = 0;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
void operator delete (void *ptr) {
|
CR_DECLARE_DESTRUCTOR ();
|
||||||
alloc.deallocate (ptr);
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
template <typename T> class LambdaFunctor : public LambdaFunctorWrapper {
|
template <typename T> class LambdaFunctor : public LambdaFunctorWrapper {
|
||||||
|
|
|
||||||
|
|
@ -40,6 +40,9 @@ public:
|
||||||
// force bot to go to the selected node
|
// force bot to go to the selected node
|
||||||
virtual void setBotGoal (int entity, int node) = 0;
|
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
|
// force bot to go to selected origin
|
||||||
virtual void setBotGoalOrigin (int entity, float *origin) = 0;
|
virtual void setBotGoalOrigin (int entity, float *origin) = 0;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -5309,14 +5309,12 @@ void Bot::startDoubleJump (edict_t *ent) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void Bot::sendBotToOrigin (const Vector &origin) {
|
void Bot::sendBotToOrigin (const Vector &origin) {
|
||||||
clearSearchNodes ();
|
|
||||||
clearTask (Task::MoveToPosition); // remove any move tasks
|
|
||||||
|
|
||||||
m_position = origin;
|
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;
|
getTask ()->data = m_chosenGoalIndex;
|
||||||
|
|
||||||
|
startTask (Task::MoveToPosition, TaskPri::Hide, m_chosenGoalIndex, 0.0f, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Bot::resetDoubleJump () {
|
void Bot::resetDoubleJump () {
|
||||||
|
|
|
||||||
|
|
@ -12,6 +12,9 @@ class YaPBModule : public IYaPBModule {
|
||||||
public:
|
public:
|
||||||
virtual ~YaPBModule () override = default;
|
virtual ~YaPBModule () override = default;
|
||||||
|
|
||||||
|
public:
|
||||||
|
CR_DECLARE_DESTRUCTOR ();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Bot *getBot (int index) {
|
Bot *getBot (int index) {
|
||||||
if (index < 1) {
|
if (index < 1) {
|
||||||
|
|
@ -39,7 +42,7 @@ public:
|
||||||
// gets the node nearest to origin
|
// gets the node nearest to origin
|
||||||
virtual int getNearestNode (float *origin) override {
|
virtual int getNearestNode (float *origin) override {
|
||||||
if (graph.length () > 0) {
|
if (graph.length () > 0) {
|
||||||
return graph.getNearest (origin);
|
return graph.getNearestNoBuckets (origin);
|
||||||
}
|
}
|
||||||
return kInvalidNodeIndex;
|
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
|
// force bot to go to selected origin
|
||||||
virtual void setBotGoalOrigin (int entity, float *origin) override {
|
virtual void setBotGoalOrigin (int entity, float *origin) override {
|
||||||
auto bot = getBot (entity);
|
auto bot = getBot (entity);
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue