]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blobdiff - qcsrc/server/cl_client.qc
Merge branch 'master' into mirceakitsune/universal_reload_system
[xonotic/xonotic-data.pk3dir.git] / qcsrc / server / cl_client.qc
index 475771fd3a23e86c174b5a2592a0122b0babe8f8..c5312469a892864b6dc231f92fc76831a4813da9 100644 (file)
@@ -2,15 +2,8 @@ void race_send_recordtime(float msg);
 void race_SendRankings(float pos, float prevpos, float del, float msg);
 
 void send_CSQC_teamnagger() {
-       WriteByte(0, SVC_TEMPENTITY);
-       WriteByte(0, TE_CSQC_TEAMNAGGER);
-}
-
-void send_CSQC_cr_maxbullets(entity e) {
-       msg_entity = e;
-       WriteByte(MSG_ONE, SVC_TEMPENTITY);
-       WriteByte(MSG_ONE, TE_CSQC_CR_MAXBULLETS);
-       WriteByte(MSG_ONE, autocvar_g_balance_campingrifle_magazinecapacity);
+       WriteByte(MSG_BROADCAST, SVC_TEMPENTITY);
+       WriteByte(MSG_BROADCAST, TE_CSQC_TEAMNAGGER);
 }
 
 void Announce(string snd) {
@@ -724,15 +717,6 @@ void PutObserverInServer (void)
                self.frags = FRAGS_SPECTATOR;
 }
 
-float RestrictSkin(float s)
-{
-       if(!teams_matter)
-               return s;
-       if(s == 6)
-               return 6;
-       return mod(s, 3);
-}
-
 void FixPlayermodel()
 {
        local string defaultmodel;
@@ -794,7 +778,7 @@ void FixPlayermodel()
                }
 
                oldskin = self.skinindex;
-               self.skinindex = RestrictSkin(stof(self.playerskin));
+               self.skinindex = stof(self.playerskin);
        }
 
        if(chmdl || oldskin != self.skinindex)
@@ -1066,8 +1050,16 @@ void PutClientInServer (void)
 
                // reset fields the weapons may use
                for (j = WEP_FIRST; j <= WEP_LAST; ++j)
+               {
                        weapon_action(j, WR_RESETPLAYER);
 
+                       // all weapons must be fully loaded when we spawn
+                       entity e;
+                       e = get_weaponinfo(j);
+                       if(e.spawnflags & WEP_FLAG_RELOADABLE) // prevent accessing undefined cvars
+                               self.weapon_load[j] = cvar(strcat("g_balance_", e.netname, "_reload_ammo"));
+               }
+
                oldself = self;
                self = spot;
                        activator = oldself;
@@ -1121,8 +1113,9 @@ float ClientInit_SendEntity(entity to, float sf)
        WriteCoord(MSG_ENTITY, self.ebouncefactor); // g_balance_grenadelauncher_bouncefactor
        WriteCoord(MSG_ENTITY, self.ebouncestop); // g_balance_grenadelauncher_bouncestop
        WriteByte(MSG_ENTITY, autocvar_g_balance_nex_secondary); // client has to know if it should zoom or not
-       WriteByte(MSG_ENTITY, autocvar_g_balance_campingrifle_secondary); // client has to know if it should zoom or not
+       WriteByte(MSG_ENTITY, autocvar_g_balance_sniperrifle_secondary); // client has to know if it should zoom or not
        WriteByte(MSG_ENTITY, serverflags); // client has to know if it should zoom or not
+       WriteCoord(MSG_ENTITY, autocvar_g_trueaim_minrange);
        return TRUE;
 }
 
@@ -1343,7 +1336,7 @@ void ClientKill_TeamChange (float targetteam) // 0 = don't change, -1 = auto, -2
                        self.killindicator.nextthink = time + (self.lip) * 0.05;
                        self.killindicator.cnt = ceil(killtime);
                        self.killindicator.count = bound(0, ceil(killtime), 10);
-                       sprint(self, strcat("^1You'll be dead in ", ftos(self.killindicator.cnt), " seconds\n"));
+                       //sprint(self, strcat("^1You'll be dead in ", ftos(self.killindicator.cnt), " seconds\n"));
 
                        for(e = world; (e = find(e, classname, "body")) != world; )
                        {
@@ -1380,7 +1373,7 @@ void ClientKill (void)
        {
                // do nothing
        }
-    else if(g_freezetag && self.freezetag_frozen == 1)
+    else if(self.freezetag_frozen)
     {
         // do nothing
     }
@@ -1750,8 +1743,6 @@ void ClientConnect (void)
        else if(autocvar_sv_teamnagger && !(autocvar_bot_vs_human && (c3==-1 && c4==-1)) && !g_ca) // teamnagger is currently bad for ca
                send_CSQC_teamnagger();
 
-       send_CSQC_cr_maxbullets(self);
-
        CheatInitClient();
 
        PlayerStats_AddPlayer(self);
@@ -2057,7 +2048,7 @@ void player_powerups (void)
                self.modelflags &~= MF_ROCKET;
        }
 
