OregonCore  revision fb2a440-git
Your Favourite TBC server
Map Class Reference

#include <Map.h>

+ Inheritance diagram for Map:

Public Types

enum  EnterState {
  CAN_ENTER = 0, CANNOT_ENTER_ALREADY_IN_MAP = 1, CANNOT_ENTER_NO_ENTRY, CANNOT_ENTER_UNINSTANCED_DUNGEON,
  CANNOT_ENTER_DIFFICULTY_UNAVAILABLE, CANNOT_ENTER_NOT_IN_RAID, CANNOT_ENTER_CORPSE_IN_DIFFERENT_INSTANCE, CANNOT_ENTER_INSTANCE_BIND_MISMATCH,
  CANNOT_ENTER_TOO_MANY_INSTANCES, CANNOT_ENTER_MAX_PLAYERS, CANNOT_ENTER_ZONE_IN_COMBAT, CANNOT_ENTER_UNSPECIFIED_REASON
}
 
typedef MapRefManager PlayerList
 
- Public Types inherited from GridRefManager< NGridType >
typedef LinkedListHead::Iterator< GridReference< NGridType > > iterator
 
- Public Types inherited from RefManager< GridRefManager< NGridType >, NGridType >
typedef LinkedListHead::Iterator< Reference< GridRefManager< NGridType >, NGridType > > iterator
 
- Public Types inherited from LinkedListHead
typedef Iterator< LinkedListElementiterator
 
- Public Types inherited from Oregon::ObjectLevelLockable< Map, ACE_Thread_Mutex >
typedef volatile Map VolatileType
 

Public Member Functions

 Map (uint32 id, time_t, uint32 InstanceId, uint8 SpawnMode, Map *_parent=NULL)
 
 ~Map () override
 
bool CanUnload (uint32 diff)
 
virtual bool AddPlayerToMap (Player *)
 
virtual void RemovePlayerFromMap (Player *, bool)
 
template<class T >
bool AddToMap (T *)
 
template<class T >
void RemoveFromMap (T *, bool)
 
void VisitNearbyCellsOf (WorldObject *obj, TypeContainerVisitor< Oregon::ObjectUpdater, GridTypeMapContainer > &gridVisitor, TypeContainerVisitor< Oregon::ObjectUpdater, WorldTypeMapContainer > &worldVisitor)
 
virtual void Update (const uint32 &)
 
float GetVisibilityRange () const
 
virtual void InitVisibilityDistance ()
 
void PlayerRelocation (Player *, float x, float y, float z, float orientation)
 
void CreatureRelocation (Creature *creature, float x, float y, float z, float ang, bool respawnRelocationOnFail=true)
 
template<class T , class CONTAINER >
void Visit (const Cell &cell, TypeContainerVisitor< T, CONTAINER > &visitor)
 
bool IsRemovalGrid (float x, float y) const
 
bool IsGridLoaded (float x, float y) const
 
bool GetUnloadLock (const GridCoord &p) const
 
void SetUnloadLock (const GridCoord &p, bool on)
 
void LoadGrid (float x, float y)
 
bool UnloadGrid (NGridType &ngrid, bool pForce)
 
virtual void UnloadAll ()
 
void ResetGridExpiry (NGridType &grid, float factor=1) const
 
time_t GetGridExpiry (void) const
 
uint32 GetId (void) const
 
Map const * GetParent () const
 
InstanceMapToInstanceMap ()
 
InstanceMap const * ToInstanceMap () const
 
float GetWaterOrGroundLevel (float x, float y, float z, float *ground=NULL, bool swim=false) const
 
float GetHeight (float x, float y, float z, bool checkVMap=true, float maxSearchDist=DEFAULT_HEIGHT_SEARCH) const
 
ZLiquidStatus getLiquidStatus (float x, float y, float z, uint8 ReqLiquidType, LiquidData *data=0) const
 
uint16 GetAreaFlag (float x, float y, float z, bool *isOutdoors=0) const
 
bool GetAreaInfo (float x, float y, float z, uint32 &mogpflags, int32 &adtId, int32 &rootId, int32 &groupId) const
 
bool IsOutdoors (float x, float y, float z) const
 
uint8 GetTerrainType (float x, float y) const
 
float GetWaterLevel (float x, float y) const
 
bool IsInWater (float x, float y, float z, LiquidData *data=nullptr) const
 
bool IsUnderWater (float x, float y, float z) const
 
bool IsSwimmable (float x, float y, float z, LiquidData *data=nullptr) const
 
uint32 GetAreaId (float x, float y, float z) const
 
uint32 GetZoneId (float x, float y, float z) const
 
void MoveAllCreaturesInMoveList ()
 
void RemoveAllObjectsInRemoveList ()
 
virtual void RemoveAllPlayers ()
 
bool CreatureRespawnRelocation (Creature *c)
 
bool CheckGridIntegrity (Creature *c, bool moved) const
 
uint32 GetInstanceId () const
 
uint8 GetSpawnMode () const
 
virtual EnterState CannotEnter (Player *)
 
const char * GetMapName () const
 
DungeonDifficulty GetDifficulty () const
 
bool IsRegularDifficulty () const
 
bool Instanceable () const
 
bool IsDungeon () const
 
bool IsRaid () const
 
bool IsHeroic () const
 
bool IsBattleground () const
 
bool IsBattleArena () const
 
bool IsBattlegroundOrArena () const
 
void AddObjectToRemoveList (WorldObject *obj)
 
void AddObjectToSwitchList (WorldObject *obj, bool on)
 
virtual void DelayedUpdate (const uint32 diff)
 
void UpdateObjectVisibility (WorldObject *obj, Cell cell, CellCoord cellpair)
 
void UpdateObjectsVisibilityFor (Player *player, Cell cell, CellCoord cellpair)
 
void resetMarkedCells ()
 
bool isCellMarked (uint32 pCellId)
 
void markCell (uint32 pCellId)
 
bool HavePlayers () const
 
uint32 GetPlayersCountExceptGMs () const
 
bool ActiveObjectsNearGrid (NGridType const &ngrid) const
 
void AddWorldObject (WorldObject *obj)
 
void RemoveWorldObject (WorldObject *obj)
 
void SendToPlayers (WorldPacket const *data) const
 
PlayerList const & GetPlayers () const
 
void ScriptsStart (std::map< uint32, std::multimap< uint32, ScriptInfo > > const &scripts, uint32 id, Object *source, Object *target)
 
void ScriptCommandStart (ScriptInfo const &script, uint32 delay, Object *source, Object *target)
 
template<class T >
void AddToActive (T *obj)
 
void AddToActive (Creature *obj)
 
template<class T >
void RemoveFromActive (T *obj)
 
void RemoveFromActive (Creature *obj)
 
void SwitchGridContainers (Creature *creature, bool toWorldContainer)
 
template<class NOTIFIER >
void VisitAll (const float &x, const float &y, float radius, NOTIFIER &notifier)
 
template<class NOTIFIER >
void VisitWorld (const float &x, const float &y, float radius, NOTIFIER &notifier)
 
template<class NOTIFIER >
void VisitGrid (const float &x, const float &y, float radius, NOTIFIER &notifier)
 
void UpdateIteratorBack (Player *player)
 
TempSummonSummonCreature (uint32 entry, const Position &pos, SummonPropertiesEntry const *properties=NULL, uint32 duration=0, Unit *summoner=NULL, uint32 spellId=0, TempSummonType spwType=TEMPSUMMON_MANUAL_DESPAWN)
 
CreatureGetCreature (uint64 guid)
 
GameObjectGetGameObject (uint64 guid)
 
DynamicObjectGetDynamicObject (uint64 guid)
 
bool isInLineOfSight (float x1, float y1, float z1, float x2, float y2, float z2) const
 
void Balance ()
 
void Remove (const GameObjectModel &mdl)
 
void Insert (const GameObjectModel &mdl)
 
bool Contains (const GameObjectModel &mdl) const
 
bool getObjectHitPos (float x1, float y1, float z1, float x2, float y2, float z2, float &rx, float &ry, float &rz, float modifyDist)
 
template<>
void AddToGrid (Creature *obj, Cell const &cell)
 
template<>
void AddToGrid (Corpse *obj, Cell const &cell)
 
template<>
void DeleteFromWorld (Player *pl)
 
template<class T , class CONTAINER >
void Visit (Cell const &cell, TypeContainerVisitor< T, CONTAINER > &visitor)
 
template<class NOTIFIER >
void VisitAll (float const &x, float const &y, float radius, NOTIFIER &notifier)
 
- Public Member Functions inherited from GridRefManager< NGridType >
GridReference< NGridType > * getFirst ()
 
GridReference< NGridType > * getLast ()
 
iterator begin ()
 
iterator end ()
 
iterator rbegin ()
 
iterator rend ()
 
- Public Member Functions inherited from RefManager< GridRefManager< NGridType >, NGridType >
 RefManager ()
 
virtual ~RefManager ()
 
Reference< GridRefManager< NGridType >, NGridType > * getFirst ()
 
Reference< GridRefManager< NGridType >, NGridType > const * getFirst () const
 
Reference< GridRefManager< NGridType >, NGridType > * getLast ()
 
Reference< GridRefManager< NGridType >, NGridType > const * getLast () const
 
iterator begin ()
 
iterator end ()
 
iterator rbegin ()
 
iterator rend ()
 
void clearReferences ()
 
- Public Member Functions inherited from LinkedListHead
 LinkedListHead ()
 
virtual ~LinkedListHead ()
 
bool isEmpty () const
 
LinkedListElementgetFirst ()
 
LinkedListElement const * getFirst () const
 
LinkedListElementgetLast ()
 
LinkedListElement const * getLast () const
 
void insertFirst (LinkedListElement *pElem)
 
void insertLast (LinkedListElement *pElem)
 
uint32 getSize () const
 
void incSize ()
 
void decSize ()
 
- Public Member Functions inherited from Oregon::ObjectLevelLockable< Map, ACE_Thread_Mutex >
 ObjectLevelLockable ()
 

Static Public Member Functions

static bool ExistMap (uint32 mapid, int gx, int gy)
 
static bool ExistVMap (uint32 mapid, int gx, int gy)
 
static void InitStateMachine ()
 
static void DeleteStateMachine ()
 
static uint32 GetAreaId (uint16 areaflag, uint32 map_id)
 
static uint32 GetZoneId (uint16 areaflag, uint32 map_id)
 

Public Attributes

CreatureGroupHolderType CreatureGroupHolder
 

Protected Types

typedef Oregon::ObjectLevelLockable< Map, ACE_Thread_Mutex >::Lock Guard
 
typedef std::set< WorldObject * > ActiveNonPlayers
 

Protected Member Functions

void SetUnloadReferenceLock (const GridCoord &p, bool on)
 

Protected Attributes

MapEntry const * i_mapEntry
 
uint8 i_spawnMode
 
uint32 i_InstanceId
 
uint32 m_unloadTimer
 
float m_VisibleDistance
 
MapRefManager m_mapRefManager
 
MapRefManager::iterator m_mapRefIter
 
int32 m_VisibilityNotifyPeriod
 
ActiveNonPlayers m_activeNonPlayers
 
ActiveNonPlayers::iterator m_activeNonPlayersIter
 

Private Member Functions

void LoadMapAndVMap (int gx, int gy)
 
void LoadVMap (int gx, int gy)
 
void LoadMMap (int gx, int gy)
 
void LoadMap (int gx, int gy, bool reload=false)
 
GridMapGetGrid (float x, float y)
 
void SetTimer (uint32 t)
 
void SendInitSelf (Player *player)
 
void SendInitTransports (Player *player)
 
void SendRemoveTransports (Player *player)
 
bool CreatureCellRelocation (Creature *creature, Cell new_cell)
 
void AddCreatureToMoveList (Creature *c, float x, float y, float z, float ang)
 
bool IsGridLoaded (const GridCoord &) const
 
void EnsureGridCreated (const GridCoord &)
 
bool EnsureGridLoaded (Cell const &)
 
void EnsureGridLoadedForActiveObject (Cell const &, WorldObject *object)
 
void buildNGridLinkage (NGridType *pNGridType)
 
template<class T >
void AddType (T *obj)
 
template<class T >
void RemoveType (T *obj, bool)
 
NGridTypegetNGrid (uint32 x, uint32 y) const
 
bool isGridObjectDataLoaded (uint32 x, uint32 y) const
 
void setGridObjectDataLoaded (bool pLoaded, uint32 x, uint32 y)
 
void setNGrid (NGridType *grid, uint32 x, uint32 y)
 
void ScriptsProcess ()
 
Player_GetScriptPlayerSourceOrTarget (Object *source, Object *target, const ScriptInfo *scriptInfo) const
 
Creature_GetScriptCreatureSourceOrTarget (Object *source, Object *target, const ScriptInfo *scriptInfo, bool bReverse=false) const
 
Unit_GetScriptUnit (Object *obj, bool isSource, const ScriptInfo *scriptInfo) const
 
Player_GetScriptPlayer (Object *obj, bool isSource, const ScriptInfo *scriptInfo) const
 
Creature_GetScriptCreature (Object *obj, bool isSource, const ScriptInfo *scriptInfo) const
 
WorldObject_GetScriptWorldObject (Object *obj, bool isSource, const ScriptInfo *scriptInfo) const
 
void _ScriptProcessDoor (Object *source, Object *target, const ScriptInfo *scriptInfo) const
 
GameObject_FindGameObject (WorldObject *pWorldObject, uint32 guid) const
 
void ProcessRelocationNotifies (const uint32 &diff)
 
template<class T >
void AddToGrid (T *object, Cell const &cell)
 
template<class T >
void DeleteFromWorld (T *)
 
template<class T >
void AddToActiveHelper (T *obj)
 
template<class T >
void RemoveFromActiveHelper (T *obj)
 

Private Attributes

CreatureMoveList i_creaturesToMove
 
DynamicMapTree m_dyn_tree
 
time_t i_gridExpiry
 
Mapm_parentMap
 
NGridTypei_grids [MAX_NUMBER_OF_GRIDS][MAX_NUMBER_OF_GRIDS]
 
GridMapGridMaps [MAX_NUMBER_OF_GRIDS][MAX_NUMBER_OF_GRIDS]
 
std::bitset< TOTAL_NUMBER_OF_CELLS_PER_MAP *TOTAL_NUMBER_OF_CELLS_PER_MAPmarked_cells
 
bool i_scriptLock
 
std::set< WorldObject * > i_objectsToRemove
 
std::map< WorldObject *, bool > i_objectsToSwitch
 
std::set< WorldObject * > i_worldObjects
 
std::multimap< time_t, ScriptActionm_scriptSchedule
 

Friends

class MapReference
 

Detailed Description

Definition at line 266 of file Map.h.

Member Typedef Documentation

typedef std::set<WorldObject*> Map::ActiveNonPlayers
protected

Definition at line 610 of file Map.h.

typedef Oregon::ObjectLevelLockable<Map, ACE_Thread_Mutex>::Lock Map::Guard
protected

Definition at line 597 of file Map.h.

Definition at line 490 of file Map.h.

Member Enumeration Documentation

Enumerator
CAN_ENTER 
CANNOT_ENTER_ALREADY_IN_MAP 
CANNOT_ENTER_NO_ENTRY 
CANNOT_ENTER_UNINSTANCED_DUNGEON 
CANNOT_ENTER_DIFFICULTY_UNAVAILABLE 
CANNOT_ENTER_NOT_IN_RAID 
CANNOT_ENTER_CORPSE_IN_DIFFERENT_INSTANCE 
CANNOT_ENTER_INSTANCE_BIND_MISMATCH 
CANNOT_ENTER_TOO_MANY_INSTANCES 
CANNOT_ENTER_MAX_PLAYERS 
CANNOT_ENTER_ZONE_IN_COMBAT 
CANNOT_ENTER_UNSPECIFIED_REASON 

Definition at line 399 of file Map.h.

400  {
401  CAN_ENTER = 0,
402  CANNOT_ENTER_ALREADY_IN_MAP = 1, // Player is already in the map
403  CANNOT_ENTER_NO_ENTRY, // No map entry was found for the target map ID
404  CANNOT_ENTER_UNINSTANCED_DUNGEON, // No instance template was found for dungeon map
405  CANNOT_ENTER_DIFFICULTY_UNAVAILABLE, // Requested instance difficulty is not available for target map
406  CANNOT_ENTER_NOT_IN_RAID, // Target instance is a raid instance and the player is not in a raid group
407  CANNOT_ENTER_CORPSE_IN_DIFFERENT_INSTANCE, // Player is dead and their corpse is not in target instance
408  CANNOT_ENTER_INSTANCE_BIND_MISMATCH, // Player's permanent instance save is not compatible with their group's current instance bind
409  CANNOT_ENTER_TOO_MANY_INSTANCES, // Player has entered too many instances recently
410  CANNOT_ENTER_MAX_PLAYERS, // Target map already has the maximum number of players allowed
411  CANNOT_ENTER_ZONE_IN_COMBAT, // A boss encounter is currently in progress on the target map
413  };

Constructor & Destructor Documentation

Map::Map ( uint32  id,
time_t  expiry,
uint32  InstanceId,
uint8  SpawnMode,
Map _parent = NULL 
)

Definition at line 202 of file Map.cpp.

References GridMaps, InitVisibilityDistance(), m_parentMap, MAX_NUMBER_OF_GRIDS, and setNGrid().

202  :
203  i_mapEntry (sMapStore.LookupEntry(id)), i_spawnMode(SpawnMode), i_InstanceId(InstanceId),
207  i_scriptLock(false)
208 {
209  m_parentMap = (_parent ? _parent : this);
210 
211  for (unsigned int idx = 0; idx < MAX_NUMBER_OF_GRIDS; ++idx)
212  {
213  for (unsigned int j = 0; j < MAX_NUMBER_OF_GRIDS; ++j)
214  {
215  //z code
216  GridMaps[idx][j] = NULL;
217  setNGrid(NULL, idx, j);
218  }
219  }
220 
221  //lets initialize visibility distance for map
223 }
virtual void InitVisibilityDistance()
Definition: Map.cpp:225
MapEntry const * i_mapEntry
Definition: Map.h:599
float m_VisibleDistance
Definition: Map.h:603
time_t i_gridExpiry
Definition: Map.h:625
Map * m_parentMap
Definition: Map.h:629
#define DEFAULT_VISIBILITY_NOTIFY_PERIOD
Definition: NGrid.h:28
#define MAX_NUMBER_OF_GRIDS
Definition: GridDefines.h:33
uint8 i_spawnMode
Definition: Map.h:600
ActiveNonPlayers m_activeNonPlayers
Definition: Map.h:611
bool i_scriptLock
Definition: Map.h:639
DBCStorage< MapEntry > sMapStore(MapEntryfmt)
GridMap * GridMaps[MAX_NUMBER_OF_GRIDS][MAX_NUMBER_OF_GRIDS]
Definition: Map.h:632
void setNGrid(NGridType *grid, uint32 x, uint32 y)
Definition: Map.cpp:2006
uint32 m_unloadTimer
Definition: Map.h:602
ActiveNonPlayers::iterator m_activeNonPlayersIter
Definition: Map.h:612
int32 m_VisibilityNotifyPeriod
Definition: Map.h:608
uint32 i_InstanceId
Definition: Map.h:601
#define DEFAULT_VISIBILITY_DISTANCE
Definition: Object.h:40
Map::~Map ( )
override

Definition at line 40 of file Map.cpp.

References ASSERT, i_worldObjects, WorldObject::IsWorldObject(), m_scriptSchedule, WorldObject::RemoveFromWorld(), WorldObject::ResetMap(), sWorld, and UnloadAll().

41 {
42  UnloadAll();
43 
44  while (!i_worldObjects.empty())
45  {
46  WorldObject* obj = *i_worldObjects.begin();
47  ASSERT(obj->IsWorldObject());
48  //ASSERT(obj->GetTypeId() == TYPEID_CORPSE);
49  obj->RemoveFromWorld();
50  obj->ResetMap();
51  }
52 
53  if (!m_scriptSchedule.empty())
54  sWorld.DecreaseScheduledScriptCount(m_scriptSchedule.size());
55 }
std::multimap< time_t, ScriptAction > m_scriptSchedule
Definition: Map.h:643
virtual void ResetMap()
Definition: Object.cpp:1972
bool IsWorldObject() const
Definition: Object.cpp:1112
virtual void RemoveFromWorld() override
Definition: Object.cpp:1169
std::set< WorldObject * > i_worldObjects
Definition: Map.h:642
virtual void UnloadAll()
Definition: Map.cpp:995
#define ASSERT
Definition: Errors.h:29
#define sWorld
Definition: World.h:860

Member Function Documentation

GameObject * Map::_FindGameObject ( WorldObject pWorldObject,
uint32  guid 
) const
inlineprivate

Definition at line 271 of file MapScripts.cpp.

References Oregon::ComputeCellCoord(), WorldObject::GetGridActivationRange(), WorldObject::GetMap(), Position::GetPositionX(), Position::GetPositionY(), and Cell::Visit().

Referenced by _ScriptProcessDoor(), and ScriptsProcess().

272 {
273  GameObject* gameobject = NULL;
274 
275  CellCoord p(Oregon::ComputeCellCoord(searchObject->GetPositionX(), searchObject->GetPositionY()));
276  Cell cell(p);
277 
278  Oregon::GameObjectWithDbGUIDCheck goCheck(*searchObject, guid);
279  Oregon::GameObjectSearcher<Oregon::GameObjectWithDbGUIDCheck> checker(searchObject, gameobject, goCheck);
280 
282  cell.Visit(p, objectChecker, *searchObject->GetMap(), *searchObject, searchObject->GetGridActivationRange());
283 
284  return gameobject;
285 }
CellCoord ComputeCellCoord(float x, float y)
Definition: GridDefines.h:167
Definition: Cell.h:46
Creature * Map::_GetScriptCreature ( Object obj,
bool  isSource,
const ScriptInfo scriptInfo 
) const
inlineprivate

Definition at line 188 of file MapScripts.cpp.

References ScriptInfo::GetDebugInfo(), Object::GetEntry(), Object::GetGUIDLow(), Object::GetTypeId(), sLog, and Object::ToCreature().

Referenced by ScriptsProcess().

189 {
190  Creature* pCreature = NULL;
191  if (!obj)
192  sLog.outError("%s %s object is NULL.", scriptInfo->GetDebugInfo().c_str(), isSource ? "source" : "target");
193  else
194  {
195  pCreature = obj->ToCreature();
196  if (!pCreature)
197  sLog.outError("%s %s object is not a creature (TypeId: %u, Entry: %u, GUID: %u).", scriptInfo->GetDebugInfo().c_str(),
198  isSource ? "source" : "target", obj->GetTypeId(), obj->GetEntry(), obj->GetGUIDLow());
199  }
200  return pCreature;
201 }
#define sLog
Log class singleton.
Definition: Log.h:187
std::string GetDebugInfo() const
Definition: ObjectMgr.cpp:218
uint32 GetGUIDLow() const
Definition: Object.h:166
uint8 GetTypeId() const
Definition: Object.h:210
Creature * ToCreature()
Definition: Object.h:395
uint32 GetEntry() const
Definition: Object.h:192
Creature * Map::_GetScriptCreatureSourceOrTarget ( Object source,
Object target,
const ScriptInfo scriptInfo,
bool  bReverse = false 
) const
inlineprivate

