Crow 9d787ca0b4
Make Vashj Strategy Compatible with Acore Bug & Use AI Instance for Targeting (#2391)
<!--
Thank you for contributing to mod-playerbots, please make sure that
you...
1. Submit your PR to the test-staging branch, not master.
2. Read the guidelines below before submitting.
3. Don't delete parts of this template.

DESIGN PHILOSOPHY: We prioritize STABILITY, PERFORMANCE, AND
PREDICTABILITY over behavioral realism.

Every action and decision executes PER BOT AND PER TRIGGER. Small
increases in logic complexity scale
poorly across thousands of bots and negatively affect all. We prioritize
a stable system over a smarter
one. Bots don't need to behave perfectly; believable behavior is the
goal, not human simulation.
Default behavior must be cheap in processing; expensive behavior must be
opt-in.

Before submitting, make sure your changes aligns with these principles.
-->

## Pull Request Description
<!-- Describe what this change does and why it is needed -->
Lady Vashj has been screwed up in Acore for a month or two. In Phase 2,
only one generator activates (instead of four). As a result, disabling
one generator brings Vashj into Phase 3. The strategy uses Vashj's HP +
unit state to determine phase--with the Acore bug, Vashj enters Phase 3
at <65% HP (instead of the correct <50% HP, as deactivating a generator
damages her by 5%) so under the current strategy, bots won't assume
Phase 3 strategies at the right moment. I tried looking into the issue
with Vashj in Acore and cannot figure it out, and I've had an issue open
with Acore and don't know if/when it will be fixed. In the meantime, I'm
modifying the strategy to use the shield barrier aura check on Vashj
instead so it will work regardless of Vashj's HP at the time the
generators are disabled. If/when Vashj is fixed, the strategy will still
work.

I also changed bot-side targeting checks throughout the strategies I've
written from GetVictim() and GetTarget() to using the AI's target state
via "current target." This approach I believe is the best way to
actually check for the target because a GetVictim() check can lock up
Elemental Shamans and Balance Druids due to them not being able to start
an attack to pass that check when outside of spell range, and a
GetTarget() check can occasionally not align with the target that the
bot is actually attacking.

- In effect, this should reduce cases where the bot AI thinks it is on
the right raid target but encounter logic disagrees because the live
victim or client selection is lagging or different.
- Exception: multipliers for blocking TankAssistAction still use a
GetVictim() check. This is because "current target" processes before
issuing an attack, and the targeting check for TankAssistAction is not
to suppress it if the bot hasn't actually issued an attack.

There is a lot more than could be refactored with past strategies to
make them better, but that's for another day. This PR is intended to be
limited and simple to review.

## Feature Evaluation
<!--
If your PR is very minimal (comment typo, wrong ID reference, etc), and
it is very obvious it will not have
any impact on performance, you may skip these question. If necessary, a
maintainer may ask you for them later.
-->

<!-- Please answer the following: -->
- Describe the **minimum logic** required to achieve the intended
behavior.
- Describe the **processing cost** when this logic executes across many
bots.
Logic is described above. There should be no relevant impact on
processing cost.


## How to Test the Changes
<!--
- Step-by-step instructions to test the change.
- Any required setup (e.g. multiple players, number of bots, specific
configuration).
- Expected behavior and how to verify it.
-->

Attempt Lady Vashj with the current bugged version. After disabling the
lone generator, bots should enter Phase 3 strategies and the encounter
should be completable.

Otherwise, generally run raids, and confirm there are no issues with
bots switching targets or starting attacking.


## Impact Assessment
<!-- As a generic test, before and after measure of pmon (playerbot pmon
tick) can help you here. -->
- Does this change increase per-bot/per-tick processing or risk scaling
poorly with thousands of bots?
    - - [x] No, not at all
    - - [ ] Minimal impact (**explain below**)
    - - [ ] Moderate impact (**explain below**)



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



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



## AI Assistance
<!--
AI assistance is allowed, but all submitted code must be fully
understood, reviewed, and owned by the contributor.
We expect contributors to be honest about what they do and do not
understand.
-->
Was AI assistance used while working on this change?
- - [x] No
- - [ ] Yes (**explain below**)
<!--
If yes, please specify:
- Purpose of usage (e.g. brainstorming, refactoring, documentation, code
generation).
- Which parts of the change were influenced or generated, and whether it
was thoroughly reviewed.
-->



<!--
TRANSLATIONS:
Anything new that the bots say in chat must be in a translatable format.
This is done using GetBotTextOrDefault,
which you can search for in the codebase to find examples. Your code
needs to have English as the default fallback,
while the full translations need to be in an SQL update file. The
languages in the file are the nine language
options supported by AzerothCore: English, Korean, French, German,
Chinese, Taiwanese, Spanish, Spanish Mexico, and
Russian. See
data/sql/playerbots/updates/2025_12_27_ai_playerbot_fishing_text.sql as
an example of a translation SQL
update, whose content are called within the codebase at
src/strategy/actions/FishingAction.cpp
-->

## Final Checklist

- - [x] Stability is not compromised.
- - [x] Performance impact is understood, tested, and acceptable.
- - [x] Added logic complexity is justified and explained.
- - [x] Any new bot dialogue lines are translated.
- - [x] Documentation updated if needed (Conf comments, WiKi commands).

## Notes for Reviewers
<!-- Anything else that's helpful to review or test your pull request.
-->
2026-05-15 23:27:42 -07:00

584 lines
20 KiB
C++

/*
* Copyright (C) 2016+ AzerothCore <www.azerothcore.org>, released under GNU AGPL v3 license, you may redistribute it
* and/or modify it under version 3 of the License, or (at your option), any later version.
*/
#include "RaidSSCHelpers.h"
#include "AiFactory.h"
#include "Creature.h"
#include "ObjectAccessor.h"
#include "Playerbots.h"
#include "RaidBossHelpers.h"
namespace SerpentShrineCavernHelpers
{
// Hydross the Unstable <Duke of Currents>
const Position HYDROSS_FROST_TANK_POSITION = { -236.669f, -358.352f, -0.828f };
const Position HYDROSS_NATURE_TANK_POSITION = { -225.471f, -327.790f, -3.682f };
std::unordered_map<uint32, time_t> hydrossFrostDpsWaitTimer;
std::unordered_map<uint32, time_t> hydrossNatureDpsWaitTimer;
std::unordered_map<uint32, time_t> hydrossChangeToFrostPhaseTimer;
std::unordered_map<uint32, time_t> hydrossChangeToNaturePhaseTimer;
bool HasMarkOfHydrossAt100Percent(Player* bot)
{
return bot->HasAura(SPELL_MARK_OF_HYDROSS_100) ||
bot->HasAura(SPELL_MARK_OF_HYDROSS_250) ||
bot->HasAura(SPELL_MARK_OF_HYDROSS_500);
}
bool HasNoMarkOfHydross(Player* bot)
{
return !bot->HasAura(SPELL_MARK_OF_HYDROSS_10) &&
!bot->HasAura(SPELL_MARK_OF_HYDROSS_25) &&
!bot->HasAura(SPELL_MARK_OF_HYDROSS_50) &&
!bot->HasAura(SPELL_MARK_OF_HYDROSS_100) &&
!bot->HasAura(SPELL_MARK_OF_HYDROSS_250) &&
!bot->HasAura(SPELL_MARK_OF_HYDROSS_500);
}
bool HasMarkOfCorruptionAt100Percent(Player* bot)
{
return bot->HasAura(SPELL_MARK_OF_CORRUPTION_100) ||
bot->HasAura(SPELL_MARK_OF_CORRUPTION_250) ||
bot->HasAura(SPELL_MARK_OF_CORRUPTION_500);
}
bool HasNoMarkOfCorruption(Player* bot)
{
return !bot->HasAura(SPELL_MARK_OF_CORRUPTION_10) &&
!bot->HasAura(SPELL_MARK_OF_CORRUPTION_25) &&
!bot->HasAura(SPELL_MARK_OF_CORRUPTION_50) &&
!bot->HasAura(SPELL_MARK_OF_CORRUPTION_100) &&
!bot->HasAura(SPELL_MARK_OF_CORRUPTION_250) &&
!bot->HasAura(SPELL_MARK_OF_CORRUPTION_500);
}
// The Lurker Below
const Position LURKER_MAIN_TANK_POSITION = { 23.706f, -406.038f, -19.686f };
std::unordered_map<uint32, time_t> lurkerSpoutTimer;
std::unordered_map<ObjectGuid, Position> lurkerRangedPositions;
bool IsLurkerCastingSpout(Unit* lurker)
{
if (!lurker || !lurker->HasUnitState(UNIT_STATE_CASTING))
return false;
Spell* currentSpell = lurker->GetCurrentSpell(CURRENT_GENERIC_SPELL);
if (!currentSpell)
return false;
uint32 spellId = currentSpell->m_spellInfo->Id;
bool isSpout = spellId == SPELL_SPOUT_VISUAL;
return isSpout;
}
// Leotheras the Blind
std::unordered_map<uint32, time_t> leotherasHumanFormDpsWaitTimer;
std::unordered_map<uint32, time_t> leotherasDemonFormDpsWaitTimer;
std::unordered_map<uint32, time_t> leotherasFinalPhaseDpsWaitTimer;
Unit* GetLeotherasHuman(Player* bot)
{
constexpr float searchRadius = 100.0f;
Creature* leotheras =
bot->FindNearestCreature(NPC_LEOTHERAS_THE_BLIND, searchRadius, true);
if (leotheras && leotheras->IsInCombat() &&
!leotheras->HasAura(SPELL_METAMORPHOSIS))
return leotheras;
return nullptr;
}
Unit* GetPhase2LeotherasDemon(Player* bot)
{
constexpr float searchRadius = 100.0f;
Creature* leotheras =
bot->FindNearestCreature(NPC_LEOTHERAS_THE_BLIND, searchRadius, true);
if (leotheras && leotheras->HasAura(SPELL_METAMORPHOSIS))
return leotheras;
return nullptr;
}
Unit* GetPhase3LeotherasDemon(Player* bot)
{
constexpr float searchRadius = 100.0f;
return bot->FindNearestCreature(NPC_SHADOW_OF_LEOTHERAS, searchRadius, true);
}
Unit* GetActiveLeotherasDemon(Player* bot)
{
Unit* phase2 = GetPhase2LeotherasDemon(bot);
Unit* phase3 = GetPhase3LeotherasDemon(bot);
return phase2 ? phase2 : phase3;
}
// (1) First priority is an assistant Warlock (real player or bot)
// (2) If no assistant Warlock, then look for any Warlock bot
Player* GetLeotherasDemonFormTank(Player* bot)
{
Group* group = bot->GetGroup();
if (!group)
return nullptr;
Player* fallbackWarlock = nullptr;
for (GroupReference* ref = group->GetFirstMember(); ref; ref = ref->next())
{
Player* member = ref->GetSource();
if (!member || !member->IsAlive() || member->getClass() != CLASS_WARLOCK)
continue;
if (group->IsAssistant(member->GetGUID()))
return member;
if (!fallbackWarlock && GET_PLAYERBOT_AI(member))
fallbackWarlock = member;
}
return fallbackWarlock;
}
// Fathom-Lord Karathress
const Position KARATHRESS_TANK_POSITION = { 474.403f, -531.118f, -7.548f };
const Position TIDALVESS_TANK_POSITION = { 511.282f, -501.162f, -13.158f };
const Position SHARKKIS_TANK_POSITION = { 508.057f, -541.109f, -10.133f };
const Position CARIBDIS_TANK_POSITION = { 464.462f, -475.820f, -13.158f };
const Position CARIBDIS_HEALER_POSITION = { 466.203f, -503.201f, -13.158f };
const Position CARIBDIS_RANGED_DPS_POSITION = { 463.197f, -501.190f, -13.158f };
std::unordered_map<uint32, time_t> karathressDpsWaitTimer;
// Morogrim Tidewalker
const Position TIDEWALKER_PHASE_1_TANK_POSITION = { 410.925f, -741.916f, -7.146f };
const Position TIDEWALKER_PHASE_TRANSITION_WAYPOINT = { 407.035f, -759.479f, -7.168f };
const Position TIDEWALKER_PHASE_2_TANK_POSITION = { 446.571f, -767.155f, -7.144f };
const Position TIDEWALKER_PHASE_2_RANGED_POSITION = { 432.595f, -766.288f, -7.145f };
std::unordered_map<ObjectGuid, uint8> tidewalkerTankStep;
std::unordered_map<ObjectGuid, uint8> tidewalkerRangedStep;
// Lady Vashj <Coilfang Matron>
const Position VASHJ_PLATFORM_CENTER_POSITION = { 29.634f, -923.541f, 42.902f };
std::unordered_map<ObjectGuid, bool> hasReachedVashjRangedPosition;
std::unordered_map<uint32, ObjectGuid> nearestTriggerGuid;
std::unordered_map<ObjectGuid, Position> intendedLineup;
std::unordered_map<uint32, time_t> lastImbueAttempt;
std::unordered_map<ObjectGuid, time_t> lastCoreInInventoryTime;
bool IsMainTankInSameSubgroup(PlayerbotAI* botAI, Player* bot)
{
Group* group = bot->GetGroup();
if (!group || !group->isRaidGroup())
return false;
uint8 botSubGroup = group->GetMemberGroup(bot->GetGUID());
if (botSubGroup >= MAX_RAID_SUBGROUPS)
return false;
for (GroupReference* ref = group->GetFirstMember(); ref; ref = ref->next())
{
Player* member = ref->GetSource();
if (!member || member == bot || !member->IsAlive())
continue;
if (group->GetMemberGroup(member->GetGUID()) != botSubGroup)
continue;
if (botAI->IsMainTank(member))
return true;
}
return false;
}
bool IsLadyVashjInPhase1(PlayerbotAI* botAI)
{
Unit* vashj =
botAI->GetAiObjectContext()->GetValue<Unit*>("find target", "lady vashj")->Get();
return vashj && vashj->GetHealthPct() > 70.0f;
}
bool IsLadyVashjInPhase2(PlayerbotAI* botAI)
{
Unit* vashj =
botAI->GetAiObjectContext()->GetValue<Unit*>("find target", "lady vashj")->Get();
return vashj && vashj->GetHealthPct() <= 70.0f && vashj->HasAura(SPELL_MAGIC_BARRIER);
}
bool IsLadyVashjInPhase3(PlayerbotAI* botAI)
{
Unit* vashj =
botAI->GetAiObjectContext()->GetValue<Unit*>("find target", "lady vashj")->Get();
return vashj && vashj->GetHealthPct() <= 70.0f && !vashj->HasAura(SPELL_MAGIC_BARRIER);
}
bool IsValidLadyVashjCombatNpc(Unit* unit, PlayerbotAI* botAI)
{
if (!unit || !unit->IsAlive())
return false;
uint32 entry = unit->GetEntry();
if (IsLadyVashjInPhase2(botAI))
{
return entry == NPC_TAINTED_ELEMENTAL || entry == NPC_ENCHANTED_ELEMENTAL ||
entry == NPC_COILFANG_ELITE || entry == NPC_COILFANG_STRIDER;
}
else if (IsLadyVashjInPhase3(botAI))
{
return entry == NPC_TAINTED_ELEMENTAL || entry == NPC_ENCHANTED_ELEMENTAL ||
entry == NPC_COILFANG_ELITE || entry == NPC_COILFANG_STRIDER ||
entry == NPC_TOXIC_SPOREBAT || entry == NPC_LADY_VASHJ;
}
return false;
}
Player* GetDesignatedCoreLooter(PlayerbotAI* botAI, Player* bot)
{
Group* group = bot->GetGroup();
if (!group)
return nullptr;
Player* leader = nullptr;
ObjectGuid leaderGuid = group->GetLeaderGUID();
if (!leaderGuid.IsEmpty())
leader = ObjectAccessor::FindPlayer(leaderGuid);
// If cheats are disabled, the group leader will be the designated looter
if (!botAI->HasCheat(BotCheatMask::raid))
return leader;
// Priority: (1) assistant melee DPS, (2) other melee DPS, (3) any ranged DPS
Player* meleeDpsAssistant = nullptr;
Player* meleeDps = nullptr;
Player* rangedDps = nullptr;
for (GroupReference* ref = group->GetFirstMember(); ref; ref = ref->next())
{
Player* member = ref->GetSource();
if (!member || !member->IsAlive() || member == leader)
continue;
PlayerbotAI* memberAI = GET_PLAYERBOT_AI(member);
if (!memberAI)
continue;
if (!meleeDpsAssistant && memberAI->IsMelee(member) &&
memberAI->IsDps(member) && group->IsAssistant(member->GetGUID()))
{
meleeDpsAssistant = member;
break;
}
if (!meleeDps && memberAI->IsMelee(member) && memberAI->IsDps(member))
meleeDps = member;
if (!rangedDps && memberAI->IsRangedDps(member))
rangedDps = member;
}
if (meleeDpsAssistant)
return meleeDpsAssistant;
if (meleeDps)
return meleeDps;
if (rangedDps)
return rangedDps;
return leader;
}
Player* GetFirstTaintedCorePasser(PlayerbotAI* botAI, Player* bot)
{
Group* group = bot->GetGroup();
if (!group)
return nullptr;
Player* designatedLooter = GetDesignatedCoreLooter(botAI, bot);
for (GroupReference* ref = group->GetFirstMember(); ref; ref = ref->next())
{
Player* member = ref->GetSource();
if (!member || !member->IsAlive() || member == designatedLooter)
continue;
PlayerbotAI* memberAI = GET_PLAYERBOT_AI(member);
if (memberAI && memberAI->IsAssistHealOfIndex(member, 0, true))
return member;
}
for (GroupReference* ref = group->GetFirstMember(); ref; ref = ref->next())
{
Player* member = ref->GetSource();
if (member && member->IsAlive() && GET_PLAYERBOT_AI(member) &&
!botAI->IsTank(member) && member != designatedLooter)
return member;
}
return nullptr;
}
Player* GetSecondTaintedCorePasser(PlayerbotAI* botAI, Player* bot)
{
Group* group = bot->GetGroup();
if (!group)
return nullptr;
Player* designatedLooter = GetDesignatedCoreLooter(botAI, bot);
Player* firstCorePasser = GetFirstTaintedCorePasser(botAI, bot);
for (GroupReference* ref = group->GetFirstMember(); ref; ref = ref->next())
{
Player* member = ref->GetSource();
if (!member || !member->IsAlive() || member == designatedLooter ||
member == firstCorePasser)
continue;
PlayerbotAI* memberAI = GET_PLAYERBOT_AI(member);
if (memberAI && memberAI->IsAssistHealOfIndex(member, 1, true))
return member;
}
for (GroupReference* ref = group->GetFirstMember(); ref; ref = ref->next())
{
Player* member = ref->GetSource();
if (member && member->IsAlive() && GET_PLAYERBOT_AI(member) &&
!botAI->IsTank(member) && member != designatedLooter &&
member != firstCorePasser)
return member;
}
return nullptr;
}
Player* GetThirdTaintedCorePasser(PlayerbotAI* botAI, Player* bot)
{
Group* group = bot->GetGroup();
if (!group)
return nullptr;
Player* designatedLooter = GetDesignatedCoreLooter(botAI, bot);
Player* firstCorePasser = GetFirstTaintedCorePasser(botAI, bot);
Player* secondCorePasser = GetSecondTaintedCorePasser(botAI, bot);
for (GroupReference* ref = group->GetFirstMember(); ref; ref = ref->next())
{
Player* member = ref->GetSource();
if (!member || !member->IsAlive() || member == designatedLooter ||
member == firstCorePasser || member == secondCorePasser)
continue;
PlayerbotAI* memberAI = GET_PLAYERBOT_AI(member);
if (memberAI && memberAI->IsAssistHealOfIndex(member, 2, true))
return member;
}
for (GroupReference* ref = group->GetFirstMember(); ref; ref = ref->next())
{
Player* member = ref->GetSource();
if (member && member->IsAlive() && GET_PLAYERBOT_AI(member) &&
!botAI->IsTank(member) && member != designatedLooter &&
member != firstCorePasser && member != secondCorePasser)
return member;
}
return nullptr;
}
Player* GetFourthTaintedCorePasser(PlayerbotAI* botAI, Player* bot)
{
Group* group = bot->GetGroup();
if (!group)
return nullptr;
Player* designatedLooter = GetDesignatedCoreLooter(botAI, bot);
Player* firstCorePasser = GetFirstTaintedCorePasser(botAI, bot);
Player* secondCorePasser = GetSecondTaintedCorePasser(botAI, bot);
Player* thirdCorePasser = GetThirdTaintedCorePasser(botAI, bot);
for (GroupReference* ref = group->GetFirstMember(); ref; ref = ref->next())
{
Player* member = ref->GetSource();
if (!member || !member->IsAlive() || member == designatedLooter ||
member == firstCorePasser || member == secondCorePasser ||
member == thirdCorePasser)
continue;
PlayerbotAI* memberAI = GET_PLAYERBOT_AI(member);
if (memberAI && memberAI->IsAssistRangedDpsOfIndex(member, 0, true))
return member;
}
for (GroupReference* ref = group->GetFirstMember(); ref; ref = ref->next())
{
Player* member = ref->GetSource();
if (member && member->IsAlive() && GET_PLAYERBOT_AI(member) &&
!botAI->IsTank(member) && member != designatedLooter &&
member != firstCorePasser && member != secondCorePasser &&
member != thirdCorePasser)
return member;
}
return nullptr;
}
std::array<Player*, 5> GetCoreHandlers(PlayerbotAI* botAI, Player* bot)
{
return
{
GetDesignatedCoreLooter(botAI, bot),
GetFirstTaintedCorePasser(botAI, bot),
GetSecondTaintedCorePasser(botAI, bot),
GetThirdTaintedCorePasser(botAI, bot),
GetFourthTaintedCorePasser(botAI, bot)
};
}
// Checks if any bot from earlier in the passing sequence has the Tainted Core or
// had it within the prior 3 seconds so the chain is not broken when the Core is in transit
bool AnyRecentCoreInInventory(PlayerbotAI* botAI, Player* bot)
{
Unit* vashj =
botAI->GetAiObjectContext()->GetValue<Unit*>("find target", "lady vashj")->Get();
if (!vashj)
return false;
auto coreHandlers = GetCoreHandlers(botAI, bot);
int8 myIndex = -1;
for (int8 i = 0; i < 5; ++i)
if (coreHandlers[i] && coreHandlers[i] == bot)
myIndex = i;
if (myIndex == -1)
return false;
const time_t now = std::time(nullptr);
constexpr uint8 lookbackSeconds = 3;
for (int8 i = 0; i <= myIndex; ++i)
{
Player* handler = coreHandlers[i];
if (!handler)
continue;
if (handler->HasItemCount(ITEM_TAINTED_CORE, 1, false))
return true;
auto it = lastCoreInInventoryTime.find(handler->GetGUID());
if (it != lastCoreInInventoryTime.end() &&
(now - it->second) <= static_cast<time_t>(lookbackSeconds))
return true;
}
return false;
}
const std::vector<uint32> SHIELD_GENERATOR_DB_GUIDS =
{
47482, // NW
47483, // NE
47484, // SE
47485 // SW
};
// Get the positions of all active Shield Generators by their database GUIDs
std::vector<GeneratorInfo> GetAllGeneratorInfosByDbGuids(
Map* map, const std::vector<uint32>& generatorDbGuids)
{
std::vector<GeneratorInfo> generators;
if (!map)
return generators;
for (uint32 dbGuid : generatorDbGuids)
{
auto bounds = map->GetGameObjectBySpawnIdStore().equal_range(dbGuid);
if (bounds.first == bounds.second)
continue;
GameObject* go = bounds.first->second;
if (!go || go->GetGoState() != GO_STATE_READY)
continue;
GeneratorInfo info;
info.guid = go->GetGUID();
info.x = go->GetPositionX();
info.y = go->GetPositionY();
info.z = go->GetPositionZ();
generators.push_back(info);
}
return generators;
}
// Returns the nearest active Shield Generator to the bot
// Active generators are powered by NPC_WORLD_INVISIBLE_TRIGGER creatures,
// which despawn after use
Unit* GetNearestActiveShieldGeneratorTriggerByEntry(Unit* reference)
{
if (!reference)
return nullptr;
std::list<Creature*> triggers;
constexpr float searchRange = 150.0f;
reference->GetCreatureListWithEntryInGrid(
triggers, NPC_WORLD_INVISIBLE_TRIGGER, searchRange);
Creature* nearest = nullptr;
float minDist = std::numeric_limits<float>::max();
for (Creature* creature : triggers)
{
if (!creature->IsAlive())
continue;
float dist = reference->GetDistance(creature);
if (dist < minDist)
{
minDist = dist;
nearest = creature;
}
}
return nearest;
}
const GeneratorInfo* GetNearestGeneratorToBot(
Player* bot, const std::vector<GeneratorInfo>& generators)
{
if (!bot || generators.empty())
return nullptr;
const GeneratorInfo* nearest = nullptr;
float minDist = std::numeric_limits<float>::max();
for (auto const& gen : generators)
{
float dist = bot->GetExactDist(gen.x, gen.y, gen.z);
if (dist < minDist)
{
minDist = dist;
nearest = &gen;
}
}
return nearest;
}
}