Skip to content

Commit

Permalink
Implement PlayerBots option By MangosBot team!
Browse files Browse the repository at this point in the history
Be sure to also update DB too using updated install script.

close #528
  • Loading branch information
cyberium committed Mar 1, 2024
1 parent 1b7d0eb commit 222f4c5
Show file tree
Hide file tree
Showing 54 changed files with 1,885 additions and 40 deletions.
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
5 changes: 5 additions & 0 deletions contrib/mmap/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,11 @@ if (BUILD_EXTRACTORS)
add_custom_command(TARGET ${EXECUTABLE_NAME} POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy_if_different ${FILES_LIST_TO_COPY} \"$<TARGET_FILE_DIR:${EXECUTABLE_NAME}>\")
endif()

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

install(TARGETS ${EXECUTABLE_NAME} DESTINATION ${BIN_DIR}/tools)
install(PROGRAMS "${CMAKE_SOURCE_DIR}/contrib/extractor_scripts/MoveMapGen.sh" DESTINATION ${BIN_DIR}/tools)
Expand Down
35 changes: 35 additions & 0 deletions contrib/mmap/src/MapBuilder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,38 @@

using namespace VMAP;

#ifdef ENABLE_MANGOSBOTS
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.
}
}
}
#endif

void from_json(const json& j, rcConfig& config)
{
config.tileSize = MMAP::VERTEX_PER_TILE;
Expand Down Expand Up @@ -997,6 +1029,9 @@ 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);
#ifdef ENABLE_MANGOSBOTS
rcModAlmostUnwalkableTriangles(m_rcContext, 50.0f, tVerts, tVertCount, tTris, tTriCount, triFlags);
#endif
rcRasterizeTriangles(m_rcContext, tVerts, tVertCount, tTris, triFlags, tTriCount, *tile.solid, tileCfg.walkableClimb);
delete[] triFlags;

Expand Down
6 changes: 3 additions & 3 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 `classicrealmd` DEFAULT CHARACTER SET utf8 COLLATE utf8_general_

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

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

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

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

GRANT SELECT, INSERT, UPDATE, DELETE, CREATE, DROP, ALTER, LOCK TABLES, CREATE TEMPORARY TABLES ON `classicrealmd`.* TO 'mangos'@'localhost';
GRANT SELECT, INSERT, UPDATE, DELETE, CREATE, DROP, ALTER, LOCK TABLES, CREATE TEMPORARY TABLES ON `classicrealmd`.* TO 'mangos'@'localhost';
2 changes: 1 addition & 1 deletion sql/create/db_drop_mysql.sql
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@ DROP USER IF EXISTS `mangos`@`localhost`;
DROP DATABASE IF EXISTS `classicmangos`;
DROP DATABASE IF EXISTS `classiclogs`;
DROP DATABASE IF EXISTS `classiccharacters`;
DROP DATABASE IF EXISTS `classicrealmd`;
DROP DATABASE IF EXISTS `classicrealmd`;
30 changes: 30 additions & 0 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,33 @@ endif()
if(BUILD_LOGIN_SERVER)
add_subdirectory(realmd)
endif()

# Playerbots module
if(BUILD_PLAYERBOTS)
include(FetchContent)

FetchContent_Declare(
playerbots
GIT_REPOSITORY "https://github.com/cmangos/playerbots.git"
GIT_TAG "master"
)

if(NOT playerbots_POPULATED)
message(STATUS "Fetching Playerbots module...")

FetchContent_Populate(playerbots)

if(EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/modules/Bots)
file(REMOVE_RECURSE ${CMAKE_CURRENT_SOURCE_DIR}/modules/Bots)
endif()

file(COPY ${playerbots_SOURCE_DIR}/. DESTINATION ${CMAKE_CURRENT_SOURCE_DIR}/modules/Bots)
message(STATUS "Playerbots module fetched and populated in ${CMAKE_CURRENT_SOURCE_DIR}/modules/Bots")
endif()

add_subdirectory(modules/Bots)
else()
if(EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/modules/Bots)
file(REMOVE_RECURSE ${CMAKE_CURRENT_SOURCE_DIR}/modules/Bots)
endif()
endif()
19 changes: 19 additions & 0 deletions src/game/BattleGround/BattleGround.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1465,6 +1465,25 @@ uint32 BattleGround::GetSingleCreatureGuid(uint8 event1, uint8 event2)
return ObjectGuid();
}

#ifdef ENABLE_PLAYERBOTS
/**
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();
}
#endif

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

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

// Handle door events
void OpenDoorEvent(uint8 /*event1*/, uint8 event2 = 0);
bool IsDoorEvent(uint8 /*event1*/, uint8 /*event2*/) const;
Expand Down
109 changes: 100 additions & 9 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 "Bots/")
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 @@ -84,22 +95,97 @@ target_link_libraries(${LIBRARY_NAME}
)

