]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blobdiff - qcsrc/server/cl_player.qc
Merge branch 'master' of git://git.xonotic.org/xonotic/xonotic-data.pk3dir
[xonotic/xonotic-data.pk3dir.git] / qcsrc / server / cl_player.qc
index a2943a76053e61e6e873e951594bfa7bd1898feb..342cbbc3d69e4a8e6e9a011c246e14d892f24a09 100644 (file)
@@ -2,7 +2,7 @@ float weaponstats_buffer;
 
 void WeaponStats_Init()
 {
-       if(cvar_string("sv_weaponstats_killfile") != "" || cvar_string("sv_weaponstats_damagefile") != "")
+       if(autocvar_sv_weaponstats_killfile != "" || autocvar_sv_weaponstats_damagefile != "")
                weaponstats_buffer = buf_create();
        else
                weaponstats_buffer = -1;
@@ -17,10 +17,10 @@ void WeaponStats_Shutdown()
        string prefix;
        if(weaponstats_buffer < 0)
                return;
-       prefix = strcat(cvar_string("hostname"), "\t", GetGametype(), "_", GetMapname(), "\t");
-       if(cvar_string("sv_weaponstats_killfile") != "")
+       prefix = strcat(autocvar_hostname, "\t", GetGametype(), "_", GetMapname(), "\t");
+       if(autocvar_sv_weaponstats_killfile != "")
        {
-               fh = fopen(cvar_string("sv_weaponstats_killfile"), FILE_APPEND);
+               fh = fopen(autocvar_sv_weaponstats_killfile, FILE_APPEND);
                if(fh >= 0)
                {
                        fputs(fh, "#begin killfile\n");
@@ -39,9 +39,9 @@ void WeaponStats_Shutdown()
                        print("Weapon kill stats written\n");
                }
        }
-       if(cvar_string("sv_weaponstats_damagefile") != "")
+       if(autocvar_sv_weaponstats_damagefile != "")
        {
-               fh = fopen(cvar_string("sv_weaponstats_damagefile"), FILE_APPEND);
+               fh = fopen(autocvar_sv_weaponstats_damagefile, FILE_APPEND);
                if(fh >= 0)
                {
                        fputs(fh, "#begin damagefile\n");
@@ -168,7 +168,7 @@ void CopyBody(float keepvelocity)
 float player_getspecies()
 {
        float s;
-       get_model_parameters(self.playermodel, self.skinindex);
+       get_model_parameters(self.model, self.skinindex);
        s = get_model_parameters_species;
        get_model_parameters(string_null, 0);
        if(s < 0)
@@ -341,7 +341,7 @@ void PlayerCorpseDamage (entity inflictor, entity attacker, float damage, float
        // damage resistance (ignore most of the damage from a bullet or similar)
        damage = max(damage - 5, 1);
 
-       v = healtharmor_applydamage(self.armorvalue, cvar("g_balance_armor_blockpercent"), damage);
+       v = healtharmor_applydamage(self.armorvalue, autocvar_g_balance_armor_blockpercent, damage);
        take = v_x;
        save = v_y;
 
@@ -365,7 +365,7 @@ void PlayerCorpseDamage (entity inflictor, entity attacker, float damage, float
                self.armorvalue = self.armorvalue - save;
                self.health = self.health - take;
                // pause regeneration for 5 seconds
-               self.pauseregen_finished = max(self.pauseregen_finished, time + cvar("g_balance_pause_health_regen"));
+               self.pauseregen_finished = max(self.pauseregen_finished, time + autocvar_g_balance_pause_health_regen);
        }
        self.dmg_save = self.dmg_save + save;//max(save - 10, 0);
        self.dmg_take = self.dmg_take + take;//max(take - 10, 0);
@@ -386,6 +386,8 @@ void PlayerCorpseDamage (entity inflictor, entity attacker, float damage, float
 }
 
 void ClientKill_Now_TeamChange();
+void freezetag_CheckWinner();
+void freezetag_Unfreeze();
 
 void PlayerDamage (entity inflictor, entity attacker, float damage, float deathtype, vector hitloc, vector force)
 {
@@ -439,7 +441,7 @@ void PlayerDamage (entity inflictor, entity attacker, float damage, float deatht
 
        if (!g_minstagib)
        {
-               v = healtharmor_applydamage(self.armorvalue, cvar("g_balance_armor_blockpercent"), damage);
+               v = healtharmor_applydamage(self.armorvalue, autocvar_g_balance_armor_blockpercent, damage);
                take = v_x;
                save = v_y;
        }
@@ -455,7 +457,7 @@ void PlayerDamage (entity inflictor, entity attacker, float damage, float deatht
        damage_take = take;
        damage_save = save;
        damage_force = force;
-       MUTATOR_CALLHOOK(PlayerDamage);
+       MUTATOR_CALLHOOK(PlayerDamage_SplitHealthArmor);
        take = bound(0, damage_take, self.health);
        save = bound(0, damage_save, self.armorvalue);
 
@@ -481,7 +483,7 @@ void PlayerDamage (entity inflictor, entity attacker, float damage, float deatht
                        self.armorvalue = self.armorvalue - save;
                        self.health = self.health - take;
                        // pause regeneration for 5 seconds
-                       self.pauseregen_finished = max(self.pauseregen_finished, time + cvar("g_balance_pause_health_regen"));
+                       self.pauseregen_finished = max(self.pauseregen_finished, time + autocvar_g_balance_pause_health_regen);
 
                        if (time > self.pain_finished)          //Don't switch pain sequences like crazy
                        {
@@ -497,7 +499,7 @@ void PlayerDamage (entity inflictor, entity attacker, float damage, float deatht
                                        }
 
                                        if(sound_allowed(MSG_BROADCAST, attacker))
-                                       if(!DEATH_ISWEAPON(deathtype, WEP_LASER) || attacker != self || self.health < 2 * cvar("g_balance_laser_primary_damage") * cvar("g_balance_selfdamagepercent") + 1)
+                                       if(!DEATH_ISWEAPON(deathtype, WEP_LASER) || attacker != self || self.health < 2 * autocvar_g_balance_laser_primary_damage * autocvar_g_balance_selfdamagepercent + 1)
                                        if(self.health > 1)
                                        // exclude pain sounds for laserjumps as long as you aren't REALLY low on health and would die of the next two
                                        {
@@ -537,7 +539,7 @@ void PlayerDamage (entity inflictor, entity attacker, float damage, float deatht
        else if(attacker.classname == "player" || attacker.classname == "gib")
        {
                self.pusher = attacker;
-               self.pushltime = time + cvar("g_maxpushtime");
+               self.pushltime = time + autocvar_g_maxpushtime;
        }
        else if(time < self.pushltime)
        {
@@ -567,6 +569,12 @@ void PlayerDamage (entity inflictor, entity attacker, float damage, float deatht
                float defer_ClientKill_Now_TeamChange;
                defer_ClientKill_Now_TeamChange = FALSE;
 
+               if(self.alivetime)
+               {
+                       PlayerStats_Event(self, PLAYERSTATS_ALIVETIME, time - self.alivetime);
+                       self.alivetime = 0;
+               }
+
                if(valid_damage_for_weaponstats)
                        WeaponStats_LogKill(DEATH_WEAPONOF(deathtype), self.weapon);
 
@@ -595,22 +603,37 @@ void PlayerDamage (entity inflictor, entity attacker, float damage, float deatht
                        }
                }
 
-               // become fully visible
-               self.alpha = 1;
-               // clear selected player display
-               ClearSelectedPlayer();
-               // throw a weapon
-               SpawnThrownWeapon (self.origin + (self.mins + self.maxs) * 0.5, self.switchweapon);
+               if(!g_freezetag)
+               {
+                       // become fully visible
+                       self.alpha = 1;
+                       // clear selected player display
+                       ClearSelectedPlayer();
+                       // throw a weapon
+                       SpawnThrownWeapon (self.origin + (self.mins + self.maxs) * 0.5, self.switchweapon);
+               }
+
                // print an obituary message
                Obituary (attacker, inflictor, self, deathtype);
                race_PreDie();
                DropAllRunes(self);
 
+               if(deathtype == DEATH_HURTTRIGGER && g_freezetag)
+               {
+                       PutClientInServer();
+                       count_alive_players(); // re-count players
+                       freezetag_CheckWinner();
+                       return;
+               }
+
                frag_attacker = attacker;
                frag_inflictor = inflictor;
                frag_target = self;
                MUTATOR_CALLHOOK(PlayerDies);
 
+               if(g_freezetag)
+            return;
+
                if(self.flagcarried)
                {
                        if(attacker.classname != "player" && attacker.classname != "gib")
@@ -620,7 +643,7 @@ void PlayerDamage (entity inflictor, entity attacker, float damage, float deatht
                        else
                                DropFlag(self.flagcarried, world, attacker);
                }
-               if(self.ballcarried)
+               if(self.ballcarried && g_nexball)
                        DropBall(self.ballcarried, self.origin, self.velocity);
                Portal_ClearAllLater(self);
                // clear waypoints
@@ -636,7 +659,7 @@ void PlayerDamage (entity inflictor, entity attacker, float damage, float deatht
                self.movetype = MOVETYPE_TOSS;
                // shootable corpse
                self.solid = SOLID_CORPSE;
-               self.ballistics_density = cvar("g_ballistics_density_corpse");
+               self.ballistics_density = autocvar_g_ballistics_density_corpse;
                // don't stick to the floor
                self.flags &~= FL_ONGROUND;
                // dying animation
@@ -646,10 +669,15 @@ void PlayerDamage (entity inflictor, entity attacker, float damage, float deatht
                waves = 0;
                sdelay = cvar(strcat("g_", GetGametype(), "_respawn_delay"));
                if(!sdelay)
-                       sdelay = cvar("g_respawn_delay");
+        {
+            if(g_cts)
+                sdelay = 0; // no respawn delay in CTS
+            else
+                sdelay = autocvar_g_respawn_delay;
+        }
                waves = cvar(strcat("g_", GetGametype(), "_respawn_waves"));
                if(!waves)
-                       waves = cvar("g_respawn_waves");
+                       waves = autocvar_g_respawn_waves;
                if(waves)
                        self.death_time = ceil((time + sdelay) / waves) * waves;
                else
@@ -691,7 +719,7 @@ void PlayerDamage (entity inflictor, entity attacker, float damage, float deatht
                if(defer_ClientKill_Now_TeamChange)
                        ClientKill_Now_TeamChange();
 
-               if(sv_gentle > 0 || cvar("ekg")) {
+               if(sv_gentle > 0 || autocvar_ekg) {
                        // remove corpse
                        PlayerCorpseDamage (inflictor, attacker, 100.0, deathtype, hitloc, force);
                }
@@ -764,7 +792,7 @@ void UpdateSelectedPlayer()
        selected = world;
        selected_score = 0.95; // 18 degrees
 
-       if(!cvar("sv_allow_shownames"))
+       if(!autocvar_sv_allow_shownames)
                return;
 
        if(clienttype(self) != CLIENTTYPE_REAL)
@@ -900,7 +928,7 @@ float Say(entity source, float teamsay, entity privatesay, string msgin, float f
        }
        */
 
-       if(cvar("g_chat_teamcolors"))
+       if(autocvar_g_chat_teamcolors)
                namestr = playername(source);
        else
                namestr = source.netname;
@@ -913,7 +941,7 @@ float Say(entity source, float teamsay, entity privatesay, string msgin, float f
                        privatemsgprefixlen = strlen(msgstr);
                        msgstr = strcat(msgstr, msgin);
                        cmsgstr = strcat(colorstr, "^3", namestr, "^3 tells you:\n^7", msgin);
-                       if(cvar("g_chat_teamcolors"))
+                       if(autocvar_g_chat_teamcolors)
                                privatemsgprefix = strcat("\{1}\{13}* ^3You tell ", playername(privatesay), ": ^7");
                        else
                                privatemsgprefix = strcat("\{1}\{13}* ^3You tell ", privatesay.netname, ": ^7");
@@ -948,23 +976,23 @@ float Say(entity source, float teamsay, entity privatesay, string msgin, float f
                float lines;
                if(privatesay)
                {
-                       flood_spl = cvar("g_chat_flood_spl_tell");
-                       flood_burst = cvar("g_chat_flood_burst_tell");
-                       flood_lmax = cvar("g_chat_flood_lmax_tell");
+                       flood_spl = autocvar_g_chat_flood_spl_tell;
+                       flood_burst = autocvar_g_chat_flood_burst_tell;
+                       flood_lmax = autocvar_g_chat_flood_lmax_tell;
                        flood_field = floodcontrol_chattell;
                }
                else if(teamsay)
                {
-                       flood_spl = cvar("g_chat_flood_spl_team");
-                       flood_burst = cvar("g_chat_flood_burst_team");
-                       flood_lmax = cvar("g_chat_flood_lmax_team");
+                       flood_spl = autocvar_g_chat_flood_spl_team;
+                       flood_burst = autocvar_g_chat_flood_burst_team;
+                       flood_lmax = autocvar_g_chat_flood_lmax_team;
                        flood_field = floodcontrol_chatteam;
                }
                else
                {
-                       flood_spl = cvar("g_chat_flood_spl");
-                       flood_burst = cvar("g_chat_flood_burst");
-                       flood_lmax = cvar("g_chat_flood_lmax");
+                       flood_spl = autocvar_g_chat_flood_spl;
+                       flood_burst = autocvar_g_chat_flood_burst;
+                       flood_lmax = autocvar_g_chat_flood_lmax;
                        flood_field = floodcontrol_chat;
                }
                flood_burst = max(0, flood_burst - 1);
@@ -1013,7 +1041,7 @@ float Say(entity source, float teamsay, entity privatesay, string msgin, float f
 
        if(flood == 2) // cannot happen for empty msgstr
        {
-               if(cvar("g_chat_flood_notify_flooder"))
+               if(autocvar_g_chat_flood_notify_flooder)
                {
                        sourcemsgstr = strcat(msgstr, "\n^3FLOOD CONTROL: ^7message too long, trimmed\n");
                        sourcecmsgstr = "";
@@ -1034,7 +1062,7 @@ float Say(entity source, float teamsay, entity privatesay, string msgin, float f
        if(!privatesay)
        if(source.classname != "player")
        {
-               if(teamsay || (cvar("g_chat_nospectators") == 1) || (cvar("g_chat_nospectators") == 2 && !inWarmupStage))
+               if(teamsay || (autocvar_g_chat_nospectators == 1) || (autocvar_g_chat_nospectators == 2 && !inWarmupStage))
                        teamsay = -1; // spectators
        }
 
@@ -1052,7 +1080,7 @@ float Say(entity source, float teamsay, entity privatesay, string msgin, float f
        }
        else if(flood == 1)
        {
-               if(cvar("g_chat_flood_notify_flooder"))
+               if(autocvar_g_chat_flood_notify_flooder)
                {
                        sprint(source, strcat("^3FLOOD CONTROL: ^7wait ^1", ftos(source.flood_field - time), "^3 seconds\n"));
                        ret = 0;
@@ -1124,12 +1152,9 @@ float GetVoiceMessageVoiceType(string type)
 }
 
 string allvoicesamples;
-float GetPlayerSoundSampleField_notFound;
-float GetPlayerSoundSampleField_fixed;
 .string GetVoiceMessageSampleField(string type)
 {
        GetPlayerSoundSampleField_notFound = 0;
-       GetPlayerSoundSampleField_fixed = 0;
        switch(type)
        {
 #define _VOICEMSG(m) case #m: return playersound_##m;
@@ -1143,7 +1168,6 @@ float GetPlayerSoundSampleField_fixed;
 .string GetPlayerSoundSampleField(string type)
 {
        GetPlayerSoundSampleField_notFound = 0;
-       GetPlayerSoundSampleField_fixed = 0;
        switch(type)
        {
 #define _VOICEMSG(m) case #m: return playersound_##m;
@@ -1205,7 +1229,7 @@ void ClearPlayerSounds()
 #undef _VOICEMSG
 }
 
-void LoadPlayerSounds(string f, float first)
+float LoadPlayerSounds(string f, float first)
 {
        float fh;
        string s;
@@ -1214,7 +1238,7 @@ void LoadPlayerSounds(string f, float first)
        if(fh < 0)
        {
                dprint("Player sound file not found: ", f, "\n");
-               return;
+               return 0;
        }
        while((s = fgets(fh)))
        {
@@ -1225,14 +1249,12 @@ void LoadPlayerSounds(string f, float first)
                        field = GetVoiceMessageSampleField(argv(0));
                if(GetPlayerSoundSampleField_notFound)
                        continue;
-               if(GetPlayerSoundSampleField_fixed)
-                       if not(first)
-                               continue;
                if(self.field)
                        strunzone(self.field);
                self.field = strzone(strcat(argv(1), " ", argv(2)));
        }
        fclose(fh);
+       return 1;
 }
 
 .float modelindex_for_playersound;
@@ -1246,7 +1268,8 @@ void UpdatePlayerSounds()
        self.skinindex_for_playersound = self.skinindex;
        ClearPlayerSounds();
        LoadPlayerSounds("sound/player/default.sounds", 1);
-       LoadPlayerSounds(get_model_datafilename(self.playermodel, self.skinindex, "sounds"), 0);
+       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)