Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- diff --git a/src/server/game/Entities/Object/Object.cpp b/src/server/game/Entities/Ob
- index c55892c..6201569 100755
- --- a/src/server/game/Entities/Object/Object.cpp
- +++ b/src/server/game/Entities/Object/Object.cpp
- @@ -1347,7 +1347,7 @@ bool WorldObject::IsWithinLOSInMap(const WorldObject* obj) cons
- float ox, oy, oz;
- obj->GetPosition(ox, oy, oz);
- - return(IsWithinLOS(ox, oy, oz));
- + return (IsWithinLOS(ox, oy, oz) && GetMap()->IsInDynLOS(GetPositionX(), GetPosit
- }
- bool WorldObject::IsWithinLOS(float ox, float oy, float oz) const
- @@ -1355,7 +1355,7 @@ bool WorldObject::IsWithinLOS(float ox, float oy, float oz) con
- float x, y, z;
- GetPosition(x, y, z);
- VMAP::IVMapManager* vMapManager = VMAP::VMapFactory::createOrGetVMapManager();
- - return vMapManager->isInLineOfSight(GetMapId(), x, y, z+2.0f, ox, oy, oz+2.0f);
- + return (vMapManager->isInLineOfSight(GetMapId(), x, y, z+2.0f, ox, oy, oz+2.0f)
- }
- bool WorldObject::GetDistanceOrder(WorldObject const* obj1, WorldObject const* obj2,
- @@ -2661,9 +2661,18 @@ void WorldObject::MovePositionToFirstCollision(Position &pos,
- // move back a bit
- destx -= CONTACT_DISTANCE * cos(angle);
- desty -= CONTACT_DISTANCE * sin(angle);
- - dist = sqrt((pos.m_positionX - destx)*(pos.m_positionX - destx) + (pos.m_pos
- }
- + while (!GetMap()->IsInDynLOS(pos.m_positionX, pos.m_positionY, pos.m_positionZ,
- + {
- + destx -= 2.0f * cos(angle);
- + desty -= 2.0f * sin(angle);
- + col = true;
- + }
- +
- + if (col)
- + dist = sqrt((pos.m_positionX - destx)*(pos.m_positionX - destx) + (pos.m_pos
- +
- float step = dist/10.0f;
- for (uint8 j = 0; j < 10; ++j)
- diff --git a/src/server/game/Maps/Map.cpp b/src/server/game/Maps/Map.cpp
- index 89049f3..8aa8327 100755
- --- a/src/server/game/Maps/Map.cpp
- +++ b/src/server/game/Maps/Map.cpp
- @@ -219,9 +219,14 @@ i_scriptLock(false), _creatureToMoveLock(false)
- }
- }
- + for (std::map<uint32, DynamicLOSObject*>::iterator i = m_dynamicLOSObjects.begin
- + delete i->second;
- +
- //lets initialize visibility distance for map
- Map::InitVisibilityDistance();
- + m_dynamicLOSCounter = 0;
- +
- sScriptMgr->OnCreateMap(this);
- }
- @@ -2717,3 +2722,179 @@ void Map::UpdateIteratorBack(Player* player)
- if (m_mapRefIter == player->GetMapRef())
- m_mapRefIter = m_mapRefIter->nocheck_prev();
- }
- +
- +/*
- + * ****************** *
- + * DYNAMIC LOS SYSTEM *
- + * ****************** *
- + */
- +
- +
- +uint32 Map::AddDynLOSObject(float x, float y, float radius)
- +{
- + DynamicLOSObject* obj = new DynamicLOSObject();
- + obj->SetCoordinates(x, y);
- + obj->SetRadius(radius);
- +
- +
- + // Add the dynamic object to the map
- + m_dynamicLOSObjects[++m_dynamicLOSCounter] = obj;
- +
- +
- + return m_dynamicLOSCounter;
- +}
- +
- +
- +uint32 Map::AddDynLOSObject(float x, float y, float z, float radius, float height)
- +{
- + DynamicLOSObject* obj = new DynamicLOSObject();
- + obj->SetCoordinates(x, y);
- + obj->SetZ(z);
- + obj->SetHeight(height);
- + obj->SetRadius(radius);
- +
- +
- + // Add the dynamic object to the map
- + m_dynamicLOSObjects[++m_dynamicLOSCounter] = obj;
- +
- +
- + return m_dynamicLOSCounter;
- +}
- +
- +
- +void Map::SetDynLOSObjectState(uint32 id, bool state)
- +{
- + std::map<uint32, DynamicLOSObject*>::iterator iter = m_dynamicLOSObjects.find(id
- + if (iter != m_dynamicLOSObjects.end())
- + iter->second->SetActiveState(state);
- +}
- +
- +
- +bool Map::GetDynLOSObjectState(uint32 id)
- +{
- + std::map<uint32, DynamicLOSObject*>::iterator iter = m_dynamicLOSObjects.find(id
- + if (iter != m_dynamicLOSObjects.end())
- + return (iter->second->IsActive());
- + return false;
- +}
- +
- +
- +bool Map::IsInDynLOS(float x, float y, float z, float x2, float y2, float z2)
- +{
- + if (!m_dynamicLOSCounter)
- + return true;
- +
- +
- + for (std::map<uint32, DynamicLOSObject*>::iterator iter = m_dynamicLOSObjects.be
- + if (iter->second->IsActive() && iter->second->IsBetween(x, y, z, x2, y2, z2)
- + return false;
- +
- +
- + return true;
- +}
- +
- +
- +DynamicLOSObject::DynamicLOSObject()
- +{
- + _x = 0.0f;
- + _y = 0.0f;
- + _z = 0.0f;
- + _height = 0.0f;
- + _radius = 0.0f;
- + _active = false;
- +}
- +
- +
- +bool DynamicLOSObject::IsBetween(float x, float y, float z, float x2, float y2, floa
- +{
- + if (IsInside(x, y) || IsInside(x2, y2))
- + {
- + if (HasHeightInfo() && IsOverOrUnder(z2))
- + return false;
- +
- +
- + return true;
- + }
- +
- +
- + // For a real handling of Z coord is necessary to do some research from this poi
- + // i.e. A player over a huge round plattaform, placed near the edge; and other p
- + // both may be able to attack each other, even when the plattaform height should
- + if ((std::max(x, x2) < (_x - _radius))
- + || (std::min(x, x2) > (_x + _radius))
- + || (std::max(y, y2) < (_y - _radius))
- + || (std::min(y, y2) > (_y + _radius)))
- + return false;
- +
- +
- + float angleToMe = atan2(_x - x, _y - y);
- + angleToMe = (angleToMe >= 0) ? angleToMe : 2 * M_PI + angleToMe;
- +
- +
- + float angleToDest = atan2(x2 - x, y2 - y);
- + angleToDest = (angleToDest >= 0) ? angleToDest : 2 * M_PI + angleToDest;
- +
- +
- + return (fabs(sin(angleToMe - angleToDest)) * GetDistance(x, y) < _radius);
- +}
- +
- +
- +bool DynamicLOSObject::IsInside(float x, float y)
- +{
- + return (((x-_x)*(x-_x)+(y-_y)*(y-_y))<(_radius*_radius));
- +}
- +
- +
- +bool DynamicLOSObject::IsOverOrUnder(float z)
- +{
- + return ((z < _z+_height) && (z > _z));
- +}
- +
- +
- +float DynamicLOSObject::GetDistance(float x, float y)
- +{
- + return sqrtf((x-_x)*(x-_x)+(y-_y)*(y-_y));
- +}
- +
- +
- +bool DynamicLOSObject::IsActive()
- +{
- + return _active;
- +}
- +
- +
- +void DynamicLOSObject::SetActiveState(bool state)
- +{
- + _active = state;
- +}
- +
- +
- +void DynamicLOSObject::SetCoordinates(float x, float y)
- +{
- + _x = x;
- + _y = y;
- +}
- +
- +
- +void DynamicLOSObject::SetRadius(float r)
- +{
- + _radius = r;
- +}
- +
- +
- +void DynamicLOSObject::SetZ(float z)
- +{
- + _z = z;
- +}
- +
- +
- +void DynamicLOSObject::SetHeight(float h)
- +{
- + _height = h;
- +}
- +
- +
- +bool DynamicLOSObject::HasHeightInfo()
- +{
- + return (_z != 0 || _height != 0);
- +}
- diff --git a/src/server/game/Maps/Map.h b/src/server/game/Maps/Map.h
- index fd58fd0..7ab550f 100755
- --- a/src/server/game/Maps/Map.h
- +++ b/src/server/game/Maps/Map.h
- @@ -200,6 +200,30 @@ public:
- #pragma pack(push, 1)
- #endif
- +class DynamicLOSObject
- +{
- + public:
- + DynamicLOSObject();
- + bool IsBetween(float x, float y, float z, float x2, float y2, float z2);
- + bool IsInside(float x, float y);
- + bool IsOverOrUnder(float z);
- + float GetDistance(float x, float y);
- + bool IsActive();
- + void SetActiveState(bool state);
- + void SetCoordinates(float x, float y);
- + void SetZ(float z);
- + void SetRadius(float r);
- + void SetHeight(float h);
- + bool HasHeightInfo();
- + private:
- + float _x;
- + float _y;
- + float _z;
- + float _height;
- + float _radius;
- + bool _active;
- +};
- +
- struct InstanceTemplate
- {
- uint32 Parent;
- @@ -425,6 +449,22 @@ class Map : public GridRefManager<NGridType>
- InstanceMap* ToInstanceMap(){ if (IsDungeon()) return reinterpret_cast<Inst
- const InstanceMap* ToInstanceMap() const { if (IsDungeon()) return (const I
- +
- + /*
- + **********************
- + * DYNAMIC LOS SYSTEM *
- + **********************
- + */
- + public:
- + uint32 AddDynLOSObject(float x, float y, float radius);
- + uint32 AddDynLOSObject(float x, float y, float z, float radius, float height
- + void SetDynLOSObjectState(uint32 id, bool state);
- + bool GetDynLOSObjectState(uint32 id);
- + bool IsInDynLOS(float x, float y, float z, float x2, float y2, float z2);
- + private:
- + std::map<uint32, DynamicLOSObject*> m_dynamicLOSObjects;
- + uint32 m_dynamicLOSCounter;
- + /* END */
- private:
- void LoadMapAndVMap(int gx, int gy);
- void LoadVMap(int gx, int gy);
Add Comment
Please, Sign In to add comment