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
*
2010-01-16 20:19:18 +03:00
* Copyright (C) 2008-2010 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
*/
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"
2010-06-08 13:05:47 -06:00
#include "UpdateFields.h"
#include "UpdateData.h"
#include "GridReference.h"
2008-10-02 16:23:55 -05:00
#include "ObjectDefines.h"
2010-06-08 13:05:47 -06:00
#include "GridDefines.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
2009-09-27 02:24:25 -07:00
#define MAX_VISIBILITY_DISTANCE 333.0f // max distance for visible object show, limited in 333 yards
#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
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
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
};
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
};
2008-10-02 16:23:55 -05:00
class WorldPacket ;
class UpdateData ;
class ByteBuffer ;
class WorldSession ;
class Creature ;
class Player ;
class UpdateMask ;
2010-08-08 22:54:58 +06:00
class InstanceScript ;
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 ;
2009-08-29 14:58:45 -05:00
class Unit ;
2010-07-30 21:54:46 -07:00
class Transport ;
2010-08-04 14:39:45 +02:00
typedef 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 :
2010-04-07 22:59:46 +02:00
virtual ~ Object ();
2009-10-17 15:51:44 -07:00
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 ()
{
2010-04-07 19:14:10 +02:00
if ( m_inWorld )
2008-10-02 16:23:55 -05:00
return ;
2009-10-17 15:51:44 -07:00
2010-07-30 20:04:28 +02:00
ASSERT ( m_uint32Values );
2009-10-17 15:51:44 -07:00
2008-10-02 16:23:55 -05:00
m_inWorld = true ;
2009-10-17 15:51:44 -07:00
2008-10-02 16:23:55 -05:00
// synchronize values mirror with values array (changes will send in updatecreate opcode any way
ClearUpdateMask ( true );
}
virtual void RemoveFromWorld ()
{
2010-04-07 19:14:10 +02:00
if ( ! m_inWorld )
2009-03-25 15:54:23 -06:00
return ;
2009-10-17 15:51:44 -07:00
2008-10-02 16:23:55 -05:00
m_inWorld = false ;
2009-10-17 15:51:44 -07:00
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
}
2009-10-17 15:51:44 -07:00
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 ); }
2009-10-17 15:51:44 -07:00
2009-08-06 10:38:46 -05:00
TypeID GetTypeId () const { return m_objectTypeId ; }
2008-10-02 16:23:55 -05:00
bool isType ( uint16 mask ) const { return ( mask & m_objectType ); }
2009-10-17 15:51:44 -07:00
2010-04-07 22:59:46 +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
2010-04-07 22:59:46 +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
2010-04-07 22:59:46 +02:00
virtual void DestroyForPlayer ( Player * target , bool anim = false ) const ;
2009-10-17 15:51:44 -07:00
2010-04-07 22:59:46 +02:00
const int32 & GetInt32Value ( uint16 index ) const
2008-10-02 16:23:55 -05:00
{
2010-04-07 22:59:46 +02:00
ASSERT ( index < m_valuesCount || PrintIndexError ( index , false ));
2008-10-02 16:23:55 -05:00
return m_int32Values [ index ];
}
2009-10-17 15:51:44 -07:00
2010-04-07 22:59:46 +02:00
const uint32 & GetUInt32Value ( uint16 index ) const
2008-10-02 16:23:55 -05:00
{
2010-04-07 22:59:46 +02:00
ASSERT ( index < m_valuesCount || PrintIndexError ( index , false ));
2008-10-02 16:23:55 -05:00
return m_uint32Values [ index ];
}
2009-10-17 15:51:44 -07:00
2010-04-07 22:59:46 +02:00
const uint64 & GetUInt64Value ( uint16 index ) const
2008-10-02 16:23:55 -05:00
{
2010-04-07 22:59:46 +02:00
ASSERT ( index + 1 < m_valuesCount || PrintIndexError ( index , false ));
2008-10-02 16:23:55 -05:00
return * (( uint64 * ) & ( m_uint32Values [ index ]));
}
2009-10-17 15:51:44 -07:00
2010-04-07 22:59:46 +02:00
const float & GetFloatValue ( uint16 index ) const
2008-10-02 16:23:55 -05:00
{
2010-04-07 22:59:46 +02:00
ASSERT ( index < m_valuesCount || PrintIndexError ( index , false ));
2008-10-02 16:23:55 -05:00
return m_floatValues [ index ];
}
2009-10-17 15:51:44 -07:00
2010-04-07 22:59:46 +02:00
uint8 GetByteValue ( uint16 index , uint8 offset ) const
2008-10-02 16:23:55 -05:00
{
2010-04-07 22:59:46 +02:00
ASSERT ( index < m_valuesCount || PrintIndexError ( index , false ));
ASSERT ( offset < 4 );
2008-10-02 16:23:55 -05:00
return * ((( uint8 * ) & m_uint32Values [ index ]) + offset );
}
2009-10-17 15:51:44 -07:00
2010-04-07 22:59:46 +02:00
uint16 GetUInt16Value ( uint16 index , uint8 offset ) const
2008-10-02 16:23:55 -05:00
{
2010-04-07 22:59:46 +02:00
ASSERT ( index < m_valuesCount || PrintIndexError ( index , false ));
ASSERT ( offset < 2 );
2008-10-02 16:23:55 -05:00
return * ((( uint16 * ) & m_uint32Values [ index ]) + offset );
}
2009-10-17 15:51:44 -07:00
2010-04-07 22:59:46 +02:00
void SetInt32Value ( uint16 index , int32 value );
void SetUInt32Value ( uint16 index , uint32 value );
void UpdateUInt32Value ( 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-10-17 15:51:44 -07:00
2010-04-07 22:59:46 +02:00
bool AddUInt64Value ( uint16 index , const uint64 & value );
bool RemoveUInt64Value ( uint16 index , const 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 );
2009-10-17 15:51:44 -07:00
2008-10-02 16:23:55 -05:00
void ApplyPercentModFloatValue ( uint16 index , float val , bool apply )
{
val = val != - 100.0f ? val : - 99.9f ;
2010-04-07 22:59:46 +02:00
SetFloatValue ( index , GetFloatValue ( index ) * ( apply ? ( 100.0f + val ) / 100.0f : 100.0f / ( 100.0f + val )));
2008-10-02 16:23:55 -05:00
}
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 );
2009-10-17 15:51:44 -07:00
2010-04-07 22:59:46 +02:00
void ToggleFlag ( uint16 index , uint32 flag )
2008-10-02 16:23:55 -05:00
{
2010-04-07 19:14:10 +02:00
if ( HasFlag ( index , flag ))
2008-10-02 16:23:55 -05:00
RemoveFlag ( index , flag );
else
SetFlag ( index , flag );
}
2009-10-17 15:51:44 -07:00
2010-04-07 22:59:46 +02:00
bool HasFlag ( uint16 index , uint32 flag ) const
2008-10-02 16:23:55 -05:00
{
2010-04-07 22:59:46 +02:00
if ( index >= m_valuesCount && ! PrintIndexError ( index , false )) return false ;
2008-10-02 16:23:55 -05:00
return ( m_uint32Values [ index ] & flag ) != 0 ;
}
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 );
2009-10-17 15:51:44 -07:00
2010-04-07 22:59:46 +02:00
void ToggleFlag ( uint16 index , uint8 offset , uint8 flag )
2008-12-12 11:21:28 -06:00
{
2010-04-07 19:14:10 +02:00
if ( HasByteFlag ( index , offset , flag ))
2008-12-12 11:21:28 -06:00
RemoveByteFlag ( index , offset , flag );
else
SetByteFlag ( index , offset , flag );
}
2009-10-17 15:51:44 -07:00
2010-04-07 22:59:46 +02:00
bool HasByteFlag ( uint16 index , uint8 offset , uint8 flag ) const
2008-12-12 11:21:28 -06:00
{
2010-04-07 22:59:46 +02:00
ASSERT ( index < m_valuesCount || PrintIndexError ( index , false ));
ASSERT ( offset < 4 );
2008-12-12 11:21:28 -06:00
return ((( uint8 * ) & m_uint32Values [ index ])[ offset ] & flag ) != 0 ;
}
2009-10-17 15:51:44 -07:00
2010-04-07 22:59:46 +02:00
void ApplyModFlag ( uint16 index , uint32 flag , bool apply )
2008-10-02 16:23:55 -05:00
{
2010-04-07 19:14:10 +02:00
if ( apply ) SetFlag ( index , flag ); else RemoveFlag ( index , flag );
2008-10-02 16:23:55 -05:00
}
2009-10-17 15:51:44 -07:00
2010-04-07 22:59:46 +02:00
void SetFlag64 ( uint16 index , uint64 newFlag )
2008-10-02 16:23:55 -05:00
{
uint64 oldval = GetUInt64Value ( index );
uint64 newval = oldval | newFlag ;
SetUInt64Value ( index , newval );
}
2009-10-17 15:51:44 -07:00
2010-04-07 22:59:46 +02:00
void RemoveFlag64 ( uint16 index , uint64 oldFlag )
2008-10-02 16:23:55 -05:00
{
uint64 oldval = GetUInt64Value ( index );
uint64 newval = oldval & ~ oldFlag ;
SetUInt64Value ( index , newval );
}
2009-10-17 15:51:44 -07:00
2010-04-07 22:59:46 +02:00
void ToggleFlag64 ( uint16 index , uint64 flag )
2008-10-02 16:23:55 -05:00
{
2010-04-07 19:14:10 +02:00
if ( HasFlag64 ( index , flag ))
2008-10-02 16:23:55 -05:00
RemoveFlag64 ( index , flag );
else
SetFlag64 ( index , flag );
}
2009-10-17 15:51:44 -07:00
2010-04-07 22:59:46 +02:00
bool HasFlag64 ( uint16 index , uint64 flag ) const
2008-10-02 16:23:55 -05:00
{
2010-04-07 22:59:46 +02:00
ASSERT ( index < m_valuesCount || PrintIndexError ( index , false ));
return ( GetUInt64Value ( index ) & flag ) != 0 ;
2008-10-02 16:23:55 -05:00
}
2009-10-17 15:51:44 -07:00
2010-04-07 22:59:46 +02:00
void ApplyModFlag64 ( uint16 index , uint64 flag , bool apply )
2008-10-02 16:23:55 -05:00
{
2010-04-07 19:14:10 +02:00
if ( apply ) SetFlag64 ( index , flag ); else RemoveFlag64 ( index , flag );
2008-10-02 16:23:55 -05:00
}
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
bool LoadValues ( const char * data );
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 ; }
2010-04-07 22:59:46 +02:00
virtual void BuildUpdate ( UpdateDataMapType & ) {}
2010-02-03 16:53:40 +02:00
void BuildFieldsUpdate ( Player * , UpdateDataMapType & ) const ;
2009-10-17 15:51:44 -07:00
2009-01-15 21:29:32 -05:00
// FG: some hacky helpers
void ForceValuesUpdateAtIndex ( uint32 );
2009-10-17 15:51:44 -07:00
2010-08-06 03:00:39 +02:00
Player * ToPlayer (){ if ( GetTypeId () == TYPEID_PLAYER ) return reinterpret_cast < Player *> ( this ); else return NULL ; }
const Player * ToPlayer () const { if ( GetTypeId () == TYPEID_PLAYER ) return ( const Player * )(( Player * ) this ); else return NULL ; }
Creature * ToCreature (){ if ( GetTypeId () == TYPEID_UNIT ) return reinterpret_cast < Creature *> ( this ); else return NULL ; }
const Creature * ToCreature () const { if ( GetTypeId () == TYPEID_UNIT ) return ( const Creature * )(( Creature * ) this ); else return NULL ; }
2010-03-07 15:20:19 +01:00
2008-10-02 16:23:55 -05:00
protected :
2009-10-17 15:51:44 -07:00
2010-04-07 22:59:46 +02:00
Object ();
2009-10-17 15:51:44 -07:00
2008-10-02 16:23:55 -05:00
void _InitValues ();
void _Create ( uint32 guidlow , uint32 entry , HighGuid guidhigh );
2010-07-30 13:15:31 +02:00
void _LoadIntoDataField ( const char * data , uint32 startOffset , uint32 count );
2009-10-17 15:51:44 -07:00
2008-10-02 16:23:55 -05:00
virtual void _SetUpdateBits ( UpdateMask * updateMask , Player * target ) const ;
2009-10-17 15:51:44 -07:00
2008-10-02 16:23:55 -05:00
virtual void _SetCreateBits ( UpdateMask * updateMask , Player * target ) const ;
2009-06-11 00:45:59 -05:00
void _BuildMovementUpdate ( ByteBuffer * data , uint16 flags ) const ;
2010-04-07 22:59:46 +02:00
void _BuildValuesUpdate ( uint8 updatetype , ByteBuffer * data , UpdateMask * updateMask , 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
2008-10-02 16:23:55 -05:00
uint32 * m_uint32Values_mirror ;
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
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 ;
Object ( const Object & ); // prevent generation copy constructor
Object & operator = ( Object const & ); // prevent generation assigment operator
};
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
{
2010-08-04 14:39:45 +02:00
struct PositionXYZStreamer
{
explicit PositionXYZStreamer ( Position & pos ) : m_pos ( & pos ) {}
Position * m_pos ;
};
struct PositionXYZOStreamer
{
explicit PositionXYZOStreamer ( Position & pos ) : m_pos ( & pos ) {}
Position * m_pos ;
};
2009-08-29 14:58:45 -05:00
float m_positionX ;
float m_positionY ;
float m_positionZ ;
float m_orientation ;
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 )
{ m_positionX = x ; m_positionY = y ; m_positionZ = z ; m_orientation = orientation ; }
void Relocate ( const Position & pos )
{ m_positionX = pos . m_positionX ; m_positionY = pos . m_positionY ; m_positionZ = pos . m_positionZ ; m_orientation = pos . m_orientation ; }
void Relocate ( const Position * pos )
2010-02-14 19:13:14 -07:00
{ m_positionX = pos -> m_positionX ; m_positionY = pos -> m_positionY ; m_positionZ = pos -> m_positionZ ; m_orientation = pos -> m_orientation ; }
2010-08-08 20:32:14 +02:00
void RelocateOffset ( const Position & offset );
2009-08-29 14:58:45 -05:00
void SetOrientation ( float orientation )
{ m_orientation = 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 ; }
void GetPosition ( Position * pos ) const
2010-04-07 18:09:10 +02:00
{
if ( pos )
pos -> Relocate ( m_positionX , m_positionY , m_positionZ , m_orientation );
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 ()
{
2010-08-08 19:45:53 +02:00
return Position :: PositionXYZStreamer ( * this );
2010-08-04 14:39:45 +02:00
}
Position :: PositionXYZOStreamer PositionXYZOStream ()
{
2010-08-08 19:45:53 +02:00
return Position :: 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 )); }
float GetExactDist2dSq ( const Position * 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 ; }
2009-08-29 14:58:45 -05:00
float GetExactDist2d ( const Position * 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 )); }
float GetExactDistSq ( const Position * 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 ; }
2009-08-29 14:58:45 -05:00
float GetExactDist ( const Position * pos ) const
2010-02-14 19:13:14 -07:00
{ return sqrt ( GetExactDistSq ( pos )); }
2009-10-17 15:51:44 -07:00
2010-08-08 20:32:14 +02:00
void GetPositionOffsetTo ( const Position & endPos , Position & retOffset ) const ;
2009-08-29 14:58:45 -05:00
float GetAngle ( const Position * pos ) const ;
float GetAngle ( float x , float y ) const ;
2010-04-07 18:09:10 +02:00
float GetRelativeAngle ( const Position * 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 ; }
bool IsInDist2d ( const Position * 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 ; }
bool IsInDist ( const Position * pos , float dist ) const
2010-02-14 19:13:14 -07:00
{ return GetExactDistSq ( pos ) < dist * dist ; }
2009-08-29 14:58:45 -05:00
bool HasInArc ( float arcangle , const Position * pos ) const ;
2009-08-29 23:20:16 -05:00
bool HasInLine ( const Unit * target , float distance , float width ) const ;
2010-08-08 20:32:14 +02:00
std :: string ToString () const ;
2009-08-29 14:58:45 -05:00
};
2010-08-04 14:39:45 +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 );
struct MovementInfo
{
// common
uint64 guid ;
uint32 flags ;
uint16 flags2 ;
Position pos ;
uint32 time ;
// transport
uint64 t_guid ;
Position t_pos ;
uint32 t_time ;
uint32 t_time2 ;
int8 t_seat ;
// swimming/flying
float pitch ;
// falling
uint32 fallTime ;
// jumping
float j_zspeed , j_sinAngle , j_cosAngle , j_xyspeed ;
// spline
float splineElevation ;
MovementInfo ()
{
2010-08-04 19:16:44 +02:00
pos . Relocate ( 0 , 0 , 0 , 0 );
2010-08-04 14:39:45 +02:00
guid = 0 ;
flags = 0 ;
flags2 = 0 ;
2010-08-04 19:16:44 +02:00
time = t_time = t_time2 = fallTime = 0 ;
2010-08-04 14:39:45 +02:00
splineElevation = 0 ;
pitch = j_zspeed = j_sinAngle = j_cosAngle = j_xyspeed = 0.0f ;
t_guid = 0 ;
2010-08-04 19:16:44 +02:00
t_pos . Relocate ( 0 , 0 , 0 , 0 );
2010-08-04 14:39:45 +02:00
t_seat = - 1 ;
}
uint32 GetMovementFlags () { return flags ; }
void AddMovementFlag ( uint32 flag ) { flags |= flag ; }
bool HasMovementFlag ( uint32 flag ) const { return flags & flag ; }
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 ); }
2009-08-29 23:20:16 -05:00
WorldLocation ( const WorldLocation & 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 ); }
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 :
GridReference < T > & GetGridRef () { return m_gridRef ; }
protected :
GridReference < T > m_gridRef ;
};
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 :
explicit WorldObject ();
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 );
2009-10-17 15:51:44 -07:00
2010-04-07 22:59:46 +02:00
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 ;
2008-10-02 16:23:55 -05:00
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-08-29 23:20:16 -05:00
void MovePosition ( Position & pos , float dist , float angle );
void GetNearPosition ( Position & pos , float dist , float angle )
{
GetPosition ( & pos );
MovePosition ( pos , dist , angle );
}
2010-07-21 02:06:51 +02:00
void MovePositionToFirstCollision ( Position & pos , float dist , float angle );
void GetFirstCollisionPosition ( Position & pos , float dist , float angle )
{
GetPosition ( & pos );
MovePositionToFirstCollision ( pos , dist , angle );
}
2009-08-29 23:20:16 -05:00
void GetRandomNearPosition ( Position & pos , float radius )
2009-01-08 14:22:15 -06:00
{
2009-08-29 23:20:16 -05:00
GetPosition ( & pos );
2010-08-22 12:39:39 -07:00
MovePosition ( pos , radius * ( float ) rand_norm (), ( float ) rand_norm () * static_cast < float > ( 2 * M_PI ));
2009-01-08 14:22:15 -06:00
}
2009-10-17 15:51:44 -07:00
2010-04-07 22:59:46 +02:00
void GetContactPoint ( const WorldObject * obj , float & x , float & y , float & z , float distance2d = CONTACT_DISTANCE ) const
2008-10-02 16:23:55 -05:00
{
// angle to face `obj` to `this` using distance includes size of `obj`
2010-04-07 22:59:46 +02:00
GetNearPoint ( obj , x , y , z , obj -> GetObjectSize (), distance2d , GetAngle ( obj ));
2008-10-02 16:23:55 -05:00
}
2009-10-17 15:51:44 -07:00
2008-10-02 16:23:55 -05:00
float GetObjectSize () const
{
2010-04-07 22:59:46 +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
}
void UpdateGroundPositionZ ( float x , float y , float & z ) const ;
2009-10-17 15:51:44 -07:00
2009-08-29 23:20:16 -05:00
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
{
float x , y , z ;
GetRandomPoint ( srcPos , distance , x , y , z );
pos . Relocate ( x , y , z , GetOrientation ());
}
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 ; }
2010-02-14 19:13:14 -07:00
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-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
2008-10-02 16:23:55 -05:00
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 ; }
2009-10-17 15:51:44 -07:00
2008-11-14 17:03:03 -06:00
virtual const char * GetNameForLocaleIdx ( int32 /*locale_idx*/ ) const { return GetName (); }
2009-10-17 15:51:44 -07:00
2009-08-29 23:20:16 -05:00
float GetDistance ( const WorldObject * obj ) const
2010-04-07 18:09:10 +02:00
{
2010-02-06 00:28:19 +01:00
float d = GetExactDist ( obj ) - GetObjectSize () - obj -> GetObjectSize ();
return d > 0.0f ? d : 0.0f ;
}
2009-08-29 23:20:16 -05:00
float GetDistance ( const Position & pos ) const
2010-04-07 18:09:10 +02:00
{
2010-02-06 00:28:19 +01:00
float d = GetExactDist ( & pos ) - GetObjectSize ();
return d > 0.0f ? d : 0.0f ;
}
2009-08-29 14:58:45 -05:00
float GetDistance ( float x , float y , float z ) const
2010-04-07 18:09:10 +02:00
{
2010-02-06 00:28:19 +01:00
float d = GetExactDist ( x , y , z ) - GetObjectSize ();
return d > 0.0f ? d : 0.0f ;
}
2009-08-29 14:58:45 -05:00
float GetDistance2d ( const WorldObject * obj ) const
2010-04-07 18:09:10 +02:00
{
2010-02-06 00:28:19 +01:00
float d = GetExactDist2d ( obj ) - GetObjectSize () - obj -> GetObjectSize ();
return d > 0.0f ? d : 0.0f ;
}
2009-08-29 14:58:45 -05:00
float GetDistance2d ( float x , float y ) const
2010-04-07 18:09:10 +02:00
{
2010-02-06 00:28:19 +01:00
float d = GetExactDist2d ( x , y ) - GetObjectSize ();
return d > 0.0f ? d : 0.0f ;
}
2008-10-02 16:23:55 -05:00
float GetDistanceZ ( const WorldObject * obj ) const ;
2009-10-17 15:51:44 -07:00
2009-01-31 16:38:50 -06:00
bool IsInMap ( const WorldObject * obj ) const
{
2010-03-22 17:47:38 +01:00
if ( obj )
return IsInWorld () && obj -> IsInWorld () && ( GetMap () == obj -> GetMap ()) && InSamePhase ( obj );
else
return false ;
2009-01-31 16:38:50 -06:00
}
2009-08-29 14:58:45 -05:00
bool IsWithinDist3d ( float x , float y , float z , float dist ) const
{ return IsInDist ( x , y , z , dist + GetObjectSize ()); }
2009-08-29 23:20:16 -05:00
bool IsWithinDist3d ( const Position * pos , float dist ) const
{ return IsInDist ( pos , dist + GetObjectSize ()); }
2009-08-29 14:58:45 -05:00
bool IsWithinDist2d ( float x , float y , float dist ) const
{ return IsInDist2d ( x , y , dist + GetObjectSize ()); }
2009-08-29 23:20:16 -05:00
bool IsWithinDist2d ( const Position * pos , float dist ) const
{ return IsInDist2d ( pos , dist + GetObjectSize ()); }
2009-05-14 16:50:47 -05:00
bool _IsWithinDist ( WorldObject const * obj , float dist2compare , bool is3D ) const ;
2010-02-06 00:28:19 +01:00
// use only if you will sure about placing both object at same map
2009-05-14 16:50:47 -05:00
bool IsWithinDist ( WorldObject const * obj , float dist2compare , bool is3D = true ) const
{
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 ;
2009-12-17 19:09:40 +01:00
bool isInFront ( WorldObject const * target , float distance , float arc = M_PI ) const ;
bool isInBack ( WorldObject const * target , float distance , float arc = M_PI ) const ;
2009-10-17 15:51:44 -07:00
2009-05-09 10:50:41 -05:00
bool IsInBetween ( const WorldObject * obj1 , const WorldObject * 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
2009-05-27 09:09:22 -05:00
virtual void SendMessageToSet ( WorldPacket * data , bool self );
virtual void SendMessageToSetInRange ( WorldPacket * data , float dist , bool self );
2010-04-04 03:46:38 +03:00
virtual void SendMessageToSet ( WorldPacket * data , Player const * skipped_rcvr );
2009-10-17 15:51:44 -07:00
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-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
2008-10-02 16:23:55 -05:00
virtual void SaveRespawnTime () {}
void AddObjectToRemoveList ();
2009-10-17 15:51:44 -07:00
2008-10-02 16:23:55 -05:00
// main visibility check function in normal case (ignore grey zone distance check)
bool isVisibleFor ( Player const * u ) const { return isVisibleForInState ( u , false ); }
2009-10-17 15:51:44 -07:00
2008-10-02 16:23:55 -05:00
// 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 ;
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
2009-08-01 00:20:32 +02:00
virtual void SetMap ( Map * map );
2009-08-10 23:47:47 -05:00
virtual void ResetMap ();
2009-07-16 11:49:00 +08:00
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!
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 ();
2009-05-31 20:45:34 -05:00
ZoneScript * GetZoneScript () const { return m_zoneScript ; }
2009-10-17 15:51:44 -07:00
2009-08-29 14:58:45 -05:00
TempSummon * SummonCreature ( uint32 id , const Position & pos , TempSummonType spwtype = TEMPSUMMON_MANUAL_DESPAWN , uint32 despwtime = 0 , uint32 vehId = 0 ) const ;
2009-08-23 22:09:43 -05:00
TempSummon * SummonCreature ( uint32 id , float x , float y , float z , float ang = 0 , TempSummonType spwtype = TEMPSUMMON_MANUAL_DESPAWN , uint32 despwtime = 0 )
2009-08-29 14:58:45 -05:00
{
2010-04-07 19:14:10 +02:00
if ( ! x && ! y && ! z )
2009-08-29 14:58:45 -05:00
{
GetClosePoint ( x , y , z , GetObjectSize ());
ang = GetOrientation ();
}
Position pos = { x , y , z , ang };
return SummonCreature ( id , pos , spwtype , despwtime , 0 );
2009-08-23 22:09:43 -05:00
}
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-10-17 15:51:44 -07:00
2009-12-17 11:40:23 +01:00
Creature * FindNearestCreature ( uint32 entry , float range , bool alive = true );
GameObject * FindNearestGameObject ( uint32 entry , float range );
2009-10-17 15:51:44 -07:00
2009-11-22 00:46:38 -08:00
void GetGameObjectListWithEntryInGrid ( std :: list < GameObject *>& lList , uint32 uiEntry , float fMaxSearchRange );
2009-12-17 11:40:23 +01:00
void GetCreatureListWithEntryInGrid ( std :: list < Creature *>& lList , uint32 uiEntry , float fMaxSearchRange );
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 );
2010-04-07 22:59:46 +02:00
void BuildUpdate ( UpdateDataMapType & );
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 ;}
bool isNeedNotify ( uint16 f ) const { return m_notifyflags & f ;}
2010-02-27 15:25:14 +02:00
uint16 GetNotifyFlags () const { return m_notifyflags ; }
2009-12-19 10:12:40 +01:00
bool NotifyExecuted ( uint16 f ) const { return m_executed_notifies & f ;}
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 );
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-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
2009-08-11 16:14:45 -05:00
bool m_isWorldObject ;
2010-05-16 17:45:45 +02:00
uint32 LastUsedScriptID ;
2010-07-30 21:54:46 -07:00
// Transports
Transport * GetTransport () const { return m_transport ; }
2010-08-08 20:32:14 +02:00
virtual float GetTransOffsetX () const { return 0 ; }
virtual float GetTransOffsetY () const { return 0 ; }
virtual float GetTransOffsetZ () const { return 0 ; }
virtual float GetTransOffsetO () const { return 0 ; }
virtual uint32 GetTransTime () const { return 0 ; }
virtual int8 GetTransSeat () const { return - 1 ; }
virtual uint64 GetTransGUID () const ;
2010-07-30 21:54:46 -07:00
void SetTransport ( Transport * t ) { m_transport = t ; }
MovementInfo m_movementInfo ;
2008-10-02 16:23:55 -05:00
protected :
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 ;
2009-10-17 15:51:44 -07:00
2010-07-30 21:54:46 -07:00
// transports
Transport * m_transport ;
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
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-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 ;
2008-10-02 16:23:55 -05:00
};
2010-05-30 04:23:27 +02:00
namespace Trinity
{
template < class T >
void RandomResizeList ( std :: list < T > & _list , uint32 _size )
{
while ( _list . size () > _size )
{
typename std :: list < T >:: iterator itr = _list . begin ();
advance ( itr , urand ( 0 , _list . size () - 1 ));
_list . erase ( itr );
}
}
2010-08-08 19:45:53 +02:00
2010-05-30 04:23:27 +02:00
// Binary predicate to sort WorldObjects based on the distance to a reference WorldObject
class ObjectDistanceOrderPred
{
public :
ObjectDistanceOrderPred ( const WorldObject * pRefObj , bool ascending = true ) : m_refObj ( pRefObj ), m_ascending ( ascending ) {}
bool operator ()( const WorldObject * pLeft , const WorldObject * pRight ) const
{
return m_ascending ? m_refObj -> GetDistanceOrder ( pLeft , pRight ) : ! m_refObj -> GetDistanceOrder ( pLeft , pRight );
}
private :
const WorldObject * m_refObj ;
const bool m_ascending ;
};
}
2008-10-02 16:23:55 -05:00
#endif