Definition at line 122 of file MapScripts.cpp.

References ScriptInfo::GetDebugInfo(), Object::GetEntry(), Object::GetGUIDLow(), Object::GetTypeId(), sLog, and Object::ToCreature().

Referenced by ScriptsProcess().

123 {
124  Creature* pCreature = NULL;
125  if (!source && !target)
126  sLog.outError("%s source and target objects are NULL.", scriptInfo->GetDebugInfo().c_str());
127  else
128  {
129  if (bReverse)
130  {
131  // Check target first, then source.
132  if (target)
133  pCreature = target->ToCreature();
134  if (!pCreature && source)
135  pCreature = source->ToCreature();
136  }
137  else
138  {
139  // Check source first, then target.
140  if (source)
141  pCreature = source->ToCreature();
142  if (!pCreature && target)
143  pCreature = target->ToCreature();
144  }
145 
146  if (!pCreature)
147  sLog.outError("%s neither source nor target are creatures (source: TypeId: %u, Entry: %u, GUID: %u; target: TypeId: %u, Entry: %u, GUID: %u), skipping.",
148  scriptInfo->GetDebugInfo().c_str(),
149  source ? source->GetTypeId() : 0, source ? source->GetEntry() : 0, source ? source->GetGUIDLow() : 0,
150  target ? target->GetTypeId() : 0, target ? target->GetEntry() : 0, target ? target->GetGUIDLow() : 0);
151  }
152  return pCreature;
153 }
#define sLog
Log class singleton.
Definition: Log.h:187
std::string GetDebugInfo() const
Definition: ObjectMgr.cpp:218
uint32 GetGUIDLow() const
Definition: Object.h:166
uint8 GetTypeId() const
Definition: Object.h:210
Creature * ToCreature()
Definition: Object.h:395
uint32 GetEntry() const
Definition: Object.h:192
Player * Map::_GetScriptPlayer ( Object obj,
bool  isSource,
const ScriptInfo scriptInfo 
) const
inlineprivate

Definition at line 173 of file MapScripts.cpp.

References ScriptInfo::GetDebugInfo(), Object::GetEntry(), Object::GetGUIDLow(), Object::GetTypeId(), sLog, and Object::ToPlayer().

Referenced by ScriptsProcess().

174 {
175  Player* pPlayer = NULL;
176  if (!obj)
177  sLog.outError("%s %s object is NULL.", scriptInfo->GetDebugInfo().c_str(), isSource ? "source" : "target");
178  else
179  {
180  pPlayer = obj->ToPlayer();
181  if (!pPlayer)
182  sLog.outError("%s %s object is not a player (TypeId: %u, Entry: %u, GUID: %u).",
183  scriptInfo->GetDebugInfo().c_str(), isSource ? "source" : "target", obj->GetTypeId(), obj->GetEntry(), obj->GetGUIDLow());
184  }
185  return pPlayer;
186 }
#define sLog
Log class singleton.
Definition: Log.h:187
std::string GetDebugInfo() const
Definition: ObjectMgr.cpp:218
uint32 GetGUIDLow() const
Definition: Object.h:166
Player * ToPlayer()
Definition: Object.h:392
uint8 GetTypeId() const
Definition: Object.h:210
uint32 GetEntry() const
Definition: Object.h:192
Definition: Player.h:922
Player * Map::_GetScriptPlayerSourceOrTarget ( Object source,
Object target,
const ScriptInfo scriptInfo 
) const
inlineprivate

Definition at line 100 of file MapScripts.cpp.

References ScriptInfo::GetDebugInfo(), Object::GetEntry(), Object::GetGUIDLow(), Object::GetTypeId(), sLog, and Object::ToPlayer().

Referenced by ScriptsProcess().

101 {
102  Player* pPlayer = NULL;
103  if (!source && !target)
104  sLog.outError("%s source and target objects are NULL.", scriptInfo->GetDebugInfo().c_str());
105  else
106  {
107  // Check target first, then source.
108  if (target)
109  pPlayer = target->ToPlayer();
110  if (!pPlayer && source)
111  pPlayer = source->ToPlayer();
112 
113  if (!pPlayer)
114  sLog.outError("%s neither source nor target object is player (source: TypeId: %u, Entry: %u, GUID: %u; target: TypeId: %u, Entry: %u, GUID: %u), skipping.",
115  scriptInfo->GetDebugInfo().c_str(),
116  source ? source->GetTypeId() : 0, source ? source->GetEntry() : 0, source ? source->GetGUIDLow() : 0,
117  target ? target->GetTypeId() : 0, target ? target->GetEntry() : 0, target ? target->GetGUIDLow() : 0);
118  }
119  return pPlayer;
120 }
#define sLog
Log class singleton.
Definition: Log.h:187
std::string GetDebugInfo() const
Definition: ObjectMgr.cpp:218
uint32 GetGUIDLow() const
Definition: Object.h:166
Player * ToPlayer()
Definition: Object.h:392
uint8 GetTypeId() const
Definition: Object.h:210
uint32 GetEntry() const
Definition: Object.h:192
Definition: Player.h:922
Unit * Map::_GetScriptUnit ( Object obj,
bool  isSource,
const ScriptInfo scriptInfo 
) const
inlineprivate

Definition at line 155 of file MapScripts.cpp.

References ScriptInfo::GetDebugInfo(), Object::GetEntry(), Object::GetGUIDLow(), Object::GetTypeId(), Object::isType(), sLog, and TYPEMASK_UNIT.

Referenced by ScriptsProcess().

156 {
157  Unit* pUnit = NULL;
158  if (!obj)
159  sLog.outError("%s %s object is NULL.", scriptInfo->GetDebugInfo().c_str(), isSource ? "source" : "target");
160  else if (!obj->isType(TYPEMASK_UNIT))
161  sLog.outError("%s %s object is not unit (TypeId: %u, Entry: %u, GUID: %u), skipping.",
162  scriptInfo->GetDebugInfo().c_str(), isSource ? "source" : "target", obj->GetTypeId(), obj->GetEntry(), obj->GetGUIDLow());
163  else
164  {
165  pUnit = dynamic_cast<Unit*>(obj);
166  if (!pUnit)
167  sLog.outError("%s %s object could not be casted to unit.",
168  scriptInfo->GetDebugInfo().c_str(), isSource ? "source" : "target");
169  }
170  return pUnit;
171 }
bool isType(uint16 mask) const
Definition: Object.h:214
#define sLog
Log class singleton.
Definition: Log.h:187
std::string GetDebugInfo() const
Definition: ObjectMgr.cpp:218
uint32 GetGUIDLow() const
Definition: Object.h:166
uint8 GetTypeId() const
Definition: Object.h:210
uint32 GetEntry() const
Definition: Object.h:192
Definition: Unit.h:908
WorldObject * Map::_GetScriptWorldObject ( Object obj,
bool  isSource,
const ScriptInfo scriptInfo 
) const
inlineprivate

Definition at line 203 of file MapScripts.cpp.

References ScriptInfo::GetDebugInfo(), Object::GetEntry(), Object::GetGUIDLow(), Object::GetTypeId(), and sLog.

Referenced by ScriptsProcess().

204 {
205  WorldObject* pWorldObject = NULL;
206  if (!obj)
207  sLog.outError("%s %s object is NULL.",
208  scriptInfo->GetDebugInfo().c_str(), isSource ? "source" : "target");
209  else
210  {
211  pWorldObject = dynamic_cast<WorldObject*>(obj);
212  if (!pWorldObject)
213  sLog.outError("%s %s object is not a world object (TypeId: %u, Entry: %u, GUID: %u).",
214  scriptInfo->GetDebugInfo().c_str(), isSource ? "source" : "target", obj->GetTypeId(), obj->GetEntry(), obj->GetGUIDLow());
215  }
216  return pWorldObject;
217 }
#define sLog
Log class singleton.
Definition: Log.h:187
std::string GetDebugInfo() const
Definition: ObjectMgr.cpp:218
uint32 GetGUIDLow() const
Definition: Object.h:166
uint8 GetTypeId() const
Definition: Object.h:210
uint32 GetEntry() const
Definition: Object.h:192
void Map::_ScriptProcessDoor ( Object source,
Object target,
const ScriptInfo scriptInfo 
) const
inlineprivate

Definition at line 219 of file MapScripts.cpp.

References _FindGameObject(), ScriptInfo::command, GAMEOBJECT_TYPE_BUTTON, GAMEOBJECT_TYPE_DOOR, ScriptInfo::GetDebugInfo(), Object::GetEntry(), GameObject::GetGoState(), GameObject::GetGoType(), Object::GetGUIDLow(), Object::GetTypeId(), GO_STATE_READY, Object::isType(), SCRIPT_COMMAND_CLOSE_DOOR, SCRIPT_COMMAND_OPEN_DOOR, sLog, ScriptInfo::ToggleDoor, TYPEMASK_GAMEOBJECT, TYPEMASK_UNIT, and GameObject::UseDoorOrButton().

Referenced by ScriptsProcess().

220 {
221  bool bOpen = false;
222  uint32 guid = scriptInfo->ToggleDoor.GOGuid;
223  int32 nTimeToToggle = std::max(15, int32(scriptInfo->ToggleDoor.ResetDelay));
224  switch (scriptInfo->command)
225  {
227  bOpen = true;
228  break;
230  break;
231  default:
232  sLog.outError("%s unknown command for _ScriptProcessDoor.", scriptInfo->GetDebugInfo().c_str());
233  return;
234  }
235  if (!guid)
236  sLog.outError("%s door guid is not specified.", scriptInfo->GetDebugInfo().c_str());
237  else if (!source)
238  sLog.outError("%s source object is NULL.", scriptInfo->GetDebugInfo().c_str());
239  else if (!source->isType(TYPEMASK_UNIT))
240  sLog.outError("%s source object is not unit (TypeId: %u, Entry: %u, GUID: %u), skipping.", scriptInfo->GetDebugInfo().c_str(),
241  source->GetTypeId(), source->GetEntry(), source->GetGUIDLow());
242  else
243  {
244  WorldObject* wSource = dynamic_cast <WorldObject*> (source);
245  if (!wSource)
246  sLog.outError("%s source object could not be casted to world object (TypeId: %u, Entry: %u, GUID: %u), skipping.",
247  scriptInfo->GetDebugInfo().c_str(), source->GetTypeId(), source->GetEntry(), source->GetGUIDLow());
248  else
249  {
250  GameObject* pDoor = _FindGameObject(wSource, guid);
251  if (!pDoor)
252  sLog.outError("%s gameobject was not found (guid: %u).", scriptInfo->GetDebugInfo().c_str(), guid);
253  else if (pDoor->GetGoType() != GAMEOBJECT_TYPE_DOOR && pDoor->GetGoType () != GAMEOBJECT_TYPE_BUTTON)
254  sLog.outError("%s gameobject is not a door (or button) (GoType: %u, Entry: %u, GUID: %u).",
255  scriptInfo->GetDebugInfo().c_str(), pDoor->GetGoType(), pDoor->GetEntry(), pDoor->GetGUIDLow());
256  else if (bOpen == (pDoor->GetGoState() == GO_STATE_READY))
257  {
258  pDoor->UseDoorOrButton(nTimeToToggle);
259 
260  if (target && target->isType(TYPEMASK_GAMEOBJECT))
261  {
262  GameObject* goTarget = dynamic_cast<GameObject*>(target);
263  if (goTarget && goTarget->GetGoType() == GAMEOBJECT_TYPE_BUTTON)
264  goTarget->UseDoorOrButton(nTimeToToggle);
265  }
266  }
267  }
268  }
269 }
GOState GetGoState() const
Definition: GameObject.h:728
ScriptCommands command
Definition: ObjectMgr.h:149
bool isType(uint16 mask) const
Definition: Object.h:214
#define sLog
Log class singleton.
Definition: Log.h:187
std::string GetDebugInfo() const
Definition: ObjectMgr.cpp:218
ACE_INT32 int32
Definition: Define.h:67
uint32 GetGUIDLow() const
Definition: Object.h:166
uint8 GetTypeId() const
Definition: Object.h:210
void UseDoorOrButton(uint32 time_to_restore=0, bool alternative=false, Unit *user=NULL)
Definition: GameObject.cpp:955
GameobjectTypes GetGoType() const
Definition: GameObject.h:720
struct ScriptInfo::@99::@112 ToggleDoor
uint32 GetEntry() const
Definition: Object.h:192
GameObject * _FindGameObject(WorldObject *pWorldObject, uint32 guid) const
Definition: MapScripts.cpp:271
ACE_UINT32 uint32
Definition: Define.h:71
bool Map::ActiveObjectsNearGrid ( NGridType const &  ngrid) const

Definition at line 2130 of file Map.cpp.

References MapRefManager::begin(), Oregon::ComputeCellCoord(), MapRefManager::end(), Position::GetPositionX(), Position::GetPositionY(), GetVisibilityRange(), NGrid< N, ACTIVE_OBJECT, WORLD_OBJECT_TYPES, GRID_OBJECT_TYPES >::getX(), NGrid< N, ACTIVE_OBJECT, WORLD_OBJECT_TYPES, GRID_OBJECT_TYPES >::getY(), m_activeNonPlayers, m_mapRefManager, MAX_NUMBER_OF_CELLS, SIZE_OF_GRID_CELL, CoordPair< LIMIT >::x_coord, and CoordPair< LIMIT >::y_coord.

Referenced by UnloadGrid(), and ActiveState::Update().

2131 {
2132  CellCoord cell_min(ngrid.getX() * MAX_NUMBER_OF_CELLS, ngrid.getY() * MAX_NUMBER_OF_CELLS);
2133  CellCoord cell_max(cell_min.x_coord + MAX_NUMBER_OF_CELLS, cell_min.y_coord + MAX_NUMBER_OF_CELLS);
2134 
2135  //we must find visible range in cells so we unload only non-visible cells...
2136  float viewDist = GetVisibilityRange();
2137  int cell_range = (int)ceilf(viewDist / SIZE_OF_GRID_CELL) + 1;
2138 
2139  cell_min << cell_range;
2140  cell_min -= cell_range;
2141  cell_max >> cell_range;
2142  cell_max += cell_range;
2143 
2144  for (MapRefManager::const_iterator iter = m_mapRefManager.begin(); iter != m_mapRefManager.end(); ++iter)
2145  {
2146  Player* plr = iter->GetSource();
2147 
2149  if ((cell_min.x_coord <= p.x_coord && p.x_coord <= cell_max.x_coord) &&
2150  (cell_min.y_coord <= p.y_coord && p.y_coord <= cell_max.y_coord))
2151  return true;
2152  }
2153 
2154  for (ActiveNonPlayers::const_iterator iter = m_activeNonPlayers.begin(); iter != m_activeNonPlayers.end(); ++iter)
2155  {
2156  WorldObject* obj = *iter;
2157 
2159  if ((cell_min.x_coord <= p.x_coord && p.x_coord <= cell_max.x_coord) &&
2160  (cell_min.y_coord <= p.y_coord && p.y_coord <= cell_max.y_coord))
2161  return true;
2162  }
2163 
2164  return false;
2165 }
#define SIZE_OF_GRID_CELL
Definition: GridDefines.h:44
#define MAX_NUMBER_OF_CELLS
Definition: GridDefines.h:43
uint32 y_coord
Definition: GridDefines.h:142
uint32 x_coord
Definition: GridDefines.h:141
iterator begin()
Definition: MapRefManager.h:48
ActiveNonPlayers m_activeNonPlayers
Definition: Map.h:611
float GetPositionY() const
Definition: Position.h:98
float GetVisibilityRange() const
Definition: Map.h:291
CellCoord ComputeCellCoord(float x, float y)
Definition: GridDefines.h:167
float GetPositionX() const
Definition: Position.h:97
MapRefManager m_mapRefManager
Definition: Map.h:605
Definition: Player.h:922
iterator end()
Definition: MapRefManager.h:52
void Map::AddCreatureToMoveList ( Creature c,
float  x,
float  y,
float  z,
float  ang 
)
private

Definition at line 762 of file Map.cpp.

References i_creaturesToMove.

Referenced by CreatureRelocation().

763 {
764  if (!c)
765  return;
766 
767  i_creaturesToMove[c] = CreatureMover(x, y, z, ang);
768 }
CreatureMoveList i_creaturesToMove
Definition: Map.h:557
void Map::AddObjectToRemoveList ( WorldObject obj)

Definition at line 2035 of file Map.cpp.

References ASSERT, WorldObject::CleanupsBeforeDelete(), GetId(), GetInstanceId(), WorldObject::GetInstanceId(), WorldLocation::GetMapId(), and i_objectsToRemove.

Referenced by WorldObject::AddObjectToRemoveList(), and MoveAllCreaturesInMoveList().

2036 {
2037  ASSERT(obj->GetMapId() == GetId() && obj->GetInstanceId() == GetInstanceId());
2038 
2039  obj->CleanupsBeforeDelete(); // remove or simplify at least cross referenced links
2040 
2041  i_objectsToRemove.insert(obj);
2042  //sLog.outMap("Object (GUID: %u TypeId: %u) added to removing list.",obj->GetGUIDLow(),obj->GetTypeId());
2043 }
std::set< WorldObject * > i_objectsToRemove
Definition: Map.h:640
virtual void CleanupsBeforeDelete()
Definition: Object.cpp:1156
uint32 GetId(void) const
Definition: Map.h:333
uint32 GetInstanceId() const
Definition: Object.h:688
uint32 GetMapId() const
Definition: Object.h:591
#define ASSERT
Definition: Errors.h:29
uint32 GetInstanceId() const
Definition: Map.h:390
void Map::AddObjectToSwitchList ( WorldObject obj,
bool  on 
)

Definition at line 2045 of file Map.cpp.

References ASSERT, GetId(), GetInstanceId(), WorldObject::GetInstanceId(), WorldLocation::GetMapId(), Object::GetTypeId(), i_objectsToSwitch, and TYPEID_UNIT.

Referenced by WorldObject::SetWorldObject().

2046 {
2047  ASSERT(obj->GetMapId() == GetId() && obj->GetInstanceId() == GetInstanceId());
2048  // i_objectsToSwitch is iterated only in Map::RemoveAllObjectsInRemoveList() and it uses
2049  // the contained objects only if GetTypeId() == TYPEID_UNIT , so we can return in all other cases
2050  if (obj->GetTypeId() != TYPEID_UNIT)
2051  return;
2052 
2053  std::map<WorldObject*, bool>::iterator itr = i_objectsToSwitch.find(obj);
2054  if (itr == i_objectsToSwitch.end())
2055  i_objectsToSwitch.insert(itr, std::make_pair(obj, on));
2056  else if (itr->second != on)
2057  i_objectsToSwitch.erase(itr);
2058  else
2059  ASSERT(false);
2060 }
std::map< WorldObject *, bool > i_objectsToSwitch
Definition: Map.h:641
uint32 GetId(void) const
Definition: Map.h:333
uint8 GetTypeId() const
Definition: Object.h:210
uint32 GetInstanceId() const
Definition: Object.h:688
uint32 GetMapId() const
Definition: Object.h:591
#define ASSERT
Definition: Errors.h:29
uint32 GetInstanceId() const
Definition: Map.h:390
bool Map::AddPlayerToMap ( Player player)
virtual

Reimplemented in BattlegroundMap, and InstanceMap.

Definition at line 393 of file Map.cpp.

References AddToGrid(), Player::AddToWorld(), ASSERT, Oregon::ComputeCellCoord(), EnsureGridLoadedForActiveObject(), Object::GetGUIDLow(), WorldObject::GetMap(), Position::GetPositionX(), Position::GetPositionY(), Player::m_clientGUIDs, SendInitSelf(), SendInitTransports(), Player::SetMap(), sLog, TOTAL_NUMBER_OF_CELLS_PER_MAP, and Player::UpdateObjectVisibility().

Referenced by InstanceMap::AddPlayerToMap(), BattlegroundMap::AddPlayerToMap(), WorldSession::HandlePlayerLogin(), and RegressionTestSuite::TestBreathingIssues().

394 {
395  // Check if we are adding to correct map
396  ASSERT (player->GetMap() == this);
397 
399  if (p.x_coord >= TOTAL_NUMBER_OF_CELLS_PER_MAP || p.y_coord >= TOTAL_NUMBER_OF_CELLS_PER_MAP)
400  {
401  sLog.outError("Map::AddToMap: Player (GUID: %u) has invalid coordinates X:%f Y:%f grid cell [%u:%u]", player->GetGUIDLow(), player->GetPositionX(), player->GetPositionY(), p.x_coord, p.y_coord);
402  return false;
403  }
404 
405  player->SetMap(this);
406 
407  Cell cell(p);
408  EnsureGridLoadedForActiveObject(cell, player);
409  AddToGrid(player, cell);
410 
411  player->SetMap(this);
412  player->AddToWorld();
413 
414  SendInitSelf(player);
415  SendInitTransports(player);
416 
417  player->m_clientGUIDs.clear();
418  player->UpdateObjectVisibility(false);
419 
420  return true;
421 }
ClientGUIDs m_clientGUIDs
Definition: Player.h:2459
void AddToGrid(T *object, Cell const &cell)
Definition: Map.cpp:234
Map * GetMap() const
Definition: Object.h:841
void AddToWorld() override
Definition: Player.cpp:1838
void SendInitTransports(Player *player)
Definition: Map.cpp:1953
#define sLog
Log class singleton.
Definition: Log.h:187
uint32 GetGUIDLow() const
Definition: Object.h:166
#define TOTAL_NUMBER_OF_CELLS_PER_MAP
Definition: GridDefines.h:49
float GetPositionY() const
Definition: Position.h:98
void UpdateObjectVisibility(bool forced=true) override
Definition: Player.cpp:18890
CellCoord ComputeCellCoord(float x, float y)
Definition: GridDefines.h:167
void EnsureGridLoadedForActiveObject(Cell const &, WorldObject *object)
Definition: Map.cpp:347
Definition: Cell.h:46
void SetMap(Map *map) override
Definition: Player.cpp:20704
#define ASSERT
Definition: Errors.h:29
float GetPositionX() const
Definition: Position.h:97
void SendInitSelf(Player *player)
Definition: Map.cpp:1917
template<class T >
void Map::AddToActive ( T *  obj)
inline

Definition at line 502 of file Map.h.

