From f9fa6dd335236b46b5ea43747868c4da207c08dc Mon Sep 17 00:00:00 2001
From: Samual Lenks <samual@xonotic.org>
Date: Sun, 7 Oct 2012 03:21:43 -0400
Subject: [PATCH] Work more on Obituary notifications/deathtypes

---
 qcsrc/client/hud.qc        |   2 -
 qcsrc/common/deathtypes.qh |   1 -
 qcsrc/server/cl_player.qc  |   3 +-
 qcsrc/server/g_damage.qc   | 121 +++++++++++++++++++++++--------------
 4 files changed, 78 insertions(+), 49 deletions(-)

diff --git a/qcsrc/client/hud.qc b/qcsrc/client/hud.qc
index 87ba606084..e91e09e078 100644
--- a/qcsrc/client/hud.qc
+++ b/qcsrc/client/hud.qc
@@ -2077,8 +2077,6 @@ void HUD_KillCenterprint(string s1, string s2, float type, float msg)
 				centerprint_hud(_("^1Don't go against team mates!"));
 			else
 				centerprint_hud(_("^1Don't shoot your team mates!"));
-		} else if (type == DEATH_QUIET) {
-			// do nothing
 		} else { // generic message
 			if(gentle)
 				centerprint_hud(_("^1You need to be more careful!"));
diff --git a/qcsrc/common/deathtypes.qh b/qcsrc/common/deathtypes.qh
index dc243b35db..4a9fa0f2bc 100644
--- a/qcsrc/common/deathtypes.qh
+++ b/qcsrc/common/deathtypes.qh
@@ -36,7 +36,6 @@ float DT_COUNT;
 	DEATHTYPE(DEATH_TOUCHEXPLODE, FALSE, FALSE, NORMAL_POS) \
 	DEATHTYPE(DEATH_CHEAT, FALSE, FALSE, NORMAL_POS) \
 	DEATHTYPE(DEATH_FIRE, FALSE, FALSE, NORMAL_POS) \
-	DEATHTYPE(DEATH_QUIET, FALSE, FALSE, NORMAL_POS) \
 	DEATHTYPE(DEATH_VHCRUSH, FALSE, FALSE, DEATH_VHFIRST) \
 	DEATHTYPE(DEATH_SBMINIGUN, FALSE, FALSE, NORMAL_POS) \
 	DEATHTYPE(DEATH_SBROCKET, FALSE, FALSE, NORMAL_POS) \
diff --git a/qcsrc/server/cl_player.qc b/qcsrc/server/cl_player.qc
index 1d8bae6368..db82486b95 100644
--- a/qcsrc/server/cl_player.qc
+++ b/qcsrc/server/cl_player.qc
@@ -1417,12 +1417,13 @@ 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);
 
+	// TODO FIXME FIXNOTIF
 	if not(show_message & 1) // admin message
 		sprint(client, strcat("\{1}\{13}^3", admin_name(), "^7: You have been moved to the ", Team_ColorName_Lower(team_colour), " team\n"));  // send a chat message
 
diff --git a/qcsrc/server/g_damage.qc b/qcsrc/server/g_damage.qc
index 3a211853c4..3ef5346636 100644
--- a/qcsrc/server/g_damage.qc
+++ b/qcsrc/server/g_damage.qc
@@ -308,76 +308,107 @@ void LogDeath(string mode, float deathtype, entity killer, entity killed)
 	GameLogEcho(s);
 }
 
-void Obituary_Notification(entity notif_target, string s1, string s2, string s3, float deathtype)
+string Deathtype_Name(float deathtype)
 {
-	/*if(deathtype)
+	if(DEATH_ISSPECIAL(deathtype))
 	{
-		#define DEATHTYPE(name,type,notification,first,last) \
-			{ if((deathtype == max(0, name)) && max(0, type) && max(0, notification)) { Send_Notification(type, notif_target, notification, s1, s2, s3); return; } }
+		#define DEATHTYPE(name,msg_info,msg_center,position) \
+			{ if(deathtype == max(0, name)) return VAR_TO_TEXT(name); }
+
+		DEATHTYPES
+	}
+	return "foobar";
+}
+
+void Obituary_SpecialDeath(entity notif_target, float deathtype, string s1, string s2, float f1, float f2, float f3)
+{
+	if(DEATH_ISSPECIAL(deathtype))
+	{
+		#define DEATHTYPE(name,msg_info,msg_center,position) \
+			{ if(deathtype == max(0, name)) \
+			{ \
+				if(max(0, msg_info)) { Send_Notification(world, MSG_INFO, msg_info, s1, s2, f1, f2, f3); } \
+				if(max(0, msg_center)) { Send_Notification(notif_target, MSG_CENTER, msg_center, s1, s2, f1, f2, f3); } \
+				return; \
+			} }
 
 		DEATHTYPES
 		backtrace("Unhandled deathtype. Please notify Samual!\n");
-	}*/
+	}
 }
 
