]> git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blobdiff - qcsrc/server/cl_player.qc
Merge branch 'master' into Mario/classname_checks
[xonotic/xonotic-data.pk3dir.git] / qcsrc / server / cl_player.qc
index 9f7e44887e8f1a6af50a26b7b0cf115374643eca..aa6258468b05a78ab157949a3cd0049c96422ba4 100644 (file)
@@ -26,7 +26,7 @@ void WeaponStats_ready(entity fh, entity pass, float status)
                        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"));
+                       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"));
@@ -167,6 +167,12 @@ void CopyBody(float keepvelocity)
        self.anim_lower_time = oldself.anim_lower_time;
        self.anim_upper_action = oldself.anim_upper_action;
        self.anim_upper_time = oldself.anim_upper_time;
+       self.anim_implicit_state = oldself.anim_implicit_state;
+       self.anim_implicit_time = oldself.anim_implicit_time;
+       self.anim_lower_implicit_action = oldself.anim_lower_implicit_action;
+       self.anim_lower_implicit_time = oldself.anim_lower_implicit_time;
+       self.anim_upper_implicit_action = oldself.anim_upper_implicit_action;
+       self.anim_upper_implicit_time = oldself.anim_upper_implicit_time;
        self.dphitcontentsmask = oldself.dphitcontentsmask;
        self.death_time = oldself.death_time;
        self.pain_finished = oldself.pain_finished;
@@ -207,7 +213,7 @@ void CopyBody(float keepvelocity)
        self.nextthink = time;
        self.think = CopyBody_Think;
        // "bake" the current animation frame for clones (they don't get clientside animation)
-       animdecide_setframes(self, self.flags, FALSE, frame, frame1time, frame2, frame2time);
+       animdecide_setframes(self, FALSE, frame, frame1time, frame2, frame2time);
 
        self = oldself;
 }
@@ -244,6 +250,7 @@ void player_anim (void)
        if(self.crouch)
                animbits |= ANIMSTATE_DUCK;
        animdecide_setstate(self, animbits, FALSE);
+       animdecide_setimplicitstate(self, (self.flags & FL_ONGROUND));
 
        if (self.weaponentity)
        {
@@ -331,7 +338,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)
 {
@@ -340,9 +346,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);
 
@@ -396,6 +399,30 @@ void PlayerDamage (entity inflictor, entity attacker, float damage, float deatht
                take = damage;
        }
 
+       if(attacker == self)
+       {
+               // don't reset pushltime for self damage as it may be an attempt to
+               // escape a lava pit or similar
+               //self.pushltime = 0;
+               self.istypefrag = 0;
+       }
+       else if(IS_PLAYER(attacker))
+       {
+               self.pusher = attacker;
+               self.pushltime = time + autocvar_g_maxpushtime;
+               self.istypefrag = self.BUTTON_CHAT;
+       }
+       else if(time < self.pushltime)
+       {
+               attacker = self.pusher;
+               self.pushltime = max(self.pushltime, time + 0.6);
+       }
+       else
+       {
+               self.pushltime = 0;
+               self.istypefrag = 0;
+       }
+
        frag_inflictor = inflictor;
        frag_attacker = attacker;
        frag_target = self;
