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_bullets(num)
#define count_cells(num)
#define count_days(time)
#define count_days_decs(time, decs)
#define count_hours(time)
#define count_hours_decs(time, decs)
#define count_matches(num)
#define count_minutes(time)
#define count_minutes_decs(time, decs)
#define count_points(num)
#define count_points_decs(time, decs)
#define count_results(num)
#define count_rockets(num)
#define count_seconds(time)
#define count_seconds_decs(time, decs)
#define count_shells(num)
#define count_votes(num)
#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 num, string zero, string one, string two, string three, string multi)
ERASEABLE string count_ordinal (int num)
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_bullets

#define count_bullets ( num)
Value:
count_fill(num, \
_("ZER^%d bullets"), \
_("ONE^%d bullet"), \
_("TWO^%d bullets"), \
_("THR^%d bullets"), \
_("MUL^%d bullets"))
ERASEABLE string count_fill(float num, string zero, string one, string two, string three, string multi)
Definition counting.qh:153

Definition at line 17 of file counting.qh.

17#define count_bullets(num) \
18 count_fill(num, \
19 _("ZER^%d bullets"), \
20 _("ONE^%d bullet"), \
21 _("TWO^%d bullets"), \
22 _("THR^%d bullets"), \
23 _("MUL^%d bullets"))

Referenced by count_ammo().

◆ count_cells

#define count_cells ( num)
Value:
count_fill(num, \
_("ZER^%d cells"), \
_("ONE^%d cell"), \
_("TWO^%d cells"), \
_("THR^%d cells"), \
_("MUL^%d cells"))

Definition at line 33 of file counting.qh.

33#define count_cells(num) \
34 count_fill(num, \
35 _("ZER^%d cells"), \
36 _("ONE^%d cell"), \
37 _("TWO^%d cells"), \
38 _("THR^%d cells"), \
39 _("MUL^%d cells"))

Referenced by count_ammo().

◆ count_days

#define count_days ( time)
Value:
_("ZER^%d days"), \
_("ONE^%d day"), \
_("TWO^%d days"), \
_("THR^%d days"), \
_("MUL^%d days"))
float time

Definition at line 95 of file counting.qh.

95#define count_days(time) \
96 count_fill(time, \
97 _("ZER^%d days"), \
98 _("ONE^%d day"), \
99 _("TWO^%d days"), \
100 _("THR^%d days"), \
101 _("MUL^%d days"))

Referenced by formatStringSpecial(), and process_time().

◆ count_days_decs

#define count_days_decs ( time,
decs )
Value:
sprintf(CTX(_("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 94 of file counting.qh.

Referenced by formatStringSpecial().

◆ count_hours

#define count_hours ( time)
Value:
_("ZER^%d hours"), \
_("ONE^%d hour"), \
_("TWO^%d hours"), \
_("THR^%d hours"), \
_("MUL^%d hours"))

Definition at line 104 of file counting.qh.

104#define count_hours(time) \
105 count_fill(time, \
106 _("ZER^%d hours"), \
107 _("ONE^%d hour"), \
108 _("TWO^%d hours"), \
109 _("THR^%d hours"), \
110 _("MUL^%d hours"))

Referenced by formatStringSpecial(), and process_time().

◆ count_hours_decs

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

Definition at line 103 of file counting.qh.

Referenced by formatStringSpecial().

◆ count_matches

#define count_matches ( num)
Value:
count_fill(num, \
_("ZER^%d matches"), \
_("ONE^%d match"), \
_("TWO^%d matches"), \
_("THR^%d matches"), \
_("MUL^%d matches"))

Definition at line 50 of file counting.qh.

50#define count_matches(num) \
51 count_fill(num, \
52 _("ZER^%d matches"), \
53 _("ONE^%d match"), \
54 _("TWO^%d matches"), \
55 _("THR^%d matches"), \
56 _("MUL^%d matches"))

Referenced by XonoticStatsList_getStats().

◆ count_minutes

#define count_minutes ( time)
Value:
_("ZER^%d minutes"), \
_("ONE^%d minute"), \
_("TWO^%d minutes"), \
_("THR^%d minutes"), \
_("MUL^%d minutes"))

Definition at line 113 of file counting.qh.

113#define count_minutes(time) \
114 count_fill(time, \
115 _("ZER^%d minutes"), \
116 _("ONE^%d minute"), \
117 _("TWO^%d minutes"), \
118 _("THR^%d minutes"), \
119 _("MUL^%d minutes"))

Referenced by formatStringSpecial(), and Scoreboard_Draw().

◆ count_minutes_decs

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

Definition at line 112 of file counting.qh.

Referenced by formatStringSpecial().

◆ count_points

#define count_points ( num)
Value:
count_fill(num, \
_("ZER^%d points"), \
_("ONE^%d point"), \
_("TWO^%d points"), \
_("THR^%d points"), \
_("MUL^%d points"))

Definition at line 59 of file counting.qh.

59#define count_points(num) \
60 count_fill(num, \
61 _("ZER^%d points"), \
62 _("ONE^%d point"), \
63 _("TWO^%d points"), \
64 _("THR^%d points"), \
65 _("MUL^%d points"))

◆ count_points_decs

#define count_points_decs ( time,
decs )
Value:
sprintf(CTX(_("DEC^%s points")), ftos_decimals(time, decs))

