]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/commitdiff
Move Local_Notification function over to use entities too
authorSamual Lenks <samual@xonotic.org>
Tue, 12 Feb 2013 11:54:56 +0000 (06:54 -0500)
committerSamual Lenks <samual@xonotic.org>
Tue, 12 Feb 2013 11:54:56 +0000 (06:54 -0500)
qcsrc/client/progs.src
qcsrc/common/notifications.qc
qcsrc/common/notifications.qh
qcsrc/server/progs.src

index 8b83daebeebdb30253b2722b70db4b71269eb9a4..335a17e5467d9f88780d14f3486c6894c91c92ef 100644 (file)
@@ -18,7 +18,6 @@ Defs.qc
 ../common/util.qh
 ../common/items.qh
 ../common/deathtypes.qh
-../common/notifications.qh
 ../common/explosion_equation.qh
 ../common/mapinfo.qh
 ../common/command/markup.qh
@@ -31,6 +30,8 @@ command/cl_cmd.qh
 
 autocvars.qh
 
+../common/notifications.qh // must be after autocvars
+
 damage.qh
 
 ../csqcmodellib/interpolate.qh
index ebaf815e2eb4817ae60e908f3a02a56a3fbba9af..5be45544605600390fcda71bd1c059f167371120 100644 (file)
@@ -144,8 +144,8 @@ void Dump_Notifications(float fh, float alsoprint)
        float i;
        entity e;
 
-       for(i = 0; i < NOTIF_INFO_COUNT; ++i) { e = Get_Notif_Ent(MSG_INFO, i); NOTIF_WRITE(MSG_INFO, e.nent_name, e.nent_normal); }
-       for(i = 0; i < NOTIF_CENTER_COUNT; ++i) { e = Get_Notif_Ent(MSG_CENTER, i); NOTIF_WRITE(MSG_CENTER, e.nent_name, e.nent_normal); }
+       for(i = 0; i < NOTIF_INFO_COUNT; ++i) { e = Get_Notif_Ent(MSG_INFO, i); NOTIF_WRITE(MSG_INFO, e.nent_name, e.nent_string); }
+       for(i = 0; i < NOTIF_CENTER_COUNT; ++i) { e = Get_Notif_Ent(MSG_CENTER, i); NOTIF_WRITE(MSG_CENTER, e.nent_name, e.nent_string); }
        
        for(i = 0; i < NOTIF_WEAPON_COUNT; ++i) { e = Get_Notif_Ent(MSG_WEAPON, i); NOTIF_WRITE(MSG_WEAPON, e.nent_name, sprintf("infoname: %s, centername: %s",
                Get_Notif_Name(MSG_INFO, Get_Notif_Infval(MSG_WEAPON, i)),
@@ -213,118 +213,79 @@ void Local_Notification(float net_type, float net_name, ...count)
                if(checkargs != "") { backtrace(sprintf("Incorrect usage of Local_Notification: %s\n", checkargs)); return; }
        }
        #endif
-       
-       float stringcount = Get_Notif_Strnum(net_type, net_name);
-       float floatcount = Get_Notif_Flnum(net_type, net_name);
 
-       string s1 = ((0 < stringcount) ? ...(0, string) : NO_STR_ARG);
-       string s2 = ((1 < stringcount) ? ...(1, string) : NO_STR_ARG);
-       string s3 = ((2 < stringcount) ? ...(2, string) : NO_STR_ARG);
-       string s4 = ((3 < stringcount) ? ...(3, string) : NO_STR_ARG);
-       float f1 = ((stringcount < count) ? ...(stringcount, float) : NO_FL_ARG);
-       float f2 = (((stringcount + 1) < count) ? ...((stringcount + 1), float) : NO_FL_ARG);
-       float f3 = (((stringcount + 2) < count) ? ...((stringcount + 2), float) : NO_FL_ARG);
-       float f4 = (((stringcount + 3) < count) ? ...((stringcount + 3), float) : NO_FL_ARG);
+       entity notif = Get_Notif_Ent(net_type, net_name);
+       if not(notif) { backtrace("Local_Notification: Could not find notification entity! (This wasn't caught by usage check?...)\n"); return; }
+       if not(notif.nent_enabled) { print("entity notification was disabled...\n"); return; }
+
+       string s1 = ((0 < notif.nent_stringcount) ? ...(0, string) : NO_STR_ARG);
+       string s2 = ((1 < notif.nent_stringcount) ? ...(1, string) : NO_STR_ARG);
+       string s3 = ((2 < notif.nent_stringcount) ? ...(2, string) : NO_STR_ARG);
+       string s4 = ((3 < notif.nent_stringcount) ? ...(3, string) : NO_STR_ARG);
+       float f1 = ((notif.nent_stringcount < count) ? ...(notif.nent_stringcount, float) : NO_FL_ARG);
+       float f2 = (((notif.nent_stringcount + 1) < count) ? ...((notif.nent_stringcount + 1), float) : NO_FL_ARG);
+       float f3 = (((notif.nent_stringcount + 2) < count) ? ...((notif.nent_stringcount + 2), float) : NO_FL_ARG);
+       float f4 = (((notif.nent_stringcount + 3) < count) ? ...((notif.nent_stringcount + 3), float) : NO_FL_ARG);
 
        #ifdef NOTIFICATIONS_DEBUG
        {
                dprint(sprintf("Local_Notification(%d, %s, %s, %s, %s, %s, %d, %d, %d, %d);\n",
-                       net_type, Get_Notif_Name(net_type, net_name),
+                       net_type, notif.nent_name,
                        s1, s2, s3, s4, f1, f2, f3, f4));
 
-               if((stringcount + floatcount) > count)
+               if((notif.nent_stringcount + notif.nent_floatcount) > count)
                        { backtrace(sprintf(strcat("Not enough arguments for Send_Notification! stringcount(%d) + floatcount(%d) > count(%d)\n", 
-                       "Check the notification definition and function call for accuracy...?\n"), stringcount, floatcount, count)); return; }
-               else if((stringcount + floatcount) < count)
+                       "Check the notification definition and function call for accuracy...?\n"), notif.nent_stringcount, notif.nent_floatcount, count)); return; }
+               else if((notif.nent_stringcount + notif.nent_floatcount) < count)
                        { backtrace(sprintf(strcat("Too many arguments for Send_Notification! stringcount(%d) + floatcount(%d) < count(%d)\n",
-                       "Check the notification definition and function call for accuracy...?\n"), stringcount, floatcount, count)); return; }
+                       "Check the notification definition and function call for accuracy...?\n"), notif.nent_stringcount, notif.nent_floatcount, count)); return; }
        }
        #endif
        
