From 605fa223ce2a600bd5bc270dd76b5b55fd424881 Mon Sep 17 00:00:00 2001 From: Boxhead78 Date: Thu, 3 Jul 2025 09:39:54 +0200 Subject: [PATCH] Move GetBotStrategyForTeam from core --- src/Playerbots.cpp | 39 ++++++++++++++++++++ src/strategy/actions/BattleGroundTactics.cpp | 28 ++++++++++---- src/strategy/actions/BattleGroundTactics.h | 9 +++++ src/strategy/triggers/PvpTriggers.cpp | 5 ++- 4 files changed, 71 insertions(+), 10 deletions(-) diff --git a/src/Playerbots.cpp b/src/Playerbots.cpp index 843a2cb6..b2fc0cd2 100644 --- a/src/Playerbots.cpp +++ b/src/Playerbots.cpp @@ -29,6 +29,7 @@ #include "ScriptMgr.h" #include "cs_playerbots.h" #include "cmath" +#include "BattleGroundTactics.h" class PlayerbotsDatabaseScript : public DatabaseScript { @@ -389,6 +390,43 @@ public: } }; +class PlayerBotsBGScript : public BGScript +{ +public: + PlayerBotsBGScript() : BGScript("PlayerBotsBGScript") {} + + void OnBattlegroundStart(Battleground* bg) override + { + BGStrategyData data; + + switch (bg->GetBgTypeID()) + { + case BATTLEGROUND_WS: + data.allianceStrategy = urand(0, WS_STRATEGY_MAX - 1); + data.hordeStrategy = urand(0, WS_STRATEGY_MAX - 1); + break; + case BATTLEGROUND_AB: + data.allianceStrategy = urand(0, AB_STRATEGY_MAX - 1); + data.hordeStrategy = urand(0, AB_STRATEGY_MAX - 1); + break; + case BATTLEGROUND_AV: + data.allianceStrategy = urand(0, AV_STRATEGY_MAX - 1); + data.hordeStrategy = urand(0, AV_STRATEGY_MAX - 1); + break; + case BATTLEGROUND_EY: + data.allianceStrategy = urand(0, EY_STRATEGY_MAX - 1); + data.hordeStrategy = urand(0, EY_STRATEGY_MAX - 1); + break; + default: + break; + } + + bgStrategies[bg->GetInstanceID()] = data; + } + + void OnBattlegroundEnd(Battleground* bg, TeamId /*winnerTeam*/) override { bgStrategies.erase(bg->GetInstanceID()); } +}; + void AddPlayerbotsScripts() { new PlayerbotsDatabaseScript(); @@ -397,6 +435,7 @@ void AddPlayerbotsScripts() new PlayerbotsServerScript(); new PlayerbotsWorldScript(); new PlayerbotsScript(); + new PlayerBotsBGScript(); AddSC_playerbots_commandscript(); } diff --git a/src/strategy/actions/BattleGroundTactics.cpp b/src/strategy/actions/BattleGroundTactics.cpp index 3adcab6b..c94b845e 100644 --- a/src/strategy/actions/BattleGroundTactics.cpp +++ b/src/strategy/actions/BattleGroundTactics.cpp @@ -108,6 +108,8 @@ enum BattleBotWsgWaitSpot BB_WSG_WAIT_SPOT_RIGHT }; +std::unordered_map bgStrategies; + std::vector const vFlagsAV = { BG_AV_OBJECTID_BANNER_H_B, BG_AV_OBJECTID_BANNER_H, BG_AV_OBJECTID_BANNER_A_B, BG_AV_OBJECTID_BANNER_A, BG_AV_OBJECTID_BANNER_CONT_A, BG_AV_OBJECTID_BANNER_CONT_A_B, @@ -1423,6 +1425,16 @@ std::string const BGTactics::HandleConsoleCommandPrivate(WorldSession* session, return "usage: showpath(=[num]) / showcreature=[num] / showobject=[num]"; } +// Depends on OnBattlegroundStart in playerbots.cpp +uint8 BGTactics::GetBotStrategyForTeam(Battleground* bg, TeamId teamId) +{ + auto itr = bgStrategies.find(bg->GetInstanceID()); + if (itr == bgStrategies.end()) + return 0; + + return teamId == TEAM_ALLIANCE ? itr->second.allianceStrategy : itr->second.hordeStrategy; +} + bool BGTactics::wsJumpDown() { Battleground* bg = bot->GetBattleground(); @@ -1848,8 +1860,8 @@ bool BGTactics::selectObjective(bool reset) BattlegroundAV* av = static_cast(bg); TeamId team = bot->GetTeamId(); uint8 role = context->GetValue("bg role")->Get(); - AVBotStrategy strategyHorde = static_cast(bg->GetBotStrategyForTeam(TEAM_HORDE)); - AVBotStrategy strategyAlliance = static_cast(bg->GetBotStrategyForTeam(TEAM_ALLIANCE)); + AVBotStrategy strategyHorde = static_cast(GetBotStrategyForTeam(bg, TEAM_HORDE)); + AVBotStrategy strategyAlliance = static_cast(GetBotStrategyForTeam(bg, TEAM_ALLIANCE)); AVBotStrategy strategy = (team == TEAM_ALLIANCE) ? strategyAlliance : strategyHorde; AVBotStrategy enemyStrategy = (team == TEAM_ALLIANCE) ? strategyHorde : strategyAlliance; @@ -2153,8 +2165,8 @@ bool BGTactics::selectObjective(bool reset) // Retrieve role uint8 role = context->GetValue("bg role")->Get(); - WSBotStrategy strategyHorde = static_cast(bg->GetBotStrategyForTeam(TEAM_HORDE)); - WSBotStrategy strategyAlliance = static_cast(bg->GetBotStrategyForTeam(TEAM_ALLIANCE)); + WSBotStrategy strategyHorde = static_cast(GetBotStrategyForTeam(bg, TEAM_HORDE)); + WSBotStrategy strategyAlliance = static_cast(GetBotStrategyForTeam(bg, TEAM_ALLIANCE)); WSBotStrategy strategy = (team == TEAM_ALLIANCE) ? strategyAlliance : strategyHorde; WSBotStrategy enemyStrategy = (team == TEAM_ALLIANCE) ? strategyHorde : strategyAlliance; @@ -2302,8 +2314,8 @@ bool BGTactics::selectObjective(bool reset) TeamId team = bot->GetTeamId(); uint8 role = context->GetValue("bg role")->Get(); - ABBotStrategy strategyHorde = static_cast(bg->GetBotStrategyForTeam(TEAM_HORDE)); - ABBotStrategy strategyAlliance = static_cast(bg->GetBotStrategyForTeam(TEAM_ALLIANCE)); + ABBotStrategy strategyHorde = static_cast(GetBotStrategyForTeam(bg, TEAM_HORDE)); + ABBotStrategy strategyAlliance = static_cast(GetBotStrategyForTeam(bg, TEAM_ALLIANCE)); ABBotStrategy strategy = (team == TEAM_ALLIANCE) ? strategyAlliance : strategyHorde; ABBotStrategy enemyStrategy = (team == TEAM_ALLIANCE) ? strategyHorde : strategyAlliance; @@ -2477,8 +2489,8 @@ bool BGTactics::selectObjective(bool reset) TeamId team = bot->GetTeamId(); uint8 role = context->GetValue("bg role")->Get(); - EYBotStrategy strategyHorde = static_cast(bg->GetBotStrategyForTeam(TEAM_HORDE)); - EYBotStrategy strategyAlliance = static_cast(bg->GetBotStrategyForTeam(TEAM_ALLIANCE)); + EYBotStrategy strategyHorde = static_cast(GetBotStrategyForTeam(bg, TEAM_HORDE)); + EYBotStrategy strategyAlliance = static_cast(GetBotStrategyForTeam(bg, TEAM_ALLIANCE)); EYBotStrategy strategy = (team == TEAM_ALLIANCE) ? strategyAlliance : strategyHorde; EYBotStrategy enemyStrategy = (team == TEAM_ALLIANCE) ? strategyHorde : strategyAlliance; diff --git a/src/strategy/actions/BattleGroundTactics.h b/src/strategy/actions/BattleGroundTactics.h index 561e21f6..7dd1f180 100644 --- a/src/strategy/actions/BattleGroundTactics.h +++ b/src/strategy/actions/BattleGroundTactics.h @@ -18,6 +18,14 @@ struct Position; typedef void (*BattleBotWaypointFunc)(); +struct BGStrategyData +{ + uint8 allianceStrategy = 0; + uint8 hordeStrategy = 0; +}; + +extern std::unordered_map bgStrategies; + struct BattleBotWaypoint { BattleBotWaypoint(float x_, float y_, float z_, BattleBotWaypointFunc func) : x(x_), y(y_), z(z_), pFunc(func){}; @@ -65,6 +73,7 @@ class BGTactics : public MovementAction { public: static bool HandleConsoleCommand(ChatHandler* handler, char const* args); + uint8 static GetBotStrategyForTeam(Battleground* bg, TeamId teamId); BGTactics(PlayerbotAI* botAI, std::string const name = "bg tactics") : MovementAction(botAI, name) {} diff --git a/src/strategy/triggers/PvpTriggers.cpp b/src/strategy/triggers/PvpTriggers.cpp index ce9ac028..7fe56ac8 100644 --- a/src/strategy/triggers/PvpTriggers.cpp +++ b/src/strategy/triggers/PvpTriggers.cpp @@ -5,6 +5,7 @@ #include "PvpTriggers.h" +#include "BattleGroundTactics.h" #include "BattlegroundEY.h" #include "BattlegroundMgr.h" #include "BattlegroundWS.h" @@ -180,7 +181,7 @@ bool PlayerHasFlag::IsCapturingFlag(Player* bot) if (controlledBases == 0) return false; // bot has flag but no place to take it - // Otherwise, return false – stay defensive / move to base + // Otherwise, return false and stay defensive / move to base return bot->GetGUID() == bg->GetFlagPickerGUID(); } } @@ -317,7 +318,7 @@ bool AllianceNoSnowfallGY::IsActive() return false; Battleground* bg = bot->GetBattleground(); - if (bg && bg->GetBotStrategyForTeam(TEAM_ALLIANCE) != AV_STRATEGY_BALANCED) + if (bg && BGTactics::GetBotStrategyForTeam(bg, TEAM_ALLIANCE) != AV_STRATEGY_BALANCED) return false; float botX = bot->GetPositionX();