-       self.effects &~= (EF_RED | EF_BLUE | EF_ADDITIVE | EF_FULLBRIGHT | EF_FLAME | EF_NODEPTHTEST);
+       self.effects &~= (EF_DIMLIGHT | EF_RED | EF_BLUE | EF_ADDITIVE | EF_FULLBRIGHT | EF_FLAME | EF_NODEPTHTEST);
 
        if(!self.modelindex || self.deadflag) // don't apply the flags if the player is gibbed
                return;
@@ -2355,11 +2346,14 @@ void SpectateCopy(entity spectatee) {
        self.ammo_nails = spectatee.ammo_nails;
        self.ammo_rockets = spectatee.ammo_rockets;
        self.ammo_fuel = spectatee.ammo_fuel;
+       self.clip_load = spectatee.clip_load;
+       self.clip_size = spectatee.clip_size;
        self.effects = spectatee.effects & EFMASK_CHEAP; // eat performance
        self.health = spectatee.health;
        self.impulse = 0;
        self.items = spectatee.items;
        self.last_pickup = spectatee.last_pickup;
+       self.hit_time = spectatee.hit_time;
        self.metertime = spectatee.metertime;
        self.strength_finished = spectatee.strength_finished;
        self.invincible_finished = spectatee.invincible_finished;
@@ -2452,7 +2446,7 @@ void ShowRespawnCountdown()
 
 void LeaveSpectatorMode()
 {
-       if(isJoinAllowed()) {
+       if(nJoinAllowed(1)) {
                if(!teams_matter || autocvar_g_campaign || autocvar_g_balance_teams || (self.wasplayer && autocvar_g_changeteam_banned) || self.team_forced > 0) {
                        self.classname = "player";
 
@@ -2489,25 +2483,30 @@ void LeaveSpectatorMode()
  * Determines whether the player is allowed to join. This depends on cvar
  * g_maxplayers, if it isn't used this function always return TRUE, otherwise
  * it checks whether the number of currently playing players exceeds g_maxplayers.
- * @return bool TRUE if the player is allowed to join, false otherwise
+ * @return int number of free slots for players, 0 if none
  */
-float isJoinAllowed() {
+float nJoinAllowed(float includeMe) {
        if(self.team_forced < 0)
                return FALSE; // forced spectators can never join
 
+       // TODO simplify this
+       local entity e;
+
+       local float totalClients;
+       FOR_EACH_CLIENT(e)
+               totalClients += 1;
+
        if (!autocvar_g_maxplayers)
-               return TRUE;
+               return maxclients - totalClients + includeMe;
 
-       local entity e;
        local float currentlyPlaying;
-       FOR_EACH_REALPLAYER(e) {
-               if(e.classname == "player")
-                       currentlyPlaying += 1;
-       }
+       FOR_EACH_REALPLAYER(e)
+               currentlyPlaying += 1;
+
        if(currentlyPlaying < autocvar_g_maxplayers)
-               return TRUE;
+               return min(maxclients - totalClients + includeMe, autocvar_g_maxplayers - currentlyPlaying);
 
-       return FALSE;
+       return 0;
 }
 
 /**
@@ -2910,7 +2909,7 @@ void PlayerPreThink (void)
        }
 
        if(!zoomstate_set)
-               SetZoomState(self.BUTTON_ZOOM || (self.BUTTON_ATCK2 && self.weapon == WEP_NEX) || (self.BUTTON_ATCK2 && self.weapon == WEP_CAMPINGRIFLE && autocvar_g_balance_campingrifle_secondary == 0));
+               SetZoomState(self.BUTTON_ZOOM || (self.BUTTON_ATCK2 && self.weapon == WEP_NEX) || (self.BUTTON_ATCK2 && self.weapon == WEP_SNIPERRIFLE && autocvar_g_balance_sniperrifle_secondary == 0));
 
        float oldspectatee_status;
        oldspectatee_status = self.spectatee_status;
@@ -2951,6 +2950,10 @@ void PlayerPreThink (void)
        }
 
        target_voicescript_next(self);
+
+       // if a player goes unarmed after holding a loaded weapon, empty his clip size and remove the crosshair ammo ring
+       if(!self.weapon)
+               self.clip_load = self.clip_size = 0;
 }
 
 float isInvisibleString(string s)
@@ -3104,7 +3107,7 @@ void PlayerPostThink (void)
 
        playerdemo_write();
 
-       if((g_cts || g_race) && self.cvar_cl_allow_uid2name == 1)
+       if((g_cts || g_race) && self.cvar_cl_allow_uidtracking == 1 && self.cvar_cl_allow_uid2name == 1)
        {
                if(!self.stored_netname)
                        self.stored_netname = strzone(uid2name(self.crypto_idfp));