Definition at line 58 of file counting.qh.

◆ count_results

#define count_results ( num)
Value:
count_fill(num, \
_("ZER^%d results"), \
_("ONE^%d result"), \
_("TWO^%d results"), \
_("THR^%d results"), \
_("MUL^%d results"))

Definition at line 67 of file counting.qh.

67#define count_results(num) \
68 count_fill(num, \
69 _("ZER^%d results"), \
70 _("ONE^%d result"), \
71 _("TWO^%d results"), \
72 _("THR^%d results"), \
73 _("MUL^%d results"))

Referenced by CvarList_UpdateResults().

◆ count_rockets

#define count_rockets ( num)
Value:
count_fill(num, \
_("ZER^%d rockets"), \
_("ONE^%d rocket"), \
_("TWO^%d rockets"), \
_("THR^%d rockets"), \
_("MUL^%d rockets"))

Definition at line 25 of file counting.qh.

25#define count_rockets(num) \
26 count_fill(num, \
27 _("ZER^%d rockets"), \
28 _("ONE^%d rocket"), \
29 _("TWO^%d rockets"), \
30 _("THR^%d rockets"), \
31 _("MUL^%d rockets"))

Referenced by count_ammo().

◆ count_seconds

#define count_seconds ( time)
Value:
_("ZER^%d seconds"), \
_("ONE^%d second"), \
_("TWO^%d seconds"), \
_("THR^%d seconds"), \
_("MUL^%d seconds"))

Definition at line 122 of file counting.qh.

122#define count_seconds(time) \
123 count_fill(time, \
124 _("ZER^%d seconds"), \
125 _("ONE^%d second"), \
126 _("TWO^%d seconds"), \
127 _("THR^%d seconds"), \
128 _("MUL^%d seconds"))

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

◆ count_seconds_decs

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

Definition at line 121 of file counting.qh.

Referenced by formatStringSpecial(), and Scoreboard_Draw().

◆ count_shells

#define count_shells ( num)
Value:
count_fill(num, \
_("ZER^%d shells"), \
_("ONE^%d shell"), \
_("TWO^%d shells"), \
_("THR^%d shells"), \
_("MUL^%d shells"))

Definition at line 9 of file counting.qh.

9#define count_shells(num) \
10 count_fill(num, \
11 _("ZER^%d shells"), \
12 _("ONE^%d shell"), \
13 _("TWO^%d shells"), \
14 _("THR^%d shells"), \
15 _("MUL^%d shells"))

Referenced by count_ammo().

◆ count_votes

#define count_votes ( num)
Value:
count_fill(num, \
_("ZER^%d votes"), \
_("ONE^%d vote"), \
_("TWO^%d votes"), \
_("THR^%d votes"), \
_("MUL^%d votes"))

Definition at line 42 of file counting.qh.

42#define count_votes(num) \
43 count_fill(num, \
44 _("ZER^%d votes"), \
45 _("ONE^%d vote"), \
46 _("TWO^%d votes"), \
47 _("THR^%d votes"), \
48 _("MUL^%d votes"))

Referenced by MapVote_FormatItem().

◆ count_weeks

#define count_weeks ( time)
Value:
_("ZER^%d weeks"), \
_("ONE^%d week"), \
_("TWO^%d weeks"), \
_("THR^%d weeks"), \
_("MUL^%d weeks"))

Definition at line 86 of file counting.qh.

86#define count_weeks(time) \
87 count_fill(time, \
88 _("ZER^%d weeks"), \
89 _("ONE^%d week"), \
90 _("TWO^%d weeks"), \
91 _("THR^%d weeks"), \
92 _("MUL^%d weeks"))

Referenced by formatStringSpecial().

◆ count_weeks_decs

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

Definition at line 85 of file counting.qh.

Referenced by formatStringSpecial().

◆ count_years

#define count_years ( time)
Value:
_("ZER^%d years"), \
_("ONE^%d year"), \
_("TWO^%d years"), \
_("THR^%d years"), \
_("MUL^%d years"))

Definition at line 77 of file counting.qh.