Referenced by AddObjectHelper(), AddToMap(), and WorldObject::setActive().

503  {
504  AddToActiveHelper(obj);
505  }
void AddToActiveHelper(T *obj)
Definition: Map.h:653
void Map::AddToActive ( Creature obj)

Definition at line 2167 of file Map.cpp.

References AddToActiveHelper(), Oregon::ComputeGridCoord(), Creature::GetDBTableGUIDLow(), Object::GetEntry(), Object::GetGUIDLow(), getNGrid(), Position::GetPositionX(), Position::GetPositionY(), Creature::GetRespawnPosition(), NGrid< N, ACTIVE_OBJECT, WORLD_OBJECT_TYPES, GRID_OBJECT_TYPES >::incUnloadActiveLock(), Unit::IsPet(), sLog, CoordPair< LIMIT >::x_coord, and CoordPair< LIMIT >::y_coord.

2168 {
2169  AddToActiveHelper(c);
2170 
2171  // also not allow unloading spawn grid to prevent creating creature clone at load
2172  if (!c->IsPet() && c->GetDBTableGUIDLow())
2173  {
2174  float x, y, z;
2175  c->GetRespawnPosition(x, y, z);
2177  if (getNGrid(p.x_coord, p.y_coord))
2179  else
2180  {
2181  GridCoord p2 = Oregon::ComputeGridCoord(c->GetPositionX(), c->GetPositionY());
2182  sLog.outError("Active creature (GUID: %u Entry: %u) added to grid[%u,%u] but spawn grid[%u,%u] not loaded.",
2183  c->GetGUIDLow(), c->GetEntry(), p.x_coord, p.y_coord, p2.x_coord, p2.y_coord);
2184  }
2185  }
2186 }
NGridType * getNGrid(uint32 x, uint32 y) const
Definition: Map.h:572
#define sLog
Log class singleton.
Definition: Log.h:187
void AddToActiveHelper(T *obj)
Definition: Map.h:653
uint32 y_coord
Definition: GridDefines.h:142
uint32 x_coord
Definition: GridDefines.h:141
void incUnloadActiveLock()
Definition: NGrid.h:116
GridCoord ComputeGridCoord(float x, float y)
Definition: GridDefines.h:162
template<class T >
void Map::AddToActiveHelper ( T *  obj)
inlineprivate

Definition at line 653 of file Map.h.

Referenced by AddToActive().

654  {
655  m_activeNonPlayers.insert(obj);
656  }
ActiveNonPlayers m_activeNonPlayers
Definition: Map.h:611
template<>
void Map::AddToGrid ( Creature obj,
Cell const &  cell 
)

Definition at line 244 of file Map.cpp.

References AddWorldObject(), Cell::CellX(), Cell::CellY(), NGrid< N, ACTIVE_OBJECT, WORLD_OBJECT_TYPES, GRID_OBJECT_TYPES >::GetGridType(), getNGrid(), Cell::GridX(), Cell::GridY(), WorldObject::IsWorldObject(), and Creature::SetCurrentCell().

245 {
246  NGridType* grid = getNGrid(cell.GridX(), cell.GridY());
247  if (obj->IsWorldObject())
248  grid->GetGridType(cell.CellX(), cell.CellY()).AddWorldObject(obj);
249  else
250  grid->GetGridType(cell.CellX(), cell.CellY()).AddGridObject(obj);
251 
252  obj->SetCurrentCell(cell);
253 }
Definition: NGrid.h:75
NGridType * getNGrid(uint32 x, uint32 y) const
Definition: Map.h:572
void SetCurrentCell(Cell const &cell)
Definition: Creature.h:642
bool IsWorldObject() const
Definition: Object.cpp:1112
GridType & GetGridType(const uint32 x, const uint32 y)
Definition: NGrid.h:85
void AddWorldObject(WorldObject *obj)
Definition: Map.h:479
template<>
void Map::AddToGrid ( Corpse obj,
Cell const &  cell 
)

Definition at line 256 of file Map.cpp.

References AddWorldObject(), Cell::CellX(), Cell::CellY(), NGrid< N, ACTIVE_OBJECT, WORLD_OBJECT_TYPES, GRID_OBJECT_TYPES >::GetGridType(), getNGrid(), Cell::GridX(), Cell::GridY(), NGrid< N, ACTIVE_OBJECT, WORLD_OBJECT_TYPES, GRID_OBJECT_TYPES >::isGridObjectDataLoaded(), and WorldObject::IsWorldObject().

257 {
258  NGridType* grid = getNGrid(cell.GridX(), cell.GridY());
259  if (grid->isGridObjectDataLoaded())
260  {
261  if (obj->IsWorldObject())
262  grid->GetGridType(cell.CellX(), cell.CellY()).AddWorldObject(obj);
263  else
264  grid->GetGridType(cell.CellX(), cell.CellY()).AddGridObject(obj);
265  }
266 }
Definition: NGrid.h:75
NGridType * getNGrid(uint32 x, uint32 y) const
Definition: Map.h:572
bool IsWorldObject() const
Definition: Object.cpp:1112
GridType & GetGridType(const uint32 x, const uint32 y)
Definition: NGrid.h:85
void AddWorldObject(WorldObject *obj)
Definition: Map.h:479
bool isGridObjectDataLoaded() const
Definition: NGrid.h:108
template<class T >
void Map::AddToGrid ( T *  object,
Cell const &  cell 
)
private

Definition at line 234 of file Map.cpp.

References Cell::CellX(), Cell::CellY(), NGrid< N, ACTIVE_OBJECT, WORLD_OBJECT_TYPES, GRID_OBJECT_TYPES >::GetGridType(), getNGrid(), Cell::GridX(), and Cell::GridY().

Referenced by AddPlayerToMap(), AddToMap(), CreatureCellRelocation(), and PlayerRelocation().

235 {
236  NGridType* grid = getNGrid(cell.GridX(), cell.GridY());
237  if (obj->IsWorldObject())
238  grid->GetGridType(cell.CellX(), cell.CellY()).template AddWorldObject<T>(obj);
239  else
240  grid->GetGridType(cell.CellX(), cell.CellY()).template AddGridObject<T>(obj);
241 }
Definition: NGrid.h:75
NGridType * getNGrid(uint32 x, uint32 y) const
Definition: Map.h:572
GridType & GetGridType(const uint32 x, const uint32 y)
Definition: NGrid.h:85
template<class T >
template bool Map::AddToMap ( T *  )

Definition at line 424 of file Map.cpp.

References AddToActive(), AddToGrid(), Oregon::ComputeCellCoord(), DEBUG_LOG, EnsureGridCreated(), EnsureGridLoadedForActiveObject(), Cell::GridX(), Cell::GridY(), GUID_LOPART, sLog, TOTAL_NUMBER_OF_CELLS_PER_MAP, UI64FMTD, CoordPair< LIMIT >::x_coord, and CoordPair< LIMIT >::y_coord.

Referenced by Battleground::AddCreature(), Player::BuildPlayerRepop(), ObjectAccessor::ConvertCorpseForPlayer(), Spell::EffectAddFarsight(), Spell::EffectPersistentAA(), Spell::EffectTameCreature(), Spell::EffectTransmitted(), GameEventMgr::GameEventSpawn(), ChatHandler::HandleCreatePetCommand(), Pet::LoadPetFromDB(), GameObject::Refresh(), RemoveFromActive(), ScriptsProcess(), PoolGroup< GameObject >::Spawn1Object(), Battleground::SpawnBGObject(), Player::SummonPet(), and GameObject::Update().

425 {
426  if (obj->IsInWorld()) // need some clean up later
427  {
428  obj->UpdateObjectVisibility(true);
429  return true;
430  }
431 
432  CellCoord p = Oregon::ComputeCellCoord(obj->GetPositionX(), obj->GetPositionY());
434  {
435  sLog.outError("Map::AddToMap: Object " UI64FMTD " has invalid coordinates X:%f Y:%f grid cell [%u:%u]", obj->GetGUID(), obj->GetPositionX(), obj->GetPositionY(), p.x_coord, p.y_coord);
436  return false;
437  }
438 
439  Cell cell(p);
440  if (obj->isActiveObject())
442  else
443  EnsureGridCreated(GridCoord(cell.GridX(), cell.GridY()));
444 
445  AddToGrid(obj, cell);
446  obj->AddToWorld();
447 
448  if (obj->isActiveObject())
449  AddToActive(obj);
450 
451  DEBUG_LOG("Object %u enters grid[%u,%u]", GUID_LOPART(obj->GetGUID()), cell.GridX(), cell.GridY());
452 
453  //trigger needs to cast spell, if not update, cannot see visual
454  obj->UpdateObjectVisibility(true);
455 
456  return true;
457 }
#define GUID_LOPART(x)
Definition: ObjectGuid.h:110
void AddToGrid(T *object, Cell const &cell)
Definition: Map.cpp:234
#define sLog
Log class singleton.
Definition: Log.h:187
uint32 y_coord
Definition: GridDefines.h:142
uint32 x_coord
Definition: GridDefines.h:141
#define TOTAL_NUMBER_OF_CELLS_PER_MAP
Definition: GridDefines.h:49
#define UI64FMTD
Definition: Common.h:149
void EnsureGridCreated(const GridCoord &)
Definition: Map.cpp:319
#define DEBUG_LOG(...)
Definition: Log.h:194
CellCoord ComputeCellCoord(float x, float y)
Definition: GridDefines.h:167
void EnsureGridLoadedForActiveObject(Cell const &, WorldObject *object)
Definition: Map.cpp:347
Definition: Cell.h:46
void AddToActive(T *obj)
Definition: Map.h:502
CoordPair< MAX_NUMBER_OF_GRIDS > GridCoord
Definition: GridDefines.h:145
template<class T >
void Map::AddType ( T *  obj)
private
void Map::AddWorldObject ( WorldObject obj)
inline

Definition at line 479 of file Map.h.

Referenced by AddToGrid(), WorldObject::SetMap(), and SwitchGridContainers().

480  {
481  i_worldObjects.insert(obj);
482  }
std::set< WorldObject * > i_worldObjects
Definition: Map.h:642
void Map::Balance ( )
inline

Definition at line 532 of file Map.h.

Referenced by EnsureGridLoaded().

532 { m_dyn_tree.balance(); }
DynamicMapTree m_dyn_tree
Definition: Map.h:624
void Map::buildNGridLinkage ( NGridType pNGridType)
inlineprivate

Definition at line 564 of file Map.h.

References NGrid< N, ACTIVE_OBJECT, WORLD_OBJECT_TYPES, GRID_OBJECT_TYPES >::link().

Referenced by EnsureGridCreated().

565  {
566  pNGridType->link(this);
567  }
void link(GridRefManager< NGrid< N, ACTIVE_OBJECT, WORLD_OBJECT_TYPES, GRID_OBJECT_TYPES > > *pTo)
Definition: NGrid.h:104
virtual EnterState Map::CannotEnter ( Player )
inlinevirtual
bool Map::CanUnload ( uint32  diff)
inline

Definition at line 274 of file Map.h.

275  {
276  if (!m_unloadTimer) return false;
277  if (m_unloadTimer <= diff) return true;
278  m_unloadTimer -= diff;
279  return false;
280  }
uint32 m_unloadTimer
Definition: Map.h:602
bool Map::CheckGridIntegrity ( Creature c,
bool  moved 
) const

Definition at line 1872 of file Map.cpp.

References Cell::CellX(), Cell::CellY(), Creature::GetCurrentCell(), Object::GetGUIDLow(), Position::GetPositionX(), Position::GetPositionY(), Cell::GridX(), Cell::GridY(), and sLog.

Referenced by CreatureRelocation().

1873 {
1874  Cell const& cur_cell = c->GetCurrentCell();
1875 
1876  Cell xy_cell(c->GetPositionX(), c->GetPositionY());
1877  if (xy_cell != cur_cell)
1878  {
1879  sLog.outMap("Creature (GUID: %u) X: %f Y: %f (%s) is in grid[%u,%u]cell[%u,%u] instead of grid[%u,%u]cell[%u,%u]",
1880  c->GetGUIDLow(),
1881  c->GetPositionX(), c->GetPositionY(), (moved ? "final" : "original"),
1882  cur_cell.GridX(), cur_cell.GridY(), cur_cell.CellX(), cur_cell.CellY(),
1883  xy_cell.GridX(), xy_cell.GridY(), xy_cell.CellX(), xy_cell.CellY());
1884  return true; // not crash at error, just output error in debug mode
1885  }
1886 
1887  return true;
1888 }
uint32 CellY() const
Definition: Cell.h:72
#define sLog
Log class singleton.
Definition: Log.h:187
uint32 GetGUIDLow() const
Definition: Object.h:166
float GetPositionY() const
Definition: Position.h:98
uint32 CellX() const
Definition: Cell.h:71
uint32 GridY() const
Definition: Cell.h:74
Definition: Cell.h:46
Cell const & GetCurrentCell() const
Definition: Creature.h:638
float GetPositionX() const
Definition: Position.h:97
uint32 GridX() const
Definition: Cell.h:73
bool Map::Contains ( const GameObjectModel mdl) const
inline

Definition at line 535 of file Map.h.

Referenced by Transport::TeleportTransport().

535 { return m_dyn_tree.contains(mdl);}
DynamicMapTree m_dyn_tree
Definition: Map.h:624
bool contains(const GameObjectModel &) const
bool Map::CreatureCellRelocation ( Creature creature,
Cell  new_cell 
)
private

Definition at line 812 of file Map.cpp.

References AddToGrid(), Cell::CellX(), Cell::CellY(), Cell::DiffCell(), Cell::DiffGrid(), EnsureGridCreated(), EnsureGridLoadedForActiveObject(), Creature::GetCurrentCell(), Object::GetEntry(), Object::GetGUIDLow(), Cell::GridX(), Cell::GridY(), WorldObject::isActiveObject(), IsGridLoaded(), GridObject< T >::RemoveFromGrid(), and sLog.

Referenced by CreatureRespawnRelocation(), and MoveAllCreaturesInMoveList().

813 {
814  Cell const& old_cell = c->GetCurrentCell();
815  if (!old_cell.DiffGrid(new_cell)) // in same grid
816  {
817  // if in same cell then none do
818  if (old_cell.DiffCell(new_cell))
819  {
820  #ifdef OREGON_DEBUG
821  sLog.outMap("Creature (GUID: %u Entry: %u) moved in grid[%u,%u] from cell[%u,%u] to cell[%u,%u].", c->GetGUIDLow(), c->GetEntry(), old_cell.GridX(), old_cell.GridY(), old_cell.CellX(), old_cell.CellY(), new_cell.CellX(), new_cell.CellY());
822  #endif
823 
824  c->RemoveFromGrid();
825  AddToGrid(c, new_cell);
826  }
827  else
828  {
829  #ifdef OREGON_DEBUG
830  sLog.outMap("Creature (GUID: %u Entry: %u) moved in same grid[%u,%u]cell[%u,%u].", c->GetGUIDLow(), c->GetEntry(), old_cell.GridX(), old_cell.GridY(), old_cell.CellX(), old_cell.CellY());
831  #endif
832  }
833 
834  return true;
835  }
836 
837  // in diff. grids but active creature
838  if (c->isActiveObject())
839  {
840  EnsureGridLoadedForActiveObject(new_cell, c);
841 
842  #ifdef OREGON_DEBUG
843  sLog.outMap("Active creature (GUID: %u Entry: %u) moved from grid[%u,%u]cell[%u,%u] to grid[%u,%u]cell[%u,%u].", c->GetGUIDLow(), c->GetEntry(), old_cell.GridX(), old_cell.GridY(), old_cell.CellX(), old_cell.CellY(), new_cell.GridX(), new_cell.GridY(), new_cell.CellX(), new_cell.CellY());
844  #endif
845 
846  c->RemoveFromGrid();
847  AddToGrid(c, new_cell);
848 
849  return true;
850  }
851 
852  // in diff. loaded grid normal creature
853  if (IsGridLoaded(GridCoord(new_cell.GridX(), new_cell.GridY())))
854  {
855  #ifdef OREGON_DEBUG
856  sLog.outMap("Creature (GUID: %u Entry: %u) moved from grid[%u,%u]cell[%u,%u] to grid[%u,%u]cell[%u,%u].", c->GetGUIDLow(), c->GetEntry(), old_cell.GridX(), old_cell.GridY(), old_cell.CellX(), old_cell.CellY(), new_cell.GridX(), new_cell.GridY(), new_cell.CellX(), new_cell.CellY());
857  #endif
858 
859  c->RemoveFromGrid();
860  EnsureGridCreated(GridCoord(new_cell.GridX(), new_cell.GridY()));
861  AddToGrid(c, new_cell);
862 
863  return true;
864  }
865 
866  // fail to move: normal creature attempt move to unloaded grid
867  #ifdef OREGON_DEBUG
868  sLog.outMap("Creature (GUID: %u Entry: %u) attempted to move from grid[%u,%u]cell[%u,%u] to unloaded grid[%u,%u]cell[%u,%u].", c->GetGUIDLow(), c->GetEntry(), old_cell.GridX(), old_cell.GridY(), old_cell.CellX(), old_cell.CellY(), new_cell.GridX(), new_cell.GridY(), new_cell.CellX(), new_cell.CellY());
869  #endif
870  return false;
871 }
void AddToGrid(T *object, Cell const &cell)
Definition: Map.cpp:234
uint32 CellY() const
Definition: Cell.h:72
bool DiffCell(const Cell &cell) const
Definition: Cell.h:59
bool DiffGrid(const Cell &cell) const
Definition: Cell.h:65
#define sLog
Log class singleton.
Definition: Log.h:187
bool IsGridLoaded(float x, float y) const
Definition: Map.h:307
void EnsureGridCreated(const GridCoord &)
Definition: Map.cpp:319
uint32 CellX() const
Definition: Cell.h:71
uint32 GridY() const
Definition: Cell.h:74
void EnsureGridLoadedForActiveObject(Cell const &, WorldObject *object)
Definition: Map.cpp:347
Definition: Cell.h:46
CoordPair< MAX_NUMBER_OF_GRIDS > GridCoord
Definition: GridDefines.h:145
uint32 GridX() const
Definition: Cell.h:73
void Map::CreatureRelocation ( Creature creature,
float  x,
float  y,
float  z,
float  ang,
bool  respawnRelocationOnFail = true 
)

Definition at line 734 of file Map.cpp.

References AddCreatureToMoveList(), ASSERT, Cell::CellX(), Cell::CellY(), CheckGridIntegrity(), Cell::DiffCell(), Cell::DiffGrid(), Creature::GetCurrentCell(), Object::GetEntry(), Object::GetGUIDLow(), getNGrid(), Cell::GridX(), Cell::GridY(), Position::Relocate(), sLog, and Unit::UpdateObjectVisibility().

Referenced by Spell::EffectSummonDeadPet(), ChatHandler::HandleNpcMoveCommand(), and Creature::RemoveCorpse().

735 {
736  ASSERT(CheckGridIntegrity(creature, false));
737 
738  Cell old_cell = creature->GetCurrentCell();
739  Cell new_cell(x, y);
740 
741  if (!respawnRelocationOnFail && !getNGrid(new_cell.GridX(), new_cell.GridY()))
742  return;
743 
744  // delay creature move for grid/cell to grid/cell moves
745  if (old_cell.DiffCell(new_cell) || old_cell.DiffGrid(new_cell))
746  {
747  #ifdef OREGON_DEBUG
748  sLog.outMap("Creature (GUID: %u Entry: %u) added to moving list from grid[%u,%u]cell[%u,%u] to grid[%u,%u]cell[%u,%u].", creature->GetGUIDLow(), creature->GetEntry(), old_cell.GridX(), old_cell.GridY(), old_cell.CellX(), old_cell.CellY(), new_cell.GridX(), new_cell.GridY(), new_cell.CellX(), new_cell.CellY());
749  #endif
750  AddCreatureToMoveList(creature, x, y, z, ang);
751  // in diffcell/diffgrid case notifiers called at finishing move creature in Map::MoveAllCreaturesInMoveList
752  }
753  else
754  {
755  creature->Relocate(x, y, z, ang);
756  creature->UpdateObjectVisibility(false);
757  }
758 
759  ASSERT(CheckGridIntegrity(creature, true));
760 }
void AddCreatureToMoveList(Creature *c, float x, float y, float z, float ang)
Definition: Map.cpp:762
uint32 CellY() const
Definition: Cell.h:72
bool DiffCell(const Cell &cell) const
Definition: Cell.h:59
NGridType * getNGrid(uint32 x, uint32 y) const
Definition: Map.h:572
bool DiffGrid(const Cell &cell) const
Definition: Cell.h:65
#define sLog
Log class singleton.
Definition: Log.h:187
void UpdateObjectVisibility(bool forced=true) override
Definition: Unit.cpp:13525
uint32 GetGUIDLow() const
Definition: Object.h:166
void Relocate(float x, float y)
Definition: Position.h:65
uint32 CellX() const
Definition: Cell.h:71
uint32 GridY() const
Definition: Cell.h:74
bool CheckGridIntegrity(Creature *c, bool moved) const
Definition: Map.cpp:1872
Definition: Cell.h:46
Cell const & GetCurrentCell() const
Definition: Creature.h:638
#define ASSERT
Definition: Errors.h:29
uint32 GetEntry() const
Definition: Object.h:192
uint32 GridX() const
Definition: Cell.h:73
bool Map::CreatureRespawnRelocation ( Creature c)

Definition at line 873 of file Map.cpp.

References Cell::CellX(), Cell::CellY(), MotionMaster::Clear(), Unit::CombatStop(), CreatureCellRelocation(), Creature::GetCurrentCell(), Object::GetEntry(), Object::GetGUIDLow(), Unit::GetMotionMaster(), Creature::GetRespawnPosition(), Cell::GridX(), Cell::GridY(), MotionMaster::Initialize(), Position::Relocate(), sLog, and Unit::UpdateObjectVisibility().

Referenced by MoveAllCreaturesInMoveList(), Creature::setDeathState(), and ObjectGridEvacuator::Visit().

