Xonotic QuakeC
The free, fast arena FPS with crisp movement and a wide array of weapons
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)
#define count_days(time)
#define count_days_decs(time, decs)
#define count_hours(time)
#define count_hours_decs(time, decs)
#define count_minutes(time)
#define count_minutes_decs(time, decs)
#define count_seconds(time)
#define count_seconds_decs(time, decs)
#define count_weeks(time)
#define count_weeks_decs(time, decs)
#define count_years(time)
#define count_years_decs(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)
Value:
if (tmp_##unit) \
output = strcat(output, ((output != "") ? ", " : ""), count_##unit(tmp_##unit))
strcat(_("^F4Countdown stopped!"), "\n^BG", _("Teams are too unbalanced."))

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 */
ERASEABLE string count_fill(float interval, string zeroth, string first, string second, string third, string multi)
Definition counting.qh:87
float time

Definition at line 28 of file counting.qh.

28#define count_days(time) \
29 count_fill(time, \
30 _("CI_ZER^%d days"), /* zeroth */ \
31 _("CI_FIR^%d day"), /* first */ \
32 _("CI_SEC^%d days"), /* day */ \
33 _("CI_THI^%d days"), /* third */ \
34 _("CI_MUL^%d days")) /* multi */

Referenced by formatStringSpecial(), and process_time().

◆ count_days_decs

#define count_days_decs ( time,
decs )
Value:
sprintf(CTX(_("CI_DEC^%s days")), ftos_decimals(time, decs))
ERASEABLE string CTX(string s)
Definition i18n.qh:46
ERASEABLE string ftos_decimals(float number, int decimals)
Converts a number to a string with the indicated number of decimals.
Definition string.qh:476

Definition at line 27 of file counting.qh.

Referenced by formatStringSpecial().

◆ 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 */

Definition at line 37 of file counting.qh.

37#define count_hours(time) \
38 count_fill(time, \
39 _("CI_ZER^%d hours"), /* zeroth */ \
40 _("CI_FIR^%d hour"), /* first */ \
41 _("CI_SEC^%d hours"), /* hour */ \
42 _("CI_THI^%d hours"), /* third */ \
43 _("CI_MUL^%d hours")) /* multi */

Referenced by formatStringSpecial(), and process_time().

◆ count_hours_decs

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

Definition at line 36 of file counting.qh.

Referenced by formatStringSpecial().

◆ 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 */

Definition at line 47 of file counting.qh.

47#define count_minutes(time) \
48 count_fill(time, \
49 _("CI_ZER^%d minutes"), /* zeroth */ \
50 _("CI_FIR^%d minute"), /* first */ \
51 _("CI_SEC^%d minutes"), /* minute */ \
52 _("CI_THI^%d minutes"), /* third */ \
53 _("CI_MUL^%d minutes")) /* multi */

Referenced by formatStringSpecial(), and Scoreboard_Draw().

◆ count_minutes_decs

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

Definition at line 46 of file counting.qh.

Referenced by formatStringSpecial().

◆ 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 */

Definition at line 56 of file counting.qh.

56#define count_seconds(time) \
57 count_fill(time, \
58 _("CI_ZER^%d seconds"), /* zeroth */ \
59 _("CI_FIR^%d second"), /* first */ \
60 _("CI_SEC^%d seconds"), /* second */ \
61 _("CI_THI^%d seconds"), /* third */ \
62 _("CI_MUL^%d seconds")) /* multi */

Referenced by formatStringSpecial(), MapVote_Draw(), process_time(), and Scoreboard_Draw().

◆ count_seconds_decs

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

Definition at line 55 of file counting.qh.

Referenced by formatStringSpecial(), and Scoreboard_Draw().

◆ 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 */

Definition at line 19 of file counting.qh.

19#define count_weeks(time) \
20 count_fill(time, \
21 _("CI_ZER^%d weeks"), /* zeroth */ \
22 _("CI_FIR^%d week"), /* first */ \
23 _("CI_SEC^%d weeks"), /* week */ \
24 _("CI_THI^%d weeks"), /* third */ \
25 _("CI_MUL^%d weeks")) /* multi */

Referenced by formatStringSpecial().

◆ count_weeks_decs

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

Definition at line 18 of file counting.qh.

Referenced by formatStringSpecial().

◆ 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 */

Definition at line 10 of file counting.qh.

10#define count_years(time) \
11 count_fill(time, \
12 _("CI_ZER^%d years"), /* zeroth */ \
13 _("CI_FIR^%d year"), /* first */ \
14 _("CI_SEC^%d years"), /* year */ \
15 _("CI_THI^%d years"), /* third */ \
16 _("CI_MUL^%d years")) /* multi */

Referenced by formatStringSpecial().

◆ count_years_decs

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

Definition at line 9 of file counting.qh.

Referenced by formatStringSpecial().

Function Documentation

◆ count_fill()

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

Definition at line 87 of file counting.qh.

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

References CTX(), and floor().

◆ count_ordinal()

ERASEABLE string count_ordinal ( int interval)

Definition at line 66 of file counting.qh.

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 switch (last2digits % 10)
77 {
78 case 1: return sprintf(_("%dst"), interval);
79 case 2: return sprintf(_("%dnd"), interval);
80 case 3: return sprintf(_("%drd"), interval);
81 }
82
83 return sprintf(_("%dth"), interval);
84}

Referenced by getladder(), getrankings(), HUD_Mod_Race(), Scoreboard_Rankings_Draw(), and ScoreString().

◆ process_time()

ERASEABLE string process_time ( float outputtype,
int seconds )

Definition at line 117 of file counting.qh.

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

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

Referenced by CommonCommand_who(), WinningCondition_Assault(), and XonoticStatsList_getStats().