commit
bc2790d690
8 changed files with 168 additions and 2 deletions
42
inc/module.h
Normal file
42
inc/module.h
Normal file
|
|
@ -0,0 +1,42 @@
|
|||
//
|
||||
// YaPB - Counter-Strike Bot based on PODBot by Markus Klinge.
|
||||
// Copyright © 2004-2020 YaPB Project <yapb@jeefo.net>.
|
||||
//
|
||||
// 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;
|
||||
};
|
||||
|
|
@ -16,6 +16,7 @@
|
|||
using namespace cr;
|
||||
|
||||
#include <product.h>
|
||||
#include <module.h>
|
||||
|
||||
// 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;
|
||||
|
|
|
|||
|
|
@ -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'
|
||||
|
|
|
|||
|
|
@ -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 ();
|
||||
|
||||
|
|
|
|||
97
src/module.cpp
Normal file
97
src/module.cpp
Normal file
|
|
@ -0,0 +1,97 @@
|
|||
//
|
||||
// YaPB - Counter-Strike Bot based on PODBot by Markus Klinge.
|
||||
// Copyright © 2004-2020 YaPB Project <yapb@jeefo.net>.
|
||||
//
|
||||
// SPDX-License-Identifier: MIT
|
||||
//
|
||||
|
||||
#include <yapb.h>
|
||||
|
||||
// module interface implementation
|
||||
class YaPBModule : public IYaPBModule, public Singleton <YaPBModule> {
|
||||
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;
|
||||
}
|
||||
|
|
@ -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"
|
||||
|
|
|
|||
|
|
@ -48,6 +48,7 @@
|
|||
<ClInclude Include="..\inc\graph.h" />
|
||||
<ClInclude Include="..\inc\manager.h" />
|
||||
<ClInclude Include="..\inc\message.h" />
|
||||
<ClInclude Include="..\inc\module.h" />
|
||||
<ClInclude Include="..\inc\product.h" />
|
||||
<ClInclude Include="..\inc\support.h" />
|
||||
<ClInclude Include="..\inc\yapb.h" />
|
||||
|
|
@ -65,6 +66,7 @@
|
|||
<ClCompile Include="..\src\linkage.cpp" />
|
||||
<ClCompile Include="..\src\manager.cpp" />
|
||||
<ClCompile Include="..\src\message.cpp" />
|
||||
<ClCompile Include="..\src\module.cpp" />
|
||||
<ClCompile Include="..\src\navigate.cpp" />
|
||||
<ClCompile Include="..\src\support.cpp" />
|
||||
</ItemGroup>
|
||||
|
|
|
|||
|
|
@ -144,6 +144,9 @@
|
|||
<ClInclude Include="..\ext\crlib\cr-deque.h">
|
||||
<Filter>inc\ext\crlib</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\inc\module.h">
|
||||
<Filter>inc</Filter>
|
||||
</ClInclude>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClCompile Include="..\src\android.cpp">
|
||||
|
|
@ -185,6 +188,9 @@
|
|||
<ClCompile Include="..\src\config.cpp">
|
||||
<Filter>src</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\src\module.cpp">
|
||||
<Filter>src</Filter>
|
||||
</ClCompile>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ResourceCompile Include="yapb.rc">
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue