Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Initial attempt to merge playerbots from zero into two #188

Open
wants to merge 10 commits into
base: master
Choose a base branch
from
  •  
  •  
  •  
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@
/*.sublime-project
/*.sublime-workspace

# VSCode
/.vscode

# Numerous always-ignore extensions
*.a
*.bak
Expand Down
7 changes: 6 additions & 1 deletion src/game/AuctionHouseBot/AuctionHouseBot.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2212,7 +2212,7 @@ void AuctionHouseBot::Rebuild(bool all)
void AuctionHouseBot::Update()
{
// nothing do...
if (!m_Buyer && !m_Seller)
if (!Enabled())
{
return;
}
Expand Down Expand Up @@ -2250,4 +2250,9 @@ void AuctionHouseBot::Update()
}
}
}

bool AuctionHouseBot::Enabled()
{
return (m_Buyer != NULL || m_Seller != NULL);
}
/** @} */
7 changes: 7 additions & 0 deletions src/game/AuctionHouseBot/AuctionHouseBot.h
Original file line number Diff line number Diff line change
Expand Up @@ -456,6 +456,13 @@ class AuctionHouseBot
*
*/
void Initialize();
/**
* @brief Whether the AuctionHouseBot is enabled
*
* @return true if buyer or seller agent exists
* @return false if neither buyer nor seller agents exist
*/
bool Enabled();

// Followed method is mainly used by level3.cpp for ingame/console command
/**
Expand Down
8 changes: 7 additions & 1 deletion src/game/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ endif()

if(PLAYERBOTS)

#Base files
#Playerbot Module group
file(GLOB Playerbot_Source ${CMAKE_SOURCE_DIR}/src/modules/Bots/playerbot/*.cpp ${CMAKE_SOURCE_DIR}/src/modules/Bots/playerbot/*.h)
source_group("Player Bot" FILES ${Playerbot_Source})
file(GLOB AHbot_Source ${CMAKE_SOURCE_DIR}/src/modules/Bots/ahbot/*.cpp ${CMAKE_SOURCE_DIR}/src/modules/Bots/ahbot/*.h)
Expand Down Expand Up @@ -126,6 +126,11 @@ source_group("Player Bot\\Strategies\\Values" FILES ${Playerbot_Values})
LIST(APPEND SRC_GRP_BOTS ${Playerbot_Values})

## Class files
#Deathknight AI
file(GLOB Playerbot_Druid ${CMAKE_SOURCE_DIR}/src/modules/Bots/playerbot/strategy/deathknight/*.cpp ${CMAKE_SOURCE_DIR}/src/modules/Bots/playerbot/strategy/deathknight/*.h)
source_group("Player Bot\\Strategies\\Druid" FILES ${Playerbot_Death_Knight})
LIST(APPEND SRC_GRP_BOTS ${Playerbot_Death_Knight})

#Druid AI
file(GLOB Playerbot_Druid ${CMAKE_SOURCE_DIR}/src/modules/Bots/playerbot/strategy/druid/*.cpp ${CMAKE_SOURCE_DIR}/src/modules/Bots/playerbot/strategy/druid/*.h)
source_group("Player Bot\\Strategies\\Druid" FILES ${Playerbot_Druid})
Expand Down Expand Up @@ -172,6 +177,7 @@ source_group("Player Bot\\Strategies\\Warrior" FILES ${Playerbot_Warrior})
LIST(APPEND SRC_GRP_BOTS ${Playerbot_Warrior})

configure_file(${CMAKE_SOURCE_DIR}/src/modules/Bots/playerbot/aiplayerbot.conf.dist.in ${CMAKE_CURRENT_BINARY_DIR}/aiplayerbot.conf.dist)
configure_file(${CMAKE_SOURCE_DIR}/src/modules/Bots/ahbot/ahbot.conf.dist.in ${CMAKE_CURRENT_BINARY_DIR}/AuctionHouseBot/ahplayerbot.conf.dist)

endif()

Expand Down
9 changes: 8 additions & 1 deletion src/game/ChatCommands/AHBotCommands.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,9 @@
#include "Chat.h"
#include "Language.h"
#include "AuctionHouseBot/AuctionHouseBot.h"

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

/**********************************************************************
Useful constants definition
Expand All @@ -49,6 +51,11 @@ static uint32 ahbotQualityIds[MAX_AUCTION_QUALITY] =

bool ChatHandler::HandleAHBotRebuildCommand(char* args)
{
if (!sAuctionBot.Enabled())
{
return false;
}

bool all = false;
if (*args)
{
Expand Down
7 changes: 7 additions & 0 deletions src/game/Object/Item.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1263,6 +1263,13 @@ bool Item::IsLimitedToAnotherMapOrZone(uint32 cur_mapId, uint32 cur_zoneId) cons
// time.
void Item::SendTimeUpdate(Player* owner)
{
#ifdef ENABLE_PLAYERBOTS
if (!owner || !owner->IsInWorld() || owner->GetPlayerbotAI())
{
return;
}
#endif

uint32 duration = GetUInt32Value(ITEM_FIELD_DURATION);
if (!duration)
{
Expand Down
40 changes: 40 additions & 0 deletions src/game/Object/Player.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,9 @@
#ifdef ENABLE_ELUNA
#include "LuaEngine.h"
#endif /* ENABLE_ELUNA */
#ifdef ENABLE_PLAYERBOTS
#include "playerbot.h"
#endif

#include <cmath>

Expand Down Expand Up @@ -435,6 +438,11 @@ UpdateMask Player::updateVisualBits;

Player::Player(WorldSession* session): Unit(), m_mover(this), m_camera(this), m_achievementMgr(this), m_reputationMgr(this)
{
#ifdef ENABLE_PLAYERBOTS
m_playerbotAI = 0;
m_playerbotMgr = 0;
#endif

m_transport = 0;

m_speakTime = 0;
Expand Down Expand Up @@ -628,6 +636,11 @@ Player::Player(WorldSession* session): Unit(), m_mover(this), m_camera(this), m_
m_lastFallZ = 0;

m_cachedGS = 0;
#ifdef ENABLE_PLAYERBOTS
m_playerbotAI = NULL;
m_playerbotMgr = NULL;
#endif

}

Player::~Player()
Expand Down Expand Up @@ -667,6 +680,21 @@ Player::~Player()
delete ItemSetEff[x];
}

#ifdef ENABLE_PLAYERBOTS
if (m_playerbotAI) {
{
delete m_playerbotAI;
}
m_playerbotAI = 0;
}
if (m_playerbotMgr) {
{
delete m_playerbotMgr;
}
m_playerbotMgr = 0;
}
#endif

// clean up player-instance binds, may unload some instance saves
for (uint8 i = 0; i < MAX_DIFFICULTY; ++i)
for (BoundInstancesMap::iterator itr = m_boundInstances[i].begin(); itr != m_boundInstances[i].end(); ++itr)
Expand Down Expand Up @@ -1624,6 +1652,18 @@ void Player::Update(uint32 update_diff, uint32 p_time)
{
TeleportTo(m_teleport_dest, m_teleport_options);
}

#ifdef ENABLE_PLAYERBOTS
if (m_playerbotAI)
{
m_playerbotAI->UpdateAI(p_time);
}
if (m_playerbotMgr)
{
m_playerbotMgr->UpdateAI(p_time);
}
#endif

}

void Player::SetDeathState(DeathState s)
Expand Down
22 changes: 22 additions & 0 deletions src/game/Object/Player.h
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,11 @@ class Item;

struct AreaTrigger;

#ifdef ENABLE_PLAYERBOTS
class PlayerbotAI;
class PlayerbotMgr;
#endif

typedef std::deque<Mail*> PlayerMails;

#define PLAYER_MAX_SKILLS 127
Expand Down Expand Up @@ -1595,6 +1600,9 @@ class Player : public Unit
/*********************************************************/

bool LoadFromDB(ObjectGuid guid, SqlQueryHolder* holder);
#ifdef ENABLE_PLAYERBOTS
bool MinimalLoadFromDB(QueryResult *result, uint32 guid);
#endif

static uint32 GetZoneIdFromDB(ObjectGuid guid);
static uint32 GetLevelFromDB(ObjectGuid guid);
Expand Down Expand Up @@ -2568,6 +2576,16 @@ class Player : public Unit

bool isAllowedToLoot(Creature* creature);

#ifdef ENABLE_PLAYERBOTS
//EquipmentSets& GetEquipmentSets() { return m_EquipmentSets; }
void SetPlayerbotAI(PlayerbotAI* ai) { assert(!m_playerbotAI && !m_playerbotMgr); m_playerbotAI = ai; }
PlayerbotAI* GetPlayerbotAI() { return m_playerbotAI; }
void SetPlayerbotMgr(PlayerbotMgr* mgr) { assert(!m_playerbotAI && !m_playerbotMgr); m_playerbotMgr = mgr; }
PlayerbotMgr* GetPlayerbotMgr() { return m_playerbotMgr; }
void SetBotDeathTimer() { m_deathTimer = 0; }
//PlayerTalentMap& GetTalentMap(uint8 spec) { return m_talents[spec]; }
#endif

DeclinedName const* GetDeclinedNames() const { return m_declinedname; }

// Rune functions, need check getClass() == CLASS_DEATH_KNIGHT before access
Expand Down Expand Up @@ -2875,6 +2893,10 @@ class Player : public Unit
GridReference<Player> m_gridRef;
MapReference m_mapRef;

#ifdef ENABLE_PLAYERBOTS
PlayerbotAI* m_playerbotAI;
PlayerbotMgr* m_playerbotMgr;
#endif
// Homebind coordinates
uint32 m_homebindMapId;
uint16 m_homebindAreaId;
Expand Down
Loading