Files
TrinityCore/src/server/game/Maps/MapManager.h
T
treeston 43fa7d48a5 Game/Maps: Clean up instance handling.
- Rename Map::CanEnter to Map::CannotEnter. Return value changed from boolean (true means player can enter) to enum Map::EnterState (CAN_ENTER=0 means player can enter, any other value is a reason for deny).
- Move hack-y player error messages from within Map::CanEnter to the function calling CanEnter as appropriate (primarily WorldSession::HandleAreaTriggerOpcode).
- Modify WorldSession::HandleAreaTriggerOpcode to properly revive the player upon touching the portal leading to the instance they died in even if they are currently unable to zone in. Fixes and closes #15758.
- Modify Player::LoadFromDB to properly spawn players in the instance they logged off in if possible. Fixes and closes #15561.
- Modify permanent save behavior to be blizzlike: Players can always enter an instance they are saved to (assuming there are no map constraints against it), but get a homebind timer if the instance is already in use.
2015-12-31 01:02:07 +01:00

202 lines
6.2 KiB
C++

/*
* Copyright (C) 2008-2015 TrinityCore <http://www.trinitycore.org/>
* 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/>.
*/
#ifndef TRINITY_MAPMANAGER_H
#define TRINITY_MAPMANAGER_H
#include "Object.h"
#include "Map.h"
#include "MapInstanced.h"
#include "GridStates.h"
#include "MapUpdater.h"
class Transport;
struct TransportCreatureProto;
class MapManager
{
public:
static MapManager* instance()
{
static MapManager instance;
return &instance;
}
Map* CreateBaseMap(uint32 mapId);
Map* FindBaseNonInstanceMap(uint32 mapId) const;
Map* CreateMap(uint32 mapId, Player* player, uint32 loginInstanceId=0);
Map* FindMap(uint32 mapId, uint32 instanceId) const;
uint16 GetAreaFlag(uint32 mapid, float x, float y, float z) const
{
Map const* m = const_cast<MapManager*>(this)->CreateBaseMap(mapid);
return m->GetAreaFlag(x, y, z);
}
uint32 GetAreaId(uint32 mapid, float x, float y, float z) const
{
return Map::GetAreaIdByAreaFlag(GetAreaFlag(mapid, x, y, z), mapid);
}
uint32 GetZoneId(uint32 mapid, float x, float y, float z) const
{
return Map::GetZoneIdByAreaFlag(GetAreaFlag(mapid, x, y, z), mapid);
}
void GetZoneAndAreaId(uint32& zoneid, uint32& areaid, uint32 mapid, float x, float y, float z)
{
Map::GetZoneAndAreaIdByAreaFlag(zoneid, areaid, GetAreaFlag(mapid, x, y, z), mapid);
}
void Initialize(void);
void Update(uint32);
void SetGridCleanUpDelay(uint32 t)
{
if (t < MIN_GRID_DELAY)
i_gridCleanUpDelay = MIN_GRID_DELAY;
else
i_gridCleanUpDelay = t;
}
void SetMapUpdateInterval(uint32 t)
{
if (t < MIN_MAP_UPDATE_DELAY)
t = MIN_MAP_UPDATE_DELAY;
i_timer.SetInterval(t);
i_timer.Reset();
}
//void LoadGrid(int mapid, int instId, float x, float y, const WorldObject* obj, bool no_unload = false);
void UnloadAll();
static bool ExistMapAndVMap(uint32 mapid, float x, float y);
static bool IsValidMAP(uint32 mapid, bool startUp);
static bool IsValidMapCoord(uint32 mapid, float x, float y)
{
return IsValidMAP(mapid, false) && Trinity::IsValidMapCoord(x, y);
}
static bool IsValidMapCoord(uint32 mapid, float x, float y, float z)
{
return IsValidMAP(mapid, false) && Trinity::IsValidMapCoord(x, y, z);
}
static bool IsValidMapCoord(uint32 mapid, float x, float y, float z, float o)
{
return IsValidMAP(mapid, false) && Trinity::IsValidMapCoord(x, y, z, o);
}
static bool IsValidMapCoord(WorldLocation const& loc)
{
return IsValidMapCoord(loc.GetMapId(), loc.GetPositionX(), loc.GetPositionY(), loc.GetPositionZ(), loc.GetOrientation());
}
void DoDelayedMovesAndRemoves();
Map::EnterState PlayerCannotEnter(uint32 mapid, Player* player, bool loginCheck = false);
void InitializeVisibilityDistanceInfo();
/* statistics */
uint32 GetNumInstances();
uint32 GetNumPlayersInInstances();
// Instance ID management
void InitInstanceIds();
uint32 GenerateInstanceId();
void RegisterInstanceId(uint32 instanceId);
void FreeInstanceId(uint32 instanceId);
uint32 GetNextInstanceId() const { return _nextInstanceId; };
void SetNextInstanceId(uint32 nextInstanceId) { _nextInstanceId = nextInstanceId; };
MapUpdater * GetMapUpdater() { return &m_updater; }
template<typename Worker>
void DoForAllMaps(Worker&& worker);
template<typename Worker>
void DoForAllMapsWithMapId(uint32 mapId, Worker&& worker);
private:
typedef std::unordered_map<uint32, Map*> MapMapType;
typedef std::vector<bool> InstanceIds;
MapManager();
~MapManager();
Map* FindBaseMap(uint32 mapId) const
{
MapMapType::const_iterator iter = i_maps.find(mapId);
return (iter == i_maps.end() ? NULL : iter->second);
}
MapManager(const MapManager &);
MapManager& operator=(const MapManager &);
std::mutex _mapsLock;
uint32 i_gridCleanUpDelay;
MapMapType i_maps;
IntervalTimer i_timer;
InstanceIds _instanceIds;
uint32 _nextInstanceId;
MapUpdater m_updater;
};
template<typename Worker>
void MapManager::DoForAllMaps(Worker&& worker)
{
std::lock_guard<std::mutex> lock(_mapsLock);
for (auto& mapPair : i_maps)
{
Map* map = mapPair.second;
if (MapInstanced* mapInstanced = map->ToMapInstanced())
{
MapInstanced::InstancedMaps& instances = mapInstanced->GetInstancedMaps();
for (auto& instancePair : instances)
worker(instancePair.second);
}
else
worker(map);
}
}
template<typename Worker>
inline void MapManager::DoForAllMapsWithMapId(uint32 mapId, Worker&& worker)
{
std::lock_guard<std::mutex> lock(_mapsLock);
auto itr = i_maps.find(mapId);
if (itr != i_maps.end())
{
Map* map = itr->second;
if (MapInstanced* mapInstanced = map->ToMapInstanced())
{
MapInstanced::InstancedMaps& instances = mapInstanced->GetInstancedMaps();
for (auto& p : instances)
worker(p.second);
}
else
worker(map);
}
}
#define sMapMgr MapManager::instance()
#endif