Improper singletons migration to clean Meyer's singletons (cherry-pick) (#2082)

# Pull Request

- Applies the clean and corrected singletons, Meyer pattern. (cherry
picked from @SmashingQuasar )

Testing by just playing the game in various ways. Been tested by myself
@Celandriel and @SmashingQuasar
---

## Complexity & Impact

- Does this change add new decision branches?
    - [x] No
    - [ ] Yes (**explain below**)

- Does this change increase per-bot or per-tick processing?
    - [x] No
    - [ ] Yes (**describe and justify impact**)

- Could this logic scale poorly under load?
    - [x] No
    - [ ] Yes (**explain why**)

---

## Defaults & Configuration

- Does this change modify default bot behavior?
    - [x] No
    - [ ] Yes (**explain why**)

---

## AI Assistance

- Was AI assistance (e.g. ChatGPT or similar tools) used while working
on this change?
    - [x] No
    - [ ] Yes (**explain below**)
---

## Final Checklist

- [x] Stability is not compromised
- [x] Performance impact is understood, tested, and acceptable
- [x] Added logic complexity is justified and explained
- [x] Documentation updated if needed

---

## Notes for Reviewers

Anything that significantly improves realism at the cost of stability or
performance should be carefully discussed
before merging.

---------

Co-authored-by: Nicolas Lebacq <nicolas.cordier@outlook.com>
Co-authored-by: Keleborn <22352763+Celandriel@users.noreply.github.com>
This commit is contained in:
bashermens
2026-01-30 21:49:37 +01:00
committed by GitHub
parent a92886032c
commit 13fff46fa0
233 changed files with 2460 additions and 2354 deletions

View File

@@ -16,13 +16,13 @@ uint8 AoeHealValue::Calculate()
float range = 0;
if (qualifier == "low")
range = sPlayerbotAIConfig->lowHealth;
range = sPlayerbotAIConfig.lowHealth;
else if (qualifier == "medium")
range = sPlayerbotAIConfig->mediumHealth;
range = sPlayerbotAIConfig.mediumHealth;
else if (qualifier == "critical")
range = sPlayerbotAIConfig->criticalHealth;
range = sPlayerbotAIConfig.criticalHealth;
else if (qualifier == "almost full")
range = sPlayerbotAIConfig->almostFullHealth;
range = sPlayerbotAIConfig.almostFullHealth;
uint8 count = 0;
Group::MemberSlotList const& groupSlot = group->GetMemberSlots();
@@ -32,7 +32,7 @@ uint8 AoeHealValue::Calculate()
if (!player || !player->IsAlive())
continue;
if (player->GetDistance(bot) >= sPlayerbotAIConfig->sightDistance)
if (player->GetDistance(bot) >= sPlayerbotAIConfig.sightDistance)
continue;
float percent = (static_cast<float>(player->GetHealth()) / player->GetMaxHealth()) * 100;

View File

@@ -29,8 +29,8 @@ GuidVector FindMaxDensity(Player* bot)
if (!other)
continue;
float d = sServerFacade->GetDistance2d(unit, other);
if (sServerFacade->IsDistanceLessOrEqualThan(d, sPlayerbotAIConfig->aoeRadius * 2))
float d = ServerFacade::instance().GetDistance2d(unit, other);
if (ServerFacade::instance().IsDistanceLessOrEqualThan(d, sPlayerbotAIConfig.aoeRadius * 2))
groups[*i].push_back(*j);
}
@@ -157,4 +157,4 @@ Aura* AreaDebuffValue::Calculate()
}
}
return nullptr;
}
}

View File

@@ -31,15 +31,15 @@ WorldLocation ArrowFormation::GetLocationInternal()
tanks.PlaceUnits(&placer);
tanks.Move(-cos(orientation) * offset, -sin(orientation) * offset);
offset += tankLines * sPlayerbotAIConfig->followDistance + sPlayerbotAIConfig->tooCloseDistance / 2;
offset += tankLines * sPlayerbotAIConfig.followDistance + sPlayerbotAIConfig.tooCloseDistance / 2;
melee.PlaceUnits(&placer);
melee.Move(-cos(orientation) * offset, -sin(orientation) * offset);
offset += meleeLines * sPlayerbotAIConfig->followDistance + sPlayerbotAIConfig->tooCloseDistance / 2;
offset += meleeLines * sPlayerbotAIConfig.followDistance + sPlayerbotAIConfig.tooCloseDistance / 2;
ranged.PlaceUnits(&placer);
ranged.Move(-cos(orientation) * offset, -sin(orientation) * offset);
offset += rangedLines * sPlayerbotAIConfig->followDistance;
offset += rangedLines * sPlayerbotAIConfig.followDistance;
healers.PlaceUnits(&placer);
healers.Move(-cos(orientation) * offset, -sin(orientation) * offset);
@@ -143,16 +143,16 @@ UnitPosition MultiLineUnitPlacer::Place(FormationUnit* unit, uint32 index, uint3
uint32 lineNo = index / 6;
uint32 indexInLine = index % 6;
uint32 lineSize = std::max(count - lineNo * 6, uint32(6));
float x = cos(orientation) * sPlayerbotAIConfig->followDistance * lineNo;
float y = sin(orientation) * sPlayerbotAIConfig->followDistance * lineNo;
float x = cos(orientation) * sPlayerbotAIConfig.followDistance * lineNo;
float y = sin(orientation) * sPlayerbotAIConfig.followDistance * lineNo;
return placer.Place(unit, indexInLine, lineSize);
}
UnitPosition SingleLineUnitPlacer::Place(FormationUnit* unit, uint32 index, uint32 count)
{
float angle = orientation - M_PI / 2.0f;
float x = cos(angle) * sPlayerbotAIConfig->followDistance * ((float)index - (float)count / 2);
float y = sin(angle) * sPlayerbotAIConfig->followDistance * ((float)index - (float)count / 2);
float x = cos(angle) * sPlayerbotAIConfig.followDistance * ((float)index - (float)count / 2);
float y = sin(angle) * sPlayerbotAIConfig.followDistance * ((float)index - (float)count / 2);
return UnitPosition(x, y);
}

View File

@@ -34,7 +34,7 @@ bool HasAggroValue::Calculate()
uint8 AttackerCountValue::Calculate()
{
uint32 count = 0;
float range = sPlayerbotAIConfig->sightDistance;
float range = sPlayerbotAIConfig.sightDistance;
GuidVector attackers = context->GetValue<GuidVector>("attackers")->Get();
for (ObjectGuid const guid : attackers)

View File

@@ -71,7 +71,7 @@ void AttackersValue::AddAttackersOf(Group* group, std::unordered_set<Unit*>& tar
{
Player* member = ObjectAccessor::FindPlayer(itr->guid);
if (!member || !member->IsAlive() || member == bot || member->GetMapId() != bot->GetMapId() ||
sServerFacade->GetDistance2d(bot, member) > sPlayerbotAIConfig->sightDistance)
ServerFacade::instance().GetDistance2d(bot, member) > sPlayerbotAIConfig.sightDistance)
continue;
AddAttackersOf(member, targets);
@@ -103,7 +103,7 @@ void AttackersValue::AddAttackersOf(Player* player, std::unordered_set<Unit*>& t
Unit* attacker = threatMgr->GetOwner();
if (player->IsValidAttackTarget(attacker) &&
player->GetDistance2d(attacker) < sPlayerbotAIConfig->sightDistance)
player->GetDistance2d(attacker) < sPlayerbotAIConfig.sightDistance)
targets.insert(attacker);
ref = ref->next();
@@ -176,8 +176,8 @@ bool AttackersValue::IsPossibleTarget(Unit* attacker, Player* bot, float /*range
// PvP prohibition checks (skip for duels)
if ((attacker->GetGUID().IsPlayer() || attacker->GetGUID().IsPet()) &&
(!bot->duel || bot->duel->Opponent != attacker) &&
(sPlayerbotAIConfig->IsPvpProhibited(attacker->GetZoneId(), attacker->GetAreaId()) ||
sPlayerbotAIConfig->IsPvpProhibited(bot->GetZoneId(), bot->GetAreaId())))
(sPlayerbotAIConfig.IsPvpProhibited(attacker->GetZoneId(), attacker->GetAreaId()) ||
sPlayerbotAIConfig.IsPvpProhibited(bot->GetZoneId(), bot->GetAreaId())))
{
// This will stop aggresive pets from starting an attack.
// This will stop currently attacking pets from continuing their attack.
@@ -269,11 +269,11 @@ bool PossibleAddsValue::Calculate()
if (!attacker)
continue;
float dist = sServerFacade->GetDistance2d(attacker, add);
if (sServerFacade->IsDistanceLessOrEqualThan(dist, sPlayerbotAIConfig->aoeRadius * 1.5f))
float dist = ServerFacade::instance().GetDistance2d(attacker, add);
if (ServerFacade::instance().IsDistanceLessOrEqualThan(dist, sPlayerbotAIConfig.aoeRadius * 1.5f))
continue;
if (sServerFacade->IsDistanceLessOrEqualThan(dist, sPlayerbotAIConfig->aggroDistance))
if (ServerFacade::instance().IsDistanceLessOrEqualThan(dist, sPlayerbotAIConfig.aggroDistance))
return true;
}
}

View File

@@ -20,7 +20,7 @@ public:
AttackersValue(PlayerbotAI* botAI) : ObjectGuidListCalculatedValue(botAI, "attackers", 1 * 1000) {}
GuidVector Calculate();
static bool IsPossibleTarget(Unit* attacker, Player* bot, float range = sPlayerbotAIConfig->sightDistance);
static bool IsPossibleTarget(Unit* attacker, Player* bot, float range = sPlayerbotAIConfig.sightDistance);
static bool IsValidTarget(Unit* attacker, Player* bot);
private:

View File

@@ -26,5 +26,5 @@ bool CanLootValue::Calculate()
{
LootObject loot = AI_VALUE(LootObject, "loot target");
return !loot.IsEmpty() && loot.GetWorldObject(bot) && loot.IsLootPossible(bot) &&
sServerFacade->IsDistanceLessOrEqualThan(AI_VALUE2(float, "distance", "loot target"), INTERACTION_DISTANCE - 2);
ServerFacade::instance().IsDistanceLessOrEqualThan(AI_VALUE2(float, "distance", "loot target"), INTERACTION_DISTANCE - 2);
}

View File

@@ -34,7 +34,7 @@ public:
return;
uint8 health = static_cast<uint8>(creature->GetHealthPct());
if (health < sPlayerbotAIConfig->mediumHealth)
if (health < sPlayerbotAIConfig.mediumHealth)
return;
float minDistance = botAI->GetRange("spell");
@@ -45,9 +45,9 @@ public:
if (*botAI->GetAiObjectContext()->GetValue<uint8>("aoe count") > 2)
{
WorldLocation aoe = *botAI->GetAiObjectContext()->GetValue<WorldLocation>("aoe position");
if (sServerFacade->IsDistanceLessOrEqualThan(
sServerFacade->GetDistance2d(creature, aoe.GetPositionX(), aoe.GetPositionY()),
sPlayerbotAIConfig->aoeRadius))
if (ServerFacade::instance().IsDistanceLessOrEqualThan(
ServerFacade::instance().GetDistance2d(creature, aoe.GetPositionX(), aoe.GetPositionY()),
sPlayerbotAIConfig.aoeRadius))
return;
}
@@ -70,7 +70,7 @@ public:
if (!botAI->IsTank(member))
continue;
float distance = sServerFacade->GetDistance2d(member, creature);
float distance = ServerFacade::instance().GetDistance2d(member, creature);
if (distance < minDistance)
minDistance = distance;
}

View File

@@ -18,7 +18,7 @@ bool CollisionValue::Calculate()
return false;
std::list<Unit*> targets;
float range = sPlayerbotAIConfig->contactDistance;
float range = sPlayerbotAIConfig.contactDistance;
Acore::AnyUnitInObjectRangeCheck u_check(bot, range);
Acore::UnitListSearcher<Acore::AnyUnitInObjectRangeCheck> searcher(bot, targets, u_check);
Cell::VisitObjects(bot, searcher, range);
@@ -28,8 +28,8 @@ bool CollisionValue::Calculate()
if (bot == target)
continue;
float dist = sServerFacade->GetDistance2d(bot, target->GetPositionX(), target->GetPositionY());
if (sServerFacade->IsDistanceLessThan(dist, target->GetCombatReach()))
float dist = ServerFacade::instance().GetDistance2d(bot, target->GetPositionX(), target->GetPositionY());
if (ServerFacade::instance().IsDistanceLessThan(dist, target->GetCombatReach()))
return true;
}

View File

@@ -24,7 +24,7 @@ float DistanceValue::Calculate()
if (!obj || !obj->IsInWorld())
return 0.0f;
return sServerFacade->GetDistance2d(botAI->GetBot(), obj);
return ServerFacade::instance().GetDistance2d(botAI->GetBot(), obj);
}
if (qualifier.find("position_") == 0)
@@ -37,7 +37,7 @@ float DistanceValue::Calculate()
if (botAI->GetBot()->GetMapId() != pos.mapId)
return 0.0f;
return sServerFacade->GetDistance2d(botAI->GetBot(), pos.x, pos.y);
return ServerFacade::instance().GetDistance2d(botAI->GetBot(), pos.x, pos.y);
}
Unit* target = nullptr;
@@ -76,7 +76,7 @@ float DistanceValue::Calculate()
{
Formation* formation = AI_VALUE(Formation*, "formation");
WorldLocation loc = formation->GetLocation();
return sServerFacade->GetDistance2d(botAI->GetBot(), loc.GetPositionX(), loc.GetPositionY());
return ServerFacade::instance().GetDistance2d(botAI->GetBot(), loc.GetPositionX(), loc.GetPositionY());
}
}
@@ -86,7 +86,7 @@ float DistanceValue::Calculate()
if (target == botAI->GetBot())
return 0.0f;
return sServerFacade->GetDistance2d(botAI->GetBot(), target);
return ServerFacade::instance().GetDistance2d(botAI->GetBot(), target);
}
bool InsideTargetValue::Calculate()
@@ -95,6 +95,6 @@ bool InsideTargetValue::Calculate()
if (!target || !target->IsInWorld() || target == botAI->GetBot())
return false;
float dist = sServerFacade->GetDistance2d(botAI->GetBot(), target->GetPositionX(), target->GetPositionY());
return sServerFacade->IsDistanceLessThan(dist, target->GetCombatReach());
float dist = ServerFacade::instance().GetDistance2d(botAI->GetBot(), target->GetPositionX(), target->GetPositionY());
return ServerFacade::instance().IsDistanceLessThan(dist, target->GetCombatReach());
}

View File

@@ -116,7 +116,7 @@ public:
float time = unit->GetHealth() / dps_;
float dis = unit->GetDistance(botAI->GetBot());
float attackRange =
botAI->IsRanged(botAI->GetBot()) ? sPlayerbotAIConfig->spellDistance : sPlayerbotAIConfig->meleeDistance;
botAI->IsRanged(botAI->GetBot()) ? sPlayerbotAIConfig.spellDistance : sPlayerbotAIConfig.meleeDistance;
attackRange += 5.0f;
int level = dis < attackRange ? 10 : 0;
if (time >= 5 && time <= 30)
@@ -198,7 +198,7 @@ public:
float time = unit->GetHealth() / dps_;
float dis = unit->GetDistance(botAI->GetBot());
float attackRange =
botAI->IsRanged(botAI->GetBot()) ? sPlayerbotAIConfig->spellDistance : sPlayerbotAIConfig->meleeDistance;
botAI->IsRanged(botAI->GetBot()) ? sPlayerbotAIConfig.spellDistance : sPlayerbotAIConfig.meleeDistance;
attackRange += 5.0f;
int level = dis < attackRange ? 10 : 0;
return level;
@@ -279,7 +279,7 @@ public:
float time = unit->GetHealth() / dps_;
float dis = unit->GetDistance(botAI->GetBot());
float attackRange =
botAI->IsRanged(botAI->GetBot()) ? sPlayerbotAIConfig->spellDistance : sPlayerbotAIConfig->meleeDistance;
botAI->IsRanged(botAI->GetBot()) ? sPlayerbotAIConfig.spellDistance : sPlayerbotAIConfig.meleeDistance;
attackRange += 5.0f;
int level = dis < attackRange ? 10 : 0;
return level;

View File

@@ -20,7 +20,7 @@ Unit* EnemyHealerTargetValue::Calculate()
if (!unit || unit == target)
continue;
if (sServerFacade->GetDistance2d(bot, unit) > botAI->GetRange("spell"))
if (ServerFacade::instance().GetDistance2d(bot, unit) > botAI->GetRange("spell"))
continue;
if (!botAI->IsInterruptableSpellCasting(unit, spell))

View File

@@ -14,7 +14,7 @@ bool NearestEnemyPlayersValue::AcceptUnit(Unit* unit)
bool inCannon = botAI->IsInVehicle(false, true);
Player* enemy = dynamic_cast<Player*>(unit);
if (enemy && botAI->IsOpposing(enemy) && enemy->IsPvP() &&
!sPlayerbotAIConfig->IsPvpProhibited(enemy->GetZoneId(), enemy->GetAreaId()) &&
!sPlayerbotAIConfig.IsPvpProhibited(enemy->GetZoneId(), enemy->GetAreaId()) &&
!enemy->HasFlag(UNIT_FIELD_FLAGS, UNIT_FLAG_NON_ATTACKABLE | UNIT_FLAG_NON_ATTACKABLE_2) &&
((inCannon || !enemy->HasFlag(UNIT_FIELD_FLAGS, UNIT_FLAG_NOT_SELECTABLE))) &&
/*!enemy->HasStealthAura() && !enemy->HasInvisibilityAura()*/ enemy->CanSeeOrDetect(bot) &&
@@ -131,7 +131,7 @@ Unit* EnemyPlayerValue::Calculate()
if (pMember == bot)
continue;
if (sServerFacade->GetDistance2d(bot, pMember) > 30.0f)
if (ServerFacade::instance().GetDistance2d(bot, pMember) > 30.0f)
continue;
if (Unit* pAttacker = pMember->getAttackerForHelper())

View File

@@ -16,7 +16,7 @@ class Unit;
class NearestEnemyPlayersValue : public PossibleTargetsValue
{
public:
NearestEnemyPlayersValue(PlayerbotAI* botAI, float range = sPlayerbotAIConfig->grindDistance)
NearestEnemyPlayersValue(PlayerbotAI* botAI, float range = sPlayerbotAIConfig.grindDistance)
: PossibleTargetsValue(botAI, "nearest enemy players", range)
{
}

View File

@@ -46,7 +46,7 @@ float EstimatedGroupDpsValue::Calculate()
if (member->GetMapId() != bot->GetMapId())
continue;
if (member->GetExactDist(bot) > sPlayerbotAIConfig->sightDistance)
if (member->GetExactDist(bot) > sPlayerbotAIConfig.sightDistance)
continue;
groupPlayer.push_back(member);
@@ -146,4 +146,4 @@ float EstimatedGroupDpsValue::GetBasicGs(uint32 level)
basic_gs = PlayerbotFactory::CalcMixedGearScore(155 + (level - 70) * 4, ITEM_QUALITY_RARE);
}
return basic_gs;
}
}

View File

@@ -64,8 +64,8 @@ WorldLocation MoveAheadFormation::GetLocation()
// if (master->isMoving())
// {
// float ori = master->GetOrientation();
// float x1 = x + sPlayerbotAIConfig->tooCloseDistance * cos(ori);
// float y1 = y + sPlayerbotAIConfig->tooCloseDistance * sin(ori);
// float x1 = x + sPlayerbotAIConfig.tooCloseDistance * cos(ori);
// float y1 = y + sPlayerbotAIConfig.tooCloseDistance * sin(ori);
// float ground = map->GetHeight(x1, y1, z);
// if (ground > INVALID_HEIGHT)
// {
@@ -111,7 +111,7 @@ public:
if (!ValidateTargetContext(master, bot, map))
return Formation::NullLocation;
float range = sPlayerbotAIConfig->followDistance;
float range = sPlayerbotAIConfig.followDistance;
float angle = GetFollowAngle();
float x = master->GetPositionX() + cos(angle) * range;
float y = master->GetPositionY() + sin(angle) * range;
@@ -127,7 +127,7 @@ public:
return WorldLocation(master->GetMapId(), x, y, z);
}
float GetMaxDistance() override { return sPlayerbotAIConfig->followDistance; }
float GetMaxDistance() override { return sPlayerbotAIConfig.followDistance; }
};
class ChaosFormation : public MoveAheadFormation
@@ -142,7 +142,7 @@ public:
if (!ValidateTargetContext(master, bot, map))
return Formation::NullLocation;
float range = sPlayerbotAIConfig->followDistance;
float range = sPlayerbotAIConfig.followDistance;
float angle = GetFollowAngle();
time_t now = time(nullptr);
@@ -150,8 +150,8 @@ public:
{
lastChangeTime = now;
dx = (urand(0, 10) / 10.0f - 0.5f) * sPlayerbotAIConfig->tooCloseDistance;
dy = (urand(0, 10) / 10.0f - 0.5f) * sPlayerbotAIConfig->tooCloseDistance;
dx = (urand(0, 10) / 10.0f - 0.5f) * sPlayerbotAIConfig.tooCloseDistance;
dy = (urand(0, 10) / 10.0f - 0.5f) * sPlayerbotAIConfig.tooCloseDistance;
dr = std::sqrt(dx * dx + dy * dy);
}
@@ -173,7 +173,7 @@ public:
return WorldLocation(master->GetMapId(), x, y, z);
}
float GetMaxDistance() override { return sPlayerbotAIConfig->followDistance + dr; }
float GetMaxDistance() override { return sPlayerbotAIConfig.followDistance + dr; }
private:
time_t lastChangeTime;
@@ -287,7 +287,7 @@ public:
if (!group)
return Formation::NullLocation;
float range = sPlayerbotAIConfig->followDistance;
float range = sPlayerbotAIConfig.followDistance;
Player* master = GetMaster();
if (!master)
@@ -326,14 +326,14 @@ public:
if (botAI->IsTank(bot) && !botAI->IsTank(master))
{
float diff = (tanks.size() % 2 == 0) ? -sPlayerbotAIConfig->tooCloseDistance / 2.0f : 0.0f;
float diff = (tanks.size() % 2 == 0) ? -sPlayerbotAIConfig.tooCloseDistance / 2.0f : 0.0f;
return MoveLine(tanks, diff, x + cos(orientation) * range, y + sin(orientation) * range, z, orientation,
range);
}
if (!botAI->IsTank(bot) && botAI->IsTank(master))
{
float diff = (dps.size() % 2 == 0) ? -sPlayerbotAIConfig->tooCloseDistance / 2.0f : 0.0f;
float diff = (dps.size() % 2 == 0) ? -sPlayerbotAIConfig.tooCloseDistance / 2.0f : 0.0f;
return MoveLine(dps, diff, x - cos(orientation) * range, y - sin(orientation) * range, z, orientation,
range);
}
@@ -354,10 +354,10 @@ public:
if (!ValidateTargetContext(master, bot, map))
return Formation::NullLocation;
float range = sPlayerbotAIConfig->farDistance;
float followRange = sPlayerbotAIConfig->followDistance;
float range = sPlayerbotAIConfig.farDistance;
float followRange = sPlayerbotAIConfig.followDistance;
if (sServerFacade->GetDistance2d(bot, master) <= range)
if (ServerFacade::instance().GetDistance2d(bot, master) <= range)
return Formation::NullLocation;
float angleToBot = master->GetAngle(bot);
@@ -378,7 +378,7 @@ public:
float tx = master->GetPositionX() + cos(a) * range + cos(followAngle) * followRange;
float ty = master->GetPositionY() + sin(a) * range + sin(followAngle) * followRange;
float dist = sServerFacade->GetDistance2d(bot, tx, ty);
float dist = ServerFacade::instance().GetDistance2d(bot, tx, ty);
float tg = master->GetMapHeight(tx, ty, z + 30.0f);
if (tg > INVALID_HEIGHT && (!minDist || dist < minDist))