-
        switch(net_type)
        {
                case MSG_INFO:
                {
-                       #define MSG_INFO_NOTIF(name,strnum,flnum,args,hudargs,icon,normal,gentle) \
-                               case name: { CHECK_AUTOCVAR(name) \
-                               { \
-                                       print(sprintf(CCR(normal_or_gentle(normal, gentle)), args)); \
-                                       #ifdef CSQC \
-                                               if(icon != "") { HUD_Notify_Push(icon, hudargs); } \
-                                       #endif \
-                               } return; }
+                       print(Fill_Notif_Args(notif.nent_args, notif.nent_string,
+                               s1, s2, s3, s4, f1, f2, f3, f4));
                                
-                       NOTIF_SWITCH_LIST(MSG_INFO, net_name, return)
-                       
-                       #undef MSG_INFO_NOTIF
+                       #ifdef CSQC 
+                       if(notif.nent_icon != "") { HUD_Notify_Push(notif.nent_icon, s1, s2); } 
+                       #endif 
                        break;
                }
+               
                #ifdef CSQC
                case MSG_CENTER:
                {
-                       #define MSG_CENTER_NOTIF(name,strnum,flnum,args,cpid,durcnt,normal,gentle) \
-                               case name: { CHECK_AUTOCVAR(name) \
-                               { \
-                                       centerprint_generic(HANDLE_CPID(cpid), sprintf(CCR(normal_or_gentle(normal, gentle)), args), durcnt); \
-                               } return; }
-
-                       NOTIF_SWITCH_LIST(MSG_CENTER, net_name, return)
-                       
-                       #undef MSG_CENTER_NOTIF
+                       centerprint_generic(HANDLE_CPID(notif.nent_cpid),
+                               Fill_Notif_Args(notif.nent_args, notif.nent_string,
+                               s1, s2, s3, s4, f1, f2, f3, f4), 0, 0);
                        break;
                }
                #endif
+               
                case MSG_WEAPON:
-               {
-                       #define MSG_WEAPON_NOTIF(name,infoname,centername) \
-                               case name: { CHECK_AUTOCVAR(name) \
-                               { \
-                                       #if infoname != NO_MSG \
-                                               Local_Notification_Without_VarArgs(MSG_INFO, infoname, \
-                                                       Get_Notif_Strnum(MSG_INFO, infoname), \
-                                                       Get_Notif_Flnum(MSG_INFO, infoname), \
-                                                       s1, s2, s3, s4, f1, f2, f3, f4); \
-                                       #endif \
-                                       #ifdef CSQC \
-                                               #if centername != NO_MSG \
-                                                       Local_Notification_Without_VarArgs(MSG_CENTER, centername, \
-                                                               Get_Notif_Strnum(MSG_CENTER, centername), \
-                                                               Get_Notif_Flnum(MSG_CENTER, centername), \
-                                                               s1, s2, s3, s4, f1, f2, f3, f4); \
-                                               #endif \
-                                       #endif \
-                               } return; }
-
-                       NOTIF_SWITCH_LIST(MSG_WEAPON, net_name, return)
-                       
-                       #undef MSG_WEAPON_NOTIF
-                       break;
-               }
                case MSG_DEATH:
                {
-                       #define MSG_DEATH_NOTIF(name,infoname,centername) \
-                               case name: { CHECK_AUTOCVAR(name) \
-                               { \
-                                       #if infoname != NO_MSG \
-                                               Local_Notification_Without_VarArgs(MSG_INFO, infoname, \
-                                                       Get_Notif_Strnum(MSG_INFO, infoname), \
-                                                       Get_Notif_Flnum(MSG_INFO, infoname), \
-                                                       s1, s2, s3, s4, f1, f2, f3, f4); \
-                                       #endif \
-                                       #ifdef CSQC \
-                                               #if centername != NO_MSG \
-                                                       Local_Notification_Without_VarArgs(MSG_CENTER, centername, \
-                                                               Get_Notif_Strnum(MSG_CENTER, centername), \
-                                                               Get_Notif_Flnum(MSG_CENTER, centername), \
-                                                               s1, s2, s3, s4, f1, f2, f3, f4); \
-                                               #endif \
-                                       #endif \
-                               } return; } 
-
-                       NOTIF_SWITCH_LIST(MSG_DEATH, net_name, return)
-                       
-                       #undef MSG_DEATH_NOTIF
+                       if(notif.nent_infoname)
+                       if(msg_info_notifs[notif.nent_infoname - 1].nent_enabled)
+                       {
+                               Local_Notification_Without_VarArgs(MSG_INFO, notif.nent_infoname, 
+                                       Get_Notif_Strnum(MSG_INFO, notif.nent_infoname), 
+                                       Get_Notif_Flnum(MSG_INFO, notif.nent_infoname), 
+                                       s1, s2, s3, s4, f1, f2, f3, f4);
+                       }
+                       #ifdef CSQC \
+                       if(notif.nent_centername)
+                       if(msg_center_notifs[notif.nent_centername - 1].nent_enabled)
+                       {
+                               Local_Notification_Without_VarArgs(MSG_CENTER, notif.nent_centername, 
+                                       Get_Notif_Strnum(MSG_CENTER, notif.nent_centername), 
+                                       Get_Notif_Flnum(MSG_CENTER, notif.nent_centername), 
+                                       s1, s2, s3, s4, f1, f2, f3, f4); 
+                       }
+                       #endif \
                        break;
                }
        }
