[10113] Some cleanups in Instance loading code.

* Remove reduncent chekc and args for MapInstanced::CreateInstance(const uint32 mapId, Player * player)
* Rename for avoid name duplication raw InstanceMap creating to MapInstanced::CreateInstanceMap
* Move lookup code of player/group bounde instance save to Player::GetBoundInstanceSaveForSelfOrGroup
This commit is contained in:
VladimirMangos 2010-06-27 19:26:35 +04:00
parent 3eb2d2910e
commit 6f4481a591
6 changed files with 50 additions and 45 deletions

View file

@ -94,13 +94,10 @@ void MapInstanced::UnloadAll(bool pForce)
/// returns a new or existing Instance /// returns a new or existing Instance
/// in case of battlegrounds it will only return an existing map, those maps are created by bg-system /// in case of battlegrounds it will only return an existing map, those maps are created by bg-system
Map* MapInstanced::CreateInstance(const uint32 mapId, Player * player) Map* MapInstanced::CreateInstance(Player * player)
{ {
if(GetId() != mapId || !player) Map* map;
return NULL; uint32 NewInstanceId; // instanceId of the resulting map
Map* map = NULL;
uint32 NewInstanceId = 0; // instanceId of the resulting map
if(IsBattleGroundOrArena()) if(IsBattleGroundOrArena())
{ {
@ -110,46 +107,29 @@ Map* MapInstanced::CreateInstance(const uint32 mapId, Player * player)
map = _FindMap(NewInstanceId); map = _FindMap(NewInstanceId);
ASSERT(map); ASSERT(map);
} }
else if (InstanceSave* pSave = player->GetBoundInstanceSaveForSelfOrGroup(GetId()))
{
// solo/perm/group
NewInstanceId = pSave->GetInstanceId();
map = _FindMap(NewInstanceId);
// it is possible that the save exists but the map doesn't
if (!map)
map = CreateInstanceMap(NewInstanceId, pSave->GetDifficulty(), pSave);
}
else else
{ {
InstancePlayerBind *pBind = player->GetBoundInstance(GetId(), player->GetDifficulty(IsRaid())); // if no instanceId via group members or instance saves is found
InstanceSave *pSave = pBind ? pBind->save : NULL; // the instance will be created for the first time
NewInstanceId = sMapMgr.GenerateInstanceId();
// the player's permanent player bind is taken into consideration first Difficulty diff = player->GetGroup() ? player->GetGroup()->GetDifficulty(IsRaid()) : player->GetDifficulty(IsRaid());
// then the player's group bind and finally the solo bind. map = CreateInstanceMap(NewInstanceId, diff);
if(!pBind || !pBind->perm)
{
InstanceGroupBind *groupBind = NULL;
Group *group = player->GetGroup();
// use the player's difficulty setting (it may not be the same as the group's)
if(group && (groupBind = group->GetBoundInstance(this,player->GetDifficulty(IsRaid()))))
pSave = groupBind->save;
}
if(pSave)
{
// solo/perm/group
NewInstanceId = pSave->GetInstanceId();
map = _FindMap(NewInstanceId);
// it is possible that the save exists but the map doesn't
if(!map)
map = CreateInstance(NewInstanceId, pSave, pSave->GetDifficulty());
}
else
{
// if no instanceId via group members or instance saves is found
// the instance will be created for the first time
NewInstanceId = sMapMgr.GenerateInstanceId();
Difficulty diff = player->GetGroup() ? player->GetGroup()->GetDifficulty(IsRaid()) : player->GetDifficulty(IsRaid());
map = CreateInstance(NewInstanceId, NULL, diff);
}
} }
return map; return map;
} }
InstanceMap* MapInstanced::CreateInstance(uint32 InstanceId, InstanceSave *save, Difficulty difficulty) InstanceMap* MapInstanced::CreateInstanceMap(uint32 InstanceId, Difficulty difficulty, InstanceSave *save)
{ {
// load/create a map // load/create a map
Guard guard(*this); Guard guard(*this);
@ -157,12 +137,12 @@ InstanceMap* MapInstanced::CreateInstance(uint32 InstanceId, InstanceSave *save,
// make sure we have a valid map id // make sure we have a valid map id
if (!sMapStore.LookupEntry(GetId())) if (!sMapStore.LookupEntry(GetId()))
{ {
sLog.outError("CreateInstance: no entry for map %d", GetId()); sLog.outError("CreateInstanceMap: no entry for map %d", GetId());
ASSERT(false); ASSERT(false);
} }
if (!ObjectMgr::GetInstanceTemplate(GetId())) if (!ObjectMgr::GetInstanceTemplate(GetId()))
{ {
sLog.outError("CreateInstance: no instance template for map %d", GetId()); sLog.outError("CreateInstanceMap: no instance template for map %d", GetId());
ASSERT(false); ASSERT(false);
} }
@ -170,7 +150,7 @@ InstanceMap* MapInstanced::CreateInstance(uint32 InstanceId, InstanceSave *save,
if (!GetMapDifficultyData(GetId(),difficulty)) if (!GetMapDifficultyData(GetId(),difficulty))
difficulty = DUNGEON_DIFFICULTY_NORMAL; difficulty = DUNGEON_DIFFICULTY_NORMAL;
DEBUG_LOG("MapInstanced::CreateInstance: %s map instance %d for %d created with difficulty %s", save?"":"new ", InstanceId, GetId(), difficulty?"heroic":"normal"); DEBUG_LOG("MapInstanced::CreateInstanceMap: %s map instance %d for %d created with difficulty %d", save?"":"new ", InstanceId, GetId(), difficulty);
InstanceMap *map = new InstanceMap(GetId(), GetGridExpiry(), InstanceId, difficulty, this); InstanceMap *map = new InstanceMap(GetId(), GetGridExpiry(), InstanceId, difficulty, this);
ASSERT(map->IsDungeon()); ASSERT(map->IsDungeon());

View file

@ -37,7 +37,7 @@ class MANGOS_DLL_DECL MapInstanced : public Map
void RemoveAllObjectsInRemoveList(); void RemoveAllObjectsInRemoveList();
void UnloadAll(bool pForce); void UnloadAll(bool pForce);
Map* CreateInstance(const uint32 mapId, Player * player); Map* CreateInstance(Player* player);
Map* FindMap(uint32 InstanceId) const { return _FindMap(InstanceId); } Map* FindMap(uint32 InstanceId) const { return _FindMap(InstanceId); }
void DestroyInstance(uint32 InstanceId); void DestroyInstance(uint32 InstanceId);
void DestroyInstance(InstancedMaps::iterator &itr); void DestroyInstance(InstancedMaps::iterator &itr);
@ -61,7 +61,7 @@ class MANGOS_DLL_DECL MapInstanced : public Map
private: private:
InstanceMap* CreateInstance(uint32 InstanceId, InstanceSave *save, Difficulty difficulty); InstanceMap* CreateInstanceMap(uint32 InstanceId, Difficulty difficulty, InstanceSave *save = NULL);
InstancedMaps m_InstancedMaps; InstancedMaps m_InstancedMaps;

View file

@ -120,7 +120,8 @@ Map* MapManager::CreateMap(uint32 id, const WorldObject* obj)
//if(!obj->IsInWorld()) sLog.outError("GetMap: called for map %d with object (typeid %d, guid %d, mapid %d, instanceid %d) who is not in world!", id, obj->GetTypeId(), obj->GetGUIDLow(), obj->GetMapId(), obj->GetInstanceId()); //if(!obj->IsInWorld()) sLog.outError("GetMap: called for map %d with object (typeid %d, guid %d, mapid %d, instanceid %d) who is not in world!", id, obj->GetTypeId(), obj->GetGUIDLow(), obj->GetMapId(), obj->GetInstanceId());
Map *m = _createBaseMap(id); Map *m = _createBaseMap(id);
if (m && (obj->GetTypeId() == TYPEID_PLAYER) && m->Instanceable()) m = ((MapInstanced*)m)->CreateInstance(id, (Player*)obj); if (m && (obj->GetTypeId() == TYPEID_PLAYER) && m->Instanceable())
m = ((MapInstanced*)m)->CreateInstance((Player*)obj);
return m; return m;
} }

View file

@ -16423,6 +16423,29 @@ InstancePlayerBind* Player::BindToInstance(InstanceSave *save, bool permanent, b
return NULL; return NULL;
} }
InstanceSave* Player::GetBoundInstanceSaveForSelfOrGroup(uint32 mapid)
{
MapEntry const* mapEntry = sMapStore.LookupEntry(mapid);
if(!mapEntry)
return NULL;
InstancePlayerBind *pBind = GetBoundInstance(mapid, GetDifficulty(mapEntry->IsRaid()));
InstanceSave *pSave = pBind ? pBind->save : NULL;
// the player's permanent player bind is taken into consideration first
// then the player's group bind and finally the solo bind.
if(!pBind || !pBind->perm)
{
InstanceGroupBind *groupBind = NULL;
Group *group = GetGroup();
// use the player's difficulty setting (it may not be the same as the group's)
if(group && (groupBind = group->GetBoundInstance(this)))
pSave = groupBind->save;
}
return pSave;
}
void Player::SendRaidInfo() void Player::SendRaidInfo()
{ {
uint32 counter = 0; uint32 counter = 0;

View file

@ -2302,6 +2302,7 @@ class MANGOS_DLL_SPEC Player : public Unit
void SendRaidInfo(); void SendRaidInfo();
void SendSavedInstances(); void SendSavedInstances();
static void ConvertInstancesToGroup(Player *player, Group *group = NULL, uint64 player_guid = 0); static void ConvertInstancesToGroup(Player *player, Group *group = NULL, uint64 player_guid = 0);
InstanceSave* GetBoundInstanceSaveForSelfOrGroup(uint32 mapid);
/*********************************************************/ /*********************************************************/
/*** GROUP SYSTEM ***/ /*** GROUP SYSTEM ***/

View file

@ -1,4 +1,4 @@
#ifndef __REVISION_NR_H__ #ifndef __REVISION_NR_H__
#define __REVISION_NR_H__ #define __REVISION_NR_H__
#define REVISION_NR "10112" #define REVISION_NR "10113"
#endif // __REVISION_NR_H__ #endif // __REVISION_NR_H__