Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- bool balanceteams(int ftr) // pro vs noobs never more
- {
- if(mastermode != MM_OPEN || totalclients < 3 ) return true;
- int tsize[2] = {0, 0}, tscore[2] = {0, 0};
- int totalscore = 0, nplayers = 0;
- int flagmult = (m_ctf ? 50 : (m_htf ? 25 : 12));
- loopv(clients) if(clients[i]->type!=ST_EMPTY)
- {
- client *c = clients[i];
- if(c->isauthed && team_isactive(c->team))
- {
- int time = servmillis - c->connectmillis + 5000;
- if ( time > gamemillis ) time = gamemillis + 5000;
- tsize[c->team]++;
- // effective score per minute, thanks to wtfthisgame for the nice idea
- // in a normal game, normal players will do 500 points in 10 minutes
- c->eff_score = c->state.points * 60 * 1000 / time + c->state.points / 6 + c->state.flagscore * flagmult;
- tscore[c->team] += c->eff_score;
- nplayers++;
- totalscore += c->state.points;
- }
- }
- int h = 0, l = 1;
- if ( tscore[1] > tscore[0] ) { h = 1; l = 0; }
- if ( 2 * tscore[h] < 3 * tscore[l] || totalscore < nplayers * 100 ) return true;
- if ( tscore[h] > 3 * tscore[l] && tscore[h] > 150 * nplayers )
- {
- // sendf(-1, 1, "ri2", SV_SERVERMODE, sendservermode(false) | AT_SHUFFLE);
- shuffleteams();
- return true;
- }
- float diffscore = tscore[h] - tscore[l];
- int besth = 0, hid = -1;
- int bestdiff = 0, bestpair[2] = {-1, -1};
- if ( tsize[h] - tsize[l] > 0 ) // the h team has more players, so we will force only one player
- {
- loopv(clients) if( clients[i]->type!=ST_EMPTY )
- {
- client *c = clients[i]; // loop for h
- // client from the h team, not forced in this game, and without the flag
- if( c->isauthed && c->team == h && !c->state.forced && clienthasflag(i) < 0 )
- {
- // do not exchange in the way that weaker team becomes the stronger or the change is less than 20% effective
- if ( 2 * c->eff_score <= diffscore && 10 * c->eff_score >= diffscore && c->eff_score > besth )
- {
- besth = c->eff_score;
- hid = i;
- }
- }
- }
- if ( hid >= 0 )
- {
- updateclientteam(hid, l, ftr);
- clients[hid]->at3_lastforce = gamemillis;
- clients[hid]->state.forced = true;
- return true;
- }
- } else { // the h score team has less or the same player number, so, lets exchange
- loopv(clients) if(clients[i]->type!=ST_EMPTY)
- {
- client *c = clients[i]; // loop for h
- if( c->isauthed && c->team == h && !c->state.forced && clienthasflag(i) < 0 )
- {
- loopvj(clients) if(clients[j]->type!=ST_EMPTY && j != i )
- {
- client *cj = clients[j]; // loop for l
- if( cj->isauthed && cj->team == l && !cj->state.forced && clienthasflag(j) < 0 )
- {
- int pairdiff = 2 * (c->eff_score - cj->eff_score);
- if ( pairdiff <= diffscore && 5 * pairdiff >= diffscore && pairdiff > bestdiff )
- {
- bestdiff = pairdiff;
- bestpair[h] = i;
- bestpair[l] = j;
- }
- }
- }
- }
- }
- if ( bestpair[h] >= 0 && bestpair[l] >= 0 )
- {
- updateclientteam(bestpair[h], l, ftr);
- updateclientteam(bestpair[l], h, ftr);
- clients[bestpair[h]]->at3_lastforce = clients[bestpair[l]]->at3_lastforce = gamemillis;
- clients[bestpair[h]]->state.forced = clients[bestpair[l]]->state.forced = true;
- return true;
- }
- }
- return false;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement