]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blobdiff - qcsrc/server/cl_player.qc
Fix csqcmodel display for cloned/dead players. Also clone aiming direction :)
[xonotic/xonotic-data.pk3dir.git] / qcsrc / server / cl_player.qc
index 4a5c8a00d2d4866e27f44f598ef3ba9e9942ae0b..0229d3ed5734a9aebe9f77021c79e4d249d939bb 100644 (file)
@@ -155,6 +155,7 @@ void CopyBody(float keepvelocity)
        self.teleportable = oldself.teleportable;
        self.damagedbycontents = oldself.damagedbycontents;
        self.angles = oldself.angles;
+       self.v_angle = oldself.v_angle;
        self.avelocity = oldself.avelocity;
        self.classname = "body";
        self.damageforcescale = oldself.damageforcescale;
@@ -262,21 +263,9 @@ void player_anim (void)
 
 void SpawnThrownWeapon (vector org, float w)
 {
-       if(g_pinata)
-       {
-               float j;
-               for(j = WEP_FIRST; j <= WEP_LAST; ++j)
-               {
-                       if(WEPSET_CONTAINS_EW(self, j))
-                               if(W_IsWeaponThrowable(j))
-                                       W_ThrowNewWeapon(self, j, FALSE, org, randomvec() * 175 + '0 0 325');
-               }
-       }
-       else
-       {
+       if(self.weapons & WepSet_FromWeapon(self.weapon))
                if(W_IsWeaponThrowable(self.weapon))
                        W_ThrowNewWeapon(self, self.weapon, FALSE, org, randomvec() * 125 + '0 0 200');
-       }
 }
 
 void PlayerCorpseDamage (entity inflictor, entity attacker, float damage, float deathtype, vector hitloc, vector force)
@@ -288,18 +277,18 @@ 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, autocvar_g_balance_armor_blockpercent, damage);
+       v = healtharmor_applydamage(self.armorvalue, autocvar_g_balance_armor_blockpercent, deathtype, damage);
        take = v_x;
        save = v_y;
 
        if(sound_allowed(MSG_BROADCAST, attacker))
        {
                if (save > 10)
-                       sound (self, CH_SHOTS, "misc/armorimpact.wav", VOL_BASE, ATTN_NORM);
+                       sound (self, CH_SHOTS, "misc/armorimpact.wav", VOL_BASE, ATTEN_NORM);
                else if (take > 30)
-                       sound (self, CH_SHOTS, "misc/bodyimpact2.wav", VOL_BASE, ATTN_NORM);
+                       sound (self, CH_SHOTS, "misc/bodyimpact2.wav", VOL_BASE, ATTEN_NORM);
                else if (take > 10)
-                       sound (self, CH_SHOTS, "misc/bodyimpact1.wav", VOL_BASE, ATTN_NORM);
+                       sound (self, CH_SHOTS, "misc/bodyimpact1.wav", VOL_BASE, ATTEN_NORM);
        }
 
        if (take > 50)
@@ -334,7 +323,6 @@ void PlayerCorpseDamage (entity inflictor, entity attacker, float damage, float
 }
 
 void ClientKill_Now_TeamChange();
