From: Samual Lenks Date: Thu, 21 Feb 2013 23:41:25 +0000 (-0500) Subject: Fix the check for hudargs, fix dumpnotifs command, add done function X-Git-Tag: xonotic-v0.7.0~62^2~23^2~185 X-Git-Url: https://git.rm.cloudns.org/?a=commitdiff_plain;h=9c6aaa71d5d6dc8e1d19936e0098e45d9313c233;p=xonotic%2Fxonotic-data.pk3dir.git Fix the check for hudargs, fix dumpnotifs command, add done function --- diff --git a/qcsrc/common/notifications.qc b/qcsrc/common/notifications.qc index 126aa2a91..6230e2174 100644 --- a/qcsrc/common/notifications.qc +++ b/qcsrc/common/notifications.qc @@ -68,24 +68,28 @@ void Dump_Notifications(float fh, float alsoprint) // it is just a semi-helpful tool for those who want to manually change their user settings. NOTIF_WRITE(sprintf("\n// MSG_INFO notifications (count = %d):\n", NOTIF_INFO_COUNT), ""); - for(i = 0; i < NOTIF_INFO_COUNT; ++i) { + for(i = 0; i <= NOTIF_INFO_COUNT; ++i) { e = Get_Notif_Ent(MSG_INFO, i); + if not(e) { backtrace("Dump_Notifications(): Missing notification entity!\n"); return; } NOTIF_WRITE_SETA(e.nent_name, e.nent_default, e.nent_string); } NOTIF_WRITE(sprintf("\n// MSG_CENTER notifications (count = %d):\n", NOTIF_CENTER_COUNT), ""); - for(i = 0; i < NOTIF_CENTER_COUNT; ++i) { + for(i = 0; i <= NOTIF_CENTER_COUNT; ++i) { e = Get_Notif_Ent(MSG_CENTER, i); + if not(e) { backtrace("Dump_Notifications(): Missing notification entity!\n"); return; } NOTIF_WRITE_SETA(e.nent_name, e.nent_default, e.nent_string); } NOTIF_WRITE(sprintf("\n// MSG_WEAPON notifications (count = %d):\n", NOTIF_WEAPON_COUNT), ""); - for(i = 0; i < NOTIF_WEAPON_COUNT; ++i) { + for(i = 0; i <= NOTIF_WEAPON_COUNT; ++i) { e = Get_Notif_Ent(MSG_WEAPON, i); + if not(e) { backtrace("Dump_Notifications(): Missing notification entity!\n"); return; } NOTIF_WRITE_SETA(e.nent_name, e.nent_default, sprintf("infoname: %s, centername: %s", e.nent_msginfo.nent_name, e.nent_msgcenter.nent_name)); } NOTIF_WRITE(sprintf("\n// MSG_DEATH notifications (count = %d):\n", NOTIF_DEATH_COUNT), ""); - for(i = 0; i < NOTIF_DEATH_COUNT; ++i) { + for(i = 0; i <= NOTIF_DEATH_COUNT; ++i) { e = Get_Notif_Ent(MSG_DEATH, i); + if not(e) { backtrace("Dump_Notifications(): Missing notification entity!\n"); return; } NOTIF_WRITE_SETA(e.nent_name, e.nent_default, sprintf("infoname: %s, centername: %s", e.nent_msginfo.nent_name, e.nent_msgcenter.nent_name)); } @@ -137,11 +141,11 @@ string Local_Notification_sprintf(string input, string args, { #define ARG_CASE(prog,selected,result) \ #ifdef CSQC \ - #if (prog == ARG_BOTH) || (prog == ARG_TRIPLE) || (prog == ARG_CSQC) \ + #if (prog == ARG_DOUBLE) || (prog == ARG_TRIPLE) || (prog == ARG_CSQC) \ case selected: { arg_slot[sel_num] = result; ++sel_num; break; } \ #endif \ #else \ - #if (prog == ARG_BOTH) || (prog == ARG_TRIPLE) || (prog == ARG_SVQC) \ + #if (prog == ARG_DOUBLE) || (prog == ARG_TRIPLE) || (prog == ARG_SVQC) \ case selected: { arg_slot[sel_num] = result; ++sel_num; break; } \ #endif \ #endif diff --git a/qcsrc/common/notifications.qh b/qcsrc/common/notifications.qh index 66c1dd360..147795db1 100644 --- a/qcsrc/common/notifications.qh +++ b/qcsrc/common/notifications.qh @@ -15,6 +15,9 @@ // or any time you change default values or add/edit/remove a special cvar. #define NOTIF_VERSION 1 +#define NOTIF_FIRST 1 +#define NOTIF_MAX 1024 // limit of recursive functions with ACCUMULATE_FUNCTION + #define NO_MSG -12345 // ping of bots defined for extra frag message notification information @@ -46,48 +49,6 @@ 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_TRIPLE 2 // also included with hudargs -#define ARG_CSQC 3 -#define ARG_SVQC 4 - -#define NOTIF_MAX_ARGS 7 -#define NOTIF_MAX_HUDARGS 2 - -#define NOTIF_HIT_MAX(count,funcname) if(sel_num == count) { backtrace(sprintf("%s: Hit maximum arguments!\n", funcname)); break; } -#define NOTIF_HIT_UNKNOWN(token,funcname) default: { backtrace(sprintf("%s: Hit unknown token in selected string! '%s'\n", funcname, selected)); break; } - -#define NOTIF_ARGUMENT_LIST \ - ARG_CASE(ARG_TRIPLE, "s1", s1) \ - ARG_CASE(ARG_TRIPLE, "s2", s2) \ - ARG_CASE(ARG_TRIPLE, "s3", s3) \ - ARG_CASE(ARG_TRIPLE, "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_BOTH, "f1p2dec", ftos_decimals(f1/100, 2)) \ - ARG_CASE(ARG_BOTH, "f2p2dec", ftos_decimals(f2/100, 2)) \ - 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 arg_slot[NOTIF_MAX_ARGS]; - void Dump_Notifications(float fh, float alsoprint); void Local_Notification(float net_type, float net_name, ...count); @@ -248,7 +209,7 @@ void Send_CSQC_Centerprint_Generic_Expire(entity e, float id); MSG_INFO_NOTIF(1, INFO_DEATH_SELF_TURRET_MLRS, 1, 1, "s1 spree_end", "s1", "notify_death", _("^BG%s^K1 got turned into smoldering gibs by an MLRS turret%s\n"), "") \ MSG_INFO_NOTIF(1, INFO_DEATH_SELF_TURRET_PLASMA, 1, 1, "s1 spree_end", "s1", "notify_death", _("^BG%s^K1 got served some superheated plasma from a turret%s\n"), "") \ MSG_INFO_NOTIF(1, INFO_DEATH_SELF_TURRET_PHASER, 1, 1, "s1 spree_end", "s1", "notify_death", _("^BG%s^K1 was phased out by a turret%s\n"), "") \ - MSG_INFO_NOTIF(1, INFO_DEATH_SELF_TURRET_TESLA, 1, 1, "s1 spree_end", "s1", "notify_death", _("^BG%s^K1 was electrocuted by a Tesla turret%s\n"), "") \ + MSG_INFO_NOTIF(1, INFO_DEATH_SELF_TURRET_TESLA, 1, 1, "s1 spree_end", "s1", "notify_death", _("^BG%s^K1 was electrocuted by a Tesla turret%s\n"), "") \ MSG_INFO_NOTIF(1, INFO_DEATH_MURDER_TELEFRAG, 2, 1, "s1 s2 spree_end", "s2 s1", "notify_telefrag", _("^BG%s^K1 was telefragged by ^BG%s^K1%s\n"), _("^F1%s^K1 tried to occupy ^BG%s^K1's teleport destination space\n")) \ MSG_INFO_NOTIF(1, INFO_DEATH_MURDER_FALL, 2, 1, "s1 s2 spree_end", "s2 s1", "notify_fall", _("^BG%s^K1 was grounded by ^BG%s^K1%s\n"), "") \ MSG_INFO_NOTIF(1, INFO_DEATH_MURDER_DROWN, 2, 1, "s1 s2 spree_end", "s2 s1", "notify_water", _("^BG%s^K1 was drowned by ^BG%s^K1%s\n"), "") \ @@ -299,10 +260,10 @@ void Send_CSQC_Centerprint_Generic_Expire(entity e, float id); MSG_INFO_NOTIF(1, INFO_QUIT_KICK_IDLING, 1, 0, "s1", "s1", "", _("^BG%s^F3 was kicked for idling\n"), "") \ MSG_INFO_NOTIF(1, INFO_QUIT_KICK_SPECTATING, 0, 0, "", "", "", _("^F2You were kicked from the server because you are a spectator and spectators aren't allowed at the moment.\n"), "") \ MSG_INFO_NOTIF(1, INFO_QUIT_SPECTATE, 1, 0, "s1", "s1", "", _("^BG%s^F3 is now spectating\n"), "") \ - MSG_INFO_NOTIF(1, INFO_RACE_FAIL, 2, 0, "s1 s2", "s1", "race_newfail", "", "") \ - MSG_INFO_NOTIF(1, INFO_RACE_NEW_RECORD, 2, 0, "s1 s2", "s1", "race_newrecordserver", "", "") \ - MSG_INFO_NOTIF(1, INFO_RACE_NEW_TIME, 2, 0, "s1 s2", "s1", "race_newtime", "", "") \ - MSG_INFO_NOTIF(1, INFO_RACE_NEW_RANK, 2, 0, "s1 s2", "s1", "race_newrankyellow", "", "") \ + MSG_INFO_NOTIF(1, INFO_RACE_FAIL, 2, 0, "s1 s2", "s1", "race_newfail", "TODO\n", "") \ + MSG_INFO_NOTIF(1, INFO_RACE_NEW_RECORD, 2, 0, "s1 s2", "s1", "race_newrecordserver", "TODO\n", "") \ + MSG_INFO_NOTIF(1, INFO_RACE_NEW_TIME, 2, 0, "s1 s2", "s1", "race_newtime", "TODO\n", "") \ + MSG_INFO_NOTIF(1, INFO_RACE_NEW_RANK, 2, 0, "s1 s2", "s1", "race_newrankyellow", "TODO\n", "") \ MULTITEAM_INFO(1, INFO_SCORES_, 4, 0, 0, "", "", "", _("^TC^TT ^BGteam scores!\n"), "") \ MSG_INFO_NOTIF(1, INFO_SPECTATE_WARNING, 0, 1, "f1", "", "", _("^F2You have to become a player within the next %s seconds, otherwise you will be kicked, because spectating isn't allowed at this time!\n"), "") \ MSG_INFO_NOTIF(1, INFO_SUPERWEAPON_BROKEN, 0, 0, "", "", "", _("^F2Superweapons have broken down\n"), "") \ @@ -591,8 +552,45 @@ void Send_CSQC_Centerprint_Generic_Expire(entity e, float id); // Initialization/Create Declarations // ==================================== -#define NOTIF_FIRST 1 -#define NOTIF_MAX 1024 // limit of recursive functions with ACCUMULATE_FUNCTION +#define ARG_DOUBLE 1 +#define ARG_TRIPLE 2 // also included with hudargs +#define ARG_CSQC 3 +#define ARG_SVQC 4 + +#define NOTIF_MAX_ARGS 7 +#define NOTIF_MAX_HUDARGS 2 + +#define NOTIF_HIT_MAX(count,funcname) if(sel_num == count) { backtrace(sprintf("%s: Hit maximum arguments!\n", funcname)); break; } +#define NOTIF_HIT_UNKNOWN(token,funcname) default: { backtrace(sprintf("%s: Hit unknown token in selected string! '%s'\n", funcname, selected)); break; } + +#define NOTIF_ARGUMENT_LIST \ + ARG_CASE(ARG_TRIPLE, "s1", s1) \ + ARG_CASE(ARG_TRIPLE, "s2", s2) \ + ARG_CASE(ARG_TRIPLE, "s3", s3) \ + ARG_CASE(ARG_TRIPLE, "s4", s4) \ + ARG_CASE(ARG_DOUBLE, "f1", ftos(f1)) \ + ARG_CASE(ARG_DOUBLE, "f2", ftos(f2)) \ + ARG_CASE(ARG_DOUBLE, "f3", ftos(f3)) \ + ARG_CASE(ARG_DOUBLE, "f4", ftos(f4)) \ + ARG_CASE(ARG_DOUBLE, "f1p2dec", ftos_decimals(f1/100, 2)) \ + ARG_CASE(ARG_DOUBLE, "f2p2dec", ftos_decimals(f2/100, 2)) \ + 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, "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)) + +string arg_slot[NOTIF_MAX_ARGS]; + var float notif_error = FALSE; // an error has occurred in this specific notification var float notif_global_error = FALSE; // an error has occurred in the notification system @@ -643,6 +641,7 @@ string Process_Notif_Line(float check_newline, string input, string notiftype, s } return input; } + string Process_Notif_Args(float is_hudargs, string args, string notiftype, string notifname) { string selected, remaining = args; @@ -663,7 +662,12 @@ string Process_Notif_Args(float is_hudargs, string args, string notiftype, strin switch(strtolower(selected)) { - #define ARG_CASE(prog,selected,result) case selected: { ++sel_num; break; } + #define ARG_CASE(prog,selected,result) \ + #if (prog == ARG_TRIPLE) \ + case selected: { ++sel_num; break; } \ + #else \ + case selected: { if(!is_hudargs) { ++sel_num; break; } } \ + #endif NOTIF_ARGUMENT_LIST #undef ARG_CASE default: @@ -678,7 +682,6 @@ string Process_Notif_Args(float is_hudargs, string args, string notiftype, strin return args; } -#define ADD_AUTOCVAR(name,default) var float autocvar_notification_##name = default; #define CREATE_NOTIF_ENTITY(default,type,name,infoname,centername,strnum,flnum,args,hudargs,icon,cpid,durcnt,normal,gentle,check_newline,subcalls) \ notif_error = FALSE; \ @@ -727,7 +730,9 @@ string Process_Notif_Args(float is_hudargs, string args, string notiftype, strin notif.nent_enabled = FALSE; \ notif_global_error = TRUE; \ } - + +#define ADD_AUTOCVAR(name,default) var float autocvar_notification_##name = default; + #define MSG_INFO_NOTIF(default,name,strnum,flnum,args,hudargs,icon,normal,gentle) \ ADD_AUTOCVAR(name, default) \ float name; \ @@ -838,12 +843,22 @@ string Process_Notif_Args(float is_hudargs, string args, string notiftype, strin } \ ACCUMULATE_FUNCTION(RegisterNotifications, RegisterNotification_##name) +var float autocvar_notification_errors_are_fatal = TRUE; +void RegisterNotifications_Done() +{ + if(notif_global_error && autocvar_notification_errors_are_fatal) + { + // shit happened- stop the loading of the program + error("Notification initialization failed!"); + } +} + // NOW we actually activate the declarations MSG_INFO_NOTIFICATIONS MSG_CENTER_NOTIFICATIONS MSG_WEAPON_NOTIFICATIONS MSG_DEATH_NOTIFICATIONS -//ACCUMULATE_FUNCTION(RegisterNotifications, RegisterNotification_Done) +ACCUMULATE_FUNCTION(RegisterNotifications, RegisterNotifications_Done) #undef MSG_INFO_NOTIF #undef MSG_CENTER_NOTIF #undef MSG_WEAPON_NOTIF