]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/common/notifications.qc
Begin progressing over to using entities for the notification system
[xonotic/xonotic-data.pk3dir.git] / qcsrc / common / notifications.qc
1 // ================================================
2 //  Unified notification system, written by Samual
3 //  Last updated: February, 2013
4 // ================================================
5
6 #ifndef MENUQC
7 string arg_slot[8];
8 string Fill_Notif_Args(string args, string input,
9         string s1, string s2, string s3, string s4,
10         float f1, float f2, float f3, float f4)
11 {
12         dprint(sprintf("Fill_Notif_Args('%s', '%s', %s, %s, %s, %s, %d, %d, %d, %d);\n",
13                 args, input, s1, s2, s3, s4, f1, f2, f3, f4));
14
15         string selected, remaining = args;
16         float sel_num = 0;
17
18         #ifdef CSQC
19         string tmp_s;
20         #endif
21         
22         if((remaining != "") && (input != ""))
23         {
24                 for(;remaining;)
25                 {
26                         selected = car(remaining); remaining = cdr(remaining);
27
28                         switch(strtolower(selected))
29                         {
30                                 #define ADD_ARG_CASE(selected,result) case selected: { arg_slot[sel_num] = result; ++sel_num; break; }
31                                 
32                                 ADD_ARG_CASE("s1", s1)
33                                 ADD_ARG_CASE("s2", s2)
34                                 ADD_ARG_CASE("s3", s3)
35                                 ADD_ARG_CASE("s4", s4)
36                                 ADD_ARG_CASE("f1", ftos(f1))
37                                 ADD_ARG_CASE("f2", ftos(f2))
38                                 ADD_ARG_CASE("f3", ftos(f3))
39                                 ADD_ARG_CASE("f4", ftos(f4))
40
41                                 #ifdef CSQC // CSQC replacements
42                                 ADD_ARG_CASE("pass_key",                ((((tmp_s = getcommandkey("pass", "+use")) != "pass") && !(strstrofs(tmp_s, "not bound", 0) >= 0)) ? sprintf(CCR(_(" ^F1(Press %s)")), tmp_s) : ""))
43                                 ADD_ARG_CASE("frag_ping",               ((f2 != BOT_PING) ? sprintf(CCR(_("\n(Ping ^2%d^BG)")), f2) : ""))
44                                 ADD_ARG_CASE("frag_stats",              sprintf(CCR(_("\n(Health ^1%d^BG / Armor ^2%d^BG)%s")), f1, f2, ((f3 != BOT_PING) ? sprintf(CCR(_(" (Ping ^2%d^BG)")), f3) : "")))
45                                 //ADD_ARG_CASE("frag_pos",              ((Should_Print_Score_Pos(f1)) ? sprintf("\n^BG%s", Read_Score_Pos(f1)) : ""))
46                                 ADD_ARG_CASE("spree_cen",               (((f1 == 3) || (f1 == 5) || (f1 == 10) || (f1 == 15) || (f1 == 20) || (f1 == 25) || (f1 == 30)) ? sprintf(normal_or_gentle(_("%d frag spree! "), _("%d score spree! ")), f1) : ""))
47                                 ADD_ARG_CASE("spree_inf",               (((f1 == 3) || (f1 == 5) || (f1 == 10) || (f1 == 15) || (f1 == 20) || (f1 == 25) || (f1 == 30)) ? sprintf(normal_or_gentle(_("%d frag spree! "), _("%d score spree! ")), f1) : ""))
48                                 ADD_ARG_CASE("spree_end",               ((f1 >= 3) ? sprintf(normal_or_gentle(_(", ending their %d frag spree"), _(", ending their %d score spree")), f1) : ""))
49                                 ADD_ARG_CASE("spree_lost",              ((f1 >= 3) ? sprintf(normal_or_gentle(_(", losing their %d frag spree"), _(", losing their %d score spree")), f1) : ""))
50                                 ADD_ARG_CASE("death_team",              Team_ColoredFullName(f1 - 1))
51                                 ADD_ARG_CASE("weapon_name",     ftos(f1)) // weaponorder[f1].netname
52
53                                 #else // SVQC replacements
54                                 ADD_ARG_CASE("spree_inf",               (((f1 == 3) || (f1 == 5) || (f1 == 10) || (f1 == 15) || (f1 == 20) || (f1 == 25) || (f1 == 30)) ? sprintf(normal_or_gentle(_("%d frag spree! "), _("%d score spree! ")), f1) : ""))
55                                 ADD_ARG_CASE("spree_end",               ((f1 >= 3) ? sprintf(normal_or_gentle(_(", ending their %d frag spree"), _(", ending their %d score spree")), f1) : ""))
56                                 ADD_ARG_CASE("spree_lost",              ((f1 >= 3) ? sprintf(normal_or_gentle(_(", losing their %d frag spree"), _(", losing their %d score spree")), f1) : ""))
57                                 ADD_ARG_CASE("death_team",              Team_ColoredFullName(f1))
58                                 ADD_ARG_CASE("weapon_name",             ftos(f1)) // weaponorder[f1].netname
59                                 #endif
60
61                                 #undef ADD_ARG_CASE
62                                 default: { print("Hit unknown token in selected string! '", selected, "'\n"); break; }
63                         }
64                         if(sel_num == 7) { print("Hit maximum arguments!\n"); break; }
65                 }
66
67                 return sprintf(CCR(input), arg_slot[0], arg_slot[1], arg_slot[2], arg_slot[3], arg_slot[4], arg_slot[5], arg_slot[6], arg_slot[7]);
68         }
69
70         return "";
71 }
72
73 // get the actual name of a notification and return it as a string
74 string Get_Field_Value(float field, float net_type, float net_name)
75 {
76         #ifdef NOTIFICATIONS_DEBUG
77                 dprint(sprintf("Get_Field_Value(%d, %d, %d);\n", field, net_type, net_name));
78         #endif
79         
80         #define GET_FIELD_VALUE_OUTPUT(field,name,strnum,flnum) switch(field) { \
81                         case F_NAME: { return VAR_TO_TEXT(name); } \
82                         case F_STRNUM: { return ftos(strnum); } \
83                         case F_FLNUM: { return ftos(flnum); } }
84
85         #define GET_FIELD_VALUE_OUTPUT_PAIR(field,name,infoname,centername,strnum,flnum) switch(field) { \
86                         case F_NAME: { return VAR_TO_TEXT(name); } \
87                         case F_INFNAME: { return VAR_TO_TEXT(infoname); } \
88                         case F_CENNAME: { return VAR_TO_TEXT(centername); } \
89                         case F_INFVAL: { return ftos(infoname); } \
90                         case F_CENVAL: { return ftos(centername); } \
91                         case F_STRNUM: { return ftos(strnum); } \
92                         case F_FLNUM: { return ftos(flnum); } }
93
94         #define CLPSE_GETVALUE(name,arg,earg) \
95                 #if name != NO_MSG \
96                         arg \
97                 #else \
98                         earg \
99                 #endif
100
101         switch(net_type)
102         {
103                 case MSG_INFO:
104                 {
105                         #define MSG_INFO_NOTIF(name,strnum,flnum,args,hudargs,icon,normal,gentle) case name: { GET_FIELD_VALUE_OUTPUT(field,name,strnum,flnum) }
106                         NOTIF_SWITCH_LIST(MSG_INFO, net_name, return "")
107                         #undef MSG_INFO_NOTIF
108                         break;
109                 }
110                 case MSG_CENTER:
111                 {
112                         #define MSG_CENTER_NOTIF(name,strnum,flnum,args,cpid,durcnt,normal,gentle) case name: { GET_FIELD_VALUE_OUTPUT(field,name,strnum,flnum) }
113                         NOTIF_SWITCH_LIST(MSG_CENTER, net_name, return "")
114                         #undef MSG_CENTER_NOTIF
115                         break;
116                 }
117                 case MSG_WEAPON:
118                 {
119                         #define MSG_WEAPON_NOTIF(name,infoname,centername) case name: { GET_FIELD_VALUE_OUTPUT_PAIR(field,name, \
120                                 CLPSE_GETVALUE(infoname, infoname, NO_MSG), CLPSE_GETVALUE(centername, centername, NO_MSG), \
121                                 max(CLPSE_GETVALUE(infoname, stof(Get_Field_Value(F_STRNUM, MSG_INFO, infoname)), 0), CLPSE_GETVALUE(centername, stof(Get_Field_Value(F_STRNUM, MSG_CENTER, centername)), 0)), \
122                                 max(CLPSE_GETVALUE(infoname, stof(Get_Field_Value(F_FLNUM, MSG_INFO, infoname)), 0), CLPSE_GETVALUE(centername, stof(Get_Field_Value(F_FLNUM, MSG_CENTER, centername)), 0))) }
123                         NOTIF_SWITCH_LIST(MSG_WEAPON, net_name, return "")
124                         #undef MSG_WEAPON_NOTIF
125                         break;
126                 }
127                 case MSG_DEATH:
128                 {
129                         #define MSG_DEATH_NOTIF(name,infoname,centername) case name: { GET_FIELD_VALUE_OUTPUT_PAIR(field,name, \
130                                 CLPSE_GETVALUE(infoname, infoname, NO_MSG), CLPSE_GETVALUE(centername, centername, NO_MSG), \
131                                 max(CLPSE_GETVALUE(infoname, stof(Get_Field_Value(F_STRNUM, MSG_INFO, infoname)), 0), CLPSE_GETVALUE(centername, stof(Get_Field_Value(F_STRNUM, MSG_CENTER, centername)), 0)), \
132                                 max(CLPSE_GETVALUE(infoname, stof(Get_Field_Value(F_FLNUM, MSG_INFO, infoname)), 0), CLPSE_GETVALUE(centername, stof(Get_Field_Value(F_FLNUM, MSG_CENTER, centername)), 0))) }
133                         NOTIF_SWITCH_LIST(MSG_DEATH, net_name, return "")
134                         #undef MSG_DEATH_NOTIF
135                         break;
136                 }
137         }
138
139         #undef GET_FIELD_VALUE_OUTPUT
140         #undef GET_FIELD_VALUE_OUTPUT_PAIR
141         #undef CLPSE_GETVALUE
142         return "";
143 }
144 #endif // ifndef MENUQC
145
146
147 // ===============================
148 //  Frontend Notification Pushing
149 // ===============================
150
151 void Dump_Notifications(float fh, float alsoprint)
152 {
153         float MSG_INFO_NOTIFS = 0, MSG_CENTER_NOTIFS = 0, MSG_WEAPON_NOTIFS = 0, MSG_DEATH_NOTIFS = 0;
154         string notif_msg;
155
156         #define NOTIF_WRITE(type,name,text) { \
157                 ++##type##_NOTIFS; \
158                 notif_msg = sprintf("seta %s 1 // %s - %s\n", #name, #type, strreplace("\n", "\\n", text)); \
159                 fputs(fh, notif_msg); \
160                 if(alsoprint) { print(strreplace("^", "^^", notif_msg)); } }
161         
162         #define MSG_INFO_NOTIF(name,strnum,flnum,args,hudargs,icon,normal,gentle) NOTIF_WRITE(MSG_INFO, name, normal)
163         MSG_INFO_NOTIFICATIONS
164         #undef MSG_INFO_NOTIF
165         
166         #define MSG_CENTER_NOTIF(name,strnum,flnum,args,cpid,durcnt,normal,gentle) NOTIF_WRITE(MSG_CENTER, name, normal)
167         MSG_CENTER_NOTIFICATIONS
168         #undef MSG_CENTER_NOTIF
169         
170         #define MSG_WEAPON_NOTIF(name,infoname,centername) NOTIF_WRITE(MSG_WEAPON, name, \
171                 sprintf("infoname: %s, centername: %s", VAR_TO_TEXT(infoname), VAR_TO_TEXT(centername)))
172         MSG_WEAPON_NOTIFICATIONS
173         #undef MSG_WEAPON_NOTIF
174         
175         #define MSG_DEATH_NOTIF(name,infoname,centername) NOTIF_WRITE(MSG_DEATH, name, \
176                 sprintf("infoname: %s, centername: %s", VAR_TO_TEXT(infoname), VAR_TO_TEXT(centername)))
177         MSG_DEATH_NOTIFICATIONS
178         #undef MSG_DEATH_NOTIF
179         
180         print(sprintf("Notification counts: MSG_INFO = %d, MSG_CENTER = %d, MSG_WEAPON = %d, MSG_DEATH = %d\n",
181                 MSG_INFO_NOTIFS, MSG_CENTER_NOTIFS, MSG_WEAPON_NOTIFS, MSG_DEATH_NOTIFS));
182         
183         return;
184         #undef NOTIF_WRITE
185 }
186
187 #ifndef MENUQC
188 #ifdef CSQC
189 void HUD_Notify_Push(string icon, string attacker, string victim)
190 {
191         if(icon != "")
192         {
193                 --kn_index;
194                 if (kn_index == -1) { kn_index = KN_MAX_ENTRIES-1; }
195                 killnotify_times[kn_index] = time;
196
197                 // icon
198                 if(killnotify_icon[kn_index]) { strunzone(killnotify_icon[kn_index]); }
199                 killnotify_icon[kn_index] = strzone(icon);
200
201                 // attacker
202                 if(killnotify_attackers[kn_index]) { strunzone(killnotify_attackers[kn_index]); }
203                 killnotify_attackers[kn_index] = strzone(attacker);
204
205                 // victim
206                 if(killnotify_victims[kn_index]) { strunzone(killnotify_victims[kn_index]); }
207                 killnotify_victims[kn_index] = strzone(victim);
208         }
209 }
210 #endif // ifdef CSQC
211
212 void Local_Notification(float net_type, float net_name, ...count)
213 {
214         // check supplied type and name for errors
215         #ifdef NOTIFICATIONS_DEBUG
216         {
217                 #define CHECKARG_TYPENAME(type) case MSG_##type##: \
218                         { if(!net_name || (net_name > NOTIF_##type##_COUNT)) \
219                         { checkargs = sprintf("Improper name: %d!", net_name); } break; }
220                         
221                 string checkargs = "";
222                 switch(net_type)
223                 {
224                         CHECKARG_TYPENAME(INFO)
225                         CHECKARG_TYPENAME(CENTER)
226                         CHECKARG_TYPENAME(WEAPON)
227                         CHECKARG_TYPENAME(DEATH)
228                         
229                         default: { checkargs = sprintf("Improper type: %d!", checkargs, net_type); break; }
230                 }
231                 #undef CHECKARG_TYPENAME
232
233                 if(checkargs != "") { backtrace(sprintf("Incorrect usage of Local_Notification: %s\n", checkargs)); return; }
234         }
235         #endif
236         
237         float stringcount = stof(Get_Field_Value(F_STRNUM, net_type, net_name));
238         float floatcount = stof(Get_Field_Value(F_FLNUM, net_type, net_name));
239
240         string s1 = ((0 < stringcount) ? ...(0, string) : NO_STR_ARG);
241         string s2 = ((1 < stringcount) ? ...(1, string) : NO_STR_ARG);
242         string s3 = ((2 < stringcount) ? ...(2, string) : NO_STR_ARG);
243         string s4 = ((3 < stringcount) ? ...(3, string) : NO_STR_ARG);
244         float f1 = ((stringcount < count) ? ...(stringcount, float) : NO_FL_ARG);
245         float f2 = (((stringcount + 1) < count) ? ...((stringcount + 1), float) : NO_FL_ARG);
246         float f3 = (((stringcount + 2) < count) ? ...((stringcount + 2), float) : NO_FL_ARG);
247         float f4 = (((stringcount + 3) < count) ? ...((stringcount + 3), float) : NO_FL_ARG);
248
249         #ifdef NOTIFICATIONS_DEBUG
250         {
251                 dprint(sprintf("Local_Notification(%d, %s, %s, %s, %s, %s, %d, %d, %d, %d);\n",
252                         net_type, Get_Field_Value(F_NAME, net_type, net_name),
253                         s1, s2, s3, s4, f1, f2, f3, f4));
254
255                 if((stringcount + floatcount) > count)
256                         { backtrace(sprintf("Not enough arguments for Local_Notification! stringcount(%d) + floatcount(%d) > count(%d) \
257                         \nCheck the notification definition and function call for accuracy...?\n", stringcount, floatcount, count)); return; }
258                 else if((stringcount + floatcount) < count)
259                         { backtrace(sprintf("Too many arguments for Local_Notification! stringcount(%d) + floatcount(%d) < count(%d) \
260                         \nCheck the notification definition and function call for accuracy...?\n", stringcount, floatcount, count)); return; }
261         }
262         #endif
263         
264
265         switch(net_type)
266         {
267                 case MSG_INFO:
268                 {
269                         #define MSG_INFO_NOTIF(name,strnum,flnum,args,hudargs,icon,normal,gentle) \
270                                 case name: { CHECK_AUTOCVAR(name) \
271                                 { \
272                                         print(sprintf(CCR(normal_or_gentle(normal, gentle)), args)); \
273                                         #ifdef CSQC \
274                                                 if(icon != "") { HUD_Notify_Push(icon, hudargs); } \
275                                         #endif \
276                                 } return; }
277                                 
278                         NOTIF_SWITCH_LIST(MSG_INFO, net_name, return)
279                         
280                         #undef MSG_INFO_NOTIF
281                         break;
282                 }
283                 #ifdef CSQC
284                 case MSG_CENTER:
285                 {
286                         #define MSG_CENTER_NOTIF(name,strnum,flnum,args,cpid,durcnt,normal,gentle) \
287                                 case name: { CHECK_AUTOCVAR(name) \
288                                 { \
289                                         centerprint_generic(HANDLE_CPID(cpid), sprintf(CCR(normal_or_gentle(normal, gentle)), args), durcnt); \
290                                 } return; }
291
292                         NOTIF_SWITCH_LIST(MSG_CENTER, net_name, return)
293                         
294                         #undef MSG_CENTER_NOTIF
295                         break;
296                 }
297                 #endif
298                 case MSG_WEAPON:
299                 {
300                         #define MSG_WEAPON_NOTIF(name,infoname,centername) \
301                                 case name: { CHECK_AUTOCVAR(name) \
302                                 { \
303                                         #if infoname != NO_MSG \
304                                                 Local_Notification_Without_VarArgs(MSG_INFO, infoname, \
305                                                         stof(Get_Field_Value(F_STRNUM, MSG_INFO, infoname)), \
306                                                         stof(Get_Field_Value(F_FLNUM, MSG_INFO, infoname)), \
307                                                         s1, s2, s3, s4, f1, f2, f3, f4); \
308                                         #endif \
309                                         #ifdef CSQC \
310                                                 #if centername != NO_MSG \
311                                                         Local_Notification_Without_VarArgs(MSG_CENTER, centername, \
312                                                                 stof(Get_Field_Value(F_STRNUM, MSG_CENTER, centername)), \
313                                                                 stof(Get_Field_Value(F_FLNUM, MSG_CENTER, centername)), \
314                                                                 s1, s2, s3, s4, f1, f2, f3, f4); \
315                                                 #endif \
316                                         #endif \
317                                 } return; }
318
319                         NOTIF_SWITCH_LIST(MSG_WEAPON, net_name, return)
320                         
321                         #undef MSG_WEAPON_NOTIF
322                         break;
323                 }
324                 case MSG_DEATH:
325                 {
326                         #define MSG_DEATH_NOTIF(name,infoname,centername) \
327                                 case name: { CHECK_AUTOCVAR(name) \
328                                 { \
329                                         #if infoname != NO_MSG \
330                                                 Local_Notification_Without_VarArgs(MSG_INFO, infoname, \
331                                                         stof(Get_Field_Value(F_STRNUM, MSG_INFO, infoname)), \
332                                                         stof(Get_Field_Value(F_FLNUM, MSG_INFO, infoname)), \
333                                                         s1, s2, s3, s4, f1, f2, f3, f4); \
334                                         #endif \
335                                         #ifdef CSQC \
336                                                 #if centername != NO_MSG \
337                                                         Local_Notification_Without_VarArgs(MSG_CENTER, centername, \
338                                                                 stof(Get_Field_Value(F_STRNUM, MSG_CENTER, centername)), \
339                                                                 stof(Get_Field_Value(F_FLNUM, MSG_CENTER, centername)), \
340                                                                 s1, s2, s3, s4, f1, f2, f3, f4); \
341                                                 #endif \
342                                         #endif \
343                                 } return; } 
344
345                         NOTIF_SWITCH_LIST(MSG_DEATH, net_name, return)
346                         
347                         #undef MSG_DEATH_NOTIF
348                         break;
349                 }
350         }
351 }
352
353 void Local_Notification_Without_VarArgs(float net_type, float net_name,
354         float stringcount, float floatcount,
355         string s1, string s2, string s3, string s4,
356         float f1, float f2, float f3, float f4)
357 {
358         #define VARITEM(stringc,floatc,args) if((stringcount == stringc) && (floatcount == floatc)) { Local_Notification(net_type, net_name, args); return; }
359         EIGHT_VARS_TO_VARARGS_VARLIST
360         #undef VARITEM
361
362         Local_Notification(net_type, net_name); // some notifications don't have any arguments at all
363 }
364
365
366 // =========================
367 //  Notification Networking
368 // =========================
369
370 #ifdef CSQC
371 void Read_Notification(float is_new)
372 {
373         float net_type = ReadByte();
374         float net_name = ReadShort();
375
376         float stringcount = stof(Get_Field_Value(F_STRNUM, net_type, net_name));
377         float floatcount = stof(Get_Field_Value(F_FLNUM, net_type, net_name));
378
379         string s1 = ((stringcount >= 1) ? ReadString() : NO_STR_ARG);
380         string s2 = ((stringcount >= 2) ? ReadString() : NO_STR_ARG);
381         string s3 = ((stringcount >= 3) ? ReadString() : NO_STR_ARG);
382         string s4 = ((stringcount == 4) ? ReadString() : NO_STR_ARG);
383         float f1 = ((floatcount >= 1) ? ReadLong() : NO_FL_ARG);
384         float f2 = ((floatcount >= 2) ? ReadLong() : NO_FL_ARG);
385         float f3 = ((floatcount >= 3) ? ReadLong() : NO_FL_ARG);
386         float f4 = ((floatcount == 4) ? ReadLong() : NO_FL_ARG);
387
388         #ifdef NOTIFICATIONS_DEBUG
389                 dprint(sprintf("Read_Notification(%d) at %d: net_name = %s.\n", is_new, time, Get_Field_Value(F_NAME, net_type, net_name)));
390         #endif
391         
392         if(is_new) { Local_Notification_Without_VarArgs(net_type, net_name, stringcount, floatcount, s1, s2, s3, s4, f1, f2, f3, f4); }
393 }
394 #endif
395
396 #ifdef SVQC
397 void Notification_Remove()
398 {
399         float i;
400         for(i = 0; i < 4; ++i) { if(self.nent_strings[i]) { strunzone(self.nent_strings[i]); } }
401         remove(self);
402 }
403
404 float Write_Notification(entity client, float sf)
405 {
406         float i, send = FALSE;
407         
408         switch(self.nent_broadcast)
409         {
410                 case NOTIF_ONE: { if((client == self.nent_client) || (client.classname == STR_SPECTATOR && client.enemy == self.nent_client)) { send = TRUE; } break; }
411                 case NOTIF_ONE_ONLY: { if(client == self.nent_client) { send = TRUE; } break; }
412                 case NOTIF_TEAM: { if((client.team == self.nent_client.team) || (client.classname == STR_SPECTATOR && client.enemy.team == self.nent_client.team)) { send = TRUE; } break; }
413                 case NOTIF_TEAM_EXCEPT: { if(((client != self.nent_client) && (client.team == self.nent_client.team) && !(client.classname == STR_SPECTATOR && client.enemy == self.nent_client))) { send = TRUE; } break; }
414                 case NOTIF_ANY: { send = TRUE; break; }
415                 case NOTIF_ANY_EXCEPT: { if((client != self.nent_client) && !(client.classname == STR_SPECTATOR && client.enemy == self.nent_client)) { send = TRUE; } break; }
416                 default: { send = FALSE; break; }
417         }
418
419         if(send)
420         {               
421                 WriteByte(MSG_ENTITY, ENT_CLIENT_NOTIFICATION);
422                 WriteByte(MSG_ENTITY, self.nent_net_type);
423                 WriteShort(MSG_ENTITY, self.nent_net_name);
424                 for(i = 0; i < self.nent_stringcount; ++i) { WriteString(MSG_ENTITY, self.nent_strings[i]); } 
425                 for(i = 0; i < self.nent_floatcount; ++i) { WriteLong(MSG_ENTITY, self.nent_floats[i]); }
426         }
427
428         return send; 
429 }
430
431 void Send_Notification(float broadcast, entity client,
432         float net_type, float net_name, ...count)
433 {
434         // check supplied broadcast, target, type, and name for errors
435         #ifdef NOTIFICATIONS_DEBUG
436         {
437                 #define CHECKARG_TYPENAME(type) case MSG_##type##: \
438                         { if(!net_name || (net_name > NOTIF_##type##_COUNT)) \
439                         { checkargs = sprintf("Improper name: %d!", net_name); } break; }
440                         
441                 string checkargs = "";
442                 switch(net_type)
443                 {
444                         CHECKARG_TYPENAME(INFO)
445                         CHECKARG_TYPENAME(CENTER)
446                         CHECKARG_TYPENAME(WEAPON)
447                         CHECKARG_TYPENAME(DEATH)
448                         
449                         default: { checkargs = sprintf("Improper type: %d!", checkargs, net_type); break; }
450                 }
451                 #undef CHECKARG_TYPENAME
452                 
453                 if(checkargs != "") { checkargs = strcat(checkargs, " "); }
454                 switch(broadcast)
455                 {
456                         case NOTIF_ONE:
457                         case NOTIF_ONE_ONLY: { if(clienttype(client) == CLIENTTYPE_NOTACLIENT) { checkargs = sprintf("%sNo client provided!", checkargs); } break; }
458                         case NOTIF_ANY_EXCEPT: { if(clienttype(client) == CLIENTTYPE_NOTACLIENT) { checkargs = sprintf("%sException can't be a non-client!", checkargs); } break; }
459                         case NOTIF_ANY: { if(client) { checkargs = sprintf("%sEntity provided when world was required!", checkargs); } break; }
460                         
461                         case NOTIF_TEAM:
462                         case NOTIF_TEAM_EXCEPT:
463                         {
464                                 if not(teamplay) { checkargs = sprintf("%sTeamplay not active!", checkargs); }
465                                 else if(clienttype(client) == CLIENTTYPE_NOTACLIENT)
466                                 {
467                                         if(broadcast == NOTIF_TEAM) { checkargs = sprintf("%sNo client provided!", checkargs); }
468                                         else { checkargs = sprintf("%sException can't be a non-client!", checkargs); }
469                                 }
470                                 break;
471                         }
472                         
473                         default: { checkargs = sprintf("%sImproper broadcast: %d!", checkargs, broadcast); break; }
474                 }
475                 
476                 if(checkargs != "") { backtrace(sprintf("Incorrect usage of Send_Notification: %s\n", checkargs)); return; }
477         }
478         #endif
479
480         // retreive counts for the arguments of this notification
481         float stringcount = stof(Get_Field_Value(F_STRNUM, net_type, net_name));
482         float floatcount = stof(Get_Field_Value(F_FLNUM, net_type, net_name));
483
484         #ifdef NOTIFICATIONS_DEBUG
485         {
486                 dprint(sprintf("Send_Notification(%d, %d, %s, stringcount: %d, floatcount: %d, varargs: %d);\n",
487                         broadcast, net_type, Get_Field_Value(F_NAME, net_type, net_name), stringcount, floatcount, count));
488
489                 if((stringcount + floatcount) > count)
490                         { backtrace(sprintf("Not enough arguments for Send_Notification! stringcount(%d) + floatcount(%d) > count(%d) \
491                         \nCheck the notification definition and function call for accuracy...?\n", stringcount, floatcount, count)); return; }
492                 else if((stringcount + floatcount) < count)
493                         { backtrace(sprintf("Too many arguments for Send_Notification! stringcount(%d) + floatcount(%d) < count(%d) \
494                         \nCheck the notification definition and function call for accuracy...?\n", stringcount, floatcount, count)); return; }
495         }
496         #endif
497
498         entity notif = spawn();
499         notif.nent_broadcast = broadcast;
500         notif.nent_client = client;
501         notif.nent_net_type = net_type;
502         notif.nent_net_name = net_name;
503         notif.nent_stringcount = stringcount;
504         notif.nent_floatcount = floatcount;
505         
506         float i;
507         
508         for(i = 0; i < stringcount; ++i) { notif.nent_strings[i] = strzone(...(i, string)); }
509         for(i = 0; i < floatcount; ++i) { notif.nent_floats[i] = ...((stringcount + i), float); }
510         
511         notif.think = Notification_Remove;
512         notif.nextthink = (time + 0.5); 
513
514         Net_LinkEntity(notif, FALSE, 0, Write_Notification);
515
516         if((!server_is_local) && (broadcast == NOTIF_ANY || broadcast == NOTIF_ANY_EXCEPT) && (net_type != MSG_CENTER))
517                 { Local_Notification_Without_VarArgs(net_type, net_name, stringcount, floatcount,
518                         IFSTR(0), IFSTR(1), IFSTR(2), IFSTR(3), IFFL(0), IFFL(1), IFFL(2), IFFL(3)); }
519 }
520
521 void Send_Notification_Without_VarArgs(float broadcast, entity client,
522         float net_type, float net_name,
523         float stringcount, float floatcount,
524         string s1, string s2, string s3, string s4,
525         float f1, float f2, float f3, float f4)
526 {               
527         #define VARITEM(stringc,floatc,args) if((stringcount == stringc) && (floatcount == floatc)) { Send_Notification(broadcast, client, net_type, net_name, args); return; }
528         EIGHT_VARS_TO_VARARGS_VARLIST
529         #undef VARITEM
530
531         Send_Notification(broadcast, client, net_type, net_name); // some notifications don't have any arguments at all
532 }
533
534 void Send_Notification_Legacy_Wrapper(float broadcast, entity client,
535         float net_type, float net_name,
536         string s1, string s2,
537         float f1, float f2, float f3)
538 {
539         float stringcount = stof(Get_Field_Value(F_STRNUM, net_type, net_name));
540         float floatcount = stof(Get_Field_Value(F_FLNUM, net_type, net_name));
541         Send_Notification_Without_VarArgs(broadcast, client, net_type, net_name, stringcount, floatcount, s1, s2, NO_STR_ARG, NO_STR_ARG, f1, f2, f3, NO_FL_ARG);
542 }
543
544
545 // =============================
546 //  LEGACY NOTIFICATION SYSTEMS
547 // =============================
548
549 void Send_CSQC_Centerprint_Generic(entity e, float id, string s, float duration, float countdown_num)
550 {
551         if ((clienttype(e) == CLIENTTYPE_REAL) && (e.flags & FL_CLIENT))
552         {
553                 msg_entity = e;
554                 WRITESPECTATABLE_MSG_ONE({
555                         WriteByte(MSG_ONE, SVC_TEMPENTITY);
556                         WriteByte(MSG_ONE, TE_CSQC_CENTERPRINT_GENERIC);
557                         WriteByte(MSG_ONE, id);
558                         WriteString(MSG_ONE, s);
559                         if (id != 0 && s != "")
560                         {
561                                 WriteByte(MSG_ONE, duration);
562                                 WriteByte(MSG_ONE, countdown_num);
563                         }
564                 });
565         }
566 }
567 void Send_CSQC_Centerprint_Generic_Expire(entity e, float id)
568 {
569         Send_CSQC_Centerprint_Generic(e, id, "", 1, 0);
570 }
571 #endif // ifdef SVQC
572 #endif // ifndef MENUQC