Stage1 refactor world position method names (#2126)

# Pull Request

This change replaces the non‑standard
WorldPosition::getX/getY/getZ/getO/getMapId wrappers with the core
getters (GetPositionX/Y/Z, GetOrientation, GetMapId) and removes the
redundant wrappers.
Goal: align the module with AzerothCore conventions, reduce local
adapters, and improve long‑term maintainability.

---

## Design Philosophy

This is a structural cleanup only (coordinate access) and does not alter
any AI behavior or decision logic.
It follows the stability/performance-first philosophy and does not add
branches or extra runtime work.

Before submitting: yes, this change aligns with the principles of
stability, performance, and predictability.

Principles:

- **Stability before intelligence**  
  A stable system is always preferred over a smarter one.

- **Performance is a shared resource**  
  Any increase in bot cost affects all players and all bots.

- **Simple logic scales better than smart logic**  
Predictable behavior under load is more valuable than perfect decisions.

- **Complexity must justify itself**  
  If a feature cannot clearly explain its cost, it should not exist.

- **Defaults must be cheap**  
  Expensive behavior must always be optional and clearly communicated.

- **Bots should look reasonable, not perfect**  
  The goal is believable behavior, not human simulation.

Before submitting, confirm that this change aligns with those
principles.

---

## Feature Evaluation

Please answer the following:

- Minimum logic required: use core getters (GetPositionX/Y/Z, GetMapId,
GetOrientation) wherever coordinates are needed.
- Cheapest implementation: direct call replacement and removal of
redundant wrappers.
- Runtime cost: negligible (same data access, no additional logic).

---

## How to Test the Changes

- No functional testing required (behavior‑neutral refactor).
- Recommended: compile the module and run a normal server startup as
validation.

## Complexity & Impact

Does this change add new decision branches?
- - [x] No
- - [x] 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
- - [x] 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?
- - [ ] No
- - [x] Yes (**explain below**)

If yes, please specify:

- AI tool or model used: Copilot
- Purpose of usage: Translate this PR text from french to English

---

## 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

This is a core-friendly cleanup only, with no behavioral change.
No additional logic or CPU cost is introduced.
This commit is contained in:
Alex Dcnh
2026-02-13 18:24:42 +01:00
committed by GitHub
parent a0a50204ec
commit 17b8d7f68b
20 changed files with 268 additions and 252 deletions

View File

@@ -71,13 +71,13 @@ WorldPosition::WorldPosition(std::vector<WorldPosition*> list, WorldPositionCons
set(*list[urand(0, size - 1)]);
else if (conType == WP_CENTROID)
{
set(std::accumulate(list.begin(), list.end(), WorldLocation(list[0]->getMapId(), 0, 0, 0, 0),
set(std::accumulate(list.begin(), list.end(), WorldLocation(list[0]->GetMapId(), 0, 0, 0, 0),
[size](WorldLocation i, WorldPosition* j)
{
i.m_positionX += j->getX() / size;
i.m_positionY += j->getY() / size;
i.m_positionZ += j->getZ() / size;
i.NormalizeOrientation(i.m_orientation += j->getO() / size);
i.m_positionX += j->GetPositionX() / size;
i.m_positionY += j->GetPositionY() / size;
i.m_positionZ += j->GetPositionZ() / size;
i.NormalizeOrientation(i.m_orientation += j->GetOrientation() / size);
return i;
}));
}
@@ -100,13 +100,13 @@ WorldPosition::WorldPosition(std::vector<WorldPosition> list, WorldPositionConst
set(list[urand(0, size - 1)]);
else if (conType == WP_CENTROID)
{
set(std::accumulate(list.begin(), list.end(), WorldLocation(list[0].getMapId(), 0, 0, 0, 0),
set(std::accumulate(list.begin(), list.end(), WorldLocation(list[0].GetMapId(), 0, 0, 0, 0),
[size](WorldLocation i, WorldPosition& j)
{
i.m_positionX += j.getX() / size;
i.m_positionY += j.getY() / size;
i.m_positionZ += j.getZ() / size;
i.NormalizeOrientation(i.m_orientation += j.getO() / size);
i.m_positionX += j.GetPositionX() / size;
i.m_positionY += j.GetPositionY() / size;
i.m_positionZ += j.GetPositionZ() / size;
i.NormalizeOrientation(i.m_orientation += j.GetOrientation() / size);
return i;
}));
}
@@ -190,16 +190,6 @@ WorldPosition& WorldPosition::operator-=(WorldPosition const& p1)
return *this;
}
uint32 WorldPosition::getMapId() { return GetMapId(); }
float WorldPosition::getX() { return GetPositionX(); }
float WorldPosition::getY() { return GetPositionY(); }
float WorldPosition::getZ() { return GetPositionZ(); }
float WorldPosition::getO() { return GetOrientation(); }
bool WorldPosition::isOverworld()
{
return GetMapId() == 0 || GetMapId() == 1 || GetMapId() == 530 || GetMapId() == 571;
@@ -243,7 +233,7 @@ float WorldPosition::size()
float WorldPosition::distance(WorldPosition* center)
{
if (GetMapId() == center->getMapId())
if (GetMapId() == center->GetMapId())
return relPoint(center).size();
// this -> mapTransfer | mapTransfer -> center
@@ -252,7 +242,7 @@ float WorldPosition::distance(WorldPosition* center)
float WorldPosition::fDist(WorldPosition* center)
{
if (GetMapId() == center->getMapId())
if (GetMapId() == center->GetMapId())
return sqrt(sqDistance2d(center));
// this -> mapTransfer | mapTransfer -> center
@@ -328,7 +318,7 @@ WorldPosition WorldPosition::firstOutRange(std::vector<WorldPosition> list, floa
// Returns true if (on the x-y plane) the position is inside the three points.
bool WorldPosition::isInside(WorldPosition* p1, WorldPosition* p2, WorldPosition* p3)
{
if (getMapId() != p1->getMapId() != p2->getMapId() != p3->getMapId())
if (GetMapId() != p1->GetMapId() != p2->GetMapId() != p3->GetMapId())
return false;
float d1, d2, d3;
@@ -348,7 +338,7 @@ MapEntry const* WorldPosition::getMapEntry() { return sMapStore.LookupEntry(GetM
uint32 WorldPosition::getInstanceId()
{
if (Map* map = sMapMgr->FindBaseMap(getMapId()))
if (Map* map = sMapMgr->FindBaseMap(GetMapId()))
return map->GetInstanceId();
return 0;
@@ -361,7 +351,7 @@ Map* WorldPosition::getMap()
float WorldPosition::getHeight() // remove const - whipowill
{
return getMap()->GetHeight(getX(), getY(), getZ());
return getMap()->GetHeight(GetPositionX(), GetPositionY(), GetPositionZ());
}
G3D::Vector3 WorldPosition::getVector3() { return G3D::Vector3(GetPositionX(), GetPositionY(), GetPositionZ()); }
@@ -381,11 +371,11 @@ std::string const WorldPosition::print()
std::string const WorldPosition::to_string()
{
std::stringstream out;
out << m_mapId << '|';
out << m_positionX << '|';
out << m_positionY << '|';
out << m_positionZ << '|';
out << m_orientation;
out << GetMapId() << '|';
out << GetPositionX() << '|';
out << GetPositionY() << '|';
out << GetPositionZ() << '|';
out << GetOrientation();
return out.str();
}
@@ -429,11 +419,14 @@ void WorldPosition::printWKT(std::vector<WorldPosition> points, std::ostringstre
WorldPosition WorldPosition::getDisplayLocation()
{
WorldPosition pos = TravelNodeMap::instance().getMapOffset(getMapId());
WorldPosition pos = TravelNodeMap::instance().getMapOffset(GetMapId());
return offset(const_cast<WorldPosition*>(&pos));
}
uint16 WorldPosition::getAreaId() { return sMapMgr->GetAreaId(PHASEMASK_NORMAL, getMapId(), getX(), getY(), getZ()); }
uint16 WorldPosition::getAreaId()
{
return sMapMgr->GetAreaId(PHASEMASK_NORMAL, GetMapId(), GetPositionX(), GetPositionY(), GetPositionZ());
}
AreaTableEntry const* WorldPosition::getArea()
{
@@ -448,7 +441,7 @@ std::string const WorldPosition::getAreaName(bool fullName, bool zoneName)
{
if (!isOverworld())
{
MapEntry const* map = sMapStore.LookupEntry(getMapId());
MapEntry const* map = sMapStore.LookupEntry(GetMapId());
if (map)
return map->name[0];
}
@@ -545,7 +538,7 @@ std::vector<WorldPosition> WorldPosition::fromGridCoord(GridCoord gridCoord)
if (d == 2 || d == 3)
g.inc_y(1);
retVec.push_back(WorldPosition(getMapId(), g));
retVec.push_back(WorldPosition(GetMapId(), g));
}
return retVec;
@@ -566,7 +559,7 @@ std::vector<WorldPosition> WorldPosition::fromCellCoord(CellCoord cellcoord)
if (d == 2 || d == 3)
p.inc_y(1);
retVec.push_back(WorldPosition(getMapId(), p));
retVec.push_back(WorldPosition(GetMapId(), p));
}
return retVec;
}
@@ -618,7 +611,7 @@ std::vector<WorldPosition> WorldPosition::frommGridCoord(mGridCoord GridCoord)
if (d == 2 || d == 3)
g.first++;
retVec.push_back(WorldPosition(getMapId(), g));
retVec.push_back(WorldPosition(GetMapId(), g));
}
return retVec;
@@ -706,7 +699,7 @@ void WorldPosition::loadMapAndVMaps(WorldPosition secondPos)
{
for (auto& grid : getmGridCoords(secondPos))
{
loadMapAndVMap(getMapId(), grid.first, grid.second);
loadMapAndVMap(GetMapId(), grid.first, grid.second);
}
}
@@ -714,7 +707,7 @@ std::vector<WorldPosition> WorldPosition::fromPointsArray(std::vector<G3D::Vecto
{
std::vector<WorldPosition> retVec;
for (auto p : path)
retVec.push_back(WorldPosition(getMapId(), p.x, p.y, p.z, getO()));
retVec.push_back(WorldPosition(GetMapId(), p.x, p.y, p.z, GetOrientation()));
return retVec;
}
@@ -729,7 +722,7 @@ std::vector<WorldPosition> WorldPosition::getPathStepFrom(WorldPosition startPos
loadMapAndVMaps(startPos);
PathGenerator path(bot);
path.CalculatePath(startPos.getX(), startPos.getY(), startPos.getZ());
path.CalculatePath(startPos.GetPositionX(), startPos.GetPositionY(), startPos.GetPositionZ());
Movement::PointsArray points = path.GetPath();
PathType type = path.GetPathType();
@@ -785,7 +778,7 @@ std::vector<WorldPosition> WorldPosition::getPathFromPath(std::vector<WorldPosit
WorldPosition currentPos = startPath.back();
// No pathfinding across maps.
if (getMapId() != currentPos.getMapId())
if (GetMapId() != currentPos.GetMapId())
return {};
std::vector<WorldPosition> subPath, fullPath = startPath;
@@ -818,10 +811,18 @@ bool WorldPosition::GetReachableRandomPointOnGround(Player* bot, float radius, b
{
radius *= randomRange ? rand_norm() : 1.f;
float angle = rand_norm() * static_cast<float>(2 * M_PI);
m_positionX += radius * cosf(angle);
m_positionY += radius * sinf(angle);
setX(GetPositionX() + radius * cosf(angle));
setY(GetPositionY() + radius * sinf(angle));
return getMap()->CanReachPositionAndGetValidCoords(bot, m_positionX, m_positionY, m_positionZ);
float x = GetPositionX();
float y = GetPositionY();
float z = GetPositionZ();
bool canReach = getMap()->CanReachPositionAndGetValidCoords(bot, x, y, z);
setX(x);
setY(y);
setZ(z);
return canReach;
}
uint32 WorldPosition::getUnitsAggro(GuidVector& units, Player* bot)
@@ -844,7 +845,7 @@ uint32 WorldPosition::getUnitsAggro(GuidVector& units, Player* bot)
void FindPointCreatureData::operator()(CreatureData const& creatureData)
{
if (!entry || creatureData.id1 == entry)
if ((!point || creatureData.mapid == point.getMapId()) &&
if ((!point || creatureData.mapid == point.GetMapId()) &&
(!radius || point.sqDistance(WorldPosition(creatureData.mapid, creatureData.posX, creatureData.posY,
creatureData.posZ)) < radius * radius))
{
@@ -855,7 +856,7 @@ void FindPointCreatureData::operator()(CreatureData const& creatureData)
void FindPointGameObjectData::operator()(GameObjectData const& gameobjectData)
{
if (!entry || gameobjectData.id == entry)
if ((!point || gameobjectData.mapid == point.getMapId()) &&
if ((!point || gameobjectData.mapid == point.GetMapId()) &&
(!radius || point.sqDistance(WorldPosition(gameobjectData.mapid, gameobjectData.posX, gameobjectData.posY,
gameobjectData.posZ)) < radius * radius))
{
@@ -3223,7 +3224,8 @@ void TravelMgr::LoadQuestTravelTable()
if (loc.second.empty())
continue;
if (!TravelNodeMap::instance().getMapOffset(loc.second.front().getMapId()) && loc.second.front().getMapId() != 0)
if (!TravelNodeMap::instance().getMapOffset(loc.second.front().GetMapId()) &&
loc.second.front().GetMapId() != 0)
continue;
std::vector<WorldPosition> points = loc.second;
@@ -3235,7 +3237,7 @@ void TravelMgr::LoadQuestTravelTable()
out << "\"center\""
<< ",";
out << points.begin()->getMapId() << ",";
out << points.begin()->GetMapId() << ",";
out << points.begin()->getAreaName() << ",";
out << points.begin()->getAreaName(true, true) << ",";
@@ -3245,7 +3247,7 @@ void TravelMgr::LoadQuestTravelTable()
out << "\"area\""
<< ",";
out << points.begin()->getMapId() << ",";
out << points.begin()->GetMapId() << ",";
out << points.begin()->getAreaName() << ",";
out << points.begin()->getAreaName(true, true) << ",";
@@ -3613,17 +3615,18 @@ void TravelMgr::LoadQuestTravelTable()
if (!pos->getMap())
continue;
float nx = pos->getX() + (x*5)-5000.0f;
float ny = pos->getY() + (y*5)-5000.0f;
float nz = pos->getZ() + 100.0f;
float nx = pos->GetPositionX() + (x * 5) - 5000.0f;
float ny = pos->GetPositionY() + (y * 5) - 5000.0f;
float nz = pos->GetPositionZ() + 100.0f;
//pos->getMap()->GetHitPosition(nx, ny, nz + 200.0f, nx, ny, nz, -0.5f);
if (!pos->getMap()->GetHeightInRange(nx, ny, nz, 5000.0f)) // GetHeight can fail
continue;
WorldPosition npos = WorldPosition(pos->getMapId(), nx, ny, nz, 0.0);
uint32 area = path.getArea(npos.getMapId(), npos.getX(), npos.getY(), npos.getZ());
WorldPosition npos = WorldPosition(pos->GetMapId(), nx, ny, nz, 0.0);
uint32 area = path.getArea(npos.GetMapId(), npos.GetPositionX(), npos.GetPositionY(),
npos.GetPositionZ());
std::ostringstream out;
out << std::fixed << area << "," << npos.getDisplayX() << "," << npos.getDisplayY();
@@ -3647,7 +3650,8 @@ void TravelMgr::LoadQuestTravelTable()
std::string const name = i.second->getTitle();
name.erase(remove(name.begin(), name.end(), '\"'), name.end());
out << std::fixed << std::setprecision(2) << name.c_str() << "," << i.first << "," << j->getDisplayX() <<
"," << j->getDisplayY() << "," << j->getX() << "," << j->getY() << "," << j->getZ(); sPlayerbotAIConfig.log(5,
"," << j->getDisplayY() << "," << j->GetPositionX() << "," << j->GetPositionY() << "," << j->GetPositionZ();
sPlayerbotAIConfig.log(5,
out.str().c_str());
}
}
@@ -4087,8 +4091,8 @@ void TravelMgr::setNullTravelTarget(Player* player)
void TravelMgr::addMapTransfer(WorldPosition start, WorldPosition end, float portalDistance, bool makeShortcuts)
{
uint32 sMap = start.getMapId();
uint32 eMap = end.getMapId();
uint32 sMap = start.GetMapId();
uint32 eMap = end.GetMapId();
if (sMap == eMap)
return;
@@ -4121,7 +4125,7 @@ void TravelMgr::addMapTransfer(WorldPosition start, WorldPosition end, float por
}
// Add actual transfer.
auto mapTransfers = mapTransfersMap.find(std::make_pair(start.getMapId(), end.getMapId()));
auto mapTransfers = mapTransfersMap.find(std::make_pair(start.GetMapId(), end.GetMapId()));
if (mapTransfers == mapTransfersMap.end())
mapTransfersMap.insert({{sMap, eMap}, {mapTransfer(start, end, portalDistance)}});
@@ -4142,8 +4146,8 @@ void TravelMgr::loadMapTransfers()
float TravelMgr::mapTransDistance(WorldPosition start, WorldPosition end)
{
uint32 sMap = start.getMapId();
uint32 eMap = end.getMapId();
uint32 sMap = start.GetMapId();
uint32 eMap = end.GetMapId();
if (sMap == eMap)
return start.distance(end);
@@ -4167,8 +4171,8 @@ float TravelMgr::mapTransDistance(WorldPosition start, WorldPosition end)
float TravelMgr::fastMapTransDistance(WorldPosition start, WorldPosition end)
{
uint32 sMap = start.getMapId();
uint32 eMap = end.getMapId();
uint32 sMap = start.GetMapId();
uint32 eMap = end.GetMapId();
if (sMap == eMap)
return start.fDist(end);