| 2180 | vector<int> shuffle; |
| 2181 | |
| 2182 | void shuffleteams(int ftr = FTR_AUTOTEAM) |
| 2183 | { |
| 2184 | int team; // top ranked player will stay on same team |
| 2185 | int sum = calcscores(); |
| 2186 | |
| 2187 | // 20220109 only try skill based if each player has more than 200 on average. competitive players against each other currently have ~=1000. |
| 2188 | if(sum==0) |
| 2189 | { |
| 2190 | sendservmsg("using randomness to shuffle teams"); |
| 2191 | // random |
| 2192 | int teamsize[2] = {0, 0}; |
| 2193 | int half = numplayers()/2; |
| 2194 | int lastrun = 9; // try to avoid alternating teams based on clientnum |
| 2195 | vector<int> done; |
| 2196 | loopv(clients){ |
| 2197 | done.add(!(clients[i]->type!=ST_EMPTY && clients[i]->isonrightmap && !team_isspect(clients[i]->team))); // only shuffle active players - team_isactive() does not include TEAM_ANYACTIVE |
| 2198 | } |
| 2199 | loopk(lastrun+1) |
| 2200 | { |
| 2201 | loopv(clients) if(!done[i]) |
| 2202 | { |
| 2203 | if(k==lastrun || rnd(lastrun+1)==lastrun) |
| 2204 | { |
| 2205 | done[i] = true; |
| 2206 | team = rnd(2); |
| 2207 | if(teamsize[team]>=half) team = team_opposite(team); |
| 2208 | updateclientteam(i, team, ftr); |
| 2209 | teamsize[team]++; |
| 2210 | } |
| 2211 | } |
| 2212 | } |
| 2213 | } |
| 2214 | else |
| 2215 | { |
| 2216 | defformatstring(skillused)("using %s skill data to shuffle teams", sum<0?"match":"vita"); sendservmsg(skillused); |
| 2217 | // skill based |
| 2218 | shuffle.shrink(0); |
| 2219 | loopv(clients) if(clients[i]->type!=ST_EMPTY && clients[i]->isonrightmap && !team_isspect(clients[i]->team)) |
| 2220 | { |
| 2221 | shuffle.add(i); |
| 2222 | }else{ |
| 2223 | clients[i]->at3_score = 0; |
| 2224 | } |
| 2225 | shuffle.sort(cmpscore); |
| 2226 | team = !clients[shuffle[0]]->team; // top player will stay on same team |
| 2227 | int weakest2weakest = -1 + ((shuffle.length()%2) ? shuffle.length(): 0); |
| 2228 | loopi(shuffle.length()) |
| 2229 | { |
| 2230 | if(i!=weakest2weakest) team = !team; // weakest player will be on "weaker" team if uneven player count |
| 2231 | updateclientteam(shuffle[i], team, ftr); |
| 2232 | } |
| 2233 | } |
| 2234 | |
| 2235 | if(m_ctf || m_htf) |
| 2236 | { |
| 2237 | ctfreset(); |
| 2238 | sendflaginfo(); |
| 2239 | } |
no test coverage detected