View File

@@ -21,7 +21,7 @@ public:
virtual ~Formation() = default;
virtual std::string const GetTargetName() { return ""; }
virtual WorldLocation GetLocation() { return NullLocation; }
virtual float GetMaxDistance() { return sPlayerbotAIConfig->followDistance; }
virtual float GetMaxDistance() { return sPlayerbotAIConfig.followDistance; }
static WorldLocation NullLocation;
static bool IsNullLocation(WorldLocation const& loc);

View File

@@ -82,12 +82,12 @@ Unit* GrindTargetValue::FindTargetForGrinding(uint32 assistCount)
if (!bot->InBattleground() && GetTargetingPlayerCount(unit) > assistCount)
continue;
// if (!bot->InBattleground() && master && master->GetDistance(unit) >= sPlayerbotAIConfig->grindDistance &&
// !sRandomPlayerbotMgr->IsRandomBot(bot)) continue;
// if (!bot->InBattleground() && master && master->GetDistance(unit) >= sPlayerbotAIConfig.grindDistance &&
// !sRandomPlayerbotMgr.IsRandomBot(bot)) continue;
// Bots in bot-groups no have a more limited range to look for grind target
if (!bot->InBattleground() && master && botAI->HasStrategy("follow", BotState::BOT_STATE_NON_COMBAT) &&
sServerFacade->GetDistance2d(master, unit) > sPlayerbotAIConfig->lootDistance)
ServerFacade::instance().GetDistance2d(master, unit) > sPlayerbotAIConfig.lootDistance)
{
if (botAI->HasStrategy("debug grind", BotState::BOT_STATE_NON_COMBAT))
botAI->TellMaster(chat->FormatWorldobject(unit) + " ignored (far from master).");

View File

@@ -47,7 +47,7 @@ bool IsNearLeaderValue::Calculate()
if (groupLeader == bot)
return true;
return sServerFacade->GetDistance2d(bot, botAI->GetGroupLeader()) < sPlayerbotAIConfig->sightDistance;
return ServerFacade::instance().GetDistance2d(bot, botAI->GetGroupLeader()) < sPlayerbotAIConfig.sightDistance;
}
bool BoolANDValue::Calculate()
@@ -155,10 +155,10 @@ bool GroupReadyValue::Calculate()
// We only wait for members that are in range otherwise we might be waiting for bots stuck in dead loops
// forever.
if (botAI->GetGroupLeader() &&
sServerFacade->GetDistance2d(member, botAI->GetGroupLeader()) > sPlayerbotAIConfig->sightDistance)
ServerFacade::instance().GetDistance2d(member, botAI->GetGroupLeader()) > sPlayerbotAIConfig.sightDistance)
continue;
if (member->GetHealthPct() < sPlayerbotAIConfig->almostFullHealth)
if (member->GetHealthPct() < sPlayerbotAIConfig.almostFullHealth)
return false;
if (!member->GetPower(POWER_MANA))
@@ -166,7 +166,7 @@ bool GroupReadyValue::Calculate()
float mana = (static_cast<float>(member->GetPower(POWER_MANA)) / member->GetMaxPower(POWER_MANA)) * 100;
if (mana < sPlayerbotAIConfig->mediumMana)
if (mana < sPlayerbotAIConfig.mediumMana)
return false;
}

