Skip to content

Commit

Permalink
Playerbot: Implement optional build of Playerbot via cmake
Browse files Browse the repository at this point in the history
  • Loading branch information
cala committed Jul 31, 2017
1 parent fc2147e commit b7eb950
Show file tree
Hide file tree
Showing 17 changed files with 132 additions and 101 deletions.
11 changes: 11 additions & 0 deletions src/game/CMakeLists.txt
Expand Up @@ -58,6 +58,17 @@ if(NOT BUILD_SCRIPTDEV)
endforeach()
endif()

if(NOT BUILD_PLAYERBOT)
# exclude Playerbot folder
set (EXCLUDE_DIR "PlayerBot/")
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()

# Create visual studio groups using folder structure
foreach(source ${LIBRARY_SRCS})
get_filename_component(source_path "${source}" PATH)
Expand Down
3 changes: 2 additions & 1 deletion src/game/Chat/Chat.cpp
Expand Up @@ -829,8 +829,9 @@ ChatCommand* ChatHandler::getCommandTable()
{ "quit", SEC_CONSOLE, true, &ChatHandler::HandleQuitCommand, "", nullptr },
{ "gearscore", SEC_ADMINISTRATOR, false, &ChatHandler::HandleShowGearScoreCommand, "", nullptr },
{ "mmap", SEC_GAMEMASTER, false, nullptr, "", mmapCommandTable },
// ------ Playerbot mod ------ //
#ifdef BUILD_PLAYERBOT
{ "bot", SEC_PLAYER, false, &ChatHandler::HandlePlayerbotCommand, "", nullptr },
#endif

{ nullptr, 0, false, nullptr, "", nullptr }
};
Expand Down
3 changes: 2 additions & 1 deletion src/game/Chat/Chat.h
Expand Up @@ -625,8 +625,9 @@ class ChatHandler
bool HandleWaterwalkCommand(char* args);
bool HandleQuitCommand(char* args);
bool HandleShowGearScoreCommand(char* args);
// ------ Playerbot mod ------ //
#ifdef BUILD_PLAYERBOT
bool HandlePlayerbotCommand(char* args);
#endif

bool HandleMmapPathCommand(char* args);
bool HandleMmapLocCommand(char* args);
Expand Down
15 changes: 9 additions & 6 deletions src/game/Chat/ChatHandler.cpp
Expand Up @@ -35,8 +35,9 @@
#include "Grids/GridNotifiersImpl.h"
#include "Grids/CellImpl.h"

// ------ Playerbot mod ------ //
#include "PlayerBot/Base/PlayerbotAI.h"
#ifdef BUILD_PLAYERBOT
#include "PlayerBot/Base/PlayerbotAI.h"
#endif

bool WorldSession::processChatmessageFurtherAfterSecurityChecks(std::string& msg, uint32 lang)
{
Expand Down Expand Up @@ -228,7 +229,7 @@ void WorldSession::HandleMessagechatOpcode(WorldPacket& recv_data)
}
}

// ------ Playerbot mod ------ //
#ifdef BUILD_PLAYERBOT
// Handle whispered command to bot
if (player->GetPlayerbotAI())
{
Expand All @@ -239,7 +240,9 @@ void WorldSession::HandleMessagechatOpcode(WorldPacket& recv_data)
else
// Unmodded core line code below
GetPlayer()->Whisper(msg, lang, player->GetObjectGuid());
// ---- End Playerbot mod ---- //
#else
GetPlayer()->Whisper(msg, lang, player->GetObjectGuid());
#endif
} break;

case CHAT_MSG_PARTY:
Expand Down Expand Up @@ -272,7 +275,7 @@ void WorldSession::HandleMessagechatOpcode(WorldPacket& recv_data)
if ((type == CHAT_MSG_PARTY_LEADER) && !group->IsLeader(_player->GetObjectGuid()))
return;

// ------ Playerbot mod ------ //
#ifdef BUILD_PLAYERBOT
// Broadcast message to bot members
for(GroupReference* itr = group->GetFirstMember(); itr != nullptr; itr=itr->next())
{
Expand All @@ -294,7 +297,7 @@ void WorldSession::HandleMessagechatOpcode(WorldPacket& recv_data)
GetPlayer()->m_speakCount = 0;
}
}
// ---- End Playerbot mod ---- //
#endif