874 {
875  float resp_x, resp_y, resp_z, resp_o;
876  c->GetRespawnPosition(resp_x, resp_y, resp_z, &resp_o);
877 
878  Cell resp_cell(resp_x, resp_y);
879 
880  c->CombatStop();
881  c->GetMotionMaster()->Clear();
882 
883  #ifdef OREGON_DEBUG
884  sLog.outMap("Creature (GUID: %u Entry: %u) moved from grid[%u,%u]cell[%u,%u] to respawn grid[%u,%u]cell[%u,%u].", c->GetGUIDLow(), c->GetEntry(), c->GetCurrentCell().GridX(), c->GetCurrentCell().GridY(), c->GetCurrentCell().CellX(), c->GetCurrentCell().CellY(), resp_cell.GridX(), resp_cell.GridY(), resp_cell.CellX(), resp_cell.CellY());
885  #endif
886 
887  // teleport it to respawn point (like normal respawn if player see)
888  if (CreatureCellRelocation(c, resp_cell))
889  {
890  c->Relocate(resp_x, resp_y, resp_z, resp_o);
891  c->GetMotionMaster()->Initialize(); // prevent possible problems with default move generators
892  //CreatureRelocationNotify(c,resp_cell,resp_cell.cellPair());
893  c->UpdateObjectVisibility(false);
894  return true;
895  }
896  else
897  return false;
898 }
void Clear(bool reset=true)
Definition: MotionMaster.h:145
uint32 CellY() const
Definition: Cell.h:72
MotionMaster * GetMotionMaster()
Definition: Unit.h:1890
#define sLog
Log class singleton.
Definition: Log.h:187
void UpdateObjectVisibility(bool forced=true) override
Definition: Unit.cpp:13525
uint32 GetGUIDLow() const
Definition: Object.h:166
void Relocate(float x, float y)
Definition: Position.h:65
uint32 CellX() const
Definition: Cell.h:71
void CombatStop(bool cast=false)
Definition: Unit.cpp:7518
uint32 GridY() const
Definition: Cell.h:74
Definition: Cell.h:46
Cell const & GetCurrentCell() const
Definition: Creature.h:638
bool CreatureCellRelocation(Creature *creature, Cell new_cell)
Definition: Map.cpp:812
uint32 GetEntry() const
Definition: Object.h:192
void GetRespawnPosition(float &x, float &y, float &z, float *ori=NULL, float *dist=NULL) const
Definition: Creature.cpp:2321
void Initialize()
uint32 GridX() const
Definition: Cell.h:73
void Map::DelayedUpdate ( const uint32  diff)
virtual

Reimplemented in MapInstanced.

Definition at line 2016 of file Map.cpp.

References ASSERT, GridRefManager< OBJECT >::end(), NGrid< N, ACTIVE_OBJECT, WORLD_OBJECT_TYPES, GRID_OBJECT_TYPES >::GetGridState(), IsBattlegroundOrArena(), MAX_GRID_STATE, RemoveAllObjectsInRemoveList(), and GridState::Update().

Referenced by MapInstanced::DelayedUpdate().

2017 {
2019 
2020  // Don't unload grids if it's battleground, since we may have manually added GOs,creatures, those doesn't load from DB at grid re-load !
2021  // This isn't really bother us, since as soon as we have instanced BG-s, the whole map unloads as the BG gets ended
2022  if (!IsBattlegroundOrArena())
2023  {
2025  {
2026  NGridType* grid = i->GetSource();
2027  GridInfo* info = i->GetSource()->getGridInfoRef();
2028  ++i; // The update might delete the map and we need the next map before the iterator gets invalid
2029  ASSERT(grid->GetGridState() >= 0 && grid->GetGridState() < MAX_GRID_STATE);
2030  si_GridStates[grid->GetGridState()]->Update(*this, *grid, *info, t_diff);
2031  }
2032  }
2033 }
Definition: NGrid.h:75
bool IsBattlegroundOrArena() const
Definition: Map.h:447
Definition: NGrid.h:30
grid_state_t GetGridState(void) const
Definition: NGrid.h:99
virtual void Update(Map &, NGridType &, GridInfo &, const uint32 t_diff) const =0
void RemoveAllObjectsInRemoveList()
Definition: Map.cpp:2062
iterator end()
#define ASSERT
Definition: Errors.h:29
GridState * si_GridStates[MAX_GRID_STATE]
Definition: Map.cpp:38
template<class T >
void Map::DeleteFromWorld ( T *  obj)
private

Definition at line 304 of file Map.cpp.

Referenced by RemoveFromMap(), and RemovePlayerFromMap().

305 {
306  // Note: In case resurrectable corpse and pet its removed from global lists in own destructor
307  delete obj;
308 }
void Map::DeleteStateMachine ( )
static

Definition at line 194 of file Map.cpp.

References GRID_STATE_ACTIVE, GRID_STATE_IDLE, GRID_STATE_INVALID, and GRID_STATE_REMOVAL.

Referenced by MapManager::~MapManager().

195 {
200 }
GridState * si_GridStates[MAX_GRID_STATE]
Definition: Map.cpp:38
void Map::EnsureGridCreated ( const GridCoord p)
private

Definition at line 319 of file Map.cpp.

References buildNGridLinkage(), CONFIG_GRID_UNLOAD, GetId(), getNGrid(), GRID_STATE_IDLE, GridMaps, i_gridExpiry, i_InstanceId, LoadMapAndVMap(), MAX_NUMBER_OF_GRIDS, NGrid< N, ACTIVE_OBJECT, WORLD_OBJECT_TYPES, GRID_OBJECT_TYPES >::SetGridState(), setNGrid(), sLog, sWorld, CoordPair< LIMIT >::x_coord, and CoordPair< LIMIT >::y_coord.

Referenced by AddToMap(), CreatureCellRelocation(), EnsureGridLoaded(), GetGrid(), and LoadMap().

320 {
321  if (!getNGrid(p.x_coord, p.y_coord))
322  {
323  Guard guard(*this);
324  if (!getNGrid(p.x_coord, p.y_coord))
325  {
326  sLog.outMap("Creating grid[%u,%u] for map %u instance %u", p.x_coord, p.y_coord, GetId(), i_InstanceId);
327 
329  p.x_coord, p.y_coord);
330 
331  // build a linkage between this map and NGridType
333 
335 
336  //z coord
337  int gx = (MAX_NUMBER_OF_GRIDS - 1) - p.x_coord;
338  int gy = (MAX_NUMBER_OF_GRIDS - 1) - p.y_coord;
339 
340  if (!GridMaps[gx][gy])
341  LoadMapAndVMap(gx, gy);
342  }
343  }
344 }
time_t i_gridExpiry
Definition: Map.h:625
NGridType * getNGrid(uint32 x, uint32 y) const
Definition: Map.h:572
#define sLog
Log class singleton.
Definition: Log.h:187
#define MAX_NUMBER_OF_GRIDS
Definition: GridDefines.h:33
uint32 y_coord
Definition: GridDefines.h:142
uint32 x_coord
Definition: GridDefines.h:141
GridMap * GridMaps[MAX_NUMBER_OF_GRIDS][MAX_NUMBER_OF_GRIDS]
Definition: Map.h:632
uint32 GetId(void) const
Definition: Map.h:333
void setNGrid(NGridType *grid, uint32 x, uint32 y)
Definition: Map.cpp:2006
void LoadMapAndVMap(int gx, int gy)
Definition: Map.cpp:175
void SetGridState(grid_state_t s)
Definition: NGrid.h:100
void buildNGridLinkage(NGridType *pNGridType)
Definition: Map.h:564
uint32 i_InstanceId
Definition: Map.h:601
#define sWorld
Definition: World.h:860
NGrid< MAX_NUMBER_OF_CELLS, Player, AllWorldObjectTypes, AllGridObjectTypes > NGridType
Definition: GridDefines.h:67
Oregon::ObjectLevelLockable< Map, ACE_Thread_Mutex >::Lock Guard
Definition: Map.h:597
bool Map::EnsureGridLoaded ( Cell const &  )
private

Definition at line 363 of file Map.cpp.

References ObjectAccessor::AddCorpsesToGrid(), ASSERT, Balance(), Cell::CellX(), Cell::CellY(), EnsureGridCreated(), NGrid< N, ACTIVE_OBJECT, WORLD_OBJECT_TYPES, GRID_OBJECT_TYPES >::GetGridType(), GetId(), getNGrid(), Cell::GridX(), Cell::GridY(), i_InstanceId, Oregon::Singleton< ObjectAccessor, Oregon::ClassLevelLockable< ObjectAccessor, ACE_Thread_Mutex > >::Instance(), isGridObjectDataLoaded(), setGridObjectDataLoaded(), and sLog.

Referenced by EnsureGridLoadedForActiveObject(), and LoadGrid().

364 {
365  EnsureGridCreated(GridCoord(cell.GridX(), cell.GridY()));
366  NGridType* grid = getNGrid(cell.GridX(), cell.GridY());
367 
368  ASSERT(grid != NULL);
369  if (!isGridObjectDataLoaded(cell.GridX(), cell.GridY()))
370  {
371  sLog.outMap("Loading grid[%u,%u] for map %u instance %u", cell.GridX(), cell.GridY(), GetId(), i_InstanceId);
372 
373  setGridObjectDataLoaded(true, cell.GridX(), cell.GridY());
374 
375  ObjectGridLoader loader(*grid, this, cell);
376  loader.LoadN();
377 
378  // Add resurrectable corpses to world object list in grid
379  ObjectAccessor::Instance().AddCorpsesToGrid(GridCoord(cell.GridX(), cell.GridY()), grid->GetGridType(cell.CellX(), cell.CellY()), this);
380 
381  Balance();
382  return true;
383  }
384 
385  return false;
386 }
Definition: NGrid.h:75
void AddCorpsesToGrid(GridCoord const &gridpair, GridType &grid, Map *map)
NGridType * getNGrid(uint32 x, uint32 y) const
Definition: Map.h:572
#define sLog
Log class singleton.
Definition: Log.h:187
GridType & GetGridType(const uint32 x, const uint32 y)
Definition: NGrid.h:85
uint32 GetId(void) const
Definition: Map.h:333
bool isGridObjectDataLoaded(uint32 x, uint32 y) const
Definition: Map.h:579
void EnsureGridCreated(const GridCoord &)
Definition: Map.cpp:319
void Balance()
Definition: Map.h:532
uint32 i_InstanceId
Definition: Map.h:601
#define ASSERT
Definition: Errors.h:29
void setGridObjectDataLoaded(bool pLoaded, uint32 x, uint32 y)
Definition: Map.h:583
CoordPair< MAX_NUMBER_OF_GRIDS > GridCoord
Definition: GridDefines.h:145
void Map::EnsureGridLoadedForActiveObject ( Cell const &  ,
WorldObject object 
)
private

Definition at line 347 of file Map.cpp.

References ASSERT, EnsureGridLoaded(), NGrid< N, ACTIVE_OBJECT, WORLD_OBJECT_TYPES, GRID_OBJECT_TYPES >::GetGridState(), Object::GetGUID(), GetId(), getNGrid(), GRID_STATE_ACTIVE, Cell::GridX(), Cell::GridY(), ResetGridExpiry(), NGrid< N, ACTIVE_OBJECT, WORLD_OBJECT_TYPES, GRID_OBJECT_TYPES >::SetGridState(), sLog, and UI64FMTD.

Referenced by AddPlayerToMap(), AddToMap(), CreatureCellRelocation(), and PlayerRelocation().

348 {
349  EnsureGridLoaded(cell);
350  NGridType* grid = getNGrid(cell.GridX(), cell.GridY());
351  ASSERT(grid != NULL);
352 
353  // refresh grid state & timer
354  if (grid->GetGridState() != GRID_STATE_ACTIVE)
355  {
356  sLog.outDebug("Active object " UI64FMTD " triggers loading of grid [%u, %u] on map %u", object->GetGUID(), cell.GridX(), cell.GridY(), GetId());
357  ResetGridExpiry(*grid, 0.1f);
359  }
360 }
Definition: NGrid.h:75
bool EnsureGridLoaded(Cell const &)
Definition: Map.cpp:363
grid_state_t GetGridState(void) const
Definition: NGrid.h:99
NGridType * getNGrid(uint32 x, uint32 y) const
Definition: Map.h:572
#define sLog
Log class singleton.
Definition: Log.h:187
uint32 GetId(void) const
Definition: Map.h:333
#define UI64FMTD
Definition: Common.h:149
void SetGridState(grid_state_t s)
Definition: NGrid.h:100
#define ASSERT
Definition: Errors.h:29
void ResetGridExpiry(NGridType &grid, float factor=1) const
Definition: Map.h:324
const uint64 & GetGUID() const
Definition: Object.h:162
bool Map::ExistMap ( uint32  mapid,
int  gx,
int  gy 
)
static

Definition at line 57 of file Map.cpp.

References map_fileheader::mapMagic, sLog, snprintf, sWorld, and map_fileheader::versionMagic.

Referenced by MapManager::ExistMapAndVMap(), and ChatHandler::HandleGPSCommand().

58 {
59  int len = sWorld.GetDataPath().length() + strlen("maps/%03u%02u%02u.map") + 1;
60  char* tmp = new char[len];
61  snprintf(tmp, len, (char*)(sWorld.GetDataPath() + "maps/%03u%02u%02u.map").c_str(), mapid, gx, gy);
62 
63  bool ret = false;
64  FILE* pf = fopen(tmp, "rb");
65 
66  if (!pf)
67  sLog.outError("Map file '%s': does not exist!", tmp);
68  else
69  {
70  map_fileheader header;
71  if (fread(&header, sizeof(header), 1, pf) == 1)
72  {
73  if (header.mapMagic != uint32(MAP_MAGIC) || header.versionMagic != uint32(MAP_VERSION_MAGIC))
74  sLog.outError("Map file '%s' is from an incompatible clientversion. Please recreate using the mapextractor.", tmp);
75  else
76  ret = true;
77  }
78  fclose(pf);
79  }
80  delete [] tmp;
81  return ret;
82 }
#define snprintf
Definition: Common.h:129
#define sLog
Log class singleton.
Definition: Log.h:187
uint32 mapMagic
Definition: Map.h:77
#define sWorld
Definition: World.h:860
ACE_UINT32 uint32
Definition: Define.h:71
uint32 versionMagic
Definition: Map.h:78
bool Map::ExistVMap ( uint32  mapid,
int  gx,
int  gy 
)
static

Definition at line 84 of file Map.cpp.

References VMAP::VMapFactory::createOrGetVMapManager(), sLog, and sWorld.

Referenced by MapManager::ExistMapAndVMap(), and ChatHandler::HandleGPSCommand().

85 {
87  {
88  if (vmgr->isMapLoadingEnabled())
89  {
90  bool exists = vmgr->existsMap((sWorld.GetDataPath() + "vmaps").c_str(), mapid, gx, gy);
91  if (!exists)
92  {
93  std::string name = vmgr->getDirFileName(mapid, gx, gy);
94  sLog.outError("VMap file '%s' is missing or points to wrong version of vmap file. Redo vmaps with latest version of vmap_assembler.exe.", (sWorld.GetDataPath() + "vmaps/" + name).c_str());
95  return false;
96  }
97  }
98  }
99 
100  return true;
101 }
#define sLog
Log class singleton.
Definition: Log.h:187
static IVMapManager * createOrGetVMapManager()
#define sWorld
Definition: World.h:860
uint16 Map::GetAreaFlag ( float  x,
float  y,
float  z,
bool *  isOutdoors = 0 
) const

Definition at line 1682 of file Map.cpp.

References WMOAreaTableEntry::areaId, AreaTableEntry::exploreFlag, GetAreaEntryByAreaID(), GetAreaFlagByMapId(), GetAreaInfo(), GetGrid(), GetWMOAreaTableEntryByTripple(), i_mapEntry, IsOutdoorWMO(), and MapEntry::MapID.

Referenced by Player::CheckAreaExploreAndOutdoor(), and MapManager::GetAreaFlag().

1683 {
1684  uint32 mogpFlags;
1685  int32 adtId, rootId, groupId;
1686  WMOAreaTableEntry const* wmoEntry = 0;
1687  AreaTableEntry const* atEntry = 0;
1688  bool haveAreaInfo = false;
1689 
1690  if (GetAreaInfo(x, y, z, mogpFlags, adtId, rootId, groupId))
1691  {
1692  haveAreaInfo = true;
1693  if ((wmoEntry = GetWMOAreaTableEntryByTripple(rootId, adtId, groupId)))
1694  atEntry = GetAreaEntryByAreaID(wmoEntry->areaId);
1695  }
1696 
1697  uint16 areaflag;
1698 
1699  if (atEntry)
1700  areaflag = atEntry->exploreFlag;
1701  else
1702  {
1703  if (GridMap* gmap = const_cast<Map*>(this)->GetGrid(x, y))
1704  areaflag = gmap->getArea(x, y);
1705  // this used while not all *.map files generated (instances)
1706  else
1707  areaflag = GetAreaFlagByMapId(i_mapEntry->MapID);
1708  }
1709 
1710  if (isOutdoors)
1711  {
1712  if (haveAreaInfo)
1713  *isOutdoors = IsOutdoorWMO(mogpFlags, i_mapEntry->MapID);
1714  else
1715  *isOutdoors = true;
1716  }
1717  return areaflag;
1718 }
bool GetAreaInfo(float x, float y, float z, uint32 &mogpflags, int32 &adtId, int32 &rootId, int32 &groupId) const
Definition: Map.cpp:1663
AreaTableEntry const * GetAreaEntryByAreaID(uint32 area_id)
Definition: DBCStores.cpp:623
MapEntry const * i_mapEntry
Definition: Map.h:599
uint32 MapID
Definition: DBCStructure.h:514
GridMap * GetGrid(float x, float y)
Definition: Map.cpp:1561
Definition: Map.h:155
WMOAreaTableEntry const * GetWMOAreaTableEntryByTripple(int32 rootid, int32 adtid, int32 groupid)
Definition: DBCStores.cpp:615
ACE_INT32 int32
Definition: Define.h:67
uint32 exploreFlag
Definition: DBCStructure.h:44
bool IsOutdoorWMO(uint32 mogpFlags, uint32 mapId)
Definition: Map.cpp:1637
ACE_UINT16 uint16
Definition: Define.h:72
ACE_UINT32 uint32
Definition: Define.h:71
uint32 GetAreaFlagByMapId(uint32 mapid)
Definition: DBCStores.cpp:643
uint32 Map::GetAreaId ( uint16  areaflag,
uint32  map_id 
)
static

Definition at line 1822 of file Map.cpp.

References GetAreaEntryByAreaFlagAndMap(), and AreaTableEntry::ID.

Referenced by MapManager::GetAreaId(), and WorldObject::GetAreaId().

1823 {
1824  AreaTableEntry const* entry = GetAreaEntryByAreaFlagAndMap(areaflag, map_id);
1825 
1826  if (entry)
1827  return entry->ID;
1828  else
1829  return 0;
1830 }
AreaTableEntry const * GetAreaEntryByAreaFlagAndMap(uint32 area_flag, uint32 map_id)
Definition: DBCStores.cpp:632
uint32 Map::GetAreaId ( float  x,
float  y,
float  z 
) const
inline

Definition at line 371 of file Map.h.

372  {
373  return GetAreaId(GetAreaFlag(x, y, z), GetId());
374  }
static uint32 GetAreaId(uint16 areaflag, uint32 map_id)
Definition: Map.cpp:1822
uint32 GetId(void) const
Definition: Map.h:333
uint16 GetAreaFlag(float x, float y, float z, bool *isOutdoors=0) const
Definition: Map.cpp:1682
bool Map::GetAreaInfo ( float  x,
float  y,
float  z,
uint32 mogpflags,
int32 adtId,
int32 rootId,
int32 groupId 
) const

Definition at line 1663 of file Map.cpp.

References VMAP::VMapFactory::createOrGetVMapManager(), VMAP::IVMapManager::getAreaInfo(), and GetId().

Referenced by GetAreaFlag(), and IsOutdoors().

1664 {
1665  float vmap_z = z;
1667  if (vmgr->getAreaInfo(GetId(), x, y, vmap_z, flags, adtId, rootId, groupId))
1668  {
1669  // check if there's terrain between player height and object height
1670  if (GridMap* gmap = const_cast<Map*>(this)->GetGrid(x, y))
1671  {
1672  float _mapheight = gmap->getHeight(x, y);
1673  // z + 2.0f condition taken from GetHeight(), not sure if it's such a great choice...
1674  if (z + 2.0f > _mapheight && _mapheight > vmap_z)
1675  return false;
1676  }
1677  return true;
1678  }
1679  return false;
1680 }
Definition: Map.h:155
uint32 GetId(void) const
Definition: Map.h:333
virtual bool getAreaInfo(unsigned int pMapId, float x, float y, float &z, uint32 &flags, int32 &adtId, int32 &rootId, int32 &groupId) const =0
static IVMapManager * createOrGetVMapManager()
DungeonDifficulty Map::GetDifficulty ( ) const
inline

Definition at line 419 of file Map.h.

Referenced by InstanceMap::CannotEnter(), Spell::CheckCast(), and Player::CheckInstanceValidity().

419 { return DungeonDifficulty(GetSpawnMode()); }
uint8 GetSpawnMode() const
Definition: Map.h:394
DungeonDifficulty
DynamicObject * Map::GetDynamicObject ( uint64  guid)

Definition at line 2642 of file Map.cpp.

References ObjectAccessor::GetObjectInMap().

Referenced by Unit::GetDynObject(), Unit::RemoveAllDynObjects(), and Unit::RemoveDynObject().

2643 {
2644  return ObjectAccessor::GetObjectInMap(guid, this, (DynamicObject*)NULL);
2645 }
static T * GetObjectInMap(uint64 guid, Map *map, T *)
GridMap * Map::GetGrid ( float  x,
float  y 
)
inlineprivate

Definition at line 1561 of file Map.cpp.

References CENTER_GRID_ID, EnsureGridCreated(), GridMaps, MAX_NUMBER_OF_GRIDS, and SIZE_OF_GRIDS.

Referenced by GetAreaFlag(), GetHeight(), GetTerrainType(), GetWaterLevel(), GetWaterOrGroundLevel(), and IsUnderWater().

1562 {
1563  // half opt method
1564  int gx = (int)(CENTER_GRID_ID - x / SIZE_OF_GRIDS); //grid x
1565  int gy = (int)(CENTER_GRID_ID - y / SIZE_OF_GRIDS); //grid y
1566 
1567  // ensure GridMap is loaded
1569 
1570  return GridMaps[gx][gy];
1571 }
#define SIZE_OF_GRIDS
Definition: GridDefines.h:35
#define CENTER_GRID_ID
Definition: GridDefines.h:36
#define MAX_NUMBER_OF_GRIDS
Definition: GridDefines.h:33
GridMap * GridMaps[MAX_NUMBER_OF_GRIDS][MAX_NUMBER_OF_GRIDS]
Definition: Map.h:632
void EnsureGridCreated(const GridCoord &)
Definition: Map.cpp:319
CoordPair< MAX_NUMBER_OF_GRIDS > GridCoord
Definition: GridDefines.h:145
time_t Map::GetGridExpiry ( void  ) const
inline

Definition at line 329 of file Map.h.

Referenced by MapInstanced::CreateBattleground(), and MapInstanced::CreateInstance().

330  {
331  return i_gridExpiry;
332  }
time_t i_gridExpiry
Definition: Map.h:625
float Map::GetHeight ( float  x,
float  y,
float  z,
bool  checkVMap = true,
float  maxSearchDist = DEFAULT_HEIGHT_SEARCH 
) const

