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