]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/common/notifications.qc
Organize that a bit better as well
[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 entity Get_Notif_Ent(float net_type, float net_name)
7 {
8         switch(net_type)
9         {
10                 case MSG_INFO: return msg_info_notifs[net_name - 1];
11                 case MSG_CENTER: return msg_center_notifs[net_name - 1];
12                 case MSG_WEAPON: return msg_weapon_notifs[net_name - 1];
13                 case MSG_DEATH: return msg_death_notifs[net_name - 1];
14         }
15         backtrace(sprintf("Get_Notif_Ent(%d, %d): Improper net type!\n", net_type, net_name));
16         return world;
17 }
18
19
20 // ===============================
21 //  Frontend Notification Pushing
22 // ===============================
23
24 void Dump_Notifications(float fh, float alsoprint)
25 {
26         #define NOTIF_WRITE(a,b) { \
27                 fputs(fh, a); \
28                 if(alsoprint) \
29                 { \
30                         if(b != "") { print(b); } \
31                         else { print(a); } \
32                 } }
33         #define NOTIF_WRITE_SETA(name,default,text) { \
34                 notif_msg = \
35                         sprintf( \
36                                 "seta notification_%s %d \"notif string: %s\"\n", \
37                                 name, default, strreplace("\n", "\\n", text) \
38                         ); \
39                 NOTIF_WRITE(notif_msg, strreplace("^", "^^", notif_msg)) }
40
41         string notif_msg;
42         float i;
43         entity e;
44
45         // Note: This warning only applies to the notifications.cfg file that is output...
46
47         // You ARE supposed to manually edit this function to add i.e. hard coded
48         // notification variables for mutators or game modes or such and then
49         // regenerate the notifications.cfg file from the new code.
50
51         NOTIF_WRITE("// ********************************************** //\n", "");
52         NOTIF_WRITE("// ** WARNING - DO NOT MANUALLY EDIT THIS FILE ** //\n", "");
53         NOTIF_WRITE("// **                                          ** //\n", "");
54         NOTIF_WRITE("// **  This file is automatically generated    ** //\n", "");
55         NOTIF_WRITE("// **  by code with the command 'dumpnotifs'.  ** //\n", "");
56         NOTIF_WRITE("// **                                          ** //\n", "");
57         NOTIF_WRITE("// **  If you add a new notification, please   ** //\n", "");
58         NOTIF_WRITE("// **  regenerate this file with that command  ** //\n", "");
59         NOTIF_WRITE("// **  making sure that the output matches     ** //\n", "");
60         NOTIF_WRITE("// **  with the lists and defaults in code.    ** //\n", "");
61         NOTIF_WRITE("// **                                          ** //\n", "");
62         NOTIF_WRITE("// ********************************************** //\n", "");
63
64         NOTIF_WRITE("\n// Version number to identify mismatches between code and config file...\n", "");
65         NOTIF_WRITE("// Increment NOTIF_VERSION in common/notifications.qh with any\n", "");
66         NOTIF_WRITE("// new notifications or other changes to notif cvars/this config.\n", "");
67         
68         NOTIF_WRITE(sprintf("set notification_version %d\n", NOTIF_VERSION), "");
69
70         // These notifications will also append their string as a comment...
71         // This is not necessary, and does not matter if they vary between config versions,
72         // it is just a semi-helpful tool for those who want to manually change their user settings.
73
74         NOTIF_WRITE(sprintf("\n// MSG_INFO notifications (count = %d):\n", NOTIF_INFO_COUNT), "");
75         for(i = 0; i <= NOTIF_INFO_COUNT; ++i) {
76                 e = Get_Notif_Ent(MSG_INFO, i);
77                 if not(e) { backtrace("Dump_Notifications(): Missing notification entity!\n"); return; }
78                 NOTIF_WRITE_SETA(e.nent_name, e.nent_default, e.nent_string); }
79
80         NOTIF_WRITE(sprintf("\n// MSG_CENTER notifications (count = %d):\n", NOTIF_CENTER_COUNT), "");
81         for(i = 0; i <= NOTIF_CENTER_COUNT; ++i) {
82                 e = Get_Notif_Ent(MSG_CENTER, i);
83                 if not(e) { backtrace("Dump_Notifications(): Missing notification entity!\n"); return; }
84                 NOTIF_WRITE_SETA(e.nent_name, e.nent_default, e.nent_string); }
85
86         NOTIF_WRITE(sprintf("\n// MSG_WEAPON notifications (count = %d):\n", NOTIF_WEAPON_COUNT), "");
87         for(i = 0; i <= NOTIF_WEAPON_COUNT; ++i) {
88                 e = Get_Notif_Ent(MSG_WEAPON, i);
89                 if not(e) { backtrace("Dump_Notifications(): Missing notification entity!\n"); return; }
90                 NOTIF_WRITE_SETA(e.nent_name, e.nent_default, sprintf("infoname: %s, centername: %s",
91                         e.nent_msginfo.nent_name, e.nent_msgcenter.nent_name)); }
92
93         NOTIF_WRITE(sprintf("\n// MSG_DEATH notifications (count = %d):\n", NOTIF_DEATH_COUNT), "");
94         for(i = 0; i <= NOTIF_DEATH_COUNT; ++i) {
95                 e = Get_Notif_Ent(MSG_DEATH, i);
96                 if not(e) { backtrace("Dump_Notifications(): Missing notification entity!\n"); return; }
97                 NOTIF_WRITE_SETA(e.nent_name, e.nent_default, sprintf("infoname: %s, centername: %s",
98                         e.nent_msginfo.nent_name, e.nent_msgcenter.nent_name)); }
99
100         // edit these to match whichever cvars are used for specific notification options
101         NOTIF_WRITE("\n// HARD CODED notification variables:\n", "");
102         NOTIF_WRITE("seta notification_errors_are_fatal 1 \"If a notification fails upon initialization, cause a Host_Error to stop the program\"\n", "");
103         NOTIF_WRITE("seta notification_ctf_pickup_team_verbose 1 \"Show extra information if a team mate picks up a flag\"\n", "");
104         NOTIF_WRITE("seta notification_ctf_pickup_enemy_verbose 1 \"Show extra information if an enemy picks up a flag\"\n", "");
105         NOTIF_WRITE("seta notification_ctf_capture_verbose 1 \"Show extra information when someone captures a flag\"\n", "");
106         NOTIF_WRITE("seta notification_frag_verbose 1 \"Show extra information when you frag someone (or when you are fragged\"\n", "");
107
108         NOTIF_WRITE(sprintf("\n// Notification counts (total = %d): MSG_INFO = %d, MSG_CENTER = %d, MSG_WEAPON = %d, MSG_DEATH = %d\n",
109                 (NOTIF_INFO_COUNT + NOTIF_CENTER_COUNT + NOTIF_WEAPON_COUNT + NOTIF_DEATH_COUNT), 
110                 NOTIF_INFO_COUNT, NOTIF_CENTER_COUNT, NOTIF_WEAPON_COUNT, NOTIF_DEATH_COUNT), "");
111         
112         return;
113         #undef NOTIF_WRITE_SETA
114         #undef NOTIF_WRITE
115 }
116
117 #ifdef SVQC
118 void Notification_GetCvars()
119 {
120         GetCvars_handleFloat(get_cvars_s, get_cvars_f, FRAG_VERBOSE, "notification_frag_verbose");
121 }
122 #endif
123
124 string Local_Notification_sprintf(string input, string args, 
125         string s1, string s2, string s3, string s4,
126         float f1, float f2, float f3, float f4)
127 {
128         #ifdef NOTIFICATIONS_DEBUG
129         dprint(
130                 sprintf("Local_Notification_sprintf('%s^7', '%s', %s, %s);\n",
131                         strreplace("\n", "\\n", input),
132                         args,
133                         sprintf("'%s^7', '%s^7', '%s^7', '%s^7'", s1, s2, s3, s4),
134                         sprintf("%d, %d, %d, %d", f1, f2, f3, f4)
135                 )
136         );
137         #endif
138         
139         string selected;
140         float sel_num;
141         for(sel_num = 0; sel_num < NOTIF_MAX_ARGS; ++sel_num) { arg_slot[sel_num] = ""; }
142
143         #ifdef CSQC
144         string tmp_s;
145         #endif
146
147         for(sel_num = 0;(args != "");)
148         {
149                 selected = car(args); args = cdr(args);
150                 NOTIF_HIT_MAX(NOTIF_MAX_ARGS, "Local_Notification_sprintf")
151                 switch(strtolower(selected))
152                 {
153                         #define ARG_CASE(prog,selected,result) \
154                                 #ifdef CSQC \
155                                         #if (prog == ARG_DOUBLE) || (prog == ARG_TRIPLE) || (prog == ARG_CSQC) \
156                                                 case selected: { arg_slot[sel_num] = result; ++sel_num; break; } \
157                                         #endif \
158                                 #else \
159                                         #if (prog == ARG_DOUBLE) || (prog == ARG_TRIPLE) || (prog == ARG_SVQC) \
160                                                 case selected: { arg_slot[sel_num] = result; ++sel_num; break; } \
161                                         #endif \
162                                 #endif
163                         NOTIF_ARGUMENT_LIST
164                         #undef ARG_CASE
165                         NOTIF_HIT_UNKNOWN(NOTIF_MAX_ARGS, "Local_Notification_sprintf")
166                 }
167         }
168         return sprintf(input, arg_slot[0], arg_slot[1], arg_slot[2], arg_slot[3], arg_slot[4], arg_slot[5], arg_slot[6]);
169 }
170
171 #ifdef CSQC
172 void Local_Notification_HUD_Notify_Push(string icon, string hudargs, string s1, string s2, string s3, string s4)
173 {
174         string selected;
175         float sel_num;
176         arg_slot[0] = ""; arg_slot[1] = "";
177
178         for(sel_num = 0;(hudargs != "");)
179         {
180                 selected = car(hudargs); hudargs = cdr(hudargs);
181                 NOTIF_HIT_MAX(NOTIF_MAX_HUDARGS, "Local_Notification_HUD_Notify_Push")
182                 switch(strtolower(selected))
183                 {
184                         #define ARG_CASE(prog,selected,result) \
185                                 #if (prog == ARG_TRIPLE) \
186                                         case selected: { arg_slot[sel_num] = result; ++sel_num; break; } \
187                                 #endif
188                         NOTIF_ARGUMENT_LIST
189                         #undef ARG_CASE
190                         NOTIF_HIT_UNKNOWN(NOTIF_MAX_HUDARGS, "Local_Notification_HUD_Notify_Push")
191                 }
192         }
193         HUD_Notify_Push(icon, arg_slot[0], arg_slot[1]);
194 }
195 #endif
196
197 void Local_Notification(float net_type, float net_name, ...count)
198 {
199         // check supplied type and name for errors
200         string checkargs = "";
201         #define CHECKARG_TYPENAME(type) case MSG_##type##: \
202                 { if(!net_name || (net_name > NOTIF_##type##_COUNT)) \
203                 { checkargs = sprintf("Improper name: %d!", net_name); } break; }
204         switch(net_type)
205         {
206                 CHECKARG_TYPENAME(INFO)
207                 CHECKARG_TYPENAME(CENTER)
208                 CHECKARG_TYPENAME(WEAPON)
209                 CHECKARG_TYPENAME(DEATH)
210                 default: { checkargs = sprintf("Improper type: %d!", checkargs, net_type); break; }
211         }
212         #undef CHECKARG_TYPENAME
213         if(checkargs != "") { backtrace(sprintf("Incorrect usage of Local_Notification: %s\n", checkargs)); return; }
214
215         entity notif = Get_Notif_Ent(net_type, net_name);
216         if not(notif) { backtrace("Local_Notification: Could not find notification entity!\n"); return; }
217         if not(notif.nent_enabled) { print("Local_Notification: Entity was disabled...\n"); return; }
218
219         if((notif.nent_stringcount + notif.nent_floatcount) > count)
220         {
221                 backtrace(sprintf(
222                         strcat(
223                                 "Not enough arguments for Local_Notification! ",
224                                 "stringcount(%d) + floatcount(%d) > count(%d)\n", 
225                                 "Check the definition and function call for accuracy...?\n"
226                         ),
227                         notif.nent_stringcount, notif.nent_floatcount, count));
228                 return;
229         }
230         else if((notif.nent_stringcount + notif.nent_floatcount) < count)
231         {
232                 backtrace(sprintf(
233                         strcat(
234                                 "Too many arguments for Local_Notification! ",
235                                 "stringcount(%d) + floatcount(%d) < count(%d)\n",
236                                 "Check the definition and function call for accuracy...?\n"
237                         ),
238                         notif.nent_stringcount, notif.nent_floatcount, count));
239                 return;
240         }
241
242         string s1 = ((0 < notif.nent_stringcount) ? ...(0, string) : "");
243         string s2 = ((1 < notif.nent_stringcount) ? ...(1, string) : "");
244         string s3 = ((2 < notif.nent_stringcount) ? ...(2, string) : "");
245         string s4 = ((3 < notif.nent_stringcount) ? ...(3, string) : "");
246         float f1 = ((0 < notif.nent_floatcount) ? ...((notif.nent_stringcount + 0), float) : 0);
247         float f2 = ((1 < notif.nent_floatcount) ? ...((notif.nent_stringcount + 1), float) : 0);
248         float f3 = ((2 < notif.nent_floatcount) ? ...((notif.nent_stringcount + 2), float) : 0);
249         float f4 = ((3 < notif.nent_floatcount) ? ...((notif.nent_stringcount + 3), float) : 0);
250
251         #ifdef NOTIFICATIONS_DEBUG
252         dprint(
253                 sprintf("Local_Notification(%d, %s, %s, %s);\n",
254                         net_type,
255                         notif.nent_name,
256                         sprintf("'%s^7', '%s^7', '%s^7', '%s^7'", s1, s2, s3, s4),
257                         sprintf("%d, %d, %d, %d", f1, f2, f3, f4)
258                 )
259         );
260         #endif
261         
262         switch(net_type)
263         {
264                 case MSG_INFO:
265                 {
266                         print(
267                                 Local_Notification_sprintf(
268                                         notif.nent_string,
269                                         notif.nent_args, 
270                                         s1, s2, s3, s4,
271                                         f1, f2, f3, f4)
272                         );
273                         #ifdef CSQC 
274                         if(notif.nent_icon != "")
275                         {
276                                 Local_Notification_HUD_Notify_Push(
277                                         notif.nent_icon,
278                                         notif.nent_hudargs,
279                                         s1, s2, s3, s4);
280                         } 
281                         #endif 
282                         break;
283                 }
284                 
285                 #ifdef CSQC
286                 case MSG_CENTER:
287                 {
288                         centerprint_generic(
289                                 notif.nent_cpid,
290                                 Local_Notification_sprintf(
291                                         notif.nent_string,
292                                         notif.nent_args, 
293                                         s1, s2, s3, s4,
294                                         f1, f2, f3, f4),
295                                 0, 0);
296                         break;
297                 }
298                 #endif
299                 
300                 case MSG_WEAPON:
301                 case MSG_DEATH:
302                 {
303                         if(notif.nent_msginfo)
304                         if(notif.nent_msginfo.nent_enabled)
305                         {
306                                 Local_Notification_WOVA(
307                                         MSG_INFO,
308                                         notif.nent_msginfo.nent_id, 
309                                         notif.nent_msginfo.nent_stringcount, 
310                                         notif.nent_msginfo.nent_floatcount, 
311                                         s1, s2, s3, s4,
312                                         f1, f2, f3, f4);
313                         }
314                         #ifdef CSQC
315                         if(notif.nent_msgcenter)
316                         if(notif.nent_msgcenter.nent_enabled)
317                         {
318                                 Local_Notification_WOVA(
319                                         MSG_CENTER,
320                                         notif.nent_msgcenter.nent_id, 
321                                         notif.nent_msgcenter.nent_stringcount, 
322                                         notif.nent_msgcenter.nent_floatcount, 
323                                         s1, s2, s3, s4,
324                                         f1, f2, f3, f4); 
325                         }
326                         #endif
327                         break;
328                 }
329         }
330 }
331
332 // WOVA = Without Variable Arguments 
333 void Local_Notification_WOVA(float net_type, float net_name,
334         float stringcount, float floatcount,
335         string s1, string s2, string s3, string s4,
336         float f1, float f2, float f3, float f4)
337 {
338         #define VARITEM(stringc,floatc,args) \
339                 if((stringcount == stringc) && (floatcount == floatc)) \
340                         { Local_Notification(net_type, net_name, args); return; }
341         EIGHT_VARS_TO_VARARGS_VARLIST
342         #undef VARITEM
343         Local_Notification(net_type, net_name); // some notifications don't have any arguments at all
344 }
345
346
347 // =========================
348 //  Notification Networking
349 // =========================
350
351 #ifdef CSQC
352 void Read_Notification(float is_new)
353 {
354         float net_type = ReadByte();
355         float net_name = ReadShort();
356
357         entity notif = Get_Notif_Ent(net_type, net_name);
358         if not(notif) { print("Read_Notification: Could not find notification entity!\n"); return; }
359
360         string s1 = ((0 < notif.nent_stringcount) ? ReadString() : "");
361         string s2 = ((1 < notif.nent_stringcount) ? ReadString() : "");
362         string s3 = ((2 < notif.nent_stringcount) ? ReadString() : "");
363         string s4 = ((3 < notif.nent_stringcount) ? ReadString() : "");
364         float f1 = ((0 < notif.nent_floatcount) ? ReadLong() : 0);
365         float f2 = ((1 < notif.nent_floatcount) ? ReadLong() : 0);
366         float f3 = ((2 < notif.nent_floatcount) ? ReadLong() : 0);
367         float f4 = ((3 < notif.nent_floatcount) ? ReadLong() : 0);
368
369         #ifdef NOTIFICATIONS_DEBUG
370         dprint(sprintf("Read_Notification(%d) at %f: net_name = %s.\n", is_new, time, notif.nent_name));
371         #endif
372         
373         if(is_new)
374         {
375                 Local_Notification_WOVA(
376                         net_type, net_name,
377                         notif.nent_stringcount,
378                         notif.nent_floatcount,
379                         s1, s2, s3, s4,
380                         f1, f2, f3, f4);
381         }
382 }
383 #endif
384
385 #ifdef SVQC
386 void Net_Notification_Remove()
387 {
388         float i;
389         for(i = 0; i < 4; ++i) { if(self.nent_strings[i]) { strunzone(self.nent_strings[i]); } }
390         remove(self);
391 }
392
393 float Net_Write_Notification(entity client, float sf)
394 {
395         float i, send = FALSE;
396         
397         switch(self.nent_broadcast)
398         {
399                 case NOTIF_ONE: // send to one client and their spectator
400                 {
401                         if(
402                                 (client == self.nent_client)
403                                 ||
404                                 (
405                                         (client.classname == STR_SPECTATOR)
406                                         &&
407                                         (client.enemy == self.nent_client)
408                                 )
409                         ) { send = TRUE; }
410                         break;
411                 }
412                 case NOTIF_ONE_ONLY: // send ONLY to one client
413                 {
414                         if(client == self.nent_client) { send = TRUE; }
415                         break;
416                 }
417                 case NOTIF_TEAM: // send only to X team and their spectators
418                 {
419                         if(
420                                 (client.team == self.nent_client.team)
421                                 ||
422                                 (
423                                         (client.classname == STR_SPECTATOR)
424                                         &&
425                                         (client.enemy.team == self.nent_client.team)
426                                 )
427                         ) { send = TRUE; }
428                         break;
429                 }
430                 case NOTIF_TEAM_EXCEPT: // send only to X team and their spectators, except for Y person and their spectators
431                 {
432                         if(
433                                 (client != self.nent_client)
434                                 &&
435                                 (
436                                         (client.team == self.nent_client.team)
437                                         ||
438                                         (
439                                                 (client.classname == STR_SPECTATOR)
440                                                 &&
441                                                 (
442                                                         (client.enemy != self.nent_client)
443                                                         &&
444                                                         (client.enemy.team == self.nent_client.team)
445                                                 )
446                                         )
447                                 )
448                         ) { send = TRUE; }
449                         break;
450                 }
451                 case NOTIF_ANY: // send to everyone
452                 {
453                         send = TRUE;
454                         break;
455                 }
456                 case NOTIF_ANY_EXCEPT: // send to everyone except X person and their spectators
457                 {
458                         if(
459                                 (client != self.nent_client)
460                                 &&
461                                 !(
462                                         (client.classname == STR_SPECTATOR)
463                                         &&
464                                         (client.enemy == self.nent_client)
465                                 )
466                         ) { send = TRUE; }
467                         break;
468                 }
469                 default: { send = FALSE; break; }
470         }
471
472         if(send)
473         {               
474                 WriteByte(MSG_ENTITY, ENT_CLIENT_NOTIFICATION);
475                 WriteByte(MSG_ENTITY, self.nent_net_type);
476                 WriteShort(MSG_ENTITY, self.nent_net_name);
477                 for(i = 0; i < self.nent_stringcount; ++i) { WriteString(MSG_ENTITY, self.nent_strings[i]); } 
478                 for(i = 0; i < self.nent_floatcount; ++i) { WriteLong(MSG_ENTITY, self.nent_floats[i]); }
479         }
480
481         return send; 
482 }
483
484 void Send_Notification(float broadcast, entity client,
485         float net_type, float net_name, ...count)
486 {
487         // check supplied broadcast, target, type, and name for errors
488         string checkargs = "";
489         #define CHECKARG_TYPENAME(type) case MSG_##type##: \
490                 { if(!net_name || (net_name > NOTIF_##type##_COUNT)) \
491                 { checkargs = sprintf("Improper name: %d!", net_name); } break; }
492         switch(net_type)
493         {
494                 CHECKARG_TYPENAME(INFO)
495                 CHECKARG_TYPENAME(CENTER)
496                 CHECKARG_TYPENAME(WEAPON)
497                 CHECKARG_TYPENAME(DEATH)
498                 default: { checkargs = sprintf("Improper type: %d!", checkargs, net_type); break; }
499         }
500         #undef CHECKARG_TYPENAME
501         if(checkargs != "") { checkargs = strcat(checkargs, " "); }
502         switch(broadcast)
503         {
504                 case NOTIF_ONE:
505                 case NOTIF_ONE_ONLY:
506                 {
507                         if(IS_NOT_A_CLIENT(client))
508                                 { checkargs = sprintf("%sNo client provided!", checkargs); }
509                         break;
510                 }
511                 
512                 case NOTIF_ANY_EXCEPT:
513                 {
514                         if(IS_NOT_A_CLIENT(client))
515                                 { checkargs = sprintf("%sException can't be a non-client!", checkargs); }
516                         break;
517                 }
518                 
519                 case NOTIF_ANY:
520                 {
521                         if(client)
522                                 { checkargs = sprintf("%sEntity provided when world was required!", checkargs); }
523                         break;
524                 }
525                 
526                 case NOTIF_TEAM:
527                 case NOTIF_TEAM_EXCEPT:
528                 {
529                         if not(teamplay) { checkargs = sprintf("%sTeamplay not active!", checkargs); }
530                         else if(IS_NOT_A_CLIENT(client))
531                         {
532                                 if(broadcast == NOTIF_TEAM) { checkargs = sprintf("%sNo client provided!", checkargs); }
533                                 else { checkargs = sprintf("%sException can't be a non-client!", checkargs); }
534                         }
535                         break;
536                 }
537                 
538                 default: { checkargs = sprintf("%sImproper broadcast: %d!", checkargs, broadcast); break; }
539         }
540         if(checkargs != "") { backtrace(sprintf("Incorrect usage of Send_Notification: %s\n", checkargs)); return; }
541
542         // retreive counts for the arguments of this notification
543         entity notif = Get_Notif_Ent(net_type, net_name);
544         if not(notif) { backtrace("Send_Notification: Could not find notification entity!\n"); return; }
545
546         if((notif.nent_stringcount + notif.nent_floatcount) > count)
547         {
548                 backtrace(sprintf(
549                         strcat(
550                                 "Not enough arguments for Send_Notification! ",
551                                 "stringcount(%d) + floatcount(%d) > count(%d)\n", 
552                                 "Check the definition and function call for accuracy...?\n"
553                         ),
554                         notif.nent_stringcount, notif.nent_floatcount, count));
555                 return;
556         }
557         else if((notif.nent_stringcount + notif.nent_floatcount) < count)
558         {
559                 backtrace(sprintf(
560                         strcat(
561                                 "Too many arguments for Send_Notification! ",
562                                 "stringcount(%d) + floatcount(%d) < count(%d)\n",
563                                 "Check the definition and function call for accuracy...?\n"
564                         ),
565                         notif.nent_stringcount, notif.nent_floatcount, count));
566                 return;
567         }
568         
569         #ifdef NOTIFICATIONS_DEBUG
570         dprint(
571                 sprintf("Send_Notification(%d, %d, %s, stringcount: %d, floatcount: %d, varargs: %d);\n",
572                         broadcast,
573                         net_type,
574                         notif.nent_name,
575                         notif.nent_stringcount,
576                         notif.nent_floatcount,
577                         count
578                 )
579         );
580         #endif
581
582         entity net_notif = spawn();
583         net_notif.nent_broadcast = broadcast;
584         net_notif.nent_client = client;
585         net_notif.nent_net_type = net_type;
586         net_notif.nent_net_name = net_name;
587         net_notif.nent_stringcount = notif.nent_stringcount;
588         net_notif.nent_floatcount = notif.nent_floatcount;
589         
590         float i;
591         for(i = 0; i < net_notif.nent_stringcount; ++i) { net_notif.nent_strings[i] = strzone(...(i, string)); }
592         for(i = 0; i < net_notif.nent_floatcount; ++i) { net_notif.nent_floats[i] = ...((net_notif.nent_stringcount + i), float); }
593         
594         net_notif.think = Net_Notification_Remove;
595         net_notif.nextthink = (time + 0.5); 
596
597         Net_LinkEntity(net_notif, FALSE, 0, Net_Write_Notification);
598
599         if((!server_is_local) && (broadcast == NOTIF_ANY || broadcast == NOTIF_ANY_EXCEPT) && (net_type != MSG_CENTER))
600         {
601                 Local_Notification_WOVA(
602                         net_type, net_name,
603                         notif.nent_stringcount,
604                         notif.nent_floatcount,
605                         IFSTR(0), IFSTR(1), IFSTR(2), IFSTR(3),
606                         IFFL(0), IFFL(1), IFFL(2), IFFL(3));
607         }
608 }
609
610 // WOVA = Without Variable Arguments 
611 void Send_Notification_WOVA(float broadcast, entity client,
612         float net_type, float net_name,
613         string s1, string s2, string s3, string s4,
614         float f1, float f2, float f3, float f4)
615 {
616         entity notif = Get_Notif_Ent(net_type, net_name);
617         #define VARITEM(stringc,floatc,args) \
618                 if((notif.nent_stringcount == stringc) && (notif.nent_floatcount == floatc)) \
619                         { Send_Notification(broadcast, client, net_type, net_name, args); return; }
620         EIGHT_VARS_TO_VARARGS_VARLIST
621         #undef VARITEM
622         Send_Notification(broadcast, client, net_type, net_name); // some notifications don't have any arguments at all
623 }
624
625
626 // =============================
627 //  LEGACY NOTIFICATION SYSTEMS
628 // =============================
629
630 #define Send_CSQC_Centerprint_Generic_Expire(e,id) Send_CSQC_Centerprint_Generic(e, id, "", 1, 0)
631
632 void Send_CSQC_Centerprint_Generic(entity e, float id, string s, float duration, float countdown_num)
633 {
634         if ((clienttype(e) == CLIENTTYPE_REAL) && (e.flags & FL_CLIENT))
635         {
636                 msg_entity = e;
637                 WRITESPECTATABLE_MSG_ONE({
638                         WriteByte(MSG_ONE, SVC_TEMPENTITY);
639                         WriteByte(MSG_ONE, TE_CSQC_CENTERPRINT_GENERIC);
640                         WriteByte(MSG_ONE, id);
641                         WriteString(MSG_ONE, s);
642                         if (id != 0 && s != "")
643                         {
644                                 WriteByte(MSG_ONE, duration);
645                                 WriteByte(MSG_ONE, countdown_num);
646                         }
647                 });
648         }
649 }
650 #endif // ifdef SVQC