Definition at line 1591 of file Map.cpp.

References VMAP::VMapFactory::createOrGetVMapManager(), GetGrid(), DynamicMapTree::getHeight(), VMAP::IVMapManager::getHeight(), GetId(), INVALID_HEIGHT, VMAP::IVMapManager::isHeightCalcEnabled(), m_dyn_tree, and VMAP_INVALID_HEIGHT_VALUE.

Referenced by RandomMovementGenerator< T >::_setRandomLocation(), WorldObject::GetPositionZTarget(), GetWaterOrGroundLevel(), ChatHandler::HandleGoGridCommand(), ChatHandler::HandleGoXYCommand(), ChatHandler::HandleGoZoneXYCommand(), ChatHandler::HandleGPSCommand(), Creature::LoadCreatureFromDB(), MotionMaster::MoveFall(), WorldObject::MovePosition(), WorldObject::UpdateAllowedPositionZ(), WorldObject::UpdateGroundPositionZ(), and Creature::UpdateMovementFlags().

1592 {
1593  // find raw .map surface under Z coordinates
1594  float mapHeight = VMAP_INVALID_HEIGHT_VALUE;
1595  float realHeight = VMAP_INVALID_HEIGHT_VALUE;
1596  if (GridMap* gmap = const_cast<Map*>(this)->GetGrid(x, y))
1597  {
1598  float gridHeight = gmap->getHeight(x, y);
1599  // look from a bit higher pos to find the floor, ignore under surface case
1600  if (z + 2.0f > gridHeight)
1601  mapHeight = gridHeight;
1602  }
1603 
1604  float vmapHeight = VMAP_INVALID_HEIGHT_VALUE;
1605  if (checkVMap)
1606  {
1608  if (vmgr->isHeightCalcEnabled())
1609  vmapHeight = vmgr->getHeight(GetId(), x, y, z + 2.0f, maxSearchDist); // look from a bit higher pos to find the floor
1610  }
1611 
1612  // Explicitly set map data, and use it if no change.
1613  realHeight = mapHeight;
1614 
1615  // mapHeight set for any above raw ground Z or <= INVALID_HEIGHT
1616  // vmapheight set for any under Z value or <= INVALID_HEIGHT
1617  if (vmapHeight > INVALID_HEIGHT)
1618  {
1619  if (mapHeight > INVALID_HEIGHT)
1620  {
1621  // we have mapheight and vmapheight and must select more appropriate
1622 
1623  // we are already under the surface or vmap height above map heigt
1624  // or if the distance of the vmap height is less the land height distance
1625  if (vmapHeight > mapHeight || std::fabs(mapHeight - z) > std::fabs(vmapHeight - z))
1626  realHeight = vmapHeight;
1627  else
1628  realHeight = mapHeight; // better use .map surface height
1629  }
1630  else
1631  realHeight = vmapHeight; // we have only vmapHeight (if have)
1632  }
1633 
1634  return std::max<float>(realHeight, m_dyn_tree.getHeight(x, y, z, maxSearchDist));
1635 }
GridMap * GetGrid(float x, float y)
Definition: Map.cpp:1561
Definition: Map.h:155
DynamicMapTree m_dyn_tree
Definition: Map.h:624
uint32 GetId(void) const
Definition: Map.h:333
#define VMAP_INVALID_HEIGHT_VALUE
Definition: IVMapManager.h:41
bool isHeightCalcEnabled() const
Definition: IVMapManager.h:86
virtual float getHeight(unsigned int pMapId, float x, float y, float z, float maxSearchDist)=0
static IVMapManager * createOrGetVMapManager()
#define INVALID_HEIGHT
Definition: Map.h:259
float getHeight(float x, float y, float z, float maxSearchDist) const
ZLiquidStatus Map::getLiquidStatus ( float  x,
float  y,
float  z,
uint8  ReqLiquidType,
LiquidData data = 0 
) const

Definition at line 1728 of file Map.cpp.

References VMAP::VMapFactory::createOrGetVMapManager(), LiquidData::depth_level, LiquidData::entry, GetId(), VMAP::IVMapManager::GetLiquidLevel(), INVALID_HEIGHT, LiquidData::level, LIQUID_MAP_ABOVE_WATER, LIQUID_MAP_IN_WATER, LIQUID_MAP_NO_WATER, LIQUID_MAP_UNDER_WATER, LIQUID_MAP_WATER_WALK, sLiquidTypeStore, sLog, and LiquidData::type_flags.

Referenced by PathInfo::BuildPolyPath(), PathInfo::getNavTerrain(), WorldObject::GetPositionZTarget(), GetWaterOrGroundLevel(), ChatHandler::HandleGPSCommand(), IsInWater(), IsSwimmable(), IsUnderWater(), and Player::UpdateUnderwaterState().

1729 {
1732  float liquid_level = INVALID_HEIGHT;
1733  float ground_level = INVALID_HEIGHT;
1734  uint32 liquid_type = 0;
1735  if (vmgr->GetLiquidLevel(GetId(), x, y, z, ReqLiquidType, liquid_level, ground_level, liquid_type))
1736  {
1737  sLog.outVMap("getLiquidStatus(): vmap liquid level: %f ground: %f type: %u", liquid_level, ground_level, liquid_type);
1738  // Check water level and ground level
1739  if (liquid_level > ground_level && z > ground_level - 2)
1740  {
1741  // All ok in water -> store data
1742  if (data)
1743  {
1744  // hardcoded in client like this convert ocean to lava
1745  if (GetId() == 530 && liquid_type == 2)
1746  liquid_type = 3;
1747 
1748  uint32 liquidFlagType = 0;
1749  if (LiquidTypeEntry const* liq = sLiquidTypeStore.LookupEntry(liquid_type))
1750  liquidFlagType = 1 << liq->Type;
1751 
1752  data->level = liquid_level;
1753  data->depth_level = ground_level;
1754 
1755  data->entry = liquid_type;
1756  data->type_flags = liquidFlagType;
1757  }
1758 
1759  // For speed check as int values
1760  float delta = liquid_level - z;
1761 
1762  // Get position delta
1763  if (delta > 2.0f) // Under water
1764  return LIQUID_MAP_UNDER_WATER;
1765  if (delta > 0.0f) // In water
1766  return LIQUID_MAP_IN_WATER;
1767  if (delta > -0.1f) // Walk on water
1768  return LIQUID_MAP_WATER_WALK;
1769  result = LIQUID_MAP_ABOVE_WATER;
1770  }
1771  }
1772 
1773  if (GridMap* gmap = const_cast<Map*>(this)->GetGrid(x, y))
1774  {
1775  LiquidData map_data;
1776  ZLiquidStatus map_result = gmap->getLiquidStatus(x, y, z, ReqLiquidType, &map_data);
1777  // Not override LIQUID_MAP_ABOVE_WATER with LIQUID_MAP_NO_WATER:
1778  if (map_result != LIQUID_MAP_NO_WATER && (map_data.level > ground_level))
1779  {
1780  if (data)
1781  {
1782  // hardcoded in client like this
1783  if (GetId() == 530 && map_data.entry == 2)
1784  map_data.entry = 15;
1785 
1786  *data = map_data;
1787  }
1788  return map_result;
1789  }
1790  }
1791  return result;
1792 }
DBCStorage< LiquidTypeEntry > sLiquidTypeStore(LiquidTypefmt)
float depth_level
Definition: Map.h:152
virtual bool GetLiquidLevel(uint32 pMapId, float x, float y, float z, uint8 ReqLiquidType, float &level, float &floor, uint32 &type) const =0
Definition: Map.h:155
#define sLog
Log class singleton.
Definition: Log.h:187
ZLiquidStatus
Definition: Map.h:126
uint32 GetId(void) const
Definition: Map.h:333
float level
Definition: Map.h:151
uint32 type_flags
Definition: Map.h:149
uint32 entry
Definition: Map.h:150
static IVMapManager * createOrGetVMapManager()
#define INVALID_HEIGHT
Definition: Map.h:259
ACE_UINT32 uint32
Definition: Define.h:71
const char * Map::GetMapName ( ) const

Definition at line 1890 of file Map.cpp.

References i_mapEntry, MapEntry::name, and sWorld.

Referenced by InstanceMap::AddPlayerToMap(), InstanceMap::CannotEnter(), ChatHandler::HandleGoZoneXYCommand(), Player::LoadFromDB(), LoadMMap(), LoadVMap(), InstanceMap::RemovePlayerFromMap(), and BattlegroundMap::RemovePlayerFromMap().

1891 {
1892  return i_mapEntry ? i_mapEntry->name[sWorld.GetDefaultDbcLocale()] : "UNNAMEDMAP\x0";
1893 }
MapEntry const * i_mapEntry
Definition: Map.h:599
#define sWorld
Definition: World.h:860
char * name[16]
Definition: DBCStructure.h:518
NGridType* Map::getNGrid ( uint32  x,
uint32  y 
) const
inlineprivate

Definition at line 572 of file Map.h.

References ASSERT, and MAX_NUMBER_OF_GRIDS.

Referenced by AddToActive(), AddToGrid(), CreatureRelocation(), EnsureGridCreated(), EnsureGridLoaded(), EnsureGridLoadedForActiveObject(), IsGridLoaded(), RemoveFromActive(), and SwitchGridContainers().

573  {
576  return i_grids[x][y];
577  }
#define MAX_NUMBER_OF_GRIDS
Definition: GridDefines.h:33
NGridType * i_grids[MAX_NUMBER_OF_GRIDS][MAX_NUMBER_OF_GRIDS]
Definition: Map.h:631
#define ASSERT
Definition: Errors.h:29
bool Map::getObjectHitPos ( float  x1,
float  y1,
float  z1,
float  x2,
float  y2,
float  z2,
float &  rx,
float &  ry,
float &  rz,
float  modifyDist 
)

Definition at line 1808 of file Map.cpp.

References DynamicMapTree::getObjectHitPos(), and m_dyn_tree.

Referenced by WorldObject::MovePositionToFirstCollision().

1809 {
1810  G3D::Vector3 startPos = G3D::Vector3(x1, y1, z1);
1811  G3D::Vector3 dstPos = G3D::Vector3(x2, y2, z2);
1812 
1813  G3D::Vector3 resultPos;
1814  bool result = m_dyn_tree.getObjectHitPos(startPos, dstPos, resultPos, modifyDist);
1815 
1816  rx = resultPos.x;
1817  ry = resultPos.y;
1818  rz = resultPos.z;
1819  return result;
1820 }
DynamicMapTree m_dyn_tree
Definition: Map.h:624
bool getObjectHitPos(const G3D::Vector3 &pPos1, const G3D::Vector3 &pPos2, G3D::Vector3 &pResultHitPos, float pModifyDist) const
Map const* Map::GetParent ( ) const
inline

Definition at line 344 of file Map.h.

Referenced by WorldObject::GetBaseMap().

345  {
346  return m_parentMap;
347  }
Map * m_parentMap
Definition: Map.h:629
uint32 Map::GetPlayersCountExceptGMs ( ) const

Definition at line 2115 of file Map.cpp.

References MapRefManager::begin(), MapRefManager::end(), and m_mapRefManager.

Referenced by InstanceMap::CannotEnter(), and Player::CheckInstanceValidity().

2116 {
2117  uint32 count = 0;
2119  if (!itr->GetSource()->IsGameMaster())
2120  ++count;
2121  return count;
2122 }
iterator begin()
Definition: MapRefManager.h:48
ACE_UINT32 uint32
Definition: Define.h:71
MapRefManager m_mapRefManager
Definition: Map.h:605
iterator end()
Definition: MapRefManager.h:52
uint8 Map::GetSpawnMode ( ) const
inline
uint8 Map::GetTerrainType ( float  x,
float  y 
) const

Definition at line 1720 of file Map.cpp.

References GetGrid().

1721 {
1722  if (GridMap* gmap = const_cast<Map*>(this)->GetGrid(x, y))
1723  return gmap->getTerrainType(x, y);
1724  else
1725  return 0;
1726 }
GridMap * GetGrid(float x, float y)
Definition: Map.cpp:1561
Definition: Map.h:155
bool Map::GetUnloadLock ( const GridCoord p) const
inline

Definition at line 312 of file Map.h.

References CoordPair< LIMIT >::x_coord, and CoordPair< LIMIT >::y_coord.

313  {
314  return getNGrid(p.x_coord, p.y_coord)->getUnloadLock();
315  }
bool getUnloadLock() const
Definition: NGrid.h:113
NGridType * getNGrid(uint32 x, uint32 y) const
Definition: Map.h:572
uint32 y_coord
Definition: GridDefines.h:142
uint32 x_coord
Definition: GridDefines.h:141
float Map::GetWaterLevel ( float  x,
float  y 
) const

Definition at line 1794 of file Map.cpp.

References GetGrid().

Referenced by RandomMovementGenerator< T >::_setRandomLocation(), ChatHandler::HandleGoGridCommand(), ChatHandler::HandleGoXYCommand(), ChatHandler::HandleGoZoneXYCommand(), and Player::IsUnderWater().

1795 {
1796  if (GridMap* gmap = const_cast<Map*>(this)->GetGrid(x, y))
1797  return gmap->getLiquidLevel(x, y);
1798  else
1799  return 0;
1800 }
GridMap * GetGrid(float x, float y)
Definition: Map.cpp:1561
Definition: Map.h:155
float Map::GetWaterOrGroundLevel ( float  x,
float  y,
float  z,
float *  ground = NULL,
bool  swim = false 
) const

Definition at line 1573 of file Map.cpp.

References GetGrid(), GetHeight(), getLiquidStatus(), LiquidData::level, MAP_ALL_LIQUIDS, and VMAP_INVALID_HEIGHT_VALUE.

Referenced by Spell::SetTargetMap(), and WorldObject::UpdateAllowedPositionZ().

1574 {
1575  if (const_cast<Map*>(this)->GetGrid(x, y))
1576  {
1577  // we need ground level (including grid height version) for proper return water level in point
1578  float ground_z = GetHeight(x, y, z, true, 50.0f);
1579  if (ground)
1580  *ground = ground_z;
1581 
1582  LiquidData liquid_status;
1583 
1584  ZLiquidStatus res = getLiquidStatus(x, y, ground_z, MAP_ALL_LIQUIDS, &liquid_status);
1585  return res ? liquid_status.level : ground_z;
1586  }
1587 
1589 }
GridMap * GetGrid(float x, float y)
Definition: Map.cpp:1561
float GetHeight(float x, float y, float z, bool checkVMap=true, float maxSearchDist=DEFAULT_HEIGHT_SEARCH) const
Definition: Map.cpp:1591
ZLiquidStatus
Definition: Map.h:126
ZLiquidStatus getLiquidStatus(float x, float y, float z, uint8 ReqLiquidType, LiquidData *data=0) const
Definition: Map.cpp:1728
float level
Definition: Map.h:151
#define VMAP_INVALID_HEIGHT_VALUE
Definition: IVMapManager.h:41
#define MAP_ALL_LIQUIDS
Definition: Map.h:142
uint32 Map::GetZoneId ( uint16  areaflag,
uint32  map_id 
)
static

Definition at line 1832 of file Map.cpp.

References GetAreaEntryByAreaFlagAndMap(), AreaTableEntry::ID, and AreaTableEntry::zone.

Referenced by MapManager::GetZoneId(), and WorldObject::GetZoneId().

1833 {
1834  AreaTableEntry const* entry = GetAreaEntryByAreaFlagAndMap(areaflag, map_id);
1835 
1836  if (entry)
1837  return (entry->zone != 0) ? entry->zone : entry->ID;
1838  else
1839  return 0;
1840 }
AreaTableEntry const * GetAreaEntryByAreaFlagAndMap(uint32 area_flag, uint32 map_id)
Definition: DBCStores.cpp:632
uint32 Map::GetZoneId ( float  x,
float  y,
float  z 
) const
inline

Definition at line 376 of file Map.h.

377  {
378  return GetZoneId(GetAreaFlag(x, y, z), GetId());
379  }
uint32 GetId(void) const
Definition: Map.h:333
static uint32 GetZoneId(uint16 areaflag, uint32 map_id)
Definition: Map.cpp:1832
uint16 GetAreaFlag(float x, float y, float z, bool *isOutdoors=0) const
Definition: Map.cpp:1682
bool Map::HavePlayers ( ) const
inline

Definition at line 472 of file Map.h.

Referenced by RemoveAllPlayers(), BattlegroundMap::RemoveAllPlayers(), InstanceMap::Reset(), Group::ResetInstances(), InstanceMap::SetResetSchedule(), and InstanceMap::UnloadAll().

473  {
474  return !m_mapRefManager.isEmpty();
475  }
bool isEmpty() const
Definition: LinkedList.h:97
MapRefManager m_mapRefManager
Definition: Map.h:605
void Map::InitStateMachine ( )
static
void Map::InitVisibilityDistance ( )
virtual

Reimplemented in BattlegroundMap, InstanceMap, and MapInstanced.

Definition at line 225 of file Map.cpp.

References World::GetVisibilityNotifyPeriodOnContinents(), m_VisibilityNotifyPeriod, m_VisibleDistance, and sWorld.

Referenced by Map().

226 {
227  //init visibility for continents
228  m_VisibleDistance = sWorld.GetMaxVisibleDistanceOnContinents();
230 }
float m_VisibleDistance
Definition: Map.h:603
static int32 GetVisibilityNotifyPeriodOnContinents()
Definition: World.h:720
int32 m_VisibilityNotifyPeriod
Definition: Map.h:608
#define sWorld
Definition: World.h:860
void Map::Insert ( const GameObjectModel mdl)
inline

Definition at line 534 of file Map.h.

Referenced by GameObject::AddToWorld(), Transport::Update(), GameObject::UpdateModel(), and GameObject::UpdateModelPosition().

534 { m_dyn_tree.insert(mdl); }
DynamicMapTree m_dyn_tree
Definition: Map.h:624
void insert(const GameObjectModel &)
bool Map::IsBattleArena ( ) const
inline

Definition at line 443 of file Map.h.

Referenced by Pet::LoadPetFromDB().

444  {
445  return i_mapEntry && i_mapEntry->IsBattleArena();
446  }
bool IsBattleArena() const
Definition: DBCStructure.h:566
MapEntry const * i_mapEntry
Definition: Map.h:599
bool Map::IsBattleground ( ) const
inline

Definition at line 439 of file Map.h.

Referenced by Aura::HandleAuraDummy().

440  {
441  return i_mapEntry && i_mapEntry->IsBattleground();
442  }
MapEntry const * i_mapEntry
Definition: Map.h:599
bool IsBattleground() const
Definition: DBCStructure.h:562
bool Map::IsBattlegroundOrArena ( ) const
inline
bool Map::isCellMarked ( uint32  pCellId)
inline

Definition at line 463 of file Map.h.

Referenced by ProcessRelocationNotifies(), and VisitNearbyCellsOf().

464  {
465  return marked_cells.test(pCellId);
466  }
std::bitset< TOTAL_NUMBER_OF_CELLS_PER_MAP *TOTAL_NUMBER_OF_CELLS_PER_MAP > marked_cells
Definition: Map.h:633
bool Map::IsGridLoaded ( float  x,
float  y 
) const
inline

Definition at line 307 of file Map.h.

References Oregon::ComputeGridCoord().

Referenced by ObjectMgr::AddGOData(), CreatureCellRelocation(), GameEventMgr::GameEventSpawn(), PoolGroup< GameObject >::Spawn1Object(), PoolGroup< Creature >::Spawn1Object(), and SwitchGridContainers().

308  {
310  }
bool IsGridLoaded(float x, float y) const
Definition: Map.h:307
GridCoord ComputeGridCoord(float x, float y)
Definition: GridDefines.h:162
bool Map::IsGridLoaded ( const GridCoord p) const
private

Definition at line 488 of file Map.cpp.

References getNGrid(), isGridObjectDataLoaded(), CoordPair< LIMIT >::x_coord, and CoordPair< LIMIT >::y_coord.

489 {
491 }
NGridType * getNGrid(uint32 x, uint32 y) const
Definition: Map.h:572
uint32 y_coord
Definition: GridDefines.h:142
uint32 x_coord
Definition: GridDefines.h:141
bool isGridObjectDataLoaded(uint32 x, uint32 y) const
Definition: Map.h:579
bool Map::isGridObjectDataLoaded ( uint32  x,
uint32  y 
) const
inlineprivate

Definition at line 579 of file Map.h.

Referenced by EnsureGridLoaded(), and IsGridLoaded().

580  {
581  return getNGrid(x, y)->isGridObjectDataLoaded();
582  }
NGridType * getNGrid(uint32 x, uint32 y) const
Definition: Map.h:572
bool isGridObjectDataLoaded() const
Definition: NGrid.h:108
bool Map::IsHeroic ( ) const
inline
bool Map::isInLineOfSight ( float  x1,
float  y1,
float  z1,
float  x2,
float  y2,
float  z2 
) const

Definition at line 1802 of file Map.cpp.

References VMAP::VMapFactory::createOrGetVMapManager(), GetId(), DynamicMapTree::isInLineOfSight(), VMAP::IVMapManager::isInLineOfSight(), and m_dyn_tree.

Referenced by WorldObject::IsWithinLOS().

1803 {
1804  return VMAP::VMapFactory::createOrGetVMapManager()->isInLineOfSight(GetId(), x1, y1, z1, x2, y2, z2)
1805  && m_dyn_tree.isInLineOfSight(x1, y1, z1, x2, y2, z2);
1806 }
DynamicMapTree m_dyn_tree
Definition: Map.h:624
uint32 GetId(void) const
Definition: Map.h:333
virtual bool isInLineOfSight(unsigned int pMapId, float x1, float y1, float z1, float x2, float y2, float z2)=0
static IVMapManager * createOrGetVMapManager()
bool isInLineOfSight(float x1, float y1, float z1, float x2, float y2, float z2) const
bool Map::IsInWater ( float  x,
float  y,
float  z,
LiquidData data = nullptr 
) const

Definition at line 1842 of file Map.cpp.

References getLiquidStatus(), LIQUID_MAP_IN_WATER, LIQUID_MAP_UNDER_WATER, and MAP_ALL_LIQUIDS.

Referenced by Unit::IsInWater().

1843 {
1844  LiquidData liquid_status;
1845  LiquidData* liquid_ptr = data ? data : &liquid_status;
1846  return (getLiquidStatus(x, y, pZ, MAP_ALL_LIQUIDS, liquid_ptr) & (LIQUID_MAP_IN_WATER | LIQUID_MAP_UNDER_WATER)) != 0;
1847 }
ZLiquidStatus getLiquidStatus(float x, float y, float z, uint8 ReqLiquidType, LiquidData *data=0) const
Definition: Map.cpp:1728
#define MAP_ALL_LIQUIDS
Definition: Map.h:142
bool Map::IsOutdoors ( float  x,
float  y,
float  z 
) const

