From ce1b0c30abe7545f2f9fc26f3403cced07f7ef65 Mon Sep 17 00:00:00 2001 From: ds Date: Thu, 5 Nov 2020 16:01:38 +0300 Subject: [PATCH] fix: correct mapping id -> bot. --- inc/module.h | 2 +- src/module.cpp | 20 ++++++++++++++------ 2 files changed, 15 insertions(+), 7 deletions(-) diff --git a/inc/module.h b/inc/module.h index b2a92c8..3380fc9 100644 --- a/inc/module.h +++ b/inc/module.h @@ -23,7 +23,7 @@ public: virtual bool isBot (int entity) = 0; // gets the node nearest to origin - virtual int getNearestNode (const Vector &origin) = 0; + virtual int getNearestNode (float *origin) = 0; // checks wether node is valid virtual bool isNodeValid (int node) = 0; diff --git a/src/module.cpp b/src/module.cpp index ebd568a..213358d 100644 --- a/src/module.cpp +++ b/src/module.cpp @@ -9,6 +9,14 @@ // module interface implementation class YaPBModule : public IYaPBModule, public Singleton { +private: + Bot *getBot (int index) { + if (index < 1) { + return nullptr; + } + return bots[game.playerOfIndex (index - 1)]; + } + public: // get the bot version string virtual const char *getBotVersion () override { @@ -22,13 +30,13 @@ public: // checks whether specified players is a yapb bot virtual bool isBot (int entity) override { - return bots[entity] != nullptr; + return getBot (entity) != nullptr; } // gets the node nearest to origin - virtual int getNearestNode (const Vector &origin) override { + virtual int getNearestNode (float *origin) override { if (graph.length () > 0) { - return graph.getNearest (origin); + return graph.getNearestNoBuckets (origin); } return kInvalidNodeIndex; } @@ -48,7 +56,7 @@ public: // get the bots current active node virtual int getCurrentNodeId (int entity) override { - auto bot = bots[entity]; + auto bot = getBot (entity); if (bot) { return bot->getCurrentNodeIndex (); @@ -61,7 +69,7 @@ public: if (!graph.exists (node)) { return; } - auto bot = bots[entity]; + auto bot = getBot (entity); if (bot) { return bot->sendBotToOrigin (graph[node].origin); @@ -70,7 +78,7 @@ public: // force bot to go to selected origin virtual void setBotGoalOrigin (int entity, float *origin) { - auto bot = bots[entity]; + auto bot = getBot (entity); if (bot) { return bot->sendBotToOrigin (origin);