From: Samual Lenks Date: Wed, 13 Feb 2013 17:24:01 +0000 (-0500) Subject: Cleanup Fill_Notif_Args a bit (and other stuff too) X-Git-Tag: xonotic-v0.7.0~62^2~23^2~219 X-Git-Url: https://git.rm.cloudns.org/?a=commitdiff_plain;h=986ab1d84e4223098be92f6df4d68771d35939fa;p=xonotic%2Fxonotic-data.pk3dir.git Cleanup Fill_Notif_Args a bit (and other stuff too) --- diff --git a/qcsrc/common/notifications.qc b/qcsrc/common/notifications.qc index 24cf3ff00..0f51f3524 100644 --- a/qcsrc/common/notifications.qc +++ b/qcsrc/common/notifications.qc @@ -4,72 +4,7 @@ // ================================================ #ifndef MENUQC -string arg_slot[8]; -string Fill_Notif_Args(string args, string input, - string s1, string s2, string s3, string s4, - float f1, float f2, float f3, float f4) -{ - dprint(sprintf("Fill_Notif_Args('%s', '%s', %s, %s, %s, %s, %d, %d, %d, %d);\n", - args, input, s1, s2, s3, s4, f1, f2, f3, f4)); - - string selected, remaining = args; - float sel_num = 0; - - #ifdef CSQC - string tmp_s; - #endif - - if((remaining != "") && (input != "")) - { - for(;remaining;) - { - selected = car(remaining); remaining = cdr(remaining); - - 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 - default: { print("Hit unknown token in selected string! '", selected, "'\n"); break; } - } - if(sel_num == 7) { print("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], arg_slot[7]); - } - - return ""; -} - +string arg_slot[7]; entity Get_Notif_Ent(float net_type, float net_name) { switch(net_type) @@ -144,16 +79,25 @@ 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_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_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)), - Get_Notif_Name(MSG_CENTER, Get_Notif_Cenval(MSG_WEAPON, i)))); } + 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)), + Get_Notif_Name(MSG_CENTER, Get_Notif_Cenval(MSG_WEAPON, i)) ) ); } - for(i = 0; i < NOTIF_DEATH_COUNT; ++i) { e = Get_Notif_Ent(MSG_DEATH, i); NOTIF_WRITE(MSG_DEATH, e.nent_name, sprintf("infoname: %s, centername: %s", - Get_Notif_Name(MSG_INFO, Get_Notif_Infval(MSG_DEATH, i)), - Get_Notif_Name(MSG_CENTER, Get_Notif_Cenval(MSG_DEATH, i)))); } + for(i = 0; i < NOTIF_DEATH_COUNT; ++i) { + e = Get_Notif_Ent(MSG_DEATH, i); + NOTIF_WRITE(MSG_DEATH, e.nent_name, sprintf("infoname: %s, centername: %s", + Get_Notif_Name(MSG_INFO, Get_Notif_Infval(MSG_DEATH, i)), + Get_Notif_Name(MSG_CENTER, Get_Notif_Cenval(MSG_DEATH, i)) ) ); } #endif @@ -189,6 +133,77 @@ void HUD_Notify_Push(string icon, string attacker, string victim) } #endif // ifdef CSQC + +string Local_Notification_sprintf(string input, string args, + string s1, string s2, string s3, string s4, + float f1, float f2, float f3, float f4) +{ + #ifdef NOTIFICATIONS_DEBUG + dprint( + sprintf("Local_Notification_sprintf('%s', '%s', %s, %s);\n", + input, args, + sprintf("%s, %s, %s, %s", s1, s2, s3, s4), + sprintf("%d, %d, %d, %d", f1, f2, f3, f4))); + #endif + + string selected, remaining = args; + float sel_num = 0; + + #ifdef CSQC + string tmp_s; + #endif + + if((remaining != "") && (input != "")) + { + for(;remaining;) + { + selected = car(remaining); remaining = cdr(remaining); + + 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 + default: { backtrace(sprintf("Hit unknown token in selected string! '%s'\n", selected)); break; } + } + if(sel_num == 6) { 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]); + } + + return ""; +} + void Local_Notification(float net_type, float net_name, ...count) { // check supplied type and name for errors @@ -246,7 +261,7 @@ void Local_Notification(float net_type, float net_name, ...count) { case MSG_INFO: { - print(Fill_Notif_Args(notif.nent_args, notif.nent_string, + print(Local_Notification_sprintf(notif.nent_string, notif.nent_args, s1, s2, s3, s4, f1, f2, f3, f4)); #ifdef CSQC @@ -259,7 +274,7 @@ void Local_Notification(float net_type, float net_name, ...count) case MSG_CENTER: { centerprint_generic(notif.nent_cpid, - Fill_Notif_Args(notif.nent_args, notif.nent_string, + Local_Notification_sprintf(notif.nent_string, notif.nent_args, s1, s2, s3, s4, f1, f2, f3, f4), 0, 0); break; } @@ -327,7 +342,7 @@ void Read_Notification(float is_new) float f4 = ((floatcount == 4) ? ReadLong() : NO_FL_ARG); #ifdef NOTIFICATIONS_DEBUG - dprint(sprintf("Read_Notification(%d) at %f: net_name = %s.\n", is_new, time, Get_Notif_Name(net_type, net_name))); + dprint(sprintf("Read_Notification(%d) at %f: net_name = %s.\n", is_new, time, Get_Notif_Name(net_type, net_name))); #endif if(is_new) { Local_Notification_Without_VarArgs(net_type, net_name, stringcount, floatcount, s1, s2, s3, s4, f1, f2, f3, f4); }