From b846591d474a2012722ccae237e87923fae77848 Mon Sep 17 00:00:00 2001
From: Samual Lenks <samual@xonotic.org>
Date: Fri, 8 Feb 2013 18:40:43 -0500
Subject: [PATCH] Transfer the switch into yet another macro

---
 qcsrc/common/notifications.qc | 48 ++++++-----------------------------
 qcsrc/common/notifications.qh |  7 +++++
 2 files changed, 15 insertions(+), 40 deletions(-)

diff --git a/qcsrc/common/notifications.qc b/qcsrc/common/notifications.qc
index 994b5d7e46..fdd93459ab 100644
--- a/qcsrc/common/notifications.qc
+++ b/qcsrc/common/notifications.qc
@@ -25,11 +25,7 @@ string Get_Field_Value(float field, float net_type, float net_name)
 		{
 			#define MSG_INFO_NOTIF(name,strnum,flnum,args,hudargs,icon,normal,gentle) case name: { GET_FIELD_VALUE_OUTPUT(field,name,strnum,flnum) }
 				
-			switch(net_name)
-			{
-				MSG_INFO_NOTIFICATIONS
-				default: { backtrace(strcat("^1NOTIFICATION HAD NO MATCH: ^7net_type = MSG_INFO, net_name = ", ftos(net_name), ".\n")); return ""; }
-			}
+			NOTIF_SWITCH_LIST(MSG_INFO, net_name, return "")
 			
 			#undef MSG_INFO_NOTIF
 			break;
@@ -38,11 +34,7 @@ string Get_Field_Value(float field, float net_type, float net_name)
 		{
 			#define MSG_CENTER_NOTIF(name,strnum,flnum,args,cpid,durcnt,normal,gentle) case name: { GET_FIELD_VALUE_OUTPUT(field,name,strnum,flnum) }
 
-			switch(net_name)
-			{
-				MSG_CENTER_NOTIFICATIONS
-				default: { backtrace(strcat("^1NOTIFICATION HAD NO MATCH: ^7net_type = MSG_CENTER, net_name = ", ftos(net_name), ".\n")); return ""; }
-			}
+			NOTIF_SWITCH_LIST(MSG_CENTER, net_name, return "")
 			
 			#undef MSG_CENTER_NOTIF
 			break;
@@ -53,11 +45,7 @@ string Get_Field_Value(float field, float net_type, float net_name)
 				max(CLPSE_GETVALUE(infoname, MSG_INFO, F_STRNUM), CLPSE_GETVALUE(centername, MSG_CENTER, F_STRNUM)), \
 				max(CLPSE_GETVALUE(infoname, MSG_INFO, F_FLNUM), CLPSE_GETVALUE(centername, MSG_CENTER, F_FLNUM))) }
 				
-			switch(net_name)
-			{
-				MSG_WEAPON_NOTIFICATIONS
-				default: { backtrace(strcat("^1NOTIFICATION HAD NO MATCH: ^7net_type = MSG_WEAPON, net_name = ", ftos(net_name), ".\n")); return ""; }
-			}
+			NOTIF_SWITCH_LIST(MSG_WEAPON, net_name, return "")
 			
 			#undef MSG_WEAPON_NOTIF
 			break;
@@ -68,11 +56,7 @@ string Get_Field_Value(float field, float net_type, float net_name)
 				max(CLPSE_GETVALUE(infoname, MSG_INFO, F_STRNUM), CLPSE_GETVALUE(centername, MSG_CENTER, F_STRNUM)), \
 				max(CLPSE_GETVALUE(infoname, MSG_INFO, F_FLNUM), CLPSE_GETVALUE(centername, MSG_CENTER, F_FLNUM))) }
 				
-			switch(net_name)
-			{
-				MSG_DEATH_NOTIFICATIONS
-				default: { backtrace(strcat("^1NOTIFICATION HAD NO MATCH: ^7net_type = MSG_DEATH, net_name = ", ftos(net_name), ".\n")); return ""; }
-			}
+			NOTIF_SWITCH_LIST(MSG_DEATH, net_name, return "")
 			
 			#undef MSG_DEATH_NOTIF
 			break;
