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

@@ -51,7 +51,7 @@ MovementAction::MovementAction(PlayerbotAI* botAI, std::string const name) : Act
void MovementAction::CreateWp(Player* wpOwner, float x, float y, float z, float o, uint32 entry, bool important)
{
float dist = wpOwner->GetDistance(x, y, z);
float delay = 1000.0f * dist / wpOwner->GetSpeed(MOVE_RUN) + sPlayerbotAIConfig->reactDelay;
float delay = 1000.0f * dist / wpOwner->GetSpeed(MOVE_RUN) + sPlayerbotAIConfig.reactDelay;
// if (!important)
// delay *= 0.25;
@@ -195,8 +195,8 @@ bool MovementAction::MoveTo(uint32 mapId, float x, float y, float z, bool idle,
bool generatePath = !bot->IsFlying() && !bot->isSwimming();
bool disableMoveSplinePath =
sPlayerbotAIConfig->disableMoveSplinePath >= 2 ||
(sPlayerbotAIConfig->disableMoveSplinePath == 1 && bot->InBattleground());
sPlayerbotAIConfig.disableMoveSplinePath >= 2 ||
(sPlayerbotAIConfig.disableMoveSplinePath == 1 && bot->InBattleground());
if (Vehicle* vehicle = bot->GetVehicle())
{
VehicleSeatEntry const* seat = vehicle->GetSeatForPassenger(bot);
@@ -216,7 +216,7 @@ bool MovementAction::MoveTo(uint32 mapId, float x, float y, float z, bool idle,
delay -= botAI->GetReactDelay();
}
delay = std::max(.0f, delay);
delay = std::min((float)sPlayerbotAIConfig->maxWaitForMove, delay);
delay = std::min((float)sPlayerbotAIConfig.maxWaitForMove, delay);
AI_VALUE(LastMovement&, "last movement").Set(mapId, x, y, z, bot->GetOrientation(), delay, priority);
return true;
}
@@ -241,7 +241,7 @@ bool MovementAction::MoveTo(uint32 mapId, float x, float y, float z, bool idle,
delay -= botAI->GetReactDelay();
}
delay = std::max(.0f, delay);
delay = std::min((float)sPlayerbotAIConfig->maxWaitForMove, delay);
delay = std::min((float)sPlayerbotAIConfig.maxWaitForMove, delay);
AI_VALUE(LastMovement&, "last movement").Set(mapId, x, y, z, bot->GetOrientation(), delay, priority);
return true;
}
@@ -250,7 +250,7 @@ bool MovementAction::MoveTo(uint32 mapId, float x, float y, float z, bool idle,
{
float modifiedZ;
Movement::PointsArray path =
SearchForBestPath(x, y, z, modifiedZ, sPlayerbotAIConfig->maxMovementSearchTime, normal_only);
SearchForBestPath(x, y, z, modifiedZ, sPlayerbotAIConfig.maxMovementSearchTime, normal_only);
if (modifiedZ == INVALID_HEIGHT)
return false;
float distance = bot->GetExactDist(x, y, modifiedZ);
@@ -272,7 +272,7 @@ bool MovementAction::MoveTo(uint32 mapId, float x, float y, float z, bool idle,
delay -= botAI->GetReactDelay();
}
delay = std::max(.0f, delay);
delay = std::min((float)sPlayerbotAIConfig->maxWaitForMove, delay);
delay = std::min((float)sPlayerbotAIConfig.maxWaitForMove, delay);
AI_VALUE(LastMovement&, "last movement").Set(mapId, x, y, z, bot->GetOrientation(), delay, priority);
return true;
}
@@ -308,8 +308,8 @@ bool MovementAction::MoveTo(uint32 mapId, float x, float y, float z, bool idle,
// }
// }
// float minDist = sPlayerbotAIConfig->targetPosRecalcDistance; //Minium distance a bot should move.
// float maxDist = sPlayerbotAIConfig->reactDistance; //Maxium distance a bot can move in one single
// float minDist = sPlayerbotAIConfig.targetPosRecalcDistance; //Minium distance a bot should move.
// float maxDist = sPlayerbotAIConfig.reactDistance; //Maxium distance a bot can move in one single
// action. float originalZ = z; // save original destination height to check
// if bot needs to fly up
@@ -372,9 +372,9 @@ bool MovementAction::MoveTo(uint32 mapId, float x, float y, float z, bool idle,
// if (startPosition.getMapId() != endPosition.getMapId() || totalDistance > maxDist)
// {
// if (!sTravelNodeMap->getNodes().empty() && !bot->InBattleground())
// if (!TravelNodeMap::instance().getNodes().empty() && !bot->InBattleground())
// {
// if (sPlayerbotAIConfig->tweakValue)
// if (sPlayerbotAIConfig.tweakValue)
// {
// if (lastMove.future.valid())
// {
@@ -388,12 +388,12 @@ bool MovementAction::MoveTo(uint32 mapId, float x, float y, float z, bool idle,
// }
// }
// else
// movePath = sTravelNodeMap->getFullPath(startPosition, endPosition, bot);
// movePath = TravelNodeMap::instance().getFullPath(startPosition, endPosition, bot);
// if (movePath.empty())
// {
// //We have no path. Beyond 450yd the standard PathGenerator will probably move the wrong way.
// if (sServerFacade->IsDistanceGreaterThan(totalDistance, maxDist * 3))
// if (ServerFacade::instance().IsDistanceGreaterThan(totalDistance, maxDist * 3))
// {
// movePath.clear();
// movePath.addPoint(endPosition);
@@ -402,7 +402,7 @@ bool MovementAction::MoveTo(uint32 mapId, float x, float y, float z, bool idle,
// bot->StopMoving();
// if (botAI->HasStrategy("debug move", BOT_STATE_NON_COMBAT))
// botAI->TellMasterNoFacing("I have no path");
// LOG_DEBUG("playerbots", "sServerFacade->IsDistanceGreaterThan(totalDistance, maxDist * 3)");
// LOG_DEBUG("playerbots", "ServerFacade::instance().IsDistanceGreaterThan(totalDistance, maxDist * 3)");
// return false;
// }
@@ -450,7 +450,7 @@ bool MovementAction::MoveTo(uint32 mapId, float x, float y, float z, bool idle,
// if (pathType == TravelNodePathType::portal) // && !botAI->isRealPlayer())
// {
// //Log bot movement
// if (sPlayerbotAIConfig->hasLog("bot_movement.csv"))
// if (sPlayerbotAIConfig.hasLog("bot_movement.csv"))
// {
// WorldPosition telePos;
// if (entry)
@@ -463,7 +463,7 @@ bool MovementAction::MoveTo(uint32 mapId, float x, float y, float z, bool idle,
// telePos = movePosition;
// std::ostringstream out;
// out << sPlayerbotAIConfig->GetTimestampStr() << "+00,";
// out << sPlayerbotAIConfig.GetTimestampStr() << "+00,";
// out << bot->GetName() << ",";
// if (telePos && telePos.GetExactDist(movePosition) > 0.001)
// startPosition.printWKT({ startPosition, movePosition, telePos }, out, 1);
@@ -475,7 +475,7 @@ bool MovementAction::MoveTo(uint32 mapId, float x, float y, float z, bool idle,
// out << bot->GetLevel() << ",";
// out << (entry ? -1 : entry);
// sPlayerbotAIConfig->log("bot_movement.csv", out.str().c_str());
// sPlayerbotAIConfig.log("bot_movement.csv", out.str().c_str());
// }
// if (entry)
@@ -621,10 +621,10 @@ bool MovementAction::MoveTo(uint32 mapId, float x, float y, float z, bool idle,
// }
// //Log bot movement
// if (sPlayerbotAIConfig->hasLog("bot_movement.csv") && lastMove.lastMoveShort.GetExactDist(movePosition) > 0.001)
// if (sPlayerbotAIConfig.hasLog("bot_movement.csv") && lastMove.lastMoveShort.GetExactDist(movePosition) > 0.001)
// {
// std::ostringstream out;
// out << sPlayerbotAIConfig->GetTimestampStr() << "+00,";
// out << sPlayerbotAIConfig.GetTimestampStr() << "+00,";
// out << bot->GetName() << ",";
// startPosition.printWKT({ startPosition, movePosition }, out, 1);
// out << std::to_string(bot->getRace()) << ",";
@@ -632,7 +632,7 @@ bool MovementAction::MoveTo(uint32 mapId, float x, float y, float z, bool idle,
// out << bot->GetLevel();
// out << 0;
// sPlayerbotAIConfig->log("bot_movement.csv", out.str().c_str());
// sPlayerbotAIConfig.log("bot_movement.csv", out.str().c_str());
// }
// // LOG_DEBUG("playerbots", "({}, {}) -> ({}, {})", startPosition.getX(), startPosition.getY(),
// movePosition.getX(), movePosition.getY()); if (!react)
@@ -694,7 +694,7 @@ bool MovementAction::MoveTo(uint32 mapId, float x, float y, float z, bool idle,
// if (botAI->GetMaster())
// {
// if (botAI->GetMaster()->m_movementInfo.HasMovementFlag(MOVEMENTFLAG_WALKING) &&
// sServerFacade->GetDistance2d(bot, botAI->GetMaster()) < 20.0f)
// ServerFacade::instance().GetDistance2d(bot, botAI->GetMaster()) < 20.0f)
// masterWalking = true;
// }
@@ -787,7 +787,7 @@ bool MovementAction::MoveTo(WorldObject* target, float distance, MovementPriorit
float angle = bot->GetAngle(target);
float needToGo = distanceToTarget - distance;
float maxDistance = sPlayerbotAIConfig->spellDistance;
float maxDistance = sPlayerbotAIConfig.spellDistance;
if (needToGo > 0 && needToGo > maxDistance)
needToGo = maxDistance;
else if (needToGo < 0 && needToGo < -maxDistance)
@@ -898,8 +898,8 @@ bool MovementAction::IsMovingAllowed(WorldObject* target)
if (bot->GetMapId() != target->GetMapId())
return false;
// float distance = sServerFacade->GetDistance2d(bot, target);
// if (!bot->InBattleground() && distance > sPlayerbotAIConfig->reactDistance)
// float distance = ServerFacade::instance().GetDistance2d(bot, target);
// if (!bot->InBattleground() && distance > sPlayerbotAIConfig.reactDistance)
// return false;
return IsMovingAllowed();
@@ -923,7 +923,7 @@ bool MovementAction::IsDuplicateMove(uint32 mapId, float x, float y, float z)
LastMovement& lastMove = *context->GetValue<LastMovement&>("last movement");
// heuristic 5s
if (lastMove.msTime + sPlayerbotAIConfig->maxWaitForMove < getMSTime() ||
if (lastMove.msTime + sPlayerbotAIConfig.maxWaitForMove < getMSTime() ||
lastMove.lastMoveShort.GetExactDist(x, y, z) > 0.01f)
return false;
@@ -1046,7 +1046,7 @@ void MovementAction::UpdateMovementState()
// if (bot->GetMotionMaster()->GetCurrentMovementGeneratorType() == CHASE_MOTION_TYPE && bot->CanNotReachTarget() &&
// !bot->InBattleground())
// {
// if (Unit* pTarget = sServerFacade->GetChaseTarget(bot))
// if (Unit* pTarget = ServerFacade::instance().GetChaseTarget(bot))
// {
// if (!bot->IsWithinMeleeRange(pTarget) && pTarget->IsCreature())
// {
@@ -1080,7 +1080,7 @@ void MovementAction::UpdateMovementState()
// bot->GetMotionMaster()->GetCurrentMovementGeneratorType() == POINT_MOTION_TYPE) && bot->CanNotReachTarget()
// && !bot->InBattleground())
// {
// if (Unit* pTarget = sServerFacade->GetChaseTarget(bot))
// if (Unit* pTarget = ServerFacade::instance().GetChaseTarget(bot))
// {
// if (pTarget != botAI->GetGroupLeader())
// return;
@@ -1117,8 +1117,8 @@ bool MovementAction::Follow(Unit* target, float distance, float angle)
if (!target)
return false;
if (!bot->InBattleground() && sServerFacade->IsDistanceLessOrEqualThan(sServerFacade->GetDistance2d(bot, target),
sPlayerbotAIConfig->followDistance))
if (!bot->InBattleground() && ServerFacade::instance().IsDistanceLessOrEqualThan(ServerFacade::instance().GetDistance2d(bot, target),
sPlayerbotAIConfig.followDistance))
{
// botAI->TellError("No need to follow");
return false;
@@ -1126,9 +1126,9 @@ bool MovementAction::Follow(Unit* target, float distance, float angle)
/*
if (!bot->InBattleground()
&& sServerFacade->IsDistanceLessOrEqualThan(sServerFacade->GetDistance2d(bot, target->GetPositionX(),
target->GetPositionY()), sPlayerbotAIConfig->sightDistance)
&& abs(bot->GetPositionZ() - target->GetPositionZ()) >= sPlayerbotAIConfig->spellDistance &&
&& ServerFacade::instance().IsDistanceLessOrEqualThan(ServerFacade::instance().GetDistance2d(bot, target->GetPositionX(),
target->GetPositionY()), sPlayerbotAIConfig.sightDistance)
&& abs(bot->GetPositionZ() - target->GetPositionZ()) >= sPlayerbotAIConfig.spellDistance &&
botAI->HasRealPlayerMaster()
&& (target->GetMapId() && bot->GetMapId() != target->GetMapId()))
{
@@ -1189,13 +1189,13 @@ bool MovementAction::Follow(Unit* target, float distance, float angle)
WorldPosition botPos(bot);
WorldPosition cPos(corpse);
if (botPos.fDist(cPos) > sPlayerbotAIConfig->spellDistance)
if (botPos.fDist(cPos) > sPlayerbotAIConfig.spellDistance)
return MoveTo(cPos.getMapId(), cPos.getX(), cPos.getY(), cPos.getZ());
}
}
if (sServerFacade->IsDistanceGreaterOrEqualThan(sServerFacade->GetDistance2d(bot, target),
sPlayerbotAIConfig->sightDistance))
if (ServerFacade::instance().IsDistanceGreaterOrEqualThan(ServerFacade::instance().GetDistance2d(bot, target),
sPlayerbotAIConfig.sightDistance))
{
if (target->GetGUID().IsPlayer())
{
@@ -1238,11 +1238,11 @@ bool MovementAction::Follow(Unit* target, float distance, float angle)
}
if (!target->HasUnitState(UNIT_STATE_IN_FLIGHT))
return MoveTo(target, sPlayerbotAIConfig->followDistance);
return MoveTo(target, sPlayerbotAIConfig.followDistance);
}
if (sServerFacade->IsDistanceLessOrEqualThan(sServerFacade->GetDistance2d(bot, target),
sPlayerbotAIConfig->followDistance))
if (ServerFacade::instance().IsDistanceLessOrEqualThan(ServerFacade::instance().GetDistance2d(bot, target),
sPlayerbotAIConfig.followDistance))
{
// botAI->TellError("No need to follow");
return false;
@@ -1251,8 +1251,8 @@ bool MovementAction::Follow(Unit* target, float distance, float angle)
if (target->IsFriendlyTo(bot) && bot->IsMounted() && AI_VALUE(GuidVector, "all targets").empty())
distance += angle;
if (!bot->InBattleground() && sServerFacade->IsDistanceLessOrEqualThan(sServerFacade->GetDistance2d(bot, target),
sPlayerbotAIConfig->followDistance))
if (!bot->InBattleground() && ServerFacade::instance().IsDistanceLessOrEqualThan(ServerFacade::instance().GetDistance2d(bot, target),
sPlayerbotAIConfig.followDistance))
{
// botAI->TellError("No need to follow");
return false;
@@ -1274,7 +1274,7 @@ bool MovementAction::Follow(Unit* target, float distance, float angle)
if (bot->GetMotionMaster()->GetCurrentMovementGeneratorType() == FOLLOW_MOTION_TYPE)
{
Unit* currentTarget = sServerFacade->GetChaseTarget(bot);
Unit* currentTarget = ServerFacade::instance().GetChaseTarget(bot);
if (currentTarget && currentTarget->GetGUID() == target->GetGUID())
return false;
}
@@ -1347,13 +1347,13 @@ void MovementAction::WaitForReach(float distance)
{
float delay = 1000.0f * MoveDelay(distance);
if (delay > sPlayerbotAIConfig->maxWaitForMove)
delay = sPlayerbotAIConfig->maxWaitForMove;
if (delay > sPlayerbotAIConfig.maxWaitForMove)
delay = sPlayerbotAIConfig.maxWaitForMove;
Unit* target = *botAI->GetAiObjectContext()->GetValue<Unit*>("current target");
Unit* player = *botAI->GetAiObjectContext()->GetValue<Unit*>("enemy player target");
if ((player || target) && delay > sPlayerbotAIConfig->globalCoolDown)
delay = sPlayerbotAIConfig->globalCoolDown;
if ((player || target) && delay > sPlayerbotAIConfig.globalCoolDown)
delay = sPlayerbotAIConfig.globalCoolDown;
if (delay < 0)
delay = 0;
@@ -1378,7 +1378,7 @@ bool MovementAction::Flee(Unit* target)
if (!target)
return false;
if (!sPlayerbotAIConfig->fleeingEnabled)
if (!sPlayerbotAIConfig.fleeingEnabled)
return false;
if (!IsMovingAllowed())
@@ -1390,7 +1390,7 @@ bool MovementAction::Flee(Unit* target)
bool foundFlee = false;
time_t lastFlee = AI_VALUE(LastMovement&, "last movement").lastFlee;
time_t now = time(0);
uint32 fleeDelay = urand(2, sPlayerbotAIConfig->returnDelay / 1000);
uint32 fleeDelay = urand(2, sPlayerbotAIConfig.returnDelay / 1000);
if (lastFlee)
{
@@ -1406,7 +1406,7 @@ bool MovementAction::Flee(Unit* target)
if (Group* group = bot->GetGroup())
{
Unit* fleeTarget = nullptr;
float fleeDistance = sPlayerbotAIConfig->sightDistance;
float fleeDistance = sPlayerbotAIConfig.sightDistance;
for (GroupReference* gref = group->GetFirstMember(); gref; gref = gref->next())
{
@@ -1416,8 +1416,8 @@ bool MovementAction::Flee(Unit* target)
if (botAI->IsTank(player))
{
float distanceToTank = sServerFacade->GetDistance2d(bot, player);
float distanceToTarget = sServerFacade->GetDistance2d(bot, target);
float distanceToTank = ServerFacade::instance().GetDistance2d(bot, player);
float distanceToTarget = ServerFacade::instance().GetDistance2d(bot, target);
if (distanceToTank < fleeDistance)
{
fleeTarget = player;
@@ -1460,10 +1460,10 @@ bool MovementAction::Flee(Unit* target)
if ((isHealer && botAI->IsHeal(player)) || needHealer)
{
float distanceToHealer = sServerFacade->GetDistance2d(bot, player);
float distanceToTarget = sServerFacade->GetDistance2d(player, target);
float distanceToHealer = ServerFacade::instance().GetDistance2d(bot, player);
float distanceToTarget = ServerFacade::instance().GetDistance2d(player, target);
if (distanceToHealer < fleeDistance &&
distanceToTarget > (botAI->GetRange("shoot") / 2 + sPlayerbotAIConfig->followDistance) &&
distanceToTarget > (botAI->GetRange("shoot") / 2 + sPlayerbotAIConfig.followDistance) &&
(needHealer || player->IsWithinLOSInMap(target)))
{
fleeTarget = player;
@@ -1473,10 +1473,10 @@ bool MovementAction::Flee(Unit* target)
}
else if (isRanged && botAI->IsRanged(player))
{
float distanceToRanged = sServerFacade->GetDistance2d(bot, player);
float distanceToTarget = sServerFacade->GetDistance2d(player, target);
float distanceToRanged = ServerFacade::instance().GetDistance2d(bot, player);
float distanceToTarget = ServerFacade::instance().GetDistance2d(player, target);
if (distanceToRanged < fleeDistance &&
distanceToTarget > (botAI->GetRange("shoot") / 2 + sPlayerbotAIConfig->followDistance) &&
distanceToTarget > (botAI->GetRange("shoot") / 2 + sPlayerbotAIConfig.followDistance) &&
player->IsWithinLOSInMap(target))
{
fleeTarget = player;
@@ -1485,10 +1485,10 @@ bool MovementAction::Flee(Unit* target)
}
}
// remember any group member in case no one else found
float distanceToFlee = sServerFacade->GetDistance2d(bot, player);
float distanceToTarget = sServerFacade->GetDistance2d(player, target);
float distanceToFlee = ServerFacade::instance().GetDistance2d(bot, player);
float distanceToTarget = ServerFacade::instance().GetDistance2d(player, target);
if (distanceToFlee < spareDistance &&
distanceToTarget > (botAI->GetRange("shoot") / 2 + sPlayerbotAIConfig->followDistance) &&
distanceToTarget > (botAI->GetRange("shoot") / 2 + sPlayerbotAIConfig.followDistance) &&
player->IsWithinLOSInMap(target))
{
spareTarget = player;
@@ -1508,8 +1508,8 @@ bool MovementAction::Flee(Unit* target)
if ((!fleeTarget || !foundFlee) && master && master->IsAlive() && master->IsWithinLOSInMap(target))
{
float distanceToTarget = sServerFacade->GetDistance2d(master, target);
if (distanceToTarget > (botAI->GetRange("shoot") / 2 + sPlayerbotAIConfig->followDistance))
float distanceToTarget = ServerFacade::instance().GetDistance2d(master, target);
if (distanceToTarget > (botAI->GetRange("shoot") / 2 + sPlayerbotAIConfig.followDistance))
foundFlee = MoveNear(master);
}
}
@@ -1846,7 +1846,7 @@ void MovementAction::DoMovePoint(Unit* unit, float x, float y, float z, bool gen
bool FleeAction::Execute(Event event)
{
return MoveAway(AI_VALUE(Unit*, "current target"), sPlayerbotAIConfig->fleeDistance, true);
return MoveAway(AI_VALUE(Unit*, "current target"), sPlayerbotAIConfig.fleeDistance, true);
}
bool FleeAction::isUseful()
@@ -1924,8 +1924,8 @@ bool AvoidAoeAction::AvoidAuraWithDynamicObj()
{
return false;
}
if (sPlayerbotAIConfig->aoeAvoidSpellWhitelist.find(spellInfo->Id) !=
sPlayerbotAIConfig->aoeAvoidSpellWhitelist.end())
if (sPlayerbotAIConfig.aoeAvoidSpellWhitelist.find(spellInfo->Id) !=
sPlayerbotAIConfig.aoeAvoidSpellWhitelist.end())
return false;
DynamicObject* dynOwner = aura->GetDynobjOwner();
@@ -1934,7 +1934,7 @@ bool AvoidAoeAction::AvoidAuraWithDynamicObj()
return false;
}
float radius = dynOwner->GetRadius();
if (!radius || radius > sPlayerbotAIConfig->maxAoeAvoidRadius)
if (!radius || radius > sPlayerbotAIConfig.maxAoeAvoidRadius)
return false;
if (bot->GetDistance(dynOwner) > radius)
{
@@ -1944,7 +1944,7 @@ bool AvoidAoeAction::AvoidAuraWithDynamicObj()
name << spellInfo->SpellName[LOCALE_enUS]; // << "] (aura)";
if (FleePosition(dynOwner->GetPosition(), radius))
{
if (sPlayerbotAIConfig->tellWhenAvoidAoe && lastTellTimer < time(NULL) - 10)
if (sPlayerbotAIConfig.tellWhenAvoidAoe && lastTellTimer < time(NULL) - 10)
{
lastTellTimer = time(NULL);
lastMoveTimer = getMSTime();
@@ -1990,8 +1990,8 @@ bool AvoidAoeAction::AvoidGameObjectWithDamage()
continue;
}
if (sPlayerbotAIConfig->aoeAvoidSpellWhitelist.find(spellId) !=
sPlayerbotAIConfig->aoeAvoidSpellWhitelist.end())
if (sPlayerbotAIConfig.aoeAvoidSpellWhitelist.find(spellId) !=
sPlayerbotAIConfig.aoeAvoidSpellWhitelist.end())
continue;
const SpellInfo* spellInfo = sSpellMgr->GetSpellInfo(spellId);
@@ -2001,7 +2001,7 @@ bool AvoidAoeAction::AvoidGameObjectWithDamage()
}
float radius = (float)goInfo->trap.diameter / 2 + go->GetCombatReach();
if (!radius || radius > sPlayerbotAIConfig->maxAoeAvoidRadius)
if (!radius || radius > sPlayerbotAIConfig.maxAoeAvoidRadius)
continue;
if (bot->GetDistance(go) > radius)
@@ -2012,7 +2012,7 @@ bool AvoidAoeAction::AvoidGameObjectWithDamage()
name << spellInfo->SpellName[LOCALE_enUS]; // << "] (object)";
if (FleePosition(go->GetPosition(), radius))
{
if (sPlayerbotAIConfig->tellWhenAvoidAoe && lastTellTimer < time(NULL) - 10)
if (sPlayerbotAIConfig.tellWhenAvoidAoe && lastTellTimer < time(NULL) - 10)
{
lastTellTimer = time(NULL);
lastMoveTimer = getMSTime();
@@ -2061,8 +2061,8 @@ bool AvoidAoeAction::AvoidUnitWithDamageAura()
sSpellMgr->GetSpellInfo(spellInfo->Effects[aurEff->GetEffIndex()].TriggerSpell);
if (!triggerSpellInfo)
continue;
if (sPlayerbotAIConfig->aoeAvoidSpellWhitelist.find(triggerSpellInfo->Id) !=
sPlayerbotAIConfig->aoeAvoidSpellWhitelist.end())
if (sPlayerbotAIConfig.aoeAvoidSpellWhitelist.find(triggerSpellInfo->Id) !=
sPlayerbotAIConfig.aoeAvoidSpellWhitelist.end())
return false;
for (int j = 0; j < MAX_SPELL_EFFECTS; j++)
{
@@ -2073,13 +2073,13 @@ bool AvoidAoeAction::AvoidUnitWithDamageAura()
{
break;
}
if (!radius || radius > sPlayerbotAIConfig->maxAoeAvoidRadius)
if (!radius || radius > sPlayerbotAIConfig.maxAoeAvoidRadius)
continue;
std::ostringstream name;
name << triggerSpellInfo->SpellName[LOCALE_enUS]; //<< "] (unit)";
if (FleePosition(unit->GetPosition(), radius))
{
if (sPlayerbotAIConfig->tellWhenAvoidAoe && lastTellTimer < time(NULL) - 10)
if (sPlayerbotAIConfig.tellWhenAvoidAoe && lastTellTimer < time(NULL) - 10)
{
lastTellTimer = time(NULL);
lastMoveTimer = getMSTime();
@@ -2134,7 +2134,7 @@ Position MovementAction::BestPositionForMeleeToFlee(Position pos, float radius)
continue;
}
bool strict = checkAngle.strict;
float fleeDis = std::min(radius + 1.0f, sPlayerbotAIConfig->fleeDistance);
float fleeDis = std::min(radius + 1.0f, sPlayerbotAIConfig.fleeDistance);
float dx = bot->GetPositionX() + cos(angle) * fleeDis;
float dy = bot->GetPositionY() + sin(angle) * fleeDis;
float dz = bot->GetPositionZ();
@@ -2146,7 +2146,7 @@ Position MovementAction::BestPositionForMeleeToFlee(Position pos, float radius)
Position fleePos{dx, dy, dz};
if (strict && currentTarget &&
fleePos.GetExactDist(currentTarget) - currentTarget->GetCombatReach() >
sPlayerbotAIConfig->tooCloseDistance &&
sPlayerbotAIConfig.tooCloseDistance &&
bot->IsWithinMeleeRange(currentTarget))
{
continue;
@@ -2197,7 +2197,7 @@ Position MovementAction::BestPositionForRangedToFlee(Position pos, float radius)
continue;
}
bool strict = checkAngle.strict;
float fleeDis = std::min(radius + 1.0f, sPlayerbotAIConfig->fleeDistance);
float fleeDis = std::min(radius + 1.0f, sPlayerbotAIConfig.fleeDistance);
float dx = bot->GetPositionX() + cos(angle) * fleeDis;
float dy = bot->GetPositionY() + sin(angle) * fleeDis;
float dz = bot->GetPositionZ();
@@ -2208,13 +2208,13 @@ Position MovementAction::BestPositionForRangedToFlee(Position pos, float radius)
}
Position fleePos{dx, dy, dz};
if (strict && currentTarget &&
fleePos.GetExactDist(currentTarget) - currentTarget->GetCombatReach() > sPlayerbotAIConfig->spellDistance)
fleePos.GetExactDist(currentTarget) - currentTarget->GetCombatReach() > sPlayerbotAIConfig.spellDistance)
{
continue;
}
if (strict && currentTarget &&
fleePos.GetExactDist(currentTarget) - currentTarget->GetCombatReach() <
(sPlayerbotAIConfig->tooCloseDistance))
(sPlayerbotAIConfig.tooCloseDistance))
{
continue;
}
@@ -2357,7 +2357,7 @@ Position CombatFormationMoveAction::AverageGroupPos(float dis, bool ranged, bool
continue;
if (!member->IsAlive() || member->GetMapId() != bot->GetMapId() || member->IsCharmed() ||
sServerFacade->GetDistance2d(bot, member) > dis)
ServerFacade::instance().GetDistance2d(bot, member) > dis)
continue;
averageX += member->GetPositionX();
@@ -2395,7 +2395,7 @@ float CombatFormationMoveAction::AverageGroupAngle(Unit* from, bool ranged, bool
continue;
if (!member->IsAlive() || member->GetMapId() != bot->GetMapId() || member->IsCharmed() ||
sServerFacade->GetDistance2d(bot, member) > sPlayerbotAIConfig->sightDistance)
ServerFacade::instance().GetDistance2d(bot, member) > sPlayerbotAIConfig.sightDistance)
continue;
cnt++;
@@ -2437,7 +2437,7 @@ Player* CombatFormationMoveAction::NearestGroupMember(float dis)
{
Player* member = ObjectAccessor::FindPlayer(itr->guid);
if (!member || !member->IsAlive() || member == bot || member->GetMapId() != bot->GetMapId() ||
member->IsCharmed() || sServerFacade->GetDistance2d(bot, member) > dis)
member->IsCharmed() || ServerFacade::instance().GetDistance2d(bot, member) > dis)
continue;
if (nearestDis > bot->GetExactDist(member))
{
@@ -2651,7 +2651,7 @@ bool MoveToLootAction::Execute(Event event)
if (!loot.IsLootPossible(bot))
return false;
return MoveNear(loot.GetWorldObject(bot), sPlayerbotAIConfig->contactDistance);
return MoveNear(loot.GetWorldObject(bot), sPlayerbotAIConfig.contactDistance);
}
bool MoveOutOfEnemyContactAction::Execute(Event event)
@@ -2660,7 +2660,7 @@ bool MoveOutOfEnemyContactAction::Execute(Event event)
if (!target)
return false;
return MoveTo(target, sPlayerbotAIConfig->contactDistance);
return MoveTo(target, sPlayerbotAIConfig.contactDistance);
}
bool MoveOutOfEnemyContactAction::isUseful() { return AI_VALUE2(bool, "inside target", "current target"); }
@@ -2674,8 +2674,8 @@ bool SetFacingTargetAction::Execute(Event event)
if (bot->HasUnitState(UNIT_STATE_IN_FLIGHT))
return true;
sServerFacade->SetFacingTo(bot, target);
botAI->SetNextCheckDelay(sPlayerbotAIConfig->reactDelay);
ServerFacade::instance().SetFacingTo(bot, target);
botAI->SetNextCheckDelay(sPlayerbotAIConfig.reactDelay);
return true;
}
@@ -2754,7 +2754,7 @@ bool SetBehindTargetAction::Execute(Event event)
bool MoveOutOfCollisionAction::Execute(Event event)
{
float angle = M_PI * 2000 / frand(1.f, 1000.f);
float distance = sPlayerbotAIConfig->followDistance;
float distance = sPlayerbotAIConfig.followDistance;
return MoveTo(bot->GetMapId(), bot->GetPositionX() + cos(angle) * distance,
bot->GetPositionY() + sin(angle) * distance, bot->GetPositionZ());
}
@@ -2771,7 +2771,7 @@ bool MoveOutOfCollisionAction::isUseful()
bool MoveRandomAction::Execute(Event event)
{
float distance = sPlayerbotAIConfig->tooCloseDistance + urand(10, 30);
float distance = sPlayerbotAIConfig.tooCloseDistance + urand(10, 30);
Map* map = bot->GetMap();
for (int i = 0; i < 3; ++i)