77#define count_years(time) \
78 count_fill(time, \
79 _("ZER^%d years"), \
80 _("ONE^%d year"), \
81 _("TWO^%d years"), \
82 _("THR^%d years"), \
83 _("MUL^%d years"))

Referenced by formatStringSpecial().

◆ count_years_decs

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

Definition at line 76 of file counting.qh.

Referenced by formatStringSpecial().

Function Documentation

◆ count_fill()

ERASEABLE string count_fill ( float num,
string zero,
string one,
string two,
string three,
string multi )

Definition at line 153 of file counting.qh.

154{
155 // This function is designed primarily for the English language, it's impossible
156 // to accomodate all languages unless we do a specific function for each one...
157 // and since that's not technically feasible/practical, this is all we've got folks.
158
159 // Here you can insert specific strings based on the input number, so you could do
160 // e.g. count_seconds which outputs like this:
161 // 0 seconds
162 // 1 second
163 // 2 seconds
164 // 3 seconds
165 // etc... minutes, hours, days, etc.
166
167 switch (floor(num))
168 {
169 case 0: return sprintf(CTX(zero), num);
170 case 1:
171 if (num == 1) // EXACTLY value of 1
172 return sprintf(CTX(one), num);
173 else
174 return sprintf(CTX(multi), num);
175 case 2: return sprintf(CTX(two), num);
176 case 3: return sprintf(CTX(three), num);
177 default: return sprintf(CTX(multi), num);
178 }
179 return "";
180}
float floor(float f)

References CTX(), and floor().

◆ count_ordinal()

ERASEABLE string count_ordinal ( int num)

Definition at line 132 of file counting.qh.

133{
134 // This function is designed primarily for the English language, it's impossible
135 // to accomodate all languages unless we do a specific function for each one...
136 // and since that's not technically feasible/practical, this is all we've got folks.
137
138 int last2digits = num % 100;
139
140 // numbers ending with 11, 12 and 13 don't follow the standard pattern
141 if (last2digits < 4 || last2digits > 20)
142 switch (last2digits % 10)
143 {
144 case 1: return sprintf(_("%dst"), num);
145 case 2: return sprintf(_("%dnd"), num);
146 case 3: return sprintf(_("%drd"), num);
147 }
148
149 return sprintf(_("%dth"), num);
150}

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 183 of file counting.qh.

184{
185 int tmp_hours = 0, tmp_minutes = 0, tmp_seconds;
186 int tmp_years = 0, tmp_weeks = 0, tmp_days = 0;
187
188 tmp_seconds = floor(seconds);
189
190 if (tmp_seconds)
191 {
192 tmp_minutes = floor(tmp_seconds / 60);
193
194 if (tmp_minutes)
195 {
196 tmp_seconds -= tmp_minutes * 60;
197 tmp_hours = floor(tmp_minutes / 60);
198
199 if (tmp_hours)
200 {
201 tmp_minutes -= tmp_hours * 60;
202 tmp_days = floor(tmp_hours / 24);
203
204 if (tmp_days)
205 {
206 tmp_hours -= tmp_days * 24;
207 tmp_weeks = floor(tmp_days / 7);
208
209 if (tmp_weeks)
210 {
211 tmp_days -= tmp_weeks * 7;
212 tmp_years = floor(tmp_weeks / 52);
213 }
214 }
215 }
216 }
217 }
218
219 switch (outputtype)
220 {
221 case 1: return sprintf("%02d:%02d:%02d", tmp_hours, tmp_minutes, tmp_seconds);
222 case 2:
223 {
224 string output = "";
225 #define APPEND_TIME(unit) \
226 if (tmp_##unit) \
227 output = strcat(output, ((output != "") ? ", " : ""), count_##unit(tmp_##unit))
228 APPEND_TIME(years);
229 APPEND_TIME(weeks);
230 APPEND_TIME(days);
231 APPEND_TIME(hours);
232 APPEND_TIME(minutes);
233 APPEND_TIME(seconds);
234 #undef APPEND_TIME
235 if (output == "")
236 return count_seconds(0);
237 return output;
238 }
239 case 3:
240 {
241 string output = count_hours(tmp_hours);
242
243 if (tmp_weeks)
244 tmp_days += (tmp_weeks * 7);
245 if (tmp_years)
246 tmp_days += (tmp_years * 365);
247 if (tmp_days)
248 output = sprintf(
249 count_days(tmp_days),
250 ((output != "") ? strcat(", ", output) : "")
251 );
252
253 return output;
254 }
255 }
256 return "";
257}
#define APPEND_TIME(unit)
#define count_hours(time)
Definition counting.qh:104
#define count_days(time)
Definition counting.qh:95
#define count_seconds(time)
Definition counting.qh:122

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

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