Skip to content

Commit

Permalink
Playerbots integration
Browse files Browse the repository at this point in the history
  • Loading branch information
davidonete committed Mar 23, 2024
1 parent d723409 commit 62cb97a
Show file tree
Hide file tree
Showing 49 changed files with 1,600 additions and 60 deletions.
10 changes: 5 additions & 5 deletions .github/workflows/windows-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,13 @@ jobs:
- OPTIONAL_DEFINES: ""
TYPE: "default"

- OPTIONAL_DEFINES: "-DBUILD_EXTRACTORS=ON -DBUILD_PLAYERBOT=ON -DBUILD_AHBOT=ON -DBUILD_RECASTDEMOMOD=ON -DBUILD_GIT_ID=ON"
- OPTIONAL_DEFINES: "-DBUILD_EXTRACTORS=ON -DBUILD_PLAYERBOTS=ON -DBUILD_AHBOT=ON -DBUILD_RECASTDEMOMOD=ON -DBUILD_GIT_ID=ON"
TYPE: "with-all"

- OPTIONAL_DEFINES: "-DBUILD_PLAYERBOT=ON -DBUILD_AHBOT=ON"
- OPTIONAL_DEFINES: "-DBUILD_PLAYERBOTS=ON -DBUILD_AHBOT=ON"
TYPE: "with-playerbot-ahbot"

- OPTIONAL_DEFINES: "-DBUILD_PLAYERBOT=ON"
- OPTIONAL_DEFINES: "-DBUILD_PLAYERBOTS=ON"
TYPE: "with-playerbot"

