Xonotic
counting.qh File Reference
#include "i18n.qh"
+ Include dependency graph for counting.qh:
+ This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Macros

#define APPEND_TIME(unit)   if (tmp_##unit) output = strcat(output, ((output != "") ? ", " : ""), count_##unit(tmp_##unit))
 
#define count_days(time)
 
#define count_days_decs(time, decs)   sprintf(CTX(_("CI_DEC^%s days")), ftos_decimals(time, decs))
 
#define count_hours(time)
 
#define count_hours_decs(time, decs)   sprintf(CTX(_("CI_DEC^%s hours")), ftos_decimals(time, decs))
 
#define count_minutes(time)
 
#define count_minutes_decs(time, decs)   sprintf(CTX(_("CI_DEC^%s minutes")), ftos_decimals(time, decs))
 
#define count_seconds(time)
 
#define count_seconds_decs(time, decs)   sprintf(CTX(_("CI_DEC^%s seconds")), ftos_decimals(time, decs))
 
#define count_weeks(time)
 
#define count_weeks_decs(time, decs)   sprintf(CTX(_("CI_DEC^%s weeks")), ftos_decimals(time, decs))
 
#define count_years(time)
 
#define count_years_decs(time, decs)   sprintf(CTX(_("CI_DEC^%s years")), ftos_decimals(time, decs))
 

Functions

ERASEABLE string count_fill (float interval, string zeroth, string first, string second, string third, string multi)
 
ERASEABLE string count_ordinal (int interval)
 
ERASEABLE string process_time (float outputtype, int seconds)
 

Macro Definition Documentation

◆ APPEND_TIME

#define APPEND_TIME (   unit)    if (tmp_##unit) output = strcat(output, ((output != "") ? ", " : ""), count_##unit(tmp_##unit))

Referenced by process_time().

◆ count_days

#define count_days (   time)
Value:
_("CI_ZER^%d days"), /* zeroth */ \
_("CI_FIR^%d day"), /* first */ \
_("CI_SEC^%d days"), /* day */ \
_("CI_THI^%d days"), /* third */ \
_("CI_MUL^%d days")) /* multi */
float time
Definition: csprogsdefs.qc:16
ERASEABLE string count_fill(float interval, string zeroth, string first, string second, string third, string multi)
Definition: counting.qh:89

Definition at line 28 of file counting.qh.

Referenced by process_time().

◆ count_days_decs

#define count_days_decs (   time,
  decs 
)    sprintf(CTX(_("CI_DEC^%s days")), ftos_decimals(time, decs))

Definition at line 27 of file counting.qh.

◆ count_hours

#define count_hours (   time)
Value:
_("CI_ZER^%d hours"), /* zeroth */ \
_("CI_FIR^%d hour"), /* first */ \
_("CI_SEC^%d hours"), /* hour */ \
_("CI_THI^%d hours"), /* third */ \
_("CI_MUL^%d hours")) /* multi */
float time
Definition: csprogsdefs.qc:16
ERASEABLE string count_fill(float interval, string zeroth, string first, string second, string third, string multi)
Definition: counting.qh:89

Definition at line 37 of file counting.qh.

Referenced by process_time().

◆ count_hours_decs

#define count_hours_decs (   time,
  decs 
)    sprintf(CTX(_("CI_DEC^%s hours")), ftos_decimals(time, decs))

Definition at line 36 of file counting.qh.

◆ count_minutes

#define count_minutes (   time)
Value:
_("CI_ZER^%d minutes"), /* zeroth */ \
_("CI_FIR^%d minute"), /* first */ \
_("CI_SEC^%d minutes"), /* minute */ \
_("CI_THI^%d minutes"), /* third */ \
_("CI_MUL^%d minutes")) /* multi */
float time
Definition: csprogsdefs.qc:16
ERASEABLE string count_fill(float interval, string zeroth, string first, string second, string third, string multi)
Definition: counting.qh:89

Definition at line 47 of file counting.qh.

◆ count_minutes_decs