View File

@@ -11,5 +11,5 @@
bool HasAvailableLootValue::Calculate()
{
return !AI_VALUE(bool, "can loot") &&
AI_VALUE(LootObjectStack*, "available loot")->CanLoot(sPlayerbotAIConfig->lootDistance);
AI_VALUE(LootObjectStack*, "available loot")->CanLoot(sPlayerbotAIConfig.lootDistance);
}

View File

@@ -99,7 +99,7 @@ ItemUsage ItemUsageValue::Calculate()
}
}
if (bot->GetGuildId() && sGuildTaskMgr->IsGuildTaskItem(itemId, bot->GetGuildId()))
if (bot->GetGuildId() && GuildTaskMgr::instance().IsGuildTaskItem(itemId, bot->GetGuildId()))
return ITEM_USAGE_GUILD_TASK;
ItemUsage equip = QueryItemUsageForEquip(proto, randomPropertyId);
@@ -129,7 +129,7 @@ ItemUsage ItemUsageValue::Calculate()
Player* master = botAI->GetMaster();
bool isSelfBot = (master == bot);
bool botNeedsItemForQuest = IsItemUsefulForQuest(bot, proto);
bool masterNeedsItemForQuest = master && sPlayerbotAIConfig->syncQuestWithPlayer && IsItemUsefulForQuest(master, proto);
bool masterNeedsItemForQuest = master && sPlayerbotAIConfig.syncQuestWithPlayer && IsItemUsefulForQuest(master, proto);
// Identify the source of loot
LootObject lootObject = AI_VALUE(LootObject, "loot target");
@@ -304,7 +304,7 @@ ItemUsage ItemUsageValue::QueryItemUsageForEquip(ItemTemplate const* itemProto,
}
bool shouldEquip = false;
// uint32 statWeight = sRandomItemMgr->GetLiveStatWeight(bot, itemProto->ItemId);
// uint32 statWeight = sRandomItemMgr.GetLiveStatWeight(bot, itemProto->ItemId);
StatsWeightCalculator calculator(bot);
calculator.SetItemSetBonus(false);
calculator.SetOverflowPenalty(false);
@@ -314,10 +314,10 @@ ItemUsage ItemUsageValue::QueryItemUsageForEquip(ItemTemplate const* itemProto,
if (itemScore)
shouldEquip = true;
if (itemProto->Class == ITEM_CLASS_WEAPON && !sRandomItemMgr->CanEquipWeapon(bot->getClass(), itemProto))
if (itemProto->Class == ITEM_CLASS_WEAPON && !sRandomItemMgr.CanEquipWeapon(bot->getClass(), itemProto))
shouldEquip = false;
if (itemProto->Class == ITEM_CLASS_ARMOR &&
!sRandomItemMgr->CanEquipArmor(bot->getClass(), bot->GetLevel(), itemProto))
!sRandomItemMgr.CanEquipArmor(bot->getClass(), bot->GetLevel(), itemProto))
shouldEquip = false;
uint8 possibleSlots = 1;
@@ -396,10 +396,10 @@ ItemUsage ItemUsageValue::QueryItemUsageForEquip(ItemTemplate const* itemProto,
float oldScore = calculator.CalculateItem(oldItemProto->ItemId, oldItem->GetInt32Value(ITEM_FIELD_RANDOM_PROPERTIES_ID));
if (oldItem)
{
// uint32 oldStatWeight = sRandomItemMgr->GetLiveStatWeight(bot, oldItemProto->ItemId);
// uint32 oldStatWeight = sRandomItemMgr.GetLiveStatWeight(bot, oldItemProto->ItemId);
if (itemScore || oldScore)
{
shouldEquipInSlot = itemScore > oldScore * sPlayerbotAIConfig->equipUpgradeThreshold;
shouldEquipInSlot = itemScore > oldScore * sPlayerbotAIConfig.equipUpgradeThreshold;
}
}
@@ -417,15 +417,15 @@ ItemUsage ItemUsageValue::QueryItemUsageForEquip(ItemTemplate const* itemProto,
}
bool existingShouldEquip = true;
if (oldItemProto->Class == ITEM_CLASS_WEAPON && !sRandomItemMgr->CanEquipWeapon(bot->getClass(), oldItemProto))
if (oldItemProto->Class == ITEM_CLASS_WEAPON && !sRandomItemMgr.CanEquipWeapon(bot->getClass(), oldItemProto))
existingShouldEquip = false;
if (oldItemProto->Class == ITEM_CLASS_ARMOR &&
!sRandomItemMgr->CanEquipArmor(bot->getClass(), bot->GetLevel(), oldItemProto))
!sRandomItemMgr.CanEquipArmor(bot->getClass(), bot->GetLevel(), oldItemProto))
existingShouldEquip = false;
// uint32 oldItemPower = sRandomItemMgr->GetLiveStatWeight(bot, oldItemProto->ItemId);
// uint32 newItemPower = sRandomItemMgr->GetLiveStatWeight(bot, itemProto->ItemId);
// uint32 oldItemPower = sRandomItemMgr.GetLiveStatWeight(bot, oldItemProto->ItemId);
// uint32 newItemPower = sRandomItemMgr.GetLiveStatWeight(bot, itemProto->ItemId);
// Compare items based on item level, quality or itemId.
bool isBetter = false;