- OPTIONAL_DEFINES: "-DBUILD_AHBOT=ON"
Expand Down Expand Up @@ -170,8 +170,8 @@ jobs:
- [Default Download](${{github.server_url}}/${{ github.repository }}/releases/download/latest/${{env.DEFAULT_ARCH_NAME}})
- [All Options Enabled](${{github.server_url}}/${{ github.repository }}/releases/download/latest/${{env.ALL_ARCH_NAME}})
- [AHBot Enabled](${{github.server_url}}/${{ github.repository }}/releases/download/latest/${{env.AB_ARCH_NAME}})
- [PlayerBot Enabled](${{github.server_url}}/${{ github.repository }}/releases/download/latest/${{env.PB_ARCH_NAME}})
- [AHBot & PlayerBot Enabled](${{github.server_url}}/${{ github.repository }}/releases/download/latest/${{env.PB_AB_ARCH_NAME}})
- [PlayerBots Enabled](${{github.server_url}}/${{ github.repository }}/releases/download/latest/${{env.PB_ARCH_NAME}})
- [AHBot & PlayerBots Enabled](${{github.server_url}}/${{ github.repository }}/releases/download/latest/${{env.PB_AB_ARCH_NAME}})
If you find any bugs or issues please report them [here](https://github.com/cmangos/issues/issues/new/choose).
footer: Created by the CMaNGOS Team!
Expand Down
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -91,3 +91,8 @@ cmake_install.cmake
# recastnavigation directory needs exception
!dep/recastnavigation/RecastDemo/Build/
/_build/

#
# Module files
#
src/modules/
12 changes: 12 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -329,6 +329,18 @@ if(NOT BUILD_GAME_SERVER AND BUILD_DEPRECATED_PLAYERBOT)
message(STATUS "BUILD_DEPRECATED_PLAYERBOT forced to OFF due to BUILD_GAME_SERVER is not set")
endif()

if(BUILD_PLAYERBOTS)
if(BUILD_DEPRECATED_PLAYERBOT)
set(BUILD_DEPRECATED_PLAYERBOT OFF)
message(STATUS "BUILD_DEPRECATED_PLAYERBOT forced to OFF because BUILD_PLAYERBOTS is set")
endif()

if(NOT BUILD_GAME_SERVER)
set(BUILD_PLAYERBOTS OFF)
message(STATUS "BUILD_PLAYERBOTS forced to OFF due to BUILD_GAME_SERVER is not set")
endif()
endif()

if(PCH)
if(${CMAKE_VERSION} VERSION_LESS "3.16")
message("PCH is not supported by your CMake version")
Expand Down
2 changes: 2 additions & 0 deletions cmake/options.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ option(BUILD_GAME_SERVER "Build game server"
option(BUILD_LOGIN_SERVER "Build login server" ON)
option(BUILD_EXTRACTORS "Build map/dbc/vmap/mmap extractors" OFF)
option(BUILD_SCRIPTDEV "Build ScriptDev. (OFF Speedup build)" ON)
option(BUILD_PLAYERBOTS "Build Playerbots mod" OFF)
option(BUILD_AHBOT "Build Auction House Bot mod" OFF)
option(BUILD_METRICS "Build Metrics, generate data for Grafana" OFF)
option(BUILD_RECASTDEMOMOD "Build map/vmap/mmap viewer" OFF)
Expand Down Expand Up @@ -33,6 +34,7 @@ message(STATUS
BUILD_GAME_SERVER Build game server (core server)
BUILD_LOGIN_SERVER Build login server (auth server)
BUILD_EXTRACTORS Build map/dbc/vmap/mmap extractor
BUILD_PLAYERBOTS Build Playerbots mod
BUILD_AHBOT Build Auction House Bot mod
BUILD_METRICS Build Metrics, generate data for Grafana
BUILD_RECASTDEMOMOD Build map/vmap/mmap viewer
Expand Down
6 changes: 6 additions & 0 deletions cmake/showoptions.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,12 @@ else()
message(STATUS "Build OLD Playerbot : No (default)")
endif()

if(BUILD_PLAYERBOTS)
message(STATUS "Build Playerbots : Yes")
else()
message(STATUS "Build Playerbots : No (default)")
endif()

if(BUILD_EXTRACTORS)
message(STATUS "Build extractors : Yes")
else()
Expand Down
34 changes: 34 additions & 0 deletions contrib/mmap/src/MapBuilder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,36 @@

using namespace VMAP;

void rcModAlmostUnwalkableTriangles(rcContext* ctx, const float walkableSlopeAngle,
const float* verts, int /*nv*/,
const int* tris, int nt,
unsigned char* areas)
{
rcIgnoreUnused(ctx);

const float walkableThr = cosf(walkableSlopeAngle / 180.0f * RC_PI);

float norm[3];

for (int i = 0; i < nt; ++i)
{
if (areas[i] & RC_WALKABLE_AREA)
{
const int* tri = &tris[i * 3];

float e0[3], e1[3];
rcVsub(e0, &verts[tri[1] * 3], &verts[tri[0] * 3]);
rcVsub(e1, &verts[tri[2] * 3], &verts[tri[0] * 3]);
rcVcross(norm, e0, e1);
rcVnormalize(norm);

// Check if the face is walkable.
if (norm[1] <= walkableThr)
areas[i] = NAV_AREA_GROUND_STEEP; //Slopes between 50 and 60. Walkable for mobs, unwalkable for players.
}
}
}

void from_json(const json& j, rcConfig& config)
{
config.tileSize = MMAP::VERTEX_PER_TILE;
Expand Down Expand Up @@ -1004,6 +1034,10 @@ namespace MMAP
unsigned char* triFlags = new unsigned char[tTriCount];
memset(triFlags, NAV_AREA_GROUND, tTriCount * sizeof(unsigned char));
rcClearUnwalkableTriangles(m_rcContext, tileCfg.walkableSlopeAngle, tVerts, tVertCount, tTris, tTriCount, triFlags);

// mark almost unwalkable triangles with steep flag
rcModAlmostUnwalkableTriangles(m_rcContext, 50.0f, tVerts, tVertCount, tTris, tTriCount, triFlags);

rcRasterizeTriangles(m_rcContext, tVerts, tVertCount, tTris, triFlags, tTriCount, *tile.solid, tileCfg.walkableClimb);
delete[] triFlags;

Expand Down
4 changes: 2 additions & 2 deletions sql/create/db_create_mysql.sql
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ CREATE DATABASE `tbcrealmd` DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci;

CREATE USER IF NOT EXISTS 'mangos'@'localhost' IDENTIFIED BY 'mangos';

GRANT SELECT, INSERT, UPDATE, DELETE, CREATE, DROP, ALTER, LOCK TABLES, CREATE TEMPORARY TABLES ON `tbcmangos`.* TO 'mangos'@'localhost';
GRANT INDEX, SELECT, INSERT, UPDATE, DELETE, CREATE, DROP, ALTER, LOCK TABLES, CREATE TEMPORARY TABLES ON `tbcmangos`.* TO 'mangos'@'localhost';

GRANT SELECT, INSERT, UPDATE, DELETE, CREATE, DROP, ALTER, LOCK TABLES, CREATE TEMPORARY TABLES ON `tbclogs`.* TO 'mangos'@'localhost';

GRANT SELECT, INSERT, UPDATE, DELETE, CREATE, DROP, ALTER, LOCK TABLES, CREATE TEMPORARY TABLES ON `tbccharacters`.* TO 'mangos'@'localhost';
GRANT INDEX SELECT, INSERT, UPDATE, DELETE, CREATE, DROP, ALTER, LOCK TABLES, CREATE TEMPORARY TABLES ON `tbccharacters`.* TO 'mangos'@'localhost';

GRANT SELECT, INSERT, UPDATE, DELETE, CREATE, DROP, ALTER, LOCK TABLES, CREATE TEMPORARY TABLES ON `tbcrealmd`.* TO 'mangos'@'localhost';
31 changes: 30 additions & 1 deletion src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,40 @@ if(BUILD_GAME_SERVER OR BUILD_LOGIN_SERVER OR BUILD_EXTRACTORS)
add_subdirectory(shared)
endif()

# Playerbots module
if(BUILD_PLAYERBOTS)
include(FetchContent)

FetchContent_Declare(
PlayerBots
SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/modules/PlayerBots"
GIT_REPOSITORY "https://github.com/cmangos/playerbots.git"
GIT_TAG "master"
)

FetchContent_GetProperties(PlayerBots)
if (NOT playerbots_POPULATED)
FetchContent_Populate(PlayerBots)
message(STATUS "Playerbots module source dir: ${playerbots_SOURCE_DIR}")
else()
message(STATUS "Playerbots module already populated: ${playerbots_POPULATED}")
endif()

add_subdirectory(${playerbots_SOURCE_DIR})

else()
if(EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/modules/PlayerBots)
message(STATUS "PlayerBots module exists, but not building. You can remove it manually if you don't need it. (rm -rf ${CMAKE_CURRENT_SOURCE_DIR}/modules/PlayerBots)")

#file(REMOVE_RECURSE ${CMAKE_CURRENT_SOURCE_DIR}/modules/PlayerBots)
endif()
endif()

if(BUILD_GAME_SERVER)
add_subdirectory(game)
add_subdirectory(mangosd)
endif()

if(BUILD_LOGIN_SERVER)
add_subdirectory(realmd)
endif()
endif()
16 changes: 16 additions & 0 deletions src/game/BattleGround/BattleGround.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1683,6 +1683,22 @@ uint32 BattleGround::GetSingleCreatureGuid(uint8 event1, uint8 event2)
return ObjectGuid();
}

/**
Function returns a gameobject guid from event map
@param event1
@param event2
*/
uint32 BattleGround::GetSingleGameObjectGuid(uint8 event1, uint8 event2)
{
auto itr = m_eventObjects[MAKE_PAIR32(event1, event2)].gameobjects.begin();
if (itr != m_eventObjects[MAKE_PAIR32(event1, event2)].gameobjects.end())
{
return *itr;
}

return ObjectGuid();
}

/**
Method that handles gameobject load from DB event map
Expand Down
3 changes: 3 additions & 0 deletions src/game/BattleGround/BattleGround.h
Original file line number Diff line number Diff line change
Expand Up @@ -561,6 +561,9 @@ class BattleGround
// Get creature guid from event
uint32 GetSingleCreatureGuid(uint8 /*event1*/, uint8 /*event2*/);

// Get gameobject guid from event
uint32 GetSingleGameObjectGuid(uint8 /*event1*/, uint8 /*event2*/);

// Handle door events
void OpenDoorEvent(uint8 /*event1*/, uint8 event2 = 0);
bool IsDoorEvent(uint8 /*event1*/, uint8 /*event2*/) const;
Expand Down
53 changes: 43 additions & 10 deletions src/game/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,17 @@ if(NOT BUILD_DEPRECATED_PLAYERBOT)
endforeach()
endif()

if(NOT BUILD_PLAYERBOTS)
# exclude Playerbots folder
set (EXCLUDE_DIR "PlayerBots/")
foreach (TMP_PATH ${LIBRARY_SRCS})
string (FIND ${TMP_PATH} ${EXCLUDE_DIR} EXCLUDE_DIR_FOUND)
if (NOT ${EXCLUDE_DIR_FOUND} EQUAL -1)
list(REMOVE_ITEM LIBRARY_SRCS ${TMP_PATH})
endif ()
endforeach()
endif()

set(PCH_BASE_FILENAME "pchdef")
# exclude pchdef files
set (EXCLUDE_FILE "${PCH_BASE_FILENAME}")
Expand Down Expand Up @@ -83,23 +94,40 @@ target_link_libraries(${LIBRARY_NAME}
PRIVATE zlib
)

# include additionals headers
set(ADDITIONAL_INCLUDE_DIRS
${CMAKE_CURRENT_SOURCE_DIR}
${CMAKE_CURRENT_SOURCE_DIR}/vmap
${CMAKE_CURRENT_SOURCE_DIR}/AuctionHouseBot
${CMAKE_CURRENT_SOURCE_DIR}/BattleGround
${CMAKE_CURRENT_SOURCE_DIR}/OutdoorPvP
${CMAKE_CURRENT_SOURCE_DIR}/PlayerBot
${CMAKE_BINARY_DIR}
)
# TO DO: Remove this if when old playerbots get removed
if(NOT BUILD_PLAYERBOTS)
set(ADDITIONAL_INCLUDE_DIRS
${CMAKE_CURRENT_SOURCE_DIR}
${CMAKE_CURRENT_SOURCE_DIR}/vmap
${CMAKE_CURRENT_SOURCE_DIR}/AuctionHouseBot
${CMAKE_CURRENT_SOURCE_DIR}/BattleGround
${CMAKE_CURRENT_SOURCE_DIR}/OutdoorPvP
${CMAKE_CURRENT_SOURCE_DIR}/PlayerBot
${CMAKE_BINARY_DIR}
)
else()
set(ADDITIONAL_INCLUDE_DIRS
${CMAKE_CURRENT_SOURCE_DIR}
${CMAKE_CURRENT_SOURCE_DIR}/vmap
${CMAKE_CURRENT_SOURCE_DIR}/AuctionHouseBot
${CMAKE_CURRENT_SOURCE_DIR}/BattleGround
${CMAKE_CURRENT_SOURCE_DIR}/OutdoorPvP
${CMAKE_BINARY_DIR}
)
endif()

target_include_directories(${LIBRARY_NAME}
INTERFACE ${CMAKE_CURRENT_SOURCE_DIR}
PRIVATE ${ADDITIONAL_INCLUDE_DIRS}
PRIVATE ${Boost_INCLUDE_DIRS}
)

if(BUILD_PLAYERBOTS)
target_link_libraries(${LIBRARY_NAME} PUBLIC playerbots)
target_include_directories(${LIBRARY_NAME} PUBLIC ${CMAKE_SOURCE_DIR}/src/modules/PlayerBots)
add_dependencies(${LIBRARY_NAME} playerbots)
endif()

if(UNIX)
# Both systems don't have libdl and don't need them
if (NOT (CMAKE_SYSTEM_NAME STREQUAL "FreeBSD" OR CMAKE_SYSTEM_NAME STREQUAL "NetBSD"))
Expand Down Expand Up @@ -127,6 +155,11 @@ if (BUILD_DEPRECATED_PLAYERBOT)
add_definitions(-DBUILD_DEPRECATED_PLAYERBOT)
endif()

# Define ENABLE_PLAYERBOTS if need
if (BUILD_PLAYERBOTS)
add_definitions(-DENABLE_PLAYERBOTS)
endif()

if (MSVC)
set_target_properties(${LIBRARY_NAME} PROPERTIES PROJECT_LABEL "Game")
endif()
Expand Down
14 changes: 14 additions & 0 deletions src/game/Chat/Chat.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,12 @@
#include "Pools/PoolManager.h"
#include "GameEvents/GameEventMgr.h"

#ifdef ENABLE_PLAYERBOTS
#include "ahbot/AhBot.h"
#include "playerbot/playerbot.h"
#include "playerbot/PlayerbotAIConfig.h"
#endif

#include <cstdarg>

// Supported shift-links (client generated and server side)
Expand Down Expand Up @@ -942,6 +948,14 @@ ChatCommand* ChatHandler::getCommandTable()
{ "auction", SEC_ADMINISTRATOR, false, nullptr, "", auctionCommandTable },
#ifdef BUILD_AHBOT
{ "ahbot", SEC_ADMINISTRATOR, true, nullptr, "", ahbotCommandTable },
#endif
#ifdef ENABLE_PLAYERBOTS
#ifndef BUILD_AHBOT
{ "ahbot", SEC_GAMEMASTER, true, &ChatHandler::HandleAhBotCommand, "", nullptr },
#endif
{ "rndbot", SEC_GAMEMASTER, true, &ChatHandler::HandleRandomPlayerbotCommand, "", nullptr },
{ "bot", SEC_PLAYER, false, &ChatHandler::HandlePlayerbotCommand, "", nullptr },
{ "pmon", SEC_GAMEMASTER, true, &ChatHandler::HandlePerfMonCommand, "", nullptr },
#endif
{ "cast", SEC_ADMINISTRATOR, false, nullptr, "", castCommandTable },
{ "character", SEC_GAMEMASTER, true, nullptr, "", characterCommandTable},
Expand Down
11 changes: 10 additions & 1 deletion src/game/Chat/Chat.h
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,9 @@ class ChatHandler
static bool HasEscapeSequences(const char* message);
static bool CheckEscapeSequences(const char* message);

bool HasSentErrorMessage() const { return sentErrorMessage;}
bool HasSentErrorMessage() const { return sentErrorMessage; }

WorldSession* GetSession() { return m_session; }

/**
* \brief Prepare SMSG_GM_MESSAGECHAT/SMSG_MESSAGECHAT
Expand Down Expand Up @@ -768,6 +770,13 @@ class ChatHandler
bool HandlePlayerbotCommand(char* args);
#endif

#ifdef ENABLE_PLAYERBOTS
bool HandlePlayerbotCommand(char* args);
bool HandleRandomPlayerbotCommand(char* args);
bool HandleAhBotCommand(char* args);
bool HandlePerfMonCommand(char* args);
#endif

bool HandleArenaFlushPointsCommand(char* args);
bool HandleArenaSeasonRewardsCommand(char* args);
bool HandleArenaDataReset(char* args);
Expand Down
Loading

0 comments on commit 62cb97a

Please sign in to comment.