23 #include "ace/RW_Thread_Mutex.h" 24 #include "ace/Thread_Mutex.h" 56 namespace Oregon {
struct ObjectUpdater; }
69 static const uint32 MAP_MAGIC = 0x5350414D;
70 static const uint32 MAP_VERSION_MAGIC = 0x332E3176;
71 static const uint32 MAP_AREA_MAGIC = 0x41455241;
72 static const uint32 MAP_HEIGHT_MAGIC = 0x5447484D;
73 static const uint32 MAP_LIQUID_MAGIC = 0x51494C4D;
90 #define MAP_AREA_NO_AREA 0x0001 99 #define MAP_HEIGHT_NO_HEIGHT 0x0001 100 #define MAP_HEIGHT_AS_INT16 0x0002 101 #define MAP_HEIGHT_AS_INT8 0x0004 111 #define MAP_LIQUID_NO_TYPE 0x0001 112 #define MAP_LIQUID_NO_HEIGHT 0x0002 136 #define MAP_LIQUID_TYPE_NO_WATER 0x00 137 #define MAP_LIQUID_TYPE_MAGMA 0x01 138 #define MAP_LIQUID_TYPE_OCEAN 0x02 139 #define MAP_LIQUID_TYPE_SLIME 0x04 140 #define MAP_LIQUID_TYPE_WATER 0x08 142 #define MAP_ALL_LIQUIDS (MAP_LIQUID_TYPE_WATER | MAP_LIQUID_TYPE_MAGMA | MAP_LIQUID_TYPE_OCEAN | MAP_LIQUID_TYPE_SLIME) 144 #define MAP_LIQUID_TYPE_DARK_WATER 0x10 145 #define MAP_LIQUID_TYPE_WMO_WATER 0x20 187 bool loadAreaData(FILE* in,
uint32 offset,
uint32 size);
188 bool loadHeightData(FILE* in,
uint32 offset,
uint32 size);
189 bool loadLiquidData(FILE* in,
uint32 offset,
uint32 size);
192 typedef float (
GridMap::*pGetHeightPtr) (
float x,
float y)
const;
194 float getHeightFromFloat(
float x,
float y)
const;
195 float getHeightFromUint16(
float x,
float y)
const;
196 float getHeightFromUint8(
float x,
float y)
const;
197 float getHeightFromFlat(
float x,
float y)
const;
202 bool loadData(
const char* filename);
205 uint16 getArea(
float x,
float y);
208 return (this->*m_gridGetHeight)(x, y);
210 float getLiquidLevel(
float x,
float y);
211 uint8 getTerrainType(
float x,
float y);
218 CreatureMover(
float _x,
float _y,
float _z,
float _ang) : x(_x), y(_y), z(_z), ang(_ang) {}
224 #if defined(__GNUC__) 250 #if defined(__GNUC__) 258 #define MAX_HEIGHT 100000.0f // can be use for find ground height at surface 259 #define INVALID_HEIGHT -100000.0f // for check, must be equal to VMAP_INVALID_HEIGHT, real value for unknown height is VMAP_INVALID_HEIGHT_VALUE 260 #define MAX_FALL_DISTANCE 250000.0f // "unlimited fall" to find VMap ground if it is available, just larger than MAX_HEIGHT - INVALID_HEIGHT 261 #define DEFAULT_HEIGHT_SEARCH 50.0f // default search distance to find height at nearby locations 262 #define MIN_UNLOAD_DELAY 1 // immediate unload 276 if (!m_unloadTimer)
return false;
277 if (m_unloadTimer <= diff)
return true;
278 m_unloadTimer -= diff;
282 virtual bool AddPlayerToMap(
Player*);
283 virtual void RemovePlayerFromMap(
Player*,
bool);
285 template<
class T>
bool AddToMap(T*);
286 template<
class T>
void RemoveFromMap(T*,
bool);
289 virtual void Update(
const uint32&);
294 virtual void InitVisibilityDistance();
296 void PlayerRelocation(
Player*,
float x,
float y,
float z,
float orientation);
297 void CreatureRelocation(
Creature* creature,
float x,
float y,
float z,
float ang,
bool respawnRelocationOnFail =
true);
320 void LoadGrid(
float x,
float y);
321 bool UnloadGrid(
NGridType& ngrid,
bool pForce);
322 virtual void UnloadAll();
335 return i_mapEntry->MapID;
338 static bool ExistMap(
uint32 mapid,
int gx,
int gy);
339 static bool ExistVMap(
uint32 mapid,
int gx,
int gy);
341 static void InitStateMachine();
342 static void DeleteStateMachine();
352 float GetWaterOrGroundLevel(
float x,
float y,
float z,
float* ground = NULL,
bool swim =
false)
const;
353 float GetHeight(
float x,
float y,
float z,
bool checkVMap =
true,
float maxSearchDist =
DEFAULT_HEIGHT_SEARCH)
const;
357 uint16 GetAreaFlag(
float x,
float y,
float z,
bool* isOutdoors = 0)
const;
358 bool GetAreaInfo(
float x,
float y,
float z,
uint32& mogpflags,
int32& adtId,
int32& rootId,
int32& groupId)
const;
360 bool IsOutdoors(
float x,
float y,
float z)
const;
362 uint8 GetTerrainType(
float x,
float y)
const;
363 float GetWaterLevel(
float x,
float y)
const;
364 bool IsInWater(
float x,
float y,
float z,
LiquidData* data =
nullptr)
const;
365 bool IsUnderWater(
float x,
float y,
float z)
const;
366 bool IsSwimmable(
float x,
float y,
float z,
LiquidData* data =
nullptr)
const;
373 return GetAreaId(GetAreaFlag(x, y, z), GetId());
378 return GetZoneId(GetAreaFlag(x, y, z), GetId());
381 void MoveAllCreaturesInMoveList();
382 void RemoveAllObjectsInRemoveList();
383 virtual void RemoveAllPlayers();
385 bool CreatureRespawnRelocation(
Creature* c);
388 bool CheckGridIntegrity(
Creature* c,
bool moved)
const;
396 return (i_spawnMode);
402 CANNOT_ENTER_ALREADY_IN_MAP = 1,
412 CANNOT_ENTER_UNSPECIFIED_REASON
416 const char* GetMapName()
const;
424 return i_mapEntry && i_mapEntry->Instanceable();
429 return i_mapEntry && i_mapEntry->IsDungeon();
433 return i_mapEntry && i_mapEntry->IsRaid();
441 return i_mapEntry && i_mapEntry->IsBattleground();
445 return i_mapEntry && i_mapEntry->IsBattleArena();
449 return i_mapEntry && i_mapEntry->IsBattlegroundOrArena();
453 void AddObjectToSwitchList(
WorldObject* obj,
bool on);
454 virtual void DelayedUpdate(
const uint32 diff);
461 marked_cells.reset();
465 return marked_cells.test(pCellId);
469 marked_cells.set(pCellId);
474 return !m_mapRefManager.isEmpty();
476 uint32 GetPlayersCountExceptGMs()
const;
477 bool ActiveObjectsNearGrid(
NGridType const& ngrid)
const;
481 i_worldObjects.insert(obj);
485 i_worldObjects.erase(obj);
493 return m_mapRefManager;
497 void ScriptsStart(std::map<
uint32, std::multimap<uint32, ScriptInfo> >
const& scripts,
uint32 id,
Object* source,
Object* target);
504 AddToActiveHelper(obj);
513 RemoveFromActiveHelper(obj);
516 void RemoveFromActive(
Creature* obj);
518 void SwitchGridContainers(
Creature* creature,
bool toWorldContainer);
519 template<
class NOTIFIER>
void VisitAll(
const float& x,
const float& y,
float radius, NOTIFIER& notifier);
520 template<
class NOTIFIER>
void VisitWorld(
const float& x,
const float& y,
float radius, NOTIFIER& notifier);
521 template<
class NOTIFIER>
void VisitGrid(
const float& x,
const float& y,
float radius, NOTIFIER& notifier);
524 void UpdateIteratorBack(
Player* player);
531 bool isInLineOfSight(
float x1,
float y1,
float z1,
float x2,
float y2,
float z2)
const;
536 bool getObjectHitPos(
float x1,
float y1,
float z1,
float x2,
float y2,
float z2,
float& rx,
float &ry,
float& rz,
float modifyDist);
538 void LoadMapAndVMap(
int gx,
int gy);
539 void LoadVMap(
int gx,
int gy);
540 void LoadMMap(
int gx,
int gy);
541 void LoadMap(
int gx,
int gy,
bool reload =
false);
542 GridMap* GetGrid(
float x,
float y);
549 void SendInitSelf(
Player* player);
551 void SendInitTransports(
Player* player);
552 void SendRemoveTransports(
Player* player);
554 bool CreatureCellRelocation(
Creature* creature,
Cell new_cell);
556 void AddCreatureToMoveList(
Creature* c,
float x,
float y,
float z,
float ang);
559 bool IsGridLoaded(
const GridCoord &)
const;
560 void EnsureGridCreated(
const GridCoord&);
561 bool EnsureGridLoaded(
Cell const&);
562 void EnsureGridLoadedForActiveObject(
Cell const&,
WorldObject*
object);
566 pNGridType->
link(
this);
569 template<
class T>
void AddType(T* obj);
570 template<
class T>
void RemoveType(T* obj,
bool);
576 return i_grids[x][y];
581 return getNGrid(x, y)->isGridObjectDataLoaded();
585 getNGrid(x, y)->setGridObjectDataLoaded(pLoaded);
589 void ScriptsProcess();
633 std::bitset<TOTAL_NUMBER_OF_CELLS_PER_MAP* TOTAL_NUMBER_OF_CELLS_PER_MAP>
marked_cells;
637 void ProcessRelocationNotifies(
const uint32& diff);
647 void AddToGrid(T*
object,
Cell const& cell);
650 void DeleteFromWorld(T*);
655 m_activeNonPlayers.insert(obj);
662 if (m_activeNonPlayersIter != m_activeNonPlayers.end())
664 ActiveNonPlayers::iterator itr = m_activeNonPlayers.find(obj);
665 if (itr == m_activeNonPlayers.end())
667 if (itr == m_activeNonPlayersIter)
668 ++m_activeNonPlayersIter;
669 m_activeNonPlayers.erase(itr);
672 m_activeNonPlayers.erase(obj);
691 bool AddPlayerToMap(
Player*)
override;
692 void RemovePlayerFromMap(
Player*,
bool)
override;
693 void Update(
const uint32&)
override;
694 void CreateInstanceData(
bool load);
695 bool Reset(
uint8 method);
704 void PermBindAllPlayers(
Player* player);
705 time_t GetResetTime();
706 void UnloadAll()
override;
708 void SendResetWarnings(
uint32 timeLeft)
const;
709 void SetResetSchedule(
bool on);
711 void InitVisibilityDistance()
override;
725 bool AddPlayerToMap(
Player*)
override;
726 void RemovePlayerFromMap(
Player*,
bool)
override;
729 void RemoveAllPlayers()
override;
731 void InitVisibilityDistance()
override;
754 template<
class T,
class CONTAINER>
764 EnsureGridLoaded(cell);
765 getNGrid(x, y)->VisitGrid(cell_x, cell_y, visitor);
769 template<
class NOTIFIER>
770 inline void Map::VisitAll(
float const& x,
float const& y,
float radius, NOTIFIER& notifier)
777 cell.
Visit(p, world_object_notifier, *
this, radius, x, y);
779 cell.
Visit(p, grid_object_notifier, *
this, radius, x, y);
782 template<
class NOTIFIER>
783 inline void Map::VisitWorld(
const float &x,
const float &y,
float radius, NOTIFIER ¬ifier)
790 cell.
Visit(p, world_object_notifier, *
this, radius, x, y);
793 template<
class NOTIFIER>
794 inline void Map::VisitGrid(
const float &x,
const float &y,
float radius, NOTIFIER ¬ifier)
801 cell.
Visit(p, grid_object_notifier, *
this, radius, x, y);
std::multimap< time_t, ScriptAction > m_scriptSchedule
despawns when UnSummon() is called
bool IsBattlegroundOrArena() const
DungeonDifficulty GetDifficulty() const
uint8 GetSpawnMode() const
bool IsBattleground() const
std::set< WorldObject * > i_objectsToRemove
UNORDERED_MAP< Creature *, CreatureMover > CreatureMoveList
MapEntry const * i_mapEntry
bool isCellMarked(uint32 pCellId)
#define DEFAULT_HEIGHT_SEARCH
void RemoveFromActiveHelper(T *obj)
ScriptInfo const * script
NGridType * getNGrid(uint32 x, uint32 y) const
void ResetTimeTracker(time_t interval)
std::map< WorldObject *, bool > i_objectsToSwitch
void SetBG(Battleground *bg)
void Remove(const GameObjectModel &mdl)
#define MAX_NUMBER_OF_GRIDS
void AddToActiveHelper(T *obj)
void SetUnloadReferenceLock(const GridCoord &p, bool on)
void RemoveWorldObject(WorldObject *obj)
bool IsGridLoaded(float x, float y) const
void RemoveFromActive(T *obj)
ActiveNonPlayers m_activeNonPlayers
CreatureMoveList i_creaturesToMove
bool CanUnload(uint32 diff)
float getHeight(float x, float y)
DynamicMapTree m_dyn_tree
pGetHeightPtr m_gridGetHeight
bool isGridObjectDataLoaded(uint32 x, uint32 y) const
void markCell(uint32 pCellId)
void Insert(const GameObjectModel &mdl)
InstanceData * GetInstanceData()
std::set< WorldObject * > ActiveNonPlayers
float m_gridIntHeightMultiplier
CreatureGroupHolderType CreatureGroupHolder
InstanceMap * ToInstanceMap()
bool IsRegularDifficulty() const
void SetUnloadLock(const GridCoord &p, bool on)
void VisitAll(const float &x, const float &y, float radius, NOTIFIER ¬ifier)
std::set< WorldObject * > i_worldObjects
float GetVisibilityRange() const
CellCoord ComputeCellCoord(float x, float y)
uint32 GetZoneId(float x, float y, float z) const
void buildNGridLinkage(NGridType *pNGridType)
std::bitset< TOTAL_NUMBER_OF_CELLS_PER_MAP *TOTAL_NUMBER_OF_CELLS_PER_MAP > marked_cells
PlayerList const & GetPlayers() const
ActiveNonPlayers::iterator m_activeNonPlayersIter
void Visit(const Cell &cell, TypeContainerVisitor< T, CONTAINER > &visitor)
int32 m_VisibilityNotifyPeriod
std::map< uint32, CreatureGroup * > CreatureGroupHolderType
InstanceMap const * ToInstanceMap() const
uint32 GetAreaId(float x, float y, float z) const
void link(GridRefManager< NGrid< N, ACTIVE_OBJECT, WORLD_OBJECT_TYPES, GRID_OBJECT_TYPES > > *pTo)
bool Contains(const GameObjectModel &mdl) const
CreatureMover(float _x, float _y, float _z, float _ang)
bool Instanceable() const
bool IsBattleArena() const
void VisitWorld(const float &x, const float &y, float radius, NOTIFIER ¬ifier)
bool GetUnloadLock(const GridCoord &p) const
void setGridObjectDataLoaded(bool pLoaded, uint32 x, uint32 y)
void AddWorldObject(WorldObject *obj)
bool IsRemovalGrid(float x, float y) const
MapRefManager::iterator m_mapRefIter
void VisitGrid(const float &x, const float &y, float radius, NOTIFIER ¬ifier)
virtual EnterState CannotEnter(Player *)
time_t GetGridExpiry(void) const
void ResetGridExpiry(NGridType &grid, float factor=1) const
Map const * GetParent() const
MapRefManager m_mapRefManager
uint32 GetInstanceId() const
void Visit(CellCoord const &, TypeContainerVisitor< T, CONTAINER > &visitor, Map &, WorldObject const &, float) const
CoordPair< MAX_NUMBER_OF_GRIDS > GridCoord
Oregon::ObjectLevelLockable< Map, ACE_Thread_Mutex >::Lock Guard
GridCoord ComputeGridCoord(float x, float y)