move more of the weapon stuff to CSQC
[xonotic/xonotic-data.pk3dir.git] / qcsrc / server / g_damage.qc
index 936b5f6..3b4a73b 100644 (file)
@@ -86,6 +86,15 @@ float IsFlying(entity a)
        return 1;
 }
 
+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);
+}
+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;
+}
+
 void UpdateFrags(entity player, float f)
 {
        PlayerTeamScore_AddScore(player, f);
@@ -146,37 +155,45 @@ void GiveFrags (entity attacker, entity targ, float f)
        }
 
        // FIXME fix the mess this is (we have REAL points now!)
+       entity oldself;
+       oldself = self;
+       self = attacker;
        frag_attacker = attacker;
        frag_target = targ;
        frag_score = f;
        if(MUTATOR_CALLHOOK(GiveFragsForKill))
        {
                f = frag_score;
+               self = oldself;
        }
-       else if(g_runematch)
-       {
-               f = RunematchHandleFrags(attacker, targ, f);
-       }
-       else if(g_lms)
+       else
        {
-               // remove a life
-               float tl;
-               tl = PlayerScore_Add(targ, SP_LMS_LIVES, -1);
-               if(tl < lms_lowest_lives)
-                       lms_lowest_lives = tl;
-               if(tl <= 0)
+               self = oldself;
+               if(g_runematch)
                {
-                       if(!lms_next_place)
-                               lms_next_place = player_count;
-                       PlayerScore_Add(targ, SP_LMS_RANK, lms_next_place); // won't ever spawn again
-                       --lms_next_place;
+                       f = RunematchHandleFrags(attacker, targ, f);
                }
-               f = 0;
-       }
-       else if(g_ctf)
-       {
-               if(g_ctf_ignore_frags)
+               else if(g_lms)
+               {
+                       // remove a life
+                       float tl;
+                       tl = PlayerScore_Add(targ, SP_LMS_LIVES, -1);
+                       if(tl < lms_lowest_lives)
+                               lms_lowest_lives = tl;
+                       if(tl <= 0)
+                       {
+                               if(!lms_next_place)
+                                       lms_next_place = player_count;
+                               PlayerScore_Add(targ, SP_LMS_RANK, lms_next_place); // won't ever spawn again
+                               --lms_next_place;
+                       }
                        f = 0;
+               }
+               else if(g_ctf)
+               {
+                       if(g_ctf_ignore_frags)
+                               f = 0;
+               }
        }
 
        attacker.totalfrags += f;
@@ -228,10 +245,34 @@ void LogDeath(string mode, float deathtype, entity killer, entity killed)
        GameLogEcho(s);
 }
 
