mirror of
https://github.com/liyunfan1223/mod-playerbots.git
synced 2026-06-20 23:49:25 +02:00
# Pull Request
Incorrect comparison fix.
---
## How to Test the Changes
- Alliance Bots should now be able to find the correct flightmaster and
use it
## 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**)
If this introduces more advanced or AI-heavy logic:
- [X] Lightweight mode remains the default
- [ ] More complex behavior is optional and thereby configurable
---
## 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
40 lines
1.2 KiB
C++
40 lines
1.2 KiB
C++
#include "FlightMasterCache.h"
|
|
|
|
void FlightMasterCache::AddHordeFlightMaster(uint32 entry, WorldPosition pos)
|
|
{
|
|
hordeFlightMasterCache[entry] = pos;
|
|
}
|
|
|
|
void FlightMasterCache::AddAllianceFlightMaster(uint32 entry, WorldPosition pos)
|
|
{
|
|
allianceFlightMasterCache[entry] = pos;
|
|
}
|
|
|
|
Creature* FlightMasterCache::GetNearestFlightMaster(Player* bot)
|
|
{
|
|
std::map<uint32, WorldPosition>& flightMasterCache =
|
|
(bot->GetTeamId() == TEAM_ALLIANCE) ? allianceFlightMasterCache : hordeFlightMasterCache;
|
|
|
|
Creature* nearestFlightMaster = nullptr;
|
|
float nearestDistance = std::numeric_limits<float>::max();
|
|
|
|
for (auto const& [entry, pos] : flightMasterCache)
|
|
{
|
|
if (pos.GetMapId() == bot->GetMapId())
|
|
{
|
|
float distance = bot->GetExactDist2dSq(pos);
|
|
if (distance < nearestDistance)
|
|
{
|
|
Creature* flightMaster = ObjectAccessor::GetSpawnedCreatureByDBGUID(bot->GetMapId(), entry);
|
|
if (flightMaster)
|
|
{
|
|
nearestDistance = distance;
|
|
nearestFlightMaster = flightMaster;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
return nearestFlightMaster;
|
|
}
|