]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blobdiff - qcsrc/server/g_damage.qc
fix player view offset and headshot bbox
[xonotic/xonotic-data.pk3dir.git] / qcsrc / server / g_damage.qc
index c544370704594b97b0d8a581c7dab6f25caf17e4..809df9ecbd892b5d6037f4cb5b07670818a3ba27 100644 (file)
@@ -88,11 +88,11 @@ float IsFlying(entity a)
 
 vector GetHeadshotMins(entity targ)
 {
-       return '0.6 0 0' * targ.mins_x + '0 0.6 0' * targ.mins_y + '0 0 1' * (1.3 * targ.view_ofs_z - 0.3 * targ.maxs_z);
+       return '-0.5 0 0' * PL_HEAD_x + '0 -0.5 0' * PL_HEAD_y + '0 0 1' * (targ.maxs_z - PL_HEAD_z);
 }
 vector GetHeadshotMaxs(entity targ)
 {
-       return '0.6 0 0' * targ.maxs_x + '0 0.6 0' * targ.maxs_y + '0 0 1' * targ.maxs_z;
+       return '0.5 0 0' * PL_HEAD_x + '0 0.5 0' * PL_HEAD_y + '0 0 1' * targ.maxs_z;
 }
 
 void UpdateFrags(entity player, float f)
@@ -257,26 +257,28 @@ void Send_KillNotification (string s1, string s2, string s3, float msg, float ty
        WriteByte(MSG_ALL, type);
 }
 
-// TODO: writespectatable?
 // Function is used to send a generic centerprint whose content CSQC gets to decide (gentle version or not in the below cases)
