Files
TCPlayerbotCore/src/server/game/Maps/Map.h
T

700 lines
25 KiB
C++
Raw Normal View History

2010-10-07 15:54:07 +02:00
/*
2011-01-01 15:01:13 +01:00
* Copyright (C) 2008-2011 TrinityCore <http://www.trinitycore.org/>
2010-10-07 15:54:07 +02:00
* Copyright (C) 2005-2009 MaNGOS <http://getmangos.com/>
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the
* Free Software Foundation; either version 2 of the License, or (at your
* option) any later version.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
* more details.
*
* You should have received a copy of the GNU General Public License along
* with this program. If not, see <http://www.gnu.org/licenses/>.
2008-10-02 16:23:55 -05:00
*/
2009-10-17 15:51:44 -07:00
2008-10-14 11:57:03 -05:00
#ifndef TRINITY_MAP_H
#define TRINITY_MAP_H
2009-10-17 15:51:44 -07:00
2010-06-07 09:04:14 -06:00
#include "Define.h"
#include <ace/RW_Thread_Mutex.h>
#include <ace/Thread_Mutex.h>
2009-10-17 15:51:44 -07:00
#include "DBCStructure.h"
2010-06-08 13:05:47 -06:00
#include "GridDefines.h"
#include "Cell.h"
#include "Timer.h"
#include "SharedDefines.h"
#include "GridRefManager.h"
#include "MapRefManager.h"
2009-10-17 15:51:44 -07:00
2008-10-02 16:23:55 -05:00
#include <bitset>
#include <list>
2009-10-17 15:51:44 -07:00
2008-10-02 16:23:55 -05:00
class Unit;
class WorldPacket;
2010-08-08 22:54:58 +06:00
class InstanceScript;
2008-10-02 16:23:55 -05:00
class Group;
class InstanceSave;
class Object;
2008-12-18 14:20:38 -06:00
class WorldObject;
2009-03-20 14:01:46 -06:00
class TempSummon;
2009-08-01 00:20:32 +02:00
class Player;
class CreatureGroup;
struct ScriptInfo;
struct ScriptAction;
2009-08-29 14:58:45 -05:00
struct Position;
2010-08-08 04:37:24 +02:00
class Battleground;
class MapInstanced;
class InstanceMap;
2010-11-13 17:18:09 +01:00
namespace Trinity { struct ObjectUpdater; }
2008-10-02 16:23:55 -05:00
struct ScriptAction
{
uint64 sourceGUID;
uint64 targetGUID;
uint64 ownerGUID; // owner of source if source is item
ScriptInfo const* script; // pointer to static script data
};
// ******************************************
// Map file format defines
// ******************************************
struct map_fileheader
{
uint32 mapMagic;
uint32 versionMagic;
uint32 buildMagic;
uint32 areaMapOffset;
uint32 areaMapSize;
uint32 heightMapOffset;
uint32 heightMapSize;
uint32 liquidMapOffset;
uint32 liquidMapSize;
};
2009-10-17 15:51:44 -07:00
#define MAP_AREA_NO_AREA 0x0001
2009-10-17 15:51:44 -07:00
struct map_areaHeader
{
uint32 fourcc;
uint16 flags;
uint16 gridArea;
};
2009-10-17 15:51:44 -07:00
#define MAP_HEIGHT_NO_HEIGHT 0x0001
#define MAP_HEIGHT_AS_INT16 0x0002
#define MAP_HEIGHT_AS_INT8 0x0004
2009-10-17 15:51:44 -07:00
struct map_heightHeader
{
uint32 fourcc;
uint32 flags;
float gridHeight;
float gridMaxHeight;
};
2009-10-17 15:51:44 -07:00
#define MAP_LIQUID_NO_TYPE 0x0001
#define MAP_LIQUID_NO_HEIGHT 0x0002
2009-10-17 15:51:44 -07:00
struct map_liquidHeader
{
uint32 fourcc;
uint16 flags;
uint16 liquidType;
uint8 offsetX;
uint8 offsetY;
uint8 width;
uint8 height;
float liquidLevel;
};
2009-10-17 15:51:44 -07:00
enum ZLiquidStatus
{
LIQUID_MAP_NO_WATER = 0x00000000,
LIQUID_MAP_ABOVE_WATER = 0x00000001,
LIQUID_MAP_WATER_WALK = 0x00000002,
LIQUID_MAP_IN_WATER = 0x00000004,
LIQUID_MAP_UNDER_WATER = 0x00000008
};
2009-10-17 15:51:44 -07:00
#define MAP_LIQUID_TYPE_NO_WATER 0x00
#define MAP_LIQUID_TYPE_WATER 0x01
#define MAP_LIQUID_TYPE_OCEAN 0x02
#define MAP_LIQUID_TYPE_MAGMA 0x04
#define MAP_LIQUID_TYPE_SLIME 0x08
2009-10-17 15:51:44 -07:00
#define MAP_ALL_LIQUIDS (MAP_LIQUID_TYPE_WATER | MAP_LIQUID_TYPE_OCEAN | MAP_LIQUID_TYPE_MAGMA | MAP_LIQUID_TYPE_SLIME)
2009-10-17 15:51:44 -07:00
#define MAP_LIQUID_TYPE_DARK_WATER 0x10
#define MAP_LIQUID_TYPE_WMO_WATER 0x20
2009-10-17 15:51:44 -07:00
struct LiquidData
{
uint32 type;
float level;
float depth_level;
};
2009-10-17 15:51:44 -07:00
class GridMap
2008-10-02 16:23:55 -05:00
{
uint32 m_flags;
// Area data
uint16 m_gridArea;
uint16 *m_area_map;
// Height level data
float m_gridHeight;
float m_gridIntHeightMultiplier;
union{
float *m_V9;
uint16 *m_uint16_V9;
uint8 *m_uint8_V9;
};
union{
float *m_V8;
uint16 *m_uint16_V8;
uint8 *m_uint8_V8;
};
// Liquid data
uint16 m_liquidType;
uint8 m_liquid_offX;
uint8 m_liquid_offY;
uint8 m_liquid_width;
uint8 m_liquid_height;
float m_liquidLevel;
uint8 *m_liquid_type;
float *m_liquid_map;
2009-10-17 15:51:44 -07:00
bool loadAreaData(FILE* in, uint32 offset, uint32 size);
bool loadHeihgtData(FILE* in, uint32 offset, uint32 size);
bool loadLiquidData(FILE* in, uint32 offset, uint32 size);
2009-10-17 15:51:44 -07:00
// Get height functions and pointers
typedef float (GridMap::*pGetHeightPtr) (float x, float y) const;
pGetHeightPtr m_gridGetHeight;
float getHeightFromFloat(float x, float y) const;
float getHeightFromUint16(float x, float y) const;
float getHeightFromUint8(float x, float y) const;
float getHeightFromFlat(float x, float y) const;
2009-10-17 15:51:44 -07:00
public:
GridMap();
~GridMap();
bool loadData(char *filaname);
void unloadData();
2009-10-17 15:51:44 -07:00
uint16 getArea(float x, float y);
inline float getHeight(float x, float y) {return (this->*m_gridGetHeight)(x, y);}
float getLiquidLevel(float x, float y);
uint8 getTerrainType(float x, float y);
ZLiquidStatus getLiquidStatus(float x, float y, float z, uint8 ReqLiquidType, LiquidData* data = 0);
};
2009-10-17 15:51:44 -07:00
2008-10-02 16:23:55 -05:00
struct CreatureMover
{
2011-07-27 11:00:39 +02:00
CreatureMover() : x(0.0f), y(0.0f), z(0.0f), ang(0.0f) {}
2008-10-02 16:23:55 -05:00
CreatureMover(float _x, float _y, float _z, float _ang) : x(_x), y(_y), z(_z), ang(_ang) {}
2009-10-17 15:51:44 -07:00
2008-10-02 16:23:55 -05:00
float x, y, z, ang;
};
2009-10-17 15:51:44 -07:00
2011-04-29 20:47:02 +02:00
// GCC have alternative #pragma pack(N) syntax and old gcc version not support pack(push, N), also any gcc version not support it at some platform
2010-04-07 22:59:46 +02:00
#if defined(__GNUC__)
2008-10-02 16:23:55 -05:00
#pragma pack(1)
#else
2011-04-29 20:47:02 +02:00
#pragma pack(push, 1)
2008-10-02 16:23:55 -05:00
#endif
2009-10-17 15:51:44 -07:00
2008-10-02 16:23:55 -05:00
struct InstanceTemplate
{
2011-04-28 22:16:13 +02:00
uint32 Parent;
uint32 ScriptId;
bool AllowMount;
2008-10-02 16:23:55 -05:00
};
2009-10-17 15:51:44 -07:00
2008-10-02 16:23:55 -05:00
enum LevelRequirementVsMode
{
LEVELREQUIREMENT_HEROIC = 70
};
2009-10-17 15:51:44 -07:00
2010-04-07 22:59:46 +02:00
#if defined(__GNUC__)
2008-10-02 16:23:55 -05:00
#pragma pack()
#else
#pragma pack(pop)
#endif
2009-10-17 15:51:44 -07:00
typedef UNORDERED_MAP<Creature*, CreatureMover> CreatureMoveList;
2009-10-17 15:51:44 -07:00
2008-10-02 16:23:55 -05:00
#define MAX_HEIGHT 100000.0f // can be use for find ground height at surface
#define INVALID_HEIGHT -100000.0f // for check, must be equal to VMAP_INVALID_HEIGHT, real value for unknown height is VMAP_INVALID_HEIGHT_VALUE
#define MAX_FALL_DISTANCE 250000.0f // "unlimited fall" to find VMap ground if it is available, just larger than MAX_HEIGHT - INVALID_HEIGHT
#define DEFAULT_HEIGHT_SEARCH 10.0f // default search distance to find height at nearby locations
2008-10-02 16:23:55 -05:00
#define MIN_UNLOAD_DELAY 1 // immediate unload
2009-10-17 15:51:44 -07:00
typedef std::map<uint32/*leaderDBGUID*/, CreatureGroup*> CreatureGroupHolderType;
2009-10-17 15:51:44 -07:00
class Map : public GridRefManager<NGridType>
2008-10-02 16:23:55 -05:00
{
friend class MapReference;
2008-10-02 16:23:55 -05:00
public:
Map(uint32 id, time_t, uint32 InstanceId, uint8 SpawnMode, Map* _parent = NULL);
2008-10-02 16:23:55 -05:00
virtual ~Map();
2009-10-17 15:51:44 -07:00
MapEntry const* GetEntry() const { return i_mapEntry; }
2008-10-02 16:23:55 -05:00
// currently unused for normal maps
2009-01-20 19:59:43 -06:00
bool CanUnload(uint32 diff)
{
2010-04-07 19:14:10 +02:00
if (!m_unloadTimer) return false;
if (m_unloadTimer <= diff) return true;
2009-01-20 19:59:43 -06:00
m_unloadTimer -= diff;
return false;
}
2009-10-17 15:51:44 -07:00
virtual bool Add(Player*);
virtual void Remove(Player* , bool);
2008-10-02 16:23:55 -05:00
template<class T> void Add(T *);
template<class T> void Remove(T *, bool);
2009-10-17 15:51:44 -07:00
2010-11-13 17:18:09 +01:00
void VisitNearbyCellsOf(WorldObject* obj, TypeContainerVisitor<Trinity::ObjectUpdater, GridTypeMapContainer> &gridVisitor, TypeContainerVisitor<Trinity::ObjectUpdater, WorldTypeMapContainer> &worldVisitor);
virtual void Update(const uint32);
2009-10-17 15:51:44 -07:00
2010-11-13 17:18:09 +01:00
float GetVisibilityRange() const { return m_VisibleDistance; }
//function for setting up visibility distance for maps on per-type/per-Id basis
virtual void InitVisibilityDistance();
2009-10-17 15:51:44 -07:00
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);
2009-10-17 15:51:44 -07:00
template<class T, class CONTAINER> void Visit(const Cell& cell, TypeContainerVisitor<T, CONTAINER> &visitor);
2009-10-17 15:51:44 -07:00
2009-01-20 19:59:43 -06:00
bool IsRemovalGrid(float x, float y) const
2008-10-02 16:23:55 -05:00
{
2008-10-14 11:57:03 -05:00
GridPair p = Trinity::ComputeGridPair(x, y);
return !getNGrid(p.x_coord, p.y_coord) || getNGrid(p.x_coord, p.y_coord)->GetGridState() == GRID_STATE_REMOVAL;
2008-10-02 16:23:55 -05:00
}
2009-10-17 15:51:44 -07:00
bool IsLoaded(float x, float y) const
{
GridPair p = Trinity::ComputeGridPair(x, y);
return loaded(p);
}
bool GetUnloadLock(const GridPair &p) const { return getNGrid(p.x_coord, p.y_coord)->getUnloadLock(); }
void SetUnloadLock(const GridPair &p, bool on) { getNGrid(p.x_coord, p.y_coord)->setUnloadExplicitLock(on); }
2008-12-20 14:10:53 -06:00
void LoadGrid(float x, float y);
bool UnloadGrid(const uint32 x, const uint32 y, bool pForce);
2009-02-25 17:53:05 -06:00
virtual void UnloadAll();
2009-10-17 15:51:44 -07:00
2008-10-02 16:23:55 -05:00
void ResetGridExpiry(NGridType &grid, float factor = 1) const
{
grid.ResetTimeTracker(time_t(float(i_gridExpiry)*factor));
2008-10-02 16:23:55 -05:00
}
2009-10-17 15:51:44 -07:00
2008-10-02 16:23:55 -05:00
time_t GetGridExpiry(void) const { return i_gridExpiry; }
2009-08-01 00:20:32 +02:00
uint32 GetId(void) const { return i_mapEntry->MapID; }
2009-10-17 15:51:44 -07:00
static bool ExistMap(uint32 mapid, int gx, int gy);
static bool ExistVMap(uint32 mapid, int gx, int gy);
2009-10-17 15:51:44 -07:00
2008-10-02 16:23:55 -05:00
static void InitStateMachine();
static void DeleteStateMachine();
2009-10-17 15:51:44 -07:00
2011-06-11 22:35:29 +02:00
Map const* GetParent() const { return m_parentMap; }
2009-10-17 15:51:44 -07:00
2008-10-02 16:23:55 -05:00
// some calls like isInWater should not use vmaps due to processor power
// can return INVALID_HEIGHT if under z+2 z coord not found height
float GetHeight(float x, float y, float z, bool pCheckVMap=true, float maxSearchDist=DEFAULT_HEIGHT_SEARCH) const;
2009-10-17 15:51:44 -07:00
ZLiquidStatus getLiquidStatus(float x, float y, float z, uint8 ReqLiquidType, LiquidData* data = 0) const;
2009-10-17 15:51:44 -07:00
2010-06-05 00:59:25 +02:00
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;
2010-04-07 22:59:46 +02:00
uint8 GetTerrainType(float x, float y) const;
float GetWaterLevel(float x, float y) const;
bool IsInWater(float x, float y, float z, LiquidData* data = 0) const;
2008-10-02 16:23:55 -05:00
bool IsUnderWater(float x, float y, float z) const;
2009-10-17 15:51:44 -07:00
2011-04-29 20:47:02 +02:00
static uint32 GetAreaIdByAreaFlag(uint16 areaflag, uint32 map_id);
static uint32 GetZoneIdByAreaFlag(uint16 areaflag, uint32 map_id);
static void GetZoneAndAreaIdByAreaFlag(uint32& zoneid, uint32& areaid, uint16 areaflag, uint32 map_id);
2009-10-17 15:51:44 -07:00
2009-01-02 11:03:43 -06:00
uint32 GetAreaId(float x, float y, float z) const
2008-10-02 16:23:55 -05:00
{
2011-04-29 20:47:02 +02:00
return GetAreaIdByAreaFlag(GetAreaFlag(x, y, z), GetId());
2008-10-02 16:23:55 -05:00
}
2009-10-17 15:51:44 -07:00
2009-01-02 11:03:43 -06:00
uint32 GetZoneId(float x, float y, float z) const
2008-10-02 16:23:55 -05:00
{
2011-04-29 20:47:02 +02:00
return GetZoneIdByAreaFlag(GetAreaFlag(x, y, z), GetId());
}
2009-10-17 15:51:44 -07:00
void GetZoneAndAreaId(uint32& zoneid, uint32& areaid, float x, float y, float z) const
{
2011-04-29 20:47:02 +02:00
GetZoneAndAreaIdByAreaFlag(zoneid, areaid, GetAreaFlag(x, y, z), GetId());
2008-10-02 16:23:55 -05:00
}
2009-10-17 15:51:44 -07:00
void MoveAllCreaturesInMoveList();
void RemoveAllObjectsInRemoveList();
virtual void RemoveAllPlayers();
2009-10-17 15:51:44 -07:00
bool CreatureRespawnRelocation(Creature* c); // used only in MoveAllCreaturesInMoveList and ObjectGridUnloader
2009-10-17 15:51:44 -07:00
2008-10-02 16:23:55 -05:00
// assert print helper
bool CheckGridIntegrity(Creature* c, bool moved) const;
2009-10-17 15:51:44 -07:00
uint32 GetInstanceId() const { return i_InstanceId; }
uint8 GetSpawnMode() const { return (i_spawnMode); }
2008-10-02 16:23:55 -05:00
virtual bool CanEnter(Player* /*player*/) { return true; }
const char* GetMapName() const;
2009-10-17 15:51:44 -07:00
// have meaning only for instanced map (that have set real difficulty)
Difficulty GetDifficulty() const { return Difficulty(GetSpawnMode()); }
bool IsRegularDifficulty() const { return GetDifficulty() == REGULAR_DIFFICULTY; }
MapDifficulty const* GetMapDifficulty() const;
2008-10-02 16:23:55 -05:00
bool Instanceable() const { return i_mapEntry && i_mapEntry->Instanceable(); }
bool IsDungeon() const { return i_mapEntry && i_mapEntry->IsDungeon(); }
2010-05-05 13:27:17 +02:00
bool IsNonRaidDungeon() const { return i_mapEntry && i_mapEntry->IsNonRaidDungeon(); }
2008-10-02 16:23:55 -05:00
bool IsRaid() const { return i_mapEntry && i_mapEntry->IsRaid(); }
2009-12-17 11:30:18 +01:00
bool IsRaidOrHeroicDungeon() const { return IsRaid() || i_spawnMode > DUNGEON_DIFFICULTY_NORMAL; }
bool IsHeroic() const { return IsRaid() ? i_spawnMode >= RAID_DIFFICULTY_10MAN_HEROIC : i_spawnMode >= DUNGEON_DIFFICULTY_HEROIC; }
bool Is25ManRaid() const { return IsRaid() && i_spawnMode & RAID_DIFFICULTY_MASK_25MAN; } // since 25man difficulties are 1 and 3, we can check them like that
2010-08-08 04:37:24 +02:00
bool IsBattleground() const { return i_mapEntry && i_mapEntry->IsBattleground(); }
2008-10-02 16:23:55 -05:00
bool IsBattleArena() const { return i_mapEntry && i_mapEntry->IsBattleArena(); }
2010-08-08 04:37:24 +02:00
bool IsBattlegroundOrArena() const { return i_mapEntry && i_mapEntry->IsBattlegroundOrArena(); }
bool GetEntrancePos(int32 &mapid, float &x, float &y)
{
2010-04-07 19:14:10 +02:00
if (!i_mapEntry)
return false;
return i_mapEntry->GetEntrancePos(mapid, x, y);
}
2009-10-17 15:51:44 -07:00
void AddObjectToRemoveList(WorldObject* obj);
void AddObjectToSwitchList(WorldObject* obj, bool on);
virtual void DelayedUpdate(const uint32 diff);
2009-10-17 15:51:44 -07:00
2008-10-02 16:23:55 -05:00
void UpdateObjectVisibility(WorldObject* obj, Cell cell, CellPair cellpair);
2010-04-07 22:59:46 +02:00
void UpdateObjectsVisibilityFor(Player* player, Cell cell, CellPair cellpair);
2009-10-17 15:51:44 -07:00
2008-10-02 16:23:55 -05:00
void resetMarkedCells() { marked_cells.reset(); }
bool isCellMarked(uint32 pCellId) { return marked_cells.test(pCellId); }
void markCell(uint32 pCellId) { marked_cells.set(pCellId); }
2009-10-17 15:51:44 -07:00
bool HavePlayers() const { return !m_mapRefManager.isEmpty(); }
uint32 GetPlayersCountExceptGMs() const;
bool ActiveObjectsNearGrid(uint32 x, uint32 y) const;
2009-10-17 15:51:44 -07:00
void AddWorldObject(WorldObject* obj) { i_worldObjects.insert(obj); }
void RemoveWorldObject(WorldObject* obj) { i_worldObjects.erase(obj); }
2009-10-17 15:51:44 -07:00
void SendToPlayers(WorldPacket const* data) const;
2009-10-17 15:51:44 -07:00
typedef MapRefManager PlayerList;
PlayerList const& GetPlayers() const { return m_mapRefManager; }
2009-10-17 15:51:44 -07:00
//per-map script storage
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);
2009-10-17 15:51:44 -07:00
// must called with AddToWorld
template<class T>
void AddToActive(T* obj) { AddToActiveHelper(obj); }
2009-10-17 15:51:44 -07:00
void AddToActive(Creature* obj);
2009-10-17 15:51:44 -07:00
// must called with RemoveFromWorld
template<class T>
void RemoveFromActive(T* obj) { RemoveFromActiveHelper(obj); }
2009-10-17 15:51:44 -07:00
void RemoveFromActive(Creature* obj);
2009-10-17 15:51:44 -07:00
template<class T> void SwitchGridContainers(T* obj, bool active);
2008-12-12 23:54:02 -06:00
template<class NOTIFIER> void VisitAll(const float &x, const float &y, float radius, NOTIFIER &notifier);
template<class NOTIFIER> void VisitFirstFound(const float &x, const float &y, float radius, NOTIFIER &notifier);
2008-12-12 23:54:02 -06:00
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);
2009-04-19 18:48:20 +02:00
CreatureGroupHolderType CreatureGroupHolder;
2009-10-17 15:51:44 -07:00
2011-06-12 02:00:43 +02:00
void UpdateIteratorBack(Player* player);
2009-10-17 15:51:44 -07:00
TempSummon* SummonCreature(uint32 entry, Position const& pos, SummonPropertiesEntry const* properties = NULL, uint32 duration = 0, Unit* summoner = NULL, uint32 spellId = 0, uint32 vehId = 0);
Creature* GetCreature(uint64 guid);
GameObject* GetGameObject(uint64 guid);
DynamicObject* GetDynamicObject(uint64 guid);
MapInstanced* ToMapInstanced(){ if (Instanceable()) return reinterpret_cast<MapInstanced*>(this); else return NULL; }
const MapInstanced* ToMapInstanced() const { if (Instanceable()) return (const MapInstanced*)((MapInstanced*)this); else return NULL; }
InstanceMap* ToInstanceMap(){ if (IsDungeon()) return reinterpret_cast<InstanceMap*>(this); else return NULL; }
const InstanceMap* ToInstanceMap() const { if (IsDungeon()) return (const InstanceMap*)((InstanceMap*)this); else return NULL; }
2008-10-02 16:23:55 -05:00
private:
void LoadMapAndVMap(int gx, int gy);
void LoadVMap(int gx, int gy);
2011-04-29 20:47:02 +02:00
void LoadMap(int gx, int gy, bool reload = false);
GridMap* GetGrid(float x, float y);
2009-10-17 15:51:44 -07:00
2008-10-02 16:23:55 -05:00
void SetTimer(uint32 t) { i_gridExpiry = t < MIN_GRID_DELAY ? MIN_GRID_DELAY : t; }
2009-10-17 15:51:44 -07:00
2011-06-11 22:35:29 +02:00
void SendInitSelf(Player* player);
2009-10-17 15:51:44 -07:00
2011-06-11 22:35:29 +02:00
void SendInitTransports(Player* player);
void SendRemoveTransports(Player* player);
2009-10-17 15:51:44 -07:00
bool CreatureCellRelocation(Creature* creature, Cell new_cell);
2009-10-17 15:51:44 -07:00
void AddCreatureToMoveList(Creature* c, float x, float y, float z, float ang);
2008-10-02 16:23:55 -05:00
CreatureMoveList i_creaturesToMove;
2009-10-17 15:51:44 -07:00
2008-10-02 16:23:55 -05:00
bool loaded(const GridPair &) const;
void EnsureGridCreated(const GridPair &);
bool EnsureGridLoaded(Cell const&);
void EnsureGridLoadedAtEnter(Cell const&, Player* player = NULL);
2009-10-17 15:51:44 -07:00
2008-10-02 16:23:55 -05:00
void buildNGridLinkage(NGridType* pNGridType) { pNGridType->link(this); }
2009-10-17 15:51:44 -07:00
2008-10-02 16:23:55 -05:00
template<class T> void AddType(T *obj);
template<class T> void RemoveType(T *obj, bool);
2009-10-17 15:51:44 -07:00
2008-10-02 16:23:55 -05:00
NGridType* getNGrid(uint32 x, uint32 y) const
{
ASSERT(x < MAX_NUMBER_OF_GRIDS);
ASSERT(y < MAX_NUMBER_OF_GRIDS);
2008-10-02 16:23:55 -05:00
return i_grids[x][y];
}
2009-10-17 15:51:44 -07:00
2011-04-29 20:47:02 +02:00
bool isGridObjectDataLoaded(uint32 x, uint32 y) const { return getNGrid(x, y)->isGridObjectDataLoaded(); }
void setGridObjectDataLoaded(bool pLoaded, uint32 x, uint32 y) { getNGrid(x, y)->setGridObjectDataLoaded(pLoaded); }
2009-10-17 15:51:44 -07:00
2009-01-20 19:59:43 -06:00
void setNGrid(NGridType* grid, uint32 x, uint32 y);
void ScriptsProcess();
2009-10-17 15:51:44 -07:00
void UpdateActiveCells(const float &x, const float &y, const uint32 t_diff);
2008-10-02 16:23:55 -05:00
protected:
void SetUnloadReferenceLock(const GridPair &p, bool on) { getNGrid(p.x_coord, p.y_coord)->setUnloadReferenceLock(on); }
2009-10-17 15:51:44 -07:00
ACE_Thread_Mutex Lock;
2009-10-17 15:51:44 -07:00
2008-10-02 16:23:55 -05:00
MapEntry const* i_mapEntry;
uint8 i_spawnMode;
uint32 i_InstanceId;
uint32 m_unloadTimer;
float m_VisibleDistance;
2009-10-17 15:51:44 -07:00
MapRefManager m_mapRefManager;
2008-11-28 11:38:28 -06:00
MapRefManager::iterator m_mapRefIter;
2009-10-17 15:51:44 -07:00
2010-02-27 15:25:14 +02:00
int32 m_VisibilityNotifyPeriod;
typedef std::set<WorldObject*> ActiveNonPlayers;
ActiveNonPlayers m_activeNonPlayers;
ActiveNonPlayers::iterator m_activeNonPlayersIter;
2009-04-15 15:46:02 +02:00
2008-10-02 16:23:55 -05:00
private:
2010-08-20 14:57:05 +06:00
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;
time_t i_gridExpiry;
2009-10-17 15:51:44 -07:00
//used for fast base_map (e.g. MapInstanced class object) search for
2010-08-08 04:37:24 +02:00
//InstanceMaps and BattlegroundMaps...
Map* m_parentMap;
2009-10-17 15:51:44 -07:00
2008-10-02 16:23:55 -05:00
NGridType* i_grids[MAX_NUMBER_OF_GRIDS][MAX_NUMBER_OF_GRIDS];
GridMap* GridMaps[MAX_NUMBER_OF_GRIDS][MAX_NUMBER_OF_GRIDS];
2008-10-02 16:23:55 -05:00
std::bitset<TOTAL_NUMBER_OF_CELLS_PER_MAP*TOTAL_NUMBER_OF_CELLS_PER_MAP> marked_cells;
2009-10-17 15:51:44 -07:00
2010-02-27 15:25:14 +02:00
//these functions used to process player/mob aggro reactions and
//visibility calculations. Highly optimized for massive calculations
void ProcessRelocationNotifies(const uint32 diff);
bool i_scriptLock;
std::set<WorldObject*> i_objectsToRemove;
2009-02-26 17:01:02 -06:00
std::map<WorldObject*, bool> i_objectsToSwitch;
std::set<WorldObject*> i_worldObjects;
typedef std::multimap<time_t, ScriptAction> ScriptScheduleMap;
ScriptScheduleMap m_scriptSchedule;
2009-10-17 15:51:44 -07:00
2008-10-02 16:23:55 -05:00
// Type specific code for add/remove to/from grid
template<class T>
void AddToGrid(T*, NGridType *, Cell const&);
2009-10-17 15:51:44 -07:00
2008-10-02 16:23:55 -05:00
template<class T>
void RemoveFromGrid(T*, NGridType *, Cell const&);
2009-10-17 15:51:44 -07:00
2008-10-02 16:23:55 -05:00
template<class T>
void DeleteFromWorld(T*);
2009-10-17 15:51:44 -07:00
template<class T>
void AddToActiveHelper(T* obj)
{
m_activeNonPlayers.insert(obj);
}
2009-10-17 15:51:44 -07:00
template<class T>
void RemoveFromActiveHelper(T* obj)
{
// Map::Update for active object in proccess
2010-04-07 19:14:10 +02:00
if (m_activeNonPlayersIter != m_activeNonPlayers.end())
{
ActiveNonPlayers::iterator itr = m_activeNonPlayers.find(obj);
2010-04-07 19:14:10 +02:00
if (itr == m_activeNonPlayers.end())
2009-03-03 19:07:52 -06:00
return;
2010-04-07 23:25:02 +02:00
if (itr == m_activeNonPlayersIter)
++m_activeNonPlayersIter;
m_activeNonPlayers.erase(itr);
}
else
m_activeNonPlayers.erase(obj);
}
2008-10-02 16:23:55 -05:00
};
2009-10-17 15:51:44 -07:00
2008-10-02 16:23:55 -05:00
enum InstanceResetMethod
{
INSTANCE_RESET_ALL,
INSTANCE_RESET_CHANGE_DIFFICULTY,
INSTANCE_RESET_GLOBAL,
INSTANCE_RESET_GROUP_DISBAND,
INSTANCE_RESET_GROUP_JOIN,
INSTANCE_RESET_RESPAWN_DELAY
};
2009-10-17 15:51:44 -07:00
2010-02-05 00:31:28 +01:00
class InstanceMap : public Map
2008-10-02 16:23:55 -05:00
{
public:
InstanceMap(uint32 id, time_t, uint32 InstanceId, uint8 SpawnMode, Map* _parent);
2008-10-02 16:23:55 -05:00
~InstanceMap();
bool Add(Player*);
void Remove(Player* , bool);
void Update(const uint32);
2008-10-02 16:23:55 -05:00
void CreateInstanceData(bool load);
bool Reset(uint8 method);
uint32 GetScriptId() { return i_script_id; }
2010-08-08 22:54:58 +06:00
InstanceScript* GetInstanceScript() { return i_data; }
2011-06-12 02:00:43 +02:00
void PermBindAllPlayers(Player* player);
2009-02-25 17:53:05 -06:00
void UnloadAll();
2008-10-02 16:23:55 -05:00
bool CanEnter(Player* player);
void SendResetWarnings(uint32 timeLeft) const;
void SetResetSchedule(bool on);
2009-12-17 11:30:18 +01:00
2009-01-22 22:44:27 -06:00
uint32 GetMaxPlayers() const;
2009-12-17 11:30:18 +01:00
uint32 GetMaxResetDelay() const;
2009-10-17 15:51:44 -07:00
virtual void InitVisibilityDistance();
2008-10-02 16:23:55 -05:00
private:
bool m_resetAfterUnload;
bool m_unloadWhenEmpty;
2010-08-08 22:54:58 +06:00
InstanceScript* i_data;
uint32 i_script_id;
2008-10-02 16:23:55 -05:00
};
2009-10-17 15:51:44 -07:00
2010-08-08 04:37:24 +02:00
class BattlegroundMap : public Map
2008-10-02 16:23:55 -05:00
{
public:
2010-08-08 04:37:24 +02:00
BattlegroundMap(uint32 id, time_t, uint32 InstanceId, Map* _parent, uint8 spawnMode);
~BattlegroundMap();
2009-10-17 15:51:44 -07:00
bool Add(Player*);
void Remove(Player* , bool);
2008-10-02 16:23:55 -05:00
bool CanEnter(Player* player);
void SetUnload();
//void UnloadAll(bool pForce);
void RemoveAllPlayers();
2009-10-17 15:51:44 -07:00
virtual void InitVisibilityDistance();
2010-08-08 04:37:24 +02:00
Battleground* GetBG() { return m_bg; }
void SetBG(Battleground* bg) { m_bg = bg; }
2009-12-17 11:30:18 +01:00
private:
2010-08-08 04:37:24 +02:00
Battleground* m_bg;
2008-10-02 16:23:55 -05:00
};
2009-10-17 15:51:44 -07:00
template<class T, class CONTAINER>
2008-10-02 16:23:55 -05:00
inline void
Map::Visit(const Cell& cell, TypeContainerVisitor<T, CONTAINER> &visitor)
2008-10-02 16:23:55 -05:00
{
const uint32 x = cell.GridX();
const uint32 y = cell.GridY();
const uint32 cell_x = cell.CellX();
const uint32 cell_y = cell.CellY();
2009-10-17 15:51:44 -07:00
2011-04-29 20:47:02 +02:00
if (!cell.NoCreate() || loaded(GridPair(x, y)))
2008-10-02 16:23:55 -05:00
{
EnsureGridLoaded(cell);
2008-10-02 16:23:55 -05:00
getNGrid(x, y)->Visit(cell_x, cell_y, visitor);
}
}
2009-10-17 15:51:44 -07:00
2008-12-12 23:54:02 -06:00
template<class NOTIFIER>
inline void
Map::VisitAll(const float &x, const float &y, float radius, NOTIFIER &notifier)
{
2010-01-07 04:05:26 +02:00
CellPair p(Trinity::ComputeCellPair(x, y));
2008-12-12 23:54:02 -06:00
Cell cell(p);
cell.data.Part.reserved = ALL_DISTRICT;
cell.SetNoCreate();
2009-10-17 15:51:44 -07:00
2008-12-12 23:54:02 -06:00
TypeContainerVisitor<NOTIFIER, WorldTypeMapContainer> world_object_notifier(notifier);
cell.Visit(p, world_object_notifier, *this, radius, x, y);
2008-12-12 23:54:02 -06:00
TypeContainerVisitor<NOTIFIER, GridTypeMapContainer > grid_object_notifier(notifier);
cell.Visit(p, grid_object_notifier, *this, radius, x, y);
2008-12-12 23:54:02 -06:00
}
2009-10-17 15:51:44 -07:00
// should be used with Searcher notifiers, tries to search world if nothing found in grid
template<class NOTIFIER>
inline void
Map::VisitFirstFound(const float &x, const float &y, float radius, NOTIFIER &notifier)
{
CellPair p(Trinity::ComputeCellPair(x, y));
Cell cell(p);
cell.data.Part.reserved = ALL_DISTRICT;
cell.SetNoCreate();
TypeContainerVisitor<NOTIFIER, WorldTypeMapContainer> world_object_notifier(notifier);
cell.Visit(p, world_object_notifier, *this, radius, x, y);
if (!notifier.i_object)
{
TypeContainerVisitor<NOTIFIER, GridTypeMapContainer > grid_object_notifier(notifier);
cell.Visit(p, grid_object_notifier, *this, radius, x, y);
}
}
2008-12-12 23:54:02 -06:00
template<class NOTIFIER>
inline void
Map::VisitWorld(const float &x, const float &y, float radius, NOTIFIER &notifier)
{
2010-01-07 04:05:26 +02:00
CellPair p(Trinity::ComputeCellPair(x, y));
2008-12-12 23:54:02 -06:00
Cell cell(p);
cell.data.Part.reserved = ALL_DISTRICT;
cell.SetNoCreate();
2009-10-17 15:51:44 -07:00
2008-12-12 23:54:02 -06:00
TypeContainerVisitor<NOTIFIER, WorldTypeMapContainer> world_object_notifier(notifier);
cell.Visit(p, world_object_notifier, *this, radius, x, y);
2008-12-12 23:54:02 -06:00
}
2009-10-17 15:51:44 -07:00
2008-12-12 23:54:02 -06:00
template<class NOTIFIER>
inline void
Map::VisitGrid(const float &x, const float &y, float radius, NOTIFIER &notifier)
{
2010-01-07 04:05:26 +02:00
CellPair p(Trinity::ComputeCellPair(x, y));
2008-12-12 23:54:02 -06:00
Cell cell(p);
cell.data.Part.reserved = ALL_DISTRICT;
cell.SetNoCreate();
2009-10-17 15:51:44 -07:00
2008-12-12 23:54:02 -06:00
TypeContainerVisitor<NOTIFIER, GridTypeMapContainer > grid_object_notifier(notifier);
cell.Visit(p, grid_object_notifier, *this, radius, x, y);
2008-12-12 23:54:02 -06:00
}
2008-10-02 16:23:55 -05:00
#endif