WorldPacket data;
ChatHandler::BuildChatPacket(data, ChatMsg(type), msg.c_str(), Language(lang), _player->GetChatTag(), _player->GetObjectGuid(), _player->GetName());
Expand Down
13 changes: 7 additions & 6 deletions src/game/Entities/CharacterHandler.cpp
Expand Up @@ -38,8 +38,9 @@
#include "Spells/SpellMgr.h"
#include "Calendar/Calendar.h"

// ------ Playerbot mod ------ //
#include "PlayerBot/Base/PlayerbotMgr.h"
#ifdef BUILD_PLAYERBOT
#include "PlayerBot/Base/PlayerbotMgr.h"
#endif

// config option SkipCinematics supported values
enum CinematicsSkipMode
Expand Down Expand Up @@ -128,7 +129,7 @@ class CharacterHandler
if (WorldSession* session = sWorld.FindSession(((LoginQueryHolder*)holder)->GetAccountId()))
session->HandlePlayerLogin((LoginQueryHolder*)holder);
}
// ------ Playerbot mod ------ //
#ifdef BUILD_PLAYERBOT
// This callback is different from the normal HandlePlayerLoginCallback in that it
// sets up the bot's world session and also stores the pointer to the bot player in the master's
// world session m_playerBots map
Expand All @@ -153,7 +154,7 @@ class CharacterHandler
botSession->HandlePlayerLogin(lqh); // will delete lqh
masterSession->GetPlayer()->GetPlayerbotMgr()->OnBotLogin(botSession->GetPlayer());
}
// ---- End Playerbot mod ---- //
#endif
} chrHandler;

void WorldSession::HandleCharEnum(QueryResult* result)
Expand Down Expand Up @@ -593,7 +594,7 @@ void WorldSession::HandlePlayerLoginOpcode(WorldPacket& recv_data)
CharacterDatabase.DelayQueryHolder(&chrHandler, &CharacterHandler::HandlePlayerLoginCallback, holder);
}

// ------ Playerbot mod ------ //
#ifdef BUILD_PLAYERBOT
// Can't easily reuse HandlePlayerLoginOpcode for logging in bots because it assumes
// a WorldSession exists for the bot. The WorldSession for a bot is created after the character is loaded.
void PlayerbotMgr::LoginPlayerBot(ObjectGuid playerGuid)
Expand All @@ -614,7 +615,7 @@ void PlayerbotMgr::LoginPlayerBot(ObjectGuid playerGuid)
}
CharacterDatabase.DelayQueryHolder(&chrHandler, &CharacterHandler::HandlePlayerBotLoginCallback, holder);
}
// ---- End Playerbot mod ---- //
#endif