@@ -436,7 +463,7 @@ void PlayerDamage (entity inflictor, entity attacker, float damage, float deatht
                        {
                                self.pain_finished = time + 0.5;        //Supajoe
 
-                               if(sv_gentle < 1) {
+                               if(autocvar_sv_gentle < 1) {
                                        if(self.classname != "body") // pain anim is BORKED on our ZYMs, FIXME remove this once we have good models
                                        {
                                                if (!self.animstate_override)
@@ -480,39 +507,18 @@ 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(attacker == self)
-       {
-               // don't reset pushltime for self damage as it may be an attempt to
-               // escape a lava pit or similar
-               //self.pushltime = 0;
-               self.istypefrag = 0;
-       }
-       else if(attacker.classname == "player")
-       {
-               self.pusher = attacker;
-               self.pushltime = time + autocvar_g_maxpushtime;
-               self.istypefrag = self.BUTTON_CHAT;
-       }
-       else if(time < self.pushltime)
-       {
-               attacker = self.pusher;
-               self.pushltime = max(self.pushltime, time + 0.6);
-       }
-       else
-       {
-               self.pushltime = 0;
-               self.istypefrag = 0;
-       }
+       if(g_ca && self != attacker && IS_PLAYER(attacker))
+               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))
        {
@@ -544,7 +550,7 @@ void PlayerDamage (entity inflictor, entity attacker, float damage, float deatht
                if(valid_damage_for_weaponstats)
                        WeaponStats_LogKill(awep, abot, self.weapon, vbot);
 
-               if(sv_gentle < 1) // TODO make a "gentle" version?
+               if(autocvar_sv_gentle < 1) // TODO make a "gentle" version?
                if(sound_allowed(MSG_BROADCAST, attacker))
                {
                        if(deathtype == DEATH_DROWN)
@@ -569,18 +575,9 @@ 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();
-               DropAllRunes(self);
 
         // increment frag counter for used weapon type
         float w;
@@ -589,27 +586,20 @@ 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))
                {
-                       stuffcmd(self, "-zoom\n");
                        self.fixangle = TRUE;
                        //msg_entity = self;
                        //WriteByte (MSG_ONE, SVC_SETANGLE);
@@ -618,19 +608,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(defer_ClientKill_Now_TeamChange)
+                       ClientKill_Now_TeamChange(); // can turn player into spectator
 
-               if(g_arena)
-                       Spawnqueue_Unmark(self);
-
-               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;
@@ -669,6 +663,10 @@ void PlayerDamage (entity inflictor, entity attacker, float damage, float deatht
                        self.respawn_countdown = 10; // first number to count down from is 10
                else
                        self.respawn_countdown = -1; // do not count down
+
+               if(g_lms || 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);
@@ -686,7 +684,7 @@ void PlayerDamage (entity inflictor, entity attacker, float damage, float deatht
                // set up to fade out later
                SUB_SetFade (self, time + 6 + random (), 1);
 
-               if(sv_gentle > 0 || autocvar_ekg) {
+               if(autocvar_sv_gentle > 0 || autocvar_ekg) {
                        // remove corpse
                        PlayerCorpseDamage (inflictor, attacker, autocvar_sv_gibhealth+1.0, deathtype, hitloc, force);
                }
@@ -721,7 +719,7 @@ float Say(entity source, float teamsay, entity privatesay, string msgin, float f
 
        msgin = formatmessage(msgin);
 
-       if(source.classname != "player")
+       if not(IS_PLAYER(source))
                colorstr = "^0"; // black for spectators
        else if(teamplay)
                colorstr = Team_ColorCode(source.team);
@@ -881,7 +879,7 @@ float Say(entity source, float teamsay, entity privatesay, string msgin, float f
        }
 
        if(!privatesay)
-       if(source.classname != "player")
+       if not(IS_PLAYER(source))
        {
                if not(intermission_running)
                        if(teamsay || (autocvar_g_chat_nospectators == 1) || (autocvar_g_chat_nospectators == 2 && !(inWarmupStage || gameover)))
@@ -923,17 +921,18 @@ float Say(entity source, float teamsay, entity privatesay, string msgin, float f
                        if(sourcecmsgstr != "" && !privatesay)
                                centerprint(source, sourcecmsgstr);
                }
-               else if(privatesay) // private message, between 2 people only, not sent to server console
+               else if(privatesay) // private message, between 2 people only
                {
                        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(cmsgstr != "")
                                centerprint(privatesay, cmsgstr);
                }
                else if(teamsay > 0) // team message, only sent to team mates
                {
                        sprint(source, sourcemsgstr);
-                       //print(msgstr); // send to server console too
+                       dedicated_print(msgstr); // send to server console too
                        if(sourcecmsgstr != "")
                                centerprint(source, sourcecmsgstr);
                        FOR_EACH_REALPLAYER(head) if(head.team == source.team)
@@ -947,15 +946,15 @@ float Say(entity source, float teamsay, entity privatesay, string msgin, float f
                else if(teamsay < 0) // spectator message, only sent to spectators
                {
                        sprint(source, sourcemsgstr);
-                       //print(msgstr); // send to server console too
-                       FOR_EACH_REALCLIENT(head) if(head.classname != "player")
+                       dedicated_print(msgstr); // send to server console too
+                       FOR_EACH_REALCLIENT(head) if not(IS_PLAYER(head))
                                if(head != source)
                                        sprint(head, msgstr);
                }
                else if(sourcemsgstr != msgstr) // trimmed/server fixed message, sent to all players
                {
                        sprint(source, sourcemsgstr);
-                       //print(msgstr); // send to server console too
+                       dedicated_print(msgstr); // send to server console too
                        FOR_EACH_REALCLIENT(head)
                                if(head != source)
                                        sprint(head, msgstr);
@@ -1121,7 +1120,7 @@ void FakeGlobalSound(string sample, float chan, float voicetype)
                        if(self.pusher)
                        {
                                msg_entity = self;
-                               if(clienttype(msg_entity) == CLIENTTYPE_REAL)
+                               if(IS_REAL_CLIENT(msg_entity))
                                        soundto(MSG_ONE, self, chan, sample, VOL_BASE, ATTN_NONE);
                        }
                        break;
@@ -1137,7 +1136,7 @@ void FakeGlobalSound(string sample, float chan, float voicetype)
                                break;
                        if(!sv_taunt)
                                break;
-                       if(sv_gentle)
+                       if(autocvar_sv_gentle)
                                break;
                        tauntrand = random();
                        msg_entity = self;
@@ -1150,12 +1149,12 @@ void FakeGlobalSound(string sample, float chan, float voicetype)
                        }
                        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)
                                break;
-                       if(sv_gentle)
+                       if(autocvar_sv_gentle)
                                break;
                        msg_entity = self;
                        if (msg_entity.cvar_cl_voice_directional >= 1)
@@ -1194,7 +1193,7 @@ 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);
@@ -1207,7 +1206,7 @@ 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);
@@ -1215,7 +1214,7 @@ void GlobalSound(string sample, float chan, float voicetype)
                                                soundto(MSG_ONE, self, chan, sample, VOL_BASEVOICE, ATTN_NONE);
                                }
                                msg_entity = self;
-                               if(clienttype(msg_entity) == CLIENTTYPE_REAL)
+                               if(IS_REAL_CLIENT(msg_entity))
                                        soundto(MSG_ONE, self, chan, sample, VOL_BASE, ATTN_NONE);
                        }
                        break;
@@ -1234,7 +1233,7 @@ void GlobalSound(string sample, float chan, float voicetype)
                                break;
                        if(!sv_taunt)
                                break;
-                       if(sv_gentle)
+                       if(autocvar_sv_gentle)
                                break;
                        tauntrand = random();
                        FOR_EACH_REALCLIENT(msg_entity)
@@ -1247,12 +1246,12 @@ void GlobalSound(string sample, float chan, float voicetype)
                                }
                        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)
                                break;
-                       if(sv_gentle)
+                       if(autocvar_sv_gentle)
                                break;
                        FOR_EACH_REALCLIENT(msg_entity)
                        {
@@ -1300,14 +1299,8 @@ void VoiceMessage(string type, string msg)
                FakeGlobalSound(self.sample, CH_VOICE, voicetype);
 }
 
-void MoveToTeam(entity client, float team_colour, float type, float show_message)
+void MoveToTeam(entity client, float team_colour, float type)
 {
-//     show_message
-//     0 (00) automove centerprint, admin message
-//     1 (01) automove centerprint, no admin message
-//     2 (10) no centerprint, admin message
-//     3 (11) no centerprint, no admin message
-
        float lockteams_backup;
 
        lockteams_backup = lockteams;  // backup any team lock
@@ -1316,14 +1309,9 @@ void MoveToTeam(entity client, float team_colour, float type, float show_message
 
        TeamchangeFrags(client);  // move the players frags
        SetPlayerColors(client, team_colour - 1);  // set the players colour
-       Damage(client, client, client, 100000, ((show_message & 2) ? DEATH_QUIET : DEATH_AUTOTEAMCHANGE), client.origin, '0 0 0');  // kill the player
+       Damage(client, client, client, 100000, DEATH_AUTOTEAMCHANGE, client.origin, '0 0 0');  // kill the player
 
        lockteams = lockteams_backup;  // restore the team lock
 
        LogTeamchange(client.playerid, client.team, type);
-
-       if not(show_message & 1) // admin message
-               sprint(client, strcat("\{1}\{13}^3", admin_name(), "^7: You have been moved to the ", Team_ColorNameLowerCase(team_colour), " team\n"));  // send a chat message
-
-       bprint(strcat(client.netname, " joined the ", ColoredTeamName(client.team), "\n"));
 }