2008-10-02 16:23:55 -05:00
/*
2009-02-04 12:42:26 +01:00
* Copyright (C) 2005-2009 MaNGOS <http://getmangos.com/>
2008-10-14 11:57:03 -05:00
*
2009-02-04 12:04:12 +01:00
* Copyright (C) 2008-2009 Trinity <http://www.trinitycore.org/>
2008-10-02 16:23:55 -05:00
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
2008-10-14 11:57:03 -05:00
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2008-10-02 16:23:55 -05:00
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
2008-10-14 11:57:03 -05:00
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
2008-10-02 16:23:55 -05:00
*/
#ifndef _OBJECT_H
#define _OBJECT_H
#include "Common.h"
#include "ByteBuffer.h"
#include "UpdateFields.h"
#include "UpdateData.h"
#include "GameSystem/GridReference.h"
#include "ObjectDefines.h"
2008-10-27 08:41:55 -05:00
#include "GridDefines.h"
2008-12-18 14:20:38 -06:00
#include "Map.h"
2008-10-02 16:23:55 -05:00
#include <set>
#include <string>
#define CONTACT_DISTANCE 0.5f
2008-11-10 09:04:23 -06:00
#define INTERACTION_DISTANCE 5.0f
2009-05-18 20:34:09 +02:00
#define ATTACK_DISTANCE 5.0f
2008-10-02 16:23:55 -05:00
#define MAX_VISIBILITY_DISTANCE (5*SIZE_OF_GRID_CELL/2.0f) // max distance for visible object show, limited by active zone for player based at cell size (active zone = 5x5 cells)
#define DEFAULT_VISIBILITY_DISTANCE (SIZE_OF_GRID_CELL) // default visible distance
#define DEFAULT_WORLD_OBJECT_SIZE 0.388999998569489f // player size, also currently used (correctly?) for any non Unit world objects
2008-12-04 23:00:35 -06:00
#define DEFAULT_COMBAT_REACH 1.5f
2008-12-05 18:39:31 -06:00
#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
2008-10-02 16:23:55 -05:00
enum TypeMask
{
TYPEMASK_OBJECT = 0x0001 ,
TYPEMASK_ITEM = 0x0002 ,
TYPEMASK_CONTAINER = 0x0006 , // TYPEMASK_ITEM | 0x0004
2009-03-10 15:26:17 -06:00
TYPEMASK_UNIT = 0x0008 , //creature or player
2008-10-02 16:23:55 -05:00
TYPEMASK_PLAYER = 0x0010 ,
TYPEMASK_GAMEOBJECT = 0x0020 ,
TYPEMASK_DYNAMICOBJECT = 0x0040 ,
TYPEMASK_CORPSE = 0x0080 ,
2009-03-10 15:26:17 -06:00
TYPEMASK_SEER = TYPEMASK_UNIT | TYPEMASK_DYNAMICOBJECT
2008-10-02 16:23:55 -05:00
};
enum TypeID
{
TYPEID_OBJECT = 0 ,
TYPEID_ITEM = 1 ,
TYPEID_CONTAINER = 2 ,
TYPEID_UNIT = 3 ,
TYPEID_PLAYER = 4 ,
TYPEID_GAMEOBJECT = 5 ,
TYPEID_DYNAMICOBJECT = 6 ,
2009-05-31 15:56:51 -05:00
TYPEID_CORPSE = 7
2008-10-02 16:23:55 -05:00
};
2009-05-31 15:56:51 -05:00
#define NUM_CLIENT_OBJECT_TYPES 8
2008-10-02 16:23:55 -05:00
uint32 GuidHigh2TypeId ( uint32 guid_hi );
enum TempSummonType
{
TEMPSUMMON_TIMED_OR_DEAD_DESPAWN = 1 , // despawns after a specified time OR when the creature disappears
TEMPSUMMON_TIMED_OR_CORPSE_DESPAWN = 2 , // despawns after a specified time OR when the creature dies
TEMPSUMMON_TIMED_DESPAWN = 3 , // despawns after a specified time
TEMPSUMMON_TIMED_DESPAWN_OUT_OF_COMBAT = 4 , // despawns after a specified time after the creature is out of combat
TEMPSUMMON_CORPSE_DESPAWN = 5 , // despawns instantly after death
TEMPSUMMON_CORPSE_TIMED_DESPAWN = 6 , // despawns after a specified time after death
TEMPSUMMON_DEAD_DESPAWN = 7 , // despawns when the creature disappears
TEMPSUMMON_MANUAL_DESPAWN = 8 // despawns when UnSummon() is called
};
2009-01-31 16:38:50 -06:00
enum PhaseMasks
{
PHASEMASK_NORMAL = 0x00000001 ,
PHASEMASK_ANYWHERE = 0xFFFFFFFF
};
2008-10-02 16:23:55 -05:00
class WorldPacket ;
class UpdateData ;
class ByteBuffer ;
class WorldSession ;
class Creature ;
class Player ;
class UpdateMask ;
class InstanceData ;
2008-10-17 18:13:04 -05:00
class GameObject ;
2009-03-19 14:41:30 -06:00
class TempSummon ;
2009-03-18 21:39:09 -06:00
class Vehicle ;
2009-04-07 19:38:09 -05:00
class CreatureAI ;
2009-05-30 22:15:05 -05:00
class ZoneScript ;
2008-10-02 16:23:55 -05:00
2008-11-10 06:53:00 -06:00
typedef UNORDERED_MAP < Player * , UpdateData > UpdateDataMapType ;
2008-10-02 16:23:55 -05:00
struct WorldLocation
{
uint32 mapid ;
2009-06-16 11:19:59 -05:00
float coord_x ;
float coord_y ;
float coord_z ;
float orientation ;
2008-11-12 16:21:08 -06:00
explicit WorldLocation ( uint32 _mapid = 0 , float _x = 0 , float _y = 0 , float _z = 0 , float _o = 0 )
2009-06-16 11:19:59 -05:00
: mapid ( _mapid ), coord_x ( _x ), coord_y ( _y ), coord_z ( _z ), orientation ( _o ) {}
2008-10-02 16:23:55 -05:00
WorldLocation ( WorldLocation const & loc )
2009-06-16 11:19:59 -05:00
: mapid ( loc . mapid ), coord_x ( loc . coord_x ), coord_y ( loc . coord_y ), coord_z ( loc . coord_z ), orientation ( loc . orientation ) {}
2008-10-02 16:23:55 -05:00
};
2009-06-16 11:19:59 -05:00
typedef float Position [ 4 ];
2008-10-14 11:57:03 -05:00
class TRINITY_DLL_SPEC Object
2008-10-02 16:23:55 -05:00
{
public :
virtual ~ Object ( );
2009-04-10 17:56:42 -05:00
const bool IsInWorld () const { return m_inWorld ; }
2008-10-02 16:23:55 -05:00
virtual void AddToWorld ()
{
if ( m_inWorld )
return ;
2009-04-01 21:17:59 -06:00
assert ( m_uint32Values );
2008-10-02 16:23:55 -05:00
m_inWorld = true ;
// synchronize values mirror with values array (changes will send in updatecreate opcode any way
ClearUpdateMask ( true );
}
virtual void RemoveFromWorld ()
{
2009-03-25 15:54:23 -06:00
if ( ! m_inWorld )
return ;
2008-10-02 16:23:55 -05:00
m_inWorld = false ;
2009-04-01 21:17:59 -06:00
// if we remove from world then sending changes not required
ClearUpdateMask ( true );
2008-10-02 16:23:55 -05:00
}
const uint64 & GetGUID () const { return GetUInt64Value ( 0 ); }
uint32 GetGUIDLow () const { return GUID_LOPART ( GetUInt64Value ( 0 )); }
uint32 GetGUIDMid () const { return GUID_ENPART ( GetUInt64Value ( 0 )); }
uint32 GetGUIDHigh () const { return GUID_HIPART ( GetUInt64Value ( 0 )); }
const ByteBuffer & GetPackGUID () const { return m_PackGUID ; }
uint32 GetEntry () const { return GetUInt32Value ( OBJECT_FIELD_ENTRY ); }
2008-11-12 16:21:08 -06:00
void SetEntry ( uint32 entry ) { SetUInt32Value ( OBJECT_FIELD_ENTRY , entry ); }
2008-10-02 16:23:55 -05:00
uint8 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 & );
2009-07-30 10:26:15 +08:00
virtual void DestroyForPlayer ( Player * target , bool anim = false ) const ;
2008-10-02 16:23:55 -05:00
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 );
}
2009-04-22 17:56:59 -05:00
uint16 GetUInt16Value ( uint16 index , uint8 offset ) const
2008-10-02 16:23:55 -05:00
{
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 SetUInt64Value ( uint16 index , const uint64 & value );
void SetFloatValue ( uint16 index , float value );
void SetByteValue ( uint16 index , uint8 offset , uint8 value );
void SetUInt16Value ( uint16 index , uint8 offset , uint16 value );
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 );
2009-03-23 20:13:37 -06:00
bool AddUInt64Value ( uint16 index , const uint64 & value );
bool RemoveUInt64Value ( uint16 index , const uint64 & value );
2008-10-02 16:23:55 -05:00
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 ))
RemoveFlag ( index , flag );
else
SetFlag ( index , flag );
}
bool HasFlag ( uint16 index , uint32 flag ) const
{
ASSERT ( index < m_valuesCount || PrintIndexError ( index , false ) );
return ( m_uint32Values [ index ] & flag ) != 0 ;
}
2008-12-12 11:21:28 -06:00
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 ))
RemoveByteFlag ( index , offset , flag );
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 ;
}
2008-10-02 16:23:55 -05:00
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 ))
RemoveFlag64 ( index , flag );
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 ; }
2009-01-15 21:29:32 -05:00
// FG: some hacky helpers
void ForceValuesUpdateAtIndex ( uint32 );
2008-10-02 16:23:55 -05:00
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 ;
2009-06-11 00:45:59 -05:00
void _BuildMovementUpdate ( ByteBuffer * data , uint16 flags ) const ;
2008-10-02 16:23:55 -05:00
void _BuildValuesUpdate ( uint8 updatetype , ByteBuffer * data , UpdateMask * updateMask , Player * target ) const ;
uint16 m_objectType ;
uint8 m_objectTypeId ;
2009-06-11 00:45:59 -05:00
uint16 m_updateFlag ;
2008-10-02 16:23:55 -05:00
union
{
int32 * m_int32Values ;
uint32 * m_uint32Values ;
2008-12-12 11:21:28 -06:00
float * m_floatValues ;
2008-10-02 16:23:55 -05:00
};
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
};
2008-10-14 11:57:03 -05:00
class TRINITY_DLL_SPEC WorldObject : public Object
2008-10-02 16:23:55 -05:00
{
public :
2009-02-24 20:05:29 -06:00
virtual ~ WorldObject ( ) {}
2008-10-02 16:23:55 -05:00
virtual void Update ( uint32 /*time_diff*/ ) { }
2009-07-16 11:49:00 +08:00
void _Create ( uint32 guidlow , HighGuid guidhigh , uint32 phaseMask );
2008-10-02 16:23:55 -05:00
2009-04-17 15:08:58 -05:00
void Relocate ( WorldObject * obj )
{
m_positionX = obj -> GetPositionX ();
m_positionY = obj -> GetPositionY ();
m_positionZ = obj -> GetPositionZ ();
m_orientation = obj -> GetOrientation ();
}
2008-10-02 16:23:55 -05:00
void Relocate ( float x , float y , float z , float orientation )
{
m_positionX = x ;
m_positionY = y ;
m_positionZ = z ;
m_orientation = orientation ;
}
void Relocate ( float x , float y , float z )
{
m_positionX = x ;
m_positionY = y ;
m_positionZ = z ;
}
2009-06-16 11:19:59 -05:00
void Relocate ( Position pos )
{ m_positionX = pos [ 0 ]; m_positionY = pos [ 1 ]; m_positionZ = pos [ 2 ]; m_orientation = pos [ 3 ]; }
2008-10-02 16:23:55 -05:00
2009-05-30 17:17:05 -05:00
void SetOrientation ( float orientation ) { m_orientation = orientation ; }
2008-10-02 16:23:55 -05:00
float GetPositionX ( ) const { return m_positionX ; }
float GetPositionY ( ) const { return m_positionY ; }
float GetPositionZ ( ) const { return m_positionZ ; }
void GetPosition ( float & x , float & y , float & z ) const
{ x = m_positionX ; y = m_positionY ; z = m_positionZ ; }
void GetPosition ( WorldLocation & loc ) const
2009-06-16 11:19:59 -05:00
{ loc . mapid = m_mapId ; GetPosition ( loc . coord_x , loc . coord_y , loc . coord_z ); loc . orientation = GetOrientation (); }
void GetPosition ( Position pos ) const
{ pos [ 0 ] = m_positionX ; pos [ 1 ] = m_positionY ; pos [ 2 ] = m_positionZ ; pos [ 3 ] = m_orientation ; }
2008-10-02 16:23:55 -05:00
float GetOrientation ( ) const { return m_orientation ; }
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
{
// angle calculated from current orientation
GetNearPoint ( NULL , x , y , z , size , distance2d , GetOrientation () + angle );
}
2009-01-09 17:52:13 -06:00
void GetGroundPoint ( float & x , float & y , float & z , float dist , float angle );
void GetGroundPointAroundUnit ( float & x , float & y , float & z , float dist , float angle )
2009-01-08 14:22:15 -06:00
{
GetPosition ( x , y , z );
2009-01-09 17:52:13 -06:00
GetGroundPoint ( x , y , z , dist , angle );
2009-01-08 14:22:15 -06:00
}
2008-10-02 16:23:55 -05:00
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
{
2009-05-24 16:18:19 +02:00
return ( m_valuesCount > UNIT_FIELD_COMBATREACH ) ? m_floatValues [ UNIT_FIELD_COMBATREACH ] : DEFAULT_WORLD_OBJECT_SIZE ;
2008-10-02 16:23:55 -05:00
}
bool IsPositionValid () const ;
void UpdateGroundPositionZ ( float x , float y , float & z ) const ;
void GetRandomPoint ( float x , float y , float z , float distance , float & rand_x , float & rand_y , float & rand_z ) const ;
uint32 GetMapId () const { return m_mapId ; }
2009-04-20 17:37:59 -05:00
uint32 GetInstanceId () const { return m_InstanceId ; }
2008-10-02 16:23:55 -05:00
2009-01-31 16:38:50 -06:00
virtual void SetPhaseMask ( uint32 newPhaseMask , bool update );
uint32 GetPhaseMask () const { return m_phaseMask ; }
bool InSamePhase ( WorldObject const * obj ) const { return InSamePhase ( obj -> GetPhaseMask ()); }
2009-02-24 11:14:28 -06:00
bool InSamePhase ( uint32 phasemask ) const { return ( GetPhaseMask () & phasemask ); }
2009-01-31 16:38:50 -06:00
2008-10-02 16:23:55 -05:00
uint32 GetZoneId () const ;
uint32 GetAreaId () const ;
2009-03-11 16:17:37 -06:00
void GetZoneAndAreaId ( uint32 & zoneid , uint32 & areaid ) const ;
2008-10-02 16:23:55 -05:00
InstanceData * GetInstanceData ();
const char * GetName () const { return m_name . c_str (); }
2008-12-12 11:21:28 -06:00
void SetName ( const std :: string & newname ) { m_name = newname ; }
2008-10-02 16:23:55 -05:00
2008-11-14 17:03:03 -06:00
virtual const char * GetNameForLocaleIdx ( int32 /*locale_idx*/ ) const { return GetName (); }
2008-10-02 16:23:55 -05:00
float GetDistance ( const WorldObject * obj ) const ;
2009-05-14 16:50:47 -05:00
float GetDistance ( float x , float y , float z ) const ;
2009-01-28 11:50:12 -06:00
float GetDistanceSq ( const float & x , const float & y , const float & z ) const ;
2009-05-10 14:29:28 -05:00
float GetDistanceSq ( const WorldObject * obj ) const ;
2008-10-02 16:23:55 -05:00
float GetDistance2d ( const WorldObject * obj ) const ;
2009-05-14 16:50:47 -05:00
float GetDistance2d ( float x , float y ) const ;
2009-04-11 22:41:15 -05:00
float GetExactDistance2d ( const float x , const float y ) const ;
2008-10-02 16:23:55 -05:00
float GetDistanceZ ( const WorldObject * obj ) const ;
2009-01-31 16:38:50 -06:00
bool IsInMap ( const WorldObject * obj ) const
{
2009-07-16 11:49:00 +08:00
return IsInWorld () && obj -> IsInWorld () && ( GetMap () == obj -> GetMap ()) && InSamePhase ( obj );
2009-01-31 16:38:50 -06:00
}
2009-05-14 16:50:47 -05:00
bool IsWithinDist3d ( float x , float y , float z , float dist2compare ) const ;
bool IsWithinDist2d ( float x , float y , float dist2compare ) const ;
bool _IsWithinDist ( WorldObject const * obj , float dist2compare , bool is3D ) const ;
bool IsWithinDist ( WorldObject const * obj , float dist2compare , bool is3D = true ) const
// use only if you will sure about placing both object at same map
{
return obj && _IsWithinDist ( obj , dist2compare , is3D );
}
bool IsWithinDistInMap ( WorldObject const * obj , float dist2compare , bool is3D = true ) const
{
return obj && IsInMap ( obj ) && _IsWithinDist ( obj , dist2compare , is3D );
}
bool IsWithinLOS ( float x , float y , float z ) const ;
2008-10-02 16:23:55 -05:00
bool IsWithinLOSInMap ( const WorldObject * obj ) const ;
2009-05-14 16:50:47 -05:00
bool GetDistanceOrder ( WorldObject const * obj1 , WorldObject const * obj2 , bool is3D = true ) const ;
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 ;
2008-10-02 16:23:55 -05:00
float GetAngle ( const WorldObject * obj ) const ;
float GetAngle ( const float x , const float y ) const ;
2009-03-23 15:26:13 -06:00
void GetSinCos ( const float x , const float y , float & vsin , float & vcos );
2008-10-02 16:23:55 -05:00
bool HasInArc ( const float arcangle , const WorldObject * obj ) const ;
2009-05-09 10:50:41 -05:00
bool IsInBetween ( const WorldObject * obj1 , const WorldObject * obj2 , float size = 0 ) const ;
2008-10-02 16:23:55 -05:00
2009-07-01 18:23:36 -05:00
virtual void CleanupsBeforeDelete (); // used in destructor or explicitly before mass creature delete to remove cross-references to already deleted units
2009-05-27 09:09:22 -05:00
virtual void SendMessageToSet ( WorldPacket * data , bool self );
virtual void SendMessageToSetInRange ( WorldPacket * data , float dist , bool self );
2008-10-02 16:23:55 -05:00
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 );
void MonsterWhisper ( const char * text , uint64 receiver , bool IsBossWhisper = false );
void MonsterSay ( int32 textId , uint32 language , uint64 TargetGuid );
void MonsterYell ( int32 textId , uint32 language , uint64 TargetGuid );
void MonsterTextEmote ( int32 textId , uint64 TargetGuid , bool IsBossEmote = false );
void MonsterWhisper ( int32 textId , uint64 receiver , bool IsBossWhisper = false );
2009-03-28 18:03:56 -06:00
void MonsterYellToZone ( int32 textId , uint32 language , uint64 TargetGuid );
2008-10-02 16:23:55 -05:00
void BuildMonsterChat ( WorldPacket * data , uint8 msgtype , char const * text , uint32 language , char const * name , uint64 TargetGuid ) const ;
2009-03-22 19:20:03 -06:00
void PlayDistanceSound ( uint32 sound_id , Player * target = NULL );
void PlayDirectSound ( uint32 sound_id , Player * target = NULL );
2008-10-02 16:23:55 -05:00
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 ;
2008-10-05 11:38:24 -05:00
// Low Level Packets
void SendPlaySound ( uint32 Sound , bool OnlySelf );
2009-07-16 11:49:00 +08:00
void SetMap ( Map * map );
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!
void ResetMap () { m_currMap = NULL ; }
//this function should be removed in nearest time...
2008-10-02 16:23:55 -05:00
Map const * GetBaseMap () const ;
2009-05-29 16:49:28 -05:00
2009-05-30 22:15:05 -05:00
void SetZoneScript ();
2009-05-31 20:45:34 -05:00
ZoneScript * GetZoneScript () const { return m_zoneScript ; }
2009-05-30 22:15:05 -05:00
2009-04-21 13:49:39 -05:00
TempSummon * SummonCreature ( uint32 id , float x , float y , float z , float ang = 0 , TempSummonType spwtype = TEMPSUMMON_MANUAL_DESPAWN , uint32 despwtime = 0 );
Vehicle * SummonVehicle ( uint32 entry , float x , float y , float z , float ang = 0 );
2008-10-17 18:13:04 -05:00
GameObject * SummonGameObject ( uint32 entry , float x , float y , float z , float ang , float rotation0 , float rotation1 , float rotation2 , float rotation3 , uint32 respawnTime );
2009-03-18 21:39:09 -06:00
Creature * SummonTrigger ( float x , float y , float z , float ang , uint32 dur , CreatureAI * ( * GetAI )( Creature * ) = NULL );
2009-05-29 16:49:28 -05:00
Creature * FindNearestCreature ( uint32 entry , float range , bool alive = true );
GameObject * FindNearestGameObject ( uint32 entry , float range );
2009-07-24 05:27:49 +02:00
void GetGameObjectListWithEntryInGrid ( std :: list < GameObject *>& lList , uint32 uiEntry , float fMaxSearchRange );
void GetCreatureListWithEntryInGrid ( std :: list < Creature *>& lList , uint32 uiEntry , float fMaxSearchRange );
2009-02-25 20:52:20 -06:00
bool isActiveObject () const { return m_isActive ; }
void setActive ( bool isActiveObject );
2009-02-26 16:29:55 -06:00
void SetWorldObject ( bool apply );
2008-12-18 14:20:38 -06:00
template < class NOTIFIER > void VisitNearbyObject ( const float & radius , NOTIFIER & notifier ) const { GetMap () -> VisitAll ( GetPositionX (), GetPositionY (), radius , notifier ); }
2008-12-19 18:31:46 -06:00
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 ); }
2009-03-02 18:01:27 -06:00
bool IsTempWorldObject ;
2009-05-25 12:05:23 -05:00
#ifdef MAP_BASED_RAND_GEN
2009-07-27 16:06:39 +02:00
// Object may not have map assigned - use global scope rand in that case
int32 irand ( int32 min , int32 max ) const { return FindMap () ? int32 ( GetMap () -> mtRand . randInt ( max - min )) + min : :: irand ( min , max ); }
uint32 urand ( uint32 min , uint32 max ) const { return FindMap () ? GetMap () -> mtRand . randInt ( max - min ) + min : :: urand ( min , max ); }
int32 rand32 () const { return FindMap () ? GetMap () -> mtRand . randInt () : :: rand32 (); }
double rand_norm () const { return FindMap () ? GetMap () -> mtRand . randExc () : :: rand_norm (); }
double rand_chance () const { return FindMap () ? GetMap () -> mtRand . randExc ( 100.0 ) : :: rand_chance (); }
2009-05-25 12:05:23 -05:00
#endif
2008-10-02 16:23:55 -05:00
protected :
explicit WorldObject ();
std :: string m_name ;
2008-10-27 08:41:55 -05:00
bool m_isActive ;
2009-05-30 22:15:05 -05:00
ZoneScript * m_zoneScript ;
2008-10-02 16:23:55 -05:00
2009-07-16 11:49:00 +08:00
//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 ; }
2008-10-02 16:23:55 -05:00
private :
2009-07-16 11:49:00 +08:00
Map * m_currMap ; //current object's Map location
2009-01-31 16:38:50 -06:00
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
2009-04-20 19:57:01 -05:00
2008-10-02 16:23:55 -05:00
float m_positionX ;
float m_positionY ;
float m_positionZ ;
float m_orientation ;
};
#endif
2009-02-17 20:07:49 -06:00