mirror of
https://github.com/TrinityCore/TrinityCore.git
synced 2026-01-21 17:54:48 +01:00
*Make position as a class;
--HG-- branch : trunk
This commit is contained in:
@@ -1079,9 +1079,16 @@ bool Object::PrintIndexError(uint32 index, bool set) const
|
||||
return false;
|
||||
}
|
||||
|
||||
bool Position::IsInLine(const Unit * const target, float distance, float width) const
|
||||
{
|
||||
if(!HasInArc(M_PI, target) || !target->IsWithinDist3d(m_positionX, m_positionY, m_positionZ, distance)) return false;
|
||||
width += target->GetObjectSize();
|
||||
float angle = GetRelativeAngle(target);
|
||||
return abs(sin(angle)) * GetExactDist2d(target->GetPositionX(), target->GetPositionY()) < width;
|
||||
}
|
||||
|
||||
WorldObject::WorldObject()
|
||||
: m_mapId(0), m_InstanceId(0), m_phaseMask(PHASEMASK_NORMAL),
|
||||
m_positionX(0.0f), m_positionY(0.0f), m_positionZ(0.0f), m_orientation(0.0f), m_currMap(NULL)
|
||||
: WorldLocation(), m_InstanceId(0), m_phaseMask(PHASEMASK_NORMAL), m_currMap(NULL)
|
||||
, m_zoneScript(NULL)
|
||||
, m_isActive(false), m_isWorldObject(false)
|
||||
, m_name("")
|
||||
@@ -1159,74 +1166,6 @@ InstanceData* WorldObject::GetInstanceData()
|
||||
Map *map = GetMap();
|
||||
return map->IsDungeon() ? ((InstanceMap*)map)->GetInstanceData() : NULL;
|
||||
}
|
||||
//slow
|
||||
float WorldObject::GetDistance(const WorldObject* obj) const
|
||||
{
|
||||
float dx = GetPositionX() - obj->GetPositionX();
|
||||
float dy = GetPositionY() - obj->GetPositionY();
|
||||
float dz = GetPositionZ() - obj->GetPositionZ();
|
||||
float sizefactor = GetObjectSize() + obj->GetObjectSize();
|
||||
float dist = sqrt((dx*dx) + (dy*dy) + (dz*dz)) - sizefactor;
|
||||
return ( dist > 0 ? dist : 0);
|
||||
}
|
||||
|
||||
float WorldObject::GetDistance2d(float x, float y) const
|
||||
{
|
||||
float dx = GetPositionX() - x;
|
||||
float dy = GetPositionY() - y;
|
||||
float sizefactor = GetObjectSize();
|
||||
float dist = sqrt((dx*dx) + (dy*dy)) - sizefactor;
|
||||
return ( dist > 0 ? dist : 0);
|
||||
}
|
||||
|
||||
float WorldObject::GetExactDistance2d(const float x, const float y) const
|
||||
{
|
||||
float dx = GetPositionX() - x;
|
||||
float dy = GetPositionY() - y;
|
||||
return sqrt((dx*dx) + (dy*dy));
|
||||
}
|
||||
|
||||
float WorldObject::GetDistance(float x, float y, float z) const
|
||||
{
|
||||
float dx = GetPositionX() - x;
|
||||
float dy = GetPositionY() - y;
|
||||
float dz = GetPositionZ() - z;
|
||||
float sizefactor = GetObjectSize();
|
||||
float dist = sqrt((dx*dx) + (dy*dy) + (dz*dz)) - sizefactor;
|
||||
return ( dist > 0 ? dist : 0);
|
||||
}
|
||||
|
||||
float WorldObject::GetExactDistSq(float x, float y, float z) const
|
||||
{
|
||||
float dx = GetPositionX() - x;
|
||||
float dy = GetPositionY() - y;
|
||||
float dz = GetPositionZ() - z;
|
||||
return dx*dx + dy*dy + dz*dz;
|
||||
}
|
||||
|
||||
float WorldObject::GetDistance2dSq(float x, float y) const
|
||||
{
|
||||
float dx = GetPositionX() - x;
|
||||
float dy = GetPositionY() - y;
|
||||
return dx*dx + dy*dy;
|
||||
}
|
||||
|
||||
float WorldObject::GetExactDistSq(const WorldObject *obj) const
|
||||
{
|
||||
float dx = GetPositionX() - obj->GetPositionX();
|
||||
float dy = GetPositionY() - obj->GetPositionY();
|
||||
float dz = GetPositionZ() - obj->GetPositionZ();
|
||||
return dx*dx + dy*dy + dz*dz;
|
||||
}
|
||||
|
||||
float WorldObject::GetDistance2d(const WorldObject* obj) const
|
||||
{
|
||||
float dx = GetPositionX() - obj->GetPositionX();
|
||||
float dy = GetPositionY() - obj->GetPositionY();
|
||||
float sizefactor = GetObjectSize() + obj->GetObjectSize();
|
||||
float dist = sqrt((dx*dx) + (dy*dy)) - sizefactor;
|
||||
return ( dist > 0 ? dist : 0);
|
||||
}
|
||||
|
||||
float WorldObject::GetDistanceZ(const WorldObject* obj) const
|
||||
{
|
||||
@@ -1236,29 +1175,6 @@ float WorldObject::GetDistanceZ(const WorldObject* obj) const
|
||||
return ( dist > 0 ? dist : 0);
|
||||
}
|
||||
|
||||
bool WorldObject::IsWithinDist3d(float x, float y, float z, float dist2compare) const
|
||||
{
|
||||
float dx = GetPositionX() - x;
|
||||
float dy = GetPositionY() - y;
|
||||
float dz = GetPositionZ() - z;
|
||||
float distsq = dx*dx + dy*dy + dz*dz;
|
||||
|
||||
float maxdist = dist2compare + GetObjectSize();
|
||||
|
||||
return distsq < maxdist * maxdist;
|
||||
}
|
||||
|
||||
bool WorldObject::IsWithinDist2d(float x, float y, float dist2compare) const
|
||||
{
|
||||
float dx = GetPositionX() - x;
|
||||
float dy = GetPositionY() - y;
|
||||
float distsq = dx*dx + dy*dy;
|
||||
|
||||
float maxdist = dist2compare + GetObjectSize();
|
||||
|
||||
return distsq < maxdist * maxdist;
|
||||
}
|
||||
|
||||
bool WorldObject::_IsWithinDist(WorldObject const* obj, float dist2compare, bool is3D) const
|
||||
{
|
||||
float dx = GetPositionX() - obj->GetPositionX();
|
||||
@@ -1380,14 +1296,14 @@ bool WorldObject::IsInRange3d(float x, float y, float z, float minRange, float m
|
||||
return distsq < maxdist * maxdist;
|
||||
}
|
||||
|
||||
float WorldObject::GetAngle(const WorldObject* obj) const
|
||||
float Position::GetAngle(const Position *obj) const
|
||||
{
|
||||
if(!obj) return 0;
|
||||
return GetAngle( obj->GetPositionX(), obj->GetPositionY() );
|
||||
}
|
||||
|
||||
// Return angle in range 0..2*pi
|
||||
float WorldObject::GetAngle( const float x, const float y ) const
|
||||
float Position::GetAngle( const float x, const float y ) const
|
||||
{
|
||||
float dx = x - GetPositionX();
|
||||
float dy = y - GetPositionY();
|
||||
@@ -1397,7 +1313,7 @@ float WorldObject::GetAngle( const float x, const float y ) const
|
||||
return ang;
|
||||
}
|
||||
|
||||
void WorldObject::GetSinCos(const float x, const float y, float &vsin, float &vcos)
|
||||
void Position::GetSinCos(const float x, const float y, float &vsin, float &vcos) const
|
||||
{
|
||||
float dx = GetPositionX() - x;
|
||||
float dy = GetPositionY() - y;
|
||||
@@ -1416,14 +1332,12 @@ void WorldObject::GetSinCos(const float x, const float y, float &vsin, float &vc
|
||||
}
|
||||
}
|
||||
|
||||
bool WorldObject::HasInArc(const float arcangle, const WorldObject* obj) const
|
||||
bool Position::HasInArc(float arc, const Position *obj) const
|
||||
{
|
||||
// always have self in arc
|
||||
if(obj == this)
|
||||
return true;
|
||||
|
||||
float arc = arcangle;
|
||||
|
||||
// move arc to range 0.. 2*pi
|
||||
while( arc >= 2.0f * M_PI )
|
||||
arc -= 2.0f * M_PI;
|
||||
@@ -1465,7 +1379,7 @@ bool WorldObject::IsInBetween(const WorldObject *obj1, const WorldObject *obj2,
|
||||
size = GetObjectSize() / 2;
|
||||
|
||||
float angle = obj1->GetAngle(this) - obj1->GetAngle(obj2);
|
||||
return abs(sin(angle)) * GetExactDistance2d(obj1->GetPositionX(), obj1->GetPositionY()) < size;
|
||||
return abs(sin(angle)) * GetExactDist2d(obj1->GetPositionX(), obj1->GetPositionY()) < size;
|
||||
}
|
||||
|
||||
void WorldObject::GetRandomPoint( float x, float y, float z, float distance, float &rand_x, float &rand_y, float &rand_z) const
|
||||
@@ -1498,7 +1412,7 @@ void WorldObject::UpdateGroundPositionZ(float x, float y, float &z) const
|
||||
z = new_z+ 0.05f; // just to be sure that we are not a few pixel under the surface
|
||||
}
|
||||
|
||||
bool WorldObject::IsPositionValid() const
|
||||
bool Position::IsPositionValid() const
|
||||
{
|
||||
return Trinity::IsValidMapCoord(m_positionX,m_positionY,m_positionZ,m_orientation);
|
||||
}
|
||||
@@ -1754,7 +1668,7 @@ void WorldObject::AddObjectToRemoveList()
|
||||
map->AddObjectToRemoveList(this);
|
||||
}
|
||||
|
||||
TempSummon *Map::SummonCreature(uint32 entry, float x, float y, float z, float angle, uint32 vehId, SummonPropertiesEntry const *properties, uint32 duration, Unit *summoner)
|
||||
TempSummon *Map::SummonCreature(uint32 entry, const Position &pos, SummonPropertiesEntry const *properties, uint32 duration, Unit *summoner, uint32 vehId)
|
||||
{
|
||||
uint32 mask = UNIT_MASK_SUMMON;
|
||||
if(properties)
|
||||
@@ -1805,13 +1719,13 @@ TempSummon *Map::SummonCreature(uint32 entry, float x, float y, float z, float a
|
||||
default: return NULL;
|
||||
}
|
||||
|
||||
if(!summon->Create(objmgr.GenerateLowGuid(HIGHGUID_UNIT), this, phase, entry, vehId, team, x, y, z, angle))
|
||||
if(!summon->Create(objmgr.GenerateLowGuid(HIGHGUID_UNIT), this, phase, entry, vehId, team, pos.GetPositionX(), pos.GetPositionY(), pos.GetPositionZ(), pos.GetOrientation()))
|
||||
{
|
||||
delete summon;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
summon->SetHomePosition(x, y, z, angle);
|
||||
summon->SetHomePosition(pos);
|
||||
|
||||
summon->InitStats(duration);
|
||||
Add((Creature*)summon);
|
||||
@@ -1833,22 +1747,18 @@ void WorldObject::SetZoneScript()
|
||||
}
|
||||
}
|
||||
|
||||
TempSummon* WorldObject::SummonCreature(uint32 entry, float x, float y, float z, float ang, uint32 vehId, TempSummonType spwtype, uint32 duration)
|
||||
TempSummon* WorldObject::SummonCreature(uint32 entry, const Position &pos, TempSummonType spwtype, uint32 duration, uint32 vehId) const
|
||||
{
|
||||
Map *map = FindMap();
|
||||
if(!map)
|
||||
return NULL;
|
||||
if(Map *map = FindMap())
|
||||
{
|
||||
if(TempSummon *summon = map->SummonCreature(entry, pos, NULL, duration, isType(TYPEMASK_UNIT) ? (Unit*)this : NULL))
|
||||
{
|
||||
summon->SetTempSummonType(spwtype);
|
||||
return summon;
|
||||
}
|
||||
}
|
||||
|
||||
if (x == 0.0f && y == 0.0f && z == 0.0f)
|
||||
GetClosePoint(x, y, z, GetObjectSize());
|
||||
|
||||
TempSummon *pCreature = map->SummonCreature(entry, x, y, z, ang, vehId, NULL, duration, isType(TYPEMASK_UNIT) ? (Unit*)this : NULL);
|
||||
if(!pCreature)
|
||||
return NULL;
|
||||
|
||||
pCreature->SetTempSummonType(spwtype);
|
||||
|
||||
return pCreature;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
Pet* Player::SummonPet(uint32 entry, float x, float y, float z, float ang, PetType petType, uint32 duration)
|
||||
|
||||
Reference in New Issue
Block a user