aboutsummaryrefslogtreecommitdiff
path: root/src/game/Object.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/game/Object.h')
-rw-r--r--src/game/Object.h116
1 files changed, 116 insertions, 0 deletions
diff --git a/src/game/Object.h b/src/game/Object.h
index 96d3252dc5d..9845ba10dce 100644
--- a/src/game/Object.h
+++ b/src/game/Object.h
@@ -17,8 +17,10 @@
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
+
#ifndef _OBJECT_H
#define _OBJECT_H
+
#include "Common.h"
#include "UpdateFields.h"
#include "UpdateData.h"
@@ -26,8 +28,10 @@
#include "ObjectDefines.h"
#include "GridDefines.h"
#include "Map.h"
+
#include <set>
#include <string>
+
#define CONTACT_DISTANCE 0.5f
#define INTERACTION_DISTANCE 5.0f
#define ATTACK_DISTANCE 5.0f
@@ -35,11 +39,13 @@
#define DEFAULT_VISIBILITY_DISTANCE 90.0f // default visible distance, 90 yards on continents
#define DEFAULT_VISIBILITY_INSTANCE 120.0f // default visible distance in instances, 120 yards
#define DEFAULT_VISIBILITY_BGARENAS 180.0f // default visible distance in BG/Arenas, 180 yards
+
#define DEFAULT_WORLD_OBJECT_SIZE 0.388999998569489f // player size, also currently used (correctly?) for any non Unit world objects
#define DEFAULT_COMBAT_REACH 1.5f
#define MIN_MELEE_REACH 2.0f
#define NOMINAL_MELEE_RANGE 5.0f
#define MELEE_RANGE (NOMINAL_MELEE_RANGE - MIN_MELEE_REACH * 2) //center to center for players
+
enum TypeMask
{
TYPEMASK_OBJECT = 0x0001,
@@ -52,6 +58,7 @@ enum TypeMask
TYPEMASK_CORPSE = 0x0080,
TYPEMASK_SEER = TYPEMASK_UNIT | TYPEMASK_DYNAMICOBJECT
};
+
enum TypeID
{
TYPEID_OBJECT = 0,
@@ -63,8 +70,11 @@ enum TypeID
TYPEID_DYNAMICOBJECT = 6,
TYPEID_CORPSE = 7
};
+
#define NUM_CLIENT_OBJECT_TYPES 8
+
uint32 GuidHigh2TypeId(uint32 guid_hi);
+
enum TempSummonType
{
TEMPSUMMON_TIMED_OR_DEAD_DESPAWN = 1, // despawns after a specified time OR when the creature disappears
@@ -76,11 +86,13 @@ enum TempSummonType
TEMPSUMMON_DEAD_DESPAWN = 7, // despawns when the creature disappears
TEMPSUMMON_MANUAL_DESPAWN = 8 // despawns when UnSummon() is called
};
+
enum PhaseMasks
{
PHASEMASK_NORMAL = 0x00000001,
PHASEMASK_ANYWHERE = 0xFFFFFFFF
};
+
class WorldPacket;
class UpdateData;
class ByteBuffer;
@@ -95,18 +107,24 @@ class Vehicle;
class CreatureAI;
class ZoneScript;
class Unit;
+
typedef UNORDERED_MAP<Player*, UpdateData> UpdateDataMapType;
+
class TRINITY_DLL_SPEC Object
{
public:
virtual ~Object ( );
+
const bool IsInWorld() const { return m_inWorld; }
virtual void AddToWorld()
{
if(m_inWorld)
return;
+
assert(m_uint32Values);
+
m_inWorld = true;
+
// synchronize values mirror with values array (changes will send in updatecreate opcode any way
ClearUpdateMask(true);
}
@@ -114,10 +132,13 @@ class TRINITY_DLL_SPEC Object
{
if(!m_inWorld)
return;
+
m_inWorld = false;
+
// if we remove from world then sending changes not required
ClearUpdateMask(true);
}
+
const uint64& GetGUID() const { return GetUInt64Value(0); }
uint32 GetGUIDLow() const { return GUID_LOPART(GetUInt64Value(0)); }
uint32 GetGUIDMid() const { return GUID_ENPART(GetUInt64Value(0)); }
@@ -125,47 +146,58 @@ class TRINITY_DLL_SPEC Object
const ByteBuffer& GetPackGUID() const { return m_PackGUID; }
uint32 GetEntry() const { return GetUInt32Value(OBJECT_FIELD_ENTRY); }
void SetEntry(uint32 entry) { SetUInt32Value(OBJECT_FIELD_ENTRY, entry); }
+
TypeID GetTypeId() const { return m_objectTypeId; }
bool isType(uint16 mask) const { return (mask & m_objectType); }
+
virtual void BuildCreateUpdateBlockForPlayer( UpdateData *data, Player *target ) const;
void SendUpdateToPlayer(Player* player);
+
void BuildValuesUpdateBlockForPlayer( UpdateData *data, Player *target ) const;
void BuildOutOfRangeUpdateBlock( UpdateData *data ) const;
void BuildMovementUpdateBlock( UpdateData * data, uint32 flags = 0 ) const;
void BuildUpdate(UpdateDataMapType &);
+
virtual void DestroyForPlayer( Player *target, bool anim = false ) const;
+
const int32& GetInt32Value( uint16 index ) const
{
ASSERT( index < m_valuesCount || PrintIndexError( index , false) );
return m_int32Values[ index ];
}
+
const uint32& GetUInt32Value( uint16 index ) const
{
ASSERT( index < m_valuesCount || PrintIndexError( index , false) );
return m_uint32Values[ index ];
}
+
const uint64& GetUInt64Value( uint16 index ) const
{
ASSERT( index + 1 < m_valuesCount || PrintIndexError( index , false) );
return *((uint64*)&(m_uint32Values[ index ]));
}
+
const float& GetFloatValue( uint16 index ) const
{
ASSERT( index < m_valuesCount || PrintIndexError( index , false ) );
return m_floatValues[ index ];
}
+
uint8 GetByteValue( uint16 index, uint8 offset) const
{
ASSERT( index < m_valuesCount || PrintIndexError( index , false) );
ASSERT( offset < 4 );
return *(((uint8*)&m_uint32Values[ index ])+offset);
}
+
uint16 GetUInt16Value( uint16 index, uint8 offset) const
{
ASSERT( index < m_valuesCount || PrintIndexError( index , false) );
ASSERT( offset < 2 );
return *(((uint16*)&m_uint32Values[ index ])+offset);
}
+
void SetInt32Value( uint16 index, int32 value );
void SetUInt32Value( uint16 index, uint32 value );
void UpdateUInt32Value( uint16 index, uint32 value );
@@ -176,20 +208,25 @@ class TRINITY_DLL_SPEC Object
void SetInt16Value( uint16 index, uint8 offset, int16 value ) { SetUInt16Value(index,offset,(uint16)value); }
void SetStatFloatValue( uint16 index, float value);
void SetStatInt32Value( uint16 index, int32 value);
+
bool AddUInt64Value( uint16 index, const uint64 &value );
bool RemoveUInt64Value( uint16 index, const uint64 &value );
+
void ApplyModUInt32Value(uint16 index, int32 val, bool apply);
void ApplyModInt32Value(uint16 index, int32 val, bool apply);
void ApplyModUInt64Value(uint16 index, int32 val, bool apply);
void ApplyModPositiveFloatValue( uint16 index, float val, bool apply);
void ApplyModSignedFloatValue( uint16 index, float val, bool apply);
+
void ApplyPercentModFloatValue(uint16 index, float val, bool apply)
{
val = val != -100.0f ? val : -99.9f ;
SetFloatValue(index, GetFloatValue(index) * (apply?(100.0f+val)/100.0f : 100.0f / (100.0f+val)) );
}
+
void SetFlag( uint16 index, uint32 newFlag );
void RemoveFlag( uint16 index, uint32 oldFlag );
+
void ToggleFlag( uint16 index, uint32 flag)
{
if(HasFlag(index, flag))
@@ -197,13 +234,16 @@ class TRINITY_DLL_SPEC Object
else
SetFlag(index, flag);
}
+
bool HasFlag( uint16 index, uint32 flag ) const
{
ASSERT( index < m_valuesCount || PrintIndexError( index , false ) );
return (m_uint32Values[ index ] & flag) != 0;
}
+
void SetByteFlag( uint16 index, uint8 offset, uint8 newFlag );
void RemoveByteFlag( uint16 index, uint8 offset, uint8 newFlag );
+
void ToggleFlag( uint16 index, uint8 offset, uint8 flag )
{
if(HasByteFlag(index, offset, flag))
@@ -211,28 +251,33 @@ class TRINITY_DLL_SPEC Object
else
SetByteFlag(index, offset, flag);
}
+
bool HasByteFlag( uint16 index, uint8 offset, uint8 flag ) const
{
ASSERT( index < m_valuesCount || PrintIndexError( index , false ) );
ASSERT( offset < 4 );
return (((uint8*)&m_uint32Values[index])[offset] & flag) != 0;
}
+
void ApplyModFlag( uint16 index, uint32 flag, bool apply)
{
if(apply) SetFlag(index,flag); else RemoveFlag(index,flag);
}
+
void SetFlag64( uint16 index, uint64 newFlag )
{
uint64 oldval = GetUInt64Value(index);
uint64 newval = oldval | newFlag;
SetUInt64Value(index,newval);
}
+
void RemoveFlag64( uint16 index, uint64 oldFlag )
{
uint64 oldval = GetUInt64Value(index);
uint64 newval = oldval & ~oldFlag;
SetUInt64Value(index,newval);
}
+
void ToggleFlag64( uint16 index, uint64 flag)
{
if(HasFlag64(index, flag))
@@ -240,57 +285,80 @@ class TRINITY_DLL_SPEC Object
else
SetFlag64(index, flag);
}
+
bool HasFlag64( uint16 index, uint64 flag ) const
{
ASSERT( index < m_valuesCount || PrintIndexError( index , false ) );
return (GetUInt64Value( index ) & flag) != 0;
}
+
void ApplyModFlag64( uint16 index, uint64 flag, bool apply)
{
if(apply) SetFlag64(index,flag); else RemoveFlag64(index,flag);
}
+
void ClearUpdateMask(bool remove);
void SendUpdateObjectToAllExcept(Player* exceptPlayer);
+
bool LoadValues(const char* data);
+
uint16 GetValuesCount() const { return m_valuesCount; }
+
virtual bool hasQuest(uint32 /* quest_id */) const { return false; }
virtual bool hasInvolvedQuest(uint32 /* quest_id */) const { return false; }
+
// FG: some hacky helpers
void ForceValuesUpdateAtIndex(uint32);
+
protected:
+
Object ( );
+
void _InitValues();
void _Create (uint32 guidlow, uint32 entry, HighGuid guidhigh);
+
virtual void _SetUpdateBits(UpdateMask *updateMask, Player *target) const;
+
virtual void _SetCreateBits(UpdateMask *updateMask, Player *target) const;
void _BuildMovementUpdate(ByteBuffer * data, uint16 flags) const;
void _BuildValuesUpdate(uint8 updatetype, ByteBuffer *data, UpdateMask *updateMask, Player *target ) const;
+
uint16 m_objectType;
+
TypeID m_objectTypeId;
uint16 m_updateFlag;
+
union
{
int32 *m_int32Values;
uint32 *m_uint32Values;
float *m_floatValues;
};
+
uint32 *m_uint32Values_mirror;
+
uint16 m_valuesCount;
+
bool m_objectUpdated;
+
private:
bool m_inWorld;
+
ByteBuffer m_PackGUID;
+
// for output helpfull error messages from asserts
bool PrintIndexError(uint32 index, bool set) const;
Object(const Object&); // prevent generation copy constructor
Object& operator=(Object const&); // prevent generation assigment operator
};
+
struct TRINITY_DLL_SPEC Position
{
float m_positionX;
float m_positionY;
float m_positionZ;
float m_orientation;
+
void Relocate(float x, float y)
{ m_positionX = x; m_positionY = y;}
void Relocate(float x, float y, float z)
@@ -303,10 +371,12 @@ struct TRINITY_DLL_SPEC Position
{ m_positionX = pos->m_positionX; m_positionY = pos->m_positionY; m_positionZ = pos->m_positionZ; m_orientation = pos->m_orientation; }
void SetOrientation(float orientation)
{ m_orientation = orientation; }
+
float GetPositionX() const { return m_positionX; }
float GetPositionY() const { return m_positionY; }
float GetPositionZ() const { return m_positionZ; }
float GetOrientation() const { return m_orientation; }
+
void GetPosition(float &x, float &y) const
{ x = m_positionX; y = m_positionY; }
void GetPosition(float &x, float &y, float &z) const
@@ -315,7 +385,9 @@ struct TRINITY_DLL_SPEC Position
{ x = m_positionX; y = m_positionY; z = m_positionZ; o = m_orientation; }
void GetPosition(Position *pos) const
{ pos->Relocate(m_positionX, m_positionY, m_positionZ, m_orientation); }
+
bool IsPositionValid() const;
+
float GetExactDist2dSq(float x, float y) const
{ float dx = m_positionX - x; float dy = m_positionY - y; return dx*dx + dy*dy; }
float GetExactDist2d(const float x, const float y) const
@@ -332,10 +404,12 @@ struct TRINITY_DLL_SPEC Position
{ float dx = m_positionX - pos->m_positionX; float dy = m_positionY - pos->m_positionY; float dz = m_positionZ - pos->m_positionZ; return dx*dx + dy*dy + dz*dz; }
float GetExactDist(const Position *pos) const
{ return sqrt(GetExactDistSq(pos)); }
+
float GetAngle(const Position *pos) const;
float GetAngle(float x, float y) const;
float GetRelativeAngle(const Position *pos) const { return GetAngle(pos) - m_orientation; }
void GetSinCos(float x, float y, float &vsin, float &vcos) const;
+
bool IsInDist2d(float x, float y, float dist) const
{ return GetExactDist2dSq(x, y) < dist * dist; }
bool IsInDist2d(const Position *pos, float dist) const
@@ -347,24 +421,32 @@ struct TRINITY_DLL_SPEC Position
bool HasInArc(float arcangle, const Position *pos) const;
bool HasInLine(const Unit *target, float distance, float width) const;
};
+
#define MAPID_INVALID 0xFFFFFFFF
+
class WorldLocation : public Position
{
public:
explicit WorldLocation(uint32 _mapid = MAPID_INVALID, float _x = 0, float _y = 0, float _z = 0, float _o = 0)
: m_mapId(_mapid) { Relocate(_x, _y, _z, _o); }
WorldLocation(const WorldLocation &loc) { WorldRelocate(loc); }
+
void WorldRelocate(const WorldLocation &loc)
{ m_mapId = loc.GetMapId(); Relocate(loc); }
uint32 GetMapId() const { return m_mapId; }
+
uint32 m_mapId;
};
+
class TRINITY_DLL_SPEC WorldObject : public Object, public WorldLocation
{
public:
virtual ~WorldObject();
+
virtual void Update ( uint32 /*time_diff*/ ) { }
+
void _Create( uint32 guidlow, HighGuid guidhigh, uint32 phaseMask);
+
void GetNearPoint2D( float &x, float &y, float distance, float absAngle) const;
void GetNearPoint( WorldObject const* searcher, float &x, float &y, float &z, float searcher_size, float distance2d,float absAngle) const;
void GetClosePoint(float &x, float &y, float &z, float size, float distance2d = 0, float angle = 0) const
@@ -383,16 +465,19 @@ class TRINITY_DLL_SPEC WorldObject : public Object, public WorldLocation
GetPosition(&pos);
MovePosition(pos, radius * rand_norm(), rand_norm() * 2 * M_PI);
}
+
void GetContactPoint( const WorldObject* obj, float &x, float &y, float &z, float distance2d = CONTACT_DISTANCE) const
{
// angle to face `obj` to `this` using distance includes size of `obj`
GetNearPoint(obj,x,y,z,obj->GetObjectSize(),distance2d,GetAngle( obj ));
}
+
float GetObjectSize() const
{
return ( m_valuesCount > UNIT_FIELD_COMBATREACH ) ? m_floatValues[UNIT_FIELD_COMBATREACH] : DEFAULT_WORLD_OBJECT_SIZE;
}
void UpdateGroundPositionZ(float x, float y, float &z) const;
+
void GetRandomPoint(const Position &srcPos, float distance, float &rand_x, float &rand_y, float &rand_z) const;
void GetRandomPoint(const Position &srcPos, float distance, Position &pos) const
{
@@ -400,18 +485,25 @@ class TRINITY_DLL_SPEC WorldObject : public Object, public WorldLocation
GetRandomPoint(srcPos, distance, x, y, z);
pos.Relocate(x, y, z, GetOrientation());
}
+
uint32 GetInstanceId() const { return m_InstanceId; }
+
virtual void SetPhaseMask(uint32 newPhaseMask, bool update);
uint32 GetPhaseMask() const { return m_phaseMask; }
bool InSamePhase(WorldObject const* obj) const { return InSamePhase(obj->GetPhaseMask()); }
bool InSamePhase(uint32 phasemask) const { return (GetPhaseMask() & phasemask); }
+
uint32 GetZoneId() const;
uint32 GetAreaId() const;
void GetZoneAndAreaId(uint32& zoneid, uint32& areaid) const;
+
InstanceData* GetInstanceData();
+
const char* GetName() const { return m_name.c_str(); }
void SetName(const std::string& newname) { m_name=newname; }
+
virtual const char* GetNameForLocaleIdx(int32 /*locale_idx*/) const { return GetName(); }
+
float GetDistance(const WorldObject *obj) const
{ return GetExactDist(obj) + GetObjectSize() + obj->GetObjectSize(); }
float GetDistance(const Position &pos) const
@@ -423,6 +515,7 @@ class TRINITY_DLL_SPEC WorldObject : public Object, public WorldLocation
float GetDistance2d(float x, float y) const
{ return GetExactDist2d(x, y) + GetObjectSize(); }
float GetDistanceZ(const WorldObject* obj) const;
+
bool IsInMap(const WorldObject* obj) const
{
return IsInWorld() && obj->IsInWorld() && (GetMap() == obj->GetMap()) && InSamePhase(obj);
@@ -451,10 +544,14 @@ class TRINITY_DLL_SPEC WorldObject : public Object, public WorldLocation
bool IsInRange(WorldObject const* obj, float minRange, float maxRange, bool is3D = true) const;
bool IsInRange2d(float x, float y, float minRange, float maxRange) const;
bool IsInRange3d(float x, float y, float z, float minRange, float maxRange) const;
+
bool IsInBetween(const WorldObject *obj1, const WorldObject *obj2, float size = 0) const;
+
virtual void CleanupsBeforeDelete(); // used in destructor or explicitly before mass creature delete to remove cross-references to already deleted units
+
virtual void SendMessageToSet(WorldPacket *data, bool self);
virtual void SendMessageToSetInRange(WorldPacket *data, float dist, bool self);
+
void MonsterSay(const char* text, uint32 language, uint64 TargetGuid);
void MonsterYell(const char* text, uint32 language, uint64 TargetGuid);
void MonsterTextEmote(const char* text, uint64 TargetGuid, bool IsBossEmote = false);
@@ -465,26 +562,36 @@ class TRINITY_DLL_SPEC WorldObject : public Object, public WorldLocation
void MonsterWhisper(int32 textId, uint64 receiver, bool IsBossWhisper = false);
void MonsterYellToZone(int32 textId, uint32 language, uint64 TargetGuid);
void BuildMonsterChat(WorldPacket *data, uint8 msgtype, char const* text, uint32 language, char const* name, uint64 TargetGuid) const;
+
void PlayDistanceSound(uint32 sound_id, Player* target = NULL);
void PlayDirectSound(uint32 sound_id, Player* target = NULL);
+
void SendObjectDeSpawnAnim(uint64 guid);
+
virtual void SaveRespawnTime() {}
void AddObjectToRemoveList();
+
// main visibility check function in normal case (ignore grey zone distance check)
bool isVisibleFor(Player const* u) const { return isVisibleForInState(u,false); }
+
// low level function for visibility change code, must be define in all main world object subclasses
virtual bool isVisibleForInState(Player const* u, bool inVisibleList) const = 0;
+
// Low Level Packets
void SendPlaySound(uint32 Sound, bool OnlySelf);
+
virtual void SetMap(Map * map);
virtual void ResetMap();
Map * GetMap() const { ASSERT(m_currMap); return m_currMap; }
Map * FindMap() const { return m_currMap; }
//used to check all object's GetMap() calls when object is not in world!
+
//this function should be removed in nearest time...
Map const* GetBaseMap() const;
+
void SetZoneScript();
ZoneScript * GetZoneScript() const { return m_zoneScript; }
+
TempSummon* SummonCreature(uint32 id, const Position &pos, TempSummonType spwtype = TEMPSUMMON_MANUAL_DESPAWN, uint32 despwtime = 0, uint32 vehId = 0) const;
TempSummon* SummonCreature(uint32 id, float x, float y, float z, float ang = 0, TempSummonType spwtype = TEMPSUMMON_MANUAL_DESPAWN, uint32 despwtime = 0)
{
@@ -498,17 +605,22 @@ class TRINITY_DLL_SPEC WorldObject : public Object, public WorldLocation
}
GameObject* SummonGameObject(uint32 entry, float x, float y, float z, float ang, float rotation0, float rotation1, float rotation2, float rotation3, uint32 respawnTime);
Creature* SummonTrigger(float x, float y, float z, float ang, uint32 dur, CreatureAI* (*GetAI)(Creature*) = NULL);
+
Creature* FindNearestCreature(uint32 entry, float range, bool alive = true);
GameObject* FindNearestGameObject(uint32 entry, float range);
+
void GetGameObjectListWithEntryInGrid(std::list<GameObject*>& lList, uint32 uiEntry, float fMaxSearchRange);
void GetCreatureListWithEntryInGrid(std::list<Creature*>& lList, uint32 uiEntry, float fMaxSearchRange);
+
void DestroyForNearbyPlayers();
+
bool isActiveObject() const { return m_isActive; }
void setActive(bool isActiveObject);
void SetWorldObject(bool apply);
template<class NOTIFIER> void VisitNearbyObject(const float &radius, NOTIFIER &notifier) const { GetMap()->VisitAll(GetPositionX(), GetPositionY(), radius, notifier); }
template<class NOTIFIER> void VisitNearbyGridObject(const float &radius, NOTIFIER &notifier) const { GetMap()->VisitGrid(GetPositionX(), GetPositionY(), radius, notifier); }
template<class NOTIFIER> void VisitNearbyWorldObject(const float &radius, NOTIFIER &notifier) const { GetMap()->VisitWorld(GetPositionX(), GetPositionY(), radius, notifier); }
+
#ifdef MAP_BASED_RAND_GEN
int32 irand(int32 min, int32 max) const { return int32 (GetMap()->mtRand.randInt(max - min)) + min; }
uint32 urand(uint32 min, uint32 max) const { return GetMap()->mtRand.randInt(max - min) + min;}
@@ -516,19 +628,23 @@ class TRINITY_DLL_SPEC WorldObject : public Object, public WorldLocation
double rand_norm() const { return GetMap()->mtRand.randExc();}
double rand_chance() const { return GetMap()->mtRand.randExc(100.0);}
#endif
+
bool m_isWorldObject;
protected:
explicit WorldObject();
std::string m_name;
bool m_isActive;
ZoneScript *m_zoneScript;
+
//these functions are used mostly for Relocate() and Corpse/Player specific stuff...
//use them ONLY in LoadFromDB()/Create() funcs and nowhere else!
//mapId/instanceId should be set in SetMap() function!
void SetLocationMapId(uint32 _mapId) { m_mapId = _mapId; }
void SetLocationInstanceId(uint32 _instanceId) { m_InstanceId = _instanceId; }
+
private:
Map * m_currMap; //current object's Map location
+
//uint32 m_mapId; // object at map with map_id
uint32 m_InstanceId; // in map copy with instance id
uint32 m_phaseMask; // in area phase state