-void Send_CSQC_Centerprint(entity e, string s1, float msg, float type)
+void Send_CSQC_Centerprint(entity e, string s1, string s2, float msg, float type)
 {
        if (clienttype(e) == CLIENTTYPE_REAL)
        {
                msg_entity = e;
-               WriteByte(MSG_ONE, SVC_TEMPENTITY);
-               WriteByte(MSG_ONE, TE_CSQC_NOTIFY);
-               WriteByte(MSG_ONE, CSQC_CENTERPRINT);
-               WriteString(MSG_ONE, s1);
-               WriteShort(MSG_ONE, msg);
-               WriteByte(MSG_ONE, type);
+               WRITESPECTATABLE_MSG_ONE({
+                       WriteByte(MSG_ONE, SVC_TEMPENTITY);
+                       WriteByte(MSG_ONE, TE_CSQC_NOTIFY);
+                       WriteByte(MSG_ONE, CSQC_CENTERPRINT);
+                       WriteString(MSG_ONE, s1);
+                       WriteString(MSG_ONE, s2);
+                       WriteShort(MSG_ONE, msg);
+                       WriteByte(MSG_ONE, type);
+               });
        }
 }
 
 void Obituary (entity attacker, entity inflictor, entity targ, float deathtype)
 {
        string  s, a, msg;
-       float p, w, type;
+       float w, type;
 
        if (targ.classname == "player" || targ.classname == "corpse")
        {
@@ -291,21 +293,8 @@ void Obituary (entity attacker, entity inflictor, entity targ, float deathtype)
                {
                        if (deathtype == DEATH_TEAMCHANGE || deathtype == DEATH_AUTOTEAMCHANGE)
                                msg = ColoredTeamName(targ.team); // TODO: check if needed?
-                       Send_CSQC_Centerprint(targ, msg, deathtype, MSG_SUICIDE);
+                       Send_CSQC_Centerprint(targ, msg, "", deathtype, MSG_SUICIDE);
 
-                       if(deathtype != DEATH_TEAMCHANGE && deathtype != DEATH_QUIET)
-                       {
-                               LogDeath("suicide", deathtype, targ, targ);
-                               GiveFrags(attacker, targ, -1);
-                       }
-                       // TODO: hmm?
-                       /*
-                               if (targ.killcount > 2)
-                                       bprint ("^1",s,"^1 faded after a ",ftos(targ.killcount)," point spree\n");
-                       */
-
-                       // TODO: wut is this?
-                       // givefrags for logging apparently?
                        if(deathtype != DEATH_TEAMCHANGE && deathtype != DEATH_QUIET)
                        {
                                LogDeath("suicide", deathtype, targ, targ);
@@ -314,60 +303,74 @@ void Obituary (entity attacker, entity inflictor, entity targ, float deathtype)
 
                        if (targ.killcount > 2)
                                msg = ftos(targ.killcount);
+                       if(teams_matter && deathtype == DEATH_MIRRORDAMAGE)
+                       {
+                               if(attacker.team == COLOR_TEAM1)
+                                       deathtype = KILL_TEAM_RED;
+                               else
+                                       deathtype = KILL_TEAM_BLUE;
+                       }
+
                        Send_KillNotification(s, msg, ftos(w), deathtype, MSG_SUICIDE);
                }
                else if (attacker.classname == "player" || attacker.classname == "gib")
                {
                        if(teams_matter && attacker.team == targ.team)
                        {
-                               type = KILL_TEAM;
+                               if(attacker.team == COLOR_TEAM1)
+                                       type = KILL_TEAM_RED;
+                               else
+                                       type = KILL_TEAM_BLUE;
 
                                GiveFrags(attacker, targ, -1);
 
+                               Send_CSQC_Centerprint(attacker, s, "", type, MSG_KILL);
+
                                if (targ.killcount > 2) {
                                        msg = ftos(targ.killcount);
-                                       a = s;
                                }
+
                                if (attacker.killcount > 2) {
                                        msg = ftos(attacker.killcount);
                                        type = KILL_TEAM_SPREE;
                                }
+                               Send_KillNotification(a, s, msg, type, MSG_KILL);
 
                                attacker.killcount = 0;
 
                                LogDeath("tk", deathtype, attacker, targ);
-                               Send_CSQC_Centerprint(attacker, s, type, MSG_KILL);
-                               Send_KillNotification(a, msg, "", type, MSG_KILL);
                        }
                        else
                        {
-                               string blood_message, victim_message;
                                if (!checkrules_firstblood)
                                {
                                        checkrules_firstblood = TRUE;
                                        Send_KillNotification(a, "", "", KILL_FIRST_BLOOD, MSG_KILL);
-                                       // TODO: make these print at newline if they dont
-                                       Send_CSQC_Centerprint(attacker, "", KILL_FIRST_BLOOD, MSG_KILL);
-                                       Send_CSQC_Centerprint(targ, "", KILL_FIRST_VICTIM, MSG_KILL);
+                                       // TODO: make these print a newline if they dont
+                                       Send_CSQC_Centerprint(attacker, "", "", KILL_FIRST_BLOOD, MSG_KILL);
+                                       Send_CSQC_Centerprint(targ, "", "", KILL_FIRST_VICTIM, MSG_KILL);
                                }
 
                                if((cvar("sv_fragmessage_information_typefrag")) && (targ.BUTTON_CHAT)) {
-                                       Send_CSQC_Centerprint(attacker, s, KILL_TYPEFRAG, MSG_KILL);
-                                       Send_CSQC_Centerprint(targ, a, KILL_TYPEFRAGGED, MSG_KILL);
+                                       Send_CSQC_Centerprint(attacker, s, GetAdvancedDeathReports(targ), KILL_TYPEFRAG, MSG_KILL);
+                                       Send_CSQC_Centerprint(targ, a, GetAdvancedDeathReports(attacker), KILL_TYPEFRAGGED, MSG_KILL);
                                } else {
-                                       Send_CSQC_Centerprint(attacker, s, KILL_FRAG, MSG_KILL);
-                                       Send_CSQC_Centerprint(targ, a, KILL_FRAGGED, MSG_KILL);
+                                       Send_CSQC_Centerprint(attacker, s, GetAdvancedDeathReports(targ), KILL_FRAG, MSG_KILL);
+                                       Send_CSQC_Centerprint(targ, a, GetAdvancedDeathReports(attacker), KILL_FRAGGED, MSG_KILL);
                                }
+
                                attacker.taunt_soundtime = time + 1;
 
                                // TODO: fix this?
-                                       if (deathtype == DEATH_CUSTOM)
-                                               msg = strcat(deathmessage, " by ^1", msg);
-                                       else if (deathtype == DEATH_HURTTRIGGER && inflictor.message2 != "")
-                                       {
-                                               msg = ftos(strstrofs(inflictor.message2, "#", 0));
-                                       }
-                                       Send_KillNotification(s, a, msg, deathtype, MSG_KILL);
+                               if (deathtype == DEATH_CUSTOM)
+                                       msg = deathmessage;
+                               else
+                                       msg = inflictor.message2;
+
+                               if(strstrofs(msg, "%", 0) < 0)
+                                       msg = strcat("%s ", msg, " by %s");
+
+                               Send_KillNotification(a, s, msg, deathtype, MSG_KILL);
 
                                if(g_ctf && targ.flagcarried)
                                {
@@ -387,10 +390,7 @@ void Obituary (entity attacker, entity inflictor, entity targ, float deathtype)
                                if (attacker.killcount > 2) {
                                        Send_KillNotification(a, ftos(attacker.killcount), "", KILL_SPREE, MSG_SPREE);
                                }
-
-                               LogDeath("frag", deathtype, attacker, targ);
-
-                               if (attacker.killcount == 3)
+                               else if (attacker.killcount == 3)
                                {
                                        Send_KillNotification(a, "", "", KILL_SPREE_3, MSG_SPREE);
                                        AnnounceTo(attacker, "03kills");
@@ -425,15 +425,18 @@ void Obituary (entity attacker, entity inflictor, entity targ, float deathtype)
                                        Send_KillNotification(a, "", "", KILL_SPREE_30, MSG_SPREE);
                                        AnnounceTo(attacker, "30kills");
                                }
+                               LogDeath("frag", deathtype, attacker, targ);
                        }
                }
                else
                {
-                       Send_CSQC_Centerprint(targ, "", deathtype, MSG_KILL_ACTION);
+                       Send_CSQC_Centerprint(targ, "", "", deathtype, MSG_KILL_ACTION);
                        if (deathtype == DEATH_HURTTRIGGER && inflictor.message != "")
                                msg = inflictor.message;
                        else if (deathtype == DEATH_CUSTOM)
                                msg = deathmessage;
+                       if(strstrofs(msg, "%", 0) < 0)
+                               msg = strcat("%s ", msg);
 
                        GiveFrags(targ, targ, -1);
                        if(PlayerScore_Add(targ, SP_SCORE, 0) == -5) {
@@ -461,6 +464,7 @@ void Obituary (entity attacker, entity inflictor, entity targ, float deathtype)
 entity damage_targ;
 entity damage_inflictor;
 entity damage_attacker;
+.float prevhitsound;
 
 void Damage (entity targ, entity inflictor, entity attacker, float damage, float deathtype, vector hitloc, vector force)
 {
@@ -723,10 +727,14 @@ void Damage (entity targ, entity inflictor, entity attacker, float damage, float
                                {
                                        if(damage > 0)
                                        {
-                                               if(targ.BUTTON_CHAT)
-                                                       attacker.typehitsound += 1;
-                                               else
-                                                       attacker.hitsound += 1;
+                                               if(attacker.weapon != WEP_ELECTRO && attacker.weapon != WEP_LASER || ((attacker.weapon == WEP_ELECTRO && cvar("g_balance_electro_lightning") || attacker.weapon == WEP_LASER) && attacker.prevhitsound + cvar("sv_hitsound_antispam_time") < time))
+                                               {
+                                                       if(targ.BUTTON_CHAT)
+                                                               attacker.typehitsound += 1;
+                                                       else
+                                                               attacker.hitsound += 1;
+                                                       attacker.prevhitsound = time;
+                                               }
 
                                                damage_goodhits += 1;
                                                damage_gooddamage += damage;
@@ -744,6 +752,8 @@ void Damage (entity targ, entity inflictor, entity attacker, float damage, float
                                                        if(deathtype & HITTYPE_HEADSHOT)
                                                                headshot = 1;
                                                }
+                                               if(g_ca)
+                                                       PlayerScore_Add(attacker, SP_SCORE, damage * cvar("g_ca_damage2score_multiplier"));
                                        }
                                }
                                else
@@ -841,20 +851,6 @@ void Damage (entity targ, entity inflictor, entity attacker, float damage, float
        }
 }
 
-vector NearestPointOnBox(entity box, vector org)
-{
-       vector m1, m2, nearest;
-
-       m1 = box.mins + box.origin;
-       m2 = box.maxs + box.origin;
-
-       nearest_x = bound(m1_x, org_x, m2_x);
-       nearest_y = bound(m1_y, org_y, m2_y);
-       nearest_z = bound(m1_z, org_z, m2_z);
-
-       return nearest;
-}
-
 void Damage_RecordDamage(entity attacker, float deathtype, float damage)
 {
        float weaponid;
@@ -997,6 +993,39 @@ float RadiusDamage (entity inflictor, entity attacker, float coredamage, float e
                                                finaldmg = finaldmg * a;
                                                a = bound(0, tfloorforce + (1-tfloorforce) * hitratio, 1);
                                                force = force * a;
+
+                                               // laser force adjustments :P
+                                               if(DEATH_WEAPONOF(deathtype) == WEP_LASER)
+                                               {
+                                                       vector vel;
+
+                                                       float force_zscale;
+                                                       float force_velocitybiasramp;
+                                                       float force_velocitybias;
+
+                                                       force_velocitybiasramp = cvar("sv_maxspeed");
+                                                       if(deathtype & HITTYPE_SECONDARY)
+                                                       {
+                                                               force_zscale = cvar("g_balance_laser_secondary_force_zscale");
+                                                               force_velocitybias = cvar("g_balance_laser_secondary_force_velocitybias");
+                                                       }
+                                                       else
+                                                       {
+                                                               force_zscale = cvar("g_balance_laser_primary_force_zscale");
+                                                               force_velocitybias = cvar("g_balance_laser_primary_force_velocitybias");
+                                                       }
+
+                                                       vel = targ.velocity;
+                                                       vel_z = 0;
+                                                       vel = normalize(vel) * bound(0, vlen(vel) / force_velocitybiasramp, 1) * force_velocitybias;
+                                                       force =
+                                                               vlen(force)
+                                                               *
+                                                               normalize(normalize(force) + vel);
+
+                                                       force_z *= force_zscale;
+                                               }
+
                                                //if (targ == attacker)
                                                //{
                                                //      print("hits ", ftos(hits), " / ", ftos(total));
@@ -1159,9 +1188,7 @@ void Fire_ApplyDamage(entity e)
        if not(Fire_IsBurning(e))
                return;
 
-       o = e.owner;
-       while(o.owner)
-               o = o.owner;
+       for(t = 0, o = e.owner; o.owner && t < 16; o = o.owner, ++t);
        if(clienttype(o) == CLIENTTYPE_NOTACLIENT)
                o = e.fire_owner;