void WorldSession::HandlePlayerLogin(LoginQueryHolder* holder)
{
Expand Down
30 changes: 17 additions & 13 deletions src/game/Entities/Creature.h
Expand Up @@ -402,34 +402,37 @@ typedef std::list<VendorItemCount> VendorItemCounts;

struct TrainerSpell
{
// ------ Playerbot mod ------ //
#ifdef BUILD_PLAYERBOT
TrainerSpell() : spell(0), spellCost(0), reqSkill(0), reqSkillValue(0), reqLevel(0), learnedSpell(0), isProvidedReqLevel(false), conditionId(0) {}

TrainerSpell(uint32 _spell, uint32 _spellCost, uint32 _reqSkill, uint32 _reqSkillValue, uint32 _reqLevel, uint32 _learnedspell, bool _isProvidedReqLevel, uint32 _conditionId)
: spell(_spell), spellCost(_spellCost), reqSkill(_reqSkill), reqSkillValue(_reqSkillValue), reqLevel(_reqLevel), learnedSpell(_learnedspell), isProvidedReqLevel(_isProvidedReqLevel), conditionId(_conditionId) {}

// Unmodded code below
/*
TrainerSpell() : spell(0), spellCost(0), reqSkill(0), reqSkillValue(0), reqLevel(0), isProvidedReqLevel(false), conditionId(0) {}
TrainerSpell(uint32 _spell, uint32 _spellCost, uint32 _reqSkill, uint32 _reqSkillValue, uint32 _reqLevel, bool _isProvidedReqLevel, uint32 _conditionId)
: spell(_spell), spellCost(_spellCost), reqSkill(_reqSkill), reqSkillValue(_reqSkillValue), reqLevel(_reqLevel), isProvidedReqLevel(_isProvidedReqLevel), conditionId(_conditionId) {}
*/
// ---- End Playerbot mod ---- //

uint32 spell;
uint32 spellCost;
uint32 reqSkill;
uint32 reqSkillValue;
uint32 reqLevel;
// ------ Playerbot mod ------ //
uint32 learnedSpell;
uint32 conditionId;
bool isProvidedReqLevel;

// ------ Playerbot mod ------ //
// helpers
bool IsCastable() const { return learnedSpell != spell; }
#else
TrainerSpell() : spell(0), spellCost(0), reqSkill(0), reqSkillValue(0), reqLevel(0), isProvidedReqLevel(false), conditionId(0) {}

TrainerSpell(uint32 _spell, uint32 _spellCost, uint32 _reqSkill, uint32 _reqSkillValue, uint32 _reqLevel, bool _isProvidedReqLevel, uint32 _conditionId)
: spell(_spell), spellCost(_spellCost), reqSkill(_reqSkill), reqSkillValue(_reqSkillValue), reqLevel(_reqLevel), isProvidedReqLevel(_isProvidedReqLevel), conditionId(_conditionId) {}

uint32 spell;
uint32 spellCost;
uint32 reqSkill;
uint32 reqSkillValue;
uint32 reqLevel;
uint32 conditionId;
bool isProvidedReqLevel;
#endif
};

typedef std::unordered_map < uint32 /*spellid*/, TrainerSpell > TrainerSpellMap;
Expand Down Expand Up @@ -557,9 +560,10 @@ class Creature : public Unit
bool IsTotem() const { return m_subtype == CREATURE_SUBTYPE_TOTEM; }
bool IsTemporarySummon() const { return m_subtype == CREATURE_SUBTYPE_TEMPORARY_SUMMON; }

// ------ Playerbot mod ------ //
#ifdef BUILD_PLAYERBOT
// Adds functionality to load/unload bots from NPC, also need to apply SQL scripts
void LoadBotMenu(Player *pPlayer);
#endif

bool IsCorpse() const { return getDeathState() == CORPSE; }
bool IsDespawned() const { return getDeathState() == DEAD; }
Expand Down
3 changes: 2 additions & 1 deletion src/game/Entities/GossipDef.h
Expand Up @@ -50,8 +50,9 @@ enum Gossip_Option
GOSSIP_OPTION_UNLEARNTALENTS = 16, // UNIT_NPC_FLAG_TRAINER (16) (bonus option for GOSSIP_OPTION_TRAINER)
GOSSIP_OPTION_UNLEARNPETSKILLS = 17, // UNIT_NPC_FLAG_TRAINER (16) (bonus option for GOSSIP_OPTION_TRAINER)
GOSSIP_OPTION_MAILBOX = 18, // UNIT_NPC_FLAG_GOSSIP (1)
// ------ Playerbot mod ------ //
#ifdef BUILD_PLAYERBOT
GOSSIP_OPTION_BOT = 99, //UNIT_NPC_FLAG_GOSSIP (1) UNUSED (just for bot system)
#endif
GOSSIP_OPTION_MAX
};

Expand Down
40 changes: 20 additions & 20 deletions src/game/Entities/Player.cpp
Expand Up @@ -67,11 +67,11 @@
#include "Calendar/Calendar.h"
#include "Loot/LootMgr.h"

// ------ Playerbot mod ------ //
#include "PlayerBot/Base/PlayerbotAI.h"
#include "PlayerBot/Base/PlayerbotMgr.h"
#include "Config/Config.h"
// ---- End Playerbot mod ---- //
#ifdef BUILD_PLAYERBOT
#include "PlayerBot/Base/PlayerbotAI.h"
#include "PlayerBot/Base/PlayerbotMgr.h"
#include "Config/Config.h"
#endif

#include <cmath>

Expand All @@ -89,8 +89,9 @@
#define SKILL_PERM_BONUS(x) int16(PAIR32_HIPART(x))
#define MAKE_SKILL_BONUS(t, p) MAKE_PAIR32(t,p)

