From 7677c63cfb68a3157c4a15f57777d1f97713a6ba Mon Sep 17 00:00:00 2001
From: Samual Lenks <samual@xonotic.org>
Date: Sat, 2 Mar 2013 19:43:12 -0500
Subject: [PATCH] Move the rest of race notifications over to new system

---
 qcsrc/common/notifications.qh | 19 +++++++------
 qcsrc/server/race.qc          | 50 ++++++++++++++---------------------
 2 files changed, 31 insertions(+), 38 deletions(-)

diff --git a/qcsrc/common/notifications.qh b/qcsrc/common/notifications.qh
index bb6d1fe8c..6bbbfa94e 100644
--- a/qcsrc/common/notifications.qh
+++ b/qcsrc/common/notifications.qh
@@ -290,11 +290,12 @@ void Send_CSQC_Centerprint_Generic(entity e, float id, string s, float duration,
 	MSG_INFO_NOTIF(2, INFO_QUIT_KICK_IDLING,				1, 0, "s1", "",							"",						_("^BG%s^F3 was kicked for idling\n"), "") \
 	MSG_INFO_NOTIF(1, INFO_QUIT_KICK_SPECTATING,			0, 0, "", "",							"",						_("^F2You were kicked from the server because you are a spectator and spectators aren't allowed at the moment.\n"), "") \
 	MSG_INFO_NOTIF(2, INFO_QUIT_SPECTATE,					1, 0, "s1", "",							"",						_("^BG%s^F3 is now spectating\n"), "") \
-	MSG_INFO_NOTIF(1, INFO_RACE_FAIL_RANKED,				1, 3, "s1 f1ord race_time race_diff", "s1",		"race_newfail",	_("^BG%s^BG couldn't break their %s place record of %s %s\n"), "") \
-	MSG_INFO_NOTIF(1, INFO_RACE_FAIL_UNRANKED,				1, 3, "s1 f1ord race_time race_diff", "s1",		"race_newfail",	_("^BG%s^BG couldn't break the %s place record of %s %s\n"), "") \
-	MSG_INFO_NOTIF(1, INFO_RACE_NEW_RECORD,					2, 0, "s1 s2", "s1",					"race_newrecordserver",	"TODO\n", "") \
-	MSG_INFO_NOTIF(1, INFO_RACE_NEW_TIME,					2, 0, "s1 s2", "s1",					"race_newtime",			"TODO\n", "") \
-	MSG_INFO_NOTIF(1, INFO_RACE_NEW_RANK,					2, 0, "s1 s2", "s1",					"race_newrankyellow",	"TODO\n", "") \
+	MSG_INFO_NOTIF(1, INFO_RACE_FAIL_RANKED,				1, 3, "s1 race_col f1ord race_col f2race_time race_diff", "s1", 			"race_newfail",				_("^BG%s^BG couldn't break their %s%s^BG place record of %s%s %s\n"), "") \
+	MSG_INFO_NOTIF(1, INFO_RACE_FAIL_UNRANKED,				1, 3, "s1 race_col f1ord race_col f2race_time race_diff", "s1", 			"race_newfail",				_("^BG%s^BG couldn't break the %s%s^BG place record of %s%s %s\n"), "") \
+	MSG_INFO_NOTIF(1, INFO_RACE_NEW_MISSING_UID,			1, 1, "s1 f1race_time", "s1", 												"race_newfail",				_("^BG%s^BG scored a new record with ^F2%s^BG, but unfortunately lacks a UID and will be lost.\n"), "") \
+	MSG_INFO_NOTIF(1, INFO_RACE_NEW_IMPROVED,				1, 3, "s1 race_col f1ord race_col f2race_time race_diff", "s1",				"race_newtime",				_("^BG%s^BG improved their %s%s^BG place record with %s%s %s\n"), "") \
+	MSG_INFO_NOTIF(1, INFO_RACE_NEW_SET,					1, 2, "s1 race_col f1ord race_col f2race_time", "s1",						"race_newrecordserver",		_("^BG%s^BG set the %s%s^BG place record with %s%s\n"), "") \
+	MSG_INFO_NOTIF(1, INFO_RACE_NEW_BROKEN,					2, 3, "s1 s2 race_col f1ord race_col f2race_time race_diff", "s1 s2", 		"race_newrankyellow", 		_("^BG%s^BG broke %s^BG's %s%s^BG place record with %s%s %s\n"), "") \
 	MULTITEAM_INFO(1, INFO_SCORES_, 4,						0, 0, "", "",							"",						_("^TC^TT ^BGteam scores!\n"), "") \
 	MSG_INFO_NOTIF(1, INFO_SPECTATE_WARNING,				0, 1, "f1", "",							"",						_("^F2You have to become a player within the next %s seconds, otherwise you will be kicked, because spectating isn't allowed at this time!\n"), "") \
 	MSG_INFO_NOTIF(1, INFO_SUPERWEAPON_PICKUP,				0, 0, "s1", "s1",						"strength",				_("^BG%s^K1 picked up a Superweapon\n"), "") \
@@ -712,6 +713,10 @@ string arg_slot[NOTIF_MAX_ARGS];
 	ARG_CASE(ARG_CS, 			"f1secs",			count_seconds(f1)) \
 	ARG_CASE(ARG_CS_SV,			"f1ord",			count_ordinal(f1)) \
 	ARG_CASE(ARG_CS,			"f1time",			process_time("todo", f1)) \
+	ARG_CASE(ARG_CS_SV,			"f1race_time",		mmssss(f1)) \
+	ARG_CASE(ARG_CS_SV,			"f2race_time",		mmssss(f2)) \
+	ARG_CASE(ARG_CS_SV,			"race_col",			CCR(((f1 == 1) ? "^F1" : "^F2"))) \
+	ARG_CASE(ARG_CS_SV, 		"race_diff",		((f2 > f3) ? sprintf(CCR("^1[+%s]"), mmssss(f2 - f3)) : sprintf(CCR("^2[-%s]"), mmssss(f3 - f2)))) \
 	ARG_CASE(ARG_CS, 			"pass_key", 		((((tmp_s = getcommandkey("pass", "+use")) != "pass") && !(strstrofs(tmp_s, "not bound", 0) >= 0)) ? sprintf(CCR(_(" ^F1(Press %s)")), tmp_s) : "")) \
 	ARG_CASE(ARG_CS, 			"frag_ping", 		((f2 != NO_MSG) ? sprintf(CCR(_("\n(Ping ^2%d^BG)")), f2) : "")) \
 	ARG_CASE(ARG_CS, 			"frag_stats", 		sprintf(CCR(_("\n(Health ^1%d^BG / Armor ^2%d^BG)%s")), f2, f3, ((f4 != NO_MSG) ? sprintf(CCR(_(" (Ping ^2%d^BG)")), f4) : ""))) \
@@ -725,9 +730,7 @@ string arg_slot[NOTIF_MAX_ARGS];
 	ARG_CASE(ARG_DC,			"item_centime", 	ftos(autocvar_notification_item_centerprinttime)) \
 	ARG_CASE(ARG_SV, 			"death_team", 		Team_ColoredFullName(f1)) \
 	ARG_CASE(ARG_CS, 			"death_team", 		Team_ColoredFullName(f1 - 1)) \
-	ARG_CASE(ARG_CS, 			"kh_teams", 		notif_arg_kh_teams(f1, f2, f3, f4)) \
-	ARG_CASE(ARG_CS_SV,			"race_time",		mmssss(f2)) \
-	ARG_CASE(ARG_CS_SV, 		"race_diff",		((f2 > f3) ? sprintf(CCR("^1[+%s]"), mmssss(f2 - f3)) : sprintf(CCR("^2[-%s]"), mmssss(f3 - f2))))
+	ARG_CASE(ARG_CS, 			"kh_teams", 		notif_arg_kh_teams(f1, f2, f3, f4))
 
 #define NOTIF_HIT_MAX(count,funcname) if(sel_num == count) { backtrace(sprintf("%s: Hit maximum arguments!\n", funcname)); break; }
 #define NOTIF_HIT_UNKNOWN(token,funcname) { backtrace(sprintf("%s: Hit unknown token in selected string! '%s'\n", funcname, selected)); break; }
diff --git a/qcsrc/server/race.qc b/qcsrc/server/race.qc
index 193d821e2..752cb1478 100644
--- a/qcsrc/server/race.qc
+++ b/qcsrc/server/race.qc
@@ -149,7 +149,7 @@ void race_setTime(string map, float t, string myuid, string mynetname, entity e)
 	}
 
 	float oldrec;
