diff --git a/inc/module.h b/inc/module.h new file mode 100644 index 0000000..3380fc9 --- /dev/null +++ b/inc/module.h @@ -0,0 +1,42 @@ +// +// YaPB - Counter-Strike Bot based on PODBot by Markus Klinge. +// Copyright © 2004-2020 YaPB Project . +// +// SPDX-License-Identifier: MIT +// + +#pragma once + +// AMX Mod X Module API Version (bump if interface changed) +constexpr int kYaPBModuleVersion = 1; + +// basic module interface, if you need to additional stuff, please post an issue +class IYaPBModule { +public: + // get the bot version string + virtual const char *getBotVersion () = 0; + + // checks if bots are currently in game + virtual bool isBotsInGame () = 0; + + // checks whether specified players is a yapb bot + virtual bool isBot (int entity) = 0; + + // gets the node nearest to origin + virtual int getNearestNode (float *origin) = 0; + + // checks wether node is valid + virtual bool isNodeValid (int node) = 0; + + // gets the node origin + virtual float *getNodeOrigin (int node) = 0; + + // get the bots current active node + virtual int getCurrentNodeId (int entity) = 0; + + // force bot to go to the selected node + virtual void setBotGoal (int entity, int node) = 0; + + // force bot to go to selected origin + virtual void setBotGoalOrigin (int entity, float *origin) = 0; +}; \ No newline at end of file diff --git a/inc/yapb.h b/inc/yapb.h index fba476c..77569f5 100644 --- a/inc/yapb.h +++ b/inc/yapb.h @@ -16,6 +16,7 @@ using namespace cr; #include +#include // forwards class Bot; @@ -1062,6 +1063,7 @@ public: void kick (); void resetDoubleJump (); void startDoubleJump (edict_t *ent); + void sendBotToOrigin (const Vector &origin); bool hasHostage (); bool usesRifle (); @@ -1120,6 +1122,11 @@ public: return m_index + 1; } + // get the current node index + int getCurrentNodeIndex () const { + return m_currentNodeIndex; + } + // set the last bot trace result void setLastTraceResult (TraceChannel channel, TraceResult *traceResult) { m_lastTrace[channel] = *traceResult; diff --git a/meson.build b/meson.build index f0e4d0c..4e081aa 100644 --- a/meson.build +++ b/meson.build @@ -216,6 +216,7 @@ sourceFiles = files ( 'src/graph.cpp', 'src/linkage.cpp', 'src/manager.cpp', + 'src/module.cpp', 'src/message.cpp', 'src/navigate.cpp', 'src/support.cpp' diff --git a/src/botlib.cpp b/src/botlib.cpp index f7c72be..562c127 100644 --- a/src/botlib.cpp +++ b/src/botlib.cpp @@ -5308,6 +5308,17 @@ void Bot::startDoubleJump (edict_t *ent) { sendToChat (strings.format ("Ok %s, i will help you!", ent->v.netname.chars ()), true); } +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.getNearest (origin); + getTask ()->data = m_chosenGoalIndex; +} + void Bot::resetDoubleJump () { completeTask (); diff --git a/src/module.cpp b/src/module.cpp new file mode 100644 index 0000000..213358d --- /dev/null +++ b/src/module.cpp @@ -0,0 +1,97 @@ +// +// YaPB - Counter-Strike Bot based on PODBot by Markus Klinge. +// Copyright © 2004-2020 YaPB Project . +// +// SPDX-License-Identifier: MIT +// + +#include + +// 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 { + 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 { + return getBot (entity) != nullptr; + } + + // gets the node nearest to origin + virtual int getNearestNode (float *origin) override { + if (graph.length () > 0) { + 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 { + 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; + } + 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) { + 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; +} diff --git a/vc/yapb.rc b/vc/yapb.rc index de18a4f..bcf8128 100644 --- a/vc/yapb.rc +++ b/vc/yapb.rc @@ -22,9 +22,9 @@ FILEOS 0x40004 FILETYPE 0x2 { BLOCK "StringFileInfo" { BLOCK "040904E4" { - VALUE "CompanyName", "YaPB Development Team" "\0" + VALUE "CompanyName", "YaPB Project" "\0" VALUE "FileDescription", "YaPB v" MODULE_BOT_VERSION "." MODULE_BUILD_COUNT " - The Counter-Strike Bot" "\0" - VALUE "LegalCopyright", "Copyright \251 2020 YaPB Development Team" "\0" + VALUE "LegalCopyright", "Copyright \251 2020 Project" "\0" VALUE "OriginalFilename", "yapb.dll" "\0" VALUE "ProductName", "YaPB" "\0" VALUE "InternalName", "YaPB DLL" "\0" diff --git a/vc/yapb.vcxproj b/vc/yapb.vcxproj index ac5443a..50abf9d 100644 --- a/vc/yapb.vcxproj +++ b/vc/yapb.vcxproj @@ -48,6 +48,7 @@ + @@ -65,6 +66,7 @@ + diff --git a/vc/yapb.vcxproj.filters b/vc/yapb.vcxproj.filters index 388638a..6709171 100644 --- a/vc/yapb.vcxproj.filters +++ b/vc/yapb.vcxproj.filters @@ -144,6 +144,9 @@ inc\ext\crlib + + inc + @@ -185,6 +188,9 @@ src + + src +