-void Obituary (entity attacker, entity inflictor, entity targ, float deathtype)
+void Obituary(entity attacker, entity inflictor, entity targ, float deathtype)
 {
+	print(sprintf("Obituary(): Deathtype = %s (%d), Attacker = %s, Inflictor = %s, Target = %s...\n", Deathtype_Name(deathtype), deathtype, attacker.netname, inflictor.netname, targ.netname));
 	string	s, a, msg;
 	float w, type;
 
-	string s1, s2, s3;
+	string s1, s2;
+	float f1, f2, f3;
 
 	if (targ.classname == "player")
 	{
-		s = targ.netname;
-		a = attacker.netname;
-
 		if (targ == attacker) // suicides
 		{
-			s1 = ((deathtype == DEATH_TEAMCHANGE || deathtype == DEATH_AUTOTEAMCHANGE) ? Team_ColoredFullName(targ.team) : "");
-
-			// no "killed your own dumb self" message in CTS
-            if(!g_cts) { Obituary_Notification(targ, s1, "", "", deathtype); }
+			if(DEATH_ISSPECIAL(deathtype))
+			{
+				if(deathtype == DEATH_TEAMCHANGE || deathtype == DEATH_AUTOTEAMCHANGE)
+				{
+					s1 = targ.netname;
+					f1 = targ.team;
+					f2 = NO_FL_ARG;
+				}
+				else
+				{
+					if(deathtype == DEATH_MIRRORDAMAGE)
+					{
+						s1 = targ.netname;
+						f1 = targ.team;
+						f2 = targ.killcount;
+					}
+					else
+					{
+						s1 = targ.netname;
+						f1 = targ.killcount;
+						f2 = NO_FL_ARG;
+					}
+					
+					// Do this manually inside of each if statement where necessary,
+					// DEATH_TEAMCHANGE and such are not supposed to have this.
+					LogDeath("suicide", deathtype, targ, targ);
+					GiveFrags(attacker, targ, -1, deathtype);
+				}
 
-			if(deathtype != DEATH_TEAMCHANGE && deathtype != DEATH_QUIET)
+				Obituary_SpecialDeath(targ, deathtype, s1, NO_STR_ARG, f1, f2, NO_FL_ARG);
+			}
+			else if(DEATH_WEAPONOF(deathtype))
 			{
-				LogDeath("suicide", deathtype, targ, targ);
-				GiveFrags(attacker, targ, -1, deathtype);
+				print("death was a weapon!\n");
+			}
+			else
+			{
+				backtrace("what the hell happened here?\n");
 			}
-
-			s1 = targ.netname;
-			s2 = ((targ.killcount > 2) ? ftos(targ.killcount) : "");
-				
-			//if(teamplay && deathtype == DEATH_MIRRORDAMAGE)
-			//	{ deathtype = ((attacker.team == FL_TEAM_1) ? KILL_TEAM_SUICIDE_RED : KILL_TEAM_SUICIDE_BLUE); }
-
-			Obituary_Notification(world, s1, s2, "", deathtype);
-			//Send_KillNotification(s, s2, ftos(w), deathtype, MSG_SUICIDE);
 		}
-		else if (attacker.classname == "player")
+		else if(attacker.classname == "player")
 		{
 			if(!IsDifferentTeam(attacker, targ))
 			{
-				//type = ((attacker.team == FL_TEAM_1) ? KILL_TEAM_FRAG_RED : KILL_TEAM_FRAG_BLUE);
-
-				GiveFrags(attacker, targ, -1, deathtype);
-
-				//Send_CSQC_KillCenterprint(attacker, s, "", type);
-
-				if (targ.killcount > 2)
-					msg = ftos(targ.killcount);
+				if(DEATH_ISSPECIAL(deathtype))
+				{
+					print("hmm death was special?\n");
+				}
+				else if(DEATH_WEAPONOF(deathtype))
+				{
+					print("death was a weapon!\n");
+				}
 				else
-					msg = "";
-
-				if (attacker.killcount > 2) {
-					msg = ftos(attacker.killcount);
-					type = KILL_TEAM_SPREE;
+				{
+					backtrace("what the hell happened here?\n");
 				}
-				Send_KillNotification(a, s, msg, type, MSG_KILL);
-
-				attacker.killcount = 0;
-
+				
 				LogDeath("tk", deathtype, attacker, targ);
+				GiveFrags(attacker, targ, -1, deathtype);
 			}
 			else
 			{
@@ -547,7 +578,7 @@ void Damage (entity targ, entity inflictor, entity attacker, float damage, float
 			}
 	}
 
-	if(deathtype == DEATH_KILL || deathtype == DEATH_TEAMCHANGE || deathtype == DEATH_AUTOTEAMCHANGE || deathtype == DEATH_QUIET)
+	if(deathtype == DEATH_KILL || deathtype == DEATH_TEAMCHANGE || deathtype == DEATH_AUTOTEAMCHANGE)
 	{
 		// These are ALWAYS lethal
 		// No damage modification here
-- 
2.39.5