-void freezetag_CheckWinner();
 
 void PlayerDamage (entity inflictor, entity attacker, float damage, float deathtype, vector hitloc, vector force)
 {
@@ -343,9 +331,6 @@ void PlayerDamage (entity inflictor, entity attacker, float damage, float deatht
        float valid_damage_for_weaponstats;
        float excess;
 
-       if((g_arena && numspawned < 2) || (g_ca && allowed_to_spawn) && !inWarmupStage)
-               return;
-
        dh = max(self.health, 0);
        da = max(self.armorvalue, 0);
 
@@ -369,7 +354,10 @@ void PlayerDamage (entity inflictor, entity attacker, float damage, float deatht
                ear1 += v_right * -10;
                ear2 += v_right * +10;
                d = inflictor.origin - self.origin;
-               f = (d * v_right) / vlen(d); // this is cos of angle of d and v_right!
+               if (d)
+                       f = (d * v_right) / vlen(d); // this is cos of angle of d and v_right!
+               else
+                       f = 0;  // Assum ecenter.
                force = v_right * vlen(force);
                Violence_GibSplash_At(ear1, force * -1, 2, bound(0, damage, 25) / 2 * (0.5 - 0.5 * f), self, attacker);
                Violence_GibSplash_At(ear2, force,      2, bound(0, damage, 25) / 2 * (0.5 + 0.5 * f), self, attacker);
@@ -388,7 +376,7 @@ void PlayerDamage (entity inflictor, entity attacker, float damage, float deatht
                Violence_GibSplash_At(hitloc, force, 2, bound(0, damage, 200) / 16, self, attacker);
 
 
-       v = healtharmor_applydamage(self.armorvalue, autocvar_g_balance_armor_blockpercent, damage);
+       v = healtharmor_applydamage(self.armorvalue, autocvar_g_balance_armor_blockpercent, deathtype, damage);
        take = v_x;
        save = v_y;
 
@@ -399,7 +387,7 @@ void PlayerDamage (entity inflictor, entity attacker, float damage, float deatht
                //self.pushltime = 0;
                self.istypefrag = 0;
        }
-       else if(attacker.classname == "player")
+       else if(IS_PLAYER(attacker))
        {
                self.pusher = attacker;
                self.pushltime = time + autocvar_g_maxpushtime;
@@ -419,6 +407,7 @@ void PlayerDamage (entity inflictor, entity attacker, float damage, float deatht
        frag_inflictor = inflictor;
        frag_attacker = attacker;
        frag_target = self;
+       frag_damage = damage;
        damage_take = take;
        damage_save = save;
        damage_force = force;
@@ -430,11 +419,11 @@ void PlayerDamage (entity inflictor, entity attacker, float damage, float deatht
        if(sound_allowed(MSG_BROADCAST, attacker))
        {
                if (save > 10)
-                       sound (self, CH_SHOTS, "misc/armorimpact.wav", VOL_BASE, ATTN_NORM);
+                       sound (self, CH_SHOTS, "misc/armorimpact.wav", VOL_BASE, ATTEN_NORM);
                else if (take > 30)
-                       sound (self, CH_SHOTS, "misc/bodyimpact2.wav", VOL_BASE, ATTN_NORM);
+                       sound (self, CH_SHOTS, "misc/bodyimpact2.wav", VOL_BASE, ATTEN_NORM);
                else if (take > 10)
-                       sound (self, CH_SHOTS, "misc/bodyimpact1.wav", VOL_BASE, ATTN_NORM); // FIXME possibly remove them?
+                       sound (self, CH_SHOTS, "misc/bodyimpact1.wav", VOL_BASE, ATTEN_NORM); // FIXME possibly remove them?
        }
 
        if (take > 50)
@@ -500,20 +489,17 @@ void PlayerDamage (entity inflictor, entity attacker, float damage, float deatht
        self.dmg_take = self.dmg_take + take;//max(take - 10, 0);
        self.dmg_inflictor = inflictor;
 
-       if(g_ca && self != attacker && attacker.classname == "player")
-               PlayerScore_Add(attacker, SP_SCORE, (damage - excess) * autocvar_g_ca_damage2score_multiplier);
-
        float abot, vbot, awep;
-       abot = (clienttype(attacker) == CLIENTTYPE_BOT);
-       vbot = (clienttype(self) == CLIENTTYPE_BOT);
+       abot = (IS_BOT_CLIENT(attacker));
+       vbot = (IS_BOT_CLIENT(self));
 
        valid_damage_for_weaponstats = 0;
        awep = 0;
 
-       if(vbot || clienttype(self) == CLIENTTYPE_REAL)
-       if(abot || clienttype(attacker) == CLIENTTYPE_REAL)
+       if(vbot || IS_REAL_CLIENT(self))
+       if(abot || IS_REAL_CLIENT(attacker))
        if(attacker && self != attacker)
-       if(IsDifferentTeam(self, attacker))
+       if(DIFF_TEAM(self, attacker))
        {
                if(DEATH_ISSPECIAL(deathtype))
                        awep = attacker.weapon;
@@ -568,14 +554,6 @@ void PlayerDamage (entity inflictor, entity attacker, float damage, float deatht
                        }
                }
 
-               if(!g_freezetag)
-               {
-                       // become fully visible
-                       self.alpha = default_player_alpha;
-                       // 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();
@@ -587,25 +565,19 @@ void PlayerDamage (entity inflictor, entity attacker, float damage, float deatht
        if(accuracy_isgooddamage(attacker, self))
         attacker.accuracy.(accuracy_frags[w-1]) += 1;
 
-               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;
+               frag_deathtype = deathtype;
                MUTATOR_CALLHOOK(PlayerDies);
+
                weapon_action(self.weapon, WR_PLAYERDEATH);
 
                RemoveGrapplingHook(self);
 
                Portal_ClearAllLater(self);
 
-               if(clienttype(self) == CLIENTTYPE_REAL)
+               if(IS_REAL_CLIENT(self))
                {
                        self.fixangle = TRUE;
                        //msg_entity = self;
@@ -615,19 +587,23 @@ void PlayerDamage (entity inflictor, entity attacker, float damage, float deatht
                        //WriteAngle (MSG_ONE, 80);
                }
 
-               if(defer_ClientKill_Now_TeamChange) // TODO does this work with FreezeTag?
-                       ClientKill_Now_TeamChange();
-
-               if(g_arena)
-                       Spawnqueue_Unmark(self);
+               if(defer_ClientKill_Now_TeamChange)
+                       ClientKill_Now_TeamChange(); // can turn player into spectator
 
-               if(g_freezetag)
+               // player could have been miraculously resuscitated ;)
+               // e.g. players in freezetag get frozen, they don't really die
+               if(self.health >= 1 || !IS_PLAYER(self))
                        return;
 
                // when we get here, player actually dies
-               // clear waypoints (do this AFTER FreezeTag)
+
+               // clear waypoints
                WaypointSprite_PlayerDead();
+               // throw a weapon
+               SpawnThrownWeapon (self.origin + (self.mins + self.maxs) * 0.5, self.switchweapon);
 
+               // become fully visible
+               self.alpha = default_player_alpha;
                // make the corpse upright (not tilted)
                self.angles_x = 0;
                self.angles_z = 0;
@@ -641,7 +617,7 @@ void PlayerDamage (entity inflictor, entity attacker, float damage, float deatht
                self.solid = SOLID_CORPSE;
                self.ballistics_density = autocvar_g_ballistics_density_corpse;
                // don't stick to the floor
-               self.flags &~= FL_ONGROUND;
+               self.flags &= ~FL_ONGROUND;
                // dying animation
                self.deadflag = DEAD_DYING;
                // when to allow respawn
@@ -662,10 +638,18 @@ void PlayerDamage (entity inflictor, entity attacker, float damage, float deatht
                        self.respawn_time = ceil((time + sdelay) / waves) * waves;
                else
                        self.respawn_time = time + sdelay;
+               if(autocvar_g_respawn_delay_max > sdelay)
+                       self.respawn_time_max = time + autocvar_g_respawn_delay_max;
+               else
+                       self.respawn_time_max = self.respawn_time;
                if((sdelay + waves >= 5.0) && (self.respawn_time - time > 1.75))
                        self.respawn_countdown = 10; // first number to count down from is 10
                else
                        self.respawn_countdown = -1; // do not count down
+
+               if(g_cts || autocvar_g_forced_respawn)
+                       self.respawn_flags = self.respawn_flags | RESPAWN_FORCE;
+
                self.death_time = time;
                if (random() < 0.5)
                        animdecide_setstate(self, self.anim_state | ANIMSTATE_DEAD1, TRUE);
@@ -718,7 +702,7 @@ float Say(entity source, float teamsay, entity privatesay, string msgin, float f
 
        msgin = formatmessage(msgin);
 
-       if(source.classname != "player")
+       if (!IS_PLAYER(source))
                colorstr = "^0"; // black for spectators
        else if(teamplay)
                colorstr = Team_ColorCode(source.team);
@@ -878,10 +862,10 @@ float Say(entity source, float teamsay, entity privatesay, string msgin, float f
        }
 
        if(!privatesay)
-       if(source.classname != "player")
+       if (!IS_PLAYER(source))
        {
-               if not(intermission_running)
-                       if(teamsay || (autocvar_g_chat_nospectators == 1) || (autocvar_g_chat_nospectators == 2 && !(inWarmupStage || gameover)))
+               if (!intermission_running)
+                       if(teamsay || (autocvar_g_chat_nospectators == 1) || (autocvar_g_chat_nospectators == 2 && !(warmup_stage || gameover)))
                                teamsay = -1; // spectators
        }
 
@@ -924,7 +908,7 @@ float Say(entity source, float teamsay, entity privatesay, string msgin, float f
                {
                        sprint(source, sourcemsgstr);
                        sprint(privatesay, msgstr);
-                       if not(autocvar_g_chat_tellprivacy) { dedicated_print(msgstr); } // send to server console too if "tellprivacy" is disabled
+                       if (!autocvar_g_chat_tellprivacy) { dedicated_print(msgstr); } // send to server console too if "tellprivacy" is disabled
                        if(cmsgstr != "")
                                centerprint(privatesay, cmsgstr);
                }
@@ -946,7 +930,7 @@ float Say(entity source, float teamsay, entity privatesay, string msgin, float f
                {
                        sprint(source, sourcemsgstr);
                        dedicated_print(msgstr); // send to server console too
-                       FOR_EACH_REALCLIENT(head) if(head.classname != "player")
+                       FOR_EACH_REALCLIENT(head) if (!IS_PLAYER(head))
                                if(head != source)
                                        sprint(head, msgstr);
                }
@@ -1035,7 +1019,7 @@ void PrecachePlayerSounds(string f)
        }
        fclose(fh);
 
-       if not(allvoicesamples)
+       if (!allvoicesamples)
        {
 #define _VOICEMSG(m) allvoicesamples = strcat(allvoicesamples, " ", #m);
                ALLVOICEMSGS
@@ -1119,16 +1103,16 @@ void FakeGlobalSound(string sample, float chan, float voicetype)
                        if(self.pusher)
                        {
                                msg_entity = self;
-                               if(clienttype(msg_entity) == CLIENTTYPE_REAL)
-                                       soundto(MSG_ONE, self, chan, sample, VOL_BASE, ATTN_NONE);
+                               if(IS_REAL_CLIENT(msg_entity))
+                                       soundto(MSG_ONE, self, chan, sample, VOL_BASE, ATTEN_NONE);
                        }
                        break;
                case VOICETYPE_TEAMRADIO:
                        msg_entity = self;
                        if(msg_entity.cvar_cl_voice_directional == 1)
-                               soundto(MSG_ONE, self, chan, sample, VOL_BASEVOICE, ATTN_MIN);
+                               soundto(MSG_ONE, self, chan, sample, VOL_BASEVOICE, ATTEN_MIN);
                        else
-                               soundto(MSG_ONE, self, chan, sample, VOL_BASEVOICE, ATTN_NONE);
+                               soundto(MSG_ONE, self, chan, sample, VOL_BASEVOICE, ATTEN_NONE);
                        break;
                case VOICETYPE_AUTOTAUNT:
                        if(!sv_autotaunt)
@@ -1142,13 +1126,13 @@ void FakeGlobalSound(string sample, float chan, float voicetype)
                        if (tauntrand < msg_entity.cvar_cl_autotaunt)
                        {
                                if (msg_entity.cvar_cl_voice_directional >= 1)
-                                       soundto(MSG_ONE, self, chan, sample, VOL_BASEVOICE, bound(ATTN_MIN, msg_entity.cvar_cl_voice_directional_taunt_attenuation, ATTN_MAX));
+                                       soundto(MSG_ONE, self, chan, sample, VOL_BASEVOICE, bound(ATTEN_MIN, msg_entity.cvar_cl_voice_directional_taunt_attenuation, ATTEN_MAX));
                                else
-                                       soundto(MSG_ONE, self, chan, sample, VOL_BASEVOICE, ATTN_NONE);
+                                       soundto(MSG_ONE, self, chan, sample, VOL_BASEVOICE, ATTEN_NONE);
                        }
                        break;
                case VOICETYPE_TAUNT:
-                       if(self.classname == "player")
+                       if(IS_PLAYER(self))
                                if(self.deadflag == DEAD_NO)
                                        animdecide_setaction(self, ANIMACTION_TAUNT, TRUE);
                        if(!sv_taunt)
@@ -1157,13 +1141,13 @@ void FakeGlobalSound(string sample, float chan, float voicetype)
                                break;
                        msg_entity = self;
                        if (msg_entity.cvar_cl_voice_directional >= 1)
-                               soundto(MSG_ONE, self, chan, sample, VOL_BASEVOICE, bound(ATTN_MIN, msg_entity.cvar_cl_voice_directional_taunt_attenuation, ATTN_MAX));
+                               soundto(MSG_ONE, self, chan, sample, VOL_BASEVOICE, bound(ATTEN_MIN, msg_entity.cvar_cl_voice_directional_taunt_attenuation, ATTEN_MAX));
                        else
-                               soundto(MSG_ONE, self, chan, sample, VOL_BASEVOICE, ATTN_NONE);
+                               soundto(MSG_ONE, self, chan, sample, VOL_BASEVOICE, ATTEN_NONE);
                        break;
                case VOICETYPE_PLAYERSOUND:
                        msg_entity = self;
-                       soundto(MSG_ONE, self, chan, sample, VOL_BASE, ATTN_NORM);
+                       soundto(MSG_ONE, self, chan, sample, VOL_BASE, ATTEN_NORM);
                        break;
                default:
                        backtrace("Invalid voice type!");
@@ -1192,12 +1176,12 @@ void GlobalSound(string sample, float chan, float voicetype)
                        if(self.pusher)
                        {
                                msg_entity = self.pusher;
-                               if(clienttype(msg_entity) == CLIENTTYPE_REAL)
+                               if(IS_REAL_CLIENT(msg_entity))
                                {
                                        if(msg_entity.cvar_cl_voice_directional == 1)
-                                               soundto(MSG_ONE, self, chan, sample, VOL_BASEVOICE, ATTN_MIN);
+                                               soundto(MSG_ONE, self, chan, sample, VOL_BASEVOICE, ATTEN_MIN);
                                        else
-                                               soundto(MSG_ONE, self, chan, sample, VOL_BASEVOICE, ATTN_NONE);
+                                               soundto(MSG_ONE, self, chan, sample, VOL_BASEVOICE, ATTEN_NONE);
                                }
                        }
                        break;
@@ -1205,16 +1189,16 @@ void GlobalSound(string sample, float chan, float voicetype)
                        if(self.pusher)
                        {
                                msg_entity = self.pusher;
-                               if(clienttype(msg_entity) == CLIENTTYPE_REAL)
+                               if(IS_REAL_CLIENT(msg_entity))
                                {
                                        if(msg_entity.cvar_cl_voice_directional == 1)
-                                               soundto(MSG_ONE, self, chan, sample, VOL_BASEVOICE, ATTN_MIN);
+                                               soundto(MSG_ONE, self, chan, sample, VOL_BASEVOICE, ATTEN_MIN);
                                        else
-                                               soundto(MSG_ONE, self, chan, sample, VOL_BASEVOICE, ATTN_NONE);
+                                               soundto(MSG_ONE, self, chan, sample, VOL_BASEVOICE, ATTEN_NONE);
                                }
                                msg_entity = self;
-                               if(clienttype(msg_entity) == CLIENTTYPE_REAL)
-                                       soundto(MSG_ONE, self, chan, sample, VOL_BASE, ATTN_NONE);
+                               if(IS_REAL_CLIENT(msg_entity))
+                                       soundto(MSG_ONE, self, chan, sample, VOL_BASE, ATTEN_NONE);
                        }
                        break;
                case VOICETYPE_TEAMRADIO:
@@ -1222,9 +1206,9 @@ void GlobalSound(string sample, float chan, float voicetype)
                                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);
+                                               soundto(MSG_ONE, self, chan, sample, VOL_BASEVOICE, ATTEN_MIN);
                                        else
-                                               soundto(MSG_ONE, self, chan, sample, VOL_BASEVOICE, ATTN_NONE);
+                                               soundto(MSG_ONE, self, chan, sample, VOL_BASEVOICE, ATTEN_NONE);
                                }
                        break;
                case VOICETYPE_AUTOTAUNT:
@@ -1239,13 +1223,13 @@ void GlobalSound(string sample, float chan, float voicetype)
                                if (tauntrand < msg_entity.cvar_cl_autotaunt)
                                {
                                        if (msg_entity.cvar_cl_voice_directional >= 1)
-                                               soundto(MSG_ONE, self, chan, sample, VOL_BASEVOICE, bound(ATTN_MIN, msg_entity.cvar_cl_voice_directional_taunt_attenuation, ATTN_MAX));
+                                               soundto(MSG_ONE, self, chan, sample, VOL_BASEVOICE, bound(ATTEN_MIN, msg_entity.cvar_cl_voice_directional_taunt_attenuation, ATTEN_MAX));
                                        else
-                                               soundto(MSG_ONE, self, chan, sample, VOL_BASEVOICE, ATTN_NONE);
+                                               soundto(MSG_ONE, self, chan, sample, VOL_BASEVOICE, ATTEN_NONE);
                                }
                        break;
                case VOICETYPE_TAUNT:
-                       if(self.classname == "player")
+                       if(IS_PLAYER(self))
                                if(self.deadflag == DEAD_NO)
                                        animdecide_setaction(self, ANIMACTION_TAUNT, TRUE);
                        if(!sv_taunt)
@@ -1255,13 +1239,13 @@ void GlobalSound(string sample, float chan, float voicetype)
                        FOR_EACH_REALCLIENT(msg_entity)
                        {
                                if (msg_entity.cvar_cl_voice_directional >= 1)
-                                       soundto(MSG_ONE, self, chan, sample, VOL_BASEVOICE, bound(ATTN_MIN, msg_entity.cvar_cl_voice_directional_taunt_attenuation, ATTN_MAX));
+                                       soundto(MSG_ONE, self, chan, sample, VOL_BASEVOICE, bound(ATTEN_MIN, msg_entity.cvar_cl_voice_directional_taunt_attenuation, ATTEN_MAX));
                                else
-                                       soundto(MSG_ONE, self, chan, sample, VOL_BASEVOICE, ATTN_NONE);
+                                       soundto(MSG_ONE, self, chan, sample, VOL_BASEVOICE, ATTEN_NONE);
                        }
                        break;
                case VOICETYPE_PLAYERSOUND:
-                       sound(self, chan, sample, VOL_BASE, ATTN_NORM);
+                       sound(self, chan, sample, VOL_BASE, ATTEN_NORM);
                        break;
                default:
                        backtrace("Invalid voice type!");