]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/commitdiff
Clean up nJoinAllowed a little
authorMario <mario@smbclan.net>
Wed, 23 Dec 2015 22:59:38 +0000 (08:59 +1000)
committerMario <mario@smbclan.net>
Wed, 23 Dec 2015 22:59:38 +0000 (08:59 +1000)
qcsrc/server/cl_client.qc
qcsrc/server/command/cmd.qc
qcsrc/server/defs.qh
qcsrc/server/scores.qc

index 967bc684b3d17aeaf577ebedbb047bfd1d34df3c..6c3e2ec0c5860c7759d95c156501781d65d16948 100644 (file)
@@ -1867,7 +1867,7 @@ void LeaveSpectatorMode()
 {SELFPARAM();
        if(self.caplayer)
                return;
-       if(nJoinAllowed(self))
+       if(nJoinAllowed(self, self))
        {
                if(!teamplay || autocvar_g_campaign || autocvar_g_balance_teams || (self.wasplayer && autocvar_g_changeteam_banned) || self.team_forced > 0)
                {
@@ -1901,40 +1901,39 @@ void LeaveSpectatorMode()
  * it checks whether the number of currently playing players exceeds g_maxplayers.
  * @return int number of free slots for players, 0 if none
  */
-float nJoinAllowed(entity ignore)
-{SELFPARAM();
+bool nJoinAllowed(entity this, entity ignore)
+{
        if(!ignore)
        // this is called that way when checking if anyone may be able to join (to build qcstatus)
        // so report 0 free slots if restricted
        {
                if(autocvar_g_forced_team_otherwise == "spectate")
-                       return 0;
+                       return false;
                if(autocvar_g_forced_team_otherwise == "spectator")
-                       return 0;
+                       return false;
        }
 
-       if(self.team_forced < 0)
-               return 0; // forced spectators can never join
+       if(this.team_forced < 0)
+               return false; // forced spectators can never join
 
        // TODO simplify this
-       entity e;
-       float totalClients = 0;
-       FOR_EACH_CLIENT(e)
-               if(e != ignore)
-                       totalClients += 1;
+       int totalClients = 0;
+       int currentlyPlaying = 0;
+       FOREACH_CLIENT(true, LAMBDA(
+               if(it != ignore)
+                       ++totalClients;
+               if(IS_REAL_CLIENT(it))
+               if(IS_PLAYER(it) || it.caplayer)
+                       ++currentlyPlaying;
+       ));
 
        if (!autocvar_g_maxplayers)
                return maxclients - totalClients;
 
-       float currentlyPlaying = 0;
-       FOR_EACH_REALCLIENT(e)
-               if(IS_PLAYER(e) || e.caplayer)
-                       currentlyPlaying += 1;
-
        if(currentlyPlaying < autocvar_g_maxplayers)
                return min(maxclients - totalClients, autocvar_g_maxplayers - currentlyPlaying);
 
-       return 0;
+       return false;
 }
 
 /**
index a743a618cce28d563a9dc8050ee50c847a4d6f17..4494c104db136b94ebdc2cfb5c3d4763b50601e8 100644 (file)
@@ -174,7 +174,7 @@ void ClientCommand_join(float request)
                                if (!IS_PLAYER(self) && !lockteams && !gameover)
                                {
                                        if (self.caplayer) return;
-                                       if (nJoinAllowed(self))
+                                       if (nJoinAllowed(self, self))
                                        {
                                                if (autocvar_g_campaign)   campaign_bots_may_start = 1;
                                                self.classname = STR_PLAYER;
index ecc5b3cb1b0cabfe6960bac0d273271785f549d1..6fa9b03f6f9be1e0a37e67995c271539971effd5 100644 (file)
@@ -179,7 +179,7 @@ float game_completion_ratio; // 0 at start, 1 near end
 .float alivetime; // time of being alive
 .float motd_actived_time; // used for both motd and campaign_message
 
-float nJoinAllowed(entity ignore);
+bool nJoinAllowed(entity this, entity ignore);
 
 .float spawnshieldtime;
 .float item_spawnshieldtime;
index e29d1723ba0aaa24abfaa124be7504695f80db9c..1b20101d990d5b7a650b7a04d24e7490a5c63c31 100644 (file)
@@ -409,7 +409,7 @@ void WinningConditionHelper()
        s = GetGametype();
        s = strcat(s, ":", autocvar_g_xonoticversion);
        s = strcat(s, ":P", ftos(cvar_purechanges_count));
-       s = strcat(s, ":S", ftos(nJoinAllowed(world)));
+       s = strcat(s, ":S", ftos(nJoinAllowed(self, world)));
        s = strcat(s, ":F", ftos(serverflags));
        s = strcat(s, ":M", modname);
        s = strcat(s, "::", GetPlayerScoreString(world, (fullstatus ? 1 : 2)));