From: Samual Lenks Date: Tue, 20 Aug 2013 22:57:05 +0000 (-0400) Subject: Mostly integrate MSG_CHOICE into initialization function X-Git-Tag: xonotic-v0.8.0~341^2~33 X-Git-Url: https://git.rm.cloudns.org/?a=commitdiff_plain;h=256e19674648dffc7e05539bee3fa3453bf568bd;p=xonotic%2Fxonotic-data.pk3dir.git Mostly integrate MSG_CHOICE into initialization function --- diff --git a/qcsrc/common/notifications.qc b/qcsrc/common/notifications.qc index 512b98836..6ede8250a 100644 --- a/qcsrc/common/notifications.qc +++ b/qcsrc/common/notifications.qc @@ -12,6 +12,7 @@ string Get_Notif_TypeName(float net_type) case MSG_CENTER: return "MSG_CENTER"; case MSG_CENTER_CPID: return "MSG_CENTER_CPID"; case MSG_MULTI: return "MSG_MULTI"; + case MSG_CHOICE: return "MSG_CHOICE"; } backtrace(sprintf("Get_Notif_TypeName(%d): Improper net type!\n", net_type)); return ""; @@ -25,6 +26,7 @@ entity Get_Notif_Ent(float net_type, float net_name) case MSG_INFO: return msg_info_notifs[net_name - 1]; case MSG_CENTER: return msg_center_notifs[net_name - 1]; case MSG_MULTI: return msg_multi_notifs[net_name - 1]; + case MSG_CHOICE: return msg_choice_notifs[net_name - 1]; } backtrace(sprintf("Get_Notif_Ent(%d, %d): Improper net type!\n", net_type, net_name)); return world; @@ -43,6 +45,7 @@ string Notification_CheckArgs_TypeName(float net_type, float net_name) CHECKARG_TYPENAME(INFO) CHECKARG_TYPENAME(CENTER) CHECKARG_TYPENAME(MULTI) + CHECKARG_TYPENAME(CHOICE) default: { checkargs = sprintf("Improper type: %d!", checkargs, net_type); break; } } #undef CHECKARG_TYPENAME @@ -141,20 +144,21 @@ void Destroy_All_Notifications(void) DESTROY_LOOP(MSG_INFO, NOTIF_INFO_COUNT) DESTROY_LOOP(MSG_CENTER, NOTIF_CENTER_COUNT) DESTROY_LOOP(MSG_MULTI, NOTIF_MULTI_COUNT) + DESTROY_LOOP(MSG_CHOICE, NOTIF_CHOICE_COUNT) #undef DESTROY_LOOP } string Process_Notif_Line( - float msg_is_info, + float typeid, float chat, string input, string notiftype, string notifname, string stringtype) { - if(msg_is_info) + #ifdef CSQC + if(typeid == MSG_INFO) { - #ifdef CSQC if((chat && autocvar_notification_allow_chatboxprint) || (autocvar_notification_allow_chatboxprint == 2)) { @@ -169,22 +173,25 @@ string Process_Notif_Line( if(substring(input, (strlen(input) - 1), 1) == "\{3}") { input = substring(input, 0, (strlen(input) - 1)); } } - #endif - if(substring(input, (strlen(input) - 1), 1) == "\n") - { - print(sprintf( - strcat( - "^1TRAILING NEW LINE AT END OF NOTIFICATION: ", - "^7net_type = %s, net_name = %s, string = %s.\n" - ), - notiftype, - notifname, - stringtype - )); - notif_error = TRUE; - return substring(input, 1, (strlen(input) - 1)); - } } + #endif + + // done to both MSG_INFO and MSG_CENTER + if(substring(input, (strlen(input) - 1), 1) == "\n") + { + print(sprintf( + strcat( + "^1TRAILING NEW LINE AT END OF NOTIFICATION: ", + "^7net_type = %s, net_name = %s, string = %s.\n" + ), + notiftype, + notifname, + stringtype + )); + notif_error = TRUE; + input = substring(input, 1, (strlen(input) - 1)); + } + return input; } @@ -360,8 +367,9 @@ void Create_Notification_Entity( string durcnt, string normal, string gentle, - float msg_is_info, - float msg_is_multi) + float chtype, + float optiona, + float optionb) { // ===================== // Global Entity Setup @@ -395,7 +403,14 @@ void Create_Notification_Entity( { typestring = "MSG_MULTI"; msg_multi_notifs[nameid - 1] = notif; - notif.classname = "MSG_MULTI_notification"; + notif.classname = "msg_multi_notification"; + break; + } + case MSG_CHOICE: + { + typestring = "MSG_CHOICE"; + msg_choice_notifs[nameid - 1] = notif; + notif.classname = "msg_choice_notification"; break; } @@ -423,147 +438,124 @@ void Create_Notification_Entity( // ==================== // Notification Setup // ==================== - if(msg_is_multi) - { - // Set MSG_MULTI string/float counts - if((anncename == NO_MSG) && (infoname == NO_MSG) && (centername == NO_MSG)) - { - print(sprintf( - strcat( - "^1NOTIFICATION WITH NO SUBCALLS: ", - "^7net_type = %s, net_name = %s.\n" - ), - typestring, - namestring - )); - notif_error = TRUE; - } - else - { - // announcements don't actually need any arguments, so lets not even count them. - if(anncename != NO_MSG) { notif.nent_msgannce = msg_annce_notifs[anncename - 1]; } - - float infoname_stringcount = 0, infoname_floatcount = 0; - float centername_stringcount = 0, centername_floatcount = 0; - - if(infoname != NO_MSG) - { - notif.nent_msginfo = msg_info_notifs[infoname - 1]; - infoname_stringcount = notif.nent_msginfo.nent_stringcount; - infoname_floatcount = notif.nent_msginfo.nent_floatcount; - } - - if(centername != NO_MSG) - { - notif.nent_msgcenter = msg_center_notifs[centername - 1]; - centername_stringcount = notif.nent_msgcenter.nent_stringcount; - centername_floatcount = notif.nent_msgcenter.nent_floatcount; - } - - // set the requirements of THIS notification to the totals of its subcalls - notif.nent_stringcount = max(infoname_stringcount, centername_stringcount); - notif.nent_floatcount = max(infoname_floatcount, centername_floatcount); - } - } - else if(typeid == MSG_ANNCE) - { - // Set MSG_ANNCE information and handle precaching - #ifdef CSQC - if not(GENTLE && (var_cvar == 1)) - { - if(snd != "") - { - if(notif.nent_enabled) - { - precache_sound(sprintf("announcer/%s/%s.wav", autocvar_cl_announcer, snd)); - notif.nent_channel = channel; - notif.nent_snd = strzone(snd); - notif.nent_vol = vol; - notif.nent_position = position; - } - } - else - { - print(sprintf( - strcat( - "^1NOTIFICATION WITH NO SOUND: ", - "^7net_type = %s, net_name = %s.\n" - ), - typestring, - namestring - )); - notif_error = TRUE; - } - } - else { notif.nent_enabled = FALSE; } - #else - notif.nent_enabled = FALSE; - #endif - } - else + switch(typeid) { - // Set MSG_INFO and MSG_CENTER string/float counts - notif.nent_stringcount = strnum; - notif.nent_floatcount = flnum; - - // Only initialize arguments if we're either a client or on a dedicated server - #ifdef SVQC - float should_process_args = server_is_dedicated; - #else - float should_process_args = TRUE; - #endif - - if(should_process_args) + case MSG_ANNCE: { - // ======================== - // Process Main Arguments - // ======================== - if(strnum + flnum) + // Set MSG_ANNCE information and handle precaching + #ifdef CSQC + if not(GENTLE && (var_cvar == 1)) { - if(args != "") + if(snd != "") { - notif.nent_args = strzone( - Process_Notif_Args(1, args, typestring, namestring)); + if(notif.nent_enabled) + { + precache_sound(sprintf("announcer/%s/%s.wav", autocvar_cl_announcer, snd)); + notif.nent_channel = channel; + notif.nent_snd = strzone(snd); + notif.nent_vol = vol; + notif.nent_position = position; + } } - else if((hudargs == "") && (durcnt =="")) + else { print(sprintf( strcat( - "^1NOTIFICATION HAS ARG COUNTS BUT NO ARGS OR HUDARGS OR DURCNT: ", - "^7net_type = %s, net_name = %s, strnum = %d, flnum = %d\n" + "^1NOTIFICATION WITH NO SOUND: ", + "^7net_type = %s, net_name = %s.\n" ), typestring, - namestring, - strnum, - flnum + namestring )); notif_error = TRUE; } } - else if(args != "") - { - notif.nent_args = strzone( - Process_Notif_Args(1, args, typestring, namestring)); - } + else { notif.nent_enabled = FALSE; } + #else + notif.nent_enabled = FALSE; + #endif + break; + } + + case MSG_INFO: + case MSG_CENTER: + { + // Set MSG_INFO and MSG_CENTER string/float counts + notif.nent_stringcount = strnum; + notif.nent_floatcount = flnum; - // ======================================= - // Process HUD and Centerprint Arguments - // Only processed on CSQC, as these - // args are only for HUD features. - // ======================================= - #ifdef CSQC - if(hudargs != "") + // Only initialize arguments if we're either a client or on a dedicated server + #ifdef SVQC + float should_process_args = server_is_dedicated; + #else + float should_process_args = TRUE; + #endif + + if(should_process_args) { - notif.nent_hudargs = strzone( - Process_Notif_Args(2, hudargs, typestring, namestring)); - - if(icon != "") { notif.nent_icon = strzone(icon); } - else + // ======================== + // Process Main Arguments + // ======================== + if(strnum + flnum) + { + if(args != "") + { + notif.nent_args = strzone( + Process_Notif_Args(1, args, typestring, namestring)); + } + else if((hudargs == "") && (durcnt =="")) + { + print(sprintf( + strcat( + "^1NOTIFICATION HAS ARG COUNTS BUT NO ARGS OR HUDARGS OR DURCNT: ", + "^7net_type = %s, net_name = %s, strnum = %d, flnum = %d\n" + ), + typestring, + namestring, + strnum, + flnum + )); + notif_error = TRUE; + } + } + else if(args != "") + { + notif.nent_args = strzone( + Process_Notif_Args(1, args, typestring, namestring)); + } + + + // ======================================= + // Process HUD and Centerprint Arguments + // Only processed on CSQC, as these + // args are only for HUD features. + // ======================================= + #ifdef CSQC + if(hudargs != "") + { + notif.nent_hudargs = strzone( + Process_Notif_Args(2, hudargs, typestring, namestring)); + + if(icon != "") { notif.nent_icon = strzone(icon); } + else + { + print(sprintf( + strcat( + "^1NOTIFICATION HAS HUDARGS BUT NO ICON: ", + "^7net_type = %s, net_name = %s.\n" + ), + typestring, + namestring + )); + notif_error = TRUE; + } + } + else if(icon != "") { print(sprintf( strcat( - "^1NOTIFICATION HAS HUDARGS BUT NO ICON: ", + "^1NOTIFICATION HAS ICON BUT NO HUDARGS: ", "^7net_type = %s, net_name = %s.\n" ), typestring, @@ -571,31 +563,60 @@ void Create_Notification_Entity( )); notif_error = TRUE; } - } - else if(icon != "") - { - print(sprintf( - strcat( - "^1NOTIFICATION HAS ICON BUT NO HUDARGS: ", - "^7net_type = %s, net_name = %s.\n" - ), - typestring, - namestring - )); - notif_error = TRUE; - } - if(durcnt != "") - { - notif.nent_durcnt = strzone( - Process_Notif_Args(3, durcnt, typestring, namestring)); - - if(cpid != NO_MSG) { notif.nent_cpid = cpid; } - else + if(durcnt != "") + { + notif.nent_durcnt = strzone( + Process_Notif_Args(3, durcnt, typestring, namestring)); + + if(cpid != NO_MSG) { notif.nent_cpid = cpid; } + else + { + print(sprintf( + strcat( + "^1NOTIFICATION HAS DURCNT BUT NO CPID: ", + "^7net_type = %s, net_name = %s.\n" + ), + typestring, + namestring + )); + notif_error = TRUE; + } + } + else if(cpid != NO_MSG) { notif.nent_cpid = cpid; } + #endif + + + // ====================== + // Process Notif String + // ====================== + #define SET_NOTIF_STRING(string,stringname) \ + notif.nent_string = strzone(CCR( \ + Process_Notif_Line( \ + typeid, \ + (var_cvar > 1), \ + string, \ + typestring, \ + namestring, \ + stringname \ + )) \ + ); + + if(GENTLE) + { + if(gentle != "") { SET_NOTIF_STRING(gentle, "GENTLE") } + else if(normal != "") { SET_NOTIF_STRING(normal, "NORMAL") } + } + else if(normal != "") { SET_NOTIF_STRING(normal, "NORMAL") } + + #undef SET_NOTIF_STRING + + // Check to make sure a string was chosen + if(notif.nent_string == "") { print(sprintf( strcat( - "^1NOTIFICATION HAS DURCNT BUT NO CPID: ", + "^1EMPTY NOTIFICATION: ", "^7net_type = %s, net_name = %s.\n" ), typestring, @@ -603,41 +624,19 @@ void Create_Notification_Entity( )); notif_error = TRUE; } - } - else if(cpid != NO_MSG) { notif.nent_cpid = cpid; } - #endif - - - // ====================== - // Process Notif String - // ====================== - #define SET_NOTIF_STRING(string,stringname) \ - notif.nent_string = strzone(CCR( \ - Process_Notif_Line( \ - msg_is_info, \ - (var_cvar > 1), \ - string, \ - typestring, \ - namestring, \ - stringname \ - )) \ - ); - - if(GENTLE) - { - if(gentle != "") { SET_NOTIF_STRING(gentle, "GENTLE") } - else if(normal != "") { SET_NOTIF_STRING(normal, "NORMAL") } } - else if(normal != "") { SET_NOTIF_STRING(normal, "NORMAL") } - - #undef SET_NOTIF_STRING - // Check to make sure a string was chosen - if(notif.nent_string == "") + break; + } + + case MSG_MULTI: + { + // Set MSG_MULTI string/float counts + if((anncename == NO_MSG) && (infoname == NO_MSG) && (centername == NO_MSG)) { print(sprintf( strcat( - "^1EMPTY NOTIFICATION: ", + "^1NOTIFICATION WITH NO SUBCALLS: ", "^7net_type = %s, net_name = %s.\n" ), typestring, @@ -645,7 +644,42 @@ void Create_Notification_Entity( )); notif_error = TRUE; } + else + { + // announcements don't actually need any arguments, so lets not even count them. + if(anncename != NO_MSG) { notif.nent_msgannce = msg_annce_notifs[anncename - 1]; } + + float infoname_stringcount = 0, infoname_floatcount = 0; + float centername_stringcount = 0, centername_floatcount = 0; + + if(infoname != NO_MSG) + { + notif.nent_msginfo = msg_info_notifs[infoname - 1]; + infoname_stringcount = notif.nent_msginfo.nent_stringcount; + infoname_floatcount = notif.nent_msginfo.nent_floatcount; + } + + if(centername != NO_MSG) + { + notif.nent_msgcenter = msg_center_notifs[centername - 1]; + centername_stringcount = notif.nent_msgcenter.nent_stringcount; + centername_floatcount = notif.nent_msgcenter.nent_floatcount; + } + + // set the requirements of THIS notification to the totals of its subcalls + notif.nent_stringcount = max(infoname_stringcount, centername_stringcount); + notif.nent_floatcount = max(infoname_floatcount, centername_floatcount); + } + + break; } + + case MSG_CHOICE: + { + break; + } + + default: print("DAFUQ?\n"); notif_error = TRUE; break; } // now check to see if any errors happened diff --git a/qcsrc/common/notifications.qh b/qcsrc/common/notifications.qh index e4a8f69a0..9e3b007d5 100644 --- a/qcsrc/common/notifications.qh +++ b/qcsrc/common/notifications.qh @@ -62,8 +62,9 @@ void Create_Notification_Entity( string durcnt, string normal, string gentle, - float msg_is_info, - float msg_is_multi); + float chtype, + float optiona, + float optionb); void Dump_Notifications(float fh, float alsoprint); @@ -572,7 +573,6 @@ void Send_Notification_WOVA( MSG_CENTER_NOTIF(1, CENTER_TIMEOUT_BEGINNING, 0, 1, "", CPID_TIMEOUT, "1 f1", _("^F4Timeout begins in ^COUNT"), "") \ MSG_CENTER_NOTIF(1, CENTER_TIMEOUT_ENDING, 0, 1, "", CPID_TIMEOUT, "1 f1", _("^F4Timeout ends in ^COUNT"), "") - #define MULTITEAM_MULTI(default,prefix,teams,anncepre,infopre,centerpre) \ MSG_MULTI_NOTIF(default, prefix##RED, anncepre##RED, infopre##RED, centerpre##RED) \ MSG_MULTI_NOTIF(default, prefix##BLUE, anncepre##BLUE, infopre##BLUE, centerpre##BLUE) \ @@ -705,21 +705,21 @@ void Send_Notification_WOVA( MSG_MULTI_NOTIF(1, WEAPON_UZI_MURDER_SNIPE, NO_MSG, INFO_WEAPON_UZI_MURDER_SNIPE, NO_MSG) \ MSG_MULTI_NOTIF(1, WEAPON_UZI_MURDER_SPRAY, NO_MSG, INFO_WEAPON_UZI_MURDER_SPRAY, NO_MSG) -#define MULTITEAM_CHOICE(default,prefix,teams,type,opa,opb) \ - MSG_CHOICE_NOTIF(default, prefix##RED, type, opa##RED, opb##RED) \ - MSG_CHOICE_NOTIF(default, prefix##BLUE, type, opa##BLUE, opb##BLUE) \ +#define MULTITEAM_CHOICE(default,prefix,teams,chtype,optiona,optionb) \ + MSG_CHOICE_NOTIF(default, prefix##RED, chtype, optiona##RED, optionb##RED) \ + MSG_CHOICE_NOTIF(default, prefix##BLUE, chtype, optiona##BLUE, optionb##BLUE) \ #if teams >= 3 \ - MSG_CHOICE_NOTIF(default, prefix##YELLOW, type, opa##YELLOW, opb##YELLOW) \ + MSG_CHOICE_NOTIF(default, prefix##YELLOW, chtype, optiona##YELLOW, optionb##YELLOW) \ #endif \ #if teams >= 4 \ - MSG_CHOICE_NOTIF(default, prefix##PINK, type, opa##PINK, opb##PINK) \ + MSG_CHOICE_NOTIF(default, prefix##PINK, chtype, optiona##PINK, optionb##PINK) \ #endif #define MSG_CHOICE_NOTIFICATIONS \ MSG_CHOICE_NOTIF(1, CHOICE_FRAG, MSG_CENTER, CENTER_DEATH_MURDER_FRAG, CENTER_DEATH_MURDER_FRAG_VERBOSE) \ MSG_CHOICE_NOTIF(1, CHOICE_FRAGGED, MSG_CENTER, CENTER_DEATH_MURDER_FRAGGED, CENTER_DEATH_MURDER_FRAGGED_VERBOSE) \ MSG_CHOICE_NOTIF(1, CHOICE_TYPEFRAG, MSG_CENTER, CENTER_DEATH_MURDER_TYPEFRAG, CENTER_DEATH_MURDER_TYPEFRAG_VERBOSE) \ - MSG_CHOICE_NOTIF(1, CHOICE_TYPERFRAGGED, MSG_CENTER, CENTER_DEATH_MURDER_TYPEFRAGGED, CENTER_DEATH_MURDER_TYPEFRAGGED_VERBOSE) \ - MSG_CHOICE_NOTIF(2, CHOICE_) + MSG_CHOICE_NOTIF(1, CHOICE_TYPERFRAGGED, MSG_CENTER, CENTER_DEATH_MURDER_TYPEFRAGGED, CENTER_DEATH_MURDER_TYPEFRAGGED_VERBOSE) + //MSG_CHOICE_NOTIF(2, CHOICE_) // =========================== @@ -1076,12 +1076,14 @@ entity msg_annce_notifs[NOTIF_MAX]; entity msg_info_notifs[NOTIF_MAX]; entity msg_center_notifs[NOTIF_MAX]; entity msg_multi_notifs[NOTIF_MAX]; +entity msg_choice_notifs[NOTIF_MAX]; // notification counts float NOTIF_ANNCE_COUNT; float NOTIF_INFO_COUNT; float NOTIF_CENTER_COUNT; float NOTIF_MULTI_COUNT; +float NOTIF_CHOICE_COUNT; float NOTIF_CPID_COUNT; // notification entity values @@ -1105,6 +1107,9 @@ float NOTIF_CPID_COUNT; .string nent_durcnt; .string nent_string; +.string nent_msgopa; +.string nent_msgopb; + // networked notification values .float nent_broadcast; .entity nent_client; @@ -1142,8 +1147,9 @@ float NOTIF_CPID_COUNT; "", /* durcnt */ \ "", /* normal */ \ "", /* gentle */ \ - FALSE, /* msg_is_info */ \ - FALSE); /* msg_is_multi */ \ + NO_MSG, /* chtype */ \ + NO_MSG, /* optiona */ \ + NO_MSG); /* optionb */ \ } \ ACCUMULATE_FUNCTION(RegisterNotifications, RegisterNotification_##name) @@ -1176,8 +1182,9 @@ float NOTIF_CPID_COUNT; "", /* durcnt */ \ normal, /* normal */ \ gentle, /* gentle */ \ - TRUE, /* msg_is_info */ \ - FALSE); /* msg_is_multi */ \ + NO_MSG, /* chtype */ \ + NO_MSG, /* optiona */ \ + NO_MSG); /* optionb */ \ } \ ACCUMULATE_FUNCTION(RegisterNotifications, RegisterNotification_##name) @@ -1212,8 +1219,9 @@ float NOTIF_CPID_COUNT; durcnt, /* durcnt */ \ normal, /* normal */ \ gentle, /* gentle */ \ - FALSE, /* msg_is_info */ \ - FALSE); /* msg_is_multi */ \ + NO_MSG, /* chtype */ \ + NO_MSG, /* optiona */ \ + NO_MSG); /* optionb */ \ } \ ACCUMULATE_FUNCTION(RegisterNotifications, RegisterNotification_##name) @@ -1246,8 +1254,44 @@ float NOTIF_CPID_COUNT; "", /* durcnt */ \ "", /* normal */ \ "", /* gentle */ \ - FALSE, /* msg_is_info */ \ - TRUE); /* msg_is_multi */ \ + NO_MSG, /* chtype */ \ + NO_MSG, /* optiona */ \ + NO_MSG); /* optionb */ \ + } \ + ACCUMULATE_FUNCTION(RegisterNotifications, RegisterNotification_##name) + +#define MSG_CHOICE_NOTIF(default,name,chtype,optiona,optionb) \ + NOTIF_ADD_AUTOCVAR(name, default) \ + float name; \ + void RegisterNotification_##name() \ + { \ + SET_FIELD_COUNT(name, NOTIF_FIRST, NOTIF_CHOICE_COUNT) \ + CHECK_MAX_COUNT(name, NOTIF_MAX, NOTIF_CHOICE_COUNT, "notifications") \ + Create_Notification_Entity( \ + default, /* var_default */ \ + autocvar_notification_##name, /* var_cvar */ \ + MSG_CHOICE, /* typeid */ \ + name, /* nameid */ \ + strtoupper(#name), /* namestring */ \ + NO_MSG, /* anncename */ \ + NO_MSG, /* infoname */ \ + NO_MSG, /* centername */ \ + NO_MSG, /* channel */ \ + "", /* snd */ \ + NO_MSG, /* vol */ \ + NO_MSG, /* position */ \ + NO_MSG, /* strnum */ \ + NO_MSG, /* flnum */ \ + "", /* args */ \ + "", /* hudargs */ \ + "", /* icon */ \ + NO_MSG, /* cpid */ \ + "", /* durcnt */ \ + "", /* normal */ \ + "", /* gentle */ \ + chtype, /* chtype */ \ + optiona, /* optiona */ \ + optionb); /* optionb */ \ } \ ACCUMULATE_FUNCTION(RegisterNotifications, RegisterNotification_##name) @@ -1297,10 +1341,12 @@ MSG_ANNCE_NOTIFICATIONS MSG_INFO_NOTIFICATIONS MSG_CENTER_NOTIFICATIONS MSG_MULTI_NOTIFICATIONS +MSG_CHOICE_NOTIFICATIONS ACCUMULATE_FUNCTION(RegisterNotifications, RegisterNotifications_Done) #undef MSG_ANNCE_NOTIF #undef MSG_INFO_NOTIF #undef MSG_CENTER_NOTIF #undef MSG_MULTI_NOTIF +#undef MSG_CHOICE_NOTIF #undef NOTIF_ADD_AUTOCVAR