Definition at line 1651 of file Map.cpp.

References GetAreaInfo(), i_mapEntry, IsOutdoorWMO(), and MapEntry::MapID.

Referenced by Spell::CheckCast(), ChatHandler::HandleGPSCommand(), and Pet::Update().

1652 {
1653  uint32 mogpFlags;
1654  int32 adtId, rootId, groupId;
1655 
1656  // no wmo found? -> outside by default
1657  if (!GetAreaInfo(x, y, z, mogpFlags, adtId, rootId, groupId))
1658  return true;
1659 
1660  return IsOutdoorWMO(mogpFlags, i_mapEntry->MapID);
1661 }
bool GetAreaInfo(float x, float y, float z, uint32 &mogpflags, int32 &adtId, int32 &rootId, int32 &groupId) const
Definition: Map.cpp:1663
MapEntry const * i_mapEntry
Definition: Map.h:599
uint32 MapID
Definition: DBCStructure.h:514
ACE_INT32 int32
Definition: Define.h:67
bool IsOutdoorWMO(uint32 mogpFlags, uint32 mapId)
Definition: Map.cpp:1637
ACE_UINT32 uint32
Definition: Define.h:71
bool Map::IsRaid ( ) const
inline

Definition at line 431 of file Map.h.

Referenced by InstanceMap::CannotEnter(), Player::CheckInstanceValidity(), Group::InCombatToInstance(), Unit::Kill(), and InstanceMap::SetResetSchedule().

432  {
433  return i_mapEntry && i_mapEntry->IsRaid();
434  }
MapEntry const * i_mapEntry
Definition: Map.h:599
bool IsRaid() const
Definition: DBCStructure.h:558
bool Map::IsRegularDifficulty ( ) const
inline

Definition at line 420 of file Map.h.

References DIFFICULTY_NORMAL.

420 { return GetDifficulty() == DIFFICULTY_NORMAL; }
DungeonDifficulty GetDifficulty() const
Definition: Map.h:419
bool Map::IsRemovalGrid ( float  x,
float  y 
) const
inline

Definition at line 301 of file Map.h.

References Oregon::ComputeGridCoord(), GRID_STATE_REMOVAL, CoordPair< LIMIT >::x_coord, and CoordPair< LIMIT >::y_coord.

Referenced by ObjectAccessor::ConvertCorpseForPlayer().

302  {
305  }
grid_state_t GetGridState(void) const
Definition: NGrid.h:99
NGridType * getNGrid(uint32 x, uint32 y) const
Definition: Map.h:572
uint32 y_coord
Definition: GridDefines.h:142
uint32 x_coord
Definition: GridDefines.h:141
GridCoord ComputeGridCoord(float x, float y)
Definition: GridDefines.h:162
bool Map::IsSwimmable ( float  x,
float  y,
float  z,
LiquidData data = nullptr 
) const

Definition at line 1859 of file Map.cpp.

References LiquidData::depth_level, getLiquidStatus(), LiquidData::level, LIQUID_MAP_IN_WATER, LIQUID_MAP_UNDER_WATER, and MAP_ALL_LIQUIDS.

1860 {
1861  LiquidData liquid_status;
1862  LiquidData* liquid_ptr = data ? data : &liquid_status;
1864  {
1865  if (liquid_ptr->level - liquid_ptr->depth_level > 1.5f)
1866  return true;
1867  }
1868 
1869  return false;
1870 }
float depth_level
Definition: Map.h:152
ZLiquidStatus getLiquidStatus(float x, float y, float z, uint8 ReqLiquidType, LiquidData *data=0) const
Definition: Map.cpp:1728
float level
Definition: Map.h:151
#define MAP_ALL_LIQUIDS
Definition: Map.h:142
bool Map::IsUnderWater ( float  x,
float  y,
float  z 
) const

Definition at line 1849 of file Map.cpp.

References GetGrid(), getLiquidStatus(), LIQUID_MAP_UNDER_WATER, MAP_LIQUID_TYPE_OCEAN, and MAP_LIQUID_TYPE_WATER.

Referenced by PathInfo::BuildPolyPath(), WorldSession::HandleMovementOpcodes(), and Unit::IsUnderWater().

1850 {
1851  if (const_cast<Map*>(this)->GetGrid(x, y))
1852  {
1854  return true;
1855  }
1856  return false;
1857 }
GridMap * GetGrid(float x, float y)
Definition: Map.cpp:1561
ZLiquidStatus getLiquidStatus(float x, float y, float z, uint8 ReqLiquidType, LiquidData *data=0) const
Definition: Map.cpp:1728
#define MAP_LIQUID_TYPE_WATER
Definition: Map.h:140
#define MAP_LIQUID_TYPE_OCEAN
Definition: Map.h:138
void Map::LoadGrid ( float  x,
float  y 
)

Definition at line 388 of file Map.cpp.

References EnsureGridLoaded().

Referenced by CinematicMgr::BeginCinematic(), and FlightPathMovementGenerator::PreloadEndGrid().

389 {
390  EnsureGridLoaded(Cell(x, y));
391 }
bool EnsureGridLoaded(Cell const &)
Definition: Map.cpp:363
Definition: Cell.h:46
void Map::LoadMap ( int  gx,
int  gy,
bool  reload = false 
)
private

Definition at line 135 of file Map.cpp.

References EnsureGridCreated(), GetId(), GridMaps, i_InstanceId, m_parentMap, MAX_NUMBER_OF_GRIDS, sLog, snprintf, and sWorld.

Referenced by LoadMapAndVMap().

136 {
137  if (i_InstanceId != 0)
138  {
139  if (GridMaps[gx][gy])
140  return;
141 
142  // load grid map for base map
143  if (!m_parentMap->GridMaps[gx][gy])
145 
146  ((MapInstanced*)(m_parentMap))->AddGridMapReference(GridCoord(gx, gy));
147  GridMaps[gx][gy] = m_parentMap->GridMaps[gx][gy];
148  return;
149  }
150 
151  if (GridMaps[gx][gy] && !reload)
152  return;
153 
154  //map already load, delete it before reloading (Is it necessary? Do we really need the ability the reload maps during runtime?)
155  if (GridMaps[gx][gy])
156  {
157  sLog.outDetail("Unloading previously loaded map %u before reloading.", GetId());
158  delete (GridMaps[gx][gy]);
159  GridMaps[gx][gy] = nullptr;
160  }
161 
162  // map file name
163  char* tmp = nullptr;
164  int len = sWorld.GetDataPath().length() + strlen("maps/%03u%02u%02u.map") + 1;
165  tmp = new char[len];
166  snprintf(tmp, len, (char*)(sWorld.GetDataPath() + "maps/%03u%02u%02u.map").c_str(), GetId(), gx, gy);
167  sLog.outDetail("Loading map %s", tmp);
168  // loading data
169  GridMaps[gx][gy] = new GridMap();
170  if (!GridMaps[gx][gy]->loadData(tmp))
171  sLog.outError("Error loading map file: \n %s\n", tmp);
172  delete [] tmp;
173 }
#define snprintf
Definition: Common.h:129
Map * m_parentMap
Definition: Map.h:629
Definition: Map.h:155
#define sLog
Log class singleton.
Definition: Log.h:187
#define MAX_NUMBER_OF_GRIDS
Definition: GridDefines.h:33
GridMap * GridMaps[MAX_NUMBER_OF_GRIDS][MAX_NUMBER_OF_GRIDS]
Definition: Map.h:632
uint32 GetId(void) const
Definition: Map.h:333
void EnsureGridCreated(const GridCoord &)
Definition: Map.cpp:319
uint32 i_InstanceId
Definition: Map.h:601
#define sWorld
Definition: World.h:860
CoordPair< MAX_NUMBER_OF_GRIDS > GridCoord
Definition: GridDefines.h:145
void Map::LoadMapAndVMap ( int  gx,
int  gy 
)
private

Definition at line 175 of file Map.cpp.

References i_InstanceId, LoadMap(), LoadMMap(), and LoadVMap().

Referenced by EnsureGridCreated().

176 {
177  LoadMap(gx, gy);
178  // Only load the data for the base map
179  if (i_InstanceId == 0)
180  {
181  LoadVMap(gx, gy);
182  LoadMMap(gx, gy);
183  }
184 }
void LoadVMap(int gx, int gy)
Definition: Map.cpp:115
void LoadMap(int gx, int gy, bool reload=false)
Definition: Map.cpp:135
void LoadMMap(int gx, int gy)
Definition: Map.cpp:103
uint32 i_InstanceId
Definition: Map.h:601
void Map::LoadMMap ( int  gx,
int  gy 
)
private

Definition at line 103 of file Map.cpp.

References MMAP::MMapFactory::createOrGetMMapManager(), GetId(), GetMapName(), MMAP::MMapFactory::IsPathfindingEnabled(), MMAP::MMapManager::loadMap(), and sLog.

Referenced by LoadMapAndVMap().

104 {
106  return;
107 
108  bool mmapLoadResult = MMAP::MMapFactory::createOrGetMMapManager()->loadMap(GetId(), gx, gy);
109  if (mmapLoadResult)
110  sLog.outDetail("MMAP loaded name:%s, id:%d, x:%d, y:%d (mmap rep.: x:%d, y:%d)", GetMapName(), GetId(), gx, gy, gx, gy);
111  else
112  sLog.outDetail("Could not load MMAP name:%s, id:%d, x:%d, y:%d (mmap rep.: x:%d, y:%d)", GetMapName(), GetId(), gx, gy, gx, gy);
113 }
#define sLog
Log class singleton.
Definition: Log.h:187
uint32 GetId(void) const
Definition: Map.h:333
bool loadMap(uint32 mapId, int32 x, int32 y)
Definition: MoveMap.cpp:172
const char * GetMapName() const
Definition: Map.cpp:1890
static MMapManager * createOrGetMMapManager()
Definition: MoveMap.cpp:34
static bool IsPathfindingEnabled(uint32 mapId)
Definition: MoveMap.cpp:61
void Map::LoadVMap ( int  gx,
int  gy 
)
private

Definition at line 115 of file Map.cpp.

References VMAP::VMapFactory::createOrGetVMapManager(), DEBUG_LOG, GetId(), GetMapName(), VMAP::IVMapManager::loadMap(), sLog, sWorld, VMAP::VMAP_LOAD_RESULT_ERROR, VMAP::VMAP_LOAD_RESULT_IGNORED, and VMAP::VMAP_LOAD_RESULT_OK.

Referenced by LoadMapAndVMap().

116 {
117  if (!VMAP::VMapFactory::createOrGetVMapManager()->isMapLoadingEnabled())
118  return;
119  // x and y are swapped !!
120  int vmapLoadResult = VMAP::VMapFactory::createOrGetVMapManager()->loadMap((sWorld.GetDataPath() + "vmaps").c_str(), GetId(), gx, gy);
121  switch (vmapLoadResult)
122  {
124  sLog.outVMap("VMAP loaded name:%s, id:%d, x:%d, y:%d (vmap rep.: x:%d, y:%d)", GetMapName(), GetId(), gx, gy, gx, gy);
125  break;
127  sLog.outVMap("Could not load VMAP name:%s, id:%d, x:%d, y:%d (vmap rep.: x:%d, y:%d)", GetMapName(), GetId(), gx, gy, gx, gy);
128  break;
130  DEBUG_LOG("Ignored VMAP name:%s, id:%d, x:%d, y:%d (vmap rep.: x:%d, y:%d)", GetMapName(), GetId(), gx, gy, gx, gy);
131  break;
132  }
133 }
#define sLog
Log class singleton.
Definition: Log.h:187
uint32 GetId(void) const
Definition: Map.h:333
const char * GetMapName() const
Definition: Map.cpp:1890
#define DEBUG_LOG(...)
Definition: Log.h:194
virtual VMAPLoadResult loadMap(const char *pBasePath, unsigned int pMapId, int x, int y)=0
static IVMapManager * createOrGetVMapManager()
#define sWorld
Definition: World.h:860
void Map::markCell ( uint32  pCellId)
inline

Definition at line 467 of file Map.h.

Referenced by VisitNearbyCellsOf().

468  {
469  marked_cells.set(pCellId);
470  }
std::bitset< TOTAL_NUMBER_OF_CELLS_PER_MAP *TOTAL_NUMBER_OF_CELLS_PER_MAP > marked_cells
Definition: Map.h:633
void Map::MoveAllCreaturesInMoveList ( )

Definition at line 770 of file Map.cpp.

References AddObjectToRemoveList(), CreatureMover::ang, Oregon::ComputeCellCoord(), CreatureCellRelocation(), CreatureRespawnRelocation(), Object::GetEntry(), Object::GetGUIDLow(), i_creaturesToMove, Unit::IsPet(), PET_SAVE_NOT_IN_SLOT, Position::Relocate(), Remove(), sLog, Unit::UpdateObjectVisibility(), CreatureMover::x, CreatureMover::y, and CreatureMover::z.

Referenced by UnloadGrid(), and Update().

771 {
772  while (!i_creaturesToMove.empty())
773  {
774  // get data and remove element;
775  CreatureMoveList::iterator iter = i_creaturesToMove.begin();
776  Creature* c = iter->first;
777  CreatureMover cm = iter->second;
778  i_creaturesToMove.erase(iter);
779 
780  // calculate cells
781  CellCoord new_val = Oregon::ComputeCellCoord(cm.x, cm.y);
782  Cell new_cell(new_val);
783 
784  // do move or do move to respawn or remove creature if previous all fail
785  if (CreatureCellRelocation(c, new_cell))
786  {
787  // update pos
788  c->Relocate(cm.x, cm.y, cm.z, cm.ang);
789  //CreatureRelocationNotify(c,new_cell,new_cell.cellPair());
790  c->UpdateObjectVisibility(false);
791  }
792  else
793  {
794  // if creature can't be move in new cell/grid (not loaded) move it to repawn cell/grid
795  // creature coordinates will be updated and notifiers send
797  {
798  // ... or unload (if respawn grid also not loaded)
799  #ifdef OREGON_DEBUG
800  sLog.outMap("Creature (GUID: %u Entry: %u) cannot be move to unloaded respawn grid.", c->GetGUIDLow(), c->GetEntry());
801  #endif
802  // crash fix for pets moving to unloaded cells.
803  if (c->IsPet())
804  ((Pet*)c)->Remove(PET_SAVE_NOT_IN_SLOT, true);
805  else
807  }
808  }
809  }
810 }
float ang
Definition: Map.h:220
#define sLog
Log class singleton.
Definition: Log.h:187
void Remove(const GameObjectModel &mdl)
Definition: Map.h:533
void UpdateObjectVisibility(bool forced=true) override
Definition: Unit.cpp:13525
void AddObjectToRemoveList(WorldObject *obj)
Definition: Map.cpp:2035
uint32 GetGUIDLow() const
Definition: Object.h:166
CreatureMoveList i_creaturesToMove
Definition: Map.h:557
float z
Definition: Map.h:220
float x
Definition: Map.h:220
void Relocate(float x, float y)
Definition: Position.h:65
CellCoord ComputeCellCoord(float x, float y)
Definition: GridDefines.h:167
bool IsPet() const
Definition: Unit.h:1048
Definition: Cell.h:46
bool CreatureCellRelocation(Creature *creature, Cell new_cell)
Definition: Map.cpp:812
bool CreatureRespawnRelocation(Creature *c)
Definition: Map.cpp:873
uint32 GetEntry() const
Definition: Object.h:192
float y
Definition: Map.h:220
Definition: Pet.h:146
void Map::PlayerRelocation ( Player player,
float  x,
float  y,
float  z,
float  orientation 
)

Definition at line 709 of file Map.cpp.

References AddToGrid(), ASSERT, DEBUG_LOG, EnsureGridLoadedForActiveObject(), WorldObject::GetName(), Position::GetPositionX(), Position::GetPositionY(), Position::Relocate(), GridObject< T >::RemoveFromGrid(), and Player::UpdateObjectVisibility().

Referenced by Player::SetPosition().

710 {
711  ASSERT(player);
712 
713  Cell old_cell(player->GetPositionX(), player->GetPositionY());
714  Cell new_cell(x, y);
715 
716  player->Relocate(x, y, z, orientation);
717 
718  if (old_cell.DiffGrid(new_cell) || old_cell.DiffCell(new_cell))
719  {
720  DEBUG_LOG("Player %s relocation grid[%u,%u]cell[%u,%u]->grid[%u,%u]cell[%u,%u]", player->GetName(), old_cell.GridX(), old_cell.GridY(), old_cell.CellX(), old_cell.CellY(), new_cell.GridX(), new_cell.GridY(), new_cell.CellX(), new_cell.CellY());
721 
722  player->RemoveFromGrid();
723 
724  if (old_cell.DiffGrid(new_cell))
725  EnsureGridLoadedForActiveObject(new_cell, player);
726 
727  AddToGrid(player, new_cell);
728  }
729 
730  player->UpdateObjectVisibility(false);
731 }
void RemoveFromGrid()
Definition: Object.h:605
void AddToGrid(T *object, Cell const &cell)
Definition: Map.cpp:234
void Relocate(float x, float y)
Definition: Position.h:65
float GetPositionY() const
Definition: Position.h:98
#define DEBUG_LOG(...)
Definition: Log.h:194
void UpdateObjectVisibility(bool forced=true) override
Definition: Player.cpp:18890
void EnsureGridLoadedForActiveObject(Cell const &, WorldObject *object)
Definition: Map.cpp:347
const char * GetName() const
Definition: Object.h:704
Definition: Cell.h:46
#define ASSERT
Definition: Errors.h:29
float GetPositionX() const
Definition: Position.h:97
void Map::ProcessRelocationNotifies ( const uint32 diff)
private

Definition at line 593 of file Map.cpp.

References CONFIG_SIGHT_MONSTER, GridRefManager< OBJECT >::end(), NGrid< N, ACTIVE_OBJECT, WORLD_OBJECT_TYPES, GRID_OBJECT_TYPES >::getGridInfoRef(), NGrid< N, ACTIVE_OBJECT, WORLD_OBJECT_TYPES, GRID_OBJECT_TYPES >::GetGridState(), GridInfo::getRelocationTimer(), NGrid< N, ACTIVE_OBJECT, WORLD_OBJECT_TYPES, GRID_OBJECT_TYPES >::getX(), NGrid< N, ACTIVE_OBJECT, WORLD_OBJECT_TYPES, GRID_OBJECT_TYPES >::getY(), GRID_STATE_ACTIVE, isCellMarked(), m_VisibilityNotifyPeriod, MAX_NUMBER_OF_CELLS, MAX_VISIBILITY_DISTANCE, Cell::SetNoCreate(), sWorld, TOTAL_NUMBER_OF_CELLS_PER_MAP, PeriodicTimer::TPassed(), PeriodicTimer::TReset(), PeriodicTimer::TUpdate(), Visit(), CoordPair< LIMIT >::x_coord, and CoordPair< LIMIT >::y_coord.

Referenced by Update().

594 {
596  {
597  NGridType* grid = i->GetSource();
598 
599  if (grid->GetGridState() != GRID_STATE_ACTIVE)
600  continue;
601 
602  grid->getGridInfoRef()->getRelocationTimer().TUpdate(diff);
603  if (!grid->getGridInfoRef()->getRelocationTimer().TPassed())
604  continue;
605 
606  uint32 gx = grid->getX(), gy = grid->getY();
607  float monsterSightRadius = (float)sWorld.getConfig(CONFIG_SIGHT_MONSTER);
608 
609  CellCoord cell_min(gx * MAX_NUMBER_OF_CELLS, gy * MAX_NUMBER_OF_CELLS);
610  CellCoord cell_max(cell_min.x_coord + MAX_NUMBER_OF_CELLS, cell_min.y_coord + MAX_NUMBER_OF_CELLS);
611 
612  for (uint32 x = cell_min.x_coord; x < cell_max.x_coord; ++x)
613  {
614  for (uint32 y = cell_min.y_coord; y < cell_max.y_coord; ++y)
615  {
616  uint32 cell_id = (y * TOTAL_NUMBER_OF_CELLS_PER_MAP) + x;
617  if (!isCellMarked(cell_id))
618  continue;
619 
620  CellCoord pair(x, y);
621  Cell cell(pair);
622  cell.SetNoCreate();
623 
624  Oregon::DelayedUnitRelocation cell_relocationCreature(cell, pair, *this, monsterSightRadius);
625  Oregon::DelayedUnitRelocation cell_relocationPlayer(cell, pair, *this, MAX_VISIBILITY_DISTANCE);
626  TypeContainerVisitor<Oregon::DelayedUnitRelocation, GridTypeMapContainer > grid_object_relocation(cell_relocationCreature);
627  TypeContainerVisitor<Oregon::DelayedUnitRelocation, WorldTypeMapContainer > world_object_relocation(cell_relocationPlayer);
628  Visit(cell, grid_object_relocation);
629  Visit(cell, world_object_relocation);
630  }
631  }
632  }
633 
634  ResetNotifier reset;
638  {
639  NGridType* grid = i->GetSource();
640 
641  if (grid->GetGridState() != GRID_STATE_ACTIVE)
642  continue;
643 
644  if (!grid->getGridInfoRef()->getRelocationTimer().TPassed())
645  continue;
646 
648 
649  uint32 gx = grid->getX(), gy = grid->getY();
650 
651  CellCoord cell_min(gx * MAX_NUMBER_OF_CELLS, gy * MAX_NUMBER_OF_CELLS);
652  CellCoord cell_max(cell_min.x_coord + MAX_NUMBER_OF_CELLS, cell_min.y_coord + MAX_NUMBER_OF_CELLS);
653 
654  for (uint32 x = cell_min.x_coord; x < cell_max.x_coord; ++x)
655  {
656  for (uint32 y = cell_min.y_coord; y < cell_max.y_coord; ++y)
657  {
658  uint32 cell_id = (y * TOTAL_NUMBER_OF_CELLS_PER_MAP) + x;
659  if (!isCellMarked(cell_id))
660  continue;
661 
662  CellCoord pair(x, y);
663  Cell cell(pair);
664  cell.SetNoCreate();
665  Visit(cell, grid_notifier);
666  Visit(cell, world_notifier);
667  }
668  }
669  }
670 }
Definition: NGrid.h:75
bool isCellMarked(uint32 pCellId)
Definition: Map.h:463
grid_state_t GetGridState(void) const
Definition: NGrid.h:99
void TUpdate(int32 diff)
Definition: Timer.h:210
#define MAX_NUMBER_OF_CELLS
Definition: GridDefines.h:43
#define TOTAL_NUMBER_OF_CELLS_PER_MAP
Definition: GridDefines.h:49
GridInfo * getGridInfoRef()
Definition: NGrid.h:111
iterator end()
void TReset(int32 diff, int32 period)
Definition: Timer.h:218
#define MAX_VISIBILITY_DISTANCE
Definition: Object.h:38
int32 getY() const
Definition: NGrid.h:102
Definition: Cell.h:46
void Visit(const Cell &cell, TypeContainerVisitor< T, CONTAINER > &visitor)
int32 m_VisibilityNotifyPeriod
Definition: Map.h:608
int32 getX() const
Definition: NGrid.h:101
PeriodicTimer & getRelocationTimer()
Definition: NGrid.h:49
#define sWorld
Definition: World.h:860
ACE_UINT32 uint32
Definition: Define.h:71
bool TPassed() const
Definition: Timer.h:214
void Map::Remove ( const GameObjectModel mdl)
inline

