6 #include "../client/sys-pre.qh"
7 #include "../dpdefs/csprogsdefs.qh"
8 #include "../client/sys-post.qh"
9 #include "../client/defs.qh"
10 #include "../dpdefs/keycodes.qh"
11 #include "constants.qh"
13 #include "../warpzonelib/anglestransform.qh"
14 #include "../warpzonelib/mathlib.qh"
15 #include "../warpzonelib/common.qh"
16 #include "../warpzonelib/client.qh"
17 #include "playerstats.qh"
24 #include "util-pre.qh"
25 #include "../menu/sys-pre.qh"
26 #include "../dpdefs/menudefs.qh"
27 #include "../dpdefs/keycodes.qh"
28 #include "../menu/sys-post.qh"
29 #include "../menu/config.qh"
30 #include "../warpzonelib/mathlib.qh"
33 #include "../menu/oo/base.qh"
34 #include "playerstats.qh"
36 #include "constants.qh"
38 #include "campaign_common.qh"
39 #include "weapons/weapons.qh"
41 #include "util-pre.qh"
42 #include "../server/sys-pre.qh"
43 #include "../dpdefs/progsdefs.qh"
44 #include "../dpdefs/dpextensions.qh"
45 #include "../server/sys-post.qh"
46 #include "../warpzonelib/anglestransform.qh"
47 #include "../warpzonelib/mathlib.qh"
48 #include "../warpzonelib/common.qh"
49 #include "../warpzonelib/util_server.qh"
50 #include "../warpzonelib/server.qh"
51 #include "constants.qh"
60 // ===============================================
61 // Time processing and counting functions/macros
62 // ===============================================
64 #define count_years_decs(time,decs) sprintf(ZCTX(_("CI_DEC^%s years")), ftos_decimals(time, decs))
65 #define count_years(time) count_fill(time, \
66 ZCTX(_("CI_ZER^%d years")), /* zeroth */ \
67 ZCTX(_("CI_FIR^%d year")), /* first */ \
68 ZCTX(_("CI_SEC^%d years")), /* year */ \
69 ZCTX(_("CI_THI^%d years")), /* third */ \
70 ZCTX(_("CI_MUL^%d years"))) /* multi */
72 #define count_weeks_decs(time,decs) sprintf(ZCTX(_("CI_DEC^%s weeks")), ftos_decimals(time, decs))
73 #define count_weeks(time) count_fill(time, \
74 ZCTX(_("CI_ZER^%d weeks")), /* zeroth */ \
75 ZCTX(_("CI_FIR^%d week")), /* first */ \
76 ZCTX(_("CI_SEC^%d weeks")), /* week */ \
77 ZCTX(_("CI_THI^%d weeks")), /* third */ \
78 ZCTX(_("CI_MUL^%d weeks"))) /* multi */
80 #define count_days_decs(time,decs) sprintf(ZCTX(_("CI_DEC^%s days")), ftos_decimals(time, decs))
81 #define count_days(time) count_fill(time, \
82 ZCTX(_("CI_ZER^%d days")), /* zeroth */ \
83 ZCTX(_("CI_FIR^%d day")), /* first */ \
84 ZCTX(_("CI_SEC^%d days")), /* day */ \
85 ZCTX(_("CI_THI^%d days")), /* third */ \
86 ZCTX(_("CI_MUL^%d days"))) /* multi */
88 #define count_hours_decs(time,decs) sprintf(ZCTX(_("CI_DEC^%s hours")), ftos_decimals(time, decs))
89 #define count_hours(time) count_fill(time, \
90 ZCTX(_("CI_ZER^%d hours")), /* zeroth */ \
91 ZCTX(_("CI_FIR^%d hour")), /* first */ \
92 ZCTX(_("CI_SEC^%d hours")), /* hour */ \
93 ZCTX(_("CI_THI^%d hours")), /* third */ \
94 ZCTX(_("CI_MUL^%d hours"))) /* multi */
97 #define count_minutes_decs(time,decs) sprintf(ZCTX(_("CI_DEC^%s minutes")), ftos_decimals(time, decs))
98 #define count_minutes(time) count_fill(time, \
99 ZCTX(_("CI_ZER^%d minutes")), /* zeroth */ \
100 ZCTX(_("CI_FIR^%d minute")), /* first */ \
101 ZCTX(_("CI_SEC^%d minutes")), /* minute */ \
102 ZCTX(_("CI_THI^%d minutes")), /* third */ \
103 ZCTX(_("CI_MUL^%d minutes"))) /* multi */
105 #define count_seconds_decs(time,decs) sprintf(ZCTX(_("CI_DEC^%s seconds")), ftos_decimals(time, decs))
106 #define count_seconds(time) count_fill(time, \
107 ZCTX(_("CI_ZER^%d seconds")), /* zeroth */ \
108 ZCTX(_("CI_FIR^%d second")), /* first */ \
109 ZCTX(_("CI_SEC^%d seconds")), /* second */ \
110 ZCTX(_("CI_THI^%d seconds")), /* third */ \
111 ZCTX(_("CI_MUL^%d seconds"))) /* multi */
113 string count_ordinal(int interval)
115 // This function is designed primarily for the English language, it's impossible
116 // to accomodate all languages unless we do a specific function for each one...
117 // and since that's not technically feasible/practical, this is all we've got folks.
119 // Basically, it just allows you to represent a number or count in different ways
120 // depending on the number... like, with count_ordinal you can provide integers
121 // and retrieve 1st, 2nd, 3rd, nth ordinal numbers in a clean and simple way.
122 if(floor((interval % 100)/10) * 10 != 10) // examples: 12th, 111th, 213th will not execute this block
124 // otherwise, check normally for 1st,2nd,3rd insertions
125 switch(interval % 10)
127 case 1: return sprintf(_("%dst"), interval);
128 case 2: return sprintf(_("%dnd"), interval);
129 case 3: return sprintf(_("%drd"), interval);
130 default: return sprintf(_("%dth"), interval);
133 else { return sprintf(_("%dth"), interval); }
138 string count_fill(float interval, string zeroth, string first, string second, string third, string multi)
140 // This function is designed primarily for the English language, it's impossible
141 // to accomodate all languages unless we do a specific function for each one...
142 // and since that's not technically feasible/practical, this is all we've got folks.
144 // Here you can insert specific strings based on the interval number, so you could do
145 // i.e. count_seconds which outputs like this:
150 // etc... minutes, hours, days, etc.
152 switch(floor(interval))
154 case 0: return sprintf(zeroth, interval);
157 if(interval == 1) // EXACTLY value of 1
158 return sprintf(first, interval);
160 return sprintf(multi, interval);
162 case 2: return sprintf(second, interval);
163 case 3: return sprintf(third, interval);
164 default: return sprintf(multi, interval);
169 string process_time(float outputtype, float seconds)
171 float tmp_hours = 0, tmp_minutes = 0, tmp_seconds = 0;
172 float tmp_years = 0, tmp_weeks = 0, tmp_days = 0;
174 tmp_seconds = floor(seconds);
178 tmp_minutes = floor(tmp_seconds / 60);
182 tmp_seconds -= (tmp_minutes * 60);
183 tmp_hours = floor(tmp_minutes / 60);
187 tmp_minutes -= (tmp_hours * 60);
188 tmp_days = floor(tmp_hours / 24);
192 tmp_hours -= (tmp_days * 24);
193 tmp_weeks = floor(tmp_days / 7);
197 tmp_days -= (tmp_weeks * 7);
198 tmp_years = floor(tmp_weeks / 52);
207 case 1: return sprintf("%02d:%02d:%02d", tmp_hours, tmp_minutes, tmp_seconds);
212 output = count_seconds(tmp_seconds);
218 count_minutes(tmp_minutes),
219 ((output != "") ? sprintf(", %s", output) : ""));
226 count_hours(tmp_hours),
227 ((output != "") ? sprintf(", %s", output) : ""));
234 count_days(tmp_days),
235 ((output != "") ? sprintf(", %s", output) : ""));
242 count_weeks(tmp_weeks),
243 ((output != "") ? sprintf(", %s", output) : ""));
250 count_years(tmp_years),
251 ((output != "") ? sprintf(", %s", output) : ""));
260 output = count_hours(tmp_hours);
262 if(tmp_weeks) { tmp_days += (tmp_weeks * 7); }
263 if(tmp_years) { tmp_days += (tmp_years * 365); }
268 count_days(tmp_days),
269 ((output != "") ? sprintf(", %s", output) : ""));