From: Samual Lenks Date: Sat, 16 Feb 2013 00:45:10 +0000 (-0500) Subject: Centralize the argument list X-Git-Tag: xonotic-v0.7.0~62^2~23^2~213 X-Git-Url: https://git.rm.cloudns.org/?a=commitdiff_plain;h=fe333674311f3413cf9ff8a1737ff6f0b21392aa;p=xonotic%2Fxonotic-data.pk3dir.git Centralize the argument list --- diff --git a/qcsrc/common/notifications.qc b/qcsrc/common/notifications.qc index 014d29deb..68055f8c5 100644 --- a/qcsrc/common/notifications.qc +++ b/qcsrc/common/notifications.qc @@ -114,8 +114,8 @@ string Local_Notification_sprintf(string input, string args, { #ifdef NOTIFICATIONS_DEBUG dprint( - sprintf("Local_Notification_sprintf('%s', '%s', %s, %s);\n", - input, args, + sprintf("Local_Notification_sprintf('%s'^7, '%s', %s, %s);\n", + strreplace("\n", "\\n", input), args, sprintf("%s, %s, %s, %s", s1, s2, s3, s4), sprintf("%d, %d, %d, %d", f1, f2, f3, f4))); #endif @@ -137,41 +137,22 @@ string Local_Notification_sprintf(string input, string args, switch(strtolower(selected)) { - #define ADD_ARG_CASE(selected,result) case selected: { arg_slot[sel_num] = result; ++sel_num; break; } - - ADD_ARG_CASE("s1", s1) - ADD_ARG_CASE("s2", s2) - ADD_ARG_CASE("s3", s3) - ADD_ARG_CASE("s4", s4) - ADD_ARG_CASE("f1", ftos(f1)) - ADD_ARG_CASE("f2", ftos(f2)) - ADD_ARG_CASE("f3", ftos(f3)) - ADD_ARG_CASE("f4", ftos(f4)) - - #ifdef CSQC // CSQC replacements - ADD_ARG_CASE("pass_key", ((((tmp_s = getcommandkey("pass", "+use")) != "pass") && !(strstrofs(tmp_s, "not bound", 0) >= 0)) ? sprintf(CCR(_(" ^F1(Press %s)")), tmp_s) : "")) - ADD_ARG_CASE("frag_ping", ((f2 != BOT_PING) ? sprintf(CCR(_("\n(Ping ^2%d^BG)")), f2) : "")) - ADD_ARG_CASE("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) : ""))) - //ADD_ARG_CASE("frag_pos", ((Should_Print_Score_Pos(f1)) ? sprintf("\n^BG%s", Read_Score_Pos(f1)) : "")) - ADD_ARG_CASE("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) : "")) - ADD_ARG_CASE("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) : "")) - ADD_ARG_CASE("spree_end", ((f1 >= 3) ? sprintf(normal_or_gentle(_(", ending their %d frag spree"), _(", ending their %d score spree")), f1) : "")) - ADD_ARG_CASE("spree_lost", ((f1 >= 3) ? sprintf(normal_or_gentle(_(", losing their %d frag spree"), _(", losing their %d score spree")), f1) : "")) - ADD_ARG_CASE("death_team", Team_ColoredFullName(f1 - 1)) - ADD_ARG_CASE("weapon_name", ftos(f1)) // weaponorder[f1].netname - - #else // SVQC replacements - ADD_ARG_CASE("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) : "")) - ADD_ARG_CASE("spree_end", ((f1 >= 3) ? sprintf(normal_or_gentle(_(", ending their %d frag spree"), _(", ending their %d score spree")), f1) : "")) - ADD_ARG_CASE("spree_lost", ((f1 >= 3) ? sprintf(normal_or_gentle(_(", losing their %d frag spree"), _(", losing their %d score spree")), f1) : "")) - ADD_ARG_CASE("death_team", Team_ColoredFullName(f1)) - ADD_ARG_CASE("weapon_name", ftos(f1)) // weaponorder[f1].netname - #endif - - #undef ADD_ARG_CASE + #define ARG_CASE(prog,selected,result) \ + #ifdef CSQC \ + #if (prog == ARG_BOTH) || (prog == ARG_CSQC) \ + case selected: { arg_slot[sel_num] = result; ++sel_num; break; } \ + #endif \ + #else \ + #if (prog == ARG_BOTH) || (prog == ARG_SVQC) \ + case selected: { arg_slot[sel_num] = result; ++sel_num; break; } \ + #endif \ + #endif + + NOTIF_ARGUMENT_LIST + #undef ARG_CASE default: { backtrace(sprintf("Hit unknown token in selected string! '%s'\n", selected)); break; } } - if(sel_num == 6) { backtrace("Hit maximum arguments!\n"); break; } + if((sel_num+1) > 7) { backtrace("Hit maximum arguments!\n"); break; } } return sprintf(input, arg_slot[0], arg_slot[1], arg_slot[2], arg_slot[3], arg_slot[4], arg_slot[5], arg_slot[6]); @@ -196,15 +177,13 @@ void Local_Notification_HUD_Notify_Push(string icon, string hudargs, string s1, switch(strtolower(selected)) { - #define ADD_ARG_CASE(selected,result) case selected: { arg_slot[sel_num] = result; ++sel_num; break; } - - ADD_ARG_CASE("s1", s1) - ADD_ARG_CASE("s2", s2) - - #undef ADD_ARG_CASE + #define ARG_CASE(selected,result) case selected: { arg_slot[sel_num] = result; ++sel_num; break; } + ARG_CASE("s1", s1) + ARG_CASE("s2", s2) + #undef ARG_CASE default: { backtrace(sprintf("Hit unknown token in selected string! '%s'\n", selected)); break; } } - if(sel_num == 7) { backtrace("Hit maximum arguments!\n"); break; } + if((sel_num+1) > 2) { backtrace("Hit maximum arguments!\n"); break; } } } diff --git a/qcsrc/common/notifications.qh b/qcsrc/common/notifications.qh index 51616a200..8ec5d781a 100644 --- a/qcsrc/common/notifications.qh +++ b/qcsrc/common/notifications.qh @@ -43,6 +43,35 @@ VARITEM(3, 4, XPD(s1, s2, s3, f1, f2, f3, f4)) \ VARITEM(4, 4, XPD(s1, s2, s3, s4, f1, f2, f3, f4)) +#define ARG_BOTH 1 +#define ARG_CSQC 2 +#define ARG_SVQC 3 + +#define NOTIF_ARGUMENT_LIST \ + ARG_CASE(ARG_BOTH, "s1", s1) \ + ARG_CASE(ARG_BOTH, "s2", s2) \ + ARG_CASE(ARG_BOTH, "s3", s3) \ + ARG_CASE(ARG_BOTH, "s4", s4) \ + ARG_CASE(ARG_BOTH, "f1", ftos(f1)) \ + ARG_CASE(ARG_BOTH, "f2", ftos(f2)) \ + ARG_CASE(ARG_BOTH, "f3", ftos(f3)) \ + ARG_CASE(ARG_BOTH, "f4", ftos(f4)) \ + ARG_CASE(ARG_CSQC, "pass_key", ((((tmp_s = getcommandkey("pass", "+use")) != "pass") && !(strstrofs(tmp_s, "not bound", 0) >= 0)) ? sprintf(CCR(_(" ^F1(Press %s)")), tmp_s) : "")) \ + ARG_CASE(ARG_CSQC, "frag_ping", ((f2 != BOT_PING) ? sprintf(CCR(_("\n(Ping ^2%d^BG)")), f2) : "")) \ + ARG_CASE(ARG_CSQC, "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) : ""))) \ + /*ARG_CASE(ARG_CSQC, "frag_pos", ((Should_Print_Score_Pos(f1)) ? sprintf("\n^BG%s", Read_Score_Pos(f1)) : ""))*/ \ + ARG_CASE(ARG_CSQC, "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) : "")) \ + ARG_CASE(ARG_CSQC, "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) : "")) \ + ARG_CASE(ARG_CSQC, "spree_end", ((f1 >= 3) ? sprintf(normal_or_gentle(_(", ending their %d frag spree"), _(", ending their %d score spree")), f1) : "")) \ + ARG_CASE(ARG_CSQC, "spree_lost", ((f1 >= 3) ? sprintf(normal_or_gentle(_(", losing their %d frag spree"), _(", losing their %d score spree")), f1) : "")) \ + ARG_CASE(ARG_CSQC, "death_team", Team_ColoredFullName(f1 - 1)) \ + ARG_CASE(ARG_CSQC, "weapon_name", ftos(f1)) \ + ARG_CASE(ARG_SVQC, "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) : "")) \ + ARG_CASE(ARG_SVQC, "spree_end", ((f1 >= 3) ? sprintf(normal_or_gentle(_(", ending their %d frag spree"), _(", ending their %d score spree")), f1) : "")) \ + ARG_CASE(ARG_SVQC, "spree_lost", ((f1 >= 3) ? sprintf(normal_or_gentle(_(", losing their %d frag spree"), _(", losing their %d score spree")), f1) : "")) \ + ARG_CASE(ARG_SVQC, "death_team", Team_ColoredFullName(f1)) \ + ARG_CASE(ARG_SVQC, "weapon_name", ftos(f1)) + entity Get_Notif_Ent(float net_type, float net_name); string Get_Notif_Name(float net_type, float net_name); float Get_Notif_Infval(float net_type, float net_name); @@ -616,7 +645,9 @@ string Process_Notif_Args(float is_hudargs, string args, string notiftype, strin switch(strtolower(selected)) { - //#undef ARG_CASE + #define ARG_CASE(prog,selected,result) case selected: { ++sel_num; break; } + NOTIF_ARGUMENT_LIST + #undef ARG_CASE default: { print(sprintf("^1NOTIFICATION WITH UNKNOWN TOKEN IN ARGUMENT STRING: ^7net_type = MSG_%s, net_name = %s, %s = '%s'.\n", @@ -625,7 +656,7 @@ string Process_Notif_Args(float is_hudargs, string args, string notiftype, strin break; } } - if(sel_num == maxargs) + if((sel_num+1) > maxargs) { print(sprintf("^1NOTIFICATION HAS TOO MANY ARGUMENTS: ^7net_type = MSG_%s, net_name = %s, max %s = %d.\n", notiftype, notifname, (is_hudargs ? "hudargs" : "args"), maxargs)); diff --git a/qcsrc/server/cl_client.qc b/qcsrc/server/cl_client.qc index 0ad60dcaf..7e89fd7df 100644 --- a/qcsrc/server/cl_client.qc +++ b/qcsrc/server/cl_client.qc @@ -1364,7 +1364,7 @@ void ClientConnect (void) DecodeLevelParms(); #ifdef WATERMARK - Send_Notification_Legacy_Wrapper(NOTIF_ONE_ONLY, self, MSG_INFO, INFO_WATERMARK, WATERMARK, "", NO_FL_ARG, NO_FL_ARG, NO_FL_ARG); + Send_Notification(NOTIF_ONE_ONLY, self, MSG_INFO, INFO_WATERMARK, WATERMARK); #endif self.classname = "player_joining";