]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blobdiff - qcsrc/server/cl_client.qc
Merge branch 'terencehill/cl_forceplayercolors_2' into 'master'
[xonotic/xonotic-data.pk3dir.git] / qcsrc / server / cl_client.qc
index fddaa09cbd422b87acb0258832f1f3bdcb89aaa8..6c3e2ec0c5860c7759d95c156501781d65d16948 100644 (file)
@@ -33,7 +33,7 @@
 #include "weapons/weaponsystem.qh"
 
 #include "../common/net_notice.qh"
-#include "../common/physics.qh"
+#include "../common/physics/player.qh"
 
 #include "../common/items/all.qc"
 
@@ -304,9 +304,9 @@ void PutObserverInServer()
        setsize (self, PL_CROUCH_MIN, PL_CROUCH_MAX); // give the spectator some space between walls for MOVETYPE_FLY_WORLDONLY
        self.view_ofs = '0 0 0'; // so that your view doesn't go into the ceiling with MOVETYPE_FLY_WORLDONLY, previously "PL_VIEW_OFS"
 
-       self.weapon = 0;
+       PS(self).m_weapon = WEP_Null;
        self.weaponname = "";
-       self.switchingweapon = 0;
+       PS(self).m_switchingweapon = WEP_Null;
        self.weaponmodel = "";
        for (int slot = 0; slot < MAX_WEAPONSLOTS; ++slot)
        {
@@ -625,9 +625,9 @@ void PutClientInServer()
 
                PS(this).m_switchweapon = w_getbestweapon(this);
                this.cnt = -1; // W_LastWeapon will not complain
-               this.weapon = 0;
+               PS(this).m_weapon = WEP_Null;
                this.weaponname = "";
-               this.switchingweapon = 0;
+               PS(this).m_switchingweapon = WEP_Null;
 
                if (!warmup_stage && !this.alivetime)
                        this.alivetime = time;
@@ -987,7 +987,7 @@ void ClientPreConnect ()
        {
                GameLogEcho(sprintf(":connect:%d:%d:%s",
                        self.playerid,
-                       num_for_edict(self),
+                       etof(self),
                        ((IS_REAL_CLIENT(self)) ? self.netaddress : "bot")
                ));
        }
@@ -1122,7 +1122,7 @@ void ClientConnect ()
         PlayerStats_GameReport_AddPlayer(self);
 
        if(autocvar_sv_eventlog)
-               GameLogEcho(strcat(":join:", ftos(self.playerid), ":", ftos(num_for_edict(self)), ":", ((IS_REAL_CLIENT(self)) ? self.netaddress : "bot"), ":", self.netname));
+               GameLogEcho(strcat(":join:", ftos(self.playerid), ":", ftos(etof(self)), ":", ((IS_REAL_CLIENT(self)) ? self.netaddress : "bot"), ":", self.netname));
 
        LogTeamchange(self.playerid, self.team, 1);
 
@@ -1681,8 +1681,8 @@ void SpectateCopy(entity this, entity spectatee)
        self.pressedkeys = spectatee.pressedkeys;
        self.weapons = spectatee.weapons;
        PS(self).m_switchweapon = PS(spectatee).m_switchweapon;
-       self.switchingweapon = spectatee.switchingweapon;
-       self.weapon = spectatee.weapon;
+       PS(self).m_switchingweapon = PS(spectatee).m_switchingweapon;
+       PS(self).m_weapon = PS(spectatee).m_weapon;
        self.vortex_charge = spectatee.vortex_charge;
        self.vortex_chargepool_ammo = spectatee.vortex_chargepool_ammo;
        self.hagar_load = spectatee.hagar_load;
@@ -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;
 }
 
 /**
@@ -2396,7 +2395,7 @@ void PlayerPreThink ()
                // WEAPONTODO: THIS SHIT NEEDS TO GO EVENTUALLY
                // It cannot be predicted by the engine!
                .entity weaponentity = weaponentities[0]; // TODO: unhardcode
-               if((self.weapon == WEP_SHOCKWAVE.m_id || self.weapon == WEP_SHOTGUN.m_id) && self.(weaponentity).wframe == WFRAME_FIRE2 && time < self.(weaponentity).weapon_nextthink)
+               if((PS(self).m_weapon == WEP_SHOCKWAVE || PS(self).m_weapon == WEP_SHOTGUN) && self.(weaponentity).wframe == WFRAME_FIRE2 && time < self.(weaponentity).weapon_nextthink)
                        do_crouch = 0;
 
                if (do_crouch)
@@ -2471,14 +2470,19 @@ void PlayerPreThink ()
 
        // WEAPONTODO: Add weapon request for this
        if(!zoomstate_set)
-               SetZoomState(self.BUTTON_ZOOM || self.BUTTON_ZOOMSCRIPT || (self.BUTTON_ATCK2 && self.weapon == WEP_VORTEX.m_id) || (self.BUTTON_ATCK2 && self.weapon == WEP_RIFLE.m_id && WEP_CVAR(rifle, secondary) == 0)); // WEAPONTODO
+               SetZoomState(
+                       self.BUTTON_ZOOM
+                       || self.BUTTON_ZOOMSCRIPT
+                       || (self.BUTTON_ATCK2 && PS(self).m_weapon == WEP_VORTEX)
+                       || (self.BUTTON_ATCK2 && PS(self).m_weapon == WEP_RIFLE && WEP_CVAR(rifle, secondary) == 0)
+               ); // WEAPONTODO
 
        float oldspectatee_status;
        oldspectatee_status = self.spectatee_status;
        if(IS_SPEC(self))
-               self.spectatee_status = num_for_edict(self.enemy);
+               self.spectatee_status = etof(self.enemy);
        else if(IS_OBSERVER(self))
-               self.spectatee_status = num_for_edict(self);
+               self.spectatee_status = etof(self);
        else
                self.spectatee_status = 0;
        if(self.spectatee_status != oldspectatee_status)
@@ -2511,7 +2515,7 @@ void PlayerPreThink ()
 
        // WEAPONTODO: Move into weaponsystem somehow
        // if a player goes unarmed after holding a loaded weapon, empty his clip size and remove the crosshair ammo ring
-       if(!self.weapon)
+       if (PS(self).m_weapon == WEP_Null)
                self.clip_load = self.clip_size = 0;
 }