yapb-noob-edition/src/module.cpp

97 lines
2.3 KiB
C++
Raw Normal View History

//
// YaPB - Counter-Strike Bot based on PODBot by Markus Klinge.
// Copyright <20> 2004-2020 YaPB Project <yapb@jeefo.net>.
//
// SPDX-License-Identifier: MIT
//
#include <yapb.h>
// module interface implementation
class YaPBModule : public IYaPBModule, public Singleton <YaPBModule> {
2020-11-05 16:01:38 +03:00
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 {
return product.version.chars ();
}
// checks if bots are currently in game
virtual bool isBotsInGame () override {
return bots.getBotCount () > 0 ;
}
// checks whether specified players is a yapb bot
virtual bool isBot (int entity) override {
2020-11-05 16:01:38 +03:00
return getBot (entity) != nullptr;
}
// gets the node nearest to origin
2020-11-05 16:01:38 +03:00
virtual int getNearestNode (float *origin) override {
if (graph.length () > 0) {
2020-11-05 16:01:38 +03:00
return graph.getNearestNoBuckets (origin);
}
return kInvalidNodeIndex;
}
// checks wether node is valid
virtual bool isNodeValid (int node) override {
return graph.exists (node);
}
// gets the node origin
virtual float *getNodeOrigin (int node) override {
if (!graph.exists (node)) {
return nullptr;
}
return graph[node].origin;
}
// get the bots current active node
virtual int getCurrentNodeId (int entity) override {
2020-11-05 16:01:38 +03:00
auto bot = getBot (entity);
if (bot) {
return bot->getCurrentNodeIndex ();
}
return kInvalidNodeIndex;
}
// force bot to go to the selected node
virtual void setBotGoal (int entity, int node) {
if (!graph.exists (node)) {
return;
}
2020-11-05 16:01:38 +03:00
auto bot = getBot (entity);
if (bot) {
return bot->sendBotToOrigin (graph[node].origin);
}
}
// force bot to go to selected origin
virtual void setBotGoalOrigin (int entity, float *origin) {
2020-11-05 16:01:38 +03:00
auto bot = getBot (entity);
if (bot) {
return bot->sendBotToOrigin (origin);
}
}
};
CR_EXPOSE_GLOBAL_SINGLETON (YaPBModule, botModule);
// export all the stuff, maybe add versioned interface ?
CR_EXPORT IYaPBModule *GetBotAPI (int version) {
if (version != kYaPBModuleVersion) {
return nullptr;
}
return &botModule;
}