#define count_minutes_decs (   time,
  decs 
)    sprintf(CTX(_("CI_DEC^%s minutes")), ftos_decimals(time, decs))

Definition at line 46 of file counting.qh.

◆ count_seconds

#define count_seconds (   time)
Value:
_("CI_ZER^%d seconds"), /* zeroth */ \
_("CI_FIR^%d second"), /* first */ \
_("CI_SEC^%d seconds"), /* second */ \
_("CI_THI^%d seconds"), /* third */ \
_("CI_MUL^%d seconds")) /* multi */
float time
Definition: csprogsdefs.qc:16
ERASEABLE string count_fill(float interval, string zeroth, string first, string second, string third, string multi)
Definition: counting.qh:89

Definition at line 56 of file counting.qh.

Referenced by process_time().

◆ count_seconds_decs

#define count_seconds_decs (   time,
  decs 
)    sprintf(CTX(_("CI_DEC^%s seconds")), ftos_decimals(time, decs))

Definition at line 55 of file counting.qh.

◆ count_weeks

#define count_weeks (   time)
Value:
_("CI_ZER^%d weeks"), /* zeroth */ \
_("CI_FIR^%d week"), /* first */ \
_("CI_SEC^%d weeks"), /* week */ \
_("CI_THI^%d weeks"), /* third */ \
_("CI_MUL^%d weeks")) /* multi */
float time
Definition: csprogsdefs.qc:16
ERASEABLE string count_fill(float interval, string zeroth, string first, string second, string third, string multi)
Definition: counting.qh:89

Definition at line 19 of file counting.qh.

◆ count_weeks_decs

#define count_weeks_decs (   time,
  decs 
)    sprintf(CTX(_("CI_DEC^%s weeks")), ftos_decimals(time, decs))

Definition at line 18 of file counting.qh.

◆ count_years

#define count_years (   time)
Value:
_("CI_ZER^%d years"), /* zeroth */ \
_("CI_FIR^%d year"), /* first */ \
_("CI_SEC^%d years"), /* year */ \
_("CI_THI^%d years"), /* third */ \
_("CI_MUL^%d years")) /* multi */
float time
Definition: csprogsdefs.qc:16
ERASEABLE string count_fill(float interval, string zeroth, string first, string second, string third, string multi)
Definition: counting.qh:89

Definition at line 10 of file counting.qh.

◆ count_years_decs

#define count_years_decs (   time,
  decs 
)    sprintf(CTX(_("CI_DEC^%s years")), ftos_decimals(time, decs))

Definition at line 9 of file counting.qh.

Function Documentation

◆ count_fill()

ERASEABLE string count_fill ( float  interval,
string  zeroth,
string  first,
string  second,
string  third,
string  multi 
)

Definition at line 89 of file counting.qh.

References CTX(), ERASEABLE, and floor().

90 {
91  // This function is designed primarily for the English language, it's impossible
92  // to accomodate all languages unless we do a specific function for each one...
93  // and since that's not technically feasible/practical, this is all we've got folks.
94 
95  // Here you can insert specific strings based on the interval number, so you could do
96  // i.e. count_seconds which outputs like this:
97  // 0 seconds
98  // 1 second
99  // 2 seconds
100  // 3 seconds
101  // etc... minutes, hours, days, etc.
102 
103  switch (floor(interval))
104  {
105  case 0: return sprintf(CTX(zeroth), interval);
106  case 1:
107  {
108  if (interval == 1) // EXACTLY value of 1
109  return sprintf(CTX(first), interval);
110  else return sprintf(CTX(multi), interval);
111  }
112  case 2: return sprintf(CTX(second), interval);
113  case 3: return sprintf(CTX(third), interval);
114  default: return sprintf(CTX(multi), interval);
115  }
116  return "";
117 }
ERASEABLE string CTX(string s)
Definition: i18n.qh:45
+ Here is the call graph for this function:

◆ count_ordinal()

ERASEABLE string count_ordinal ( int  interval)

