void BattleGroundMgr::CreateInitialBattleGrounds() { std::string bg_Name; uint32 MaxPlayersPerTeam; uint32 MapId; float AStartLoc[4]; float HStartLoc[4]; uint32 LevMin; uint32 LevMax; // Create BG, Warsong Gulch, Levels 1-60, 10 per team bg_Name = "Warsong Gulch"; MapId = 489; MaxPlayersPerTeam = 10; AStartLoc[0] = 1519.530273f; AStartLoc[1] = 1481.868408f; AStartLoc[2] = 352.023743f; AStartLoc[3] = 3.141593f; HStartLoc[0] = 933.989685f; HStartLoc[1] = 1430.735840f; HStartLoc[2] = 345.537140f; HStartLoc[3] = 3.141593f; LevMin = 1; LevMax = 60; sLog.outString("Creating battleground %s, %u-%u", bg_Name.c_str(), LevMin, LevMax); CreateBattleGround(MaxPlayersPerTeam, LevMin, LevMax, bg_Name, MapId, AStartLoc[0], AStartLoc[1], AStartLoc[2], AStartLoc[3], HStartLoc[0], HStartLoc[1], HStartLoc[2], HStartLoc[3]); sLog.outString("Created initial battlegrounds."); }
/* - return the right instance for the object, based on its InstanceId - create the instance if it's not created already - the player is not actually added to the instance (only in InstanceMap::Add) */ Map* MapInstanced::CreateInstance(const uint32 mapId, Player * player) { if (GetId() != mapId || !player) return NULL; Map* map = NULL; uint32 NewInstanceId = 0; // instanceId of the resulting map if (IsBattleGroundOrArena()) { // instantiate or find existing bg map for player // the instance id is set in battlegroundid NewInstanceId = player->GetBattleGroundId(); if (!NewInstanceId) return NULL; map = _FindMap(NewInstanceId); if (!map) map = CreateBattleGround(NewInstanceId, player->GetBattleGround()); } else { InstancePlayerBind *pBind = player->GetBoundInstance(GetId(), player->GetDifficulty()); 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 = player->GetGroup(); // use the player's difficulty setting (it may not be the same as the group's) if (group) { groupBind = group->GetBoundInstance(this); if (groupBind) 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 = MapManager::Instance().GenerateInstanceId(); map = CreateInstance(NewInstanceId, NULL, player->GetDifficulty()); } } return map; }
void BattleGroundMgr::CreateInitialBattleGrounds() { float AStartLoc[4]; float HStartLoc[4]; uint32 MaxPlayersPerTeam, MinPlayersPerTeam, MinLvl, MaxLvl, start1, start2; WorldSafeLocsEntry const *start; uint32 count = 0; // 0 1 2 3 4 5 6 7 8 QueryResult *result = WorldDatabase.Query("SELECT id, MinPlayersPerTeam,MaxPlayersPerTeam,MinLvl,MaxLvl,AllianceStartLoc,AllianceStartO,HordeStartLoc,HordeStartO FROM battleground_template"); if(!result) { barGoLink bar(1); bar.step(); sLog.outString(); sLog.outErrorDb(">> Loaded 0 battlegrounds. DB table `battleground_template` is empty."); return; } barGoLink bar(result->GetRowCount()); do { Field *fields = result->Fetch(); bar.step(); uint32 bgTypeID = fields[0].GetUInt32(); // can be overwrited by values from DB MaxPlayersPerTeam = 0; MinPlayersPerTeam = 0; MinLvl = 0; MaxLvl = 0; if(fields[1].GetUInt32()) MinPlayersPerTeam = fields[1].GetUInt32(); if(fields[2].GetUInt32()) MaxPlayersPerTeam = fields[2].GetUInt32(); if(fields[3].GetUInt32()) MinLvl = fields[3].GetUInt32(); if(fields[4].GetUInt32()) MaxLvl = fields[4].GetUInt32(); start1 = fields[5].GetUInt32(); start = sWorldSafeLocsStore.LookupEntry(start1); if(start) { AStartLoc[0] = start->x; AStartLoc[1] = start->y; AStartLoc[2] = start->z; AStartLoc[3] = fields[6].GetFloat(); } else { sLog.outErrorDb("Table `battleground_template` for id %u have non-existed WorldSafeLocs.dbc id %u in field `AllianceStartLoc`. BG not created.",bgTypeID,start1); continue; } start2 = fields[7].GetUInt32(); start = sWorldSafeLocsStore.LookupEntry(start2); if(start) { HStartLoc[0] = start->x; HStartLoc[1] = start->y; HStartLoc[2] = start->z; HStartLoc[3] = fields[8].GetFloat(); } else { sLog.outErrorDb("Table `battleground_template` for id %u have non-existed WorldSafeLocs.dbc id %u in field `HordeStartLoc`. BG not created.",bgTypeID,start2); continue; } //sLog.outDetail("Creating battleground %s, %u-%u", bl->name[sWorld.GetDBClang()], MinLvl, MaxLvl); if(!CreateBattleGround(bgTypeID, MinPlayersPerTeam, MaxPlayersPerTeam, MinLvl, MaxLvl, AStartLoc[0], AStartLoc[1], AStartLoc[2], AStartLoc[3], HStartLoc[0], HStartLoc[1], HStartLoc[2], HStartLoc[3])) continue; ++count; } while (result->NextRow()); delete result; sLog.outString(); sLog.outString( ">> Loaded %u battlegrounds", count ); }
/* - return the right instance for the object, based on its InstanceId - create the instance if it's not created already - the player is not actually added to the instance (only in InstanceMap::Add) */ Map* MapInstanced::GetInstance(const WorldObject* obj) { uint32 CurInstanceId = obj->GetInstanceId(); Map* map = NULL; if (obj->GetMapId() == GetId() && CurInstanceId != 0) { // the object wants to be put in a certain instance of this map map = _FindMap(CurInstanceId); if(!map) { // For players if the instanceId is set, it's assumed they are already in a map, // hence the map must be loaded. For Creatures, GameObjects etc the map must exist // prior to calling GetMap, they are not allowed to create maps for themselves. sLog.outError("GetInstance: object %s(%d), typeId %d, in world %d, should be in map %d,%d but that's not loaded yet.", obj->GetName(), obj->GetGUIDLow(), obj->GetTypeId(), obj->IsInWorld(), obj->GetMapId(), obj->GetInstanceId()); assert(false); } return(map); } else { // instance not specified, find an existing or create a new one if(obj->GetTypeId() != TYPEID_PLAYER) { sLog.outError("MAPINSTANCED: WorldObject '%u' (Entry: %u TypeID: %u) is in map %d,%d and requested base map instance of map %d, this must not happen", obj->GetGUIDLow(), obj->GetEntry(), obj->GetTypeId(), obj->GetMapId(), obj->GetInstanceId(), GetId()); assert(false); return NULL; } else { uint32 NewInstanceId = 0; // instanceId of the resulting map Player* player = (Player*)obj; if(IsBattleGroundOrArena()) { // instantiate or find existing bg map for player // the instance id is set in battlegroundid NewInstanceId = player->GetBattleGroundId(); if(!NewInstanceId) { if(player->GetSession()->PlayerLoading()) return NULL; else assert(NewInstanceId); } map = _FindMap(NewInstanceId); if(!map) { map = CreateBattleGround(NewInstanceId); ((BattleGroundMap*)map)->SetBG(player->GetBattleGround()); } if(!((BattleGroundMap*)map)->GetBG()) { sLog.outError("The bg-class couldn't be assigned (very early) to the battlegroundmap, it's possible, that some db-spawned creatures are now not handled right this is related to battleground alterac valley (av) - please post bugreport, and add information how this bg was created (if you don't have information, report it also) Player: %s (%u) in map:%u requested map:%u", player->GetName(), player->GetGUIDLow(), player->GetMapId(), GetId()); if(player->GetBattleGround()) { sLog.outError("somehow the battleground was found, but please report also - i end this bg now.."); ((BattleGroundMap*)map)->SetBG(player->GetBattleGround()); player->GetBattleGround()->EndBattleGround(0); //to avoid the assert } //assert(false); } return map; } InstancePlayerBind *pBind = player->GetBoundInstance(GetId(), player->GetDifficulty()); InstanceSave *pSave = pBind ? pBind->save : NULL; // the player's permanet 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 = player->GetGroup(); // use the player's difficulty setting (it may not be the same as the group's) if(group && (groupBind = group->GetBoundInstance(GetId(), player->GetDifficulty()))) 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()); return map; } else { // if no instanceId via group members or instance saves is found // the instance will be created for the first time NewInstanceId = MapManager::Instance().GenerateInstanceId(); return CreateInstance(NewInstanceId, NULL, player->GetDifficulty()); } } } }