/// returns a new or existing Instance /// in case of battlegrounds it will only return an existing map, those maps are created by bg-system Map* MapInstanced::CreateInstance(Player * player) { Map* map; uint32 NewInstanceId; // instanceId of the resulting map if(IsBattleGroundOrArena()) { // find existing bg map for player NewInstanceId = player->GetBattleGroundId(); MANGOS_ASSERT(NewInstanceId); map = _FindMap(NewInstanceId); MANGOS_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 { // if no instanceId via group members or instance saves is found // the instance will be created for the first time NewInstanceId = sObjectMgr.GenerateLowGuid(HIGHGUID_INSTANCE); Difficulty diff = player->GetGroup() ? player->GetGroup()->GetDifficulty(IsRaid()) : player->GetDifficulty(IsRaid()); map = CreateInstanceMap(NewInstanceId, diff); } return map; }
///// returns a new or existing Instance ///// in case of battlegrounds it will only return an existing map, those maps are created by bg-system Map* MapManager::CreateInstance(uint32 id, Player * player) { Map* map = NULL; Map * pNewMap = NULL; uint32 NewInstanceId = 0; // instanceId of the resulting map const MapEntry* entry = sMapStore.LookupEntry(id); if(entry->IsBattleGroundOrArena()) { // find existing bg map for player NewInstanceId = player->GetBattleGroundId(); ASSERT(NewInstanceId); if (map = FindMap(id, NewInstanceId)) ASSERT(map); } else if (InstanceSave* pSave = player->GetBoundInstanceSaveForSelfOrGroup(id)) { // solo/perm/group NewInstanceId = pSave->GetGUID(); map = FindMap(id, NewInstanceId); // it is possible that the save exists but the map doesn't if (!map) { pNewMap = CreateInstanceMap(id, NewInstanceId, pSave->GetDifficulty(), pSave); NewInstanceId = pNewMap->GetInstanceId(); } } else { // if no instanceId via group members or instance saves is found // the instance will be created for the first time NewInstanceId = sObjectMgr.GenerateLowGuid(HIGHGUID_INSTANCE); Difficulty diff = player->GetGroup() ? player->GetGroup()->GetDifficulty(entry->IsRaid()) : player->GetDifficulty(entry->IsRaid()); pNewMap = CreateInstanceMap(id, NewInstanceId, diff); NewInstanceId = pNewMap->GetInstanceId(); } //add a new map object into the registry if(pNewMap) { i_maps[MapID(id, NewInstanceId)] = pNewMap; map = pNewMap; } return map; }
void DistributeWorkersAcrossStmgrs(CommonResources& common) { // which stmgr is this component going to get assigned to sp_int32 stmgr_assignment_round = 0; sp_int32 global_index = 0; // Distribute the spouts for (int spout = 0; spout < common.num_spouts_; ++spout) { for (int spout_instance = 0; spout_instance < common.num_spout_instances_; ++spout_instance) { heron::proto::system::Instance* imap = CreateInstanceMap(spout, spout_instance, stmgr_assignment_round, global_index++, true); common.stmgr_instance_id_list_[stmgr_assignment_round].push_back(imap->instance_id()); common.stmgr_instance_list_[stmgr_assignment_round].push_back(imap); common.instanceid_instance_[imap->instance_id()] = imap; common.instanceid_stmgr_[imap->instance_id()] = stmgr_assignment_round; // Have we completed a round of distribution of components if (++stmgr_assignment_round == common.num_stmgrs_) { stmgr_assignment_round = 0; } } } stmgr_assignment_round = 0; // Distribute the bolts for (int bolt = 0; bolt < common.num_bolts_; ++bolt) { for (int bolt_instance = 0; bolt_instance < common.num_bolt_instances_; ++bolt_instance) { heron::proto::system::Instance* imap = CreateInstanceMap(bolt, bolt_instance, stmgr_assignment_round, global_index++, false); // Have we completed a round of distribution of components common.stmgr_instance_id_list_[stmgr_assignment_round].push_back(imap->instance_id()); common.stmgr_instance_list_[stmgr_assignment_round].push_back(imap); common.instanceid_instance_[imap->instance_id()] = imap; common.instanceid_stmgr_[imap->instance_id()] = stmgr_assignment_round; if (++stmgr_assignment_round == common.num_stmgrs_) { stmgr_assignment_round = 0; } } } }