]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/common/notifications.qc
Clean up macros
[xonotic/xonotic-data.pk3dir.git] / qcsrc / common / notifications.qc
1 // ================================================
2 //  Unified notification system, written by Samual
3 //  Last updated: August, 2013
4 // ================================================
5
6 string Get_Notif_TypeName(int net_type)
7 {
8         switch(net_type)
9         {
10                 case MSG_ANNCE: return "MSG_ANNCE";
11                 case MSG_INFO: return "MSG_INFO";
12                 case MSG_CENTER: return "MSG_CENTER";
13                 case MSG_CENTER_CPID: return "MSG_CENTER_CPID";
14                 case MSG_MULTI: return "MSG_MULTI";
15                 case MSG_CHOICE: return "MSG_CHOICE";
16         }
17         backtrace(sprintf("Get_Notif_TypeName(%d): Improper net type!\n", net_type));
18         return "";
19 }
20
21 entity Get_Notif_Ent(int net_type, int net_name)
22 {
23         switch(net_type)
24         {
25                 case MSG_ANNCE: return msg_annce_notifs[net_name - 1];
26                 case MSG_INFO: return msg_info_notifs[net_name - 1];
27                 case MSG_CENTER: return msg_center_notifs[net_name - 1];
28                 case MSG_MULTI: return msg_multi_notifs[net_name - 1];
29                 case MSG_CHOICE: return msg_choice_notifs[net_name - 1];
30         }
31         backtrace(sprintf("Get_Notif_Ent(%d, %d): Improper net type!\n", net_type, net_name));
32         return world;
33 }
34
35 #ifdef SVQC
36 #ifdef NOTIFICATIONS_DEBUG
37 string Get_Notif_BroadcastName(float broadcast)
38 {
39         switch(broadcast)
40         {
41                 case NOTIF_ONE: return "NOTIF_ONE";
42                 case NOTIF_ONE_ONLY: return "NOTIF_ONE_ONLY";
43                 case NOTIF_ALL_EXCEPT: return "NOTIF_ALL_EXCEPT";
44                 case NOTIF_ALL: return "NOTIF_ALL";
45                 case NOTIF_TEAM: return "NOTIF_TEAM";
46                 case NOTIF_TEAM_EXCEPT: return "NOTIF_TEAM_EXCEPT";
47         }
48         backtrace(sprintf("Get_Notif_BroadcastName(%d): Improper broadcast!\n", broadcast));
49         return "";
50 }
51 #endif
52 #endif
53
54 string Notification_CheckArgs_TypeName(float net_type, float net_name)
55 {
56         // check supplied type and name for errors
57         string checkargs = "";
58         #define CHECKARG_TYPENAME(type) case MSG_##type##: \
59                 { if(!net_name || (net_name > NOTIF_##type##_COUNT)) \
60                 { checkargs = sprintf("Improper name: %d!", net_name); } break; }
61         switch(net_type)
62         {
63                 CHECKARG_TYPENAME(ANNCE)
64                 CHECKARG_TYPENAME(INFO)
65                 CHECKARG_TYPENAME(CENTER)
66                 CHECKARG_TYPENAME(MULTI)
67                 CHECKARG_TYPENAME(CHOICE)
68                 default: { checkargs = sprintf("Improper type: %d!", checkargs, net_type); break; }
69         }
70         #undef CHECKARG_TYPENAME
71         return checkargs;
72 }
73
74 #ifdef SVQC
75 string Notification_CheckArgs(
76         float broadcast, entity client,
77         float net_type, float net_name)
78 {
79         // check supplied broadcast, target, type, and name for errors
80         string checkargs = Notification_CheckArgs_TypeName(net_type, net_name);
81         if(checkargs != "") { checkargs = strcat(checkargs, " "); }
82         switch(broadcast)
83         {
84                 case NOTIF_ONE:
85                 case NOTIF_ONE_ONLY:
86                 {
87                         if(IS_NOT_A_CLIENT(client))
88                                 { checkargs = sprintf("%sNo client provided!", checkargs); }
89                         break;
90                 }
91
92                 case NOTIF_ALL_EXCEPT:
93                 {
94                         if(IS_NOT_A_CLIENT(client))
95                                 { checkargs = sprintf("%sException can't be a non-client!", checkargs); }
96                         break;
97                 }
98
99                 case NOTIF_ALL:
100                 {
101                         if(client)
102                                 { checkargs = sprintf("%sEntity provided when world was required!", checkargs); }
103                         break;
104                 }
105
106                 case NOTIF_TEAM:
107                 {
108                         if (!teamplay)
109                                 { checkargs = sprintf("%sTeamplay not active!", checkargs); }
110                         //else if (!client.team) { checkargs = sprintf("%sNo team provided!", checkargs); }
111                         break;
112                 }
113
114                 case NOTIF_TEAM_EXCEPT:
115                 {
116                         if (!teamplay)
117                                 { checkargs = sprintf("%sTeamplay not active!", checkargs); }
118                         else if(IS_NOT_A_CLIENT(client))
119                                 { checkargs = sprintf("%sException can't be a non-client!", checkargs); }
120                         break;
121                 }
122
123                 default: { checkargs = sprintf("%sImproper broadcast: %d!", checkargs, broadcast); break; }
124         }
125         return checkargs;
126 }
127
128 float Notification_ShouldSend(float broadcast, entity to_client, entity other_client)
129 {
130         switch(broadcast)
131         {
132                 case NOTIF_ONE: // send to one client and their spectator
133                 {
134                         if(
135                                 (to_client == other_client)
136                                 ||
137                                 (
138                                         IS_SPEC(to_client)
139                                         &&
140                                         (to_client.enemy == other_client)
141                                 )
142                         ) { return true; }
143                         break;
144                 }
145                 case NOTIF_ONE_ONLY: // send ONLY to one client
146                 {
147                         if(to_client == other_client) { return true; }
148                         break;
149                 }
150                 case NOTIF_TEAM: // send only to X team and their spectators
151                 {
152                         if(
153                                 (to_client.team == other_client.team)
154                                 ||
155                                 (
156                                         IS_SPEC(to_client)
157                                         &&
158                                         (to_client.enemy.team == other_client.team)
159                                 )
160                         ) { return true; }
161                         break;
162                 }
163                 case NOTIF_TEAM_EXCEPT: // send only to X team and their spectators, except for Y person and their spectators
164                 {
165                         if(
166                                 (to_client != other_client)
167                                 &&
168                                 (
169                                         (to_client.team == other_client.team)
170                                         ||
171                                         (
172                                                 IS_SPEC(to_client)
173                                                 &&
174                                                 (
175                                                         (to_client.enemy != other_client)
176                                                         &&
177                                                         (to_client.enemy.team == other_client.team)
178                                                 )
179                                         )
180                                 )
181                         ) { return true; }
182                         break;
183                 }
184                 case NOTIF_ALL: // send to everyone
185                 {
186                         return true;
187                 }
188                 case NOTIF_ALL_EXCEPT: // send to everyone except X person and their spectators
189                 {
190                         if(
191                                 (to_client != other_client)
192                                 &&
193                                 !(
194                                         IS_SPEC(to_client)
195                                         &&
196                                         (to_client.enemy == other_client)
197                                 )
198                         ) { return true; }
199                         break;
200                 }
201         }
202         return false;
203 }
204
205 #endif
206
207 // ===============================
208 //  Initialization Core Functions
209 // ===============================
210
211 // used by restartnotifs command to initialize notifications
212 void Destroy_Notification_Entity(entity notif)
213 {
214         if(notif.nent_name != "") { strunzone(notif.nent_name); }
215         if(notif.nent_snd != "") { strunzone(notif.nent_snd); }
216         if(notif.nent_args != "") { strunzone(notif.nent_args); }
217         if(notif.nent_hudargs != "") { strunzone(notif.nent_hudargs); }
218         if(notif.nent_icon != "") { strunzone(notif.nent_icon); }
219         if(notif.nent_durcnt != "") { strunzone(notif.nent_durcnt); }
220         if(notif.nent_string != "") { strunzone(notif.nent_string); }
221         remove(notif);
222 }
223
224 void Destroy_All_Notifications(void)
225 {
226         entity notif;
227         int i;
228
229         #define DESTROY_LOOP(type,count) do { \
230                 for(i = 1; i <= count; ++i) \
231                 { \
232                         notif = Get_Notif_Ent(type, i); \
233                         if (!notif) { backtrace("Destroy_All_Notifications(): Missing notification entity!\n"); return; } \
234                         Destroy_Notification_Entity(notif); \
235                 } \
236         } while(0)
237
238         // kill all networked notifications and centerprints
239         #ifdef SVQC
240         Kill_Notification(NOTIF_ALL, world, 0, 0);
241         #else
242         reset_centerprint_messages();
243         #endif
244
245         // kill all real notification entities
246         DESTROY_LOOP(MSG_ANNCE, NOTIF_ANNCE_COUNT);
247         DESTROY_LOOP(MSG_INFO, NOTIF_INFO_COUNT);
248         DESTROY_LOOP(MSG_CENTER, NOTIF_CENTER_COUNT);
249         DESTROY_LOOP(MSG_MULTI, NOTIF_MULTI_COUNT);
250         DESTROY_LOOP(MSG_CHOICE, NOTIF_CHOICE_COUNT);
251         #undef DESTROY_LOOP
252 }
253
254 string Process_Notif_Line(
255         int typeId,
256         bool chat,
257         string input,
258         string notiftype,
259         string notifname,
260         string stringtype)
261 {
262         #ifdef CSQC
263         if(typeId == MSG_INFO)
264         {
265                 if((chat && autocvar_notification_allow_chatboxprint)
266                         || (autocvar_notification_allow_chatboxprint == 2))
267                 {
268                         // pass 1: add ETX char at beginning of line
269                         input = strcat("\{3}", input);
270
271                         // pass 2: add ETX char at end of each new line (so that
272                         // messages with multiple lines are put through chatbox too)
273                         input = strreplace("\n", "\n\{3}", input);
274
275                         // pass 3: strip trailing ETX char
276                         if(substring(input, (strlen(input) - 1), 1) == "\{3}")
277                                 { input = substring(input, 0, (strlen(input) - 1)); }
278                 }
279         }
280         #endif
281
282         // done to both MSG_INFO and MSG_CENTER
283         if(substring(input, (strlen(input) - 1), 1) == "\n")
284         {
285                 printf(
286                         strcat(
287                                 "^1TRAILING NEW LINE AT END OF NOTIFICATION: ",
288                                 "^7net_type = %s, net_name = %s, string = %s.\n"
289                         ),
290                         notiftype,
291                         notifname,
292                         stringtype
293                 );
294                 notif_error = true;
295                 input = substring(input, 1, (strlen(input) - 1));
296         }
297
298         return input;
299 }
300
301 string Process_Notif_Args(
302         float arg_type,
303         string args,
304         string notiftype,
305         string notifname)
306 {
307         string selected, remaining = args;
308         float sel_num = 0;
309
310         for(0;(remaining != "");)
311         {
312                 selected = car(remaining); remaining = cdr(remaining);
313
314                 switch(arg_type)
315                 {
316                         case 1: // normal args
317                         {
318                                 if(sel_num == NOTIF_MAX_ARGS)
319                                 {
320                                         printf(
321                                                 strcat(
322                                                         "^1NOTIFICATION HAS TOO MANY ARGUMENTS: ",
323                                                         "^7net_type = %s, net_name = %s, max args = %d.\n"
324                                                 ),
325                                                 notiftype,
326                                                 notifname,
327                                                 NOTIF_MAX_ARGS
328                                         );
329                                         notif_error = true;
330                                         break;
331                                 }
332
333                                 switch(strtolower(selected))
334                                 {
335                                         #define ARG_CASE_ARG_CS_SV_HA(selected,result) case selected: { ++sel_num; break; }
336                                         #define ARG_CASE_ARG_CS_SV_DC(selected,result) case selected: { ++sel_num; break; }
337                                         #define ARG_CASE_ARG_CS_SV(selected,result)    case selected: { ++sel_num; break; }
338                                         #define ARG_CASE_ARG_CS(selected,result)       case selected: { ++sel_num; break; }
339                                         #define ARG_CASE_ARG_SV(selected,result)       case selected: { ++sel_num; break; }
340                                         #define ARG_CASE_ARG_DC(selected,result)
341                                         #define ARG_CASE(prog,selected,result)         ARG_CASE_##prog(selected,result)
342                                         NOTIF_ARGUMENT_LIST
343                                         #undef ARG_CASE
344                                         #undef ARG_CASE_ARG_DC
345                                         #undef ARG_CASE_ARG_SV
346                                         #undef ARG_CASE_ARG_CS
347                                         #undef ARG_CASE_ARG_CS_SV
348                                         #undef ARG_CASE_ARG_CS_SV_DC
349                                         #undef ARG_CASE_ARG_CS_SV_HA
350                                         default:
351                                         {
352                                                 printf(
353                                                         strcat(
354                                                                 "^1NOTIFICATION WITH UNKNOWN TOKEN IN ARGUMENT STRING: ",
355                                                                 "^7net_type = %s, net_name = %s, args arg = '%s'.\n"
356                                                         ),
357                                                         notiftype,
358                                                         notifname,
359                                                         selected
360                                                 );
361                                                 notif_error = true;
362                                                 break;
363                                         }
364                                 }
365                                 break;
366                         }
367                         case 2: // hudargs
368                         {
369                                 if(sel_num == NOTIF_MAX_HUDARGS)
370                                 {
371                                         printf(
372                                                 strcat(
373                                                         "^1NOTIFICATION HAS TOO MANY ARGUMENTS: ",
374                                                         "^7net_type = %s, net_name = %s, max hudargs = %d.\n"
375                                                 ),
376                                                 notiftype,
377                                                 notifname,
378                                                 NOTIF_MAX_HUDARGS
379                                         );
380                                         notif_error = true;
381                                         break;
382                                 }
383
384                                 switch(strtolower(selected))
385                                 {
386                                         #define ARG_CASE_ARG_CS_SV_HA(selected,result) case selected: { ++sel_num; break; }
387                                         #define ARG_CASE_ARG_CS_SV_DC(selected,result)
388                                         #define ARG_CASE_ARG_CS_SV(selected,result)
389                                         #define ARG_CASE_ARG_CS(selected,result)
390                                         #define ARG_CASE_ARG_SV(selected,result)
391                                         #define ARG_CASE_ARG_DC(selected,result)
392                                         #define ARG_CASE(prog,selected,result)         ARG_CASE_##prog(selected,result)
393                                         NOTIF_ARGUMENT_LIST
394                                         #undef ARG_CASE
395                                         #undef ARG_CASE_ARG_DC
396                                         #undef ARG_CASE_ARG_SV
397                                         #undef ARG_CASE_ARG_CS
398                                         #undef ARG_CASE_ARG_CS_SV
399                                         #undef ARG_CASE_ARG_CS_SV_DC
400                                         #undef ARG_CASE_ARG_CS_SV_HA
401                                         default:
402                                         {
403                                                 printf(
404                                                         strcat(
405                                                                 "^1NOTIFICATION WITH UNKNOWN TOKEN IN ARGUMENT STRING: ",
406                                                                 "^7net_type = %s, net_name = %s, hudargs arg = '%s'.\n"
407                                                         ),
408                                                         notiftype,
409                                                         notifname,
410                                                         selected
411                                                 );
412                                                 notif_error = true;
413                                                 break;
414                                         }
415                                 }
416                                 break;
417                         }
418                         case 3: // durcnt
419                         {
420                                 if(sel_num == NOTIF_MAX_DURCNT)
421                                 {
422                                         printf(
423                                                 strcat(
424                                                         "^1NOTIFICATION HAS TOO MANY ARGUMENTS: ",
425                                                         "^7net_type = %s, net_name = %s, max durcnt = %d.\n"
426                                                 ),
427                                                 notiftype,
428                                                 notifname,
429                                                 NOTIF_MAX_DURCNT
430                                         );
431                                         notif_error = true;
432                                         break;
433                                 }
434
435                                 switch(strtolower(selected))
436                                 {
437                                         #define ARG_CASE_ARG_CS_SV_HA(selected,result)
438                                         #define ARG_CASE_ARG_CS_SV_DC(selected,result) case selected: { ++sel_num; break; }
439                                         #define ARG_CASE_ARG_CS_SV(selected,result)
440                                         #define ARG_CASE_ARG_CS(selected,result)
441                                         #define ARG_CASE_ARG_SV(selected,result)
442                                         #define ARG_CASE_ARG_DC(selected,result)       case selected: { ++sel_num; break; }
443                                         #define ARG_CASE(prog,selected,result)         ARG_CASE_##prog(selected,result)
444                                         NOTIF_ARGUMENT_LIST
445                                         #undef ARG_CASE
446                                         #undef ARG_CASE_ARG_DC
447                                         #undef ARG_CASE_ARG_SV
448                                         #undef ARG_CASE_ARG_CS
449                                         #undef ARG_CASE_ARG_CS_SV
450                                         #undef ARG_CASE_ARG_CS_SV_DC
451                                         #undef ARG_CASE_ARG_CS_SV_HA
452                                         default:
453                                         {
454                                                 if(ftos(stof(selected)) != "") { ++sel_num; }
455                                                 else
456                                                 {
457                                                         printf(
458                                                                 strcat(
459                                                                         "^1NOTIFICATION WITH UNKNOWN TOKEN IN ARGUMENT STRING: ",
460                                                                         "^7net_type = %s, net_name = %s, durcnt arg = '%s'.\n"
461                                                                 ),
462                                                                 notiftype,
463                                                                 notifname,
464                                                                 selected
465                                                         );
466                                                         notif_error = true;
467                                                 }
468                                                 break;
469                                         }
470                                 }
471                                 break;
472                         }
473                 }
474         }
475         return args;
476 }
477
478 void Create_Notification_Entity(
479         float var_default,
480         float var_cvar,
481         int typeId,
482         int nameid,
483         string namestring,
484         float strnum,
485         float flnum,
486         /* MSG_ANNCE */
487         float channel,
488         string snd,
489         float vol,
490         float position,
491         /* MSG_INFO & MSG_CENTER */
492         string args,
493         string hudargs,
494         string icon,
495         float cpid,
496         string durcnt,
497         string normal,
498         string gentle,
499         /* MSG_MULTI */
500         int anncename,
501         int infoname,
502         int centername,
503         /* MSG_CHOICE */
504         float challow_def,
505         float challow_var,
506         int chtype,
507         int optiona,
508         int optionb)
509 {
510         // =====================
511         //  Global Entity Setup
512         // =====================
513         entity notif = spawn();
514         switch(typeId)
515         {
516                 case MSG_ANNCE:
517                 {
518                         msg_annce_notifs[nameid - 1] = notif;
519                         notif.classname = "msg_annce_notification";
520                         break;
521                 }
522                 case MSG_INFO:
523                 {
524                         msg_info_notifs[nameid - 1] = notif;
525                         notif.classname = "msg_info_notification";
526                         break;
527                 }
528                 case MSG_CENTER:
529                 {
530                         msg_center_notifs[nameid - 1] = notif;
531                         notif.classname = "msg_center_notification";
532                         break;
533                 }
534                 case MSG_MULTI:
535                 {
536                         msg_multi_notifs[nameid - 1] = notif;
537                         notif.classname = "msg_multi_notification";
538                         break;
539                 }
540                 case MSG_CHOICE:
541                 {
542                         msg_choice_notifs[nameid - 1] = notif;
543                         notif.classname = "msg_choice_notification";
544                         break;
545                 }
546
547                 default:
548                 {
549                         error(sprintf(
550                                 strcat(
551                                         "^1NOTIFICATION WITH IMPROPER TYPE: ",
552                                         "^7net_type = %d, net_name = %s.\n"
553                                 ),
554                                 typeId,
555                                 namestring
556                         ));
557                         return; // It's not possible to recover from this one
558                 }
559         }
560         notif.nent_default = var_default;
561         notif.nent_enabled = (1 <= var_cvar);
562         notif.nent_type = typeId;
563         notif.nent_id = nameid;
564         notif.nent_name = strzone(namestring);
565
566         string typestring = Get_Notif_TypeName(typeId);
567
568         // Other pre-notif-setup requisites
569         notif_error = false;
570
571         // ====================
572         //  Notification Setup
573         // ====================
574         switch(typeId)
575         {
576                 case MSG_ANNCE:
577                 {
578                         // Set MSG_ANNCE information and handle precaching
579                         #ifdef CSQC
580                         if (!(GENTLE && (var_cvar == 1)))
581                         {
582                                 if(snd != "")
583                                 {
584                                         if(notif.nent_enabled)
585                                         {
586                                                 precache_sound(sprintf("announcer/%s/%s.wav", autocvar_cl_announcer, snd));
587                                                 notif.nent_channel = channel;
588                                                 notif.nent_snd = strzone(snd);
589                                                 notif.nent_vol = vol;
590                                                 notif.nent_position = position;
591                                         }
592                                 }
593                                 else
594                                 {
595                                         printf(
596                                                 strcat(
597                                                         "^1NOTIFICATION WITH NO SOUND: ",
598                                                         "^7net_type = %s, net_name = %s.\n"
599                                                 ),
600                                                 typestring,
601                                                 namestring
602                                         );
603                                         notif_error = true;
604                                 }
605                         }
606                         else { notif.nent_enabled = false; }
607                         #else
608                         notif.nent_enabled = false;
609                         #endif
610
611                         break;
612                 }
613
614                 case MSG_INFO:
615                 case MSG_CENTER:
616                 {
617                         // Set MSG_INFO and MSG_CENTER string/float counts
618                         notif.nent_stringcount = strnum;
619                         notif.nent_floatcount = flnum;
620
621                         // Only initialize arguments if we're either a client or on a dedicated server
622                         #ifdef SVQC
623                         float should_process_args = server_is_dedicated;
624                         #else
625                         float should_process_args = true;
626                         #endif
627
628                         if(should_process_args)
629                         {
630                                 // ========================
631                                 //  Process Main Arguments
632                                 // ========================
633                                 if(strnum + flnum)
634                                 {
635                                         if(args != "")
636                                         {
637                                                 notif.nent_args = strzone(
638                                                         Process_Notif_Args(1, args, typestring, namestring));
639                                         }
640                                         else if((hudargs == "") && (durcnt ==""))
641                                         {
642                                                 printf(
643                                                         strcat(
644                                                                 "^1NOTIFICATION HAS ARG COUNTS BUT NO ARGS OR HUDARGS OR DURCNT: ",
645                                                                 "^7net_type = %s, net_name = %s, strnum = %d, flnum = %d\n"
646                                                         ),
647                                                         typestring,
648                                                         namestring,
649                                                         strnum,
650                                                         flnum
651                                                 );
652                                                 notif_error = true;
653                                         }
654                                 }
655                                 else if(args != "")
656                                 {
657                                         notif.nent_args = strzone(
658                                                 Process_Notif_Args(1, args, typestring, namestring));
659                                 }
660
661
662                                 // =======================================
663                                 //  Process HUD and Centerprint Arguments
664                                 //    Only processed on CSQC, as these
665                                 //    args are only for HUD features.
666                                 // =======================================
667                                 #ifdef CSQC
668                                 if(hudargs != "")
669                                 {
670                                         notif.nent_hudargs = strzone(
671                                                 Process_Notif_Args(2, hudargs, typestring, namestring));
672
673                                         if(icon != "") { notif.nent_icon = strzone(icon); }
674                                         else
675                                         {
676                                                 printf(
677                                                         strcat(
678                                                                 "^1NOTIFICATION HAS HUDARGS BUT NO ICON: ",
679                                                                 "^7net_type = %s, net_name = %s.\n"
680                                                         ),
681                                                         typestring,
682                                                         namestring
683                                                 );
684                                                 notif_error = true;
685                                         }
686                                 }
687                                 else if(icon != "")
688                                 {
689                                         printf(
690                                                 strcat(
691                                                         "^1NOTIFICATION HAS ICON BUT NO HUDARGS: ",
692                                                         "^7net_type = %s, net_name = %s.\n"
693                                                 ),
694                                                 typestring,
695                                                 namestring
696                                         );
697                                         notif_error = true;
698                                 }
699
700                                 if(durcnt != "")
701                                 {
702                                         notif.nent_durcnt = strzone(
703                                                 Process_Notif_Args(3, durcnt, typestring, namestring));
704
705                                         if(cpid != NO_MSG) { notif.nent_cpid = cpid; }
706                                         else
707                                         {
708                                                 printf(
709                                                         strcat(
710                                                                 "^1NOTIFICATION HAS DURCNT BUT NO CPID: ",
711                                                                 "^7net_type = %s, net_name = %s.\n"
712                                                         ),
713                                                         typestring,
714                                                         namestring
715                                                 );
716                                                 notif_error = true;
717                                         }
718                                 }
719                                 else if(cpid != NO_MSG) { notif.nent_cpid = cpid; }
720                                 #endif
721
722
723                                 // ======================
724                                 //  Process Notif String
725                                 // ======================
726                                 #define SET_NOTIF_STRING(string,stringname) do { \
727                                         notif.nent_string = strzone(CCR( \
728                                                 Process_Notif_Line( \
729                                                         typeId, \
730                                                         (var_cvar > 1), \
731                                                         string, \
732                                                         typestring, \
733                                                         namestring, \
734                                                         stringname \
735                                                 )) \
736                                         ); \
737                                 } while(0)
738
739                                 if(GENTLE)
740                                 {
741                                         if(gentle != "") { SET_NOTIF_STRING(gentle, "GENTLE"); }
742                                         else if(normal != "") { SET_NOTIF_STRING(normal, "NORMAL"); }
743                                 }
744                                 else if(normal != "") { SET_NOTIF_STRING(normal, "NORMAL"); }
745                                 #undef SET_NOTIF_STRING
746
747                                 // Check to make sure a string was chosen
748                                 if(notif.nent_string == "")
749                                 {
750                                         printf(
751                                                 strcat(
752                                                         "^1EMPTY NOTIFICATION: ",
753                                                         "^7net_type = %s, net_name = %s.\n"
754                                                 ),
755                                                 typestring,
756                                                 namestring
757                                         );
758                                         notif_error = true;
759                                 }
760                         }
761
762                         break;
763                 }
764
765                 case MSG_MULTI:
766                 {
767                         // Set MSG_MULTI string/float counts
768                         if((anncename == NO_MSG) && (infoname == NO_MSG) && (centername == NO_MSG))
769                         {
770                                 printf(
771                                         strcat(
772                                                 "^1NOTIFICATION WITH NO SUBCALLS: ",
773                                                 "^7net_type = %s, net_name = %s.\n"
774                                         ),
775                                         typestring,
776                                         namestring
777                                 );
778                                 notif_error = true;
779                         }
780                         else
781                         {
782                                 // announcements don't actually need any arguments, so lets not even count them.
783                                 if(anncename != NO_MSG) { notif.nent_msgannce = msg_annce_notifs[anncename - 1]; }
784
785                                 float infoname_stringcount = 0, infoname_floatcount = 0;
786                                 float centername_stringcount = 0, centername_floatcount = 0;
787
788                                 if(infoname != NO_MSG)
789                                 {
790                                         notif.nent_msginfo = msg_info_notifs[infoname - 1];
791                                         infoname_stringcount = notif.nent_msginfo.nent_stringcount;
792                                         infoname_floatcount = notif.nent_msginfo.nent_floatcount;
793                                 }
794
795                                 if(centername != NO_MSG)
796                                 {
797                                         notif.nent_msgcenter = msg_center_notifs[centername - 1];
798                                         centername_stringcount = notif.nent_msgcenter.nent_stringcount;
799                                         centername_floatcount = notif.nent_msgcenter.nent_floatcount;
800                                 }
801
802                                 // set the requirements of THIS notification to the totals of its subcalls
803                                 notif.nent_stringcount = max(infoname_stringcount, centername_stringcount);
804                                 notif.nent_floatcount = max(infoname_floatcount, centername_floatcount);
805                         }
806
807                         break;
808                 }
809
810                 case MSG_CHOICE:
811                 {
812                         if((chtype == NO_MSG) || (optiona == NO_MSG) || (optionb == NO_MSG))
813                         {
814                                 printf(
815                                         strcat(
816                                                 "^1NOTIFICATION IS MISSING CHOICE PARAMS: ",
817                                                 "^7net_type = %s, net_name = %s.\n"
818                                         ),
819                                         typestring,
820                                         namestring
821                                 );
822                                 notif_error = true;
823                         }
824                         else
825                         {
826                                 switch(chtype)
827                                 {
828                                         case MSG_ANNCE:
829                                         {
830                                                 notif.nent_optiona = msg_annce_notifs[optiona - 1];
831                                                 notif.nent_optionb = msg_annce_notifs[optionb - 1];
832                                                 break;
833                                         }
834                                         case MSG_INFO:
835                                         {
836                                                 notif.nent_optiona = msg_info_notifs[optiona - 1];
837                                                 notif.nent_optionb = msg_info_notifs[optionb - 1];
838                                                 break;
839                                         }
840                                         case MSG_CENTER:
841                                         {
842                                                 notif.nent_optiona = msg_center_notifs[optiona - 1];
843                                                 notif.nent_optionb = msg_center_notifs[optionb - 1];
844                                                 break;
845                                         }
846                                         case MSG_MULTI:
847                                         {
848                                                 notif.nent_optiona = msg_multi_notifs[optiona - 1];
849                                                 notif.nent_optionb = msg_multi_notifs[optionb - 1];
850                                                 break;
851                                         }
852                                         case MSG_CHOICE: // should we REALLY allow nested options?...
853                                         {
854                                                 notif.nent_optiona = msg_choice_notifs[optiona - 1];
855                                                 notif.nent_optionb = msg_choice_notifs[optionb - 1];
856                                                 break;
857                                         }
858
859                                         default:
860                                         {
861                                                 printf(
862                                                         strcat(
863                                                                 "^1NOTIFICATION WITH IMPROPER TYPE: ",
864                                                                 "^7net_type = %d, net_name = %s.\n"
865                                                         ),
866                                                         typeId,
867                                                         namestring
868                                                 );
869                                                 notif_error = true;
870                                                 break;
871                                         }
872                                 }
873                                 notif.nent_challow_def = challow_def; // 0: never allowed, 1: allowed in warmup, 2: always allowed
874                                 notif.nent_challow_var = challow_var; // 0: never allowed, 1: allowed in warmup, 2: always allowed
875                                 notif.nent_stringcount = max(notif.nent_optiona.nent_stringcount, notif.nent_optionb.nent_stringcount);
876                                 notif.nent_floatcount = max(notif.nent_optiona.nent_floatcount, notif.nent_optionb.nent_floatcount);
877
878                                 /*#ifdef NOTIFICATIONS_DEBUG
879                                 Debug_Notification(sprintf(
880                                         "Create_Notification_Entity(...): MSG_CHOICE: %s\n%s\n%s\n",
881                                         notif.nent_name,
882                                         sprintf(
883                                                 "^ optiona: %s %s : %d %d",
884                                                 Get_Notif_TypeName(notif.nent_optiona.nent_type),
885                                                 notif.nent_optiona.nent_name,
886                                                 notif.nent_optiona.nent_stringcount,
887                                                 notif.nent_optiona.nent_floatcount
888                                         ),
889                                         sprintf(
890                                                 "^ optionb: %s %s : %d %d",
891                                                 Get_Notif_TypeName(notif.nent_optionb.nent_type),
892                                                 notif.nent_optionb.nent_name,
893                                                 notif.nent_optionb.nent_stringcount,
894                                                 notif.nent_optionb.nent_floatcount
895                                         )
896                                 ));
897                                 #endif*/
898                         }
899                         break;
900                 }
901
902                 default:
903                 {
904                         printf(
905                                 strcat(
906                                         "^1NOTIFICATION WITH IMPROPER TYPE: ",
907                                         "^7net_type = %d, net_name = %s.\n"
908                                 ),
909                                 typeId,
910                                 namestring
911                         );
912                         notif_error = true;
913                         break;
914                 }
915         }
916
917         // now check to see if any errors happened
918         if(notif_error)
919         {
920                 notif.nent_enabled = false; // disable the notification so it can't cause trouble
921                 notif_global_error = true; // throw the red flag that an error happened on init
922         }
923 }
924
925
926 // ===============
927 //  Cvar Handling
928 // ===============
929
930 // used by MSG_CHOICE to build list of choices
931 #ifdef SVQC
932 void Notification_GetCvars(void)
933 {
934         float i;
935         for(i = 0; i <= NOTIF_CHOICE_COUNT; ++i)
936         {
937                 GetCvars_handleFloat(
938                         get_cvars_s,
939                         get_cvars_f,
940                         msg_choice_choices[i],
941                         sprintf("notification_%s", msg_choice_notifs[i].nent_name)
942                 );
943         }
944 }
945 #endif
946
947 // used to output notifications.cfg file
948 void Dump_Notifications(float fh, float alsoprint)
949 {
950         #define NOTIF_WRITE(a) { \
951                 fputs(fh, a); \
952                 if(alsoprint) { print(a); } }
953         #define NOTIF_WRITE_ENTITY(description) { \
954                 notif_msg = \
955                         sprintf( \
956                                 "seta notification_%s \"%d\" \"%s\"\n", \
957                                 e.nent_name, e.nent_default, description \
958                         ); \
959                 NOTIF_WRITE(notif_msg) }
960         #define NOTIF_WRITE_ENTITY_CHOICE(descriptiona,descriptionb) { \
961                 notif_msg = \
962                         sprintf( \
963                                 "seta notification_%s \"%d\" \"%s\"\n" \
964                                 "seta notification_%s_ALLOWED \"%d\" \"%s\"\n", \
965                                 e.nent_name, e.nent_default, descriptiona, \
966                                 e.nent_name, e.nent_challow_def, descriptionb \
967                         ); \
968                 NOTIF_WRITE(notif_msg) }
969         #define NOTIF_WRITE_HARDCODED(cvar,default,description) { \
970                 notif_msg = \
971                         sprintf( \
972                                 "seta notification_%s \"%s\" \"%s\"\n", \
973                                 cvar, default, description \
974                         ); \
975                 NOTIF_WRITE(notif_msg) }
976
977         string notif_msg;
978         int i;
979         entity e;
980
981         // Note: This warning only applies to the notifications.cfg file that is output...
982
983         // You ARE supposed to manually edit this function to add i.e. hard coded
984         // notification variables for mutators or game modes or such and then
985         // regenerate the notifications.cfg file from the new code.
986
987         NOTIF_WRITE("// ********************************************** //\n");
988         NOTIF_WRITE("// ** WARNING - DO NOT MANUALLY EDIT THIS FILE ** //\n");
989         NOTIF_WRITE("// **                                          ** //\n");
990         NOTIF_WRITE("// **  This file is automatically generated    ** //\n");
991         NOTIF_WRITE("// **  by code with the command 'dumpnotifs'.  ** //\n");
992         NOTIF_WRITE("// **                                          ** //\n");
993         NOTIF_WRITE("// **  If you add a new notification, please   ** //\n");
994         NOTIF_WRITE("// **  regenerate this file with that command  ** //\n");
995         NOTIF_WRITE("// **  making sure that the output matches     ** //\n");
996         NOTIF_WRITE("// **  with the lists and defaults in code.    ** //\n");
997         NOTIF_WRITE("// **                                          ** //\n");
998         NOTIF_WRITE("// ********************************************** //\n");
999
1000         // These notifications will also append their string as a comment...
1001         // This is not necessary, and does not matter if they vary between config versions,
1002         // it is just a semi-helpful tool for those who want to manually change their user settings.
1003
1004         NOTIF_WRITE(sprintf("\n// MSG_ANNCE notifications (count = %d):\n", NOTIF_ANNCE_COUNT));
1005         for(i = 1; i <= NOTIF_ANNCE_COUNT; ++i)
1006         {
1007                 e = Get_Notif_Ent(MSG_ANNCE, i);
1008                 if (!e) { backtrace("Dump_Notifications(): Missing notification entity!\n"); return; }
1009
1010                 NOTIF_WRITE_ENTITY(
1011                         "0 = disabled, 1 = enabled if gentle mode is off, 2 = always enabled"
1012                 );
1013         }
1014
1015         NOTIF_WRITE(sprintf("\n// MSG_INFO notifications (count = %d):\n", NOTIF_INFO_COUNT));
1016         for(i = 1; i <= NOTIF_INFO_COUNT; ++i)
1017         {
1018                 e = Get_Notif_Ent(MSG_INFO, i);
1019                 if (!e) { backtrace("Dump_Notifications(): Missing notification entity!\n"); return; }
1020
1021                 NOTIF_WRITE_ENTITY(
1022                         "0 = off, 1 = print to console, "
1023                         "2 = print to console and chatbox (if notification_allow_chatboxprint is enabled)"
1024                 );
1025         }
1026
1027         NOTIF_WRITE(sprintf("\n// MSG_CENTER notifications (count = %d):\n", NOTIF_CENTER_COUNT));
1028         for(i = 1; i <= NOTIF_CENTER_COUNT; ++i)
1029         {
1030                 e = Get_Notif_Ent(MSG_CENTER, i);
1031                 if (!e) { backtrace("Dump_Notifications(): Missing notification entity!\n"); return; }
1032
1033                 NOTIF_WRITE_ENTITY(
1034                         "0 = off, 1 = centerprint"
1035                 );
1036         }
1037
1038         NOTIF_WRITE(sprintf("\n// MSG_MULTI notifications (count = %d):\n", NOTIF_MULTI_COUNT));
1039         for(i = 1; i <= NOTIF_MULTI_COUNT; ++i)
1040         {
1041                 e = Get_Notif_Ent(MSG_MULTI, i);
1042                 if (!e) { backtrace("Dump_Notifications(): Missing notification entity!\n"); return; }
1043
1044                 NOTIF_WRITE_ENTITY(
1045                         "Enable this multiple notification"
1046                 );
1047         }
1048
1049         NOTIF_WRITE(sprintf("\n// MSG_CHOICE notifications (count = %d):\n", NOTIF_CHOICE_COUNT));
1050         for(i = 1; i <= NOTIF_CHOICE_COUNT; ++i)
1051         {
1052                 e = Get_Notif_Ent(MSG_CHOICE, i);
1053                 if (!e) { backtrace("Dump_Notifications(): Missing notification entity!\n"); return; }
1054
1055                 NOTIF_WRITE_ENTITY_CHOICE(
1056                         "Choice for this notification 0 = off, 1 = default message, 2 = verbose message",
1057                         "Allow choice for this notification 0 = off, 1 = only in warmup mode, 2 = always"
1058                 );
1059         }
1060
1061         // edit these to match whichever cvars are used for specific notification options
1062         NOTIF_WRITE("\n// HARD CODED notification variables:\n");
1063
1064         NOTIF_WRITE_HARDCODED(
1065                 "allow_chatboxprint", "1",
1066                 "Allow INFO notifications to be printed to chat box"
1067                 "0 = do not allow, "
1068                 "1 = allow only if allowed by individual notification_INFO* cvars, "
1069                 "2 = force all INFO notifications to be printed to the chatbox"
1070         );
1071
1072         NOTIF_WRITE_HARDCODED(
1073                 "debug", "0",
1074                 "Print extra debug information on all notification function calls "
1075                 "(Requires -DNOTIFICATIONS_DEBUG flag to be enabled on QCSRC compilation)... "
1076                 "0 = disabled, 1 = dprint, 2 = print"
1077         );
1078
1079         NOTIF_WRITE_HARDCODED(
1080                 "errors_are_fatal", "1",
1081                 "If a notification fails upon initialization, cause a Host_Error to stop the program"
1082         );
1083
1084         NOTIF_WRITE_HARDCODED(
1085                 "item_centerprinttime", "1.5",
1086                 "How long to show item information centerprint messages (like 'You got the Electro' or such)"
1087         );
1088
1089         NOTIF_WRITE_HARDCODED(
1090                 "lifetime_mapload", "10",
1091                 "Amount of time that notification entities last immediately at mapload (in seconds) "
1092                 "to help prevent notifications from being lost on early init (like gamestart countdown)"
1093         );
1094
1095         NOTIF_WRITE_HARDCODED(
1096                 "lifetime_runtime", "0.5",
1097                 "Amount of time that notification entities last on the server during runtime (In seconds)"
1098         );
1099
1100         NOTIF_WRITE_HARDCODED(
1101                 "server_allows_location", "1",
1102                 "Server side cvar for allowing death messages to show location information too"
1103         );
1104
1105         NOTIF_WRITE_HARDCODED(
1106                 "show_location", "0",
1107                 "Append location information to MSG_INFO death/kill messages"
1108         );
1109
1110         NOTIF_WRITE_HARDCODED(
1111                 "show_location_string", "",
1112                 "Replacement string piped into sprintf, "
1113                 "so you can do different messages like this: ' at the %s' or ' (near %s)'"
1114         );
1115
1116         NOTIF_WRITE_HARDCODED(
1117                 "show_sprees", "1",
1118                 "Print information about sprees in death/kill messages"
1119         );
1120
1121         NOTIF_WRITE_HARDCODED(
1122                 "show_sprees_center", "1",
1123                 "Show spree information in MSG_CENTER messages... "
1124                 "0 = off, 1 = target (but only for first victim) and attacker"
1125         );
1126
1127         NOTIF_WRITE_HARDCODED(
1128                 "show_sprees_center_specialonly", "1",
1129                 "Don't show spree information in MSG_CENTER messages if it isn't an achievement"
1130         );
1131
1132         NOTIF_WRITE_HARDCODED(
1133                 "show_sprees_info", "3",
1134                 "Show spree information in MSG_INFO messages... "
1135                 "0 = off, 1 = target only, 2 = attacker only, 3 = target and attacker"
1136         );
1137
1138         NOTIF_WRITE_HARDCODED(
1139                 "show_sprees_info_newline", "1",
1140                 "Show attacker spree information for MSG_INFO messages on a separate line than the death notification itself"
1141         );
1142
1143         NOTIF_WRITE_HARDCODED(
1144                 "show_sprees_info_specialonly", "1",
1145                 "Don't show attacker spree information in MSG_INFO messages if it isn't an achievement"
1146         );
1147
1148         NOTIF_WRITE(sprintf(
1149                 strcat(
1150                         "\n// Notification counts (total = %d): ",
1151                         "MSG_ANNCE = %d, MSG_INFO = %d, MSG_CENTER = %d, MSG_MULTI = %d, MSG_CHOICE = %d\n"
1152                 ),
1153                 (
1154                         NOTIF_ANNCE_COUNT +
1155                         NOTIF_INFO_COUNT +
1156                         NOTIF_CENTER_COUNT +
1157                         NOTIF_MULTI_COUNT +
1158                         NOTIF_CHOICE_COUNT
1159                 ),
1160                 NOTIF_ANNCE_COUNT,
1161                 NOTIF_INFO_COUNT,
1162                 NOTIF_CENTER_COUNT,
1163                 NOTIF_MULTI_COUNT,
1164                 NOTIF_CHOICE_COUNT
1165         ));
1166
1167         return;
1168         #undef NOTIF_WRITE_HARDCODED
1169         #undef NOTIF_WRITE_ENTITY
1170         #undef NOTIF_WRITE
1171 }
1172
1173
1174 // ===============================
1175 //  Frontend Notification Pushing
1176 // ===============================
1177
1178 #ifdef NOTIFICATIONS_DEBUG
1179 void Debug_Notification(string input)
1180 {
1181         switch(autocvar_notification_debug)
1182         {
1183                 case 1: { dprint(input); break; }
1184                 case 2: { print(input); break; }
1185         }
1186 }
1187 #endif
1188
1189 string Local_Notification_sprintf(
1190         string input, string args,
1191         string s1, string s2, string s3, string s4,
1192         int f1, float f2, float f3, float f4)
1193 {
1194         #ifdef NOTIFICATIONS_DEBUG
1195         Debug_Notification(sprintf(
1196                 "Local_Notification_sprintf('%s^7', '%s', %s, %s);\n",
1197                 MakeConsoleSafe(input),
1198                 args,
1199                 MakeConsoleSafe(sprintf("'%s^7', '%s^7', '%s^7', '%s^7'", s1, s2, s3, s4)),
1200                 sprintf("%d, %d, %d, %d", f1, f2, f3, f4)
1201         ));
1202         #endif
1203
1204         string selected;
1205         int sel_num;
1206         for(sel_num = 0; sel_num < NOTIF_MAX_ARGS; ++sel_num) { arg_slot[sel_num] = ""; }
1207
1208         string tmp_s;
1209
1210         for(sel_num = 0;(args != "");)
1211         {
1212                 selected = car(args); args = cdr(args);
1213                 NOTIF_HIT_MAX(NOTIF_MAX_ARGS, "Local_Notification_sprintf");
1214                 switch(strtolower(selected))
1215                 {
1216                         #ifdef CSQC
1217                         #define ARG_CASE_ARG_CS_SV_HA(selected,result) case selected: { arg_slot[sel_num] = result; ++sel_num; break; }
1218                         #define ARG_CASE_ARG_CS_SV_DC(selected,result) case selected: { arg_slot[sel_num] = result; ++sel_num; break; }
1219                         #define ARG_CASE_ARG_CS_SV(selected,result)    case selected: { arg_slot[sel_num] = result; ++sel_num; break; }
1220                         #define ARG_CASE_ARG_CS(selected,result)       case selected: { arg_slot[sel_num] = result; ++sel_num; break; }
1221                         #define ARG_CASE_ARG_SV(selected,result)
1222                         #define ARG_CASE_ARG_DC(selected,result)
1223                         #else
1224                         #define ARG_CASE_ARG_CS_SV_HA(selected,result) case selected: { arg_slot[sel_num] = result; ++sel_num; break; }
1225                         #define ARG_CASE_ARG_CS_SV_DC(selected,result) case selected: { arg_slot[sel_num] = result; ++sel_num; break; }
1226                         #define ARG_CASE_ARG_CS_SV(selected,result)    case selected: { arg_slot[sel_num] = result; ++sel_num; break; }
1227                         #define ARG_CASE_ARG_CS(selected,result)
1228                         #define ARG_CASE_ARG_SV(selected,result)       case selected: { arg_slot[sel_num] = result; ++sel_num; break; }
1229                         #define ARG_CASE_ARG_DC(selected,result)
1230                         #endif
1231                         #define ARG_CASE(prog,selected,result)         ARG_CASE_##prog(selected,result)
1232                         NOTIF_ARGUMENT_LIST
1233                         #undef ARG_CASE
1234                         #undef ARG_CASE_ARG_DC
1235                         #undef ARG_CASE_ARG_SV
1236                         #undef ARG_CASE_ARG_CS
1237                         #undef ARG_CASE_ARG_CS_SV
1238                         #undef ARG_CASE_ARG_CS_SV_DC
1239                         #undef ARG_CASE_ARG_CS_SV_HA
1240                         default: NOTIF_HIT_UNKNOWN(NOTIF_MAX_ARGS, "Local_Notification_sprintf")
1241                 }
1242         }
1243         return sprintf(
1244                 strcat(input, "\n"),
1245                 arg_slot[0],
1246                 arg_slot[1],
1247                 arg_slot[2],
1248                 arg_slot[3],
1249                 arg_slot[4],
1250                 arg_slot[5],
1251                 arg_slot[6]
1252         );
1253 }
1254
1255 #ifdef CSQC
1256 void Local_Notification_sound(
1257         float soundchannel, string soundfile,
1258         float soundvolume, float soundposition)
1259 {
1260         if((soundfile != prev_soundfile) || (time >= (prev_soundtime + autocvar_cl_announcer_antispam)))
1261         {
1262                 #ifdef NOTIFICATIONS_DEBUG
1263                 Debug_Notification(sprintf(
1264                         "Local_Notification_sound(world, %f, '%s', %f, %f);\n",
1265                         soundchannel,
1266                         sprintf(
1267                                 "announcer/%s/%s.wav",
1268                                 autocvar_cl_announcer,
1269                                 soundfile
1270                         ),
1271                         soundvolume,
1272                         soundposition
1273                 ));
1274                 #endif
1275
1276                 sound(
1277                         world,
1278                         soundchannel,
1279                         sprintf(
1280                                 "announcer/%s/%s.wav",
1281                                 autocvar_cl_announcer,
1282                                 soundfile
1283                         ),
1284                         soundvolume,
1285                         soundposition
1286                 );
1287
1288                 if(prev_soundfile) { strunzone(prev_soundfile); }
1289                 prev_soundfile = strzone(soundfile);
1290                 prev_soundtime = time;
1291         }
1292         else
1293         {
1294                 #ifdef NOTIFICATIONS_DEBUG
1295                 Debug_Notification(sprintf(
1296                         strcat(
1297                                 "Local_Notification_sound(world, %f, '%s', %f, %f) ",
1298                                 "^1BLOCKED BY ANTISPAM:^7 prevsnd: '%s', timediff: %f, limit: %f\n"
1299                          ),
1300                         soundchannel,
1301                         sprintf(
1302                                 "announcer/%s/%s.wav",
1303                                 autocvar_cl_announcer,
1304                                 soundfile
1305                         ),
1306                         soundvolume,
1307                         soundposition,
1308                         prev_soundfile,
1309                         (time - prev_soundtime),
1310                         autocvar_cl_announcer_antispam
1311                 ));
1312                 #endif
1313         }
1314 }
1315
1316 void Local_Notification_HUD_Notify_Push(
1317         string icon, string hudargs,
1318         string s1, string s2, string s3, string s4,
1319         float f1, float f2, float f3, float f4)
1320 {
1321         string selected;
1322         arg_slot[0] = ""; arg_slot[1] = "";
1323
1324         int sel_num;
1325         for(sel_num = 0;(hudargs != "");)
1326         {
1327                 selected = car(hudargs); hudargs = cdr(hudargs);
1328                 NOTIF_HIT_MAX(NOTIF_MAX_HUDARGS, "Local_Notification_HUD_Notify_Push");
1329                 switch(strtolower(selected))
1330                 {
1331                         #define ARG_CASE_ARG_CS_SV_HA(selected,result) case selected: { arg_slot[sel_num] = result; ++sel_num; break; }
1332                         #define ARG_CASE_ARG_CS_SV_DC(selected,result)
1333                         #define ARG_CASE_ARG_CS_SV(selected,result)
1334                         #define ARG_CASE_ARG_CS(selected,result)
1335                         #define ARG_CASE_ARG_SV(selected,result)
1336                         #define ARG_CASE_ARG_DC(selected,result)
1337                         #define ARG_CASE(prog,selected,result)         ARG_CASE_##prog(selected,result)
1338                         NOTIF_ARGUMENT_LIST
1339                         #undef ARG_CASE
1340                         #undef ARG_CASE_ARG_DC
1341                         #undef ARG_CASE_ARG_SV
1342                         #undef ARG_CASE_ARG_CS
1343                         #undef ARG_CASE_ARG_CS_SV
1344                         #undef ARG_CASE_ARG_CS_SV_DC
1345                         #undef ARG_CASE_ARG_CS_SV_HA
1346                         default: NOTIF_HIT_UNKNOWN(NOTIF_MAX_HUDARGS, "Local_Notification_HUD_Notify_Push")
1347                 }
1348         }
1349         #ifdef NOTIFICATIONS_DEBUG
1350         Debug_Notification(sprintf(
1351                 "Local_Notification_HUD_Notify_Push('%s^7', '%s', %s, %s, %s);\n",
1352                 icon,
1353                 hudargs,
1354                 MakeConsoleSafe(sprintf("'%s^7', '%s^7', '%s^7', '%s^7'", s1, s2, s3, s4)),
1355                 sprintf("%d, %d, %d, %d", f1, f2, f3, f4),
1356                 MakeConsoleSafe(sprintf("'%s^7', '%s^7'", stof(arg_slot[0]), stof(arg_slot[1])))
1357         ));
1358         #endif
1359         HUD_Notify_Push(icon, arg_slot[0], arg_slot[1]);
1360 }
1361
1362 void Local_Notification_centerprint_generic(
1363         string input, string durcnt,
1364         float cpid, float f1, float f2)
1365 {
1366         string selected;
1367         float sel_num;
1368         arg_slot[0] = ""; arg_slot[1] = "";
1369
1370         for(sel_num = 0;(durcnt != "");)
1371         {
1372                 selected = car(durcnt); durcnt = cdr(durcnt);
1373                 NOTIF_HIT_MAX(NOTIF_MAX_DURCNT, "Local_Notification_centerprint_generic");
1374                 switch(strtolower(selected))
1375                 {
1376                         #define ARG_CASE_ARG_CS_SV_HA(selected,result)
1377                         #define ARG_CASE_ARG_CS_SV_DC(selected,result) case selected: { arg_slot[sel_num] = result; ++sel_num; break; }
1378                         #define ARG_CASE_ARG_CS_SV(selected,result)
1379                         #define ARG_CASE_ARG_CS(selected,result)
1380                         #define ARG_CASE_ARG_SV(selected,result)
1381                         #define ARG_CASE_ARG_DC(selected,result)       case selected: { arg_slot[sel_num] = result; ++sel_num; break; }
1382                         #define ARG_CASE(prog,selected,result)         ARG_CASE_##prog(selected,result)
1383                         NOTIF_ARGUMENT_LIST
1384                         #undef ARG_CASE
1385                         #undef ARG_CASE_ARG_DC
1386                         #undef ARG_CASE_ARG_SV
1387                         #undef ARG_CASE_ARG_CS
1388                         #undef ARG_CASE_ARG_CS_SV
1389                         #undef ARG_CASE_ARG_CS_SV_DC
1390                         #undef ARG_CASE_ARG_CS_SV_HA
1391                         default:
1392                         {
1393                                 if(ftos(stof(selected)) != "") { arg_slot[sel_num] = selected; ++sel_num; }
1394                                 else { NOTIF_HIT_UNKNOWN(NOTIF_MAX_DURCNT, "Local_Notification_centerprint_generic") }
1395                                 break;
1396                         }
1397                 }
1398         }
1399         #ifdef NOTIFICATIONS_DEBUG
1400         Debug_Notification(sprintf(
1401                 "Local_Notification_centerprint_generic('%s^7', '%s', %d, %d, %d, %d);\n",
1402                 MakeConsoleSafe(input),
1403                 durcnt,
1404                 f1, f2,
1405                 stof(arg_slot[0]),
1406                 stof(arg_slot[1])
1407         ));
1408         #endif
1409         centerprint_generic(cpid, input, stof(arg_slot[0]), stof(arg_slot[1]));
1410 }
1411 #endif
1412
1413 void Local_Notification(float net_type, float net_name, ...count)
1414 {
1415         // check if this should be aborted
1416         if(net_name == NOTIF_ABORT)
1417         {
1418                 #ifdef NOTIFICATIONS_DEBUG
1419                 Debug_Notification(sprintf(
1420                         "Local_Notification(%s, %s, ...);\n",
1421                         Get_Notif_TypeName(net_type),
1422                         "NOTIF_ABORT"
1423                 ));
1424                 #endif
1425                 return;
1426         }
1427
1428         // check supplied type and name for errors
1429         string checkargs = Notification_CheckArgs_TypeName(net_type, net_name);
1430         if(checkargs != "")
1431         {
1432                 #ifdef NOTIFICATIONS_DEBUG
1433                 Debug_Notification(sprintf(
1434                         "Local_Notification(%s, %d, ...);\n",
1435                         Get_Notif_TypeName(net_type),
1436                         Get_Notif_Ent(net_type, net_name).nent_name
1437                 ));
1438                 #endif
1439                 backtrace(sprintf("Incorrect usage of Local_Notification: %s\n", checkargs));
1440                 return;
1441         }
1442
1443         // retreive entity of this notification
1444         entity notif = Get_Notif_Ent(net_type, net_name);
1445         if (!notif)
1446         {
1447                 #ifdef NOTIFICATIONS_DEBUG
1448                 Debug_Notification(sprintf(
1449                         "Local_Notification(%s, %d, ...);\n",
1450                         Get_Notif_TypeName(net_type),
1451                         net_name
1452                 ));
1453                 #endif
1454                 backtrace("Local_Notification: Could not find notification entity!\n");
1455                 return;
1456         }
1457
1458         // check if the notification is enabled
1459         if (!notif.nent_enabled)
1460         {
1461                 #ifdef NOTIFICATIONS_DEBUG
1462                 Debug_Notification(sprintf(
1463                         "Local_Notification(%s, %s, ...): Entity was disabled...\n",
1464                         Get_Notif_TypeName(net_type),
1465                         notif.nent_name
1466                 ));
1467                 #endif
1468                 return;
1469         }
1470
1471         string s1 = ((0 < notif.nent_stringcount) ? ...(0, string) : "");
1472         string s2 = ((1 < notif.nent_stringcount) ? ...(1, string) : "");
1473         string s3 = ((2 < notif.nent_stringcount) ? ...(2, string) : "");
1474         string s4 = ((3 < notif.nent_stringcount) ? ...(3, string) : "");
1475         float f1 = ((0 < notif.nent_floatcount) ? ...((notif.nent_stringcount + 0), float) : 0);
1476         float f2 = ((1 < notif.nent_floatcount) ? ...((notif.nent_stringcount + 1), float) : 0);
1477         float f3 = ((2 < notif.nent_floatcount) ? ...((notif.nent_stringcount + 2), float) : 0);
1478         float f4 = ((3 < notif.nent_floatcount) ? ...((notif.nent_stringcount + 3), float) : 0);
1479
1480         #ifdef NOTIFICATIONS_DEBUG
1481         Debug_Notification(sprintf(
1482                 "Local_Notification(%s, %s, %s, %s);\n",
1483                 Get_Notif_TypeName(net_type),
1484                 notif.nent_name,
1485                 MakeConsoleSafe(sprintf("'%s^7', '%s^7', '%s^7', '%s^7'", s1, s2, s3, s4)),
1486                 sprintf("%d, %d, %d, %d", f1, f2, f3, f4)
1487         ));
1488         #endif
1489
1490         if((notif.nent_stringcount + notif.nent_floatcount) > count)
1491         {
1492                 backtrace(sprintf(
1493                         strcat(
1494                                 "Not enough arguments for Local_Notification(%s, %s, ...)! ",
1495                                 "stringcount(%d) + floatcount(%d) > count(%d)\n",
1496                                 "Check the definition and function call for accuracy...?\n"
1497                         ),
1498                         Get_Notif_TypeName(net_type),
1499                         notif.nent_name,
1500                         notif.nent_stringcount,
1501                         notif.nent_floatcount,
1502                         count
1503                 ));
1504                 return;
1505         }
1506         else if((notif.nent_stringcount + notif.nent_floatcount) < count)
1507         {
1508                 backtrace(sprintf(
1509                         strcat(
1510                                 "Too many arguments for Local_Notification(%s, %s, ...)! ",
1511                                 "stringcount(%d) + floatcount(%d) < count(%d)\n",
1512                                 "Check the definition and function call for accuracy...?\n"
1513                         ),
1514                         Get_Notif_TypeName(net_type),
1515                         notif.nent_name,
1516                         notif.nent_stringcount,
1517                         notif.nent_floatcount,
1518                         count
1519                 ));
1520                 return;
1521         }
1522
1523         switch(net_type)
1524         {
1525                 case MSG_ANNCE:
1526                 {
1527                         #ifdef CSQC
1528                         Local_Notification_sound(
1529                                 notif.nent_channel,
1530                                 notif.nent_snd,
1531                                 notif.nent_vol,
1532                                 notif.nent_position
1533                         );
1534                         #else
1535                         backtrace("MSG_ANNCE on server?... Please notify Samual immediately!\n");
1536                         #endif
1537                         break;
1538                 }
1539
1540                 case MSG_INFO:
1541                 {
1542                         print(
1543                                 Local_Notification_sprintf(
1544                                         notif.nent_string,
1545                                         notif.nent_args,
1546                                         s1, s2, s3, s4,
1547                                         f1, f2, f3, f4)
1548                         );
1549                         #ifdef CSQC
1550                         if(notif.nent_icon != "")
1551                         {
1552                                 Local_Notification_HUD_Notify_Push(
1553                                         notif.nent_icon,
1554                                         notif.nent_hudargs,
1555                                         s1, s2, s3, s4,
1556                                         f1, f2, f3, f4);
1557                         }
1558                         #endif
1559                         break;
1560                 }
1561
1562                 #ifdef CSQC
1563                 case MSG_CENTER:
1564                 {
1565                         Local_Notification_centerprint_generic(
1566                                 Local_Notification_sprintf(
1567                                         notif.nent_string,
1568                                         notif.nent_args,
1569                                         s1, s2, s3, s4,
1570                                         f1, f2, f3, f4),
1571                                 notif.nent_durcnt,
1572                                 notif.nent_cpid,
1573                                 f1, f2);
1574                         break;
1575                 }
1576                 #endif
1577
1578                 case MSG_MULTI:
1579                 {
1580                         if(notif.nent_msginfo)
1581                         if(notif.nent_msginfo.nent_enabled)
1582                         {
1583                                 Local_Notification_WOVA(
1584                                         MSG_INFO,
1585                                         notif.nent_msginfo.nent_id,
1586                                         notif.nent_msginfo.nent_stringcount,
1587                                         notif.nent_msginfo.nent_floatcount,
1588                                         s1, s2, s3, s4,
1589                                         f1, f2, f3, f4);
1590                         }
1591                         #ifdef CSQC
1592                         if(notif.nent_msgannce)
1593                         if(notif.nent_msgannce.nent_enabled)
1594                         {
1595                                 Local_Notification_WOVA(
1596                                         MSG_ANNCE,
1597                                         notif.nent_msgannce.nent_id,
1598                                         0, 0,
1599                                         "", "", "", "",
1600                                         0, 0, 0, 0);
1601                         }
1602                         if(notif.nent_msgcenter)
1603                         if(notif.nent_msgcenter.nent_enabled)
1604                         {
1605                                 Local_Notification_WOVA(
1606                                         MSG_CENTER,
1607                                         notif.nent_msgcenter.nent_id,
1608                                         notif.nent_msgcenter.nent_stringcount,
1609                                         notif.nent_msgcenter.nent_floatcount,
1610                                         s1, s2, s3, s4,
1611                                         f1, f2, f3, f4);
1612                         }
1613                         #endif
1614                         break;
1615                 }
1616
1617                 case MSG_CHOICE:
1618                 {
1619                         entity found_choice;
1620
1621                         if(notif.nent_challow_var && (warmup_stage || (notif.nent_challow_var == 2)))
1622                         {
1623                                 switch(cvar_string(sprintf("notification_%s", notif.nent_name)))
1624                                 {
1625                                         case 1: found_choice = notif.nent_optiona; break;
1626                                         case 2: found_choice = notif.nent_optionb; break;
1627                                         default: return; // not enabled anyway
1628                                 }
1629                         }
1630                         else { found_choice = notif.nent_optiona; }
1631
1632                         Local_Notification_WOVA(
1633                                 found_choice.nent_type,
1634                                 found_choice.nent_id,
1635                                 found_choice.nent_stringcount,
1636                                 found_choice.nent_floatcount,
1637                                 s1, s2, s3, s4,
1638                                 f1, f2, f3, f4);
1639                 }
1640         }
1641 }
1642
1643 // WOVA = Without Variable Arguments
1644 void Local_Notification_WOVA(
1645         float net_type, float net_name,
1646         float stringcount, float floatcount,
1647         string s1, string s2, string s3, string s4,
1648         float f1, float f2, float f3, float f4)
1649 {
1650         #define VARITEM(stringc,floatc,args) \
1651                 if((stringcount == stringc) && (floatcount == floatc)) \
1652                         { Local_Notification(net_type, net_name, args); return; }
1653         EIGHT_VARS_TO_VARARGS_VARLIST
1654         #undef VARITEM
1655         Local_Notification(net_type, net_name); // some notifications don't have any arguments at all
1656 }
1657
1658
1659 // =========================
1660 //  Notification Networking
1661 // =========================
1662
1663 #ifdef CSQC
1664 void Read_Notification(float is_new)
1665 {
1666         float net_type = ReadByte();
1667         float net_name = ReadShort();
1668
1669         entity notif;
1670
1671         if(net_type == MSG_CENTER_CPID)
1672         {
1673                 #ifdef NOTIFICATIONS_DEBUG
1674                 Debug_Notification(sprintf(
1675                         "Read_Notification(%d) at %f: net_type = %s, net_name = %d\n",
1676                         is_new,
1677                         time,
1678                         Get_Notif_TypeName(net_type),
1679                         net_name
1680                 ));
1681                 #endif
1682
1683                 if(is_new)
1684                 {
1685                         if(net_name == 0) { reset_centerprint_messages(); }
1686                         else if(net_name != NO_CPID)
1687                         {
1688                                 // in this case, net_name IS the cpid we want to kill
1689                                 centerprint_generic(net_name, "", 0, 0);
1690                         }
1691                         else
1692                         {
1693                                 backtrace(sprintf(
1694                                         "Read_Notification(%d) at %f: ^1TRIED TO KILL NO_CPID CENTERPRINT!\n",
1695                                         is_new,
1696                                         time
1697                                 ));
1698                         }
1699                 }
1700         }
1701         else
1702         {
1703                 notif = Get_Notif_Ent(net_type, net_name);
1704                 if (!notif) { backtrace("Read_Notification: Could not find notification entity!\n"); return; }
1705
1706                 #ifdef NOTIFICATIONS_DEBUG
1707                 Debug_Notification(sprintf(
1708                         "Read_Notification(%d) at %f: net_type = %s, net_name = %s\n",
1709                         is_new,
1710                         time,
1711                         Get_Notif_TypeName(net_type),
1712                         notif.nent_name
1713                 ));
1714                 #endif
1715
1716                 string s1 = ((0 < notif.nent_stringcount) ? ReadString() : "");
1717                 string s2 = ((1 < notif.nent_stringcount) ? ReadString() : "");
1718                 string s3 = ((2 < notif.nent_stringcount) ? ReadString() : "");
1719                 string s4 = ((3 < notif.nent_stringcount) ? ReadString() : "");
1720                 float f1 = ((0 < notif.nent_floatcount) ? ReadLong() : 0);
1721                 float f2 = ((1 < notif.nent_floatcount) ? ReadLong() : 0);
1722                 float f3 = ((2 < notif.nent_floatcount) ? ReadLong() : 0);
1723                 float f4 = ((3 < notif.nent_floatcount) ? ReadLong() : 0);
1724
1725                 if(is_new)
1726                 {
1727                         Local_Notification_WOVA(
1728                                 net_type, net_name,
1729                                 notif.nent_stringcount,
1730                                 notif.nent_floatcount,
1731                                 s1, s2, s3, s4,
1732                                 f1, f2, f3, f4);
1733                 }
1734         }
1735 }
1736 #endif
1737
1738 #ifdef SVQC
1739 void Net_Notification_Remove()
1740 {
1741         if (!self) { backtrace(sprintf("Net_Notification_Remove() at %f: Missing self!?\n", time)); return; }
1742
1743         #ifdef NOTIFICATIONS_DEBUG
1744         Debug_Notification(sprintf(
1745                 "Net_Notification_Remove() at %f: %s '%s - %s' notification\n",
1746                 time,
1747                 ((self.nent_net_name == -1) ? "Killed" : "Removed"),
1748                 Get_Notif_TypeName(self.nent_net_type),
1749                 self.owner.nent_name
1750         ));
1751         #endif
1752
1753         float i;
1754         for(i = 0; i < 4; ++i) { if(self.nent_strings[i]) { strunzone(self.nent_strings[i]); } }
1755         remove(self);
1756 }
1757
1758 float Net_Write_Notification(entity client, float sf)
1759 {
1760         if(Notification_ShouldSend(self.nent_broadcast, client, self.nent_client))
1761         {
1762                 float i;
1763                 WriteByte(MSG_ENTITY, ENT_CLIENT_NOTIFICATION);
1764                 WriteByte(MSG_ENTITY, self.nent_net_type);
1765                 WriteShort(MSG_ENTITY, self.nent_net_name);
1766                 for(i = 0; i < self.nent_stringcount; ++i) { WriteString(MSG_ENTITY, self.nent_strings[i]); }
1767                 for(i = 0; i < self.nent_floatcount; ++i) { WriteLong(MSG_ENTITY, self.nent_floats[i]); }
1768                 return true;
1769         }
1770         else { return false; }
1771 }
1772
1773 void Kill_Notification(
1774         float broadcast, entity client,
1775         float net_type, float net_name)
1776 {
1777         #ifdef NOTIFICATIONS_DEBUG
1778         Debug_Notification(sprintf(
1779                 "Kill_Notification(%s, '%s', %s, %d);\n",
1780                 Get_Notif_BroadcastName(broadcast),
1781                 client.netname,
1782                 (net_type ? Get_Notif_TypeName(net_type) : "0"),
1783                 net_name
1784         ));
1785         #endif
1786
1787         string checkargs = Notification_CheckArgs(broadcast, client, 1, 1);
1788         if(checkargs != "") { backtrace(sprintf("Incorrect usage of Kill_Notification: %s\n", checkargs)); return; }
1789
1790         entity notif, net_notif;
1791         float killed_cpid = NO_CPID;
1792
1793         switch(net_type)
1794         {
1795                 case 0:
1796                 {
1797                         killed_cpid = 0; // kill ALL centerprints
1798                         break;
1799                 }
1800
1801                 case MSG_CENTER:
1802                 {
1803                         if(net_name)
1804                         {
1805                                 entity notif = Get_Notif_Ent(net_type, net_name);
1806                                 if (!notif) { backtrace("Kill_Notification: Could not find notification entity!\n"); return; }
1807
1808                                 if(notif.nent_cpid)
1809                                         killed_cpid = notif.nent_cpid;
1810                                 else
1811                                         killed_cpid = NO_CPID;
1812                         }
1813                         else
1814                         {
1815                                 killed_cpid = 0; // kill ALL centerprints
1816                         }
1817                         break;
1818                 }
1819
1820                 case MSG_CENTER_CPID:
1821                 {
1822                         killed_cpid = net_name;
1823                         break;
1824                 }
1825         }
1826
1827         if(killed_cpid != NO_CPID)
1828         {
1829                 net_notif = spawn();
1830                 net_notif.classname = "net_kill_notification";
1831                 net_notif.nent_broadcast = broadcast;
1832                 net_notif.nent_client = client;
1833                 net_notif.nent_net_type = MSG_CENTER_CPID;
1834                 net_notif.nent_net_name = killed_cpid;
1835                 Net_LinkEntity(net_notif, false, autocvar_notification_lifetime_runtime, Net_Write_Notification);
1836         }
1837
1838         for(notif = world; (notif = find(notif, classname, "net_notification"));)
1839         {
1840                 if(net_type)
1841                 {
1842                         if((killed_cpid != NO_CPID) && (notif.nent_net_type == MSG_CENTER))
1843                         {
1844                                 if(notif.owner.nent_cpid == killed_cpid)
1845                                 {
1846                                         notif.nent_net_name = -1;
1847                                         notif.nextthink = time;
1848                                 }
1849                                 else { continue; } // we ARE looking for a specific CPID, don't kill everything else too
1850                         }
1851                         else if(notif.nent_net_type == net_type)
1852                         {
1853                                 if(net_name)
1854                                 {
1855                                         if(notif.nent_net_name == net_name) { notif.nent_net_name = -1; notif.nextthink = time; }
1856                                         else { continue; } // we ARE looking for a certain net_name, don't kill everything else too
1857                                 }
1858                                 else { notif.nent_net_name = -1; notif.nextthink = time; }
1859                         }
1860                         else { continue; } // we ARE looking for a certain net_type, don't kill everything else too
1861                 }
1862                 else { notif.nent_net_name = -1; notif.nextthink = time; }
1863         }
1864 }
1865
1866 void Send_Notification(
1867         float broadcast, entity client,
1868         float net_type, float net_name,
1869         ...count)
1870 {
1871         // check if this should be aborted
1872         if(net_name == NOTIF_ABORT)
1873         {
1874                 #ifdef NOTIFICATIONS_DEBUG
1875                 Debug_Notification(sprintf(
1876                         "Send_Notification(%s, '%s', %s, %s, ...);\n",
1877                         Get_Notif_BroadcastName(broadcast),
1878                         client.classname,
1879                         Get_Notif_TypeName(net_type),
1880                         "NOTIF_ABORT"
1881                 ));
1882                 #endif
1883                 return;
1884         }
1885
1886         // check supplied broadcast, target, type, and name for errors
1887         string checkargs = Notification_CheckArgs(broadcast, client, net_type, net_name);
1888         if(checkargs != "")
1889         {
1890                 #ifdef NOTIFICATIONS_DEBUG
1891                 Debug_Notification(sprintf(
1892                         "Send_Notification(%s, '%s', %s, %s, ...);\n",
1893                         Get_Notif_BroadcastName(broadcast),
1894                         client.classname,
1895                         Get_Notif_TypeName(net_type),
1896                         Get_Notif_Ent(net_type, net_name).nent_name
1897                 ));
1898                 #endif
1899                 backtrace(sprintf("Incorrect usage of Send_Notification: %s\n", checkargs));
1900                 return;
1901         }
1902
1903         // retreive entity of this notification
1904         entity notif = Get_Notif_Ent(net_type, net_name);
1905         if (!notif)
1906         {
1907                 #ifdef NOTIFICATIONS_DEBUG
1908                 Debug_Notification(sprintf(
1909                         "Send_Notification(%s, '%s', %s, %d, ...);\n",
1910                         Get_Notif_BroadcastName(broadcast),
1911                         client.classname,
1912                         Get_Notif_TypeName(net_type),
1913                         net_name
1914                 ));
1915                 #endif
1916                 backtrace("Send_Notification: Could not find notification entity!\n");
1917                 return;
1918         }
1919
1920         string s1 = ((0 < notif.nent_stringcount) ? ...(0, string) : "");
1921         string s2 = ((1 < notif.nent_stringcount) ? ...(1, string) : "");
1922         string s3 = ((2 < notif.nent_stringcount) ? ...(2, string) : "");
1923         string s4 = ((3 < notif.nent_stringcount) ? ...(3, string) : "");
1924         float f1 = ((0 < notif.nent_floatcount) ? ...((notif.nent_stringcount + 0), float) : 0);
1925         float f2 = ((1 < notif.nent_floatcount) ? ...((notif.nent_stringcount + 1), float) : 0);
1926         float f3 = ((2 < notif.nent_floatcount) ? ...((notif.nent_stringcount + 2), float) : 0);
1927         float f4 = ((3 < notif.nent_floatcount) ? ...((notif.nent_stringcount + 3), float) : 0);
1928
1929         #ifdef NOTIFICATIONS_DEBUG
1930         Debug_Notification(sprintf(
1931                 "Send_Notification(%s, %s, %s);\n",
1932                 sprintf(
1933                         "%s, '%s', %s, %s",
1934                         Get_Notif_BroadcastName(broadcast),
1935                         client.classname,
1936                         Get_Notif_TypeName(net_type),
1937                         notif.nent_name
1938                 ),
1939                 MakeConsoleSafe(sprintf("'%s^7', '%s^7', '%s^7', '%s^7'", s1, s2, s3, s4)),
1940                 sprintf("%d, %d, %d, %d", f1, f2, f3, f4)
1941         ));
1942         #endif
1943
1944         if((notif.nent_stringcount + notif.nent_floatcount) > count)
1945         {
1946                 backtrace(sprintf(
1947                         strcat(
1948                                 "Not enough arguments for Send_Notification(%s, ...)! ",
1949                                 "stringcount(%d) + floatcount(%d) > count(%d)\n",
1950                                 "Check the definition and function call for accuracy...?\n"
1951                         ),
1952                         sprintf(
1953                                 #ifdef NOTIFICATIONS_DEBUG
1954                                 "%s, '%s', %s, %s",
1955                                 Get_Notif_BroadcastName(broadcast),
1956                                 #else
1957                                 "%d, '%s', %s, %s",
1958                                 broadcast,
1959                                 #endif
1960                                 client.classname,
1961                                 Get_Notif_TypeName(net_type),
1962                                 notif.nent_name
1963                         ),
1964                         notif.nent_stringcount,
1965                         notif.nent_floatcount,
1966                         count
1967                 ));
1968                 return;
1969         }
1970         else if((notif.nent_stringcount + notif.nent_floatcount) < count)
1971         {
1972                 backtrace(sprintf(
1973                         strcat(
1974                                 "Too many arguments for Send_Notification(%s, ...)! ",
1975                                 "stringcount(%d) + floatcount(%d) < count(%d)\n",
1976                                 "Check the definition and function call for accuracy...?\n"
1977                         ),
1978                         sprintf(
1979                                 #ifdef NOTIFICATIONS_DEBUG
1980                                 "%s, '%s', %s, %s",
1981                                 Get_Notif_BroadcastName(broadcast),
1982                                 #else
1983                                 "%d, '%s', %s, %s",
1984                                 broadcast,
1985                                 #endif
1986                                 client.classname,
1987                                 Get_Notif_TypeName(net_type),
1988                                 notif.nent_name
1989                         ),
1990                         notif.nent_stringcount,
1991                         notif.nent_floatcount,
1992                         count
1993                 ));
1994                 return;
1995         }
1996
1997         if(
1998                 server_is_dedicated
1999                 &&
2000                 (
2001                         broadcast == NOTIF_ALL
2002                         ||
2003                         broadcast == NOTIF_ALL_EXCEPT
2004                 )
2005                 &&
2006                 !(
2007                         net_type == MSG_ANNCE
2008                         ||
2009                         net_type == MSG_CENTER
2010                 )
2011         )
2012         {
2013                 Local_Notification_WOVA(
2014                         net_type, net_name,
2015                         notif.nent_stringcount,
2016                         notif.nent_floatcount,
2017                         s1, s2, s3, s4,
2018                         f1, f2, f3, f4);
2019         }
2020
2021         if(net_type == MSG_CHOICE)
2022         {
2023                 // THIS GETS TRICKY... now we have to cycle through each possible player (checking broadcast)
2024                 // and then do an individual NOTIF_ONE_ONLY recursive call for each one depending on their option...
2025                 // It's slow, but it's better than the alternatives:
2026                 //   1. Constantly networking all info and letting client decide
2027                 //   2. Manually handling each separate call on per-usage basis (See old CTF usage of verbose)
2028                 entity found_choice;
2029
2030                 #define RECURSE_FROM_CHOICE(ent,action) \
2031                         if(notif.nent_challow_var && (warmup_stage || (notif.nent_challow_var == 2))) \
2032                         { \
2033                                 switch(ent.msg_choice_choices[net_name - 1]) \
2034                                 { \
2035                                         case 1: found_choice = notif.nent_optiona; break; \
2036                                         case 2: found_choice = notif.nent_optionb; break; \
2037                                         default: action; \
2038                                 } \
2039                         } \
2040                         else { found_choice = notif.nent_optiona; } \
2041                         Send_Notification_WOVA( \
2042                                 NOTIF_ONE_ONLY, \
2043                                 ent, \
2044                                 found_choice.nent_type, \
2045                                 found_choice.nent_id, \
2046                                 found_choice.nent_stringcount, \
2047                                 found_choice.nent_floatcount, \
2048                                 s1, s2, s3, s4, \
2049                                 f1, f2, f3, f4);
2050
2051                 switch(broadcast)
2052                 {
2053                         case NOTIF_ONE_ONLY: // we can potentially save processing power with this broadcast method
2054                         {
2055                                 if(IS_REAL_CLIENT(client))
2056                                         { RECURSE_FROM_CHOICE(client, return) }
2057                                 break;
2058                         }
2059                         default:
2060                         {
2061                                 entity to;
2062                                 FOR_EACH_REALCLIENT(to)
2063                                         { if(Notification_ShouldSend(broadcast, to, client))
2064                                                 { RECURSE_FROM_CHOICE(to, continue) } }
2065                                 break;
2066                         }
2067                 }
2068         }
2069         else
2070         {
2071                 entity net_notif = spawn();
2072                 net_notif.owner = notif;
2073                 net_notif.classname = "net_notification";
2074                 net_notif.nent_broadcast = broadcast;
2075                 net_notif.nent_client = client;
2076                 net_notif.nent_net_type = net_type;
2077                 net_notif.nent_net_name = net_name;
2078                 net_notif.nent_stringcount = notif.nent_stringcount;
2079                 net_notif.nent_floatcount = notif.nent_floatcount;
2080
2081                 float i;
2082                 for(i = 0; i < net_notif.nent_stringcount; ++i)
2083                         { net_notif.nent_strings[i] = strzone(...(i, string)); }
2084                 for(i = 0; i < net_notif.nent_floatcount; ++i)
2085                         { net_notif.nent_floats[i] = ...((net_notif.nent_stringcount + i), float); }
2086
2087                 net_notif.think = Net_Notification_Remove;
2088                 net_notif.nextthink =
2089                         ((time > autocvar_notification_lifetime_mapload)
2090                         ?
2091                                 (time + autocvar_notification_lifetime_runtime)
2092                                 :
2093                                 autocvar_notification_lifetime_mapload
2094                         );
2095
2096                 Net_LinkEntity(net_notif, false, 0, Net_Write_Notification);
2097         }
2098 }
2099
2100 // WOVA = Without Variable Arguments
2101 void Send_Notification_WOVA(
2102         float broadcast, entity client,
2103         float net_type, float net_name,
2104         float stringcount, float floatcount,
2105         string s1, string s2, string s3, string s4,
2106         float f1, float f2, float f3, float f4)
2107 {
2108         #ifdef NOTIFICATIONS_DEBUG
2109         entity notif = Get_Notif_Ent(net_type, net_name);
2110         Debug_Notification(sprintf(
2111                 "Send_Notification_WOVA(%s, %d, %d, %s, %s);\n",
2112                 sprintf(
2113                         "%s, '%s', %s, %s",
2114                         Get_Notif_BroadcastName(broadcast),
2115                         client.classname,
2116                         Get_Notif_TypeName(net_type),
2117                         notif.nent_name
2118                 ),
2119                 stringcount,
2120                 floatcount,
2121                 MakeConsoleSafe(sprintf("'%s^7', '%s^7', '%s^7', '%s^7'", s1, s2, s3, s4)),
2122                 sprintf("%d, %d, %d, %d", f1, f2, f3, f4)
2123         ));
2124         #endif
2125
2126         #define VARITEM(stringc,floatc,args) \
2127                 if((stringcount == stringc) && (floatcount == floatc)) \
2128                         { Send_Notification(broadcast, client, net_type, net_name, args); return; }
2129         EIGHT_VARS_TO_VARARGS_VARLIST
2130         #undef VARITEM
2131         Send_Notification(broadcast, client, net_type, net_name); // some notifications don't have any arguments at all
2132 }
2133
2134 // WOCOVA = Without Counts Or Variable Arguments
2135 void Send_Notification_WOCOVA(
2136         float broadcast, entity client,
2137         float net_type, float net_name,
2138         string s1, string s2, string s3, string s4,
2139         float f1, float f2, float f3, float f4)
2140 {
2141         entity notif = Get_Notif_Ent(net_type, net_name);
2142
2143         #ifdef NOTIFICATIONS_DEBUG
2144         Debug_Notification(sprintf(
2145                 "Send_Notification_WOCOVA(%s, %s, %s);\n",
2146                 sprintf(
2147                         "%s, '%s', %s, %s",
2148                         Get_Notif_BroadcastName(broadcast),
2149                         client.classname,
2150                         Get_Notif_TypeName(net_type),
2151                         notif.nent_name
2152                 ),
2153                 MakeConsoleSafe(sprintf("'%s^7', '%s^7', '%s^7', '%s^7'", s1, s2, s3, s4)),
2154                 sprintf("%d, %d, %d, %d", f1, f2, f3, f4)
2155         ));
2156         #endif
2157
2158         #define VARITEM(stringc,floatc,args) \
2159                 if((notif.nent_stringcount == stringc) && (notif.nent_floatcount == floatc)) \
2160                         { Send_Notification(broadcast, client, net_type, net_name, args); return; }
2161         EIGHT_VARS_TO_VARARGS_VARLIST
2162         #undef VARITEM
2163         Send_Notification(broadcast, client, net_type, net_name); // some notifications don't have any arguments at all
2164 }
2165 #endif // ifdef SVQC