// ------ Playerbot mod ------ //
extern Config botConfig;
#ifdef BUILD_PLAYERBOT
extern Config botConfig;
#endif

enum CharacterFlags
{
Expand Down Expand Up @@ -404,11 +405,10 @@ Player::Player(WorldSession* session): Unit(), m_mover(this), m_camera(this), m_
{
m_transport = nullptr;

// ------ Playerbot mod ------ //
#ifdef BUILD_PLAYERBOT
m_playerbotAI = 0;
m_playerbotMgr = 0;
// ---- End Playerbot mod ---- //

#endif
m_speakTime = 0;
m_speakCount = 0;

Expand Down Expand Up @@ -631,7 +631,7 @@ Player::~Player()
delete m_declinedname;
delete m_runes;

// ------ Playerbot mod ------ //
#ifdef BUILD_PLAYERBOT
if (m_playerbotAI)
{
delete m_playerbotAI;
Expand All @@ -642,7 +642,7 @@ Player::~Player()
delete m_playerbotMgr;
m_playerbotMgr = 0;
}
// ---- End Playerbot mod ---- //
#endif
}

void Player::CleanupsBeforeDelete()
Expand Down Expand Up @@ -1452,12 +1452,12 @@ void Player::Update(uint32 update_diff, uint32 p_time)
if (IsHasDelayedTeleport())
TeleportTo(m_teleport_dest, m_teleport_options);

// ------ Playerbot mod ------ //
#ifdef BUILD_PLAYERBOT
if (m_playerbotAI)
m_playerbotAI->UpdateAI(p_time);
else if (m_playerbotMgr)
m_playerbotMgr->UpdateAI(p_time);
// ---- End Playerbot mod ---- //
#endif
}

void Player::SetDeathState(DeathState s)
Expand Down Expand Up @@ -1713,12 +1713,12 @@ bool Player::TeleportTo(uint32 mapid, float x, float y, float z, float orientati

MapEntry const* mEntry = sMapStore.LookupEntry(mapid); // Validity checked in IsValidMapCoord

// ------ Playerbot mod ------ //
#ifdef BUILD_PLAYERBOT
// If this user has bots, tell them to stop following master
// so they don't try to follow the master after the master teleports
if (GetPlayerbotMgr())
GetPlayerbotMgr()->Stay();
// ---- End Playerbot mod ---- //
#endif

// don't let enter battlegrounds without assigned battleground id (for example through areatrigger)...
// don't let gm level > 1 either
Expand Down Expand Up @@ -12900,7 +12900,7 @@ void Player::PrepareGossipMenu(WorldObject* pSource, uint32 menuId)
case GOSSIP_OPTION_AUCTIONEER:
case GOSSIP_OPTION_MAILBOX:
break; // no checks
// ------ Playerbot mod ------ //
#ifdef BUILD_PLAYERBOT
case GOSSIP_OPTION_BOT:
{
if(botConfig.GetBoolDefault("PlayerbotAI.DisableBots", false) && !pCreature->isInnkeeper())
Expand All @@ -12917,7 +12917,7 @@ void Player::PrepareGossipMenu(WorldObject* pSource, uint32 menuId)
hasMenuItem = false;
break;
}
// ---- End Playerbot mod ---- //
#endif
default:
sLog.outErrorDb("Creature entry %u have unknown gossip option %u for menu %u", pCreature->GetEntry(), gossipMenu.option_id, gossipMenu.menu_id);
hasMenuItem = false;
Expand Down Expand Up @@ -13163,7 +13163,7 @@ void Player::OnGossipSelect(WorldObject* pSource, uint32 gossipListId, uint32 me
GetSession()->SendBattlegGroundList(guid, bgTypeId);
break;
}
// ------ Playerbot mod ------ //
#ifdef BUILD_PLAYERBOT
case GOSSIP_OPTION_BOT:
{
// DEBUG_LOG("GOSSIP_OPTION_BOT");
Expand Down Expand Up @@ -13217,7 +13217,7 @@ void Player::OnGossipSelect(WorldObject* pSource, uint32 gossipListId, uint32 me
}
return;
}
// ---- End Playerbot mod ---- //
#endif
}

if (pMenuData.m_gAction_script)
Expand Down

0 comments on commit b7eb950

Please sign in to comment.