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