# 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)
include_directories(
${CMAKE_SOURCE_DIR}/src/game
${CMAKE_SOURCE_DIR}/src/game/AI
${CMAKE_SOURCE_DIR}/src/game/Accounts
${CMAKE_SOURCE_DIR}/src/game/Addons
${CMAKE_SOURCE_DIR}/src/game/Arena
${CMAKE_SOURCE_DIR}/src/game/AuctionHouse
${CMAKE_SOURCE_DIR}/src/game/BattleGround
${CMAKE_SOURCE_DIR}/src/game/Chat
${CMAKE_SOURCE_DIR}/src/game/ChatCommands
${CMAKE_SOURCE_DIR}/src/game/Combat
${CMAKE_SOURCE_DIR}/src/game/DBScripts
${CMAKE_SOURCE_DIR}/src/game/Entities
${CMAKE_SOURCE_DIR}/src/game/GMTickets
${CMAKE_SOURCE_DIR}/src/game/GameEvents
${CMAKE_SOURCE_DIR}/src/game/Globals
${CMAKE_SOURCE_DIR}/src/game/Grids
${CMAKE_SOURCE_DIR}/src/game/Groups
${CMAKE_SOURCE_DIR}/src/game/Guilds
${CMAKE_SOURCE_DIR}/src/game/LFG
${CMAKE_SOURCE_DIR}/src/game/Loot
${CMAKE_SOURCE_DIR}/src/game/Mails
${CMAKE_SOURCE_DIR}/src/game/Maps
${CMAKE_SOURCE_DIR}/src/game/MotionGenerators
${CMAKE_SOURCE_DIR}/src/game/Movement
${CMAKE_SOURCE_DIR}/src/game/Object
${CMAKE_SOURCE_DIR}/src/game/OutdoorPvP
${CMAKE_SOURCE_DIR}/src/game/Pools
${CMAKE_SOURCE_DIR}/src/game/Quests
${CMAKE_SOURCE_DIR}/src/game/References
${CMAKE_SOURCE_DIR}/src/game/Reputation
${CMAKE_SOURCE_DIR}/src/game/Server
${CMAKE_SOURCE_DIR}/src/game/Server
${CMAKE_SOURCE_DIR}/src/game/Skills
${CMAKE_SOURCE_DIR}/src/game/Social
${CMAKE_SOURCE_DIR}/src/game/Spells
${CMAKE_SOURCE_DIR}/src/game/Tools
${CMAKE_SOURCE_DIR}/src/game/Trade
${CMAKE_SOURCE_DIR}/src/game/VoiceChat
${CMAKE_SOURCE_DIR}/src/game/Warden
${CMAKE_SOURCE_DIR}/src/game/Weather
${CMAKE_SOURCE_DIR}/src/game/World
${CMAKE_SOURCE_DIR}/src/game/WorldHandlers
${CMAKE_SOURCE_DIR}/src/game/movement
${CMAKE_SOURCE_DIR}/src/game/vmap
${CMAKE_SOURCE_DIR}/src/shared
${CMAKE_SOURCE_DIR}/src/shared/Auth
${CMAKE_SOURCE_DIR}/src/shared/Config
${CMAKE_SOURCE_DIR}/src/shared/Common
${CMAKE_SOURCE_DIR}/src/shared/Database
${CMAKE_SOURCE_DIR}/src/shared/DataStores
${CMAKE_SOURCE_DIR}/src/shared/Utilities
${CMAKE_SOURCE_DIR}/src/shared/Log
${CMAKE_SOURCE_DIR}/src/shared/Threading
${CMAKE_SOURCE_DIR}/src/modules/Bots/playerbot
${CMAKE_SOURCE_DIR}/src/modules/Bots/ahbot
)

target_link_libraries(${LIBRARY_NAME} PUBLIC Bots)
add_dependencies(${LIBRARY_NAME} Bots)
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 +213,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 @@ -35,6 +35,12 @@
#include "Pools/PoolManager.h"
#include "GameEvents/GameEventMgr.h"

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

#include <cstdarg>

// Supported shift-links (client generated and server side)
Expand Down Expand Up @@ -900,6 +906,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, "", NULL },
#endif
{ "rndbot", SEC_GAMEMASTER, true, &ChatHandler::HandleRandomPlayerbotCommand, "", NULL },
{ "bot", SEC_PLAYER, false, &ChatHandler::HandlePlayerbotCommand, "", NULL },
{ "pmon", SEC_GAMEMASTER, true, &ChatHandler::HandlePerfMonCommand, "" },
#endif
{ "cast", SEC_ADMINISTRATOR, false, nullptr, "", castCommandTable },
{ "character", SEC_GAMEMASTER, true, nullptr, "", characterCommandTable},
Expand Down
Loading

0 comments on commit 222f4c5

Please sign in to comment.