@@ -174,11 +158,7 @@ void Local_Notification(float net_type, float net_name, ...count)
 						#endif \
 					} return; }
 					
-				switch(net_name)
-				{
-					MSG_INFO_NOTIFICATIONS
-					default: { backtrace(strcat("^1NOTIFICATION HAD NO MATCH: ^7net_type = MSG_INFO, net_name = ", ftos(net_name), ".\n")); return; }
-				}
+				NOTIF_SWITCH_LIST(MSG_INFO, net_name, return)
 				
 				#undef MSG_INFO_NOTIF
 				break;
@@ -192,11 +172,7 @@ void Local_Notification(float net_type, float net_name, ...count)
 						centerprint_generic(HANDLE_CPID(cpid), sprintf(CCR(normal_or_gentle(normal, gentle)), args), durcnt); \
 					} return; }
 
-				switch(net_name)
-				{
-					MSG_CENTER_NOTIFICATIONS
-					default: { backtrace(strcat("^1NOTIFICATION HAD NO MATCH: ^7net_type = MSG_CENTER, net_name = ", ftos(net_name), ".\n")); return; }
-				}
+				NOTIF_SWITCH_LIST(MSG_CENTER, net_name, return)
 				
 				#undef MSG_CENTER_NOTIF
 				break;
@@ -223,11 +199,7 @@ void Local_Notification(float net_type, float net_name, ...count)
 						#endif \
 					} return; }
 
-				switch(net_name)
-				{
-					MSG_WEAPON_NOTIFICATIONS
-					default: { backtrace(strcat("^1NOTIFICATION HAD NO MATCH: ^7net_type = MSG_WEAPON, net_name = ", ftos(net_name), ".\n")); return; }
-				}
+				NOTIF_SWITCH_LIST(MSG_WEAPON, net_name, return)
 				
 				#undef MSG_WEAPON_NOTIF
 				break;
@@ -253,11 +225,7 @@ void Local_Notification(float net_type, float net_name, ...count)
 						#endif \
 					} return; } 
 
-				switch(net_name)
-				{
-					MSG_DEATH_NOTIFICATIONS
-					default: { backtrace(strcat("^1NOTIFICATION HAD NO MATCH: ^7net_type = MSG_DEATH, net_name = ", ftos(net_name), ".\n")); return; }
-				}
+				NOTIF_SWITCH_LIST(MSG_DEATH, net_name, return)
 				
 				#undef MSG_DEATH_NOTIF
 				break;
diff --git a/qcsrc/common/notifications.qh b/qcsrc/common/notifications.qh
index a1f2e7e462..d3a93ea0e9 100644
--- a/qcsrc/common/notifications.qh
+++ b/qcsrc/common/notifications.qh
@@ -89,6 +89,13 @@ string got_commandkey;
 #define ADD_AUTOCVAR(name) var float autocvar_notification_##name = TRUE;
 #define CHECK_AUTOCVAR(name) if(autocvar_notification_##name)
 
+#define NOTIF_SWITCH_LIST(net_type,net_name,returnv) \
+	switch(net_name) \
+	{ \
+		##net_type##_NOTIFICATIONS \
+		default: { backtrace(strcat("^1NOTIFICATION HAD NO MATCH: ^7net_type = ##net_type##, net_name = ", ftos(net_name), ".\n")); returnv; } \
+	}
+
 string Get_Field_Value(float field, float net_type, float net_name); // get the actual name of a notification and return it as a string
 void Local_Notification(float net_type, float net_name, ...count);
 void Local_Notification_Without_VarArgs(float net_type, float net_name, float stringcount, float floatcount, string s1, string s2, string s3, string s4, float f1, float f2, float f3, float f4);
-- 
2.39.5