mirror of
https://github.com/mod-playerbots/mod-playerbots.git
synced 2026-02-27 05:45:55 +00:00
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:
@@ -62,9 +62,9 @@ void FleeManager::calculatePossibleDestinations(std::vector<FleePoint*>& points)
|
||||
}
|
||||
Unit* target = *botAI->GetAiObjectContext()->GetValue<Unit*>("current target");
|
||||
|
||||
float botPosX = startPosition.getX();
|
||||
float botPosY = startPosition.getY();
|
||||
float botPosZ = startPosition.getZ();
|
||||
float botPosX = startPosition.GetPositionX();
|
||||
float botPosY = startPosition.GetPositionY();
|
||||
float botPosZ = startPosition.GetPositionZ();
|
||||
|
||||
FleePoint start(botAI, botPosX, botPosY, botPosZ);
|
||||
calculateDistanceToCreatures(&start);
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -120,12 +120,6 @@ public:
|
||||
WorldPosition& operator+=(WorldPosition const& p1);
|
||||
WorldPosition& operator-=(WorldPosition const& p1);
|
||||
|
||||
uint32 getMapId();
|
||||
float getX();
|
||||
float getY();
|
||||
float getZ();
|
||||
float getO();
|
||||
|
||||
G3D::Vector3 getVector3();
|
||||
std::string const print();
|
||||
|
||||
@@ -185,29 +179,29 @@ public:
|
||||
// Quick square distance in 2d plane.
|
||||
float sqDistance2d(WorldPosition center)
|
||||
{
|
||||
return (getX() - center.getX()) * (getX() - center.getX()) +
|
||||
(getY() - center.getY()) * (getY() - center.getY());
|
||||
return (GetPositionX() - center.GetPositionX()) * (GetPositionX() - center.GetPositionX()) +
|
||||
(GetPositionY() - center.GetPositionY()) * (GetPositionY() - center.GetPositionY());
|
||||
}
|
||||
|
||||
// Quick square distance calculation without map check. Used for getting the minimum distant points.
|
||||
float sqDistance(WorldPosition center)
|
||||
{
|
||||
return (getX() - center.getX()) * (getX() - center.getX()) +
|
||||
(getY() - center.getY()) * (getY() - center.getY()) +
|
||||
(getZ() - center.getZ()) * (getZ() - center.getZ());
|
||||
return (GetPositionX() - center.GetPositionX()) * (GetPositionX() - center.GetPositionX()) +
|
||||
(GetPositionY() - center.GetPositionY()) * (GetPositionY() - center.GetPositionY()) +
|
||||
(GetPositionZ() - center.GetPositionZ()) * (GetPositionZ() - center.GetPositionZ());
|
||||
}
|
||||
|
||||
float sqDistance2d(WorldPosition* center)
|
||||
{
|
||||
return (getX() - center->getX()) * (getX() - center->getX()) +
|
||||
(getY() - center->getY()) * (getY() - center->getY());
|
||||
return (GetPositionX() - center->GetPositionX()) * (GetPositionX() - center->GetPositionX()) +
|
||||
(GetPositionY() - center->GetPositionY()) * (GetPositionY() - center->GetPositionY());
|
||||
}
|
||||
|
||||
float sqDistance(WorldPosition* center)
|
||||
{
|
||||
return (getX() - center->getX()) * (getX() - center->getX()) +
|
||||
(getY() - center->getY()) * (getY() - center->getY()) +
|
||||
(getZ() - center->getZ()) * (getZ() - center->getZ());
|
||||
return (GetPositionX() - center->GetPositionX()) * (GetPositionX() - center->GetPositionX()) +
|
||||
(GetPositionY() - center->GetPositionY()) * (GetPositionY() - center->GetPositionY()) +
|
||||
(GetPositionZ() - center->GetPositionZ()) * (GetPositionZ() - center->GetPositionZ());
|
||||
}
|
||||
|
||||
// Returns the closest point of the list. Fast but only works for the same map.
|
||||
@@ -227,7 +221,7 @@ public:
|
||||
|
||||
float getAngleTo(WorldPosition endPos)
|
||||
{
|
||||
float ang = atan2(endPos.getY() - getY(), endPos.getX() - getX());
|
||||
float ang = atan2(endPos.GetPositionY() - GetPositionY(), endPos.GetPositionX() - GetPositionX());
|
||||
return (ang >= 0) ? ang : 2 * static_cast<float>(M_PI) + ang;
|
||||
}
|
||||
|
||||
@@ -238,7 +232,8 @@ public:
|
||||
|
||||
float mSign(WorldPosition* p1, WorldPosition* p2)
|
||||
{
|
||||
return (getX() - p2->getX()) * (p1->getY() - p2->getY()) - (p1->getX() - p2->getX()) * (getY() - p2->getY());
|
||||
return (GetPositionX() - p2->GetPositionX()) * (p1->GetPositionY() - p2->GetPositionY()) -
|
||||
(p1->GetPositionX() - p2->GetPositionX()) * (GetPositionY() - p2->GetPositionY());
|
||||
}
|
||||
|
||||
bool isInside(WorldPosition* p1, WorldPosition* p2, WorldPosition* p3);
|
||||
@@ -251,18 +246,23 @@ public:
|
||||
|
||||
std::set<Transport*> getTransports(uint32 entry = 0);
|
||||
|
||||
GridCoord getGridCoord() { return Acore::ComputeGridCoord(getX(), getY()); };
|
||||
CellCoord getCellCoord() { return Acore::ComputeCellCoord(GetPositionX(), GetPositionY()); }
|
||||
GridCoord getGridCoord()
|
||||
{
|
||||
CellCoord cellCoord = getCellCoord();
|
||||
Cell cell(cellCoord);
|
||||
return GridCoord(cell.GridX(), cell.GridY());
|
||||
}
|
||||
std::vector<GridCoord> getGridCoord(WorldPosition secondPos);
|
||||
std::vector<WorldPosition> fromGridCoord(GridCoord GridCoord);
|
||||
|
||||
CellCoord getCellCoord() { return Acore::ComputeCellCoord(getX(), getY()); }
|
||||
std::vector<WorldPosition> fromCellCoord(CellCoord cellCoord);
|
||||
std::vector<WorldPosition> gridFromCellCoord(CellCoord cellCoord);
|
||||
|
||||
mGridCoord getmGridCoord()
|
||||
{
|
||||
return std::make_pair((int32)(CENTER_GRID_ID - getX() / SIZE_OF_GRIDS),
|
||||
(int32)(CENTER_GRID_ID - getY() / SIZE_OF_GRIDS));
|
||||
return std::make_pair((int32)(CENTER_GRID_ID - GetPositionX() / SIZE_OF_GRIDS),
|
||||
(int32)(CENTER_GRID_ID - GetPositionY() / SIZE_OF_GRIDS));
|
||||
}
|
||||
|
||||
std::vector<mGridCoord> getmGridCoords(WorldPosition secondPos);
|
||||
@@ -270,15 +270,15 @@ public:
|
||||
|
||||
void loadMapAndVMap(uint32 mapId, uint8 x, uint8 y);
|
||||
|
||||
void loadMapAndVMap() { loadMapAndVMap(getMapId(), getmGridCoord().first, getmGridCoord().second); }
|
||||
void loadMapAndVMap() { loadMapAndVMap(GetMapId(), getmGridCoord().first, getmGridCoord().second); }
|
||||
|
||||
void loadMapAndVMaps(WorldPosition secondPos);
|
||||
|
||||
// Display functions
|
||||
WorldPosition getDisplayLocation();
|
||||
float getDisplayX() { return getDisplayLocation().getY() * -1.0; }
|
||||
float getDisplayX() { return getDisplayLocation().GetPositionY() * -1.0; }
|
||||
|
||||
float getDisplayY() { return getDisplayLocation().getX(); }
|
||||
float getDisplayY() { return getDisplayLocation().GetPositionX(); }
|
||||
|
||||
uint16 getAreaId();
|
||||
AreaTableEntry const* getArea();
|
||||
@@ -334,11 +334,11 @@ private:
|
||||
|
||||
inline ByteBuffer& operator<<(ByteBuffer& b, WorldPosition& guidP)
|
||||
{
|
||||
b << guidP.getMapId();
|
||||
b << guidP.getX();
|
||||
b << guidP.getY();
|
||||
b << guidP.getZ();
|
||||
b << guidP.getO();
|
||||
b << guidP.GetMapId();
|
||||
b << guidP.GetPositionX();
|
||||
b << guidP.GetPositionY();
|
||||
b << guidP.GetPositionZ();
|
||||
b << guidP.GetOrientation();
|
||||
b << guidP.getVisitors();
|
||||
return b;
|
||||
}
|
||||
@@ -461,9 +461,9 @@ public:
|
||||
{
|
||||
}
|
||||
|
||||
bool isFrom(WorldPosition point) { return point.getMapId() == pointFrom.getMapId(); }
|
||||
bool isFrom(WorldPosition point) { return point.GetMapId() == pointFrom.GetMapId(); }
|
||||
|
||||
bool isTo(WorldPosition point) { return point.getMapId() == pointTo.getMapId(); }
|
||||
bool isTo(WorldPosition point) { return point.GetMapId() == pointTo.GetMapId(); }
|
||||
|
||||
WorldPosition* getPointFrom() { return &pointFrom; }
|
||||
|
||||
@@ -543,7 +543,7 @@ public:
|
||||
WorldPosition* nearestPoint(WorldPosition* pos);
|
||||
|
||||
float distanceTo(WorldPosition* pos) { return nearestPoint(pos)->distance(pos); }
|
||||
bool onMap(WorldPosition* pos) { return nearestPoint(pos)->getMapId() == pos->getMapId(); }
|
||||
bool onMap(WorldPosition* pos) { return nearestPoint(pos)->GetMapId() == pos->GetMapId(); }
|
||||
virtual bool isIn(WorldPosition* pos, float radius = 0.f)
|
||||
{
|
||||
return onMap(pos) && distanceTo(pos) <= (radius ? radius : radiusMin);
|
||||
|
||||
@@ -81,7 +81,7 @@ void TravelNodePath::calculateCost(bool distanceOnly)
|
||||
}
|
||||
}
|
||||
|
||||
if (lastPoint && point.getMapId() == lastPoint.getMapId())
|
||||
if (lastPoint && point.GetMapId() == lastPoint.GetMapId())
|
||||
{
|
||||
if (!distanceOnly && (point.isInWater() || lastPoint.isInWater()))
|
||||
swimDistance += point.distance(lastPoint);
|
||||
@@ -687,7 +687,7 @@ bool TravelPath::makeShortCut(WorldPosition startPos, float maxDist)
|
||||
// if (p.point.getMapId() != startPos.getMapId())
|
||||
// continue;
|
||||
|
||||
if (p.point.getMapId() == startPos.getMapId())
|
||||
if (p.point.GetMapId() == startPos.GetMapId())
|
||||
{
|
||||
float curDist = p.point.sqDistance(startPos);
|
||||
|
||||
@@ -722,7 +722,7 @@ bool TravelPath::makeShortCut(WorldPosition startPos, float maxDist)
|
||||
newPath.push_back(p);
|
||||
}
|
||||
|
||||
if (newPath.empty() || minDist > maxDistSq || newPath.front().point.getMapId() != startPos.getMapId())
|
||||
if (newPath.empty() || minDist > maxDistSq || newPath.front().point.GetMapId() != startPos.GetMapId())
|
||||
{
|
||||
clear();
|
||||
return false;
|
||||
@@ -800,7 +800,7 @@ bool TravelPath::shouldMoveToNextPoint(WorldPosition startPos, std::vector<PathN
|
||||
|
||||
float nextMove = p->point.distance(nextP->point);
|
||||
|
||||
if (p->point.getMapId() != startPos.getMapId() ||
|
||||
if (p->point.GetMapId() != startPos.GetMapId() ||
|
||||
((moveDist + nextMove > maxDist || startPos.distance(nextP->point) > maxDist) && moveDist > 0))
|
||||
{
|
||||
return false;
|
||||
@@ -827,7 +827,7 @@ WorldPosition TravelPath::getNextPoint(WorldPosition startPos, float maxDist, Tr
|
||||
// Get the closest point on the path to start from.
|
||||
for (auto p = startP; p != ed; p++)
|
||||
{
|
||||
if (p->point.getMapId() != startPos.getMapId())
|
||||
if (p->point.GetMapId() != startPos.GetMapId())
|
||||
continue;
|
||||
|
||||
float curDist = p->point.distance(startPos);
|
||||
@@ -1126,7 +1126,7 @@ std::vector<TravelNode*> TravelNodeMap::getNodes(WorldPosition pos, float range)
|
||||
|
||||
for (auto& node : m_nodes)
|
||||
{
|
||||
if (node->getMapId() == pos.getMapId())
|
||||
if (node->getMapId() == pos.GetMapId())
|
||||
if (range == -1 || node->getDistance(pos) <= range)
|
||||
retVec.push_back(node);
|
||||
}
|
||||
@@ -1787,8 +1787,9 @@ void TravelNodeMap::generateTransportNodes()
|
||||
float dy = -1 * p.second->Y;
|
||||
|
||||
WorldPosition pos =
|
||||
WorldPosition(basePos.getMapId(), basePos.getX() + dx, basePos.getY() + dy,
|
||||
basePos.getZ() + p.second->Z, basePos.getO());
|
||||
WorldPosition(basePos.GetMapId(), basePos.GetPositionX() + dx,
|
||||
basePos.GetPositionY() + dy, basePos.GetPositionZ() + p.second->Z,
|
||||
basePos.GetOrientation());
|
||||
|
||||
if (prevNode)
|
||||
{
|
||||
@@ -1830,8 +1831,9 @@ void TravelNodeMap::generateTransportNodes()
|
||||
float dx = -1 * p.second->X;
|
||||
float dy = -1 * p.second->Y;
|
||||
WorldPosition pos =
|
||||
WorldPosition(basePos.getMapId(), basePos.getX() + dx, basePos.getY() + dy,
|
||||
basePos.getZ() + p.second->Z, basePos.getO());
|
||||
WorldPosition(basePos.GetMapId(), basePos.GetPositionX() + dx,
|
||||
basePos.GetPositionY() + dy, basePos.GetPositionZ() + p.second->Z,
|
||||
basePos.GetOrientation());
|
||||
|
||||
ppath.push_back(pos);
|
||||
|
||||
@@ -2356,10 +2358,10 @@ void TravelNodeMap::saveNodeStore()
|
||||
stmt->SetData(0, i);
|
||||
stmt->SetData(1, saveNodes.find(link.first)->second);
|
||||
stmt->SetData(2, j);
|
||||
stmt->SetData(3, point.getMapId());
|
||||
stmt->SetData(4, point.getX());
|
||||
stmt->SetData(5, point.getY());
|
||||
stmt->SetData(6, point.getZ());
|
||||
stmt->SetData(3, point.GetMapId());
|
||||
stmt->SetData(4, point.GetPositionX());
|
||||
stmt->SetData(5, point.GetPositionY());
|
||||
stmt->SetData(6, point.GetPositionZ());
|
||||
trans->Append(stmt);
|
||||
|
||||
points++;
|
||||
@@ -2516,10 +2518,10 @@ void TravelNodeMap::calcMapOffset()
|
||||
}
|
||||
else
|
||||
{
|
||||
min.back().setX(std::min(min.back().getX(), node->getX()));
|
||||
min.back().setY(std::min(min.back().getY(), node->getY()));
|
||||
max.back().setX(std::max(max.back().getX(), node->getX()));
|
||||
max.back().setY(std::max(max.back().getY(), node->getY()));
|
||||
min.back().setX(std::min(min.back().GetPositionX(), node->getX()));
|
||||
min.back().setY(std::min(min.back().GetPositionY(), node->getY()));
|
||||
max.back().setX(std::max(max.back().GetPositionX(), node->getX()));
|
||||
max.back().setY(std::max(max.back().GetPositionY(), node->getY()));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -2533,14 +2535,15 @@ void TravelNodeMap::calcMapOffset()
|
||||
for (auto& mapId : mapIds)
|
||||
{
|
||||
mapOffsets.push_back(std::make_pair(
|
||||
mapId, WorldPosition(mapId, curPos.getX() - min[i].getX(), curPos.getY() - max[i].getY(), 0, 0)));
|
||||
mapId, WorldPosition(mapId, curPos.GetPositionX() - min[i].GetPositionX(),
|
||||
curPos.GetPositionY() - max[i].GetPositionY(), 0, 0)));
|
||||
|
||||
maxY = std::max(maxY, (max[i].getY() - min[i].getY() + 500));
|
||||
curPos.setX(curPos.getX() + (max[i].getX() - min[i].getX() + 500));
|
||||
maxY = std::max(maxY, (max[i].GetPositionY() - min[i].GetPositionY() + 500));
|
||||
curPos.setX(curPos.GetPositionX() + (max[i].GetPositionX() - min[i].GetPositionX() + 500));
|
||||
|
||||
if (curPos.getX() > endPos.getX())
|
||||
if (curPos.GetPositionX() > endPos.GetPositionX())
|
||||
{
|
||||
curPos.setY(curPos.getY() - maxY);
|
||||
curPos.setY(curPos.GetPositionY() - maxY);
|
||||
curPos.setX(-13000);
|
||||
}
|
||||
|
||||
|
||||
@@ -251,11 +251,11 @@ public:
|
||||
}
|
||||
|
||||
// WorldLocation shortcuts
|
||||
uint32 getMapId() { return point.getMapId(); }
|
||||
float getX() { return point.getX(); }
|
||||
float getY() { return point.getY(); }
|
||||
float getZ() { return point.getZ(); }
|
||||
float getO() { return point.getO(); }
|
||||
uint32 getMapId() { return point.GetMapId(); }
|
||||
float getX() { return point.GetPositionX(); }
|
||||
float getY() { return point.GetPositionY(); }
|
||||
float getZ() { return point.GetPositionZ(); }
|
||||
float getO() { return point.GetOrientation(); }
|
||||
float getDistance(WorldPosition pos) { return point.distance(pos); }
|
||||
float getDistance(TravelNode* node) { return point.distance(node->getPosition()); }
|
||||
float fDist(TravelNode* node) { return point.fDist(node->getPosition()); }
|
||||
|
||||
Reference in New Issue
Block a user