View File

@@ -14,7 +14,7 @@ class PlayerbotAI;
class NearestAddsValue : public PossibleTargetsValue
{
public:
NearestAddsValue(PlayerbotAI* botAI, float range = sPlayerbotAIConfig->tooCloseDistance)
NearestAddsValue(PlayerbotAI* botAI, float range = sPlayerbotAIConfig.tooCloseDistance)
: PossibleTargetsValue(botAI, "nearest adds", range, true)
{
}

View File

@@ -14,7 +14,7 @@ class PlayerbotAI;
class NearestCorpsesValue : public NearestUnitsValue
{
public:
NearestCorpsesValue(PlayerbotAI* botAI, float range = sPlayerbotAIConfig->sightDistance)
NearestCorpsesValue(PlayerbotAI* botAI, float range = sPlayerbotAIConfig.sightDistance)
: NearestUnitsValue(botAI, "nearest corpses", range, true)
{
}

View File

@@ -14,7 +14,7 @@ class PlayerbotAI;
class NearestFriendlyPlayersValue : public NearestUnitsValue
{
public:
NearestFriendlyPlayersValue(PlayerbotAI* botAI, float range = sPlayerbotAIConfig->sightDistance)
NearestFriendlyPlayersValue(PlayerbotAI* botAI, float range = sPlayerbotAIConfig.sightDistance)
: NearestUnitsValue(botAI, "nearest friendly players", range)
{
}

View File

@@ -33,7 +33,7 @@ private:
class NearestGameObjects : public ObjectGuidListCalculatedValue
{
public:
NearestGameObjects(PlayerbotAI* botAI, float range = sPlayerbotAIConfig->sightDistance, bool ignoreLos = false,
NearestGameObjects(PlayerbotAI* botAI, float range = sPlayerbotAIConfig.sightDistance, bool ignoreLos = false,
std::string const name = "nearest game objects")
: ObjectGuidListCalculatedValue(botAI, name, 1 * 1000), range(range), ignoreLos(ignoreLos)
{

View File

@@ -14,7 +14,7 @@ class PlayerbotAI;
class NearestNonBotPlayersValue : public NearestUnitsValue
{
public:
NearestNonBotPlayersValue(PlayerbotAI* botAI, float range = sPlayerbotAIConfig->grindDistance)
NearestNonBotPlayersValue(PlayerbotAI* botAI, float range = sPlayerbotAIConfig.grindDistance)
: NearestUnitsValue(botAI, "nearest non bot players", range, true)
{
}

View File

@@ -14,7 +14,7 @@ class PlayerbotAI;
class NearestNpcsValue : public NearestUnitsValue
{
public:
NearestNpcsValue(PlayerbotAI* botAI, float range = sPlayerbotAIConfig->sightDistance)
NearestNpcsValue(PlayerbotAI* botAI, float range = sPlayerbotAIConfig.sightDistance)
: NearestUnitsValue(botAI, "nearest npcs", range)
{
}
@@ -27,7 +27,7 @@ protected:
class NearestHostileNpcsValue : public NearestUnitsValue
{
public:
NearestHostileNpcsValue(PlayerbotAI* botAI, float range = sPlayerbotAIConfig->sightDistance)
NearestHostileNpcsValue(PlayerbotAI* botAI, float range = sPlayerbotAIConfig.sightDistance)
: NearestUnitsValue(botAI, "nearest hostile npcs", range)
{
}
@@ -40,7 +40,7 @@ protected:
class NearestVehiclesValue : public NearestUnitsValue
{
public:
NearestVehiclesValue(PlayerbotAI* botAI, float range = sPlayerbotAIConfig->sightDistance)
NearestVehiclesValue(PlayerbotAI* botAI, float range = sPlayerbotAIConfig.sightDistance)
: NearestUnitsValue(botAI, "nearest vehicles", range)
{
}
@@ -53,7 +53,7 @@ protected:
class NearestTriggersValue : public NearestUnitsValue
{
public:
NearestTriggersValue(PlayerbotAI* botAI, float range = sPlayerbotAIConfig->sightDistance)
NearestTriggersValue(PlayerbotAI* botAI, float range = sPlayerbotAIConfig.sightDistance)
: NearestUnitsValue(botAI, "nearest triggers", range)
{
}

View File

@@ -16,7 +16,7 @@ class NearestUnitsValue : public ObjectGuidListCalculatedValue
{
public:
NearestUnitsValue(PlayerbotAI* botAI, std::string const name = "nearest units",
float range = sPlayerbotAIConfig->sightDistance, bool ignoreLos = false, uint32 checkInterval = 1)
float range = sPlayerbotAIConfig.sightDistance, bool ignoreLos = false, uint32 checkInterval = 1)
: ObjectGuidListCalculatedValue(botAI, name, checkInterval), range(range), ignoreLos(ignoreLos)
{
}

View File

@@ -46,10 +46,10 @@ Unit* PartyMemberToHeal::Calculate()
if (player && player->IsAlive())
{
uint8 health = player->GetHealthPct();
if (isRaid || health < sPlayerbotAIConfig->mediumHealth || !IsTargetOfSpellCast(player, predicate))
if (isRaid || health < sPlayerbotAIConfig.mediumHealth || !IsTargetOfSpellCast(player, predicate))
{
uint32 probeValue = 100;
if (player->GetDistance2d(bot) > sPlayerbotAIConfig->healDistance)
if (player->GetDistance2d(bot) > sPlayerbotAIConfig.healDistance)
{
probeValue = health + 30;
}
@@ -70,7 +70,7 @@ Unit* PartyMemberToHeal::Calculate()
{
uint8 health = ((Unit*)pet)->GetHealthPct();
uint32 probeValue = 100;
if (isRaid || health < sPlayerbotAIConfig->mediumHealth)
if (isRaid || health < sPlayerbotAIConfig.mediumHealth)
probeValue = health + 30;
// delay Check pet to here for better performance
if (probeValue < calc.minValue && Check(pet))
@@ -84,7 +84,7 @@ Unit* PartyMemberToHeal::Calculate()
{
uint8 health = charm->GetHealthPct();
uint32 probeValue = 100;
if (isRaid || health < sPlayerbotAIConfig->mediumHealth)
if (isRaid || health < sPlayerbotAIConfig.mediumHealth)
probeValue = health + 30;
// delay Check charm to here for better performance
if (probeValue < calc.minValue && Check(charm))
@@ -99,10 +99,10 @@ Unit* PartyMemberToHeal::Calculate()
bool PartyMemberToHeal::Check(Unit* player)
{
// return player && player != bot && player->GetMapId() == bot->GetMapId() && player->IsInWorld() &&
// sServerFacade->GetDistance2d(bot, player) < (player->IsPlayer() && botAI->IsTank((Player*)player) ? 50.0f
// ServerFacade::instance().GetDistance2d(bot, player) < (player->IsPlayer() && botAI->IsTank((Player*)player) ? 50.0f
// : 40.0f);
return player->GetMapId() == bot->GetMapId() && !player->IsCharmed() &&
bot->GetDistance2d(player) < sPlayerbotAIConfig->healDistance * 2 && bot->IsWithinLOSInMap(player);
bot->GetDistance2d(player) < sPlayerbotAIConfig.healDistance * 2 && bot->IsWithinLOSInMap(player);
}
Unit* PartyMemberToProtect::Calculate()
@@ -129,7 +129,7 @@ Unit* PartyMemberToProtect::Calculate()
continue;
float attackDistance = 30.0f;
if (sServerFacade->GetDistance2d(pVictim, unit) > attackDistance)
if (ServerFacade::instance().GetDistance2d(pVictim, unit) > attackDistance)
continue;
if (botAI->IsTank((Player*)pVictim) && pVictim->GetHealthPct() > 10)

View File

@@ -4,6 +4,7 @@
*/
#include "PartyMemberValue.h"
#include "Corpse.h"
#include "Playerbots.h"
#include "ServerFacade.h"
@@ -102,10 +103,10 @@ Unit* PartyMemberValue::FindPartyMember(FindPlayerPredicate& predicate, bool ign
bool PartyMemberValue::Check(Unit* player)
{
// return player && player != bot && player->GetMapId() == bot->GetMapId() && bot->IsWithinDistInMap(player,
// sPlayerbotAIConfig->sightDistance, false);
// sPlayerbotAIConfig.sightDistance, false);
bool isGM = player->ToPlayer() && player->ToPlayer()->IsGameMaster();
return player && player->GetMapId() == bot->GetMapId() && !isGM &&
bot->GetDistance(player) < sPlayerbotAIConfig->spellDistance * 2 &&
bot->GetDistance(player) < sPlayerbotAIConfig.spellDistance * 2 &&
bot->IsWithinLOS(player->GetPositionX(), player->GetPositionY(), player->GetPositionZ());
}
@@ -170,4 +171,4 @@ Unit* PartyMemberMainTankValue::Calculate()
{
FindMainTankPlayer findMainTankPlayer(botAI);
return FindPartyMember(findMainTankPlayer);
}
}

View File

@@ -17,7 +17,7 @@ class PartyMemberWithoutAuraValue : public PartyMemberValue, public Qualified
{
public:
PartyMemberWithoutAuraValue(PlayerbotAI* botAI, std::string const name = "party member without aura",
float range = sPlayerbotAIConfig->sightDistance)
float range = sPlayerbotAIConfig.sightDistance)
: PartyMemberValue(botAI, name)
{
}

View File

@@ -17,7 +17,7 @@ class PartyMemberWithoutItemValue : public PartyMemberValue, public Qualified
{
public:
PartyMemberWithoutItemValue(PlayerbotAI* botAI, std::string const name = "party member without item",
float range = sPlayerbotAIConfig->farDistance)
float range = sPlayerbotAIConfig.farDistance)
: PartyMemberValue(botAI, name)
{
}

View File

@@ -71,7 +71,7 @@ public:
bool EqualToLast(WorldPosition value) override
{
return value.fDist(lastValue) < sPlayerbotAIConfig->tooCloseDistance;
return value.fDist(lastValue) < sPlayerbotAIConfig.tooCloseDistance;
}
WorldPosition Calculate() override;

View File

@@ -60,7 +60,7 @@ bool PossibleRpgTargetsValue::AcceptUnit(Unit* unit)
if (unit->IsHostileTo(bot) || unit->IsPlayer())
return false;
if (sServerFacade->GetDistance2d(bot, unit) <= sPlayerbotAIConfig->tooCloseDistance)
if (ServerFacade::instance().GetDistance2d(bot, unit) <= sPlayerbotAIConfig.tooCloseDistance)
return false;
if (unit->HasNpcFlag(UNIT_NPC_FLAG_SPIRITHEALER))

View File

@@ -15,7 +15,7 @@ class PossibleTargetsValue : public NearestUnitsValue
{
public:
PossibleTargetsValue(PlayerbotAI* botAI, std::string const name = "possible targets",
float range = sPlayerbotAIConfig->sightDistance, bool ignoreLos = false)
float range = sPlayerbotAIConfig.sightDistance, bool ignoreLos = false)
: NearestUnitsValue(botAI, name, range, ignoreLos)
{
}
@@ -28,7 +28,7 @@ protected:
class AllTargetsValue : public PossibleTargetsValue
{
public:
AllTargetsValue(PlayerbotAI* botAI, float range = sPlayerbotAIConfig->sightDistance)
AllTargetsValue(PlayerbotAI* botAI, float range = sPlayerbotAIConfig.sightDistance)
: PossibleTargetsValue(botAI, "all targets", range, true)
{
}

View File

@@ -34,7 +34,7 @@ Unit* FlagCarrierValue::Calculate()
if (carrier)
{
if (ignoreRange || bot->IsWithinDistInMap(carrier, sPlayerbotAIConfig->sightDistance))
if (ignoreRange || bot->IsWithinDistInMap(carrier, sPlayerbotAIConfig.sightDistance))
{
return carrier;
}
@@ -65,7 +65,7 @@ Unit* FlagCarrierValue::Calculate()
if (carrier)
{
if (ignoreRange || bot->IsWithinDistInMap(carrier, sPlayerbotAIConfig->sightDistance))
if (ignoreRange || bot->IsWithinDistInMap(carrier, sPlayerbotAIConfig.sightDistance))
{
return carrier;
}
@@ -84,7 +84,7 @@ std::vector<CreatureData const*> BgMastersValue::Calculate()
std::vector<uint32> entries;
std::map<TeamId, std::map<BattlegroundTypeId, std::vector<uint32>>> battleMastersCache =
sRandomPlayerbotMgr->getBattleMastersCache();
sRandomPlayerbotMgr.getBattleMastersCache();
entries.insert(entries.end(), battleMastersCache[TEAM_NEUTRAL][bgTypeId].begin(),
battleMastersCache[TEAM_NEUTRAL][bgTypeId].end());
entries.insert(entries.end(), battleMastersCache[TEAM_ALLIANCE][bgTypeId].begin(),
@@ -199,7 +199,7 @@ BattlegroundTypeId RpgBgTypeValue::Calculate()
continue;
std::map<TeamId, std::map<BattlegroundTypeId, std::vector<uint32>>> battleMastersCache =
sRandomPlayerbotMgr->getBattleMastersCache();
sRandomPlayerbotMgr.getBattleMastersCache();
for (auto& entry : battleMastersCache[TEAM_NEUTRAL][bgTypeId])
if (entry == guidPosition.GetEntry())

View File

@@ -60,8 +60,8 @@ Unit* RtiTargetValue::Calculate()
Unit* unit = botAI->GetUnit(guid);
if (!unit || unit->isDead() || !bot->IsWithinLOSInMap(unit) || !AttackersValue::IsValidTarget(unit, bot) ||
sServerFacade->IsDistanceGreaterThan(sServerFacade->GetDistance2d(bot, unit),
sPlayerbotAIConfig->sightDistance))
ServerFacade::instance().IsDistanceGreaterThan(ServerFacade::instance().GetDistance2d(bot, unit),
sPlayerbotAIConfig.sightDistance))
return nullptr;
// Also prevent chasing raid icon targets that are too far away from the master,
@@ -69,8 +69,8 @@ Unit* RtiTargetValue::Calculate()
if (Player* master = botAI->GetMaster())
{
if (master->IsInWorld() && master->GetMapId() == unit->GetMapId() &&
sServerFacade->IsDistanceGreaterThan(sServerFacade->GetDistance2d(master, unit),
sPlayerbotAIConfig->sightDistance))
ServerFacade::instance().IsDistanceGreaterThan(ServerFacade::instance().GetDistance2d(master, unit),
sPlayerbotAIConfig.sightDistance))
return nullptr;
}

View File

@@ -30,7 +30,7 @@ Unit* SnareTargetValue::Calculate()
return unit;
case CHASE_MOTION_TYPE:
{
chaseTarget = sServerFacade->GetChaseTarget(unit);
chaseTarget = ServerFacade::instance().GetChaseTarget(unit);
if (!chaseTarget)
continue;
Player* chaseTargetPlayer = ObjectAccessor::FindPlayer(chaseTarget->GetGUID());

View File

@@ -48,7 +48,7 @@ WorldLocation Stance::GetNearLocation(float angle, float distance)
WorldLocation MoveStance::GetLocationInternal()
{
Unit* target = GetTarget();
float distance = std::max(sPlayerbotAIConfig->meleeDistance, target->GetCombatReach());
float distance = std::max(sPlayerbotAIConfig.meleeDistance, target->GetCombatReach());
float angle = GetAngle();
return GetNearLocation(angle, distance);
@@ -56,7 +56,7 @@ WorldLocation MoveStance::GetLocationInternal()
std::string const Stance::GetTargetName() { return "current target"; }
float Stance::GetMaxDistance() { return sPlayerbotAIConfig->contactDistance; }
float Stance::GetMaxDistance() { return sPlayerbotAIConfig.contactDistance; }
StanceValue::~StanceValue()
{

View File

@@ -183,8 +183,8 @@ bool IsInCombatValue::Calculate()
continue;
if (member->IsInCombat() &&
sServerFacade->IsDistanceLessOrEqualThan(sServerFacade->GetDistance2d(member, bot),
sPlayerbotAIConfig->reactDistance))
ServerFacade::instance().IsDistanceLessOrEqualThan(ServerFacade::instance().GetDistance2d(member, bot),
sPlayerbotAIConfig.reactDistance))
return true;
}
}

View File

@@ -175,4 +175,4 @@ Unit* BossTargetValue::Calculate()
{
FindBossTargetStrategy strategy(botAI);
return FindTarget(&strategy);
}
}