From: Samual Date: Mon, 7 Nov 2011 21:36:40 +0000 (-0500) Subject: Begin "shuffleteams" command -- basically it randomly builds a set of new teams,... X-Git-Tag: xonotic-v0.6.0~188^2~28^2~237 X-Git-Url: https://git.rm.cloudns.org/?a=commitdiff_plain;h=9dc5d148aa9cc28a43447c9377231d3d30f74b8b;p=xonotic%2Fxonotic-data.pk3dir.git Begin "shuffleteams" command -- basically it randomly builds a set of new teams, the idea is to make pickup matches or similar more easy to just pick teams, or even as a tool for autobalancing. --- diff --git a/qcsrc/server/gamecommand.qc b/qcsrc/server/gamecommand.qc index c3cb7847e..6385001e8 100644 --- a/qcsrc/server/gamecommand.qc +++ b/qcsrc/server/gamecommand.qc @@ -1403,6 +1403,79 @@ void GameCommand_setbots(float request, float argc) } } } +#define SHUFFLETEAMS_MAX_PLAYERS 255 +float shuffleteams_player_entno[SHUFFLETEAMS_MAX_PLAYERS]; // maximum of 255 player slots +void GameCommand_shuffleteams(float request, float argc) +{ + switch(request) + { + case GC_REQUEST_COMMAND: + { + if(teamplay) + { + entity tmp_player; + float i, random_number, team_color; + float t1, t2, t3, t4; + + // build a list of the players in a random order + FOR_EACH_PLAYER(tmp_player) + { + for(;;) + { + random_number = bound(1, floor(random() * maxclients) + 1, maxclients); + print("attempting to select number ", ftos(random_number), ". \n"); + + if(shuffleteams_player_entno[random_number]) + { + continue; // a player is already assigned to this slot + } + else + { + shuffleteams_player_entno[random_number] = num_for_edict(tmp_player); + break; + } + } + print("player ", ftos(num_for_edict(tmp_player)), " has been assigned to slot ", ftos(random_number), ". \n"); + } + + // clear all currently playing clients + //FOR_EACH_PLAYER(tmp_player) + //{ + // self = tmp_player; + // PutObserverInServer(); + //} + + // finally, from the list made earlier, re-join the players in different order. + for(i = 1; i < maxclients; ++i) + { + self = edict_num(i); + if(shuffleteams_player_entno[i]) + JoinBestTeam(self, FALSE, TRUE); + } + + print("finished\n"); + + // clear the buffer now + for (i=0; i