Definition at line 533 of file Map.h.

Referenced by MoveAllCreaturesInMoveList(), GameObject::RemoveFromWorld(), Transport::TeleportTransport(), GameObject::UpdateModel(), and GameObject::UpdateModelPosition().

533 { m_dyn_tree.remove(mdl); }
DynamicMapTree m_dyn_tree
Definition: Map.h:624
void remove(const GameObjectModel &)
void Map::RemoveAllObjectsInRemoveList ( )

Definition at line 2062 of file Map.cpp.

References Unit::CleanupsBeforeDelete(), ObjectAccessor::GetCorpse(), Object::GetGUID(), Object::GetGUIDLow(), Object::GetTypeId(), i_objectsToRemove, i_objectsToSwitch, Oregon::Singleton< ObjectAccessor, Oregon::ClassLevelLockable< ObjectAccessor, ACE_Thread_Mutex > >::Instance(), WorldObject::IsPermanentWorldObject(), RemoveFromMap(), sLog, SwitchGridContainers(), Object::ToCreature(), TYPEID_CORPSE, TYPEID_DYNAMICOBJECT, TYPEID_GAMEOBJECT, and TYPEID_UNIT.

Referenced by DelayedUpdate(), and UnloadGrid().

2063 {
2064  while (!i_objectsToSwitch.empty())
2065  {
2066  std::map<WorldObject*, bool>::iterator itr = i_objectsToSwitch.begin();
2067  WorldObject* obj = itr->first;
2068  bool on = itr->second;
2069  i_objectsToSwitch.erase(itr);
2070 
2071  if (obj->GetTypeId() == TYPEID_UNIT && !obj->IsPermanentWorldObject())
2072  SwitchGridContainers(obj->ToCreature(), on);
2073  }
2074 
2075  //sLog.outMap("Object remover 1 check.");
2076  while (!i_objectsToRemove.empty())
2077  {
2078  std::set<WorldObject*>::iterator itr = i_objectsToRemove.begin();
2079  WorldObject* obj = *itr;
2080 
2081  switch (obj->GetTypeId())
2082  {
2083  case TYPEID_CORPSE:
2084  {
2085  Corpse* corpse = ObjectAccessor::Instance().GetCorpse(*obj, obj->GetGUID());
2086  if (!corpse)
2087  sLog.outError("Tried to delete corpse/bones %u that is not in map.", obj->GetGUIDLow());
2088  else
2089  RemoveFromMap(corpse, true);
2090  break;
2091  }
2092  case TYPEID_DYNAMICOBJECT:
2093  RemoveFromMap((DynamicObject*)obj, true);
2094  break;
2095  case TYPEID_GAMEOBJECT:
2096  RemoveFromMap((GameObject*)obj, true);
2097  break;
2098  case TYPEID_UNIT:
2099  // in case triggered sequence some spell can continue casting after prev CleanupsBeforeDelete call
2100  // make sure that like sources auras/etc removed before destructor start
2101  obj->ToCreature()->CleanupsBeforeDelete();
2102  RemoveFromMap(obj->ToCreature(), true);
2103  break;
2104  default:
2105  sLog.outError("Non-grid object (TypeId: %u) is in grid object remove list, ignored.", obj->GetTypeId());
2106  break;
2107  }
2108 
2109  i_objectsToRemove.erase(itr);
2110  }
2111 
2112  //sLog.outMap("Object remover 2 check.");
2113 }
Definition: Corpse.h:48
std::set< WorldObject * > i_objectsToRemove
Definition: Map.h:640
void SwitchGridContainers(Creature *creature, bool toWorldContainer)
Definition: Map.cpp:268
void RemoveFromMap(T *, bool)
Definition: Map.cpp:688
std::map< WorldObject *, bool > i_objectsToSwitch
Definition: Map.h:641
#define sLog
Log class singleton.
Definition: Log.h:187
uint32 GetGUIDLow() const
Definition: Object.h:166
uint8 GetTypeId() const
Definition: Object.h:210
Creature * ToCreature()
Definition: Object.h:395
void CleanupsBeforeDelete() override
Definition: Unit.cpp:11165
static Corpse * GetCorpse(WorldObject const &u, uint64 guid)
bool IsPermanentWorldObject() const
Definition: Object.h:917
const uint64 & GetGUID() const
Definition: Object.h:162
void Map::RemoveAllPlayers ( )
virtual

Reimplemented in BattlegroundMap.

Definition at line 978 of file Map.cpp.

References MapRefManager::begin(), MapRefManager::end(), GetId(), WorldObject::GetName(), Position::GetOrientation(), HavePlayers(), Player::IsBeingTeleportedFar(), Player::m_homebindMapId, Player::m_homebindX, Player::m_homebindY, Player::m_homebindZ, m_mapRefManager, sLog, and Player::TeleportTo().

979 {
980  if (HavePlayers())
981  {
982  for (MapRefManager::iterator itr = m_mapRefManager.begin(); itr != m_mapRefManager.end(); ++itr)
983  {
984  Player* plr = itr->GetSource();
985  if (!plr->IsBeingTeleportedFar())
986  {
987  // this is happening for bg
988  sLog.outError("Map::UnloadAll: player %s is still in map %u during unload, this should not happen!", plr->GetName(), GetId());
989  plr->TeleportTo(plr->m_homebindMapId, plr->m_homebindX, plr->m_homebindY, plr->m_homebindZ, plr->GetOrientation());
990  }
991  }
992  }
993 }
bool IsBeingTeleportedFar() const
Definition: Player.h:2046
float m_homebindY
Definition: Player.h:2442
uint32 m_homebindMapId
Definition: Player.h:2439
#define sLog
Log class singleton.
Definition: Log.h:187
iterator begin()
Definition: MapRefManager.h:48
uint32 GetId(void) const
Definition: Map.h:333
bool TeleportTo(uint32 mapid, float x, float y, float z, float orientation, uint32 options=0)
Definition: Player.cpp:1488
float GetOrientation() const
Definition: Position.h:100
bool HavePlayers() const
Definition: Map.h:472
const char * GetName() const
Definition: Object.h:704
MapRefManager m_mapRefManager
Definition: Map.h:605
Definition: Player.h:922
float m_homebindX
Definition: Player.h:2441
iterator end()
Definition: MapRefManager.h:52
float m_homebindZ
Definition: Player.h:2443
template<class T >
void Map::RemoveFromActive ( T *  obj)
inline

Definition at line 511 of file Map.h.

Referenced by RemoveFromMap(), and WorldObject::setActive().

512  {
514  }
void RemoveFromActiveHelper(T *obj)
Definition: Map.h:659
void Map::RemoveFromActive ( Creature obj)

Definition at line 2188 of file Map.cpp.

References AddToMap(), Oregon::ComputeGridCoord(), NGrid< N, ACTIVE_OBJECT, WORLD_OBJECT_TYPES, GRID_OBJECT_TYPES >::decUnloadActiveLock(), Creature::GetDBTableGUIDLow(), Object::GetEntry(), Object::GetGUIDLow(), getNGrid(), Position::GetPositionX(), Position::GetPositionY(), Creature::GetRespawnPosition(), Unit::IsPet(), RemoveFromActiveHelper(), RemoveFromMap(), sLog, CoordPair< LIMIT >::x_coord, and CoordPair< LIMIT >::y_coord.

2189 {
2191 
2192  // also allow unloading spawn grid
2193  if (!c->IsPet() && c->GetDBTableGUIDLow())
2194  {
2195  float x, y, z;
2196  c->GetRespawnPosition(x, y, z);
2198  if (getNGrid(p.x_coord, p.y_coord))
2200  else
2201  {
2202  GridCoord p2 = Oregon::ComputeGridCoord(c->GetPositionX(), c->GetPositionY());
2203  sLog.outError("Active creature (GUID: %u Entry: %u) removed from grid[%u,%u] but spawn grid[%u,%u] not loaded.",
2204  c->GetGUIDLow(), c->GetEntry(), p.x_coord, p.y_coord, p2.x_coord, p2.y_coord);
2205  }
2206  }
2207 }
void decUnloadActiveLock()
Definition: NGrid.h:117
void RemoveFromActiveHelper(T *obj)
Definition: Map.h:659
NGridType * getNGrid(uint32 x, uint32 y) const
Definition: Map.h:572
#define sLog
Log class singleton.
Definition: Log.h:187
uint32 y_coord
Definition: GridDefines.h:142
uint32 x_coord
Definition: GridDefines.h:141
GridCoord ComputeGridCoord(float x, float y)
Definition: GridDefines.h:162
template<class T >
void Map::RemoveFromActiveHelper ( T *  obj)
inlineprivate

Definition at line 659 of file Map.h.

Referenced by RemoveFromActive().

660  {
661  // Map::Update for active object in proccess
663  {
664  ActiveNonPlayers::iterator itr = m_activeNonPlayers.find(obj);
665  if (itr == m_activeNonPlayers.end())
666  return;
667  if (itr == m_activeNonPlayersIter)
669  m_activeNonPlayers.erase(itr);
670  }
671  else
672  m_activeNonPlayers.erase(obj);
673  }
ActiveNonPlayers m_activeNonPlayers
Definition: Map.h:611
ActiveNonPlayers::iterator m_activeNonPlayersIter
Definition: Map.h:612
template<class T >
template void Map::RemoveFromMap ( T *  ,
bool   
)

Definition at line 688 of file Map.cpp.

References CONFIG_SAVE_RESPAWN_TIME_IMMEDIATELY, DeleteFromWorld(), RemoveFromActive(), and sWorld.

Referenced by RemoveAllObjectsInRemoveList(), ObjectAccessor::RemoveCorpse(), and RemoveFromActive().

689 {
690  obj->RemoveFromWorld();
691  if (obj->isActiveObject())
692  RemoveFromActive(obj);
693 
694  obj->UpdateObjectVisibility(true);
695  obj->RemoveFromGrid();
696 
697  obj->ResetMap();
698 
699  if (remove)
700  {
701  // if option set then object already saved at this moment
703  obj->SaveRespawnTime();
704  DeleteFromWorld(obj);
705  }
706 }
void RemoveFromActive(T *obj)
Definition: Map.h:511
void DeleteFromWorld(T *)
Definition: Map.cpp:304
#define sWorld
Definition: World.h:860
void Map::RemovePlayerFromMap ( Player player,
bool  remove 
)
virtual

Reimplemented in BattlegroundMap, and InstanceMap.

Definition at line 672 of file Map.cpp.

References ASSERT, DeleteFromWorld(), GridObject< T >::IsInGrid(), GridObject< T >::RemoveFromGrid(), Player::RemoveFromWorld(), SendRemoveTransports(), and Player::UpdateObjectVisibility().

Referenced by WorldSession::HandleMoveWorldportAckOpcode(), WorldSession::LogoutPlayer(), InstanceMap::RemovePlayerFromMap(), BattlegroundMap::RemovePlayerFromMap(), Player::TeleportTo(), and RegressionTestSuite::TestBreathingIssues().

673 {
674  player->RemoveFromWorld();
675  SendRemoveTransports(player);
676 
677  player->UpdateObjectVisibility(true);
678  if (player->IsInGrid())
679  player->RemoveFromGrid();
680  else
681  ASSERT(remove); //maybe deleted in logoutplayer when player is not in a map
682 
683  if (remove)
684  DeleteFromWorld(player);
685 }
void SendRemoveTransports(Player *player)
Definition: Map.cpp:1983
void RemoveFromGrid()
Definition: Object.h:605
bool IsInGrid() const
Definition: Object.h:603
void RemoveFromWorld() override
Definition: Player.cpp:1850
void DeleteFromWorld(T *)
Definition: Map.cpp:304
void UpdateObjectVisibility(bool forced=true) override
Definition: Player.cpp:18890
#define ASSERT
Definition: Errors.h:29
template<class T >
void Map::RemoveType ( T *  obj,
bool   
)
private
void Map::RemoveWorldObject ( WorldObject obj)
inline

Definition at line 483 of file Map.h.

Referenced by WorldObject::ResetMap(), and SwitchGridContainers().

484  {
485  i_worldObjects.erase(obj);
486  }
std::set< WorldObject * > i_worldObjects
Definition: Map.h:642
void Map::ResetGridExpiry ( NGridType grid,
float  factor = 1 
) const
inline

Definition at line 324 of file Map.h.

References NGrid< N, ACTIVE_OBJECT, WORLD_OBJECT_TYPES, GRID_OBJECT_TYPES >::ResetTimeTracker().

Referenced by EnsureGridLoadedForActiveObject(), ActiveState::Update(), IdleState::Update(), and RemovalState::Update().

325  {
326  grid.ResetTimeTracker(time_t(float(i_gridExpiry)*factor));
327  }
time_t i_gridExpiry
Definition: Map.h:625
void ResetTimeTracker(time_t interval)
Definition: NGrid.h:118
void Map::resetMarkedCells ( )
inline

Definition at line 459 of file Map.h.

Referenced by Update().

460  {
461  marked_cells.reset();
462  }
std::bitset< TOTAL_NUMBER_OF_CELLS_PER_MAP *TOTAL_NUMBER_OF_CELLS_PER_MAP > marked_cells
Definition: Map.h:633
void Map::ScriptCommandStart ( ScriptInfo const &  script,
uint32  delay,
Object source,
Object target 
)

Definition at line 71 of file MapScripts.cpp.

References Object::GetGUID(), Object::GetTypeId(), i_scriptLock, m_scriptSchedule, ScriptAction::ownerGUID, ScriptAction::script, ScriptsProcess(), ScriptAction::sourceGUID, sWorld, ScriptAction::targetGUID, and TYPEID_ITEM.

Referenced by Spell::EffectActivateObject(), and Spell::EffectDummy().

72 {
73  // NOTE: script record _must_ exist until command executed
74 
75  // prepare static data
76  uint64 sourceGUID = source ? source->GetGUID() : (uint64)0;
77  uint64 targetGUID = target ? target->GetGUID() : (uint64)0;
78  uint64 ownerGUID = (source->GetTypeId() == TYPEID_ITEM) ? ((Item*)source)->GetOwnerGUID() : (uint64)0;
79 
80  ScriptAction sa;
81  sa.sourceGUID = sourceGUID;
82  sa.targetGUID = targetGUID;
83  sa.ownerGUID = ownerGUID;
84 
85  sa.script = &script;
86  m_scriptSchedule.insert(std::pair<time_t, ScriptAction>(time_t(sWorld.GetGameTime() + delay), sa));
87 
88  sWorld.IncreaseScheduledScriptsCount();
89 
90  // If effects should be immediate, launch the script execution
91  if (delay == 0 && !i_scriptLock)
92  {
93  i_scriptLock = true;
95  i_scriptLock = false;
96  }
97 }
std::multimap< time_t, ScriptAction > m_scriptSchedule
Definition: Map.h:643
ScriptInfo const * script
Definition: Map.h:63
bool i_scriptLock
Definition: Map.h:639
uint8 GetTypeId() const
Definition: Object.h:210
uint64 sourceGUID
Definition: Map.h:60
Definition: Item.h:196
uint64 targetGUID
Definition: Map.h:61
ACE_UINT64 uint64
Definition: Define.h:70
#define sWorld
Definition: World.h:860
uint64 ownerGUID
Definition: Map.h:62
void ScriptsProcess()
Definition: MapScripts.cpp:288
const uint64 & GetGUID() const
Definition: Object.h:162
void Map::ScriptsProcess ( )
private

Definition at line 288 of file MapScripts.cpp.

References _FindGameObject(), _GetScriptCreature(), _GetScriptCreatureSourceOrTarget(), _GetScriptPlayer(), _GetScriptPlayerSourceOrTarget(), _GetScriptUnit(), _GetScriptWorldObject(), _ScriptProcessDoor(), AddToMap(), Player::AreaExploredOrEventHappens(), ScriptInfo::CallScript, ScriptInfo::CastSpell, Unit::CastSpell(), CHAT_MSG_RAID_BOSS_WHISPER, CHAT_TYPE_BOSS_EMOTE, CHAT_TYPE_SAY, CHAT_TYPE_TEXT_EMOTE, CHAT_TYPE_WHISPER, CHAT_TYPE_YELL, ScriptInfo::command, Oregon::ComputeCellCoord(), ScriptInfo::CreateItem, ScriptInfo::DespawnSelf, ScriptInfo::Emote, ScriptInfo::Equip, EQUIP_ERR_OK, Player::FailQuest(), ScriptInfo::FieldSet, HashMapHolder< T >::Find(), ScriptInfo::FlagToggle, GAMEOBJECT_TYPE_BUTTON, GAMEOBJECT_TYPE_DOOR, GAMEOBJECT_TYPE_FISHINGNODE, GAMEOBJECT_TYPE_TRAP, GetClosestCreatureWithEntry(), ScriptInfo::GetDebugInfo(), Object::GetEntry(), GameObject::GetGoType(), WorldObject::GetGridActivationRange(), Object::GetGUID(), Object::GetGUIDLow(), Player::GetItemByGuid(), WorldObject::GetMap(), Position::GetPositionX(), Position::GetPositionY(), GetScriptCommandName(), GetScriptsMapByType(), GetScriptsTableNameByType(), Object::GetTypeId(), Object::GetValuesCount(), GO_READY, GUID_HIPART, HIGHGUID_CORPSE, HIGHGUID_GAMEOBJECT, HIGHGUID_ITEM, HIGHGUID_MO_TRANSPORT, HIGHGUID_PET, HIGHGUID_PLAYER, HIGHGUID_UNIT, Oregon::Singleton< MapManager, Oregon::ClassLevelLockable< MapManager, ACE_Thread_Mutex > >::Instance(), IS_PLAYER_GUID, GameObject::isSpawned(), Object::isType(), WorldObject::IsWithinDistInMap(), JUST_DIED, ScriptInfo::Kill, ScriptInfo::KillCredit, LANG_UNIVERSAL, Movement::MoveSplineInit::Launch(), ScriptInfo::LoadPath, m_scriptSchedule, MapManager::m_Transports, MAKE_NEW_GUID, ScriptInfo::Model, Movement::MoveSplineInit::MoveTo(), ScriptInfo::MoveTo, NULL_BAG, NULL_SLOT, OBJECT_FIELD_ENTRY, ScriptInfo::Orientation, ScriptAction::ownerGUID, ScriptInfo::PlaySound, ScriptInfo::QuestExplored, ScriptInfo::RemoveAura, ScriptInfo::RespawnGameobject, ScriptAction::script, SCRIPT_COMMAND_ACTIVATE_OBJECT, SCRIPT_COMMAND_CALLSCRIPT_TO_UNIT, SCRIPT_COMMAND_CAST_SPELL, SCRIPT_COMMAND_CLOSE_DOOR, SCRIPT_COMMAND_CLOSE_GOSSIP, SCRIPT_COMMAND_CREATE_ITEM, SCRIPT_COMMAND_DESPAWN_SELF, SCRIPT_COMMAND_DO_NOTHING, SCRIPT_COMMAND_EMOTE, SCRIPT_COMMAND_EQUIP, SCRIPT_COMMAND_FIELD_SET, SCRIPT_COMMAND_FLAG_REMOVE, SCRIPT_COMMAND_FLAG_SET, SCRIPT_COMMAND_KILL, SCRIPT_COMMAND_KILL_CREDIT, SCRIPT_COMMAND_LOAD_PATH, SCRIPT_COMMAND_MODEL, SCRIPT_COMMAND_MOVE_TO, SCRIPT_COMMAND_OPEN_DOOR, SCRIPT_COMMAND_ORIENTATION, SCRIPT_COMMAND_PLAY_SOUND, SCRIPT_COMMAND_QUEST_EXPLORED, SCRIPT_COMMAND_REMOVE_AURA, SCRIPT_COMMAND_RESPAWN_GAMEOBJECT, SCRIPT_COMMAND_TALK, SCRIPT_COMMAND_TELEPORT_TO, SCRIPT_COMMAND_TEMP_SUMMON_CREATURE, ScriptsStart(), GameObject::SetLootState(), GameObject::SetRespawnTime(), SF_CASTSPELL_SEARCH_CREATURE, SF_CASTSPELL_SOURCE_TO_SOURCE, SF_CASTSPELL_SOURCE_TO_TARGET, SF_CASTSPELL_TARGET_TO_SOURCE, SF_CASTSPELL_TARGET_TO_TARGET, SF_CASTSPELL_TRIGGERED, SF_EMOTE_USE_STATE, SF_KILLCREDIT_REWARD_GROUP, SF_ORIENTATION_FACE_TARGET, SF_PLAYSOUND_DISTANCE_SOUND, SF_PLAYSOUND_TARGET_PLAYER, SF_REMOVEAURA_REVERSE, SF_TALK_USE_PLAYER, SF_TELEPORT_USE_CREATURE, sLog, sObjectMgr, ScriptAction::sourceGUID, sWaypointMgr, sWorld, ScriptInfo::Talk, ScriptAction::targetGUID, ScriptInfo::TeleportTo, TEMPSUMMON_TIMED_OR_DEAD_DESPAWN, ScriptInfo::TempSummonCreature, Object::ToPlayer(), ScriptInfo::type, TYPEID_GAMEOBJECT, TYPEID_PLAYER, TYPEID_UNIT, TYPEMASK_UNIT, UNIT_NPC_EMOTESTATE, and Cell::Visit().

Referenced by ScriptCommandStart(), ScriptsStart(), and Update().

289 {
290  if (m_scriptSchedule.empty())
291  return;
292 
293  // Process overdue queued scripts
294  std::multimap<time_t, ScriptAction>::iterator iter = m_scriptSchedule.begin();
295  // ok as multimap is a *sorted* associative container
296  while (!m_scriptSchedule.empty() && (iter->first <= sWorld.GetGameTime()))
297  {
298  ScriptAction const& step = iter->second;
299 
300  Object* source = NULL;
301 
302  if (step.sourceGUID)
303  {
304  switch (GUID_HIPART(step.sourceGUID))
305  {
306  case HIGHGUID_ITEM:
307  // case HIGHGUID_CONTAINER: == HIGHGUID_ITEM
308  {
310  if (player)
311  source = player->GetItemByGuid(step.sourceGUID);
312  break;
313  }
314  case HIGHGUID_UNIT:
316  break;
317  case HIGHGUID_PET:
318  source = HashMapHolder<Pet>::Find(step.sourceGUID);
319  break;
320  case HIGHGUID_PLAYER:
322  break;
323  case HIGHGUID_GAMEOBJECT:
325  break;
326  case HIGHGUID_CORPSE:
328  break;
330  for (MapManager::TransportSet::iterator iter = MapManager::Instance().m_Transports.begin(); iter != MapManager::Instance().m_Transports.end(); ++iter)
331  {
332  if ((*iter)->GetGUID() == step.sourceGUID)
333  {
334  source = reinterpret_cast<Object*>(*iter);
335  break;
336  }
337  }
338  break;
339  default:
340  sLog.outError("*_script source with unsupported high guid value %u", GUID_HIPART(step.sourceGUID));
341  break;
342  }
343  }
344 
345  //if (source && !source->IsInWorld()) source = NULL;
346 
347  Object* target = NULL;
348 
349  if (step.targetGUID)
350  {
351  switch (GUID_HIPART(step.targetGUID))
352  {
353  case HIGHGUID_UNIT:
355  break;
356  case HIGHGUID_PET:
357  target = HashMapHolder<Pet>::Find(step.targetGUID);
358  break;
359  case HIGHGUID_PLAYER: // empty GUID case also
361  break;
362  case HIGHGUID_GAMEOBJECT:
364  break;
365  case HIGHGUID_CORPSE:
367  break;
368  default:
369  sLog.outError("*_script source with unsupported high guid value %u", GUID_HIPART(step.targetGUID));
370  break;
371  }
372  }
373 
374  //if (target && !target->IsInWorld()) target = NULL;
375 
376  std::string tableName = GetScriptsTableNameByType(step.script->type);
377  std::string commandName = GetScriptCommandName(step.script->command);
378  switch (step.script->command)
379  {
380  case SCRIPT_COMMAND_TALK:
381  if (step.script->Talk.ChatType > CHAT_TYPE_WHISPER && step.script->Talk.ChatType != CHAT_MSG_RAID_BOSS_WHISPER)
382  {
383  sLog.outError("%s invalid chat type (%u) specified, skipping.", step.script->GetDebugInfo().c_str(), step.script->Talk.ChatType);
384  break;
385  }
386  if (step.script->Talk.Flags & SF_TALK_USE_PLAYER)
387  {
388  if (Player* pSource = _GetScriptPlayerSourceOrTarget(source, target, step.script))
389  {
390  uint64 targetGUID = target ? target->GetGUID() : 0;
391  uint32 loc_idx = pSource->GetSession()->GetSessionDbLocaleIndex();
392  std::string text(sObjectMgr.GetOregonString(step.script->Talk.TextID, loc_idx));
393 
394  switch (step.script->Talk.ChatType)
395  {
396  case CHAT_TYPE_SAY:
397  pSource->Say(text, LANG_UNIVERSAL);
398  break;
399  case CHAT_TYPE_YELL:
400  pSource->Yell(text, LANG_UNIVERSAL);
401  break;
404  pSource->TextEmote(text);
405  break;
406  case CHAT_TYPE_WHISPER:
408  if (!targetGUID || !IS_PLAYER_GUID(targetGUID))
409  {
410  sLog.outError("%s attempt to whisper to non-player unit, skipping.", step.script->GetDebugInfo().c_str());
411  break;
412  }
413  pSource->Whisper(text, LANG_UNIVERSAL, targetGUID);
414  break;
415  default:
416  break; // must be already checked at load
417  }
418  }
419  }
420  else
421  {
422  // Source or target must be Creature.
423  if (Creature* cSource = _GetScriptCreatureSourceOrTarget(source, target, step.script))
424  {
425  uint64 targetGUID = target ? target->GetGUID() : 0;
426  switch (step.script->Talk.ChatType)
427  {
428  case CHAT_TYPE_SAY:
429  cSource->Say(step.script->Talk.TextID, LANG_UNIVERSAL, targetGUID);
430  break;
431  case CHAT_TYPE_YELL:
432  cSource->Yell(step.script->Talk.TextID, LANG_UNIVERSAL, targetGUID);
433  break;
435  cSource->TextEmote(step.script->Talk.TextID, targetGUID);
436  break;
438  cSource->MonsterTextEmote(step.script->Talk.TextID, targetGUID, true);
439  break;
440  case CHAT_TYPE_WHISPER:
441  if (!targetGUID || !IS_PLAYER_GUID(targetGUID))
442  {
443  sLog.outError("%s attempt to whisper to non-player unit, skipping.", step.script->GetDebugInfo().c_str());
444  break;
445  }
446  cSource->Whisper(step.script->Talk.TextID, targetGUID);
447  break;
448  case CHAT_MSG_RAID_BOSS_WHISPER: //42
449  if (!targetGUID || !IS_PLAYER_GUID(targetGUID))
450  {
451  sLog.outError("%s attempt to raidbosswhisper to non-player unit, skipping.", step.script->GetDebugInfo().c_str());
452  break;
453  }
454  cSource->MonsterWhisper(step.script->Talk.TextID, targetGUID, true);
455  break;
456  default:
457  break; // must be already checked at load
458  }
459  }
460  }
461  break;
462 
464  // Source or target must be Creature.
465  if (Creature* cSource = _GetScriptCreatureSourceOrTarget(source, target, step.script))
466  {
467  if (step.script->Emote.Flags & SF_EMOTE_USE_STATE)
468  cSource->SetUInt32Value(UNIT_NPC_EMOTESTATE, step.script->Emote.EmoteID);
469  else
470  cSource->HandleEmoteCommand(step.script->Emote.EmoteID);
471  }
472  break;
473 
475  // Source or target must be Creature.
476  if (Creature* cSource = _GetScriptCreatureSourceOrTarget(source, target, step.script))
477  {
478  // Validate field number.
479  if (step.script->FieldSet.FieldID <= OBJECT_FIELD_ENTRY || step.script->FieldSet.FieldID >= cSource->GetValuesCount())
480  sLog.outError("%s wrong field %u (max count: %u) in object (TypeId: %u, Entry: %u, GUID: %u) specified, skipping.",
481  step.script->GetDebugInfo().c_str(), step.script->FieldSet.FieldID,
482  cSource->GetValuesCount(), cSource->GetTypeId(), cSource->GetEntry(), cSource->GetGUIDLow());
483  else
484  cSource->SetUInt32Value(step.script->FieldSet.FieldID, step.script->FieldSet.FieldValue);
485  }
486  break;
487 
489  // Source or target must be Creature.
490  if (Creature* cSource = _GetScriptCreatureSourceOrTarget(source, target, step.script))
491  {
492  Movement::MoveSplineInit init(*cSource);
493  init.MoveTo(step.script->MoveTo.DestX, step.script->MoveTo.DestY, step.script->MoveTo.DestZ, true);
494  int32 duration = init.Launch();
495  if (duration != step.script->MoveTo.TravelTime)
496  sLog.outError("SCRIPT_COMMAND_MOVE_TO : Travel time and duration from spline don't match (travel time : %u, duration : %i). Object (TypeId: %u, Entry: %u, GUID: %u)",
497  step.script->MoveTo.TravelTime, duration,
498  source->GetTypeId(), source->GetEntry(), source->GetGUIDLow());
499  cSource->GetMap()->CreatureRelocation(cSource, step.script->MoveTo.DestX, step.script->MoveTo.DestY, step.script->MoveTo.DestZ, ((Unit *)source)->GetAngle(step.script->MoveTo.DestX, step.script->MoveTo.DestY));
500  }
501  break;
502 
504  // Source or target must be Creature.
505  if (Creature* cSource = _GetScriptCreatureSourceOrTarget(source, target, step.script))
506  {
507  // Validate field number.
508  if (step.script->FlagToggle.FieldID <= OBJECT_FIELD_ENTRY || step.script->FlagToggle.FieldID >= cSource->GetValuesCount())
509  sLog.outError("%s wrong field %u (max count: %u) in object (TypeId: %u, Entry: %u, GUID: %u) specified, skipping.",
510  step.script->GetDebugInfo().c_str(), step.script->FlagToggle.FieldID,
511  source->GetValuesCount(), source->GetTypeId(), source->GetEntry(), source->GetGUIDLow());
512  else
513  cSource->SetFlag(step.script->FlagToggle.FieldID, step.script->FlagToggle.FieldValue);
514  }
515  break;
516 
518  // Source or target must be Creature.
519  if (Creature* cSource = _GetScriptCreatureSourceOrTarget(source, target, step.script))
520  {
521  // Validate field number.
522  if (step.script->FlagToggle.FieldID <= OBJECT_FIELD_ENTRY || step.script->FlagToggle.FieldID >= cSource->GetValuesCount())
523  sLog.outError("%s wrong field %u (max count: %u) in object (TypeId: %u, Entry: %u, GUID: %u) specified, skipping.",
524  step.script->GetDebugInfo().c_str(), step.script->FlagToggle.FieldID,
525  source->GetValuesCount(), source->GetTypeId(), source->GetEntry(), source->GetGUIDLow());
526  else
527  cSource->RemoveFlag(step.script->FlagToggle.FieldID, step.script->FlagToggle.FieldValue);
528  }
529  break;
530 
532  if (step.script->TeleportTo.Flags & SF_TELEPORT_USE_CREATURE)
533  {
534  // Source or target must be Creature.
535  if (Creature* cSource = _GetScriptCreatureSourceOrTarget(source, target, step.script, true))
536  cSource->NearTeleportTo(step.script->TeleportTo.DestX, step.script->TeleportTo.DestY, step.script->TeleportTo.DestZ, step.script->TeleportTo.Orientation);
537  }
538  else
539  {
540  // Source or target must be Player.
541  if (Player* pSource = _GetScriptPlayerSourceOrTarget(source, target, step.script))
542  pSource->TeleportTo(step.script->TeleportTo.MapID, step.script->TeleportTo.DestX, step.script->TeleportTo.DestY, step.script->TeleportTo.DestZ, step.script->TeleportTo.Orientation);
543  }
544  break;
545 
547  {
548  if (!source)
549  {
550  sLog.outError("%s source object is NULL.", step.script->GetDebugInfo().c_str());
551  break;
552  }
553  if (!target)
554  {
555  sLog.outError("%s target object is NULL.", step.script->GetDebugInfo().c_str());
556  break;
557  }
558 
559  // when script called for item spell casting then target == (unit or GO) and source is player
560  WorldObject* worldObject;
561  Player* pTarget = target->ToPlayer();
562  if (pTarget)
563  {
564  if (source->GetTypeId() != TYPEID_UNIT && source->GetTypeId() != TYPEID_GAMEOBJECT && source->GetTypeId() != TYPEID_PLAYER)
565  {
566  sLog.outError("%s source is not unit, gameobject or player (TypeId: %u, Entry: %u, GUID: %u), skipping.",
567  step.script->GetDebugInfo().c_str(), source->GetTypeId(), source->GetEntry(), source->GetGUIDLow());
568  break;
569  }
570  worldObject = dynamic_cast<WorldObject*>(source);
571  }
572  else
573  {
574  pTarget = source->ToPlayer();
575  if (pTarget)
576  {
577  if (target->GetTypeId() != TYPEID_UNIT && target->GetTypeId() != TYPEID_GAMEOBJECT && target->GetTypeId() != TYPEID_PLAYER)
578  {
579  sLog.outError("%s target is not unit, gameobject or player (TypeId: %u, Entry: %u, GUID: %u), skipping.",
580  step.script->GetDebugInfo().c_str(), target->GetTypeId(), target->GetEntry(), target->GetGUIDLow());
581  break;
582  }
583  worldObject = dynamic_cast<WorldObject*>(target);
584  }
585  else
586  {
587  sLog.outError("%s neither source nor target is player (source: TypeId: %u, Entry: %u, GUID: %u; target: TypeId: %u, Entry: %u, GUID: %u), skipping.",
588  step.script->GetDebugInfo().c_str(),
589  source ? source->GetTypeId() : 0, source ? source->GetEntry() : 0, source ? source->GetGUIDLow() : 0,
590  target ? target->GetTypeId() : 0, target ? target->GetEntry() : 0, target ? target->GetGUIDLow() : 0);
591  break;
592  }
593  }
594 
595  // quest id and flags checked at script loading
596  if ((worldObject->GetTypeId() != TYPEID_UNIT || ((Unit*)worldObject)->IsAlive()) &&
597  (step.script->QuestExplored.Distance == 0 || worldObject->IsWithinDistInMap(pTarget, float(step.script->QuestExplored.Distance))))
598  pTarget->AreaExploredOrEventHappens(step.script->QuestExplored.QuestID);
599  else
600  pTarget->FailQuest(step.script->QuestExplored.QuestID);
601 
602  break;
603  }
604 
606  // Source or target must be Player.
607  if (Player* pSource = _GetScriptPlayerSourceOrTarget(source, target, step.script))
608  {
609  if (step.script->KillCredit.Flags & SF_KILLCREDIT_REWARD_GROUP)
610  pSource->RewardPlayerAndGroupAtEvent(step.script->KillCredit.CreatureEntry, pSource);
611  else
612  pSource->KilledMonsterCredit(step.script->KillCredit.CreatureEntry, 0);
613  }
614  break;
615 
617  if (!step.script->RespawnGameobject.GOGuid)
618  {
619  sLog.outError("%s gameobject guid (datalong) is not specified.", step.script->GetDebugInfo().c_str());
620  break;
621  }
622 
623  // Source or target must be WorldObject.
624  if (WorldObject* pSummoner = _GetScriptWorldObject(source, true, step.script))
625  {
626  GameObject* pGO = _FindGameObject(pSummoner, step.script->RespawnGameobject.GOGuid);
627  if (!pGO)
628  {
629  sLog.outError("%s gameobject was not found (guid: %u).", step.script->GetDebugInfo().c_str(), step.script->RespawnGameobject.GOGuid);
630  break;
631  }
632 
633  if (pGO->GetGoType() == GAMEOBJECT_TYPE_FISHINGNODE ||
634  pGO->GetGoType() == GAMEOBJECT_TYPE_DOOR ||
635  pGO->GetGoType() == GAMEOBJECT_TYPE_BUTTON ||
637  {
638  sLog.outError("%s can not be used with gameobject of type %u (guid: %u).",
639  step.script->GetDebugInfo().c_str(), uint32(pGO->GetGoType()), step.script->RespawnGameobject.GOGuid);
640  break;
641  }
642 
643  // Check that GO is not spawned
644  if (!pGO->isSpawned())
645  {
646  int32 nTimeToDespawn = std::max(5, int32(step.script->RespawnGameobject.DespawnDelay));
647  pGO->SetLootState(GO_READY);
648  pGO->SetRespawnTime(nTimeToDespawn);
649 
650  pGO->GetMap()->AddToMap(pGO);
651  }
652  }
653  break;
654 
656  {
657  // Source must be WorldObject.
658  if (WorldObject* pSummoner = _GetScriptWorldObject(source, true, step.script))
659  {
660  if (!step.script->TempSummonCreature.CreatureEntry)
661  sLog.outError("%s creature entry (datalong) is not specified.", step.script->GetDebugInfo().c_str());
662  else
663  {
664  float x = step.script->TempSummonCreature.PosX;
665  float y = step.script->TempSummonCreature.PosY;
666  float z = step.script->TempSummonCreature.PosZ;
667  float o = step.script->TempSummonCreature.Orientation;
668 
669  if (!pSummoner->SummonCreature(step.script->TempSummonCreature.CreatureEntry, x, y, z, o, TEMPSUMMON_TIMED_OR_DEAD_DESPAWN, step.script->TempSummonCreature.DespawnDelay))
670  sLog.outError("%s creature was not spawned (entry: %u).", step.script->GetDebugInfo().c_str(), step.script->TempSummonCreature.CreatureEntry);
671  }
672  }
673  break;
674  }
675 
678  _ScriptProcessDoor(source, target, step.script);
679  break;
680 
682  // Source must be Unit.
683  if (Unit* pSource = _GetScriptUnit(source, true, step.script))
684  {
685  // Target must be GameObject.
686  if (!target)
687  {
688  sLog.outError("%s target object is NULL.", step.script->GetDebugInfo().c_str());
689  break;
690  }
691 
692  if (target->GetTypeId() != TYPEID_GAMEOBJECT)
693  {
694  sLog.outError("%s target object is not gameobject (TypeId: %u, Entry: %u, GUID: %u), skipping.",
695  step.script->GetDebugInfo().c_str(), target->GetTypeId(), target->GetEntry(), target->GetGUIDLow());
696  break;
697  }
698 
699  if (GameObject* pGO = dynamic_cast<GameObject*>(target))
700  if (pGO->IsUsedBy(pSource->GetGUID()))
701  pGO->Use(pSource);
702  }
703  break;
704 
706  {
707  // Source (datalong2 != 0) or target (datalong2 == 0) must be Unit.
708  bool bReverse = step.script->RemoveAura.Flags & SF_REMOVEAURA_REVERSE;
709  if (Unit* pTarget = _GetScriptUnit(bReverse ? source : target, bReverse, step.script))
710  pTarget->RemoveAurasDueToSpell(step.script->RemoveAura.SpellID);
711  break;
712  }
713 
715  {
716  // @todo Allow gameobjects to be targets and casters
717  if (!source && !target)
718  {
719  sLog.outError("%s source and target objects are NULL.", step.script->GetDebugInfo().c_str());
720  break;
721  }
722 
723  Unit* uSource = NULL;
724  Unit* uTarget = NULL;
725  // source/target cast spell at target/source (script->datalong2: 0: s->t 1: s->s 2: t->t 3: t->s
726  switch (step.script->CastSpell.Flags)
727  {
728  case SF_CASTSPELL_SOURCE_TO_TARGET: // source -> target
729  uSource = dynamic_cast<Unit*>(source);
730  uTarget = dynamic_cast<Unit*>(target);
731  break;
732  case SF_CASTSPELL_SOURCE_TO_SOURCE: // source -> source
733  uSource = dynamic_cast<Unit*>(source);
734  uTarget = uSource;
735  break;
736  case SF_CASTSPELL_TARGET_TO_TARGET: // target -> target
737  uSource = dynamic_cast<Unit*>(target);
738  uTarget = uSource;
739  break;
740  case SF_CASTSPELL_TARGET_TO_SOURCE: // target -> source
741  uSource = dynamic_cast<Unit*>(target);
742  uTarget = dynamic_cast<Unit*>(source);
743  break;
744  case SF_CASTSPELL_SEARCH_CREATURE: // source -> creature with entry
745  uSource = dynamic_cast<Unit*>(source);
746  uTarget = GetClosestCreatureWithEntry(uSource, abs(step.script->CastSpell.CreatureEntry), step.script->CastSpell.SearchRadius);
747  break;
748  }
749 
750  if (!uSource || !uSource->isType(TYPEMASK_UNIT))
751  {
752  sLog.outError("%s no source unit found for spell %u", step.script->GetDebugInfo().c_str(), step.script->CastSpell.SpellID);
753  break;
754  }
755 
756  if (!uTarget || !uTarget->isType(TYPEMASK_UNIT))
757  {
758  sLog.outError("%s no target unit found for spell %u", step.script->GetDebugInfo().c_str(), step.script->CastSpell.SpellID);
759  break;
760  }
761 
762  bool triggered = (step.script->CastSpell.Flags != 4) ?
763  step.script->CastSpell.CreatureEntry & SF_CASTSPELL_TRIGGERED :
764  step.script->CastSpell.CreatureEntry < 0;
765  uSource->CastSpell(uTarget, step.script->CastSpell.SpellID, triggered);
766  break;
767  }
768 
770  // Source must be WorldObject.
771  if (WorldObject* pSource = _GetScriptWorldObject(source, true, step.script))
772  {
773  // PlaySound.Flags bitmask: 0/1=anyone/target
774  Player* pTarget = NULL;
775  if (step.script->PlaySound.Flags & SF_PLAYSOUND_TARGET_PLAYER)
776  {
777  // Target must be Player.
778  pTarget = _GetScriptPlayer(target, false, step.script);
779  if (!pTarget)
780  break;
781  }
782 
783  // PlaySound.Flags bitmask: 0/2=without/with distance dependent
784  if (step.script->PlaySound.Flags & SF_PLAYSOUND_DISTANCE_SOUND)
785  pSource->PlayDistanceSound(step.script->PlaySound.SoundID, pTarget);
786  else
787  pSource->PlayDirectSound(step.script->PlaySound.SoundID, pTarget);
788  }
789  break;
790 
792  // Target or source must be Player.
793  if (Player* pReceiver = _GetScriptPlayerSourceOrTarget(source, target, step.script))
794  {
795  ItemPosCountVec dest;
796  uint8 msg = pReceiver->CanStoreNewItem(NULL_BAG, NULL_SLOT, dest, step.script->CreateItem.ItemEntry, step.script->CreateItem.Amount);
797  if (msg == EQUIP_ERR_OK)
798  {
799  if (Item* item = pReceiver->StoreNewItem(dest, step.script->CreateItem.ItemEntry, true))
800  pReceiver->SendNewItem(item, step.script->CreateItem.Amount, false, true);
801  }
802  else
803  pReceiver->SendEquipError(msg, NULL, NULL);
804  }
805  break;
806 
808  // Target or source must be Creature.
809  if (Creature* cSource = _GetScriptCreatureSourceOrTarget(source, target, step.script, true))
810  cSource->ForcedDespawn(step.script->DespawnSelf.DespawnDelay);
811  break;
813  break;
815  // Source must be Unit.
816  if (Unit* pSource = _GetScriptUnit(source, true, step.script))
817  {
818  if (!sWaypointMgr->GetPath(step.script->LoadPath.PathID))
819  sLog.outError("%s source object has an invalid path (%u), skipping.", step.script->GetDebugInfo().c_str(), step.script->LoadPath.PathID);
820  else
821  pSource->GetMotionMaster()->MovePath(step.script->LoadPath.PathID, step.script->LoadPath.IsRepeatable);
822  }
823  break;
824 
826  {
827  if (!step.script->CallScript.CreatureEntry)
828  {
829  sLog.outError("%s creature entry is not specified, skipping.", step.script->GetDebugInfo().c_str());
830  break;
831  }
832  if (!step.script->CallScript.ScriptID)
833  {
834  sLog.outError("%s script id is not specified, skipping.", step.script->GetDebugInfo().c_str());
835  break;
836  }
837 
838  Creature* cTarget = NULL;
839  WorldObject* wSource = dynamic_cast <WorldObject*> (source);
840  if (wSource) //using grid searcher
841  {
842  CellCoord p(Oregon::ComputeCellCoord(wSource->GetPositionX(), wSource->GetPositionY()));
843  Cell cell(p);
844