Merge pull request #3901 from Yelvann/master

Core/Arenas: Members of same arena team were able to fight each othe...
This commit is contained in:
Jorge
2011-11-09 11:59:13 -08:00
@@ -911,104 +911,83 @@ void BattlegroundQueue::BattlegroundQueueUpdate(uint32 diff, BattlegroundTypeId
uint32 discardTime = getMSTime() - sBattlegroundMgr->GetRatingDiscardTimer(); uint32 discardTime = getMSTime() - sBattlegroundMgr->GetRatingDiscardTimer();
// we need to find 2 teams which will play next game // we need to find 2 teams which will play next game
GroupsQueueType::iterator itr_teams[BG_TEAMS_COUNT];
GroupsQueueType::iterator itr_team[BG_TEAMS_COUNT]; uint8 found = 0;
uint8 team = 0;
//optimalization : --- we dont need to use selection_pools - each update we select max 2 groups
for (uint32 i = BG_QUEUE_PREMADE_ALLIANCE; i < BG_QUEUE_NORMAL_ALLIANCE; i++) for (uint8 i = BG_QUEUE_PREMADE_ALLIANCE; i < BG_QUEUE_NORMAL_ALLIANCE; i++)
{ {
// take the group that joined first // take the group that joined first
itr_team[i] = m_QueuedGroups[bracket_id][i].begin(); GroupsQueueType::iterator itr = m_QueuedGroups[bracket_id][i].begin();
for (; itr_team[i] != m_QueuedGroups[bracket_id][i].end(); ++(itr_team[i])) for (; itr != m_QueuedGroups[bracket_id][i].end(); ++itr)
{ {
// if group match conditions, then add it to pool // if group match conditions, then add it to pool
if (!(*itr_team[i])->IsInvitedToBGInstanceGUID if (!(*itr)->IsInvitedToBGInstanceGUID
&& (((*itr_team[i])->ArenaMatchmakerRating >= arenaMinRating && (*itr_team[i])->ArenaMatchmakerRating <= arenaMaxRating) && (((*itr)->ArenaMatchmakerRating >= arenaMinRating && (*itr)->ArenaMatchmakerRating <= arenaMaxRating)
|| (*itr_team[i])->JoinTime < discardTime)) || (*itr)->JoinTime < discardTime))
{ {
m_SelectionPools[i].AddGroup((*itr_team[i]), MaxPlayersPerTeam); itr_teams[found++] = itr;
// break for cycle to be able to start selecting another group from same faction queue team = i;
break; break;
} }
} }
} }
// now we are done if we have 2 groups - ali vs horde! if (!found)
// if we don't have, we must try to continue search in same queue return;
// tmp variables are correctly set
// this code isn't much userfriendly - but it is supposed to continue search for mathing group in HORDE queue if (found == 1)
if (m_SelectionPools[BG_TEAM_ALLIANCE].GetPlayerCount() == 0 && m_SelectionPools[BG_TEAM_HORDE].GetPlayerCount())
{ {
itr_team[BG_TEAM_ALLIANCE] = itr_team[BG_TEAM_HORDE]; for (GroupsQueueType::iterator itr = itr_teams[0]; itr != m_QueuedGroups[bracket_id][team].end(); ++itr)
++itr_team[BG_TEAM_ALLIANCE];
for (; itr_team[BG_TEAM_ALLIANCE] != m_QueuedGroups[bracket_id][BG_QUEUE_PREMADE_HORDE].end(); ++(itr_team[BG_TEAM_ALLIANCE]))
{ {
if (!(*itr_team[BG_TEAM_ALLIANCE])->IsInvitedToBGInstanceGUID if (!(*itr)->IsInvitedToBGInstanceGUID
&& (((*itr_team[BG_TEAM_ALLIANCE])->ArenaMatchmakerRating >= arenaMinRating && (*itr_team[BG_TEAM_ALLIANCE])->ArenaMatchmakerRating <= arenaMaxRating) && (((*itr)->ArenaMatchmakerRating >= arenaMinRating && (*itr)->ArenaMatchmakerRating <= arenaMaxRating)
|| (*itr_team[BG_TEAM_ALLIANCE])->JoinTime < discardTime)) || (*itr)->JoinTime < discardTime)
&& (*itr_teams[0])->ArenaTeamId != (*itr)->ArenaTeamId)
{ {
m_SelectionPools[BG_TEAM_ALLIANCE].AddGroup((*itr_team[BG_TEAM_ALLIANCE]), MaxPlayersPerTeam); itr_teams[found++] = itr;
break; break;
} }
} }
} }
// this code isn't much userfriendly - but it is supposed to continue search for mathing group in ALLIANCE queue
if (m_SelectionPools[BG_TEAM_HORDE].GetPlayerCount() == 0 && m_SelectionPools[BG_TEAM_ALLIANCE].GetPlayerCount())
{
itr_team[BG_TEAM_HORDE] = itr_team[BG_TEAM_ALLIANCE];
++itr_team[BG_TEAM_HORDE];
for (; itr_team[BG_TEAM_HORDE] != m_QueuedGroups[bracket_id][BG_QUEUE_PREMADE_ALLIANCE].end(); ++(itr_team[BG_TEAM_HORDE]))
{
if (!(*itr_team[BG_TEAM_HORDE])->IsInvitedToBGInstanceGUID
&& (((*itr_team[BG_TEAM_HORDE])->ArenaMatchmakerRating >= arenaMinRating && (*itr_team[BG_TEAM_HORDE])->ArenaMatchmakerRating <= arenaMaxRating)
|| (*itr_team[BG_TEAM_HORDE])->JoinTime < discardTime))
{
m_SelectionPools[BG_TEAM_HORDE].AddGroup((*itr_team[BG_TEAM_HORDE]), MaxPlayersPerTeam);
break;
}
}
}
//if we have 2 teams, then start new arena and invite players! //if we have 2 teams, then start new arena and invite players!
if (m_SelectionPools[BG_TEAM_ALLIANCE].GetPlayerCount() && m_SelectionPools[BG_TEAM_HORDE].GetPlayerCount()) if (found == 2)
{ {
GroupQueueInfo* aTeam = *itr_teams[BG_TEAM_ALLIANCE];
GroupQueueInfo* hTeam = *itr_teams[BG_TEAM_HORDE];
Battleground* arena = sBattlegroundMgr->CreateNewBattleground(bgTypeId, bracketEntry, arenaType, true); Battleground* arena = sBattlegroundMgr->CreateNewBattleground(bgTypeId, bracketEntry, arenaType, true);
if (!arena) if (!arena)
{ {
sLog->outError("BattlegroundQueue::Update couldn't create arena instance for rated arena match!"); sLog->outError("BattlegroundQueue::Update couldn't create arena instance for rated arena match!");
return; return;
} }
(*(itr_team[BG_TEAM_ALLIANCE]))->OpponentsTeamRating = (*(itr_team[BG_TEAM_HORDE]))->ArenaTeamRating; aTeam->OpponentsTeamRating = hTeam->ArenaTeamRating;
(*(itr_team[BG_TEAM_ALLIANCE]))->OpponentsMatchmakerRating = (*(itr_team[BG_TEAM_HORDE]))->ArenaMatchmakerRating; hTeam->OpponentsTeamRating = aTeam->ArenaTeamRating;
sLog->outDebug(LOG_FILTER_BATTLEGROUND, "setting oposite teamrating for team %u to %u", (*(itr_team[BG_TEAM_ALLIANCE]))->ArenaTeamId, (*(itr_team[BG_TEAM_ALLIANCE]))->OpponentsTeamRating); aTeam->OpponentsMatchmakerRating = hTeam->ArenaMatchmakerRating;
(*(itr_team[BG_TEAM_HORDE]))->OpponentsTeamRating = (*(itr_team[BG_TEAM_ALLIANCE]))->ArenaTeamRating; hTeam->OpponentsMatchmakerRating = aTeam->ArenaMatchmakerRating;
(*(itr_team[BG_TEAM_HORDE]))->OpponentsMatchmakerRating = (*(itr_team[BG_TEAM_ALLIANCE]))->ArenaMatchmakerRating; sLog->outDebug(LOG_FILTER_BATTLEGROUND, "setting oposite teamrating for team %u to %u", aTeam->ArenaTeamId, aTeam->OpponentsTeamRating);
sLog->outDebug(LOG_FILTER_BATTLEGROUND, "setting oposite teamrating for team %u to %u", (*(itr_team[BG_TEAM_HORDE]))->ArenaTeamId, (*(itr_team[BG_TEAM_HORDE]))->OpponentsTeamRating); sLog->outDebug(LOG_FILTER_BATTLEGROUND, "setting oposite teamrating for team %u to %u", hTeam->ArenaTeamId, hTeam->OpponentsTeamRating);
// now we must move team if we changed its faction to another faction queue, because then we will spam log by errors in Queue::RemovePlayer // now we must move team if we changed its faction to another faction queue, because then we will spam log by errors in Queue::RemovePlayer
if ((*(itr_team[BG_TEAM_ALLIANCE]))->Team != ALLIANCE) if (aTeam->Team != ALLIANCE)
{ {
// add to alliance queue m_QueuedGroups[bracket_id][BG_QUEUE_PREMADE_ALLIANCE].push_front(aTeam);
m_QueuedGroups[bracket_id][BG_QUEUE_PREMADE_ALLIANCE].push_front(*(itr_team[BG_TEAM_ALLIANCE])); m_QueuedGroups[bracket_id][BG_QUEUE_PREMADE_HORDE].erase(itr_teams[BG_TEAM_ALLIANCE]);
// erase from horde queue
m_QueuedGroups[bracket_id][BG_QUEUE_PREMADE_HORDE].erase(itr_team[BG_TEAM_ALLIANCE]);
itr_team[BG_TEAM_ALLIANCE] = m_QueuedGroups[bracket_id][BG_QUEUE_PREMADE_ALLIANCE].begin();
} }
if ((*(itr_team[BG_TEAM_HORDE]))->Team != HORDE) if (hTeam->Team != HORDE)
{ {
m_QueuedGroups[bracket_id][BG_QUEUE_PREMADE_HORDE].push_front(*(itr_team[BG_TEAM_HORDE])); m_QueuedGroups[bracket_id][BG_QUEUE_PREMADE_HORDE].push_front(hTeam);
m_QueuedGroups[bracket_id][BG_QUEUE_PREMADE_ALLIANCE].erase(itr_team[BG_TEAM_HORDE]); m_QueuedGroups[bracket_id][BG_QUEUE_PREMADE_ALLIANCE].erase(itr_teams[BG_TEAM_HORDE]);
itr_team[BG_TEAM_HORDE] = m_QueuedGroups[bracket_id][BG_QUEUE_PREMADE_HORDE].begin();
} }
arena->SetArenaMatchmakerRating(ALLIANCE, (*(itr_team[BG_TEAM_ALLIANCE]))->ArenaMatchmakerRating); arena->SetArenaMatchmakerRating(ALLIANCE, aTeam->ArenaMatchmakerRating);
arena->SetArenaMatchmakerRating(HORDE, (*(itr_team[BG_TEAM_HORDE]))->ArenaMatchmakerRating); arena->SetArenaMatchmakerRating( HORDE, hTeam->ArenaMatchmakerRating);
InviteGroupToBG(*(itr_team[BG_TEAM_ALLIANCE]), arena, ALLIANCE); InviteGroupToBG(aTeam, arena, ALLIANCE);
InviteGroupToBG(*(itr_team[BG_TEAM_HORDE]), arena, HORDE); InviteGroupToBG(hTeam, arena, HORDE);
sLog->outDebug(LOG_FILTER_BATTLEGROUND, "Starting rated arena match!"); sLog->outDebug(LOG_FILTER_BATTLEGROUND, "Starting rated arena match!");
arena->StartBattleground(); arena->StartBattleground();
} }
} }