Merge branch 'master' into Mario/strength_stat_field
[xonotic/xonotic-data.pk3dir.git] / qcsrc / common / notifications / all.qh
1 #pragma once
2
3 #include <common/command/_mod.qh>
4
5 #include <common/constants.qh>
6 #include <common/teams.qh>
7 #include <common/util.qh>
8 #include <common/sounds/sound.qh>
9 #include <common/weapons/all.qh>
10
11 #ifdef CSQC
12 #include <client/autocvars.qh>
13 #endif
14
15 /** main types/groups of notifications */
16 ENUMCLASS(MSG)
17         /** "Global" AND "personal" announcer messages */
18         CASE(MSG, ANNCE)
19         /** "Global" information messages */
20         CASE(MSG, INFO)
21         /** "Personal" centerprint messages */
22         CASE(MSG, CENTER)
23         /** Subcall MSG_INFO and/or MSG_CENTER notifications */
24         CASE(MSG, MULTI)
25         /** Choose which subcall wrapper to activate */
26         CASE(MSG, CHOICE)
27         /** Kill centerprint message @deprecated */
28         CASE(MSG, CENTER_KILL)
29 ENUMCLASS_END(MSG)
30
31 string Get_Notif_TypeName(MSG net_type)
32 {
33         switch (net_type)
34         {
35                 case MSG_ANNCE: return "MSG_ANNCE";
36                 case MSG_INFO: return "MSG_INFO";
37                 case MSG_CENTER: return "MSG_CENTER";
38                 case MSG_MULTI: return "MSG_MULTI";
39                 case MSG_CHOICE: return "MSG_CHOICE";
40         }
41         LOG_WARNF("Get_Notif_TypeName(%d): Improper net type!", ORDINAL(net_type));
42         return "";
43 }
44
45 ENUMCLASS(CPID)
46         CASE(CPID, ASSAULT_ROLE)
47         CASE(CPID, ROUND)
48         CASE(CPID, CAMPCHECK)
49         CASE(CPID, CTF_CAPSHIELD)
50         CASE(CPID, CTF_LOWPRIO)
51         CASE(CPID, CTF_PASS)
52         CASE(CPID, STALEMATE)
53         CASE(CPID, NADES)
54         CASE(CPID, IDLING)
55         CASE(CPID, ITEM)
56         CASE(CPID, PREVENT_JOIN)
57         CASE(CPID, KEEPAWAY)
58         CASE(CPID, KEEPAWAY_WARN)
59         CASE(CPID, KEYHUNT)
60         CASE(CPID, KEYHUNT_OTHER)
61         CASE(CPID, LMS)
62         CASE(CPID, MISSING_TEAMS)
63         CASE(CPID, MISSING_PLAYERS)
64         CASE(CPID, INSTAGIB_FINDAMMO)
65         CASE(CPID, CAMPAIGN_MESSAGE)
66         CASE(CPID, MOTD)
67         CASE(CPID, NIX)
68         CASE(CPID, ONSLAUGHT)
69         CASE(CPID, ONS_CAPSHIELD)
70         CASE(CPID, OVERTIME)
71         CASE(CPID, POWERUP)
72         CASE(CPID, RACE_FINISHLAP)
73         CASE(CPID, TEAMCHANGE)
74         CASE(CPID, TIMEOUT)
75         CASE(CPID, TIMEIN)
76         CASE(CPID, VEHICLES)
77         CASE(CPID, VEHICLES_OTHER)
78         /** always last */
79         CASE(CPID, LAST)
80 ENUMCLASS_END(CPID)
81
82 USING(Notification, entity);
83
84 // used for notification system multi-team identifiers
85 #define APP_TEAM_NUM(num, prefix) ((num == NUM_TEAM_1) ? prefix##_RED : ((num == NUM_TEAM_2) ? prefix##_BLUE : ((num == NUM_TEAM_3) ? prefix##_YELLOW : prefix##_PINK)))
86 #define APP_NUM(num, prefix) ((num) ? APP_TEAM_NUM(num, prefix) : prefix##_NEUTRAL)
87
88 #define EIGHT_VARS_TO_VARARGS_VARLIST \
89         VARITEM(1, 0, s1) \
90         VARITEM(2, 0, XPD(s1, s2)) \
91         VARITEM(3, 0, XPD(s1, s2, s3)) \
92         VARITEM(4, 0, XPD(s1, s2, s3, s4)) \
93         VARITEM(0, 1, f1) \
94         VARITEM(1, 1, XPD(s1, f1)) \
95         VARITEM(2, 1, XPD(s1, s2, f1)) \
96         VARITEM(3, 1, XPD(s1, s2, s3, f1)) \
97         VARITEM(4, 1, XPD(s1, s2, s3, s4, f1)) \
98         VARITEM(0, 2, XPD(f1, f2)) \
99         VARITEM(1, 2, XPD(s1, f1, f2)) \
100         VARITEM(2, 2, XPD(s1, s2, f1, f2)) \
101         VARITEM(3, 2, XPD(s1, s2, s3, f1, f2)) \
102         VARITEM(4, 2, XPD(s1, s2, s3, s4, f1, f2)) \
103         VARITEM(0, 3, XPD(f1, f2, f3)) \
104         VARITEM(1, 3, XPD(s1, f1, f2, f3)) \
105         VARITEM(2, 3, XPD(s1, s2, f1, f2, f3)) \
106         VARITEM(3, 3, XPD(s1, s2, s3, f1, f2, f3)) \
107         VARITEM(4, 3, XPD(s1, s2, s3, s4, f1, f2, f3)) \
108         VARITEM(0, 4, XPD(f1, f2, f3, f4)) \
109         VARITEM(1, 4, XPD(s1, f1, f2, f3, f4)) \
110         VARITEM(2, 4, XPD(s1, s2, f1, f2, f3, f4)) \
111         VARITEM(3, 4, XPD(s1, s2, s3, f1, f2, f3, f4)) \
112         VARITEM(4, 4, XPD(s1, s2, s3, s4, f1, f2, f3, f4))
113
114 void Destroy_All_Notifications();
115 void Create_Notification_Entity(entity notif,
116         float var_default,
117         float var_cvar,
118         MSG typeId,
119         string namestring,
120         int teamnum);
121 void Create_Notification_Entity_Annce(entity notif,
122                                                                                 float var_cvar,
123                                                                                 string namestring,
124                                                                                 /* MSG_ANNCE */
125                                                                                 float channel,
126                                                                                 string snd,
127                                                                                 float vol,
128                                                                                 float position);
129
130 void Create_Notification_Entity_InfoCenter(entity notif,
131                                                                                         float var_cvar,
132                                                                                         string namestring,
133                                                                                         int strnum,
134                                                                                         int flnum,
135                                                                                         /* MSG_INFO & MSG_CENTER */
136                                                                                         string args,
137                                                                                         string hudargs,
138                                                                                         string icon,
139                                                                                         CPID cpid,
140                                                                                         string durcnt,
141                                                                                         string normal,
142                                                                                         string gentle);
143
144 void Create_Notification_Entity_Multi(entity notif,
145                                                                                 float var_cvar,
146                                                                                 string namestring,
147                                                                                 /* MSG_MULTI */
148                                                                                 Notification anncename,
149                                                                                 Notification infoname,
150                                                                                 Notification centername);
151
152 void Create_Notification_Entity_Choice(entity notif,
153                                                                                 float var_cvar,
154                                                                                 string namestring,
155                                                                                 /* MSG_CHOICE */
156                                                                                 float challow_def,
157                                                                                 float challow_var,
158                                                                                 MSG chtype,
159                                                                                 Notification optiona,
160                                                                                 Notification optionb);
161
162 void Dump_Notifications(int fh, bool alsoprint);
163
164 GENERIC_COMMAND(dumpnotifs, "Dump all notifications into notifications_dump.txt", false)
165 {
166         switch (request)
167         {
168                 case CMD_REQUEST_COMMAND:
169                 {
170                         #ifdef GAMEQC
171                         string filename = argv(1);
172                         bool alsoprint = false;
173                         if (filename == "")
174                         {
175                                 filename = "notifications_dump.cfg";
176                                 alsoprint = false;
177                         }
178                         else if (filename == "-")
179                         {
180                                 filename = "notifications_dump.cfg";
181                                 alsoprint = true;
182                         }
183                         int fh = fopen(filename, FILE_WRITE);
184                         if (fh >= 0)
185                         {
186                                 Dump_Notifications(fh, alsoprint);
187                                 LOG_INFOF("Dumping notifications... File located in ^2data/data/%s^7.", filename);
188                                 fclose(fh);
189                         }
190                         else
191                         {
192                                 LOG_INFOF("^1Error: ^7Could not open file '%s'!", filename);
193                         }
194                         #else
195                         LOG_INFO(_("Notification dump command only works with cl_cmd and sv_cmd."));
196                         #endif
197                         return;
198                 }
199                 default:
200                 case CMD_REQUEST_USAGE:
201                 {
202                         LOG_INFO("Usage:^3 ", GetProgramCommandPrefix(), " dumpnotifs [filename]");
203                         LOG_INFO("  Where 'filename' is the file to write (default is notifications_dump.cfg),");
204                         LOG_INFO("  if supplied with '-' output to console as well as default,");
205                         LOG_INFO("  if left blank, it will only write to default.");
206                         return;
207                 }
208         }
209 }
210
211 #ifdef NOTIFICATIONS_DEBUG
212 bool autocvar_notification_debug = false;
213 void Debug_Notification(string input)
214 {
215         switch (autocvar_notification_debug)
216         {
217                 case 1: { LOG_TRACE(input); break; }
218                 case 2: { LOG_INFO(input); break; }
219         }
220 }
221 #endif
222
223 void Local_Notification(MSG net_type, Notification net_name, ...count);
224 /** glue for networking, forwards to `Local_Notification` */
225 void Local_Notification_WOVA(
226         MSG net_type, Notification net_name,
227         float stringcount, float floatcount,
228         string s1, string s2, string s3, string s4,
229         float f1, float f2, float f3, float f4);
230
231 #ifdef CSQC
232 string prev_soundfile;
233 float prev_soundtime;
234 #endif
235
236 #ifdef SVQC
237 IntrusiveList g_notifications;
238 STATIC_INIT(g_notifications) { g_notifications = IL_NEW(); }
239 #endif
240
241 #ifdef SVQC
242 ENUMCLASS(NOTIF)
243         /** send to one client and their spectators */
244         CASE(NOTIF, ONE)
245         /** send ONLY to one client */
246         CASE(NOTIF, ONE_ONLY)
247         /** send only to X team and their spectators */
248         CASE(NOTIF, TEAM)
249         /** send only to X team and their spectators, except for Y person and their spectators */
250         CASE(NOTIF, TEAM_EXCEPT)
251         /** send to everyone */
252         CASE(NOTIF, ALL)
253         /** send to everyone except X person and their spectators */
254         CASE(NOTIF, ALL_EXCEPT)
255 ENUMCLASS_END(NOTIF)
256
257 string Get_Notif_BroadcastName(NOTIF broadcast)
258 {
259         switch (broadcast)
260         {
261                 case NOTIF_ONE: return "NOTIF_ONE";
262                 case NOTIF_ONE_ONLY: return "NOTIF_ONE_ONLY";
263                 case NOTIF_ALL_EXCEPT: return "NOTIF_ALL_EXCEPT";
264                 case NOTIF_ALL: return "NOTIF_ALL";
265                 case NOTIF_TEAM: return "NOTIF_TEAM";
266                 case NOTIF_TEAM_EXCEPT: return "NOTIF_TEAM_EXCEPT";
267         }
268         LOG_WARNF("Get_Notif_BroadcastName(%d): Improper broadcast!", broadcast);
269         return "";
270 }
271
272 void Kill_Notification(
273         NOTIF broadcast, entity client,
274         MSG net_type, CPID net_name);
275 void Send_Notification(
276         NOTIF broadcast, entity client,
277         MSG net_type, Notification net_name,
278         ...count);
279 void Send_Notification_WOVA(
280         NOTIF broadcast, entity client,
281         MSG net_type, Notification net_name,
282         float stringcount, float floatcount,
283         string s1, string s2, string s3, string s4,
284         float f1, float f2, float f3, float f4);
285 void Send_Notification_WOCOVA(
286         NOTIF broadcast, entity client,
287         MSG net_type, Notification net_name,
288         string s1, string s2, string s3, string s4,
289         float f1, float f2, float f3, float f4);
290 #endif
291
292 // ===========================
293 //  Special CVAR Declarations
294 // ===========================
295
296 // MAKE SURE THIS IS ALWAYS SYNCHRONIZED WITH THE DUMP
297 // NOTIFICATIONS FUNCTION IN THE .QC FILE!
298
299 #define NOTIF_ADD_AUTOCVAR(name,defaultvalue) float autocvar_notification_##name = defaultvalue;
300
301 float autocvar_notification_show_location = false;
302 string autocvar_notification_show_location_string = ""; //_(" at the %s");
303 float autocvar_notification_show_sprees = true;
304 float autocvar_notification_show_sprees_info = 3; // 0 = off, 1 = target only, 2 = attacker only, 3 = target and attacker
305 float autocvar_notification_show_sprees_info_newline = true;
306 float autocvar_notification_show_sprees_info_specialonly = true;
307 float autocvar_notification_errors_are_fatal = true;
308 #ifdef SVQC
309 float autocvar_notification_lifetime_runtime = 0.5;
310 float autocvar_notification_lifetime_mapload = 10;
311 #endif
312
313 #ifdef SVQC
314 void Notification_GetCvars(entity this);
315 float autocvar_notification_server_allows_location = 1; // 0 = no, 1 = yes
316 #else
317 float autocvar_notification_item_centerprinttime = 1.5;
318
319 // 0 = no, 1 = yes, 2 = forced on for all MSG_INFO notifs
320 // DISABLED IN CODE, BUT ENABLED IN CONFIG FOR COMPATIBILITY WITH OLD CLIENTS
321 float autocvar_notification_allow_chatboxprint = 0;
322
323 float autocvar_notification_show_sprees_center = true;
324 float autocvar_notification_show_sprees_center_specialonly = true;
325 #endif
326
327
328 // ============================
329 //  Notification Argument List
330 // ============================
331 /*
332  These arguments get replaced with the Local_Notification_sprintf
333  and other such functions found in all.qc to supply data
334  from networked notifications to their usage in sprintf... It
335  allows for more dynamic data to be inferred by the local
336  notification parser, so that the server does not have to network
337  anything too crazy on a per-client/per-situation basis.
338
339  Pay attention to the CSQC/SVQC relations, some of these are redefined
340  in slightly different ways for different programs, this is because the
341  server does a more conservative approach to the notifs than the client.
342
343  All arguments are swapped into strings, so be sure that your
344  sprintf usage matches with proper %s placement.
345
346  Argument descriptions:
347         s1-s4: string arguments to be literally swapped into sprintf
348         s2loc: s2 string of locations of deaths or other events
349         s3loc: s3 string of locations of deaths or other events
350         f1-f4: float arguments expanded into strings to be swapped into sprintf
351         f1p2dec: f1 float to string with 2 decimal places
352         f2p2dec: f2 float to string with 2 decimal places
353         f2primsec: f2 float primary or secondary selection for weapons
354         f3primsec: f3 float primary or secondary selection for weapons
355         f1secs: count_seconds of f1
356         f1points: point or points depending on f1
357         f1ord: count_ordinal of f1
358         f1time: process_time of f1
359         f1race_time: mmssss of f1
360         f2race_time: mmssss of f2
361         race_col: color of race time/position (i.e. good or bad)
362         race_diff: show time difference between f2 and f3
363         missing_teams: show which teams still need players
364         pass_key: find the keybind for "passing" or "dropping" in CTF game mode
365         nade_key: find the keybind for nade throwing
366         frag_ping: show the ping of a player
367         frag_stats: show health/armor/ping of a player
368         frag_pos: show score status and position in the match of a player
369         spree_cen: centerprint notif for kill spree/how many kills they have
370         spree_inf: info notif for kill spree/how many kills they have
371         spree_end: placed at the end of murder messages to show ending of sprees
372         spree_lost: placed at the end of suicide messages to show losing of sprees
373         item_wepname: return full name of a weapon from weaponid
374         item_wepammo: ammo display for weapon from f1 and f2
375         item_centime: amount of time to display weapon message in centerprint
376         item_buffname: return full name of a buff from buffid
377         death_team: show the full name of the team a player is switching from
378         minigame1_name: return human readable name of a minigame from its id(s1)
379         minigame1_d: return descriptor name of a minigame from its id(s1)
380 */
381
382 const float NOTIF_MAX_ARGS = 7;
383 const float NOTIF_MAX_HUDARGS = 2;
384 const float NOTIF_MAX_DURCNT = 2;
385
386 string arg_slot[NOTIF_MAX_ARGS];
387
388 const float ARG_CS_SV_HA = 1; // enabled on CSQC, SVQC, and Hudargs
389 const float ARG_CS_SV_DC = 2; // enabled on CSQC, SVQC, and durcnt centerprint
390 const float ARG_CS_SV = 3; // enabled on CSQC and SVQC
391 const float ARG_CS = 4; // unique result to CSQC
392 const float ARG_SV = 5; // unique result to SVQC
393 const float ARG_DC = 6; // unique result to durcnt/centerprint
394
395 // todo possible idea.... declare how many floats/strings each arg needs, and then dynamically increment the input
396 // this way, we don't need to have duplicates like i.e. s2loc and s3loc?
397
398 string BUFF_NAME(int i);
399
400 #define NOTIF_ARGUMENT_LIST \
401         ARG_CASE(ARG_CS_SV_HA,  "s1",            s1) \
402         ARG_CASE(ARG_CS_SV_HA,  "s2",            s2) \
403         ARG_CASE(ARG_CS_SV_HA,  "s3",            s3) \
404         ARG_CASE(ARG_CS_SV_HA,  "s4",            s4) \
405         ARG_CASE(ARG_CS_SV,     "s2loc",         ((autocvar_notification_show_location && (s2 != "")) ? sprintf(( ((tmp_s = autocvar_notification_show_location_string) != "") ? tmp_s : _(" (near %s)") ), s2) : "")) \
406         ARG_CASE(ARG_CS_SV,     "s3loc",         ((autocvar_notification_show_location && (s3 != "")) ? sprintf(( ((tmp_s = autocvar_notification_show_location_string) != "") ? tmp_s : _(" (near %s)") ), s3) : "")) \
407         ARG_CASE(ARG_CS_SV_DC,  "f1",            ftos(f1)) \
408         ARG_CASE(ARG_CS_SV_DC,  "f2",            ftos(f2)) \
409         ARG_CASE(ARG_CS_SV,     "f3",            ftos(f3)) \
410         ARG_CASE(ARG_CS_SV,     "f4",            ftos(f4)) \
411         ARG_CASE(ARG_CS_SV,     "f1dtime",       ftos_decimals(TIME_DECODE(f1), 2)) \
412         ARG_CASE(ARG_CS_SV,     "f2dtime",       ftos_decimals(TIME_DECODE(f2), 2)) \
413         ARG_CASE(ARG_CS,        "f2primsec",     (f2 ? _("secondary") : _("primary"))) \
414         ARG_CASE(ARG_CS,        "f3primsec",     (f3 ? _("secondary") : _("primary"))) \
415         ARG_CASE(ARG_CS,        "f1secs",        count_seconds(f1)) \
416         ARG_CASE(ARG_CS,        "f1points",      (f1 == 1 ? _("point") : _("points"))) \
417         ARG_CASE(ARG_CS_SV,     "f1ord",         count_ordinal(f1)) \
418         ARG_CASE(ARG_CS_SV,     "f1time",        process_time(2, f1)) \
419         ARG_CASE(ARG_CS_SV_HA,  "f1race_time",   mmssss(f1)) \
420         ARG_CASE(ARG_CS_SV_HA,  "f2race_time",   mmssss(f2)) \
421         ARG_CASE(ARG_CS_SV_HA,  "f3race_time",   mmssss(f3)) \
422         ARG_CASE(ARG_CS_SV,     "race_col",      CCR(((f1 == 1) ? "^F1" : "^F2"))) \
423         ARG_CASE(ARG_CS_SV,     "race_diff",     ((f2 > f3) ? sprintf(CCR("^1[+%s]"), mmssss(f2 - f3)) : sprintf(CCR("^2[-%s]"), mmssss(f3 - f2)))) \
424         ARG_CASE(ARG_CS,        "missing_teams", notif_arg_missing_teams(f1)) \
425         ARG_CASE(ARG_CS,        "pass_key",      getcommandkey(_("drop flag"), "+use")) \
426         ARG_CASE(ARG_CS,        "nade_key",      getcommandkey(_("throw nade"), "dropweapon")) \
427         ARG_CASE(ARG_CS,        "join_key",      getcommandkey(_("jump"), "+jump")) \
428         ARG_CASE(ARG_CS,        "frag_ping",     notif_arg_frag_ping(true, f2)) \
429         ARG_CASE(ARG_CS,        "frag_stats",    notif_arg_frag_stats(f2, f3, f4)) \
430         /*ARG_CASE(ARG_CS,      "frag_pos",      ((Should_Print_Score_Pos(f1)) ? sprintf("\n^BG%s", Read_Score_Pos(f1)) : ""))*/ \
431         ARG_CASE(ARG_CS,        "spree_cen",     (autocvar_notification_show_sprees ? notif_arg_spree_cen(f1) : "")) \
432         ARG_CASE(ARG_CS_SV,     "spree_inf",     (autocvar_notification_show_sprees ? notif_arg_spree_inf(1, input, s2, f2) : "")) \
433         ARG_CASE(ARG_CS_SV,     "spree_end",     (autocvar_notification_show_sprees ? notif_arg_spree_inf(-1, "", "", f1) : "")) \
434         ARG_CASE(ARG_CS_SV,     "spree_lost",    (autocvar_notification_show_sprees ? notif_arg_spree_inf(-2, "", "", f1) : "")) \
435         ARG_CASE(ARG_CS_SV,     "item_wepname",  Weapons_from(f1).m_name) \
436         ARG_CASE(ARG_CS_SV,     "item_buffname", BUFF_NAME(f1)) \
437         ARG_CASE(ARG_CS_SV,     "f3buffname",    BUFF_NAME(f3)) \
438         ARG_CASE(ARG_CS_SV,     "item_wepammo",  (f2 > 0 ? notif_arg_item_wepammo(f1, f2) : "")) \
439         ARG_CASE(ARG_DC,        "item_centime",  ftos(autocvar_notification_item_centerprinttime)) \
440         ARG_CASE(ARG_SV,        "death_team",    Team_ColoredFullName(f1)) \
441         ARG_CASE(ARG_CS,        "death_team",    Team_ColoredFullName(f1 - 1)) \
442         ARG_CASE(ARG_CS_SV_HA,  "minigame1_name",find(NULL,netname,s1).descriptor.message) \
443         ARG_CASE(ARG_CS_SV_HA,  "minigame1_d",   find(NULL,netname,s1).descriptor.netname)
444
445 #define NOTIF_HIT_MAX(count,funcname) MACRO_BEGIN \
446         if(sel_num == count) { backtrace(sprintf("%s: Hit maximum arguments!\n", funcname)); break; } \
447 MACRO_END
448
449 #define NOTIF_HIT_UNKNOWN(token,funcname) { backtrace(sprintf("%s: Hit unknown token in selected string! '%s'\n", funcname, selected)); break; }
450
451 #define KILL_SPREE_LIST \
452         SPREE_ITEM(3, 03, _("TRIPLE FRAG! "), _("%s^K1 made a TRIPLE FRAG! %s^BG"), _("%s^K1 made a TRIPLE SCORE! %s^BG")) \
453         SPREE_ITEM(5, 05, _("RAGE! "), _("%s^K1 unlocked RAGE! %s^BG"), _("%s^K1 made FIVE SCORES IN A ROW! %s^BG")) \
454         SPREE_ITEM(10, 10, _("MASSACRE! "), _("%s^K1 started a MASSACRE! %s^BG"), _("%s^K1 made TEN SCORES IN A ROW! %s^BG")) \
455         SPREE_ITEM(15, 15, _("MAYHEM! "), _("%s^K1 executed MAYHEM! %s^BG"), _("%s^K1 made FIFTEEN SCORES IN A ROW! %s^BG")) \
456         SPREE_ITEM(20, 20, _("BERSERKER! "), _("%s^K1 is a BERSERKER! %s^BG"), _("%s^K1 made TWENTY SCORES IN A ROW! %s^BG")) \
457         SPREE_ITEM(25, 25, _("CARNAGE! "), _("%s^K1 inflicts CARNAGE! %s^BG"), _("%s^K1 made TWENTY FIVE SCORES IN A ROW! %s^BG")) \
458         SPREE_ITEM(30, 30, _("ARMAGEDDON! "), _("%s^K1 unleashes ARMAGEDDON! %s^BG"), _("%s^K1 made THIRTY SCORES IN A ROW! %s^BG"))
459
460 #ifdef CSQC
461 string notif_arg_frag_ping(bool newline, float fping)
462 {
463         string s = newline ? "\n" : " ";
464         if (fping < 0)
465                 return sprintf(CCR(_("%s(^F1Bot^BG)")), s);
466         else
467                 return sprintf(CCR(_("%s(Ping ^F1%d^BG)")), s, fping);
468 }
469
470 string notif_arg_frag_stats(float fhealth, float farmor, float fping)
471 {
472         string s = notif_arg_frag_ping(false, fping);
473         if (fhealth > 1)
474                 return sprintf(CCR(_("\n(Health ^1%d^BG / Armor ^2%d^BG)%s")), fhealth, farmor, s);
475         else
476                 return sprintf(CCR(_("\n(^F4Dead^BG)%s")), s);
477 }
478
479 string notif_arg_missing_teams(float f1)
480 {
481         return strcat(
482                 ((f1 & BIT(0)) ? strcat(Team_ColoredFullName(NUM_TEAM_1), (f1 >> 1) ? ", " : "") : ""),
483                 ((f1 & BIT(1)) ? strcat(Team_ColoredFullName(NUM_TEAM_2), (f1 >> 2) ? ", " : "") : ""),
484                 ((f1 & BIT(2)) ? strcat(Team_ColoredFullName(NUM_TEAM_3), (f1 >> 3) ? ", " : "") : ""),
485                 ((f1 & BIT(3)) ?        Team_ColoredFullName(NUM_TEAM_4)                         : "")
486         );
487 }
488
489 string notif_arg_spree_cen(float spree)
490 {
491         // 0 = off, 1 = target (but only for first victim) and attacker
492         if(autocvar_notification_show_sprees_center)
493         {
494                 if(spree > 1)
495                 {
496                         #define SPREE_ITEM(counta,countb,center,normal,gentle) \
497                                 case counta: { return normal_or_gentle(center, sprintf(_("%d score spree! "), spree)); }
498
499                         switch(spree)
500                         {
501                                 KILL_SPREE_LIST
502                                 default:
503                                 {
504                                         if (!autocvar_notification_show_sprees_center_specialonly)
505                                         {
506                                                 return
507                                                         sprintf(
508                                                                 normal_or_gentle(
509                                                                         _("%d frag spree! "),
510                                                                         _("%d score spree! ")
511                                                                 ),
512                                                                 spree);
513                                         }
514                                         else { return ""; } // don't show spree information if it isn't an achievement
515                                 }
516                         }
517
518                         #undef SPREE_ITEM
519                 }
520                 else if(spree == -1) // first blood
521                 {
522                         return normal_or_gentle(_("First blood! "), _("First score! "));
523                 }
524                 else if(spree == -2) // first victim
525                 {
526                         return normal_or_gentle(_("First victim! "), _("First casualty! "));
527                 }
528         }
529         return "";
530 }
531 #endif
532
533 string notif_arg_spree_inf(float type, string input, string player, float spree)
534 {
535         switch(type)
536         {
537                 case 1: // attacker kill spree
538                 {
539                         // 0 = off, 1 = target only, 2 = attacker only, 3 = target and attacker
540                         // this conditional (& 2) is true for 2 and 3
541                         if(autocvar_notification_show_sprees_info & 2)
542                         {
543                                 #ifdef CSQC
544                                 string spree_newline =
545                                         ( autocvar_notification_show_sprees_info_newline ?
546                                                 ((substring(input, 0, 1) == "\{3}") ? "\n\{3}" : "\n") : "" );
547                                 #else
548                                 string spree_newline =
549                                         (autocvar_notification_show_sprees_info_newline ? "\n" : "");
550                                 #endif
551
552                                 if(spree > 1)
553                                 {
554                                         #define SPREE_ITEM(counta,countb,center,normal,gentle) \
555                                                 case counta: { return sprintf(CCR(normal_or_gentle(normal, gentle)), player, spree_newline); }
556
557                                         switch(spree)
558                                         {
559                                                 KILL_SPREE_LIST
560                                                 default:
561                                                 {
562                                                         if (!autocvar_notification_show_sprees_info_specialonly)
563                                                         {
564                                                                 return
565                                                                         sprintf(
566                                                                                 CCR(normal_or_gentle(
567                                                                                         _("%s^K1 has %d frags in a row! %s^BG"),
568                                                                                         _("%s^K1 made %d scores in a row! %s^BG")
569                                                                                 )),
570                                                                                 player,
571                                                                                 spree,
572                                                                                 spree_newline
573                                                                         );
574                                                         }
575                                                         else { return ""; } // don't show spree information if it isn't an achievement
576                                                 }
577                                         }
578
579                                         #undef SPREE_ITEM
580                                 }
581                                 else if(spree == -1) // firstblood
582                                 {
583                                         return
584                                                 sprintf(
585                                                         CCR(normal_or_gentle(
586                                                                 _("%s^K1 drew first blood! %s^BG"),
587                                                                 _("%s^K1 got the first score! %s^BG")
588                                                         )),
589                                                         player,
590                                                         spree_newline
591                                                 );
592                                 }
593                         }
594                         break;
595                 }
596
597                 case -1: // kill spree ended
598                 {
599                         if((spree > 1) && (autocvar_notification_show_sprees_info & 1))
600                         {
601                                 return
602                                         sprintf(normal_or_gentle(
603                                                 _(", ending their %d frag spree"),
604                                                 _(", ending their %d score spree")
605                                                 ),
606                                                 spree
607                                         );
608                         }
609                         break;
610                 }
611
612                 case -2: // kill spree lost
613                 {
614                         if((spree > 1) && (autocvar_notification_show_sprees_info & 1))
615                         {
616                                 return
617                                         sprintf(normal_or_gentle(
618                                                 _(", losing their %d frag spree"),
619                                                 _(", losing their %d score spree")
620                                                 ),
621                                                 spree
622                                         );
623                         }
624                         break;
625                 }
626         }
627         return "";
628 }
629
630 string notif_arg_item_wepammo(float f1, float f2)
631 {
632         string ammoitems = "";
633         Weapon wep = Weapons_from(f1);
634         switch (wep.ammo_type)
635         {
636                 case RES_SHELLS:  ammoitems = ITEM_Shells.m_name;      break;
637                 case RES_BULLETS: ammoitems = ITEM_Bullets.m_name;     break;
638                 case RES_ROCKETS: ammoitems = ITEM_Rockets.m_name;     break;
639                 case RES_CELLS:   ammoitems = ITEM_Cells.m_name;       break;
640                 case RES_PLASMA:  ammoitems = ITEM_Plasma.m_name;      break;
641                 case RES_FUEL:    ammoitems = ITEM_JetpackFuel.m_name; break;
642                 default: return ""; // doesn't use ammo
643         }
644         return sprintf(_(" with %d %s"), f2, ammoitems);
645 }
646
647
648 // ====================================
649 //  Initialization/Create Declarations
650 // ====================================
651
652 // common notification entity values
653 .int nent_default;
654 .bool nent_enabled;
655 .MSG nent_type;
656 .string nent_name;
657 .int nent_stringcount;
658 .int nent_floatcount;
659 .int nent_teamnum;
660
661 // MSG_ANNCE entity values
662 .int nent_channel;
663 .string nent_snd;
664 .float nent_vol;
665 .float nent_position;
666
667 // MSG_INFO and MSG_CENTER entity values
668 .string nent_args; // used by both
669 .string nent_hudargs; // used by info
670 .string nent_icon; // used by info
671 .CPID nent_cpid; // used by center
672 .string nent_durcnt; // used by center
673 .string nent_string; // used by both
674
675 // MSG_MULTI entity values
676 .entity nent_msgannce;
677 .entity nent_msginfo;
678 .entity nent_msgcenter;
679
680 // MSG_CHOICE entity values
681 .float nent_challow_def;
682 .float nent_challow_var;
683 .entity nent_optiona;
684 .entity nent_optionb;
685
686 // networked notification entity values
687 #ifdef SVQC
688 .NOTIF nent_broadcast;
689 #endif
690 .entity nent_client;
691 .MSG nent_net_type;
692 .float nent_net_name;
693 .string nent_strings[4];
694 .float nent_floats[4];
695
696 #define ACVNN(name) autocvar_notification_##name
697
698 REGISTRY(Notifications, BITS(11))
699 REGISTER_REGISTRY(Notifications)
700 REGISTRY_SORT(Notifications);
701 STATIC_INIT(Notifications) { FOREACH(Notifications, true, it.m_id = i); }
702 REGISTRY_CHECK(Notifications)
703
704 const int NOTIF_CHOICE_MAX = 20;
705 // NOTE: a team choice is actually made of 4 choices (one per team) with the same nent_choice_idx
706 // thus they are counted as 1 in nent_choice_count
707 int nent_choice_count = 0;
708 .int nent_choice_idx;
709 .int msg_choice_choices[NOTIF_CHOICE_MAX]; // set on each player containing MSG_CHOICE choices
710 // initialization error detection
711 bool notif_error;
712 bool notif_global_error;
713
714 STATIC_INIT_LATE(Notif_Choices)
715 {
716         if (nent_choice_count > NOTIF_CHOICE_MAX)
717                 LOG_FATALF("Too many MSG_CHOICE notifications (%d), hit NOTIF_CHOICE_MAX (%d) limit",
718                         nent_choice_count, NOTIF_CHOICE_MAX);
719 }
720
721 string Get_Notif_CvarName(Notification notif)
722 {
723         if(!notif.nent_teamnum)
724                 return notif.nent_name;
725         return substring(notif.nent_name, 0, -strlen(Static_Team_ColorName(notif.nent_teamnum)) - 2);
726 }
727
728 Notification Get_Notif_Ent(MSG net_type, int net_name)
729 {
730         Notification it = _Notifications_from(net_name, NULL);
731         if (it.nent_type != net_type) {
732                 LOG_WARNF("Get_Notif_Ent(%s (%d), %s (%d)): Improper net type '%s'!",
733                         Get_Notif_TypeName(net_type), net_type,
734                         it.registered_id, net_name,
735                         Get_Notif_TypeName(it.nent_type)
736                 );
737                 return NULL;
738         }
739         return it;
740 }
741
742 #define MSG_ANNCE_NOTIF_TEAM(teamnum, name, cvarname, defaultvalue, sound, channel, volume, position) \
743         MSG_ANNCE_NOTIF_(teamnum, ANNCE_##name, ANNCE_##cvarname, defaultvalue, sound, channel, volume, position)
744
745 #define MSG_ANNCE_NOTIF(name, defaultvalue, sound, channel, volume, position) \
746         NOTIF_ADD_AUTOCVAR(ANNCE_##name, defaultvalue) \
747         MSG_ANNCE_NOTIF_(0, ANNCE_##name, ANNCE_##name, defaultvalue, sound, channel, volume, position)
748
749 #define MSG_ANNCE_NOTIF_(teamnum, name, cvarname, defaultvalue, sound, channel, volume, position) \
750         REGISTER(Notifications, name, m_id, new_pure(msg_annce_notification)) { \
751                 Create_Notification_Entity      (this, defaultvalue, ACVNN(cvarname), MSG_ANNCE, strtoupper(#name), teamnum); \
752                 Create_Notification_Entity_Annce(this, ACVNN(cvarname), strtoupper(#name), \
753                         channel,   /* channel  */ \
754                         sound,     /* snd      */ \
755                         volume,    /* vol      */ \
756                         position); /* position */ \
757         }
758
759 #define MSG_INFO_NOTIF_TEAM(teamnum, name, cvarname, defaultvalue, strnum, flnum, args, hudargs, icon, normal, gentle) \
760         MSG_INFO_NOTIF_(teamnum, INFO_##name, INFO_##cvarname, defaultvalue, strnum, flnum, args, hudargs, icon, normal, gentle)
761
762 #define MSG_INFO_NOTIF(name, defaultvalue, strnum, flnum, args, hudargs, icon, normal, gentle) \
763         NOTIF_ADD_AUTOCVAR(INFO_##name, defaultvalue) \
764         MSG_INFO_NOTIF_(0, INFO_##name, INFO_##name, defaultvalue, strnum, flnum, args, hudargs, icon, normal, gentle)
765
766 #define MSG_INFO_NOTIF_(teamnum, name, cvarname, defaultvalue, strnum, flnum, args, hudargs, icon, normal, gentle) \
767         REGISTER(Notifications, name, m_id, new_pure(msg_info_notification)) { \
768                 Create_Notification_Entity           (this, defaultvalue, ACVNN(cvarname), MSG_INFO, strtoupper(#name), teamnum); \
769                 Create_Notification_Entity_InfoCenter(this, ACVNN(cvarname), strtoupper(#name), strnum, flnum, \
770                         args,     /* args    */ \
771                         hudargs,  /* hudargs */ \
772                         icon,     /* icon    */ \
773                         CPID_Null,/* cpid    */ \
774                         "",       /* durcnt  */ \
775                         normal,   /* normal  */ \
776                         gentle);  /* gentle  */ \
777         }
778
779 .string nent_iconargs;
780 #define MULTIICON_INFO(name, defaultvalue, strnum, flnum, args, hudargs, iconargs, icon, normal, gentle) \
781         MULTIICON_INFO_(INFO_##name, defaultvalue, strnum, flnum, args, hudargs, iconargs, icon, normal, gentle)
782 #define MULTIICON_INFO_(name, defaultvalue, strnum, flnum, args, hudargs, iconargs, icon, normal, gentle) \
783         NOTIF_ADD_AUTOCVAR(name, defaultvalue) \
784         REGISTER(Notifications, name, m_id, new_pure(msg_info_notification)) { \
785                 Create_Notification_Entity           (this, defaultvalue, ACVNN(name), MSG_INFO, strtoupper(#name), 0); \
786                 Create_Notification_Entity_InfoCenter(this, ACVNN(name), strtoupper(#name), strnum, flnum, \
787                         args,     /* args    */ \
788                         hudargs,  /* hudargs */ \
789                         icon,     /* icon    */ \
790                         CPID_Null,/* cpid    */ \
791                         "",       /* durcnt  */ \
792                         normal,   /* normal  */ \
793                         gentle);  /* gentle  */ \
794                 this.nent_iconargs = iconargs; \
795         }
796
797 #define MSG_CENTER_NOTIF_TEAM(teamnum, name, cvarname, defaultvalue, strnum, flnum, args, cpid, durcnt, normal, gentle) \
798         MSG_CENTER_NOTIF_(teamnum, CENTER_##name, CENTER_##cvarname, defaultvalue, strnum, flnum, args, cpid, durcnt, normal, gentle)
799
800 #define MSG_CENTER_NOTIF(name, defaultvalue, strnum, flnum, args, cpid, durcnt, normal, gentle) \
801         NOTIF_ADD_AUTOCVAR(CENTER_##name, defaultvalue) \
802         MSG_CENTER_NOTIF_(0, CENTER_##name, CENTER_##name, defaultvalue, strnum, flnum, args, cpid, durcnt, normal, gentle)
803
804 #define MSG_CENTER_NOTIF_(teamnum, name, cvarname, defaultvalue, strnum, flnum, args, cpid, durcnt, normal, gentle) \
805         REGISTER(Notifications, name, m_id, new_pure(msg_center_notification)) { \
806                 Create_Notification_Entity           (this, defaultvalue, ACVNN(cvarname), MSG_CENTER, strtoupper(#name), teamnum); \
807                 Create_Notification_Entity_InfoCenter(this, ACVNN(cvarname), strtoupper(#name), strnum, flnum, \
808                         args,    /* args    */ \
809                         "",      /* hudargs */ \
810                         "",      /* icon    */ \
811                         cpid,    /* cpid    */ \
812                         durcnt,  /* durcnt  */ \
813                         normal,  /* normal  */ \
814                         gentle); /* gentle  */ \
815         }
816
817 #define MSG_MULTI_NOTIF(name, defaultvalue, anncename, infoname, centername) \
818         NOTIF_ADD_AUTOCVAR(name, defaultvalue) \
819         REGISTER(Notifications, name, m_id, new_pure(msg_multi_notification)) { \
820                 Create_Notification_Entity      (this, defaultvalue, ACVNN(name), MSG_MULTI, strtoupper(#name), 0); \
821                 Create_Notification_Entity_Multi(this, ACVNN(name), strtoupper(#name), \
822                         anncename,   /* anncename  */ \
823                         infoname,    /* infoname   */ \
824                         centername); /* centername */ \
825         }
826
827 #define MSG_CHOICE_NOTIF_TEAM(teamnum, name, cvarname, defaultvalue, challow, chtype, optiona, optionb) \
828         MSG_CHOICE_NOTIF_(teamnum, CHOICE_##name, CHOICE_##cvarname, defaultvalue, challow, chtype, optiona, optionb)
829
830 #define MSG_CHOICE_NOTIF(name, defaultvalue, challow, chtype, optiona, optionb) \
831         NOTIF_ADD_AUTOCVAR(CHOICE_##name, defaultvalue) \
832         NOTIF_ADD_AUTOCVAR(CHOICE_##name##_ALLOWED, challow) \
833         MSG_CHOICE_NOTIF_(0, CHOICE_##name, CHOICE_##name, defaultvalue, challow, chtype, optiona, optionb)
834
835 #define MSG_CHOICE_NOTIF_(teamnum, name, cvarname, defaultvalue, challow, chtype, optiona, optionb) \
836         REGISTER(Notifications, name, m_id, new_pure(msg_choice_notification)) { \
837                 this.nent_choice_idx = nent_choice_count; \
838                 if (!teamnum || teamnum == NUM_TEAM_4) \
839                         nent_choice_count++; \
840                 Create_Notification_Entity       (this, defaultvalue, ACVNN(cvarname), MSG_CHOICE, strtoupper(#name), teamnum); \
841                 Create_Notification_Entity_Choice(this, ACVNN(cvarname), strtoupper(#name), \
842                         challow,                                 /* challow_def */ \
843                         autocvar_notification_##cvarname##_ALLOWED,  /* challow_var */ \
844                         chtype,                                  /* chtype      */ \
845                         optiona,                                 /* optiona     */ \
846                         optionb);                                /* optionb     */ \
847         }
848
849 REGISTRY_BEGIN(Notifications)
850 {
851         notif_global_error = false;
852 }
853
854 REGISTRY_END(Notifications)
855 {
856         if (!notif_global_error) return;
857         // shit happened... stop the loading of the program now if this is unacceptable
858         if (autocvar_notification_errors_are_fatal)
859                 LOG_FATAL("Notification initialization failed! Read above and fix the errors!");
860         else
861                 LOG_SEVERE("Notification initialization failed! Read above and fix the errors!");
862 }
863
864 #ifdef CSQC
865 .int cvar_value;
866 void ReplicateVars(bool would_destroy)
867 {
868         if (!would_destroy)
869                 FOREACH(Notifications, it.nent_type == MSG_CHOICE && (!it.nent_teamnum || it.nent_teamnum == NUM_TEAM_1), {
870                         string cvarname = strcat("notification_", Get_Notif_CvarName(it));
871                         // NOTE: REPLICATE_SIMPLE can return;
872                         REPLICATE_SIMPLE(it.cvar_value, cvarname);
873                 });
874 }
875 #endif
876
877 #include "all.inc"