index 23784363eecba0018e920c59a359658dbc8f97f6..c08eec28f55079c2a0c91e6a7cbc0af73677ff87 100644 (file)
        VARITEM(3, 4, XPD(s1, s2, s3, f1, f2, f3, f4)) \
        VARITEM(4, 4, XPD(s1, s2, s3, s4, f1, f2, f3, f4))
 
-/*
- Acquire special information to generate for display in the
- notification from variables networked to the client.
- Macro descriptions:
-       PASS_KEY: find the keybind for "passing" or "dropping" in CTF game mode
-       FRAG_PING: show the ping of a player
-       FRAG_STATS: show health/armor/ping of a player
-       FRAG_POS: show score status and position in the match of a player
-       SPREE_CEN: centerprint notif for kill spree/how many kills they have
-       SPREE_INF: info notif for kill spree/how many kills they have
-       SPREE_END: placed at the end of murder messages to show ending of sprees
-       SPREE_LOST: placed at the end of suicide messages to show losing of sprees
-       DEATH_TEAM: show the full name of the team a player is switching from
-       WEAPON_NAME: return the full name of a weapon from a weaponid
-*/
-
-#ifdef CSQC // CSQC replacements
-string got_commandkey;
-#define PASS_KEY ((((got_commandkey = getcommandkey("pass", "+use")) != "pass") && !(strstrofs(got_commandkey, "not bound", 0) >= 0)) ? sprintf(CCR(_(" ^F1(Press %s)")), got_commandkey) : "")
-#define FRAG_PING ((f2 != BOT_PING) ? sprintf(CCR(_("\n(Ping ^2%d^BG)")), f2) : "")
-#define FRAG_STATS sprintf(CCR(_("\n(Health ^1%d^BG / Armor ^2%d^BG)%s")), f1, f2, ((f3 != BOT_PING) ? sprintf(CCR(_(" (Ping ^2%d^BG)")), f3) : ""))
-#define FRAG_POS ((Should_Print_Score_Pos(f1)) ? sprintf("\n^BG%s", Read_Score_Pos(f1)) : "")
-#define SPREE_CEN (((f1 == 3) || (f1 == 5) || (f1 == 10) || (f1 == 15) || (f1 == 20) || (f1 == 25) || (f1 == 30)) ? sprintf(normal_or_gentle(_("%d frag spree! "), _("%d score spree! ")), f1) : "")
-#define SPREE_INF (((f1 == 3) || (f1 == 5) || (f1 == 10) || (f1 == 15) || (f1 == 20) || (f1 == 25) || (f1 == 30)) ? sprintf(normal_or_gentle(_("%d frag spree! "), _("%d score spree! ")), f1) : "")
-#define SPREE_END ((f1 >= 3) ? sprintf(normal_or_gentle(_(", ending their %d frag spree"), _(", ending their %d score spree")), f1) : "")
-#define SPREE_LOST ((f1 >= 3) ? sprintf(normal_or_gentle(_(", losing their %d frag spree"), _(", losing their %d score spree")), f1) : "")
-#define DEATH_TEAM Team_ColoredFullName(f1 - 1)
-#define WEAPON_NAME f1 // weaponorder[f1].netname
-
-#else // SVQC replacements
-#define SPREE_INF (((f1 == 3) || (f1 == 5) || (f1 == 10) || (f1 == 15) || (f1 == 20) || (f1 == 25) || (f1 == 30)) ? sprintf(normal_or_gentle(_("%d frag spree! "), _("%d score spree! ")), f1) : "")
-#define SPREE_END ((f1 >= 3) ? sprintf(normal_or_gentle(_(", ending their %d frag spree"), _(", ending their %d score spree")), f1) : "")
-#define SPREE_LOST ((f1 >= 3) ? sprintf(normal_or_gentle(_(", losing their %d frag spree"), _(", losing their %d score spree")), f1) : "")
-#define DEATH_TEAM Team_ColoredFullName(f1)
-#define WEAPON_NAME f1 // weaponorder[f1].netname
-#endif
-
 #define NOTIF_SWITCH_LIST(net_type,net_name,returnv) \
        switch(net_name) \
        { \
@@ -611,9 +574,6 @@ void Dump_Notifications(float fh, float alsoprint);
 #define NOTIF_FIRST 1
 #define NOTIF_MAX 1024 // limit of recursive functions with ACCUMULATE_FUNCTION
 
-#define ADD_AUTOCVAR(name) var float autocvar_notification_##name = TRUE;
-#define CHECK_AUTOCVAR(name) if(autocvar_notification_##name)
-
 float NOTIF_INFO_COUNT;
 float NOTIF_CENTER_COUNT;
 float NOTIF_WEAPON_COUNT;
@@ -633,6 +593,7 @@ entity msg_death_notifs[NOTIF_MAX];
 .float nent_floats[4];
 
 .string nent_name;
+.float nent_enabled; 
 .float nent_infoname;
 .float nent_centername;
 .float nent_stringcount;
@@ -642,18 +603,30 @@ entity msg_death_notifs[NOTIF_MAX];
 .string nent_icon;
 .float nent_cpid;
 .string nent_durcnt;
-.string nent_normal;
-.string nent_gentle;
+.string nent_string;
 
 //     notif.nent_args = strzone(args); \
 //     notif.nent_hudargs = strzone(hudargs); \
 // if(durcnt != "") { notif.nent_durcnt = durcnt; } \
 
+string Process_Notif_Line(float check_newline, string input, string notiftype, string notifname, string stringtype)
+{
+       if(check_newline) 
+       if(substring(input, (strlen(input) - 1), 1) != "\n")
+       {
+               print(sprintf("^1MISSING/BROKEN NEW LINE AT END OF NOTIFICATION: ^7net_type = MSG_%s, net_name = %s, %s string.\n", notiftype, notifname, stringtype));
+               return strcat(input, "\n");
+       }
+       return input;
+}
+#define ADD_AUTOCVAR(name) var float autocvar_notification_##name = TRUE;
+
 #define CREATE_NOTIF_ENTITY(type,name,infoname,centername,strnum,flnum,args,hudargs,icon,cpid,durcnt,normal,gentle,check_newline,subcalls) \
        entity notif = spawn(); \
        msg_##type##_notifs[name - 1] = notif; \
        notif.classname = "msg_#type#_notification"; \
        notif.nent_name = strzone(#name); \
+       notif.nent_enabled = autocvar_notification_##name; \
        #if subcalls \
                #if (infoname == NO_MSG) && (centername == NO_MSG) \
                        print(sprintf("^1NOTIFICATION WITH NO SUBCALLS: ^7net_type = MSG_%s, net_name = %s.\n", strtoupper(#type), #name)); \
@@ -676,14 +649,15 @@ entity msg_death_notifs[NOTIF_MAX];
                notif.nent_stringcount = strnum; \
                notif.nent_floatcount = flnum; \
                if(icon != "") { notif.nent_icon = strzone(icon); } \
-               if(normal != "") { notif.nent_normal = strzone(CCR(normal)); } \
-               else { print(sprintf("^1EMPTY NOTIFICATION: ^7net_type = MSG_%s, net_name = %s.\n", strtoupper(#type), #name)); } \
-               if(gentle != "") { notif.nent_gentle = strzone(CCR(gentle)); } \
-               #if check_newline \
-                       if(normal != "") { if not(substring(normal, (strlen(normal) - 1), 1) == "\n") { print(sprintf("^1MISSING/BROKEN NEW LINE AT END OF NOTIFICATION: ^7net_type = MSG_%s, net_name = %s, NORMAL string.\n", strtoupper(#type), #name)); } } \
-                       if(gentle != "") { if not(substring(gentle, (strlen(gentle) - 1), 1) == "\n") { print(sprintf("^1MISSING/BROKEN NEW LINE AT END OF NOTIFICATION: ^7net_type = MSG_%s, net_name = %s, GENTLE string.\n", strtoupper(#type), #name)); } } \
-               #else \
-                       if(cpid != NO_MSG) { notif.nent_cpid = cpid; } \
+               if(GENTLE) \
+               { \
+                       if(gentle != "") { notif.nent_string = strzone(CCR(Process_Notif_Line(check_newline, gentle, strtoupper(#type), #name, "GENTLE"))); } \
+                       else if(normal != "") { notif.nent_string = strzone(CCR(Process_Notif_Line(check_newline, normal, strtoupper(#type), #name, "NORMAL"))); } \
+               } \
+               else { if(normal != "") { notif.nent_string = strzone(CCR(Process_Notif_Line(check_newline, normal, strtoupper(#type), #name, "NORMAL"))); } } \
+               if(notif.nent_string == "") { print(sprintf("^1EMPTY NOTIFICATION: ^7net_type = MSG_%s, net_name = %s.\n", strtoupper(#type), #name)); } \
+               #if !check_newline \
+               if(cpid != NO_MSG) { notif.nent_cpid = cpid; } \
                #endif \
        #endif
 
index dcd144d31634b3474985f63f917c564dd02e41dd..ef4bc98cf2143098826be4705eb51e029bf41086 100644 (file)
@@ -17,7 +17,6 @@ sys-post.qh
 ../common/util.qh
 ../common/items.qh
 ../common/deathtypes.qh
-../common/notifications.qh
 ../common/explosion_equation.qh
 ../common/urllib.qh
 ../common/command/markup.qh
@@ -31,6 +30,8 @@ autocvars.qh
 constants.qh
 defs.qh                // Should rename this, it has fields and globals
 
+../common/notifications.qh // must be after autocvars
+
 mutators/base.qh
 mutators/mutators.qh
 mutators/gamemode_ctf.qh