From e2d5ab1348e707e3dd01663974d70a69b416bd24 Mon Sep 17 00:00:00 2001 From: Samual Lenks Date: Sun, 3 Mar 2013 00:53:23 -0500 Subject: [PATCH] Put more work into process_time function --- qcsrc/common/notifications.qh | 4 +- qcsrc/common/util.qc | 101 +++++++++++++++++++++++++-------- qcsrc/common/util.qh | 39 +++++++++++-- qcsrc/server/command/common.qc | 2 +- 4 files changed, 114 insertions(+), 32 deletions(-) diff --git a/qcsrc/common/notifications.qh b/qcsrc/common/notifications.qh index 69949bafa..0753a83f3 100644 --- a/qcsrc/common/notifications.qh +++ b/qcsrc/common/notifications.qh @@ -457,7 +457,7 @@ void Send_Notification_WOVA( MSG_CENTER_NOTIF(1, CENTER_NIX_NEWWEAPON, 0, 1, "item_wepname", CPID_NIX, "0 0", _("^F2Active weapon: ^F1%s"), "") \ MSG_CENTER_NOTIF(1, CENTER_JOIN_NOSPAWNS, 0, 0, "", CPID_PREVENT_JOIN, "0 0", _("^K1No spawnpoints available!\nHope your team can fix it..."), "") \ MSG_CENTER_NOTIF(1, CENTER_JOIN_PREVENT, 0, 0, "", CPID_PREVENT_JOIN, "0 0", _("^K1You may not join the game at this time.\nThe player limit reached maximum capacity."), "") \ - MSG_CENTER_NOTIF(1, CENTER_OVERTIME_TIME, 0, 1, "f1time", CPID_OVERTIME, "0 0", _("^F2Now playing ^F4OVERTIME^F2!\nAdded ^F4%s ^F2minute(s) to the game!"), "") \ + MSG_CENTER_NOTIF(1, CENTER_OVERTIME_TIME, 0, 1, "f1time", CPID_OVERTIME, "0 0", _("^F2Now playing ^F4OVERTIME^F2!\nAdded ^F4%s ^F2to the game!"), "") \ MSG_CENTER_NOTIF(1, CENTER_OVERTIME_FRAG, 0, 0, "", CPID_OVERTIME, "0 0", _("^F2Now playing ^F4OVERTIME^F2!\nKeep fragging until we have a winner!"), _("^F2Now playing ^F4OVERTIME^F2!\nKeep scoring until we have a winner!")) \ MSG_CENTER_NOTIF(1, CENTER_POWERDOWN_INVISIBILITY, 0, 0, "", CPID_POWERUP, "0 0", _("^F2Invisibility has worn off"), "") \ MSG_CENTER_NOTIF(1, CENTER_POWERDOWN_SHIELD, 0, 0, "", CPID_POWERUP, "0 0", _("^F2Shield has worn off"), "") \ @@ -710,7 +710,7 @@ string arg_slot[NOTIF_MAX_ARGS]; ARG_CASE(ARG_CS, "f3primsec", (f3 ? _("secondary") : _("primary"))) \ ARG_CASE(ARG_CS, "f1secs", count_seconds(f1)) \ ARG_CASE(ARG_CS_SV, "f1ord", count_ordinal(f1)) \ - ARG_CASE(ARG_CS, "f1time", process_time("todo", f1)) \ + ARG_CASE(ARG_CS, "f1time", process_time(2, f1)) \ ARG_CASE(ARG_CS_SV, "f1race_time", mmssss(f1)) \ ARG_CASE(ARG_CS_SV, "f2race_time", mmssss(f2)) \ ARG_CASE(ARG_CS_SV, "race_col", CCR(((f1 == 1) ? "^F1" : "^F2"))) \ diff --git a/qcsrc/common/util.qc b/qcsrc/common/util.qc index 10b76ba95..a7a7d5982 100644 --- a/qcsrc/common/util.qc +++ b/qcsrc/common/util.qc @@ -2670,7 +2670,7 @@ string count_fill(float interval, string zeroth, string first, string second, st return ""; } -string process_time(string fields, float seconds) +string process_time(float outputtype, float seconds) { float tmp_hours = 0, tmp_minutes = 0, tmp_seconds = 0; float tmp_years = 0, tmp_weeks = 0, tmp_days = 0; @@ -2678,33 +2678,86 @@ string process_time(string fields, float seconds) tmp_seconds = floor(seconds); if(tmp_seconds) - { tmp_minutes = floor(tmp_seconds / 60); } - - if(tmp_minutes) - { tmp_seconds -= (tmp_minutes * 60); - tmp_hours = floor(tmp_minutes / 60); } - - if(tmp_hours) - { tmp_minutes -= (tmp_hours * 60); } - - if(tmp_hours) - { tmp_days = floor(tmp_hours / 24); } + { + tmp_minutes = floor(tmp_seconds / 60); + + if(tmp_minutes) + { + tmp_seconds -= (tmp_minutes * 60); + tmp_hours = floor(tmp_minutes / 60); - if(tmp_days) - { tmp_hours -= (tmp_days * 60); - tmp_weeks = floor(tmp_days / 7); } - - if(tmp_weeks) - { tmp_days -= (tmp_weeks * 60); - tmp_years = floor(tmp_weeks / 52); } + if(tmp_hours) + { + tmp_minutes -= (tmp_hours * 60); + tmp_days = floor(tmp_hours / 24); + + if(tmp_days) + { + tmp_hours -= (tmp_days * 24); + tmp_weeks = floor(tmp_days / 7); + + if(tmp_weeks) + { + tmp_days -= (tmp_weeks * 7); + tmp_years = floor(tmp_weeks / 52); + } + } + } + } + } - //fields = strreplace(" - /*switch(output) + switch(outputtype) { case 1: return sprintf("%02d:%02d:%02d", tmp_hours, tmp_minutes, tmp_seconds); - //todo - default: return ""; - }*/ + case 2: + { + string output = ""; + + output = count_seconds(tmp_seconds); + + if(tmp_minutes) + { + output = sprintf( + "%s%s", + count_minutes(tmp_minutes), + ((output != "") ? sprintf(", %s", output) : "")); + } + + if(tmp_hours) + { + output = sprintf( + "%s%s", + count_hours(tmp_hours), + ((output != "") ? sprintf(", %s", output) : "")); + } + + if(tmp_days) + { + output = sprintf( + "%s%s", + count_days(tmp_days), + ((output != "") ? sprintf(", %s", output) : "")); + } + + if(tmp_weeks) + { + output = sprintf( + "%s%s", + count_weeks(tmp_weeks), + ((output != "") ? sprintf(", %s", output) : "")); + } + + if(tmp_years) + { + output = sprintf( + "%s%s", + count_years(tmp_years), + ((output != "") ? sprintf(", %s", output) : "")); + } + + return output; + } + } return ""; } diff --git a/qcsrc/common/util.qh b/qcsrc/common/util.qh index 2eebd1b8d..eb2713864 100644 --- a/qcsrc/common/util.qh +++ b/qcsrc/common/util.qh @@ -422,8 +422,40 @@ vector vec3(float x, float y, float z); vector animfixfps(entity e, vector a, vector b); #endif -#define count_minutes_decs(time,decs) sprintf(ZCTX(_("CI_DEC^%s minutes")), ftos_decimals(time, decs)) +#define count_years_decs(time,decs) sprintf(ZCTX(_("CI_DEC^%s years")), ftos_decimals(time, decs)) +#define count_years(time) count_fill(time, \ + ZCTX(_("CI_ZER^%d years")), /* zeroth */ \ + ZCTX(_("CI_FIR^%d year")), /* first */ \ + ZCTX(_("CI_SEC^%d years")), /* year */ \ + ZCTX(_("CI_THI^%d years")), /* third */ \ + ZCTX(_("CI_MUL^%d years"))) /* multi */ + +#define count_weeks_decs(time,decs) sprintf(ZCTX(_("CI_DEC^%s weeks")), ftos_decimals(time, decs)) +#define count_weeks(time) count_fill(time, \ + ZCTX(_("CI_ZER^%d weeks")), /* zeroth */ \ + ZCTX(_("CI_FIR^%d week")), /* first */ \ + ZCTX(_("CI_SEC^%d weeks")), /* week */ \ + ZCTX(_("CI_THI^%d weeks")), /* third */ \ + ZCTX(_("CI_MUL^%d weeks"))) /* multi */ + +#define count_days_decs(time,decs) sprintf(ZCTX(_("CI_DEC^%s days")), ftos_decimals(time, decs)) +#define count_days(time) count_fill(time, \ + ZCTX(_("CI_ZER^%d days")), /* zeroth */ \ + ZCTX(_("CI_FIR^%d day")), /* first */ \ + ZCTX(_("CI_SEC^%d days")), /* day */ \ + ZCTX(_("CI_THI^%d days")), /* third */ \ + ZCTX(_("CI_MUL^%d days"))) /* multi */ + +#define count_hours_decs(time,decs) sprintf(ZCTX(_("CI_DEC^%s hours")), ftos_decimals(time, decs)) +#define count_hours(time) count_fill(time, \ + ZCTX(_("CI_ZER^%d hours")), /* zeroth */ \ + ZCTX(_("CI_FIR^%d hour")), /* first */ \ + ZCTX(_("CI_SEC^%d hours")), /* hour */ \ + ZCTX(_("CI_THI^%d hours")), /* third */ \ + ZCTX(_("CI_MUL^%d hours"))) /* multi */ + +#define count_minutes_decs(time,decs) sprintf(ZCTX(_("CI_DEC^%s minutes")), ftos_decimals(time, decs)) #define count_minutes(time) count_fill(time, \ ZCTX(_("CI_ZER^%d minutes")), /* zeroth */ \ ZCTX(_("CI_FIR^%d minute")), /* first */ \ @@ -432,7 +464,6 @@ vector animfixfps(entity e, vector a, vector b); ZCTX(_("CI_MUL^%d minutes"))) /* multi */ #define count_seconds_decs(time,decs) sprintf(ZCTX(_("CI_DEC^%s seconds")), ftos_decimals(time, decs)) - #define count_seconds(time) count_fill(time, \ ZCTX(_("CI_ZER^%d seconds")), /* zeroth */ \ ZCTX(_("CI_FIR^%d second")), /* first */ \ @@ -441,10 +472,8 @@ vector animfixfps(entity e, vector a, vector b); ZCTX(_("CI_MUL^%d seconds"))) /* multi */ string count_ordinal(float interval); - string count_fill(float interval, string zeroth, string first, string second, string third, string multi); - -string process_time(string fields, float seconds); +string process_time(float outputtype, float seconds); #ifdef SVQC void dedicated_print(string input); diff --git a/qcsrc/server/command/common.qc b/qcsrc/server/command/common.qc index 69c8e2e16..14e6dad62 100644 --- a/qcsrc/server/command/common.qc +++ b/qcsrc/server/command/common.qc @@ -636,7 +636,7 @@ void CommonCommand_who(float request, entity caller, float argc) tmp_player.netname, tmp_player.ping, tmp_player.ping_packetloss, - process_time("%02d:%02d:%02d", time - tmp_player.jointime), + process_time(2, time - tmp_player.jointime), tmp_netaddress, tmp_crypto_idfp)); -- 2.39.2