+void Send_KillNotification (string s1, string s2, string s3, float msg, float type)
+{
+       WriteByte(MSG_ALL, SVC_TEMPENTITY);
+       WriteByte(MSG_ALL, TE_CSQC_NOTIFY);
+       WriteByte(MSG_ALL, CSQC_KILLNOTIFY);
+       WriteString(MSG_ALL, s1);
+       WriteString(MSG_ALL, s2);
+       WriteString(MSG_ALL, s3);
+       WriteByte(MSG_ALL, msg);
+       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 deathtype)
+{
+       msg_entity = e;
+       WriteByte(MSG_ONE, SVC_TEMPENTITY);
+       WriteByte(MSG_ONE, TE_CSQC_NOTIFY);
+       WriteByte(MSG_ONE, CSQC_CENTERPRINT);
+       WriteString(MSG_ONE, s1);
+       WriteByte(MSG_ONE, deathtype);
+}
+
 void Obituary (entity attacker, entity inflictor, entity targ, float deathtype)
 {
-       string  s, a;
-       float p, w;
+       string  s, a, msg;
+       float p, w, type;
 
        if (targ.classname == "player" || targ.classname == "corpse")
        {
@@ -242,8 +283,11 @@ void Obituary (entity attacker, entity inflictor, entity targ, float deathtype)
 
                a = attacker.netname;
 
-               if (targ == attacker)
+               if (targ == attacker) // suicides
                {
+                       if (deathtype == DEATH_TEAMCHANGE || deathtype == DEATH_AUTOTEAMCHANGE)
+                               msg = ColoredTeamName(targ.team); // TODO: check if needed?
+                       /*
                        if (deathtype == DEATH_TEAMCHANGE) {
                                centerprint(targ, strcat(DAMAGE_CENTERPRINT_SPACER, "You are now on: ", ColoredTeamName(targ.team)));
                        } else if (deathtype == DEATH_AUTOTEAMCHANGE) {
@@ -277,6 +321,11 @@ void Obituary (entity attacker, entity inflictor, entity targ, float deathtype)
                                else
                                        centerprint(targ, strcat(DAMAGE_CENTERPRINT_SPACER, "^1You killed your own dumb self!"));
                        }
+                       */
+                       Send_CSQC_Centerprint(targ, msg, deathtype);
+
+                       // TODO: message
+                       /*
                        if(sv_gentle) {
                                if (deathtype == DEATH_CAMP)
                                        bprint ("^1",s, "^1 thought they found a nice camping ground\n");
@@ -293,14 +342,6 @@ void Obituary (entity attacker, entity inflictor, entity targ, float deathtype)
                                if (targ.killcount > 2)
                                        bprint ("^1",s,"^1 faded after a ",ftos(targ.killcount)," point spree\n");
                        } else {
-                               w = DEATH_WEAPONOF(deathtype);
-                               if(WEP_VALID(w))
-                               {
-                                       w_deathtypestring = "couldn't resist the urge to self-destruct";
-                                       w_deathtype = deathtype;
-                                       weapon_action(w, WR_SUICIDEMESSAGE);
-                                       bprint("^1", s, "^1 ", w_deathtypestring, "\n");
-                               }
                                else if (deathtype == DEATH_KILL)
                                        bprint ("^1",s, "^1 couldn't take it anymore\n");
                                else if (deathtype == DEATH_ROT)
@@ -318,27 +359,39 @@ void Obituary (entity attacker, entity inflictor, entity targ, float deathtype)
                                else if (deathtype != DEATH_TEAMCHANGE && deathtype != DEATH_QUIET)
                                        bprint ("^1",s, "^1 couldn't resist the urge to self-destruct\n");
 
-                               if(deathtype != DEATH_TEAMCHANGE && deathtype != DEATH_QUIET)
-                               {
-                                       LogDeath("suicide", deathtype, targ, targ);
-                                       GiveFrags(attacker, targ, -1);
-                               }
-                               if (targ.killcount > 2)
                                        bprint ("^1",s,"^1 ended it all after a ",ftos(targ.killcount)," kill spree\n");
                        }
+                       */
+
+                       // TODO: wut is this?
+                       // givefrags for logging apparently?
+                       if(deathtype != DEATH_TEAMCHANGE && deathtype != DEATH_QUIET)
+                       {
+                               LogDeath("suicide", deathtype, targ, targ);
+                               GiveFrags(attacker, targ, -1);
+                       }
+
+                       if (targ.killcount > 2)
+                               msg = ftos(targ.killcount);
+                       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(sv_gentle) {
+                               // TODO: the centerprint!
                                        centerprint(attacker, strcat(DAMAGE_CENTERPRINT_SPACER, "^1Moron! You went against a team mate!"));
                                        bprint ("^1", a, "^1 took action against a team mate\n");
                                } else {
                                        centerprint(attacker, strcat(DAMAGE_CENTERPRINT_SPACER, "^1Moron! You fragged ", s, ", a team mate!"));
                                        bprint ("^1", a, "^1 mows down a team mate\n");
                                }
+                               */
                                GiveFrags(attacker, targ, -1);
+                               /*
                                if (targ.killcount > 2) {
                                        if(sv_gentle)
                                                bprint ("^1",s,"'s ^1",ftos(targ.killcount)," scoring spree was ended by a team mate!\n");
@@ -351,9 +404,22 @@ void Obituary (entity attacker, entity inflictor, entity targ, float deathtype)
                                        else
                                                bprint ("^1",a,"^1 ended a ",ftos(attacker.killcount)," kill spree by killing a team mate\n");
                                }
+                               */
+
+                               if (targ.killcount > 2) {
+                                       msg = ftos(targ.killcount);
+                                       a = s;
+                               }
+                               if (attacker.killcount > 2) {
+                                       msg = ftos(attacker.killcount);
+                                       type = KILL_TEAM_SPREE;
+                               }
+
                                attacker.killcount = 0;
 
                                LogDeath("tk", deathtype, attacker, targ);
+                               Send_CSQC_Centerprint(attacker, s, MSG_KILL);
+                               Send_KillNotification(a, msg, "", type, MSG_KILL);
                        }
                        else
                        {
@@ -361,36 +427,36 @@ void Obituary (entity attacker, entity inflictor, entity targ, float deathtype)
                                if (!checkrules_firstblood)
                                {
                                        checkrules_firstblood = TRUE;
-                                       if(sv_gentle)
-                                       {
-                                               bprint("^1",a, "^1 was the first to score", "\n");
-                                               blood_message = "^1First point\n";
-                                               //victim_message = "^1First victim\n";  // or First casualty
-                                       }
-                                       else
-                                       {
-                                               bprint("^1",a, "^1 drew first blood", "\n");
-                                               blood_message = "^1First blood\n";
-                                               victim_message = "^1First victim\n";  // or First casualty
-                                       }
+                                       Send_KillNotification(a, "", "", KILL_FIRST_BLOOD, MSG_KILL);
+                                       //bprint("^1",a, "^1 drew first blood", "\n");
+                                       // TODO: make these print at newline if they dont
+                                       Send_CSQC_Centerprint(attacker, "", KILL_FIRST_BLOOD);
+                                       Send_CSQC_Centerprint(targ, "", KILL_FIRST_VICTIM);
+                                       //blood_message = "^1First blood\n";
+                                       //victim_message = "^1First victim\n";  // or First casualty
                                }
-                               if(sv_gentle > 0) {
-                                       centerprint(attacker, strcat(DAMAGE_CENTERPRINT_SPACER, blood_message, "^4You scored against ^7", s, GetAdvancedDeathReports(targ)));
-                                       centerprint(targ, strcat(DAMAGE_CENTERPRINT_SPACER, a,"^1 scored against you ^7", GetAdvancedDeathReports(attacker)));
+                               //if(sv_gentle > 0) {
+                               //      centerprint(attacker, strcat(DAMAGE_CENTERPRINT_SPACER, blood_message, "^4You scored against ^7", s, GetAdvancedDeathReports(targ)));
+                               //      centerprint(targ, strcat(DAMAGE_CENTERPRINT_SPACER, a,"^1 scored against you ^7", GetAdvancedDeathReports(attacker)));
+
+                               if((cvar("sv_fragmessage_information_typefrag")) && (targ.BUTTON_CHAT)) {
+                                       Send_CSQC_Centerprint(attacker, s, KILL_TYPEFRAG);
+                                       //centerprint(attacker, strcat(DAMAGE_CENTERPRINT_SPACER, blood_message, "^1You typefragged ^7", s, GetAdvancedDeathReports(targ)));
+                                       Send_CSQC_Centerprint(targ, a, KILL_TYPEFRAGGED);
+                                       //centerprint(targ, strcat(DAMAGE_CENTERPRINT_SPACER, victim_message, "^1You were typefragged by ^7", a, GetAdvancedDeathReports(attacker)));
                                } else {
-                                       if((cvar("sv_fragmessage_information_typefrag")) && (targ.BUTTON_CHAT)) {
-                                               centerprint(attacker, strcat(DAMAGE_CENTERPRINT_SPACER, blood_message, "^1You typefragged ^7", s, GetAdvancedDeathReports(targ)));
-                                               centerprint(targ, strcat(DAMAGE_CENTERPRINT_SPACER, victim_message, "^1You were typefragged by ^7", a, GetAdvancedDeathReports(attacker)));
-                                       } else {
-                                               centerprint(attacker, strcat(DAMAGE_CENTERPRINT_SPACER, blood_message, "^4You fragged ^7", s, GetAdvancedDeathReports(targ)));
-                                               centerprint(targ, strcat(DAMAGE_CENTERPRINT_SPACER, victim_message, "^1You were fragged by ^7", a, GetAdvancedDeathReports(attacker)));
-                                       }
-                                       attacker.taunt_soundtime = time + 1;
+                                       Send_CSQC_Centerprint(attacker, s, KILL_FRAG);
+                                       //centerprint(attacker, strcat(DAMAGE_CENTERPRINT_SPACER, blood_message, "^4You fragged ^7", s, GetAdvancedDeathReports(targ)));
+                                       Send_CSQC_Centerprint(targ, a, KILL_FRAGGED);
+                                       //centerprint(targ, strcat(DAMAGE_CENTERPRINT_SPACER, victim_message, "^1You were fragged by ^7", a, GetAdvancedDeathReports(attacker)));
                                }
+                               attacker.taunt_soundtime = time + 1;
 
-                               if(sv_gentle) {
-                                       bprint ("^1",s, "^1 needs a restart thanks to ", a, "\n");
-                               } else {
+                               // TODO: more msg
+                               //if(sv_gentle) {
+                               //      bprint ("^1",s, "^1 needs a restart thanks to ", a, "\n");
+                               //} else {
+                                       /*
                                        w = DEATH_WEAPONOF(deathtype);
                                        if(WEP_VALID(w))
                                        {
@@ -432,6 +498,7 @@ void Obituary (entity attacker, entity inflictor, entity targ, float deathtype)
                                        else if(deathtype == DEATH_SBROCKET)
                         bprint ("^1",s, "^1 was blased to bits by ^1", a, "\n");
                                        else if(deathtype == DEATH_SBBLOWUP)
+                                       [
                         bprint ("^1",s, "^1 got cought in the destruction of ^1", a, "'s vehicle\n");
 
                                        else if(deathtype == DEATH_WAKIGUN)
@@ -453,7 +520,14 @@ void Obituary (entity attacker, entity inflictor, entity targ, float deathtype)
                                                bprint ("^1",s, "^1 ", deathmessage, " by ^1", a, "\n");
                                        else
                                                bprint ("^1",s, "^1 was fragged by ", a, "\n");
-                               }
+                                       */
+
+                                       //w = DEATH_WEAPONOF(deathtype);
+
+                                       if (deathtype == DEATH_CUSTOM)
+                                               msg = strcat(deathmessage, " by ^1", msg);
+                                       Send_KillNotification(s, a, msg, deathtype, MSG_KILL);
+                               //}
 
                                if(g_ctf && targ.flagcarried)
                                {
@@ -465,94 +539,124 @@ void Obituary (entity attacker, entity inflictor, entity targ, float deathtype)
                                        GiveFrags(attacker, targ, 1);
 
                                if (targ.killcount > 2) {
+                                       /*
                                        if(sv_gentle)
                                                bprint ("^1",s,"'s ^1", ftos(targ.killcount), " scoring spree was ended by ", a, "\n");
                                        else
                                                bprint ("^1",s,"'s ^1", ftos(targ.killcount), " kill spree was ended by ", a, "\n");
+                                       */
+                                       Send_KillNotification(s, ftos(targ.killcount), a, KILL_END_SPREE, MSG_SPREE);
                                }
 
                                attacker.killcount = attacker.killcount + 1;
 
                                if (attacker.killcount > 2) {
+                                       /*
                                        if(sv_gentle)
                                                bprint ("^1",a,"^1 made ",ftos(attacker.killcount)," scores in a row\n");
                                        else
                                                bprint ("^1",a,"^1 has ",ftos(attacker.killcount)," frags in a row\n");
+                                       */
+                                       Send_KillNotification(a, ftos(attacker.killcount), "", KILL_SPREE, MSG_SPREE);
                                }
 
                                LogDeath("frag", deathtype, attacker, targ);
 
                                if (attacker.killcount == 3)
                                {
-                                       if(sv_gentle) {
-                                               bprint (a,"^7 made a ^1TRIPLE SCORE\n");
-                                       } else {
-                                               bprint (a,"^7 made a ^1TRIPLE FRAG\n");
-                                               AnnounceTo(attacker, "03kills");
-                                       }
+                                       //if(sv_gentle) {
+                                       //      bprint (a,"^7 made a ^1TRIPLE SCORE\n");
+                                       //} else {
+                                       //      bprint (a,"^7 made a ^1TRIPLE FRAG\n");
+                                       //
+                                       Send_KillNotification(a, "", "", KILL_SPREE_3, MSG_SPREE);
+                                       AnnounceTo(attacker, "03kills");
+
+                                       //}
                                }
                                else if (attacker.killcount == 5)
                                {
-                                       if(sv_gentle) {
-                                               bprint (a,"^7 unleashes ^1SCORING RAGE\n");
-                                       } else {
-                                               bprint (a,"^7 unleashes ^1RAGE\n");
-                                               AnnounceTo(attacker, "05kills");
-                                       }
+                                       //if(sv_gentle) {
+                                       //      bprint (a,"^7 unleashes ^1SCORING RAGE\n");
+                                       //} else {
+                                       //      bprint (a,"^7 unleashes ^1RAGE\n");
+                                       Send_KillNotification(a, "", "", KILL_SPREE_5, MSG_SPREE);
+                                       AnnounceTo(attacker, "05kills");
+                                       //}
                                }
                                else if (attacker.killcount == 10)
                                {
-                                       if(sv_gentle) {
-                                               bprint (a,"^7 made ^1TEN SCORES IN A ROW!\n");
-                                       } else {
-                                               bprint (a,"^7 starts the ^1MASSACRE!\n");
-                                               AnnounceTo(attacker, "10kills");
-                                       }
+                                       //if(sv_gentle) {
+                                       //      bprint (a,"^7 made ^1TEN SCORES IN A ROW!\n");
+                                       //} else {
+                                       //      bprint (a,"^7 starts the ^1MASSACRE!\n");
+                                       Send_KillNotification(a, "", "", KILL_SPREE_10, MSG_SPREE);
+                                       AnnounceTo(attacker, "10kills");
+                                       //}
                                }
                                else if (attacker.killcount == 15)
                                {
+                                       /*
                                        if(sv_gentle) {
                                                bprint (a,"^7 made ^1FIFTEEN SCORES IN A ROW!\n");
                                        } else {
                                                bprint (a,"^7 executes ^1MAYHEM!\n");
                                                AnnounceTo(attacker, "15kills");
                                        }
+                                       */
+                                       Send_KillNotification(a, "", "", KILL_SPREE_15, MSG_SPREE);
+                                       AnnounceTo(attacker, "15kills");
                                }
                                else if (attacker.killcount == 20)
                                {
+                                       /*
                                        if(sv_gentle) {
                                                bprint (a,"^7 made ^1TWENTY SCORES IN A ROW!\n");
                                        } else {
                                                bprint (a,"^7 is a ^1BERSERKER!\n");
                                                AnnounceTo(attacker, "20kills");
                                        }
+                                       */
+                                       Send_KillNotification(a, "", "", KILL_SPREE_20, MSG_SPREE);
+                                       AnnounceTo(attacker, "20kills");
                                }
                                else if (attacker.killcount == 25)
                                {
+                                       /*
                                        if(sv_gentle) {
                                                bprint (a,"^7 made ^1TWENTY FIFE SCORES IN A ROW!\n");
                                        } else {
                                                bprint (a,"^7 inflicts ^1CARNAGE!\n");
                                                AnnounceTo(attacker, "25kills");
-                                       }
+                                       }*/
+                                       Send_KillNotification(a, "", "", KILL_SPREE_25, MSG_SPREE);
+                                       AnnounceTo(attacker, "25kills");
                                }
                                else if (attacker.killcount == 30)
                                {
+                                       /*
                                        if(sv_gentle) {
                                                bprint (a,"^7 made ^1THIRTY SCORES IN A ROW!\n");
                                        } else {
                                                bprint (a,"^7 unleashes ^1ARMAGEDDON!\n");
                                                AnnounceTo(attacker, "30kills");
                                        }
+                                       */
+                                       Send_KillNotification(a, "", "", KILL_SPREE_30, MSG_SPREE);
+                                       AnnounceTo(attacker, "30kills");
                                }
                        }
                }
                else
                {
-                       centerprint(targ, strcat(DAMAGE_CENTERPRINT_SPACER, "^1Watch your step!"));
+                       //centerprint(targ, strcat(DAMAGE_CENTERPRINT_SPACER, "^1Watch your step!"));
+                       Send_CSQC_Centerprint(targ, "", MSG_KILL_ACTION);
                        if (deathtype == DEATH_HURTTRIGGER && inflictor.message != "")
-                               bprint ("^1",s, "^1 ", inflictor.message, "\n");
-                       else if (deathtype == DEATH_DROWN)
+                               msg = inflictor.message;
+                       else if (deathtype == DEATH_CUSTOM)
+                               msg = deathmessage;
+                               //bprint ("^1",s, "^1 ", inflictor.message, "\n");
+                       /*else if (deathtype == DEATH_DROWN)
                                if(sv_gentle)
                                        bprint ("^1",s, "^1 was in the water for too long\n");
                                else
@@ -578,8 +682,8 @@ void Obituary (entity attacker, entity inflictor, entity targ, float deathtype)
                                        bprint ("^1",s, "^1 is now conserved for centuries to come\n");
                        else if(deathtype == DEATH_TURRET)
                                bprint ("^1",s, "^1 was mowed down by a turret \n");
-            else if (deathtype == DEATH_CUSTOM)
-                bprint ("^1",s, "^1 ", deathmessage, "\n");
+                       else if (deathtype == DEATH_CUSTOM)
+                               bprint ("^1",s, "^1 ", deathmessage, "\n");
                        else if(deathtype == DEATH_TOUCHEXPLODE)
                                bprint ("^1",s, "^1 died in an accident\n");
                        else if(deathtype == DEATH_CHEAT)
@@ -594,16 +698,19 @@ void Obituary (entity attacker, entity inflictor, entity targ, float deathtype)
                                        bprint ("^1",s, "^1 needs a restart\n");
                                else
                                        bprint ("^1",s, "^1 died\n");
+                       */
                        GiveFrags(targ, targ, -1);
                        if(PlayerScore_Add(targ, SP_SCORE, 0) == -5) {
                                AnnounceTo(targ, "botlike");
                        }
+                       Send_KillNotification(s, msg, "", deathtype, MSG_KILL_ACTION);
 
                        if (targ.killcount > 2)
-                               if(sv_gentle)
-                                       bprint ("^1",s,"^1 needs a restart after a ",ftos(targ.killcount)," scoring spree\n");
-                               else
-                                       bprint ("^1",s,"^1 died with a ",ftos(targ.killcount)," kill spree\n");
+                               Send_KillNotification(s, ftos(targ.killcount), "", 0, MSG_KILL_ACTION_SPREE);
+                               //if(sv_gentle)
+                               //      bprint ("^1",s,"^1 needs a restart after a ",ftos(targ.killcount)," scoring spree\n");
+                               //else
+                               //      bprint ("^1",s,"^1 died with a ",ftos(targ.killcount)," kill spree\n");
 
                        LogDeath("accident", deathtype, targ, targ);
                }
@@ -864,8 +971,8 @@ void Damage (entity targ, entity inflictor, entity attacker, float damage, float
                                // if above view_ofs and below maxs, and also in the middle half of the bbox, it is head shot
                                vector headmins, headmaxs, org;
                                org = antilag_takebackorigin(targ, time - ANTILAG_LATENCY(attacker));
-                               headmins = org + '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);
-                               headmaxs = org + '0.6 0 0' * targ.maxs_x + '0 0.6 0' * targ.maxs_y + '0 0 1' * targ.maxs_z;
+                               headmins = org + GetHeadshotMins(targ);
+                               headmaxs = org + GetHeadshotMaxs(targ);
                                if(trace_hits_box(railgun_start, railgun_end, headmins, headmaxs))
                                {
                                        deathtype |= HITTYPE_HEADSHOT;