]> git.rm.cloudns.org Git - xonotic/xonotic-data.pk3dir.git/commitdiff
Put more work into process_time function
authorSamual Lenks <samual@xonotic.org>
Sun, 3 Mar 2013 05:53:23 +0000 (00:53 -0500)
committerSamual Lenks <samual@xonotic.org>
Sun, 3 Mar 2013 05:53:23 +0000 (00:53 -0500)
qcsrc/common/notifications.qh
qcsrc/common/util.qc
qcsrc/common/util.qh
qcsrc/server/command/common.qc

index 69949bafa9432ca2f65ec7095af0909c902741af..0753a83f302f439090e30ef0efa17244c2061b51 100644 (file)
@@ -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"))) \
index 10b76ba95639657d39e8c9f338c45a6866a52200..a7a7d59822be2d3bc2aaf2fd83e52051b7efa89c 100644 (file)
@@ -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 "";
 }
 
index 2eebd1b8d59c0ef9225da4782b8b29db115151f5..eb2713864d7d62e146dafa5829c4665b39c1b6a4 100644 (file)
@@ -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);
index 69c8e2e166e6d86c72585e3dae1a1742844dbf28..14e6dad62f468c7fe98017368511d0aa2789e5c2 100644 (file)
@@ -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));