1 // ================================================
2 // Unified notification system, written by Samual
3 // Last updated: September, 2012
4 // ================================================
6 // main types/groups of notifications
7 #define MSG_INFO 1 // "Global" information messages (sent to console)
8 #define MSG_NOTIFY 2 // "Global" events to be sent to the notification panel
9 #define MSG_CENTER 3 // "Personal" centerprint messages
10 #define MSG_WEAPON 4 // "Personal" weapon messages (like "You got the Nex", sent to weapon notify panel)
12 // expand multiple arguments into one argument
13 #define XPND4(a,b,c,d) a, b, c, d
14 #define XPND3(a,b,c) a, b, c
15 #define XPND2(a,b) a, b
17 // allow sending of notifications to also pass through to spectators (specifically for centerprints)
19 #define WRITESPECTATABLE_MSG_ONE_VARNAME(varname,statement) entity varname; varname = msg_entity; FOR_EACH_REALCLIENT(msg_entity) if(msg_entity == varname || (msg_entity.classname == STR_SPECTATOR && msg_entity.enemy == varname)) statement msg_entity = varname
20 #define WRITESPECTATABLE_MSG_ONE(statement) WRITESPECTATABLE_MSG_ONE_VARNAME(oldmsg_entity, statement)
21 #define WRITESPECTATABLE(msg,statement) if(msg == MSG_ONE) { WRITESPECTATABLE_MSG_ONE(statement); } else statement float WRITESPECTATABLE_workaround = 0
24 #define HANDLE_CPID(cpid) ((min(NOTIF_MAX, cpid) == NO_CPID) ? FALSE : cpid)
25 #define CHECK_MATCH(a,b) if(min(NOTIF_MAX, a) == b)
26 #define VAR_TO_TEXT(var) #var
29 // ====================================
30 // Notifications List and Information
31 // ====================================
33 List of all notifications (including identifiers and display information)
34 Format: name, args, *icon/CPID, *durcnt, normal, gentle
35 Asterisked fields are not present in all notification types.
38 Arguments for sprintf(string, args), if no args needed then use ""
40 MSG_NOTIFY: STRING: icon string name for the hud notify panel, "" if no icon is used
41 MSG_CENTER: FLOAT: centerprint ID number (CPID_*), NO_CPID if no CPID is needed
43 MSG_CENTER: XPND2(FLOAT, FLOAT): extra arguments for centerprint messages
44 Normal message (string for sprintf when gentle messages are NOT enabled)
45 Gentle message (string for sprintf when gentle messages ARE enabled)
47 Messages have ^F1, ^F2, and ^BG in them-- these are replaced
48 with colors according to the cvars the user has chosen.
49 ^F1 = highest priority, "primary"
50 ^F2 = next highest priority, "secondary"
51 ^BG = normal/less important priority, "tertiary"
53 Guidlines (please try and follow these):
54 ALWAYS start the string with a color, preferably background.
55 ALWAYS end messages with a new line.
56 ALWAYS properly use tab spacing to even out the notifications.
57 NEVER re-declare an event twice.
58 NEVER add or remove fields from the format, it SHOULD already work.
59 ARIRE unir frk jvgu lbhe bja zbgure. (gvc sbe zvxrrhfn) -- Don't pay attention to this ^_^
60 Be clean and simple with your notification naming, nothing too long.
61 Keep the notifications in alphabetical order.
63 #define MSG_INFO_NOTIFICATIONS \
64 MSG_INFO_NOTIF(DEATH_MARBLES_LOST, XPND3(s1, s2, s3), _("^F1%s^BG lost their marbles against ^F1%s^BG using the ^F2%s^BG\n"), "") \
67 #define MSG_NOTIFY_NOTIFICATIONS \
68 MSG_NOTIFY_NOTIF(DEATH_MARBLES_LOST2, XPND3(s1, s2, s3), "notify_death", _("^F1%s^BG lost their marbles against ^F1%s^BG using the ^F2%s^BG\n"), "") \
69 #undef MSG_NOTIFY_NOTIF
71 #define MSG_CENTER_NOTIFICATIONS \
72 MSG_CENTER_NOTIF(CENTER_CTF_CAPTURESHIELD_SHIELDED, "", CPID_CTF_CAPTURESHIELD, XPND2(0, 0), _("^BGYou are now ^F1shielded^BG from the flag\n^BGfor ^F2too many unsuccessful attempts^BG to capture.\n^BGMake some defensive scores before trying again."), "") \
73 MSG_CENTER_NOTIF(CENTER_CTF_CAPTURESHIELD_FREE, "", CPID_CTF_CAPTURESHIELD, XPND2(0, 0), _("^BGYou are now free.\n^BGFeel free to ^F2try to capture^BG the flag again\n^BGif you think you will succeed."), "") \
74 MSG_CENTER_NOTIF(CENTER_CTF_EVENT_PASS, XPND2(s1, s2, s3), CPID_CTF_PASS, XPND2(0, 0), _("^BG%s passed the ^F1%s^BG to %s"), "") \
75 MSG_CENTER_NOTIF(CENTER_CTF_EVENT_PASS_SENT, XPND2(s1, s2), CPID_CTF_PASS, XPND2(0, 0), _("^BGYou passed the ^F1%s^BG to %s"), "") \
76 MSG_CENTER_NOTIF(CENTER_CTF_EVENT_PASS_RECEIVED, XPND2(s1, s2), CPID_CTF_PASS, XPND2(0, 0), _("^BGYou received the ^F1%s^BG from %s"), "") \
77 MSG_CENTER_NOTIF(CENTER_CTF_EVENT_RETURN, s1, CPID_CTF_LOWPRIO, XPND2(0, 0), _("^BGYou returned the ^F1%s"), "") \
78 MSG_CENTER_NOTIF(CENTER_CTF_EVENT_CAPTURE, s1, NO_CPID, XPND2(0, 0), _("^BGYou captured the ^F1%s"), "") \
79 #undef MSG_CENTER_NOTIF
81 #define MSG_WEAPON_NOTIFICATIONS \
82 MSG_WEAPON_NOTIF(DEATH_MARBLES_LOST3, XPND3(s1, s2, s3), _("^F1%s^BG lost their marbles against ^F1%s^BG using the ^F2%s^BG\n"), "") \
83 #undef MSG_WEAPON_NOTIF
86 // ====================================
87 // Initialization/Create Declarations
88 // ====================================
91 #define NOTIF_MAX 1024 // limit of recursive functions with ACCUMULATE_FUNCTION
92 float NOTIF_INFO_COUNT;
93 float NOTIF_NOTIFY_COUNT;
94 float NOTIF_CENTER_COUNT;
95 float NOTIF_WEAPON_COUNT;
96 float NOTIF_CPID_COUNT;
98 #define CHECK_FIELD_AND_COUNT(field,count) if(!field) { field = (NOTIF_FIRST + count); ++count; }
99 #define CHECK_MAX_NOTIFICATIONS(count) if(count == NOTIF_MAX) { error("Maximum notifications hit!\n"); }
101 #define MSG_INFO_NOTIF(name,args,normal,gentle) \
103 void DecNotif_##name() \
105 CHECK_FIELD_AND_COUNT(name, NOTIF_INFO_COUNT) \
106 CHECK_MAX_NOTIFICATIONS(NOTIF_INFO_COUNT) \
108 ACCUMULATE_FUNCTION(DecNotifs, DecNotif_##name)
110 #define MSG_NOTIFY_NOTIF(name,args,icon,normal,gentle) \
112 void DecNotif_##name() \
114 CHECK_FIELD_AND_COUNT(name, NOTIF_NOTIFY_COUNT) \
115 CHECK_MAX_NOTIFICATIONS(NOTIF_NOTIFY_COUNT) \
117 ACCUMULATE_FUNCTION(DecNotifs, DecNotif_##name)
119 #define MSG_CENTER_NOTIF(name,args,cpid,durcnt,normal,gentle) \
122 void DecNotif_##name() \
124 CHECK_FIELD_AND_COUNT(name, NOTIF_CENTER_COUNT) \
125 CHECK_FIELD_AND_COUNT(cpid, NOTIF_CPID_COUNT) \
126 CHECK_MAX_NOTIFICATIONS(NOTIF_CENTER_COUNT) \
128 ACCUMULATE_FUNCTION(DecNotifs, DecNotif_##name)
130 #define MSG_WEAPON_NOTIF(name,args,normal,gentle) \
132 void DecNotif_##name() \
134 CHECK_FIELD_AND_COUNT(name, NOTIF_WEAPON_COUNT) \
135 CHECK_MAX_NOTIFICATIONS(NOTIF_WEAPON_COUNT) \
137 ACCUMULATE_FUNCTION(DecNotifs, DecNotif_##name)
139 // NOW we actually activate the declarations
140 MSG_INFO_NOTIFICATIONS
141 MSG_NOTIFY_NOTIFICATIONS
142 MSG_CENTER_NOTIFICATIONS
143 MSG_WEAPON_NOTIFICATIONS
146 // ======================
147 // Supporting Functions
148 // ======================
150 // select between the normal or the gentle message string based on client (or server) settings
151 string normal_or_gentle(string normal, string gentle)
154 if(autocvar_cl_gentle || autocvar_cl_gentle_messages)
156 if(autocvar_sv_gentle)
158 return ((gentle != "") ? gentle : normal);
163 // get the actual name of a notification and return it as a string
164 string Get_Notif_Name(float net_type, float net_name)
170 #define MSG_INFO_NOTIF(name,args,normal,gentle) \
171 { CHECK_MATCH(name,net_name) { return VAR_TO_TEXT(name); } }
172 MSG_INFO_NOTIFICATIONS
177 #define MSG_NOTIFY_NOTIF(name,args,icon,normal,gentle) \
178 { CHECK_MATCH(name,net_name) { return VAR_TO_TEXT(name); } }
179 MSG_NOTIFY_NOTIFICATIONS
184 #define MSG_CENTER_NOTIF(name,args,cpid,durcnt,normal,gentle) \
185 { CHECK_MATCH(name,net_name) { return VAR_TO_TEXT(name); } }
186 MSG_CENTER_NOTIFICATIONS
191 #define MSG_WEAPON_NOTIF(name,args,normal,gentle) \
192 { CHECK_MATCH(name,net_name) { return VAR_TO_TEXT(name); } }
193 MSG_WEAPON_NOTIFICATIONS
201 // color code replace, place inside of sprintf and parse the string
202 string CCR(string input)
204 input = strreplace("^F1", "^3", input);
205 input = strreplace("^F2", "^2", input);
206 input = strreplace("^BG", "^7", input);
208 input = strreplace("^N", "^7", input); // "none"-- reset to white
214 // ===============================
215 // Frontend Notification Pushing
216 // ===============================
219 void Local_Notification(float net_type, float net_name, string s1, string s2, string s3)
225 #define MSG_INFO_NOTIF(name,args,normal,gentle) \
226 { CHECK_MATCH(name, net_name) { print(sprintf(CCR(normal_or_gentle(normal, gentle)), args)); } }
228 MSG_INFO_NOTIFICATIONS
239 #define MSG_CENTER_NOTIF(name,args,cpid,durcnt,normal,gentle) \
240 { CHECK_MATCH(name, net_name) { centerprint_generic(HANDLE_CPID(cpid), sprintf(CCR(normal_or_gentle(normal, gentle)), args), durcnt); } }
242 MSG_CENTER_NOTIFICATIONS
255 // =========================
256 // Notification Networking
257 // =========================
260 void Send_Notification(float net_type, entity client, float net_name, string s1, string s2, string s3)
262 print("notification: ", Get_Notif_Name(net_type, net_name), ": ", ftos(net_name), ".\n");
263 if(net_type && net_name)
265 if(client && (clienttype(client) == CLIENTTYPE_REAL) && (client.flags & FL_CLIENT))
268 WRITESPECTATABLE_MSG_ONE({
269 WriteByte(MSG_ONE, SVC_TEMPENTITY);
270 WriteByte(MSG_ONE, TE_CSQC_NOTIFICATION);
271 WriteShort(MSG_ONE, net_type);
272 WriteCoord(MSG_ONE, net_name);
273 WriteString(MSG_ONE, s1);
274 WriteString(MSG_ONE, s2);
275 WriteString(MSG_ONE, s3);
279 if(!server_is_local && ((net_type == MSG_INFO || net_type == MSG_NOTIFY) || client == world))
285 #define MSG_INFO_NOTIF(name,args,normal,gentle) \
286 { if(min(NOTIF_MAX, name) == net_name) { print(sprintf(CCR(normal_or_gentle(normal, gentle)), args)); } }
288 MSG_INFO_NOTIFICATIONS
299 else { backtrace("Incorrect usage of Send_Notification!\n"); }
302 void Send_Notification_ToTeam(float targetteam, entity except, float net_type, float net_name, string s1, string s2, string s3)
305 FOR_EACH_REALCLIENT(tmp_entity)
307 if(tmp_entity.classname == STR_PLAYER)
308 if(tmp_entity.team == targetteam)
309 if(tmp_entity != except)
311 Send_Notification(net_type, tmp_entity, net_name, s1, s2, s3);
316 void Send_Notification_ToAll(entity except, float spectators, float net_type, float net_name, string s1, string s2, string s3)
319 FOR_EACH_REALCLIENT(tmp_entity)
321 if((tmp_entity.classname == STR_PLAYER) || spectators)
322 if(tmp_entity != except)
324 Send_Notification(net_type, tmp_entity, net_name, s1, s2, s3);
329 // LEGACY NOTIFICATION SYSTEMS
330 void Send_KillNotification(string s1, string s2, string s3, float msg, float type)
332 WriteByte(MSG_ALL, SVC_TEMPENTITY);
333 WriteByte(MSG_ALL, TE_CSQC_KILLNOTIFY);
334 WriteString(MSG_ALL, s1);
335 WriteString(MSG_ALL, s2);
336 WriteString(MSG_ALL, s3);
337 WriteShort(MSG_ALL, msg);
338 WriteByte(MSG_ALL, type);
341 // Function is used to send a generic centerprint whose content CSQC gets to decide (gentle version or not in the below cases)
342 void Send_CSQC_KillCenterprint(entity e, string s1, string s2, float msg, float type)
344 if (clienttype(e) == CLIENTTYPE_REAL)
347 WRITESPECTATABLE_MSG_ONE({
348 WriteByte(MSG_ONE, SVC_TEMPENTITY);
349 WriteByte(MSG_ONE, TE_CSQC_KILLCENTERPRINT);
350 WriteString(MSG_ONE, s1);
351 WriteString(MSG_ONE, s2);
352 WriteShort(MSG_ONE, msg);
353 WriteByte(MSG_ONE, type);
358 void Send_CSQC_Centerprint_Generic(entity e, float id, string s, float duration, float countdown_num)
360 if ((clienttype(e) == CLIENTTYPE_REAL) && (e.flags & FL_CLIENT))
363 WRITESPECTATABLE_MSG_ONE({
364 WriteByte(MSG_ONE, SVC_TEMPENTITY);
365 WriteByte(MSG_ONE, TE_CSQC_CENTERPRINT_GENERIC);
366 WriteByte(MSG_ONE, id);
367 WriteString(MSG_ONE, s);
368 if (id != 0 && s != "")
370 WriteByte(MSG_ONE, duration);
371 WriteByte(MSG_ONE, countdown_num);
376 void Send_CSQC_Centerprint_Generic_Expire(entity e, float id)
378 Send_CSQC_Centerprint_Generic(e, id, "", 1, 0);