-	string recorddifference, oldrec_holder;
+	string oldrec_holder;
 	if (player_prevpos && (player_prevpos < newpos || !newpos))
 	{
 		oldrec = race_readTime(GetMapname(), player_prevpos);
@@ -168,7 +168,7 @@ void race_setTime(string map, float t, string myuid, string mynetname, entity e)
 	// if the player does not have a UID we can unfortunately not store the record, as the rankings system relies on UIDs
 	if(myuid == "")
 	{
-		bprint(mynetname, "^1 scored a new record with ^7", TIME_ENCODED_TOSTRING(t), "^1, but lacks a UID, so the record will unfortunately be lost.\n");
+		Send_Notification(NOTIF_ALL, world, MSG_INFO, INFO_RACE_NEW_MISSING_UID, mynetname, t);
 		return;
 	}
 
@@ -187,34 +187,24 @@ void race_setTime(string map, float t, string myuid, string mynetname, entity e)
 	if(rankings_reply)
 		strunzone(rankings_reply);
 	rankings_reply = strzone(getrankings());
-	if(newpos == 1) {
-		if(newpos == player_prevpos) {
-			recorddifference = strcat(" ^2[-", TIME_ENCODED_TOSTRING(oldrec - t), "]");
-			bprint(mynetname, "^1 improved their 1st place record with ", TIME_ENCODED_TOSTRING(t), recorddifference, "\n");
-		} else if (oldrec == 0) {
-			bprint(mynetname, "^1 set the 1st place record with ", TIME_ENCODED_TOSTRING(t), "\n");
-		} else {
-			recorddifference = strcat(" ^2[-", TIME_ENCODED_TOSTRING(oldrec - t), "]");
-			bprint(mynetname, "^1 broke ", oldrec_holder, "^1's 1st place record with ", strcat(TIME_ENCODED_TOSTRING(t), recorddifference, "\n"));
-		}
-		race_SendStatus(3, e); // "new server record"
-		Send_Notification(NOTIF_ALL, world, MSG_INFO, INFO_RACE_NEW_RECORD, e.netname, TIME_ENCODED_TOSTRING(t));
-	} else {
-		if(newpos == player_prevpos) {
-			recorddifference = strcat(" ^2[-", TIME_ENCODED_TOSTRING(oldrec - t), "]");
-			bprint(mynetname, "^5 improved their ", race_placeName(newpos), " ^5place record with ", TIME_ENCODED_TOSTRING(t), recorddifference, "\n");
-			race_SendStatus(1, e); // "new time"
-			Send_Notification(NOTIF_ALL, world, MSG_INFO, INFO_RACE_NEW_TIME, e.netname, TIME_ENCODED_TOSTRING(t));
-		} else if (oldrec == 0) {
-			bprint(mynetname, "^2 set the ", race_placeName(newpos), " ^2place record with ", TIME_ENCODED_TOSTRING(t), "\n");
-			race_SendStatus(2, e); // "new rank"
-			Send_Notification(NOTIF_ALL, world, MSG_INFO, INFO_RACE_NEW_RANK, e.netname, TIME_ENCODED_TOSTRING(t));
-		} else {
-			recorddifference = strcat(" ^2[-", TIME_ENCODED_TOSTRING(oldrec - t), "]");
-			bprint(mynetname, "^2 broke ", oldrec_holder, "^2's ", race_placeName(newpos), " ^2place record with ", strcat(TIME_ENCODED_TOSTRING(t), recorddifference, "\n"));
-			race_SendStatus(2, e); // "new rank"
-			Send_Notification(NOTIF_ALL, world, MSG_INFO, INFO_RACE_NEW_RANK, e.netname, TIME_ENCODED_TOSTRING(t));
-		}
+	
+	if(newpos == player_prevpos)
+	{
+		Send_Notification(NOTIF_ALL, world, MSG_INFO, INFO_RACE_NEW_IMPROVED, mynetname, newpos, t, oldrec);
+		if(newpos == 1) { race_SendStatus(3, e); } // "new server record"
+		else { race_SendStatus(1, e); } // "new time"
+	}
+	else if(oldrec == 0)
+	{
+		Send_Notification(NOTIF_ALL, world, MSG_INFO, INFO_RACE_NEW_SET, mynetname, newpos, t);
+		if(newpos == 1) { race_SendStatus(3, e); } // "new server record"
+		else { race_SendStatus(2, e); } // "new rank"
+	}
+	else
+	{
+		Send_Notification(NOTIF_ALL, world, MSG_INFO, INFO_RACE_NEW_BROKEN, mynetname, oldrec_holder, newpos, t, oldrec);
+		if(newpos == 1) { race_SendStatus(3, e); } // "new server record"
+		else { race_SendStatus(2, e); } // "new rank"
 	}
 }
 
-- 
2.39.5