diff options
Diffstat (limited to 'src/server/game/Maps')
| -rw-r--r-- | src/server/game/Maps/Map.cpp | 161 | ||||
| -rw-r--r-- | src/server/game/Maps/Map.h | 14 | ||||
| -rw-r--r-- | src/server/game/Maps/MapInstanced.cpp | 6 | ||||
| -rw-r--r-- | src/server/game/Maps/MapManager.cpp | 99 | ||||
| -rw-r--r-- | src/server/game/Maps/MapManager.h | 27 | ||||
| -rw-r--r-- | src/server/game/Maps/MapRefManager.h | 2 | ||||
| -rw-r--r-- | src/server/game/Maps/MapReference.h | 2 | ||||
| -rw-r--r-- | src/server/game/Maps/MapUpdater.cpp | 2 |
8 files changed, 179 insertions, 134 deletions
diff --git a/src/server/game/Maps/Map.cpp b/src/server/game/Maps/Map.cpp index 11bfdcd6f99..6c9b505d6c9 100644 --- a/src/server/game/Maps/Map.cpp +++ b/src/server/game/Maps/Map.cpp @@ -28,8 +28,8 @@ #include "InstanceData.h" #include "Map.h" #include "GridNotifiersImpl.h" -#include "Config/ConfigEnv.h" -#include "Transports.h" +#include "ConfigEnv.h" +#include "Transport.h" #include "ObjectAccessor.h" #include "ObjectMgr.h" #include "World.h" @@ -94,10 +94,9 @@ bool Map::ExistMap(uint32 mapid,int gx,int gy) map_fileheader header; fread(&header, sizeof(header), 1, pf); - if (header.mapMagic != uint32(MAP_MAGIC) || - header.versionMagic != uint32(MAP_VERSION_MAGIC)) + if (header.mapMagic != uint32(MAP_MAGIC) || header.versionMagic != uint32(MAP_VERSION_MAGIC)) { - sLog.outError("Map file '%s' is non-compatible version (outdated?). Please, create new using ad.exe program.",tmp); + sLog.outError("Map file '%s' is from an incompatible clientversion. Please recreate using the mapextractor.",tmp); delete [] tmp; fclose(pf); //close file before return return false; @@ -114,7 +113,6 @@ bool Map::ExistVMap(uint32 mapid,int gx,int gy) { if (vmgr->isMapLoadingEnabled()) { - // x and y are swapped !! => fixed now bool exists = vmgr->existsMap((sWorld.GetDataPath()+ "vmaps").c_str(), mapid, gx,gy); if (!exists) { @@ -326,7 +324,7 @@ void Map::DeleteFromWorld(T* obj) template<> void Map::DeleteFromWorld(Player* pl) { - ObjectAccessor::Instance().RemoveObject(pl); + sObjectAccessor.RemoveObject(pl); delete pl; } @@ -335,7 +333,7 @@ Map::EnsureGridCreated(const GridPair &p) { if (!getNGrid(p.x_coord, p.y_coord)) { - Guard guard(*this); + ACE_GUARD(ACE_Thread_Mutex, Guard, Lock); if (!getNGrid(p.x_coord, p.y_coord)) { sLog.outDebug("Creating grid[%u,%u] for map %u instance %u", p.x_coord, p.y_coord, GetId(), i_InstanceId); @@ -396,7 +394,7 @@ bool Map::EnsureGridLoaded(const Cell &cell) loader.LoadN(); // Add resurrectable corpses to world object list in grid - ObjectAccessor::Instance().AddCorpsesToGrid(GridPair(cell.GridX(),cell.GridY()),(*grid)(cell.CellX(), cell.CellY()), this); + sObjectAccessor.AddCorpsesToGrid(GridPair(cell.GridX(),cell.GridY()),(*grid)(cell.CellX(), cell.CellY()), this); setGridObjectDataLoaded(true,cell.GridX(), cell.GridY()); return true; @@ -829,7 +827,7 @@ bool Map::RemoveBones(uint64 guid, float x, float y) { if (IsRemovalGrid(x, y)) { - Corpse * corpse = ObjectAccessor::Instance().GetObjectInWorld(GetId(), x, y, guid, (Corpse*)NULL); + Corpse * corpse = sObjectAccessor.GetObjectInWorld(GetId(), x, y, guid, (Corpse*)NULL); if (corpse && corpse->GetTypeId() == TYPEID_CORPSE && corpse->GetType() == CORPSE_BONES) corpse->DeleteBonesFromWorld(); else @@ -1209,8 +1207,7 @@ bool GridMap::loadData(char *filename) if (!in) return true; fread(&header, sizeof(header),1,in); - if (header.mapMagic == uint32(MAP_MAGIC) && - header.versionMagic == uint32(MAP_VERSION_MAGIC)) + if (header.mapMagic == uint32(MAP_MAGIC) && header.versionMagic == uint32(MAP_VERSION_MAGIC)) { // loadup area data if (header.areaMapOffset && !loadAreaData(in, header.areaMapOffset, header.areaMapSize)) @@ -1236,18 +1233,18 @@ bool GridMap::loadData(char *filename) fclose(in); return true; } - sLog.outError("Map file '%s' is a non-compatible version (outdated?). Please, create new using the ad.exe program.", filename); + sLog.outError("Map file '%s' is from an incompatible clientversion. Please recreate using the mapextractor.", filename); fclose(in); return false; } void GridMap::unloadData() { - if (m_area_map) delete[] m_area_map; - if (m_V9) delete[] m_V9; - if (m_V8) delete[] m_V8; - if (m_liquid_type) delete[] m_liquid_type; - if (m_liquid_map) delete[] m_liquid_map; + delete[] m_area_map; + delete[] m_V9; + delete[] m_V8; + delete[] m_liquid_type; + delete[] m_liquid_map; m_area_map = NULL; m_V9 = NULL; m_V8 = NULL; @@ -2071,7 +2068,7 @@ void Map::SendInitSelf(Player * player) void Map::SendInitTransports(Player * player) { // Hack to send out transports - MapManager::TransportMap& tmap = MapManager::Instance().m_TransportsByMap; + MapManager::TransportMap& tmap = sMapMgr.m_TransportsByMap; // no transports at map if (tmap.find(player->GetMapId()) == tmap.end()) @@ -2098,7 +2095,7 @@ void Map::SendInitTransports(Player * player) void Map::SendRemoveTransports(Player * player) { // Hack to send out transports - MapManager::TransportMap& tmap = MapManager::Instance().m_TransportsByMap; + MapManager::TransportMap& tmap = sMapMgr.m_TransportsByMap; // no transports at map if (tmap.find(player->GetMapId()) == tmap.end()) @@ -2198,7 +2195,7 @@ void Map::RemoveAllObjectsInRemoveList() { case TYPEID_CORPSE: { - Corpse* corpse = ObjectAccessor::Instance().GetCorpse(*obj, obj->GetGUID()); + Corpse* corpse = sObjectAccessor.GetCorpse(*obj, obj->GetGUID()); if (!corpse) sLog.outError("Tried to delete corpse/bones %u that is not in map.", obj->GetGUIDLow()); else @@ -2352,11 +2349,8 @@ InstanceMap::InstanceMap(uint32 id, time_t expiry, uint32 InstanceId, uint8 Spaw InstanceMap::~InstanceMap() { - if (i_data) - { - delete i_data; - i_data = NULL; - } + delete i_data; + i_data = NULL; } void InstanceMap::InitVisibilityDistance() @@ -2400,6 +2394,32 @@ bool InstanceMap::CanEnter(Player *player) return false; } + // cannot enter if instance is in use by another party/soloer that have a + // permanent save in the same instance id + + PlayerList const &playerList = GetPlayers(); + Player *firstInsidePlayer = NULL; + + if (!playerList.isEmpty()) + for (PlayerList::const_iterator i = playerList.begin(); i != playerList.end(); ++i) + if (Player *iPlayer = i->getSource()) + { + if (iPlayer->isGameMaster()) // bypass GMs + continue; + if (!player->GetGroup()) // player has not group and there is someone inside, deny entry + { + player->SendTransferAborted(GetId(), TRANSFER_ABORT_MAX_PLAYERS); + return false; + } + // player inside instance has no group or his groups is different to entering player's one, deny entry + if (!iPlayer->GetGroup() || iPlayer->GetGroup() != player->GetGroup() ) + { + player->SendTransferAborted(GetId(), TRANSFER_ABORT_MAX_PLAYERS); + return false; + } + break; + } + return Map::CanEnter(player); } @@ -2413,7 +2433,7 @@ bool InstanceMap::Add(Player *player) // Is it needed? { - Guard guard(*this); + ACE_GUARD_RETURN(ACE_Thread_Mutex, guard, Lock, false); // Check moved to void WorldSession::HandleMoveWorldportAckOpcode() //if (!CanEnter(player)) //return false; @@ -2738,7 +2758,7 @@ bool BattleGroundMap::CanEnter(Player * player) bool BattleGroundMap::Add(Player * player) { { - Guard guard(*this); + ACE_GUARD_RETURN(ACE_Thread_Mutex, guard, Lock, false); //Check moved to void WorldSession::HandleMoveWorldportAckOpcode() //if (!CanEnter(player)) //return false; @@ -2882,7 +2902,7 @@ void Map::ScriptsProcess() source = HashMapHolder<Corpse>::Find(step.sourceGUID); break; case HIGHGUID_MO_TRANSPORT: - for (MapManager::TransportSet::iterator iter = MapManager::Instance().m_Transports.begin(); iter != MapManager::Instance().m_Transports.end(); ++iter) + for (MapManager::TransportSet::iterator iter = sMapMgr.m_Transports.begin(); iter != sMapMgr.m_Transports.end(); ++iter) { if ((*iter)->GetGUID() == step.sourceGUID) { @@ -2941,8 +2961,9 @@ void Map::ScriptsProcess() break; } - Creature* cSource = NULL; - cSource = source->ToCreature() != NULL ? source->ToCreature() : target->ToCreature(); + Creature* cSource = source->ToCreature(); + if (!cSource && target) + cSource = target->ToCreature(); if (!cSource) { @@ -2998,8 +3019,9 @@ void Map::ScriptsProcess() break; } - Creature* cSource = NULL; - cSource = source->ToCreature() != NULL ? source->ToCreature() : target->ToCreature(); + Creature* cSource = source->ToCreature(); + if (!cSource && target) + target->ToCreature(); if (!cSource) { @@ -3023,7 +3045,10 @@ void Map::ScriptsProcess() break; } - Creature* cSource = source->ToCreature() != NULL ? source->ToCreature() : target->ToCreature(); + Creature* cSource = source->ToCreature(); + if (!cSource && target) + cSource = target->ToCreature(); + if (!cSource) { sLog.outError("SCRIPT_COMMAND_FIELD_SET (script id: %u) call for non-creature source.", step.script->id); @@ -3049,7 +3074,10 @@ void Map::ScriptsProcess() break; } - Creature* cSource = source->ToCreature() != NULL ? source->ToCreature() : target->ToCreature(); + Creature* cSource = source->ToCreature(); + if (!cSource && target) + cSource = target->ToCreature(); + if (!cSource) { sLog.outError("SCRIPT_COMMAND_MOVE_TO (script id: %u) call for non-creature (TypeId: %u, Entry: %u, GUID: %u), skipping.", @@ -3070,7 +3098,10 @@ void Map::ScriptsProcess() break; } - Creature* cSource = source->ToCreature() != NULL ? source->ToCreature() : target->ToCreature(); + Creature* cSource = source->ToCreature(); + if (!cSource && target) + cSource = target->ToCreature(); + if (!cSource) { sLog.outError("SCRIPT_COMMAND_FLAG_SET (script id: %u) call for non-creature source.", step.script->id); @@ -3096,7 +3127,10 @@ void Map::ScriptsProcess() break; } - Creature* cSource = source->ToCreature() != NULL ? source->ToCreature() : target->ToCreature(); + Creature* cSource = source->ToCreature(); + if (!cSource && target) + cSource = target->ToCreature(); + if (!cSource) { sLog.outError("SCRIPT_COMMAND_FLAG_REMOVE (script id: %u) call for non-creature source.", step.script->id); @@ -3125,7 +3159,12 @@ void Map::ScriptsProcess() if (step.script->datalong2 == 0) { - Player* pSource = target->ToPlayer() != NULL ? target->ToPlayer() : source->ToPlayer(); + Player* pSource = NULL; + if (target) + pSource = target->ToPlayer(); + if (!pSource && source) + pSource = source->ToPlayer(); + // must be only Player if (!pSource) { @@ -3138,7 +3177,12 @@ void Map::ScriptsProcess() } else if (step.script->datalong2 == 1) { - Creature *cSource = target->ToCreature() != NULL ? target->ToCreature() : source->ToCreature(); + Creature *cSource = NULL; + if (target) + cSource = target->ToCreature(); + if (!cSource && source) + cSource = source->ToCreature(); + // must be only Creature if (!cSource) { @@ -3154,16 +3198,14 @@ void Map::ScriptsProcess() case SCRIPT_COMMAND_KILL_CREDIT: { + Player* pSource = NULL; // accept player in any one from target/source arg - if (!target && !source) - { - sLog.outError("SCRIPT_COMMAND_KILL_CREDIT (script id: %u) call for NULL object.", step.script->id); - break; - } - - Player* pSource = target->ToPlayer() != NULL ? target->ToPlayer() : source->ToPlayer(); - // must be only Player - if (!pSource) + if (target) + pSource = target->ToPlayer(); + if (!pSource && source) + pSource = source->ToPlayer(); + + if (!pSource) // must be only Player { sLog.outError("SCRIPT_COMMAND_KILL_CREDIT (script id: %u) call for non-player (TypeIdSource: %u)(TypeIdTarget: %u), skipping.", step.script->id, source ? source->GetTypeId() : 0, target ? target->GetTypeId() : 0); @@ -3277,6 +3319,7 @@ void Map::ScriptsProcess() go->GetMap()->Add(go); break; } + case SCRIPT_COMMAND_OPEN_DOOR: { if (!step.script->datalong) // door not specified @@ -3334,6 +3377,7 @@ void Map::ScriptsProcess() ((GameObject*)target)->UseDoorOrButton(time_to_close); break; } + case SCRIPT_COMMAND_CLOSE_DOOR: { if (!step.script->datalong) // guid for door not specified @@ -3392,6 +3436,7 @@ void Map::ScriptsProcess() break; } + case SCRIPT_COMMAND_QUEST_EXPLORED: { if (!source) @@ -3408,7 +3453,7 @@ void Map::ScriptsProcess() // when script called for item spell casting then target == (unit or GO) and source is player WorldObject* worldObject; - Player* pTarget; + Player* pTarget = NULL; pTarget = target->ToPlayer(); if (pTarget) @@ -3577,7 +3622,7 @@ void Map::ScriptsProcess() } // bitmask: 0/1=anyone/target, 0/2=with distance dependent - Player* pTarget; + Player* pTarget = NULL; if (step.script->datalong2 & 1) { if (!target) @@ -3586,7 +3631,7 @@ void Map::ScriptsProcess() break; } - pTarget = target->ToPlayer(); + pTarget = target ? target->ToPlayer() : NULL; if (!pTarget) { sLog.outError("SCRIPT_COMMAND_PLAY_SOUND (script id: %u) in targeted mode call for non-player (TypeId: %u, Entry: %u, GUID: %u), skipping.", @@ -3605,13 +3650,19 @@ void Map::ScriptsProcess() case SCRIPT_COMMAND_CREATE_ITEM: { - if (!target && !source) + if (!source) { - sLog.outError("SCRIPT_COMMAND_CREATE_ITEM (script id: %u) call for NULL object.", step.script->id); + sLog.outError("SCRIPT_COMMAND_CREATE_ITEM (script id: %u) call for NULL source.", + step.script->id); break; } - Player *pReceiver = target->ToPlayer() != NULL ? target->ToPlayer() : source->ToPlayer(); + Player *pReceiver = NULL; + if (target) + pReceiver = target->ToPlayer(); + if (!pReceiver) + pReceiver = source->ToPlayer(); + // only Player if (!pReceiver) { @@ -3798,6 +3849,7 @@ void Map::ScriptsProcess() uSource->SendMovementFlagUpdate(); break; } + case SCRIPT_COMMAND_EQUIP: { if (!source) @@ -3816,6 +3868,7 @@ void Map::ScriptsProcess() cSource->LoadEquipment(step.script->datalong); break; } + case SCRIPT_COMMAND_MODEL: { if (!source) diff --git a/src/server/game/Maps/Map.h b/src/server/game/Maps/Map.h index ceb526b8244..4d25381fbe1 100644 --- a/src/server/game/Maps/Map.h +++ b/src/server/game/Maps/Map.h @@ -21,8 +21,7 @@ #ifndef TRINITY_MAP_H #define TRINITY_MAP_H -#include "Platform/Define.h" -#include "Policies/ThreadingModel.h" +#include "Define.h" #include "ace/RW_Thread_Mutex.h" #include "ace/Thread_Mutex.h" @@ -31,9 +30,9 @@ #include "Cell.h" #include "Timer.h" #include "SharedDefines.h" -#include "GameSystem/GridRefManager.h" +#include "GridRefManager.h" #include "MapRefManager.h" -#include "mersennetwister/MersenneTwister.h" +#include "MersenneTwister.h" #include <bitset> #include <list> @@ -57,7 +56,7 @@ class BattleGround; // Map file format defines //****************************************** #define MAP_MAGIC 'SPAM' -#define MAP_VERSION_MAGIC '0.1w' +#define MAP_VERSION_MAGIC '1.1v' #define MAP_AREA_MAGIC 'AERA' #define MAP_HEIGHT_MAGIC 'TGHM' #define MAP_LIQUID_MAGIC 'QILM' @@ -66,6 +65,7 @@ struct map_fileheader { uint32 mapMagic; uint32 versionMagic; + uint32 buildMagic; uint32 areaMapOffset; uint32 areaMapSize; uint32 heightMapOffset; @@ -238,7 +238,7 @@ typedef UNORDERED_MAP<Creature*, CreatureMover> CreatureMoveList; typedef std::map<uint32/*leaderDBGUID*/, CreatureGroup*> CreatureGroupHolderType; -class Map : public GridRefManager<NGridType>, public Trinity::ObjectLevelLockable<Map, ACE_Thread_Mutex> +class Map : public GridRefManager<NGridType> { friend class MapReference; public: @@ -489,7 +489,7 @@ class Map : public GridRefManager<NGridType>, public Trinity::ObjectLevelLockabl protected: void SetUnloadReferenceLock(const GridPair &p, bool on) { getNGrid(p.x_coord, p.y_coord)->setUnloadReferenceLock(on); } - typedef Trinity::ObjectLevelLockable<Map, ACE_Thread_Mutex>::Lock Guard; + ACE_Thread_Mutex Lock; MapEntry const* i_mapEntry; uint8 i_spawnMode; diff --git a/src/server/game/Maps/MapInstanced.cpp b/src/server/game/Maps/MapInstanced.cpp index 0736bfa6fb3..008baeb79d9 100644 --- a/src/server/game/Maps/MapInstanced.cpp +++ b/src/server/game/Maps/MapInstanced.cpp @@ -170,7 +170,7 @@ Map* MapInstanced::CreateInstance(const uint32 mapId, Player * player) { // if no instanceId via group members or instance saves is found // the instance will be created for the first time - NewInstanceId = MapManager::Instance().GenerateInstanceId(); + NewInstanceId = sMapMgr.GenerateInstanceId(); Difficulty diff = player->GetGroup() ? player->GetGroup()->GetDifficulty(IsRaid()) : player->GetDifficulty(IsRaid()); map = CreateInstance(NewInstanceId, NULL, diff); @@ -183,7 +183,7 @@ Map* MapInstanced::CreateInstance(const uint32 mapId, Player * player) InstanceMap* MapInstanced::CreateInstance(uint32 InstanceId, InstanceSave *save, Difficulty difficulty) { // load/create a map - Guard guard(*this); + ACE_GUARD_RETURN(ACE_Thread_Mutex, Guard, Lock, NULL); // make sure we have a valid map id const MapEntry* entry = sMapStore.LookupEntry(GetId()); @@ -219,7 +219,7 @@ InstanceMap* MapInstanced::CreateInstance(uint32 InstanceId, InstanceSave *save, BattleGroundMap* MapInstanced::CreateBattleGround(uint32 InstanceId, BattleGround* bg) { // load/create a map - Guard guard(*this); + ACE_GUARD_RETURN(ACE_Thread_Mutex, Guard, Lock, NULL); sLog.outDebug("MapInstanced::CreateBattleGround: map bg %d for %d created.", InstanceId, GetId()); diff --git a/src/server/game/Maps/MapManager.cpp b/src/server/game/Maps/MapManager.cpp index de3d0ebbaff..36999aab14f 100644 --- a/src/server/game/Maps/MapManager.cpp +++ b/src/server/game/Maps/MapManager.cpp @@ -20,16 +20,15 @@ #include "MapManager.h" #include "InstanceSaveMgr.h" -#include "Policies/SingletonImp.h" -#include "Database/DatabaseEnv.h" +#include "DatabaseEnv.h" #include "Log.h" #include "ObjectAccessor.h" -#include "Transports.h" +#include "Transport.h" #include "GridDefines.h" #include "MapInstanced.h" #include "InstanceData.h" #include "DestinationHolderImp.h" -#include "Config/ConfigEnv.h" +#include "ConfigEnv.h" #include "World.h" #include "CellImpl.h" #include "Corpse.h" @@ -37,10 +36,6 @@ #include "Language.h" #include "WorldPacket.h" -#define CLASS_LOCK Trinity::ClassLevelLockable<MapManager, ACE_Thread_Mutex> -INSTANTIATE_SINGLETON_2(MapManager, CLASS_LOCK); -INSTANTIATE_CLASS_MUTEX(MapManager, ACE_Thread_Mutex); - extern GridState* si_GridStates[]; // debugging code, should be deleted some day MapManager::MapManager() @@ -116,7 +111,7 @@ Map* MapManager::_createBaseMap(uint32 id) if (m == NULL) { - Guard guard(*this); + ACE_GUARD_RETURN(ACE_Thread_Mutex, Guard, Lock, NULL); const MapEntry* entry = sMapStore.LookupEntry(id); if (entry && entry->Instanceable()) @@ -166,14 +161,35 @@ bool MapManager::CanPlayerEnter(uint32 mapid, Player* player, bool loginCheck) if (!entry->IsDungeon()) return true; + InstanceTemplate const* instance = objmgr.GetInstanceTemplate(mapid); + if (!instance) + return false; + + //The player has a heroic mode and tries to enter into instance which has no a heroic mode + MapDifficulty const* mapDiff = GetMapDifficultyData(entry->MapID,player->GetDifficulty(entry->IsRaid())); + if (!mapDiff) + { + bool isNormalTargetMap = entry->IsRaid() + ? (player->GetRaidDifficulty() == RAID_DIFFICULTY_10MAN_NORMAL) + : (player->GetDungeonDifficulty() == DUNGEON_DIFFICULTY_NORMAL); + + // Send aborted message + // FIX ME: what about absent normal/heroic mode with specific players limit... + player->SendTransferAborted(mapid, TRANSFER_ABORT_DIFFICULTY, isNormalTargetMap ? DUNGEON_DIFFICULTY_NORMAL : DUNGEON_DIFFICULTY_HEROIC); + return false; + } + + //Bypass checks for GMs + if (player->isGameMaster()) + return true; + const char *mapName = entry->name[player->GetSession()->GetSessionDbcLocale()]; Group* pGroup = player->GetGroup(); if (entry->IsRaid()) { // can only enter in a raid group - // GMs can avoid raid limitations - if ((!pGroup || !pGroup->isRaidGroup()) && !player->isGameMaster() && !sWorld.getConfig(CONFIG_INSTANCE_IGNORE_RAID)) + if ((!pGroup || !pGroup->isRaidGroup()) && !sWorld.getConfig(CONFIG_INSTANCE_IGNORE_RAID)) { // probably there must be special opcode, because client has this string constant in GlobalStrings.lua // TODO: this is not a good place to send the message @@ -183,20 +199,6 @@ bool MapManager::CanPlayerEnter(uint32 mapid, Player* player, bool loginCheck) } } - //The player has a heroic mode and tries to enter into instance which has no a heroic mode - MapDifficulty const* mapDiff = GetMapDifficultyData(entry->MapID,player->GetDifficulty(entry->IsRaid())); - if (!mapDiff) - { - bool isNormalTargetMap = entry->IsRaid() - ? (player->GetRaidDifficulty() == RAID_DIFFICULTY_10MAN_NORMAL) - : (player->GetDungeonDifficulty() == DUNGEON_DIFFICULTY_NORMAL); - - // Send aborted message - // FIX ME: what about absent normal/heroic mode with specific players limit... - player->SendTransferAborted(mapid, TRANSFER_ABORT_DIFFICULTY, isNormalTargetMap ? DUNGEON_DIFFICULTY_NORMAL : DUNGEON_DIFFICULTY_HEROIC); - return false; - } - if (!player->isAlive()) { if (Corpse *corpse = player->GetCorpse()) @@ -226,49 +228,24 @@ bool MapManager::CanPlayerEnter(uint32 mapid, Player* player, bool loginCheck) sLog.outDebug("Map::CanPlayerEnter - player '%s' is dead but does not have a corpse!", player->GetName()); } - InstanceTemplate const* instance = objmgr.GetInstanceTemplate(mapid); - if (!instance) - return false; - //Get instance where player's group is bound & its map if (pGroup) { - InstanceGroupBind* boundedInstance = pGroup->GetBoundInstance(player); + InstanceGroupBind* boundedInstance = pGroup->GetBoundInstance(entry); if (boundedInstance && boundedInstance->save) - { - if (Map *boundedMap = MapManager::Instance().FindMap(mapid,boundedInstance->save->GetInstanceId())) - { + if (Map *boundedMap = sMapMgr.FindMap(mapid,boundedInstance->save->GetInstanceId())) + if (!loginCheck && !boundedMap->CanEnter(player)) + return false; + /* + This check has to be moved to InstanceMap::CanEnter() // Player permanently bounded to different instance than groups one - InstancePlayerBind* playerBoundedInstance = player->GetBoundInstance(mapid, player->GetDungeonDifficulty()); + InstancePlayerBind* playerBoundedInstance = player->GetBoundInstance(mapid, player->GetDifficulty(entry->IsRaid())); if (playerBoundedInstance && playerBoundedInstance->perm && playerBoundedInstance->save && boundedInstance->save->GetInstanceId() != playerBoundedInstance->save->GetInstanceId()) { //TODO: send some kind of error message to the player return false; - } - - // Encounters in progress - if (!loginCheck && entry->IsRaid() && ((InstanceMap*)boundedMap)->GetInstanceData() && ((InstanceMap*)boundedMap)->GetInstanceData()->IsEncounterInProgress()) - { - sLog.outDebug("MAP: Player '%s' cannot enter instance '%s' while an encounter is in progress.", player->GetName(), mapName); - player->SendTransferAborted(mapid, TRANSFER_ABORT_ZONE_IN_COMBAT); - return false; - } - - // Instance is full - MapDifficulty const* mapDiff = ((InstanceMap*)boundedMap)->GetMapDifficulty(); - int8 maxPlayers = mapDiff ? mapDiff->maxPlayers : 0; - if (maxPlayers != -1) //-1: unlimited access - { - if (boundedMap->GetPlayersCountExceptGMs() >= (loginCheck ? maxPlayers+1 : maxPlayers)) - { - sLog.outDebug("MAP: Player '%s' cannot enter instance '%s' because it is full.", player->GetName(), mapName); - player->SendTransferAborted(mapid, TRANSFER_ABORT_MAX_PLAYERS); - return false; - } - } - } - } + }*/ } //Other requirements @@ -307,7 +284,7 @@ void MapManager::Update(uint32 diff) for (iter = i_maps.begin(); iter != i_maps.end(); ++iter) iter->second->DelayedUpdate(i_timer.GetCurrent()); - ObjectAccessor::Instance().Update(i_timer.GetCurrent()); + sObjectAccessor.Update(i_timer.GetCurrent()); for (TransportSet::iterator iter = m_Transports.begin(); iter != m_Transports.end(); ++iter) (*iter)->Update(i_timer.GetCurrent()); @@ -361,7 +338,7 @@ void MapManager::InitMaxInstanceId() uint32 MapManager::GetNumInstances() { - Guard guard(*this); + ACE_GUARD_RETURN(ACE_Thread_Mutex, Guard, Lock, NULL); uint32 ret = 0; for (MapMapType::iterator itr = i_maps.begin(); itr != i_maps.end(); ++itr) @@ -378,7 +355,7 @@ uint32 MapManager::GetNumInstances() uint32 MapManager::GetNumPlayersInInstances() { - Guard guard(*this); + ACE_GUARD_RETURN(ACE_Thread_Mutex, Guard, Lock, NULL); uint32 ret = 0; for (MapMapType::iterator itr = i_maps.begin(); itr != i_maps.end(); ++itr) diff --git a/src/server/game/Maps/MapManager.h b/src/server/game/Maps/MapManager.h index d94f9fced0e..47cb9d2f795 100644 --- a/src/server/game/Maps/MapManager.h +++ b/src/server/game/Maps/MapManager.h @@ -21,8 +21,8 @@ #ifndef TRINITY_MAPMANAGER_H #define TRINITY_MAPMANAGER_H -#include "Platform/Define.h" -#include "Policies/Singleton.h" +#include "Define.h" +#include "ace/Singleton.h" #include "ace/Thread_Mutex.h" #include "Common.h" #include "Map.h" @@ -31,10 +31,9 @@ class Transport; -class MapManager : public Trinity::Singleton<MapManager, Trinity::ClassLevelLockable<MapManager, ACE_Thread_Mutex> > +class MapManager { - - friend class Trinity::OperatorNew<MapManager>; + friend class ACE_Singleton<MapManager, ACE_Thread_Mutex>; typedef UNORDERED_MAP<uint32, Map*> MapMapType; typedef std::pair<UNORDERED_MAP<uint32, Map*>::iterator, bool> MapMapPair; @@ -108,6 +107,21 @@ class MapManager : public Trinity::Singleton<MapManager, Trinity::ClassLevelLock return IsValidMapCoord(loc.GetMapId(), loc.GetPositionX(), loc.GetPositionY(), loc.GetPositionZ(), loc.GetOrientation()); } + // modulos a radian orientation to the range of 0..2PI + static float NormalizeOrientation(float o) + { + // fmod only supports positive numbers. Thus we have + // to emulate negative numbers + if (o < 0) + { + float mod = o *-1; + mod = fmod(mod, 2.0f * static_cast<float>(M_PI)); + mod = -mod + 2.0f * M_PI; + return mod; + } + return fmod(o, 2.0f * static_cast<float>(M_PI)); + } + void DoDelayedMovesAndRemoves(); void LoadTransports(); @@ -147,7 +161,7 @@ class MapManager : public Trinity::Singleton<MapManager, Trinity::ClassLevelLock return (iter == i_maps.end() ? NULL : iter->second); } - typedef Trinity::ClassLevelLockable<MapManager, ACE_Thread_Mutex>::Lock Guard; + ACE_Thread_Mutex Lock; uint32 i_gridCleanUpDelay; MapMapType i_maps; IntervalTimer i_timer; @@ -155,4 +169,5 @@ class MapManager : public Trinity::Singleton<MapManager, Trinity::ClassLevelLock uint32 i_MaxInstanceId; MapUpdater m_updater; }; +#define sMapMgr (*ACE_Singleton<MapManager, ACE_Thread_Mutex>::instance()) #endif diff --git a/src/server/game/Maps/MapRefManager.h b/src/server/game/Maps/MapRefManager.h index 4337aa75fd9..2cf38c1b000 100644 --- a/src/server/game/Maps/MapRefManager.h +++ b/src/server/game/Maps/MapRefManager.h @@ -19,7 +19,7 @@ #ifndef _MAPREFMANAGER #define _MAPREFMANAGER -#include "Utilities/LinkedReference/RefManager.h" +#include "RefManager.h" class MapReference; diff --git a/src/server/game/Maps/MapReference.h b/src/server/game/Maps/MapReference.h index 7cd4fcde76c..e74fdba229b 100644 --- a/src/server/game/Maps/MapReference.h +++ b/src/server/game/Maps/MapReference.h @@ -19,7 +19,7 @@ #ifndef _MAPREFERENCE_H #define _MAPREFERENCE_H -#include "Utilities/LinkedReference/Reference.h" +#include "Reference.h" #include "Map.h" class MapReference : public Reference<Map, Player> diff --git a/src/server/game/Maps/MapUpdater.cpp b/src/server/game/Maps/MapUpdater.cpp index f9bb5e2bbbc..5720ed1eb50 100644 --- a/src/server/game/Maps/MapUpdater.cpp +++ b/src/server/game/Maps/MapUpdater.cpp @@ -1,7 +1,7 @@ #include "MapUpdater.h" #include "DelayExecutor.h" #include "Map.h" -#include "Database/DatabaseEnv.h" +#include "DatabaseEnv.h" #include <ace/Guard_T.h> #include <ace/Method_Request.h> |
