Commit 9e33101d authored by Mikleo's avatar Mikleo
Browse files

--

parent f68c4c0c
Pipeline #6105 passed with stages
in 16 seconds
......@@ -23,13 +23,14 @@ void OnClientPutInServer_SimpleBalance(int client)
}
// true is allow team
// false is block team
bool CheckTeamBalance(int client,int currentTeam,int clientTeam)
public Action CheckTeamBalance(int client,int currentTeam,int clientTeam)
{
// dont teambalance if it is not enabled
if(dp_simplebalance.IntValue == 0 || clientTeam < 2 || currentTeam == clientTeam)
return true;
if(dp_simplebalance.IntValue == 0 || clientTeam < 2)
return Plugin_Continue;
if(currentTeam == clientTeam)
return Plugin_Handled;
......@@ -43,31 +44,32 @@ bool CheckTeamBalance(int client,int currentTeam,int clientTeam)
if(clientTeam == 2)
{
ExecuteAutoBalance(client,3);
return false;
return Plugin_Handled;
}
else if(clientTeam == 3)
else
{
ForceTeam(client,3);
return false;
ForceTeam(client,2);
return Plugin_Handled;
}
}
else if(numplayers[0] < numplayers[1] )
{
if(clientTeam == 3)
if(clientTeam == 3 || clientTeam == 4)
{
ExecuteAutoBalance(client,2);
return false;
return Plugin_Handled;
}
else if(clientTeam == 2)
else
{
ForceTeam(client,2);
return false;
return Plugin_Handled;
}
}
}
//teams are even
float ratings[MAXPLAYERS+1];
......@@ -119,12 +121,12 @@ bool CheckTeamBalance(int client,int currentTeam,int clientTeam)
if((averagemmr[0] < averagemmr[1] && clientmmr > avgmmr) || (averagemmr[0] > averagemmr[1] && clientmmr <avgmmr))
{
ForceTeam(client,2);
return false;
return Plugin_Handled;
}
else
{
ForceTeam(client,3);
return false;
return Plugin_Handled;
}
}
......@@ -135,15 +137,9 @@ bool CheckTeamBalance(int client,int currentTeam,int clientTeam)
// if there are less players than our playerratio or in a non classic map dont autobalance here
if(playerRatio < dp_simplebalance_playerratio.FloatValue || (EU_IsClassicMap() && dp_simplebalance_nocomm.IntValue == 0))
return true;
if(!wasTeamBalanced[client] && (clientTeam == 2 || clientTeam == 3))
if(!wasTeamBalanced[client] && playerRatio > dp_simplebalance_playerratio.FloatValue && (EU_IsClassicMap() || dp_simplebalance_nocomm.IntValue != 0))
{
int t = clientTeam -2;
float diff = averagemmr[t] - averagemmr [OppTeam(t)];
......@@ -155,16 +151,17 @@ bool CheckTeamBalance(int client,int currentTeam,int clientTeam)
{
wasTeamBalanced[client] = true;
ExecuteAutoBalance(client,OppTeam(team));
return false;
return Plugin_Handled;
}
}
}
return true;
ForceTeam(client,clientTeam);
return Plugin_Handled;
}
......
......@@ -8,7 +8,7 @@
#include <empstats>
#include <updater>
#define PluginVersion "0.86"
#define PluginVersion "0.87"
#define UPDATE_URL "https://sourcemod.docs.empiresmod.com/DraftPick/dist/updater.txt"
......@@ -628,10 +628,7 @@ public Action Command_Join_Team(int client, const String:command[], args)
if(!draftEnabled)
{
if(!CheckTeamBalance(client,oldTeam,team))
return Plugin_Handled;
return Plugin_Continue;
return CheckTeamBalance(client,oldTeam,team);
}
......@@ -677,7 +674,7 @@ public Action Command_Join_Team(int client, const String:command[], args)
else
{
// increase the time for spectators
timeToWait = 6 + RoundFloat(float(numClientsNotInDraftTeam()) * 1.25);
timeToWait = 8 + RoundFloat(float(numClientsNotInDraftTeam()) * 0.75);
}
StartBatchJoin(client,timeToWait);
......@@ -888,110 +885,77 @@ void ExecuteBatchJoin()
}
int teamToChoose = 0;
int oppTeam = 0;
int chosenTeam = 0;
int numPlayers = joiningPlayers.Length;
for(int i = 0;i<numPlayers;i++)
{
if(mmrcount[0] < mmrcount[1])
{
teamToChoose = 0;
}
else if(mmrcount[1] < mmrcount[0])
{
teamToChoose = 1;
}
else
// do the player with the extreme ratings first
// the last player will be the closest to the average.
int bestClientIndex = -1;
float maxDistance = -1.0;
float avgmmr = (averagemmr[0] + averagemmr[1]) / 2;
for(int j = 0;j<joiningPlayers.Length;j++)
{
if(joiningPlayers.Length > 1)
int client = joiningPlayers.Get(j);
float distance = FloatAbs(avgmmr - ratings[client]);
if(distance > maxDistance)
{
// doesent matter here.
teamToChoose = 0;
maxDistance = distance;
bestClientIndex = j;
}
else
{
// if the teams are equal and this is the last player;
// make a guess based on the average mmr for the server.
float avgmmr = (averagemmr[0] + averagemmr[1]) / 2;
float clientmmr = ratings[joiningPlayers.Get(0)];
if((averagemmr[0] < averagemmr[1] && clientmmr > avgmmr) || (averagemmr[0] > averagemmr[1] && clientmmr <avgmmr))
{
teamToChoose = 0;
}
else
{
teamToChoose = 1;
}
}
}
oppTeam = OppBinaryTeam(teamToChoose);
int bestClient = -1;
int bestClient = joiningPlayers.Get(bestClientIndex);
if(averagemmr[teamToChoose] < averagemmr[oppTeam])
{
// get best player
float highestRating = 0.0;
for(int j = 0;j<joiningPlayers.Length;j++)
{
int client = joiningPlayers.Get(j);
if(ratings[client] > highestRating)
{
highestRating = ratings[client];
bestClient = j;
}
}
float clientmmr = ratings[bestClient];
if(mmrcount[0] + joiningPlayers.Length <= mmrcount[1])
{
chosenTeam = 0;
}
else if(mmrcount[1] + joiningPlayers.Length <= mmrcount[0])
{
chosenTeam = 1;
}
else
{
// get worst player
float lowestRating = 10000.0;
for(int j = 0;j<joiningPlayers.Length;j++)
if((averagemmr[0] < averagemmr[1] && clientmmr > avgmmr) || (averagemmr[0] > averagemmr[1] && clientmmr <avgmmr))
{
int client = joiningPlayers.Get(j);
if(ratings[client] < lowestRating)
{
lowestRating = ratings[client];
bestClient = j;
}
chosenTeam = 0;
}
else
{
chosenTeam = 1;
}
}
if(bestClient >= 0)
{
int client = joiningPlayers.Get(bestClient);
totalmmr[teamToChoose] += ratings[client];
mmrcount[teamToChoose] ++;
mmrcount[teamToChoose] ++;
averagemmr[teamToChoose] = totalmmr[teamToChoose]/mmrcount[teamToChoose];
joinTime[client] = -1;
ForceTeam(client,teamToChoose + 2);
char clientName[64];
GetClientName(client,clientName,sizeof(clientName));
joiningPlayers.Erase(bestClient);
totalmmr[chosenTeam] += ratings[bestClient];
mmrcount[chosenTeam] ++;
averagemmr[chosenTeam] = totalmmr[chosenTeam]/mmrcount[chosenTeam];
joinTime[bestClient] = -1;
ForceTeam(bestClient,chosenTeam + 2);
joiningPlayers.Erase(bestClientIndex);
}
}
}
int OppBinaryTeam(int team)
{
if(team == 0)
return 1;
else
return 0;
}
void StartJoin(int client,int time)
......@@ -2918,7 +2882,7 @@ Stage_Game_Start()
Format(mBuffer,sizeof(mBuffer),"\x04[DP] \x01 All players drafted. Vote for a commander and organize your teams!");
PrintToChatAllDelay(mBuffer,0.1);
unlockTime = GetTime() + 40;
unlockTime = GetTime() + 30;
for (int i=1; i<=MaxClients; i++)
{
......
......@@ -4,7 +4,7 @@
{
"Version"
{
"Latest" "0.86"
"Latest" "0.87"
}
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment