2010-10-07 15:54:07 +02:00
/*
2014-01-01 00:07:53 +01:00
* Copyright (C) 2008-2014 TrinityCore <http://www.trinitycore.org/>
2010-10-07 15:54:07 +02:00
* Copyright (C) 2005-2009 MaNGOS <http://getmangos.com/>
*
* 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 MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the 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, see <http://www.gnu.org/licenses/>.
2008-10-02 16:23:55 -05:00
*/
2009-10-17 15:51:44 -07:00
2008-10-02 16:23:55 -05:00
#ifndef _OBJECT_H
#define _OBJECT_H
2009-10-17 15:51:44 -07:00
2008-10-02 16:23:55 -05:00
#include "Common.h"
2013-01-22 18:45:09 +01:00
#include "UpdateMask.h"
2010-06-08 13:05:47 -06:00
#include "GridReference.h"
2008-10-02 16:23:55 -05:00
#include "ObjectDefines.h"
2008-12-18 14:20:38 -06:00
#include "Map.h"
2009-10-17 15:51:44 -07:00
2008-10-02 16:23:55 -05:00
#include <set>
#include <string>
2010-08-08 20:32:14 +02:00
#include <sstream>
2009-10-17 15:51:44 -07:00
2008-10-02 16:23:55 -05:00
#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
2014-04-24 14:34:19 +02:00
#define INSPECT_DISTANCE 28.0f
2014-04-25 20:52:17 +02:00
#define TRADE_DISTANCE 11.11f
2012-06-03 05:36:27 +02:00
#define MAX_VISIBILITY_DISTANCE SIZE_OF_GRIDS // max distance for visible objects
2010-11-13 17:18:09 +01:00
#define SIGHT_RANGE_UNIT 50.0f
2012-06-03 05:36:27 +02:00
#define DEFAULT_VISIBILITY_DISTANCE 90.0f // default visible distance, 90 yards on continents
#define DEFAULT_VISIBILITY_INSTANCE 170.0f // default visible distance in instances, 170 yards
#define DEFAULT_VISIBILITY_BGARENAS 533.0f // default visible distance in BG/Arenas, roughly 533 yards
2009-10-17 15:51:44 -07:00
2008-10-02 16:23:55 -05:00
#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
2009-10-17 15:51:44 -07:00
2008-10-02 16:23:55 -05:00
enum TypeMask
{
TYPEMASK_OBJECT = 0x0001 ,
TYPEMASK_ITEM = 0x0002 ,
TYPEMASK_CONTAINER = 0x0006 , // TYPEMASK_ITEM | 0x0004
2012-10-24 13:29:34 +02:00
TYPEMASK_UNIT = 0x0008 , // creature
2008-10-02 16:23:55 -05:00
TYPEMASK_PLAYER = 0x0010 ,
TYPEMASK_GAMEOBJECT = 0x0020 ,
TYPEMASK_DYNAMICOBJECT = 0x0040 ,
TYPEMASK_CORPSE = 0x0080 ,
2013-09-01 12:50:00 +02:00
TYPEMASK_SEER = TYPEMASK_PLAYER | TYPEMASK_UNIT | TYPEMASK_DYNAMICOBJECT
2008-10-02 16:23:55 -05:00
};
2009-10-17 15:51:44 -07:00
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-10-17 15:51:44 -07:00
2009-05-31 15:56:51 -05:00
#define NUM_CLIENT_OBJECT_TYPES 8
2009-10-17 15:51:44 -07:00
2008-10-02 16:23:55 -05:00
uint32 GuidHigh2TypeId ( uint32 guid_hi );
2009-10-17 15:51:44 -07:00
2008-10-02 16:23:55 -05:00
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-10-17 15:51:44 -07:00
2009-01-31 16:38:50 -06:00
enum PhaseMasks
{
PHASEMASK_NORMAL = 0x00000001 ,
PHASEMASK_ANYWHERE = 0xFFFFFFFF
};
2009-10-17 15:51:44 -07:00
2009-12-19 10:12:40 +01:00
enum NotifyFlags
{
NOTIFY_NONE = 0x00 ,
NOTIFY_AI_RELOCATION = 0x01 ,
NOTIFY_VISIBILITY_CHANGED = 0x02 ,
NOTIFY_ALL = 0xFF
};
2013-03-25 10:36:30 +01:00
class Corpse ;
2008-10-02 16:23:55 -05:00
class Creature ;
2013-03-25 10:36:30 +01:00
class CreatureAI ;
class DynamicObject ;
2008-10-17 18:13:04 -05:00
class GameObject ;
2013-03-25 10:36:30 +01:00
class InstanceScript ;
class Player ;
2009-03-19 14:41:30 -06:00
class TempSummon ;
2010-07-30 21:54:46 -07:00
class Transport ;
2013-03-25 10:36:30 +01:00
class Unit ;
class UpdateData ;
class WorldObject ;
class WorldPacket ;
class ZoneScript ;
2010-07-30 21:54:46 -07:00
2014-05-01 10:10:13 +02:00
typedef std :: unordered_map < Player * , UpdateData > UpdateDataMapType ;
2010-07-30 21:54:46 -07:00
2010-02-05 00:31:28 +01:00
class Object
2008-10-02 16:23:55 -05:00
{
public :
2012-03-29 13:42:04 +08:00
virtual ~ Object ();
2009-10-17 15:51:44 -07:00
2011-08-01 14:23:27 +02:00
bool IsInWorld () const { return m_inWorld ; }
2009-10-17 15:51:44 -07:00
2011-08-30 13:46:36 +02:00
virtual void AddToWorld ();
virtual void RemoveFromWorld ();
2009-10-17 15:51:44 -07:00
2011-08-03 11:23:08 +02:00
uint64 GetGUID () const { return GetUInt64Value ( 0 ); }
2008-10-02 16:23:55 -05:00
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 ); }
2009-10-17 15:51:44 -07:00
2013-08-17 23:46:36 +02:00
float GetObjectScale () const { return GetFloatValue ( OBJECT_FIELD_SCALE_X ); }
2013-06-15 14:45:28 +02:00
virtual void SetObjectScale ( float scale ) { SetFloatValue ( OBJECT_FIELD_SCALE_X , scale ); }
2012-05-26 23:00:54 +02:00
2009-08-06 10:38:46 -05:00
TypeID GetTypeId () const { return m_objectTypeId ; }
2014-07-17 15:42:57 +02:00
bool isType ( uint16 mask ) const { return ( mask & m_objectType ) != 0 ; }
2009-10-17 15:51:44 -07:00
2011-09-15 14:08:17 +02:00
virtual void BuildCreateUpdateBlockForPlayer ( UpdateData * data , Player * target ) const ;
2009-12-19 19:46:07 +01:00
void SendUpdateToPlayer ( Player * player );
2009-10-17 15:51:44 -07:00
2011-09-15 14:08:17 +02:00
void BuildValuesUpdateBlockForPlayer ( UpdateData * data , Player * target ) const ;
void BuildOutOfRangeUpdateBlock ( UpdateData * data ) const ;
void BuildMovementUpdateBlock ( UpdateData * data , uint32 flags = 0 ) const ;
2009-10-17 15:51:44 -07:00
2012-02-29 12:43:59 +01:00
virtual void DestroyForPlayer ( Player * target , bool onDeath = false ) const ;
2009-10-17 15:51:44 -07:00
2013-03-04 11:45:57 +01:00
int32 GetInt32Value ( uint16 index ) const ;
uint32 GetUInt32Value ( uint16 index ) const ;
uint64 GetUInt64Value ( uint16 index ) const ;
float GetFloatValue ( uint16 index ) const ;
uint8 GetByteValue ( uint16 index , uint8 offset ) const ;
uint16 GetUInt16Value ( uint16 index , uint8 offset ) const ;
2009-10-17 15:51:44 -07:00
2011-08-28 17:36:02 +02:00
void SetInt32Value ( uint16 index , int32 value );
void SetUInt32Value ( uint16 index , uint32 value );
void UpdateUInt32Value ( uint16 index , uint32 value );
2011-08-30 13:46:36 +02:00
void SetUInt64Value ( uint16 index , uint64 value );
2011-08-28 17:36:02 +02:00
void SetFloatValue ( uint16 index , float value );
2010-04-07 22:59:46 +02:00
void SetByteValue ( uint16 index , uint8 offset , uint8 value );
void SetUInt16Value ( uint16 index , uint8 offset , uint16 value );
2011-04-29 20:47:02 +02:00
void SetInt16Value ( uint16 index , uint8 offset , int16 value ) { SetUInt16Value ( index , offset , ( uint16 ) value ); }
2010-04-07 22:59:46 +02:00
void SetStatFloatValue ( uint16 index , float value );
void SetStatInt32Value ( uint16 index , int32 value );
2009-10-17 15:51:44 -07:00
2011-08-30 13:46:36 +02:00
bool AddUInt64Value ( uint16 index , uint64 value );
bool RemoveUInt64Value ( uint16 index , uint64 value );
2009-10-17 15:51:44 -07:00
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 );
2010-04-07 22:59:46 +02:00
void ApplyModPositiveFloatValue ( uint16 index , float val , bool apply );
void ApplyModSignedFloatValue ( uint16 index , float val , bool apply );
2013-03-04 11:45:57 +01:00
void ApplyPercentModFloatValue ( uint16 index , float val , bool apply );
2009-10-17 15:51:44 -07:00
2010-04-07 22:59:46 +02:00
void SetFlag ( uint16 index , uint32 newFlag );
void RemoveFlag ( uint16 index , uint32 oldFlag );
2013-03-04 11:45:57 +01:00
void ToggleFlag ( uint16 index , uint32 flag );
bool HasFlag ( uint16 index , uint32 flag ) const ;
void ApplyModFlag ( uint16 index , uint32 flag , bool apply );
2009-10-17 15:51:44 -07:00
2010-04-07 22:59:46 +02:00
void SetByteFlag ( uint16 index , uint8 offset , uint8 newFlag );
void RemoveByteFlag ( uint16 index , uint8 offset , uint8 newFlag );
2013-03-04 11:45:57 +01:00
void ToggleByteFlag ( uint16 index , uint8 offset , uint8 flag );
bool HasByteFlag ( uint16 index , uint8 offset , uint8 flag ) const ;
2009-10-17 15:51:44 -07:00
2013-03-04 11:45:57 +01:00
void SetFlag64 ( uint16 index , uint64 newFlag );
void RemoveFlag64 ( uint16 index , uint64 oldFlag );
void ToggleFlag64 ( uint16 index , uint64 flag );
bool HasFlag64 ( uint16 index , uint64 flag ) const ;
void ApplyModFlag64 ( uint16 index , uint64 flag , bool apply );
2009-10-17 15:51:44 -07:00
2008-10-02 16:23:55 -05:00
void ClearUpdateMask ( bool remove );
2009-10-17 15:51:44 -07:00
2008-10-02 16:23:55 -05:00
uint16 GetValuesCount () const { return m_valuesCount ; }
2009-10-17 15:51:44 -07:00
2008-10-02 16:23:55 -05:00
virtual bool hasQuest ( uint32 /* quest_id */ ) const { return false ; }
virtual bool hasInvolvedQuest ( uint32 /* quest_id */ ) const { return false ; }
2013-10-27 22:27:46 +01:00
virtual void BuildUpdate ( UpdateDataMapType & ) { }
2011-09-29 12:43:05 +02:00
void BuildFieldsUpdate ( Player * , UpdateDataMapType & ) const ;
2009-10-17 15:51:44 -07:00
2012-07-22 14:20:26 +02:00
void SetFieldNotifyFlag ( uint16 flag ) { _fieldNotifyFlags |= flag ; }
void RemoveFieldNotifyFlag ( uint16 flag ) { _fieldNotifyFlags &= ~ flag ; }
2009-01-15 21:29:32 -05:00
// FG: some hacky helpers
void ForceValuesUpdateAtIndex ( uint32 );
2009-10-17 15:51:44 -07:00
2012-02-29 12:43:59 +01:00
Player * ToPlayer () { if ( GetTypeId () == TYPEID_PLAYER ) return reinterpret_cast < Player *> ( this ); else return NULL ; }
2013-03-20 14:18:26 +01:00
Player const * ToPlayer () const { if ( GetTypeId () == TYPEID_PLAYER ) return reinterpret_cast < Player const *> ( this ); else return NULL ; }
2012-02-29 12:43:59 +01:00
Creature * ToCreature () { if ( GetTypeId () == TYPEID_UNIT ) return reinterpret_cast < Creature *> ( this ); else return NULL ; }
2013-03-20 14:18:26 +01:00
Creature const * ToCreature () const { if ( GetTypeId () == TYPEID_UNIT ) return reinterpret_cast < Creature const *> ( this ); else return NULL ; }
Unit * ToUnit () { if ( isType ( TYPEMASK_UNIT )) return reinterpret_cast < Unit *> ( this ); else return NULL ; }
Unit const * ToUnit () const { if ( isType ( TYPEMASK_UNIT )) return reinterpret_cast < Unit const *> ( this ); else return NULL ; }
2010-03-07 15:20:19 +01:00
2012-02-29 12:43:59 +01:00
GameObject * ToGameObject () { if ( GetTypeId () == TYPEID_GAMEOBJECT ) return reinterpret_cast < GameObject *> ( this ); else return NULL ; }
2013-03-20 14:18:26 +01:00
GameObject const * ToGameObject () const { if ( GetTypeId () == TYPEID_GAMEOBJECT ) return reinterpret_cast < GameObject const *> ( this ); else return NULL ; }
2011-08-26 12:05:47 +02:00
2012-02-29 12:43:59 +01:00
Corpse * ToCorpse () { if ( GetTypeId () == TYPEID_CORPSE ) return reinterpret_cast < Corpse *> ( this ); else return NULL ; }
2013-03-20 14:18:26 +01:00
Corpse const * ToCorpse () const { if ( GetTypeId () == TYPEID_CORPSE ) return reinterpret_cast < Corpse const *> ( this ); else return NULL ; }
2009-10-17 15:51:44 -07:00
2013-03-25 10:36:30 +01:00
DynamicObject * ToDynObject () { if ( GetTypeId () == TYPEID_DYNAMICOBJECT ) return reinterpret_cast < DynamicObject *> ( this ); else return NULL ; }
DynamicObject const * ToDynObject () const { if ( GetTypeId () == TYPEID_DYNAMICOBJECT ) return reinterpret_cast < DynamicObject const *> ( this ); else return NULL ; }
2013-03-20 14:18:26 +01:00
protected :
2012-03-29 13:42:04 +08:00
Object ();
2009-10-17 15:51:44 -07:00
2008-10-02 16:23:55 -05:00
void _InitValues ();
2012-07-22 14:20:26 +02:00
void _Create ( uint32 guidlow , uint32 entry , HighGuid guidhigh );
2011-04-11 14:39:00 +06:00
std :: string _ConcatFields ( uint16 startIndex , uint16 size ) const ;
2012-10-24 13:29:34 +02:00
void _LoadIntoDataField ( std :: string const & data , uint32 startOffset , uint32 count );
2009-10-17 15:51:44 -07:00
2013-02-03 12:16:10 +01:00
uint32 GetUpdateFieldData ( Player const * target , uint32 *& flags ) const ;
2009-10-17 15:51:44 -07:00
2013-06-15 15:16:36 +02:00
void BuildMovementUpdate ( ByteBuffer * data , uint16 flags ) const ;
virtual void BuildValuesUpdate ( uint8 updatetype , ByteBuffer * data , Player * target ) const ;
2009-10-17 15:51:44 -07:00
2008-10-02 16:23:55 -05:00
uint16 m_objectType ;
2009-10-17 15:51:44 -07:00
2009-08-06 10:38:46 -05:00
TypeID m_objectTypeId ;
2009-06-11 00:45:59 -05:00
uint16 m_updateFlag ;
2009-10-17 15:51:44 -07:00
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
};
2009-10-17 15:51:44 -07:00
2013-01-22 18:45:09 +01:00
UpdateMask _changesMask ;
2009-10-17 15:51:44 -07:00
2008-10-02 16:23:55 -05:00
uint16 m_valuesCount ;
2009-10-17 15:51:44 -07:00
2012-07-22 14:20:26 +02:00
uint16 _fieldNotifyFlags ;
2008-10-02 16:23:55 -05:00
bool m_objectUpdated ;
2009-10-17 15:51:44 -07:00
2008-10-02 16:23:55 -05:00
private :
bool m_inWorld ;
2009-10-17 15:51:44 -07:00
2008-10-02 16:23:55 -05:00
ByteBuffer m_PackGUID ;
2009-10-17 15:51:44 -07:00
2008-10-02 16:23:55 -05:00
// for output helpfull error messages from asserts
bool PrintIndexError ( uint32 index , bool set ) const ;
2014-04-29 16:35:11 +02:00
Object ( Object const & right ) = delete ;
Object & operator = ( Object const & right ) = delete ;
2008-10-02 16:23:55 -05:00
};
2009-10-17 15:51:44 -07:00
2010-02-05 00:31:28 +01:00
struct Position
2009-08-29 14:58:45 -05:00
{
2014-04-01 22:49:15 +02:00
Position ( float x = 0 , float y = 0 , float z = 0 , float o = 0 )
: m_positionX ( x ), m_positionY ( y ), m_positionZ ( z ), m_orientation ( NormalizeOrientation ( o )) { }
Position ( const Position & loc ) { Relocate ( loc ); }
2010-08-04 14:39:45 +02:00
struct PositionXYZStreamer
{
2013-10-27 22:27:46 +01:00
explicit PositionXYZStreamer ( Position & pos ) : m_pos ( & pos ) { }
2010-08-04 14:39:45 +02:00
Position * m_pos ;
};
struct PositionXYZOStreamer
{
2013-10-27 22:27:46 +01:00
explicit PositionXYZOStreamer ( Position & pos ) : m_pos ( & pos ) { }
2010-08-04 14:39:45 +02:00
Position * m_pos ;
};
2009-08-29 14:58:45 -05:00
float m_positionX ;
float m_positionY ;
float m_positionZ ;
2013-03-25 10:36:30 +01:00
// Better to limit access to m_orientation field, but this will be hard to achieve with many scripts using array initialization for this structure
//private:
2009-08-29 14:58:45 -05:00
float m_orientation ;
2013-03-25 10:36:30 +01:00
//public:
bool operator == ( Position const & a );
inline bool operator != ( Position const & a )
{
return ! ( operator == ( a ));
}
2009-10-17 15:51:44 -07:00
2009-08-29 14:58:45 -05:00
void Relocate ( float x , float y )
{ m_positionX = x ; m_positionY = y ;}
void Relocate ( float x , float y , float z )
{ m_positionX = x ; m_positionY = y ; m_positionZ = z ; }
void Relocate ( float x , float y , float z , float orientation )
2013-03-25 10:36:30 +01:00
{ m_positionX = x ; m_positionY = y ; m_positionZ = z ; SetOrientation ( orientation ); }
void Relocate ( Position const & pos )
{ m_positionX = pos . m_positionX ; m_positionY = pos . m_positionY ; m_positionZ = pos . m_positionZ ; SetOrientation ( pos . m_orientation ); }
void Relocate ( Position const * pos )
{ m_positionX = pos -> m_positionX ; m_positionY = pos -> m_positionY ; m_positionZ = pos -> m_positionZ ; SetOrientation ( pos -> m_orientation ); }
void RelocateOffset ( Position const & offset );
2009-08-29 14:58:45 -05:00
void SetOrientation ( float orientation )
2013-03-25 10:36:30 +01:00
{ m_orientation = NormalizeOrientation ( orientation ); }
2009-10-17 15:51:44 -07:00
2009-08-29 14:58:45 -05:00
float GetPositionX () const { return m_positionX ; }
float GetPositionY () const { return m_positionY ; }
float GetPositionZ () const { return m_positionZ ; }
float GetOrientation () const { return m_orientation ; }
2009-10-17 15:51:44 -07:00
2009-08-29 14:58:45 -05:00
void GetPosition ( float & x , float & y ) const
{ x = m_positionX ; y = m_positionY ; }
void GetPosition ( float & x , float & y , float & z ) const
{ x = m_positionX ; y = m_positionY ; z = m_positionZ ; }
void GetPosition ( float & x , float & y , float & z , float & o ) const
{ x = m_positionX ; y = m_positionY ; z = m_positionZ ; o = m_orientation ; }
2014-04-25 21:19:30 +02:00
Position GetPosition () const
2010-04-07 18:09:10 +02:00
{
2014-04-25 21:19:30 +02:00
return * this ;
2010-02-06 00:28:19 +01:00
}
2009-10-17 15:51:44 -07:00
2010-08-04 14:39:45 +02:00
Position :: PositionXYZStreamer PositionXYZStream ()
{
2011-09-01 22:38:32 +03:00
return PositionXYZStreamer ( * this );
2010-08-04 14:39:45 +02:00
}
Position :: PositionXYZOStreamer PositionXYZOStream ()
{
2011-09-01 22:38:32 +03:00
return PositionXYZOStreamer ( * this );
2010-08-04 14:39:45 +02:00
}
2009-08-29 14:58:45 -05:00
bool IsPositionValid () const ;
2009-10-17 15:51:44 -07:00
2009-08-29 14:58:45 -05:00
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
{ return sqrt ( GetExactDist2dSq ( x , y )); }
2013-03-25 10:36:30 +01:00
float GetExactDist2dSq ( Position const * pos ) const
2010-02-14 19:13:14 -07:00
{ float dx = m_positionX - pos -> m_positionX ; float dy = m_positionY - pos -> m_positionY ; return dx * dx + dy * dy ; }
2013-03-25 10:36:30 +01:00
float GetExactDist2d ( Position const * pos ) const
2010-02-14 19:13:14 -07:00
{ return sqrt ( GetExactDist2dSq ( pos )); }
2009-08-29 14:58:45 -05:00
float GetExactDistSq ( float x , float y , float z ) const
{ float dz = m_positionZ - z ; return GetExactDist2dSq ( x , y ) + dz * dz ; }
float GetExactDist ( float x , float y , float z ) const
{ return sqrt ( GetExactDistSq ( x , y , z )); }
2013-03-25 10:36:30 +01:00
float GetExactDistSq ( Position const * pos ) const
2010-02-14 19:13:14 -07:00
{ 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 ; }
2013-03-25 10:36:30 +01:00
float GetExactDist ( Position const * pos ) const
2010-02-14 19:13:14 -07:00
{ return sqrt ( GetExactDistSq ( pos )); }
2009-10-17 15:51:44 -07:00
2013-03-25 10:36:30 +01:00
void GetPositionOffsetTo ( Position const & endPos , Position & retOffset ) const ;
2010-08-08 20:32:14 +02:00
2013-03-25 10:36:30 +01:00
float GetAngle ( Position const * pos ) const ;
2009-08-29 14:58:45 -05:00
float GetAngle ( float x , float y ) const ;
2013-03-25 10:36:30 +01:00
float GetRelativeAngle ( Position const * pos ) const
2010-02-14 19:13:14 -07:00
{ return GetAngle ( pos ) - m_orientation ; }
2009-11-19 18:20:34 -08:00
float GetRelativeAngle ( float x , float y ) const { return GetAngle ( x , y ) - m_orientation ; }
2009-08-29 14:58:45 -05:00
void GetSinCos ( float x , float y , float & vsin , float & vcos ) const ;
2009-10-17 15:51:44 -07:00
2009-08-29 14:58:45 -05:00
bool IsInDist2d ( float x , float y , float dist ) const
{ return GetExactDist2dSq ( x , y ) < dist * dist ; }
2013-03-25 10:36:30 +01:00
bool IsInDist2d ( Position const * pos , float dist ) const
2010-02-14 19:13:14 -07:00
{ return GetExactDist2dSq ( pos ) < dist * dist ; }
2009-08-29 14:58:45 -05:00
bool IsInDist ( float x , float y , float z , float dist ) const
{ return GetExactDistSq ( x , y , z ) < dist * dist ; }
2013-03-25 10:36:30 +01:00
bool IsInDist ( Position const * pos , float dist ) const
2010-02-14 19:13:14 -07:00
{ return GetExactDistSq ( pos ) < dist * dist ; }
2013-03-25 10:36:30 +01:00
bool HasInArc ( float arcangle , Position const * pos , float border = 2.0f ) const ;
2012-02-21 20:03:27 +01:00
bool HasInLine ( WorldObject const * target , float width ) const ;
2010-08-08 20:32:14 +02:00
std :: string ToString () const ;
2013-03-25 10:36:30 +01:00
// modulos a radian orientation to the range of 0..2PI
static float NormalizeOrientation ( float o )
{
// fmod only supports positive numbers. Thus we have
// to emulate negative numbers
if ( o < 0 )
{
float mod = o *- 1 ;
mod = fmod ( mod , 2.0f * static_cast < float > ( M_PI ));
mod = - mod + 2.0f * static_cast < float > ( M_PI );
return mod ;
}
return fmod ( o , 2.0f * static_cast < float > ( M_PI ));
}
2009-08-29 14:58:45 -05:00
};
2011-08-28 17:36:02 +02:00
ByteBuffer & operator >> ( ByteBuffer & buf , Position :: PositionXYZOStreamer const & streamer );
ByteBuffer & operator << ( ByteBuffer & buf , Position :: PositionXYZStreamer const & streamer );
ByteBuffer & operator >> ( ByteBuffer & buf , Position :: PositionXYZStreamer const & streamer );
ByteBuffer & operator << ( ByteBuffer & buf , Position :: PositionXYZOStreamer const & streamer );
2010-08-04 14:39:45 +02:00
struct MovementInfo
{
// common
2013-03-25 10:36:30 +01:00
uint64 guid ;
uint32 flags ;
uint16 flags2 ;
2010-08-04 14:39:45 +02:00
Position pos ;
2013-03-25 10:36:30 +01:00
uint32 time ;
2013-06-18 18:15:33 +02:00
2010-08-04 14:39:45 +02:00
// transport
2013-06-18 18:15:33 +02:00
struct TransportInfo
{
void Reset ()
{
guid = 0 ;
pos . Relocate ( 0.0f , 0.0f , 0.0f , 0.0f );
seat = - 1 ;
time = 0 ;
time2 = 0 ;
}
uint64 guid ;
Position pos ;
int8 seat ;
uint32 time ;
uint32 time2 ;
} transport ;
2010-08-04 14:39:45 +02:00
// swimming/flying
2013-03-25 10:36:30 +01:00
float pitch ;
2013-06-18 18:15:33 +02:00
2010-08-04 14:39:45 +02:00
// falling
2013-03-25 10:36:30 +01:00
uint32 fallTime ;
2013-06-18 18:15:33 +02:00
// jumping
struct JumpInfo
{
void Reset ()
{
zspeed = sinAngle = cosAngle = xyspeed = 0.0f ;
}
float zspeed , sinAngle , cosAngle , xyspeed ;
} jump ;
2010-08-04 14:39:45 +02:00
// spline
2013-03-25 10:36:30 +01:00
float splineElevation ;
2010-08-04 14:39:45 +02:00
2013-03-25 10:36:30 +01:00
MovementInfo () :
2013-09-03 23:05:02 +02:00
guid ( 0 ), flags ( 0 ), flags2 ( 0 ), time ( 0 ), pitch ( 0.0f ), fallTime ( 0 ), splineElevation ( 0.0f )
2013-06-18 18:15:33 +02:00
{
pos . Relocate ( 0.0f , 0.0f , 0.0f , 0.0f );
transport . Reset ();
jump . Reset ();
}
2010-08-04 14:39:45 +02:00
2012-06-21 21:05:45 +03:00
uint32 GetMovementFlags () const { return flags ; }
2012-01-14 15:34:41 +01:00
void SetMovementFlags ( uint32 flag ) { flags = flag ; }
2010-08-04 14:39:45 +02:00
void AddMovementFlag ( uint32 flag ) { flags |= flag ; }
2012-01-14 15:34:41 +01:00
void RemoveMovementFlag ( uint32 flag ) { flags &= ~ flag ; }
2014-07-17 15:42:57 +02:00
bool HasMovementFlag ( uint32 flag ) const { return ( flags & flag ) != 0 ; }
2010-12-29 12:09:57 +01:00
2012-06-21 21:05:45 +03:00
uint16 GetExtraMovementFlags () const { return flags2 ; }
2011-01-06 22:54:33 +01:00
void AddExtraMovementFlag ( uint16 flag ) { flags2 |= flag ; }
2014-07-17 15:42:57 +02:00
bool HasExtraMovementFlag ( uint16 flag ) const { return ( flags2 & flag ) != 0 ; }
2010-12-29 12:09:57 +01:00
2012-03-17 20:34:03 +01:00
void SetFallTime ( uint32 time ) { fallTime = time ; }
2010-08-08 20:32:14 +02:00
void OutDebug ();
2010-08-04 14:39:45 +02:00
};
2009-10-17 15:51:44 -07:00
2009-08-29 23:20:16 -05:00
#define MAPID_INVALID 0xFFFFFFFF
2009-10-17 15:51:44 -07:00
2009-08-29 14:58:45 -05:00
class WorldLocation : public Position
2008-10-02 16:23:55 -05:00
{
public :
2009-08-29 23:20:16 -05:00
explicit WorldLocation ( uint32 _mapid = MAPID_INVALID , float _x = 0 , float _y = 0 , float _z = 0 , float _o = 0 )
2009-08-29 14:58:45 -05:00
: m_mapId ( _mapid ) { Relocate ( _x , _y , _z , _o ); }
2014-04-01 22:49:15 +02:00
WorldLocation ( const WorldLocation & loc ) : Position ( loc ) { WorldRelocate ( loc ); }
2009-10-17 15:51:44 -07:00
2009-08-29 23:20:16 -05:00
void WorldRelocate ( const WorldLocation & loc )
{ m_mapId = loc . GetMapId (); Relocate ( loc ); }
2014-04-25 21:19:30 +02:00
WorldLocation GetWorldLocation () const
{
return * this ;
}
2009-08-29 14:58:45 -05:00
uint32 GetMapId () const { return m_mapId ; }
2009-10-17 15:51:44 -07:00
2009-08-29 14:58:45 -05:00
uint32 m_mapId ;
};
2009-10-17 15:51:44 -07:00
2009-12-26 11:38:30 +01:00
template < class T >
class GridObject
{
public :
2014-04-20 16:48:35 +02:00
virtual ~ GridObject () { }
2011-11-10 17:31:45 -05:00
bool IsInGrid () const { return _gridRef . isValid (); }
void AddToGrid ( GridRefManager < T >& m ) { ASSERT ( ! IsInGrid ()); _gridRef . link ( & m , ( T * ) this ); }
void RemoveFromGrid () { ASSERT ( IsInGrid ()); _gridRef . unlink (); }
private :
GridReference < T > _gridRef ;
2009-12-26 11:38:30 +01:00
};
2010-11-13 17:18:09 +01:00
template < class T_VALUES , class T_FLAGS , class FLAG_TYPE , uint8 ARRAY_SIZE >
class FlaggedValuesArray32
{
public :
FlaggedValuesArray32 ()
{
memset ( & m_values , 0x00 , sizeof ( T_VALUES ) * ARRAY_SIZE );
m_flags = 0 ;
}
T_FLAGS GetFlags () const { return m_flags ; }
bool HasFlag ( FLAG_TYPE flag ) const { return m_flags & ( 1 << flag ); }
void AddFlag ( FLAG_TYPE flag ) { m_flags |= ( 1 << flag ); }
void DelFlag ( FLAG_TYPE flag ) { m_flags &= ~ ( 1 << flag ); }
T_VALUES GetValue ( FLAG_TYPE flag ) const { return m_values [ flag ]; }
void SetValue ( FLAG_TYPE flag , T_VALUES value ) { m_values [ flag ] = value ; }
void AddValue ( FLAG_TYPE flag , T_VALUES value ) { m_values [ flag ] += value ; }
private :
T_VALUES m_values [ ARRAY_SIZE ];
T_FLAGS m_flags ;
};
2013-10-16 18:37:29 +02:00
enum MapObjectCellMoveState
{
MAP_OBJECT_CELL_MOVE_NONE , //not in move list
MAP_OBJECT_CELL_MOVE_ACTIVE , //in move list
MAP_OBJECT_CELL_MOVE_INACTIVE , //in move list but should not move
};
class MapObject
{
friend class Map ; //map for moving creatures
friend class ObjectGridLoader ; //grid loader for loading creatures
protected :
2013-12-01 16:19:30 +01:00
MapObject () : _moveState ( MAP_OBJECT_CELL_MOVE_NONE )
2014-01-12 00:32:16 +00:00
{
2013-12-01 16:19:30 +01:00
_newPosition . Relocate ( 0.0f , 0.0f , 0.0f , 0.0f );
}
2013-10-16 18:37:29 +02:00
private :
Cell _currentCell ;
Cell const & GetCurrentCell () const { return _currentCell ; }
void SetCurrentCell ( Cell const & cell ) { _currentCell = cell ; }
MapObjectCellMoveState _moveState ;
Position _newPosition ;
void SetNewCellPosition ( float x , float y , float z , float o )
{
_moveState = MAP_OBJECT_CELL_MOVE_ACTIVE ;
_newPosition . Relocate ( x , y , z , o );
}
};
2010-02-05 00:31:28 +01:00
class WorldObject : public Object , public WorldLocation
2009-08-29 14:58:45 -05:00
{
2010-08-08 20:32:14 +02:00
protected :
2011-12-20 17:05:08 -05:00
explicit WorldObject ( bool isWorldObject ); //note: here it means if it is in grid object list or world object list
2009-08-29 14:58:45 -05:00
public :
virtual ~ WorldObject ();
2009-10-17 15:51:44 -07:00
2010-04-07 22:59:46 +02:00
virtual void Update ( uint32 /*time_diff*/ ) { }
2009-10-17 15:51:44 -07:00
2010-04-07 22:59:46 +02:00
void _Create ( uint32 guidlow , HighGuid guidhigh , uint32 phaseMask );
2014-08-09 20:17:40 +01:00
virtual void RemoveFromWorld () override ;
2010-11-16 21:17:49 +01:00
2010-04-07 22:59:46 +02:00
void GetNearPoint2D ( float & x , float & y , float distance , float absAngle ) const ;
2011-04-29 20:47:02 +02:00
void GetNearPoint ( WorldObject const * searcher , float & x , float & y , float & z , float searcher_size , float distance2d , float absAngle ) const ;
2013-03-04 11:45:57 +01:00
void GetClosePoint ( float & x , float & y , float & z , float size , float distance2d = 0 , float angle = 0 ) const ;
2009-08-29 23:20:16 -05:00
void MovePosition ( Position & pos , float dist , float angle );
2014-04-25 21:19:30 +02:00
Position GetNearPosition ( float dist , float angle );
2010-07-21 02:06:51 +02:00
void MovePositionToFirstCollision ( Position & pos , float dist , float angle );
2014-04-25 21:19:30 +02:00
Position GetFirstCollisionPosition ( float dist , float angle );
Position GetRandomNearPosition ( float radius );
2013-03-25 10:36:30 +01:00
void GetContactPoint ( WorldObject const * obj , float & x , float & y , float & z , float distance2d = CONTACT_DISTANCE ) const ;
2009-10-17 15:51:44 -07:00
2013-03-04 11:45:57 +01:00
float GetObjectSize () const ;
2008-10-02 16:23:55 -05:00
void UpdateGroundPositionZ ( float x , float y , float & z ) const ;
2012-01-14 15:34:41 +01:00
void UpdateAllowedPositionZ ( float x , float y , float & z ) const ;
2009-10-17 15:51:44 -07:00
2013-03-25 10:36:30 +01:00
void GetRandomPoint ( Position const & srcPos , float distance , float & rand_x , float & rand_y , float & rand_z ) const ;
2014-04-25 21:19:30 +02:00
Position GetRandomPoint ( Position const & srcPos , float distance ) const ;
2009-10-17 15:51:44 -07:00
2009-08-25 11:42:18 -05:00
uint32 GetInstanceId () const { return m_InstanceId ; }
2009-10-17 15:51:44 -07:00
2009-01-31 16:38:50 -06:00
virtual void SetPhaseMask ( uint32 newPhaseMask , bool update );
uint32 GetPhaseMask () const { return m_phaseMask ; }
2013-03-04 11:45:57 +01:00
bool InSamePhase ( WorldObject const * obj ) const ;
2014-07-17 15:42:57 +02:00
bool InSamePhase ( uint32 phasemask ) const { return ( GetPhaseMask () & phasemask ) != 0 ; }
2009-10-17 15:51:44 -07: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 ;
2009-10-17 15:51:44 -07:00
2010-08-08 22:54:58 +06:00
InstanceScript * GetInstanceScript ();
2009-10-17 15:51:44 -07:00
2012-10-24 13:29:34 +02:00
std :: string const & GetName () const { return m_name ; }
2012-10-24 15:34:23 +02:00
void SetName ( std :: string const & newname ) { m_name = newname ; }
2009-10-17 15:51:44 -07:00
2012-10-24 13:29:34 +02:00
virtual std :: string const & GetNameForLocaleIdx ( LocaleConstant /*locale_idx*/ ) const { return m_name ; }
2009-10-17 15:51:44 -07:00
2013-03-25 10:36:30 +01:00
float GetDistance ( WorldObject const * obj ) const ;
float GetDistance ( Position const & pos ) const ;
2013-03-04 11:45:57 +01:00
float GetDistance ( float x , float y , float z ) const ;
2013-03-25 10:36:30 +01:00
float GetDistance2d ( WorldObject const * obj ) const ;
2013-03-04 11:45:57 +01:00
float GetDistance2d ( float x , float y ) const ;
2013-03-25 10:36:30 +01:00
float GetDistanceZ ( WorldObject const * obj ) const ;
2009-10-17 15:51:44 -07:00
2013-03-25 10:36:30 +01:00
bool IsSelfOrInSameMap ( WorldObject const * obj ) const ;
bool IsInMap ( WorldObject const * obj ) const ;
2013-03-04 11:45:57 +01:00
bool IsWithinDist3d ( float x , float y , float z , float dist ) const ;
2013-03-25 10:36:30 +01:00
bool IsWithinDist3d ( Position const * pos , float dist ) const ;
2013-03-04 11:45:57 +01:00
bool IsWithinDist2d ( float x , float y , float dist ) const ;
2013-03-25 10:36:30 +01:00
bool IsWithinDist2d ( Position const * pos , float dist ) const ;
2010-02-06 00:28:19 +01:00
// use only if you will sure about placing both object at same map
2013-03-04 11:45:57 +01:00
bool IsWithinDist ( WorldObject const * obj , float dist2compare , bool is3D = true ) const ;
bool IsWithinDistInMap ( WorldObject const * obj , float dist2compare , bool is3D = true ) const ;
2009-05-14 16:50:47 -05:00
bool IsWithinLOS ( float x , float y , float z ) const ;
2013-03-25 10:36:30 +01:00
bool IsWithinLOSInMap ( WorldObject const * 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 ;
2012-02-21 20:03:27 +01:00
bool isInFront ( WorldObject const * target , float arc = M_PI ) const ;
bool isInBack ( WorldObject const * target , float arc = M_PI ) const ;
2009-10-17 15:51:44 -07:00
2013-03-25 10:36:30 +01:00
bool IsInBetween ( WorldObject const * obj1 , WorldObject const * obj2 , float size = 0 ) const ;
2009-10-17 15:51:44 -07:00
2010-01-22 20:03:47 +01:00
virtual void CleanupsBeforeDelete ( bool finalCleanup = true ); // used in destructor or explicitly before mass creature delete to remove cross-references to already deleted units
2009-10-17 15:51:44 -07:00
2011-09-15 14:08:17 +02:00
virtual void SendMessageToSet ( WorldPacket * data , bool self );
virtual void SendMessageToSetInRange ( WorldPacket * data , float dist , bool self );
virtual void SendMessageToSet ( WorldPacket * data , Player const * skipped_rcvr );
2009-10-17 15:51:44 -07:00
2010-11-13 17:18:09 +01:00
virtual uint8 getLevelForTarget ( WorldObject const * /*target*/ ) const { return 1 ; }
2013-12-23 14:23:49 +01:00
void MonsterSay ( const char * text , uint32 language , WorldObject const * target );
void MonsterYell ( const char * text , uint32 language , WorldObject const * target );
void MonsterTextEmote ( const char * text , WorldObject const * target , bool IsBossEmote = false );
void MonsterWhisper ( const char * text , Player const * target , bool IsBossWhisper = false );
void MonsterSay ( int32 textId , uint32 language , WorldObject const * target );
void MonsterYell ( int32 textId , uint32 language , WorldObject const * target );
void MonsterTextEmote ( int32 textId , WorldObject const * target , bool IsBossEmote = false );
void MonsterWhisper ( int32 textId , Player const * target , bool IsBossWhisper = false );
2009-10-17 15:51:44 -07:00
2009-03-22 19:20:03 -06:00
void PlayDistanceSound ( uint32 sound_id , Player * target = NULL );
void PlayDirectSound ( uint32 sound_id , Player * target = NULL );
2009-10-17 15:51:44 -07:00
2008-10-02 16:23:55 -05:00
void SendObjectDeSpawnAnim ( uint64 guid );
2009-10-17 15:51:44 -07:00
2013-10-27 22:27:46 +01:00
virtual void SaveRespawnTime () { }
2008-10-02 16:23:55 -05:00
void AddObjectToRemoveList ();
2009-10-17 15:51:44 -07:00
2010-11-13 17:18:09 +01:00
float GetGridActivationRange () const ;
float GetVisibilityRange () const ;
2013-03-25 10:36:30 +01:00
float GetSightRange ( WorldObject const * target = NULL ) const ;
2013-06-11 21:25:12 -02:30
bool CanSeeOrDetect ( WorldObject const * obj , bool ignoreStealth = false , bool distanceCheck = false ) const ;
2010-11-13 17:18:09 +01:00
FlaggedValuesArray32 < int32 , uint32 , StealthType , TOTAL_STEALTH_TYPES > m_stealth ;
FlaggedValuesArray32 < int32 , uint32 , StealthType , TOTAL_STEALTH_TYPES > m_stealthDetect ;
FlaggedValuesArray32 < int32 , uint32 , InvisibilityType , TOTAL_INVISIBILITY_TYPES > m_invisibility ;
FlaggedValuesArray32 < int32 , uint32 , InvisibilityType , TOTAL_INVISIBILITY_TYPES > m_invisibilityDetect ;
2009-10-17 15:51:44 -07:00
2010-11-13 17:18:09 +01:00
FlaggedValuesArray32 < int32 , uint32 , ServerSideVisibilityType , TOTAL_SERVERSIDE_VISIBILITY_TYPES > m_serverSideVisibility ;
FlaggedValuesArray32 < int32 , uint32 , ServerSideVisibilityType , TOTAL_SERVERSIDE_VISIBILITY_TYPES > m_serverSideVisibilityDetect ;
2009-10-17 15:51:44 -07:00
2008-10-05 11:38:24 -05:00
// Low Level Packets
void SendPlaySound ( uint32 Sound , bool OnlySelf );
2009-10-17 15:51:44 -07:00
2011-09-15 14:08:17 +02:00
virtual void SetMap ( Map * map );
2009-08-10 23:47:47 -05:00
virtual void ResetMap ();
2011-09-15 14:08:17 +02:00
Map * GetMap () const { ASSERT ( m_currMap ); return m_currMap ; }
Map * FindMap () const { return m_currMap ; }
2009-07-16 11:49:00 +08:00
//used to check all object's GetMap() calls when object is not in world!
2009-10-17 15:51:44 -07:00
2009-07-16 11:49:00 +08:00
//this function should be removed in nearest time...
2008-10-02 16:23:55 -05:00
Map const * GetBaseMap () const ;
2009-10-17 15:51:44 -07:00
2009-05-30 22:15:05 -05:00
void SetZoneScript ();
2011-09-15 14:08:17 +02:00
ZoneScript * GetZoneScript () const { return m_zoneScript ; }
2009-10-17 15:51:44 -07:00
2013-03-25 10:36:30 +01:00
TempSummon * SummonCreature ( uint32 id , Position const & pos , TempSummonType spwtype = TEMPSUMMON_MANUAL_DESPAWN , uint32 despwtime = 0 , uint32 vehId = 0 ) const ;
2013-03-04 11:45:57 +01:00
TempSummon * SummonCreature ( uint32 id , float x , float y , float z , float ang = 0 , TempSummonType spwtype = TEMPSUMMON_MANUAL_DESPAWN , uint32 despwtime = 0 ) const ;
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 );
2013-02-26 02:33:08 +01:00
void SummonCreatureGroup ( uint8 group , std :: list < TempSummon *>* list = NULL );
2009-10-17 15:51:44 -07:00
2011-08-30 13:46:36 +02:00
Creature * FindNearestCreature ( uint32 entry , float range , bool alive = true ) const ;
GameObject * FindNearestGameObject ( uint32 entry , float range ) const ;
2012-09-08 23:15:29 +01:00
GameObject * FindNearestGameObjectOfType ( GameobjectTypes type , float range ) const ;
2009-10-17 15:51:44 -07:00
2011-08-30 13:46:36 +02:00
void GetGameObjectListWithEntryInGrid ( std :: list < GameObject *>& lList , uint32 uiEntry , float fMaxSearchRange ) const ;
void GetCreatureListWithEntryInGrid ( std :: list < Creature *>& lList , uint32 uiEntry , float fMaxSearchRange ) const ;
2009-10-17 15:51:44 -07:00
2009-08-28 14:19:14 -05:00
void DestroyForNearbyPlayers ();
2010-02-27 15:25:14 +02:00
virtual void UpdateObjectVisibility ( bool forced = true );
2014-08-09 20:17:40 +01:00
void BuildUpdate ( UpdateDataMapType & ) override ;
2009-10-17 15:51:44 -07:00
2010-02-27 15:25:14 +02:00
//relocation and visibility system functions
2009-12-19 10:12:40 +01:00
void AddToNotify ( uint16 f ) { m_notifyflags |= f ;}
2014-07-17 15:42:57 +02:00
bool isNeedNotify ( uint16 f ) const { return ( m_notifyflags & f ) != 0 ; }
2010-02-27 15:25:14 +02:00
uint16 GetNotifyFlags () const { return m_notifyflags ; }
2014-07-17 15:42:57 +02:00
bool NotifyExecuted ( uint16 f ) const { return ( m_executed_notifies & f ) != 0 ; }
2009-12-19 10:12:40 +01:00
void SetNotified ( uint16 f ) { m_executed_notifies |= f ;}
void ResetAllNotifies () { m_notifyflags = 0 ; m_executed_notifies = 0 ; }
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 );
2011-12-20 17:05:08 -05:00
bool IsPermanentWorldObject () const { return m_isWorldObject ; }
bool IsWorldObject () const ;
2011-10-19 17:40:44 +01:00
template < class NOTIFIER > void VisitNearbyObject ( float const & radius , NOTIFIER & notifier ) const { if ( IsInWorld ()) GetMap () -> VisitAll ( GetPositionX (), GetPositionY (), radius , notifier ); }
template < class NOTIFIER > void VisitNearbyGridObject ( float const & radius , NOTIFIER & notifier ) const { if ( IsInWorld ()) GetMap () -> VisitGrid ( GetPositionX (), GetPositionY (), radius , notifier ); }
template < class NOTIFIER > void VisitNearbyWorldObject ( float const & radius , NOTIFIER & notifier ) const { if ( IsInWorld ()) GetMap () -> VisitWorld ( GetPositionX (), GetPositionY (), radius , notifier ); }
2009-10-17 15:51:44 -07:00
2009-05-25 12:05:23 -05:00
#ifdef MAP_BASED_RAND_GEN
2009-08-03 16:35:33 +02:00
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 ;}
int32 rand32 () const { return GetMap () -> mtRand . randInt ();}
double rand_norm () const { return GetMap () -> mtRand . randExc ();}
double rand_chance () const { return GetMap () -> mtRand . randExc ( 100.0 );}
2009-05-25 12:05:23 -05:00
#endif
2009-10-17 15:51:44 -07:00
2010-05-16 17:45:45 +02:00
uint32 LastUsedScriptID ;
2010-07-30 21:54:46 -07:00
// Transports
2011-09-15 14:08:17 +02:00
Transport * GetTransport () const { return m_transport ; }
2013-10-16 18:37:29 +02:00
float GetTransOffsetX () const { return m_movementInfo . transport . pos . GetPositionX (); }
float GetTransOffsetY () const { return m_movementInfo . transport . pos . GetPositionY (); }
float GetTransOffsetZ () const { return m_movementInfo . transport . pos . GetPositionZ (); }
float GetTransOffsetO () const { return m_movementInfo . transport . pos . GetOrientation (); }
uint32 GetTransTime () const { return m_movementInfo . transport . time ; }
int8 GetTransSeat () const { return m_movementInfo . transport . seat ; }
2010-08-08 20:32:14 +02:00
virtual uint64 GetTransGUID () const ;
2011-09-15 14:08:17 +02:00
void SetTransport ( Transport * t ) { m_transport = t ; }
2010-07-30 21:54:46 -07:00
MovementInfo m_movementInfo ;
2013-10-16 18:37:29 +02:00
virtual float GetStationaryX () const { return GetPositionX (); }
virtual float GetStationaryY () const { return GetPositionY (); }
virtual float GetStationaryZ () const { return GetPositionZ (); }
virtual float GetStationaryO () const { return GetOrientation (); }
2008-10-02 16:23:55 -05:00
protected :
std :: string m_name ;
2008-10-27 08:41:55 -05:00
bool m_isActive ;
2011-12-20 17:05:08 -05:00
const bool m_isWorldObject ;
2011-09-15 14:08:17 +02:00
ZoneScript * m_zoneScript ;
2009-10-17 15:51:44 -07:00
2010-07-30 21:54:46 -07:00
// transports
2011-09-15 14:08:17 +02:00
Transport * m_transport ;
2010-07-30 21:54:46 -07:00
2009-08-25 11:42:18 -05: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 ; }
2009-10-17 15:51:44 -07:00
2011-10-13 14:02:07 -04:00
virtual bool IsNeverVisible () const { return ! IsInWorld (); }
2011-10-13 17:01:55 -04:00
virtual bool IsAlwaysVisibleFor ( WorldObject const * /*seer*/ ) const { return false ; }
virtual bool IsInvisibleDueToDespawn () const { return false ; }
//difference from IsAlwaysVisibleFor: 1. after distance check; 2. use owner or charmer as seer
virtual bool IsAlwaysDetectableFor ( WorldObject const * /*seer*/ ) const { return false ; }
2008-10-02 16:23:55 -05:00
private :
2011-09-15 14:08:17 +02:00
Map * m_currMap ; //current object's Map location
2009-10-17 15:51:44 -07:00
2009-08-29 14:58:45 -05:00
//uint32 m_mapId; // object at map with map_id
2009-08-25 11:42:18 -05:00
uint32 m_InstanceId ; // in map copy with instance id
2009-01-31 16:38:50 -06:00
uint32 m_phaseMask ; // in area phase state
2009-12-19 10:12:40 +01:00
uint16 m_notifyflags ;
uint16 m_executed_notifies ;
2011-10-13 14:02:07 -04:00
virtual bool _IsWithinDist ( WorldObject const * obj , float dist2compare , bool is3D ) const ;
2013-03-04 11:45:57 +01:00
bool CanNeverSee ( WorldObject const * obj ) const ;
2011-10-13 17:01:55 -04:00
virtual bool CanAlwaysSee ( WorldObject const * /*obj*/ ) const { return false ; }
bool CanDetect ( WorldObject const * obj , bool ignoreStealth ) const ;
bool CanDetectInvisibilityOf ( WorldObject const * obj ) const ;
bool CanDetectStealthOf ( WorldObject const * obj ) const ;
2008-10-02 16:23:55 -05:00
};
2010-05-30 04:23:27 +02:00
namespace Trinity
{
// Binary predicate to sort WorldObjects based on the distance to a reference WorldObject
class ObjectDistanceOrderPred
{
public :
2014-08-14 16:09:14 +02:00
ObjectDistanceOrderPred ( WorldObject const * refObj , bool ascending = true ) : _refObj ( refObj ), _ascending ( ascending ) { }
bool operator ()( WorldObject const * left , WorldObject const * right ) const
2010-05-30 04:23:27 +02:00
{
2014-08-14 16:09:14 +02:00
return _refObj -> GetDistanceOrder ( left , right ) == _ascending ;
2010-05-30 04:23:27 +02:00
}
2014-08-14 16:09:14 +02:00
2010-05-30 04:23:27 +02:00
private :
2014-08-14 16:09:14 +02:00
WorldObject const * _refObj ;
bool _ascending ;
2010-05-30 04:23:27 +02:00
};
}
2008-10-02 16:23:55 -05:00
#endif