Move GetBotStrategyForTeam from core

This commit is contained in:
Boxhead78
2025-07-03 09:39:54 +02:00
parent 309d177dd8
commit 605fa223ce
4 changed files with 71 additions and 10 deletions

View File

@@ -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();
}

View File

@@ -108,6 +108,8 @@ enum BattleBotWsgWaitSpot
BB_WSG_WAIT_SPOT_RIGHT
};
std::unordered_map<uint32, BGStrategyData> bgStrategies;
std::vector<uint32> 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<BattlegroundAV*>(bg);
TeamId team = bot->GetTeamId();
uint8 role = context->GetValue<uint32>("bg role")->Get();
AVBotStrategy strategyHorde = static_cast<AVBotStrategy>(bg->GetBotStrategyForTeam(TEAM_HORDE));
AVBotStrategy strategyAlliance = static_cast<AVBotStrategy>(bg->GetBotStrategyForTeam(TEAM_ALLIANCE));
AVBotStrategy strategyHorde = static_cast<AVBotStrategy>(GetBotStrategyForTeam(bg, TEAM_HORDE));
AVBotStrategy strategyAlliance = static_cast<AVBotStrategy>(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<uint32>("bg role")->Get();
WSBotStrategy strategyHorde = static_cast<WSBotStrategy>(bg->GetBotStrategyForTeam(TEAM_HORDE));
WSBotStrategy strategyAlliance = static_cast<WSBotStrategy>(bg->GetBotStrategyForTeam(TEAM_ALLIANCE));
WSBotStrategy strategyHorde = static_cast<WSBotStrategy>(GetBotStrategyForTeam(bg, TEAM_HORDE));
WSBotStrategy strategyAlliance = static_cast<WSBotStrategy>(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<uint32>("bg role")->Get();
ABBotStrategy strategyHorde = static_cast<ABBotStrategy>(bg->GetBotStrategyForTeam(TEAM_HORDE));
ABBotStrategy strategyAlliance = static_cast<ABBotStrategy>(bg->GetBotStrategyForTeam(TEAM_ALLIANCE));
ABBotStrategy strategyHorde = static_cast<ABBotStrategy>(GetBotStrategyForTeam(bg, TEAM_HORDE));
ABBotStrategy strategyAlliance = static_cast<ABBotStrategy>(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<uint32>("bg role")->Get();
EYBotStrategy strategyHorde = static_cast<EYBotStrategy>(bg->GetBotStrategyForTeam(TEAM_HORDE));
EYBotStrategy strategyAlliance = static_cast<EYBotStrategy>(bg->GetBotStrategyForTeam(TEAM_ALLIANCE));
EYBotStrategy strategyHorde = static_cast<EYBotStrategy>(GetBotStrategyForTeam(bg, TEAM_HORDE));
EYBotStrategy strategyAlliance = static_cast<EYBotStrategy>(GetBotStrategyForTeam(bg, TEAM_ALLIANCE));
EYBotStrategy strategy = (team == TEAM_ALLIANCE) ? strategyAlliance : strategyHorde;
EYBotStrategy enemyStrategy = (team == TEAM_ALLIANCE) ? strategyHorde : strategyAlliance;

View File

@@ -18,6 +18,14 @@ struct Position;
typedef void (*BattleBotWaypointFunc)();
struct BGStrategyData
{
uint8 allianceStrategy = 0;
uint8 hordeStrategy = 0;
};
extern std::unordered_map<uint32, BGStrategyData> 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) {}

View File

@@ -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 <EFBFBD> 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();