]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blobdiff - qcsrc/server/cl_player.qc
Merge remote-tracking branch 'origin/terencehill/arena_stuff'
[xonotic/xonotic-data.pk3dir.git] / qcsrc / server / cl_player.qc
index 04ce7c0d35016166119514aaa3c99e80101638dc..e5e2d377cf4981f7d9527d1a4ca7f927caf87bec 100644 (file)
@@ -1,6 +1,5 @@
 .entity accuracy;
 .float accuracy_frags[WEP_MAXCOUNT];
-FTEQCC_YOU_SUCK_THIS_IS_NOT_UNREFERENCED(accuracy_frags);
 
 float weaponstats_buffer;
 
@@ -14,23 +13,26 @@ void WeaponStats_Init()
 
 #define WEAPONSTATS_GETINDEX(awep,abot,vwep,vbot) (((vwep) + (awep) * (WEP_LAST - WEP_FIRST + 1) - (WEP_FIRST + WEP_FIRST * (WEP_LAST - WEP_FIRST + 1))) * 4 + (abot) * 2 + (vbot))
 
-void WeaponStats_Shutdown()
+void WeaponStats_ready(entity fh, entity pass, float status)
 {
-       float i, j, ibot, jbot, idx;
-       float fh;
+       float i, j, n, ibot, jbot, idx;
        vector v;
-       string prefix;
-       if(weaponstats_buffer < 0)
-               return;
-       prefix = strcat(autocvar_hostname, "\t", GetGametype(), "_", GetMapname(), "\t");
-       if(autocvar_sv_weaponstats_file != "")
+       string prefix, s;
+       switch(status)
        {
-               fh = fopen(autocvar_sv_weaponstats_file, FILE_APPEND);
-               if(fh >= 0)
-               {
-                       fputs(fh, "#begin statsfile\n");
-                       fputs(fh, strcat("#date ", strftime(TRUE, "%a %b %e %H:%M:%S %Z %Y"), "\n"));
-                       fputs(fh, strcat("#config ", ftos(crc16(FALSE, cvar_changes)), "\n"));
+               case URL_READY_CANWRITE:
+                       // url_fopen returned, we can write
+                       prefix = strcat(autocvar_hostname, "\t", GetGametype(), "_", GetMapname(), "\t");
+                       url_fputs(fh, "#begin statsfile\n");
+                       url_fputs(fh, strcat("#date ", strftime(TRUE, "%a %b %e %H:%M:%S %Z %Y"), "\n"));
+#ifdef WATERMARK
+                       url_fputs(fh, strcat("#version ", WATERMARK(), "\n"));
+#endif
+                       url_fputs(fh, strcat("#config ", ftos(crc16(FALSE, cvar_purechanges)), "\n"));
+                       url_fputs(fh, strcat("#cvar_purechanges ", ftos(cvar_purechanges_count), "\n"));
+                       n = tokenizebyseparator(cvar_purechanges, "\n");
+                       for(i = 0; i < n; ++i)
+                               url_fputs(fh, strcat("#cvar_purechange ", argv(i), "\n"));
                        for(i = WEP_FIRST; i <= WEP_LAST; ++i) for(ibot = 0; ibot <= 1; ++ibot)
                                for(j = WEP_FIRST; j <= WEP_LAST; ++j) for(jbot = 0; jbot <= 1; ++jbot)
                                {
@@ -39,17 +41,48 @@ void WeaponStats_Shutdown()
                                        if(v != '0 0 0')
                                        {
                                                //vector is: kills hits damage
-                                               fputs(fh, sprintf("%s%d %d\t%d %d\t", prefix, i, ibot, j, jbot));
-                                               fputs(fh, sprintf("%d %d %g\n", v_x, v_y, v_z));
+                                               url_fputs(fh, sprintf("%s%d %d\t%d %d\t", prefix, i, ibot, j, jbot));
+                                               url_fputs(fh, sprintf("%d %d %g\n", v_x, v_y, v_z));
                                        }
                                }
-                       fputs(fh, "#end\n\n");
-                       fclose(fh);
+                       url_fputs(fh, "#end\n\n");
+                       url_fclose(fh, WeaponStats_ready, world);
+                       buf_del(weaponstats_buffer);
+                       weaponstats_buffer = -1;
+                       break;
+               case URL_READY_CANREAD:
+                       // url_fclose is processing, we got a response for writing the data
+                       // this must come from HTTP
+                       print("Got response from weapon stats server:\n");
+                       while((s = url_fgets(fh)))
+                               print("  ", s, "\n");
+                       print("End of response.\n");
+                       url_fclose(fh, WeaponStats_ready, world);
+                       break;
+               case URL_READY_CLOSED:
+                       // url_fclose has finished
                        print("Weapon stats written\n");
-               }
+                       break;
+               case URL_READY_ERROR:
+               default:
+                       print("Weapon stats writing failed: ", ftos(status), "\n");
+                       break;
+       }
+}
+
+void WeaponStats_Shutdown()
+{
+       if(weaponstats_buffer < 0)
+               return;
+       if(autocvar_sv_weaponstats_file != "")
+       {
+               url_fopen(autocvar_sv_weaponstats_file, FILE_APPEND, WeaponStats_ready, world);
+       }
+       else
+       {
+               buf_del(weaponstats_buffer);
+               weaponstats_buffer = -1;
        }
-       buf_del(weaponstats_buffer);
-       weaponstats_buffer = -1;
 }
 
 void WeaponStats_LogItem(float awep, float abot, float vwep, float vbot, vector item)
@@ -341,11 +374,11 @@ void PlayerCorpseDamage (entity inflictor, entity attacker, float damage, float
        if(sound_allowed(MSG_BROADCAST, attacker))
        {
                if (save > 10)
-                       sound (self, CHAN_PROJECTILE, "misc/armorimpact.wav", VOL_BASE, ATTN_NORM);
+                       sound (self, CH_SHOTS, "misc/armorimpact.wav", VOL_BASE, ATTN_NORM);
                else if (take > 30)
-                       sound (self, CHAN_PROJECTILE, "misc/bodyimpact2.wav", VOL_BASE, ATTN_NORM);
+                       sound (self, CH_SHOTS, "misc/bodyimpact2.wav", VOL_BASE, ATTN_NORM);
                else if (take > 10)
-                       sound (self, CHAN_PROJECTILE, "misc/bodyimpact1.wav", VOL_BASE, ATTN_NORM);
+                       sound (self, CH_SHOTS, "misc/bodyimpact1.wav", VOL_BASE, ATTN_NORM);
        }
 
        if (take > 50)
@@ -388,7 +421,7 @@ void PlayerDamage (entity inflictor, entity attacker, float damage, float deatht
        float valid_damage_for_weaponstats;
        float excess;
 
-       if((g_arena && numspawned < 2) || (g_ca && ca_players < required_ca_players) && !inWarmupStage)
+       if((g_arena && numspawned < 2) || (g_ca && !ca_teams_ok) && !inWarmupStage)
                return;
 
        dh = max(self.health, 0);
@@ -458,11 +491,11 @@ void PlayerDamage (entity inflictor, entity attacker, float damage, float deatht
        if(sound_allowed(MSG_BROADCAST, attacker))
        {
                if (save > 10)
-                       sound (self, CHAN_PROJECTILE, "misc/armorimpact.wav", VOL_BASE, ATTN_NORM);
+                       sound (self, CH_SHOTS, "misc/armorimpact.wav", VOL_BASE, ATTN_NORM);
                else if (take > 30)
-                       sound (self, CHAN_PROJECTILE, "misc/bodyimpact2.wav", VOL_BASE, ATTN_NORM);
+                       sound (self, CH_SHOTS, "misc/bodyimpact2.wav", VOL_BASE, ATTN_NORM);
                else if (take > 10)
-                       sound (self, CHAN_PROJECTILE, "misc/bodyimpact1.wav", VOL_BASE, ATTN_NORM); // FIXME possibly remove them?
+                       sound (self, CH_SHOTS, "misc/bodyimpact1.wav", VOL_BASE, ATTN_NORM); // FIXME possibly remove them?
        }
 
        if (take > 50)
@@ -498,15 +531,15 @@ void PlayerDamage (entity inflictor, entity attacker, float damage, float deatht
                                        // exclude pain sounds for laserjumps as long as you aren't REALLY low on health and would die of the next two
                                        {
                                                if(deathtype == DEATH_FALL)
-                                                       PlayerSound(playersound_fall, CHAN_PAIN, VOICETYPE_PLAYERSOUND);
+                                                       PlayerSound(playersound_fall, CH_PAIN, VOICETYPE_PLAYERSOUND);
                                                else if(self.health > 75) // TODO make a "gentle" version?
-                                                       PlayerSound(playersound_pain100, CHAN_PAIN, VOICETYPE_PLAYERSOUND);
+                                                       PlayerSound(playersound_pain100, CH_PAIN, VOICETYPE_PLAYERSOUND);
                                                else if(self.health > 50)
-                                                       PlayerSound(playersound_pain75, CHAN_PAIN, VOICETYPE_PLAYERSOUND);
+                                                       PlayerSound(playersound_pain75, CH_PAIN, VOICETYPE_PLAYERSOUND);
                                                else if(self.health > 25)
-                                                       PlayerSound(playersound_pain50, CHAN_PAIN, VOICETYPE_PLAYERSOUND);
+                                                       PlayerSound(playersound_pain50, CH_PAIN, VOICETYPE_PLAYERSOUND);
                                                else
-                                                       PlayerSound(playersound_pain25, CHAN_PAIN, VOICETYPE_PLAYERSOUND);
+                                                       PlayerSound(playersound_pain25, CH_PAIN, VOICETYPE_PLAYERSOUND);
                                        }
                                }
 
@@ -530,7 +563,7 @@ void PlayerDamage (entity inflictor, entity attacker, float damage, float deatht
                // escape a lava pit or similar
                //self.pushltime = 0;
        }
-       else if(attacker.classname == "player" || attacker.classname == "gib")
+       else if(attacker.classname == "player")
        {
                self.pusher = attacker;
                self.pushltime = time + autocvar_g_maxpushtime;
@@ -559,7 +592,7 @@ void PlayerDamage (entity inflictor, entity attacker, float damage, float deatht
                        awep = DEATH_WEAPONOF(deathtype);
                valid_damage_for_weaponstats = 1;
        }
-       
+
        if(valid_damage_for_weaponstats)
        {
                dh = dh - max(self.health, 0);
@@ -585,9 +618,9 @@ void PlayerDamage (entity inflictor, entity attacker, float damage, float deatht
                if(sound_allowed(MSG_BROADCAST, attacker))
                {
                        if(deathtype == DEATH_DROWN)
-                               PlayerSound(playersound_drown, CHAN_PAIN, VOICETYPE_PLAYERSOUND);
+                               PlayerSound(playersound_drown, CH_PAIN, VOICETYPE_PLAYERSOUND);
                        else
-                               PlayerSound(playersound_death, CHAN_PAIN, VOICETYPE_PLAYERSOUND);
+                               PlayerSound(playersound_death, CH_PAIN, VOICETYPE_PLAYERSOUND);
                }
 
                // get rid of kill indicator
@@ -643,7 +676,7 @@ void PlayerDamage (entity inflictor, entity attacker, float damage, float deatht
 
                if(self.flagcarried)
                {
-                       if(attacker.classname != "player" && attacker.classname != "gib")
+                       if(attacker.classname != "player")
                                DropFlag(self.flagcarried, self, attacker); // penalty for flag loss by suicide
                        else if(attacker.team == self.team)
                                DropFlag(self.flagcarried, attacker, attacker); // penalty for flag loss by suicide/teamkill
@@ -772,7 +805,7 @@ float Say(entity source, float teamsay, entity privatesay, string msgin, float f
 
        if(source.classname != "player")
                colorstr = "^0"; // black for spectators
-       else if(teams_matter)
+       else if(teamplay)
                colorstr = Team_ColorCode(source.team);
        else
                teamsay = FALSE;
@@ -1134,8 +1167,9 @@ void UpdatePlayerSounds()
        self.skinindex_for_playersound = self.skinindex;
        ClearPlayerSounds();
        LoadPlayerSounds("sound/player/default.sounds", 1);
-       if(!LoadPlayerSounds(get_model_datafilename(self.model, self.skinindex, "sounds"), 0))
-               LoadPlayerSounds(get_model_datafilename(self.model, 0, "sounds"), 0);
+       if(!autocvar_g_debug_defaultsounds)
+               if(!LoadPlayerSounds(get_model_datafilename(self.model, self.skinindex, "sounds"), 0))
+                       LoadPlayerSounds(get_model_datafilename(self.model, 0, "sounds"), 0);
 }
 
 void FakeGlobalSound(string sample, float chan, float voicetype)
@@ -1261,7 +1295,7 @@ void GlobalSound(string sample, float chan, float voicetype)
                        break;
                case VOICETYPE_TEAMRADIO:
                        FOR_EACH_REALCLIENT(msg_entity)
-                               if(!teams_matter || msg_entity.team == self.team)
+                               if(!teamplay || msg_entity.team == self.team)
                                {
                                        if(msg_entity.cvar_cl_voice_directional == 1)
                                                soundto(MSG_ONE, self, chan, sample, VOL_BASEVOICE, ATTN_MIN);
@@ -1335,9 +1369,9 @@ void VoiceMessage(string type, string msg)
        flood = Say(self, ownteam, world, msg, 1);
 
        if (flood > 0)
-               GlobalSound(self.sample, CHAN_VOICE, voicetype);
+               GlobalSound(self.sample, CH_VOICE, voicetype);
        else if (flood < 0)
-               FakeGlobalSound(self.sample, CHAN_VOICE, voicetype);
+               FakeGlobalSound(self.sample, CH_VOICE, voicetype);
 }
 
 void MoveToTeam(entity client, float team_colour, float type, float show_message)