Skip to content

Commit

Permalink
Auto scale mechanism for the botActiveAlone value
Browse files Browse the repository at this point in the history
  • Loading branch information
hermensbas committed Oct 2, 2024
1 parent 54a8445 commit ff3110a
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 29 deletions.
4 changes: 4 additions & 0 deletions conf/playerbots.conf.dist
Original file line number Diff line number Diff line change
Expand Up @@ -1462,6 +1462,10 @@ AiPlayerbot.RandombotsWalkingRPG.InDoors = 0
# The default is 10. With 10% of all bots going active or inactive each minute.
AiPlayerbot.BotActiveAlone = 100

# Specify 1 for enabled, 0 for disabled.
# The default is 1. Automatically adjusts 'BotActiveAlone' percentage based on server latency.
AiPlayerbot.botActiveAloneAutoScale = 1

# Premade spell to avoid (undetected spells)
# spellid-radius, ...
AiPlayerbot.PremadeAvoidAoe = 62234-4
Expand Down
53 changes: 24 additions & 29 deletions src/PlayerbotAI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4063,8 +4063,6 @@ bool PlayerbotAI::AllowActive(ActivityType activityType)
return true;
}

uint32 maxDiff = sWorldUpdateTime.GetMaxUpdateTime();

Group* group = bot->GetGroup();
if (group)
{
Expand Down Expand Up @@ -4144,35 +4142,32 @@ bool PlayerbotAI::AllowActive(ActivityType activityType)
if (sPlayerbotAIConfig->botActiveAlone <= 0)
return false;

if (sPlayerbotAIConfig->botActiveAlone >= 100)
return true;

if (maxDiff > 1000)
return false;

uint32 mod = 100;

// if has real players - slow down continents without player
if (maxDiff > 100)
mod = 50;

if (maxDiff > 150)
mod = 25;

if (maxDiff > 200)
mod = 10;

if (maxDiff > 250)
// use the configured 'botActiveAlone 'percentages. Downscale the activity, within
// reason ,with the intension to give the server some breathing space when needed.
uint32 mod = sPlayerbotAIConfig->botActiveAlone > 100 ? 100 : sPlayerbotAIConfig->botActiveAlone;
if (sPlayerbotAIConfig->botActiveAloneAutoScale)
{
if (Map* map = bot->GetMap())
{
if (map->GetEntry()->IsWorldMap())
uint32 maxDiff = sWorldUpdateTime.GetPercentile(50);
if (maxDiff > 1000)
return false;
if (maxDiff > 80)
mod = (mod * 9) / 10;
if (maxDiff > 100)
mod = (mod * 5) / 10;
if (maxDiff > 150)
mod = (mod * 3) / 10;
if (maxDiff > 200)
{
mod = (mod * 1) / 10;
if (Map* map = bot->GetMap())
{
if (!HasRealPlayers(map))
return false;

if (!map->IsGridLoaded(bot->GetPositionX(), bot->GetPositionY()))
return false;
if (map->GetEntry()->IsWorldMap())
{
if (!HasRealPlayers(map))
return false;
if (!map->IsGridLoaded(bot->GetPositionX(), bot->GetPositionY()))
return false;
}
}
}
}
Expand Down
1 change: 1 addition & 0 deletions src/PlayerbotAIConfig.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -465,6 +465,7 @@ bool PlayerbotAIConfig::Initialize()
playerbotsXPrate = sConfigMgr->GetOption<int32>("AiPlayerbot.KillXPRate", 1);
disableDeathKnightLogin = sConfigMgr->GetOption<bool>("AiPlayerbot.DisableDeathKnightLogin", 0);
botActiveAlone = sConfigMgr->GetOption<int32>("AiPlayerbot.BotActiveAlone", 100);
botActiveAloneAutoScale = sConfigMgr->GetOption<bool>("AiPlayerbot.botActiveAloneAutoScale", true);

enablePrototypePerformanceDiff = sConfigMgr->GetOption<bool>("AiPlayerbot.EnablePrototypePerformanceDiff", false);
diffWithPlayer = sConfigMgr->GetOption<int32>("AiPlayerbot.DiffWithPlayer", 100);
Expand Down
1 change: 1 addition & 0 deletions src/PlayerbotAIConfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,7 @@ class PlayerbotAIConfig
uint32 playerbotsXPrate;
bool disableDeathKnightLogin;
uint32 botActiveAlone;
bool botActiveAloneAutoScale;

uint32 enablePrototypePerformanceDiff;
uint32 diffWithPlayer;
Expand Down

0 comments on commit ff3110a

Please sign in to comment.