Core/Battlegrounds: implment even BG teams configuration

This commit is contained in:
ShinDarth
2015-10-08 14:13:28 +02:00
parent 30eaf23b6a
commit d7cb84f6cd
4 changed files with 64 additions and 25 deletions

View File

@@ -1165,48 +1165,58 @@ void Battleground::RemoveFromBGFreeSlotQueue()
// returns the number how many players can join battleground to MaxPlayersPerTeam
uint32 Battleground::GetFreeSlotsForTeam(uint32 Team) const
{
// if BG is starting ... invite anyone
if (GetStatus() == STATUS_WAIT_JOIN)
// if BG is starting and CONFIG_BATTLEGROUND_INVITATION_TYPE == BG_QUEUE_INVITATION_TYPE_NO_BALANCE, invite anyone
if (GetStatus() == STATUS_WAIT_JOIN && sWorld->getIntConfig(CONFIG_BATTLEGROUND_INVITATION_TYPE) == BG_QUEUE_INVITATION_TYPE_NO_BALANCE)
return (GetInvitedCount(Team) < GetMaxPlayersPerTeam()) ? GetMaxPlayersPerTeam() - GetInvitedCount(Team) : 0;
// if BG is already started .. do not allow to join too much players of one faction
uint32 otherTeam;
uint32 otherIn;
// if BG is already started or CONFIG_BATTLEGROUND_INVITATION_TYPE != BG_QUEUE_INVITATION_TYPE_NO_BALANCE, do not allow to join too much players of one faction
uint32 otherTeamInvitedCount;
uint32 thisTeamInvitedCount;
uint32 otherTeamPlayersCount;
uint32 thisTeamPlayersCount;
if (Team == ALLIANCE)
{
otherTeam = GetInvitedCount(HORDE);
otherIn = GetPlayersCountByTeam(HORDE);
thisTeamInvitedCount = GetInvitedCount(ALLIANCE);
otherTeamInvitedCount = GetInvitedCount(HORDE);
thisTeamPlayersCount = GetPlayersCountByTeam(ALLIANCE);
otherTeamPlayersCount = GetPlayersCountByTeam(HORDE);
}
else
{
otherTeam = GetInvitedCount(ALLIANCE);
otherIn = GetPlayersCountByTeam(ALLIANCE);
thisTeamInvitedCount = GetInvitedCount(HORDE);
otherTeamInvitedCount = GetInvitedCount(ALLIANCE);
thisTeamPlayersCount = GetPlayersCountByTeam(HORDE);
otherTeamPlayersCount = GetPlayersCountByTeam(ALLIANCE);
}
if (GetStatus() == STATUS_IN_PROGRESS)
if (GetStatus() == STATUS_IN_PROGRESS || GetStatus() == STATUS_WAIT_JOIN)
{
// difference based on ppl invited (not necessarily entered battle)
// default: allow 0
uint32 diff = 0;
// allow join one person if the sides are equal (to fill up bg to minplayersperteam)
if (otherTeam == GetInvitedCount(Team))
// allow join one person if the sides are equal (to fill up bg to minPlayerPerTeam)
if (otherTeamInvitedCount == thisTeamInvitedCount)
diff = 1;
// allow join more ppl if the other side has more players
else if (otherTeam > GetInvitedCount(Team))
diff = otherTeam - GetInvitedCount(Team);
else if (otherTeamInvitedCount > thisTeamInvitedCount)
diff = otherTeamInvitedCount - thisTeamInvitedCount;
// difference based on max players per team (don't allow inviting more)
uint32 diff2 = (GetInvitedCount(Team) < GetMaxPlayersPerTeam()) ? GetMaxPlayersPerTeam() - GetInvitedCount(Team) : 0;
uint32 diff2 = (thisTeamInvitedCount < GetMaxPlayersPerTeam()) ? GetMaxPlayersPerTeam() - thisTeamInvitedCount : 0;
// difference based on players who already entered
// default: allow 0
uint32 diff3 = 0;
// allow join one person if the sides are equal (to fill up bg minplayersperteam)
if (otherIn == GetPlayersCountByTeam(Team))
// allow join one person if the sides are equal (to fill up bg minPlayerPerTeam)
if (otherTeamPlayersCount == thisTeamPlayersCount)
diff3 = 1;
// allow join more ppl if the other side has more players
else if (otherIn > GetPlayersCountByTeam(Team))
diff3 = otherIn - GetPlayersCountByTeam(Team);
else if (otherTeamPlayersCount > thisTeamPlayersCount)
diff3 = otherTeamPlayersCount - thisTeamPlayersCount;
// or other side has less than minPlayersPerTeam
else if (GetInvitedCount(Team) <= GetMinPlayersPerTeam())
diff3 = GetMinPlayersPerTeam() - GetInvitedCount(Team) + 1;
else if (thisTeamInvitedCount <= GetMinPlayersPerTeam())
diff3 = GetMinPlayersPerTeam() - thisTeamInvitedCount + 1;
// return the minimum of the 3 differences

View File

@@ -497,24 +497,45 @@ void BattlegroundQueue::FillPlayersToBG(Battleground* bg, BattlegroundBracketId
{
int32 hordeFree = bg->GetFreeSlotsForTeam(HORDE);
int32 aliFree = bg->GetFreeSlotsForTeam(ALLIANCE);
uint32 aliCount = m_QueuedGroups[bracket_id][BG_QUEUE_NORMAL_ALLIANCE].size();
uint32 hordeCount = m_QueuedGroups[bracket_id][BG_QUEUE_NORMAL_HORDE].size();
// try to get even teams
if (sWorld->getIntConfig(CONFIG_BATTLEGROUND_INVITATION_TYPE) == BG_QUEUE_INVITATION_TYPE_EVEN)
{
int32 hordeExtra = hordeCount - aliCount;
int32 aliExtra = aliCount - hordeCount;
hordeExtra = std::max(hordeExtra, 0);
aliExtra = std::max(aliExtra, 0);
if (aliCount != hordeCount)
{
aliFree -= aliExtra;
hordeFree -= hordeExtra;
aliFree = std::max(aliFree, 0);
hordeFree = std::max(hordeFree, 0);
}
}
//iterator for iterating through bg queue
GroupsQueueType::const_iterator Ali_itr = m_QueuedGroups[bracket_id][BG_QUEUE_NORMAL_ALLIANCE].begin();
//count of groups in queue - used to stop cycles
uint32 aliCount = m_QueuedGroups[bracket_id][BG_QUEUE_NORMAL_ALLIANCE].size();
//index to queue which group is current
uint32 aliIndex = 0;
for (; aliIndex < aliCount && m_SelectionPools[TEAM_ALLIANCE].AddGroup((*Ali_itr), aliFree); aliIndex++)
++Ali_itr;
//the same thing for horde
GroupsQueueType::const_iterator Horde_itr = m_QueuedGroups[bracket_id][BG_QUEUE_NORMAL_HORDE].begin();
uint32 hordeCount = m_QueuedGroups[bracket_id][BG_QUEUE_NORMAL_HORDE].size();
uint32 hordeIndex = 0;
for (; hordeIndex < hordeCount && m_SelectionPools[TEAM_HORDE].AddGroup((*Horde_itr), hordeFree); hordeIndex++)
++Horde_itr;
//if ofc like BG queue invitation is set in config, then we are happy
if (sWorld->getIntConfig(CONFIG_BATTLEGROUND_INVITATION_TYPE) == 0)
if (sWorld->getIntConfig(CONFIG_BATTLEGROUND_INVITATION_TYPE) == BG_QUEUE_INVITATION_TYPE_NO_BALANCE)
return;
/*
@@ -649,7 +670,7 @@ bool BattlegroundQueue::CheckNormalMatch(Battleground* bg_template, Battleground
uint32 j = TEAM_ALLIANCE;
if (m_SelectionPools[TEAM_HORDE].GetPlayerCount() < m_SelectionPools[TEAM_ALLIANCE].GetPlayerCount())
j = TEAM_HORDE;
if (sWorld->getIntConfig(CONFIG_BATTLEGROUND_INVITATION_TYPE) != 0
if (sWorld->getIntConfig(CONFIG_BATTLEGROUND_INVITATION_TYPE) != BG_QUEUE_INVITATION_TYPE_NO_BALANCE
&& m_SelectionPools[TEAM_HORDE].GetPlayerCount() >= minPlayers && m_SelectionPools[TEAM_ALLIANCE].GetPlayerCount() >= minPlayers)
{
//we will try to invite more groups to team with less players indexed by j

View File

@@ -64,6 +64,13 @@ enum BattlegroundQueueGroupTypes
};
#define BG_QUEUE_GROUP_TYPES_COUNT 4
enum BattlegroundQueueInvitationType
{
BG_QUEUE_INVITATION_TYPE_NO_BALANCE = 0, // no balance: N+M vs N players
BG_QUEUE_INVITATION_TYPE_BALANCED = 1, // teams balanced: N+1 vs N players
BG_QUEUE_INVITATION_TYPE_EVEN = 2 // teams even: N vs N players
};
class Battleground;
class BattlegroundQueue
{

View File

@@ -2197,6 +2197,7 @@ Battleground.StoreStatistics.Enable = 0
# Don't bother with balance)
# 1 - (Experimental, Don't allow to invite much more players
# of one faction)
# 2 - (Experimental, Try to have even teams)
Battleground.InvitationType = 0