Definition at line 66 of file counting.qh.

Referenced by depthfirst(), getladder(), getrankings(), and Scoreboard_Rankings_Draw().

67 {
68  // This function is designed primarily for the English language, it's impossible
69  // to accomodate all languages unless we do a specific function for each one...
70  // and since that's not technically feasible/practical, this is all we've got folks.
71 
72  int last2digits = interval % 100;
73 
74  // numbers ending with 11, 12 and 13 don't follow the standard pattern
75  if (last2digits < 4 || last2digits > 20)
76  {
77  switch (last2digits % 10)
78  {
79  case 1: return sprintf(_("%dst"), interval);
80  case 2: return sprintf(_("%dnd"), interval);
81  case 3: return sprintf(_("%drd"), interval);
82  }
83  }
84 
85  return sprintf(_("%dth"), interval);
86 }
+ Here is the caller graph for this function:

◆ process_time()

ERASEABLE string process_time ( float  outputtype,
int  seconds 
)

Definition at line 120 of file counting.qh.

References APPEND_TIME, count_days, count_hours, count_seconds, floor(), and strcat().

Referenced by CommonCommand_who(), and WinningCondition_Assault().

121 {
122  int tmp_hours = 0, tmp_minutes = 0, tmp_seconds = 0;
123  int tmp_years = 0, tmp_weeks = 0, tmp_days = 0;
124 
125  tmp_seconds = floor(seconds);
126 
127  if (tmp_seconds)
128  {
129  tmp_minutes = floor(tmp_seconds / 60);
130 
131  if (tmp_minutes)
132  {
133  tmp_seconds -= (tmp_minutes * 60);
134  tmp_hours = floor(tmp_minutes / 60);
135 
136  if (tmp_hours)
137  {
138  tmp_minutes -= (tmp_hours * 60);
139  tmp_days = floor(tmp_hours / 24);
140 
141  if (tmp_days)
142  {
143  tmp_hours -= (tmp_days * 24);
144  tmp_weeks = floor(tmp_days / 7);
145 
146  if (tmp_weeks)
147  {
148  tmp_days -= (tmp_weeks * 7);
149  tmp_years = floor(tmp_weeks / 52);
150  }
151  }
152  }
153  }
154  }
155 
156  switch (outputtype)
157  {
158  case 1: return sprintf("%02d:%02d:%02d", tmp_hours, tmp_minutes, tmp_seconds);
159  case 2:
160  {
161  string output = "";
162  #define APPEND_TIME(unit) \
163  if (tmp_##unit) output = strcat(output, ((output != "") ? ", " : ""), count_##unit(tmp_##unit))
164  APPEND_TIME(years);
165  APPEND_TIME(weeks);
166  APPEND_TIME(days);
167  APPEND_TIME(hours);
168  APPEND_TIME(minutes);
169  APPEND_TIME(seconds);
170  #undef APPEND_TIME
171  if (output == "")
172  return count_seconds(0);
173  return output;
174  }
175  case 3:
176  {
177  string output = "";
178 
179  output = count_hours(tmp_hours);
180 
181  if (tmp_weeks) tmp_days += (tmp_weeks * 7);
182  if (tmp_years) tmp_days += (tmp_years * 365);
183  if (tmp_days)
184  {
185  output = sprintf(
186  count_days(tmp_days),
187  ((output != "") ? strcat(", ", output) : ""));
188  }
189 
190  return output;
191  }
192  }
193  return "";
194 }
#define count_hours(time)
Definition: counting.qh:37
#define count_days(time)
Definition: counting.qh:28
spree_cen s1 spree_cen s1 spree_cen s1 spree_cen s1 spree_cen s1 spree_cen s1 spree_cen s1 f1 s1 strcat(_("Level %s: "), "^BG%s\3\, _("^BGPress ^F2%s^BG to enter the game"))
#define count_seconds(time)
Definition: counting.qh:56
#define APPEND_TIME(unit)
+ Here is the call graph for this function:
+ Here is the caller graph for this function: