1 // =========================================================
2 // Reply messages for common commands, re-worked by Samual
3 // Last updated: December 30th, 2011
4 // =========================================================
6 // These strings are set usually during init in g_world.qc,
7 // or also by some game modes or other functions manually,
8 // and their purpose is to output information to clients
9 // without using any extra processing time.
11 // See common.qc for their proper commands
13 // todo: Re-write this to be more user friendly... I'll probably do it after it is merged.
15 string getrecords(float page) // 50 records per page
29 for (i = page * 200; i < MapInfo_count && i < page * 200 + 200; ++i)
31 if (MapInfo_Get_ByID(i))
33 r = stof(db_get(ServerProgsDB, strcat(MapInfo_Map_bspname, "/captimerecord/time")));
37 h = db_get(ServerProgsDB, strcat(MapInfo_Map_bspname, "/captimerecord/netname"));
38 s = strcat(s, strpad(32, MapInfo_Map_bspname), " ", strpad(-6, ftos_decimals(r, 2)), " ", h, "\n");
46 for (i = page * 200; i < MapInfo_count && i < page * 200 + 200; ++i)
48 if (MapInfo_Get_ByID(i))
50 r = race_readTime(MapInfo_Map_bspname, 1);
53 h = race_readName(MapInfo_Map_bspname, 1);
54 s = strcat(s, strpad(32, MapInfo_Map_bspname), " ", strpad(-8, TIME_ENCODED_TOSTRING(r)), " ", h, "\n");
62 for (i = page * 200; i < MapInfo_count && i < page * 200 + 200; ++i)
64 if (MapInfo_Get_ByID(i))
66 r = race_readTime(MapInfo_Map_bspname, 1);
69 h = race_readName(MapInfo_Map_bspname, 1);
70 s = strcat(s, strpad(32, MapInfo_Map_bspname), " ", strpad(-8, TIME_ENCODED_TOSTRING(r)), " ", h, "\n");
78 if (s == "" && page == 0)
79 return "No records are available on this server.\n";
97 for (i = 1; i <= RANKINGS_CNT; ++i)
99 t = race_readTime(map, i);
102 n = race_readName(map, i);
103 p = race_placeName(i);
104 s = strcat(s, strpad(8, p), " ", strpad(-8, TIME_ENCODED_TOSTRING(t)), " ", n, "\n");
107 MapInfo_ClearTemps();
110 return strcat("No records are available for the map: ", map, "\n");
112 return strcat("Records for ", map, ":\n", s);
117 float i, j, k, uidcnt;
131 for (k = 0; k < MapInfo_count; ++k)
133 if (MapInfo_Get_ByID(k))
135 for (i = 0; i <= LADDER_CNT; ++i) { // i = 0 because it is the speed award
136 if(i == 0) // speed award
138 if(stof(db_get(ServerProgsDB, strcat(MapInfo_Map_bspname, rr, "speed/speed"))) == 0)
141 myuid = db_get(ServerProgsDB, strcat(MapInfo_Map_bspname, rr, "speed/crypto_idfp"));
143 else // normal record, if it exists (else break)
145 if(race_readTime(MapInfo_Map_bspname, i) == 0)
148 myuid = race_readUID(MapInfo_Map_bspname, i);
151 // string s contains:
152 // arg 0 = # of speed recs
153 // arg 1 = # of 1st place recs
154 // arg 2 = # of 2nd place recs
156 // LADDER_CNT+1 = total points
158 temp_s = db_get(TemporaryDB, strcat("ladder", myuid));
161 db_put(TemporaryDB, strcat("uid", ftos(uidcnt)), myuid);
163 for (j = 0; j <= LADDER_CNT + 1; ++j)
165 if(j != LADDER_CNT + 1)
166 temp_s = strcat(temp_s, "0 ");
168 temp_s = strcat(temp_s, "0");
172 tokenize_console(temp_s);
175 if(i == 0) // speed award
176 for (j = 0; j <= LADDER_CNT; ++j) // loop over each arg in the string
178 if(j == 0) // speed award
179 s = strcat(s, ftos(stof(argv(j)) +1)); // add 1 to speed rec count and write
181 s = strcat(s, " ", argv(j)); // just copy over everything else
184 for (j = 0; j <= LADDER_CNT; ++j) // loop over each arg in the string
187 s = strcat(s, argv(j)); // speed award, dont prefix with " "
188 else if(j == i) // wanted rec!
189 s = strcat(s, " ", ftos(stof(argv(j)) +1)); // update argv(j)
191 s = strcat(s, " ", argv(j)); // just copy over everything else
194 // total points are (by default) calculated like this:
195 // speedrec = floor(100 / 10) = 10 points
196 // 1st place = floor(100 / 1) = 100 points
197 // 2nd place = floor(100 / 2) = 50 points
198 // 3rd place = floor(100 / 3) = 33 points
199 // 4th place = floor(100 / 4) = 25 points
200 // 5th place = floor(100 / 5) = 20 points
204 s = strcat(s, " ", ftos(stof(argv(LADDER_CNT+1)) + LADDER_FIRSTPOINT / 10)); // speed award, add LADDER_FIRSTPOINT / 10 points
206 s = strcat(s, " ", ftos(stof(argv(LADDER_CNT+1)) + floor(LADDER_FIRSTPOINT / i))); // record, add LADDER_FIRSTPOINT / i points
208 db_put(TemporaryDB, strcat("ladder", myuid), s);
215 for (i = 0; i <= uidcnt; ++i) // for each known uid
217 thisuid = db_get(TemporaryDB, strcat("uid", ftos(i)));
218 temp_s = db_get(TemporaryDB, strcat("ladder", thisuid));
219 tokenize_console(temp_s);
220 thiscnt = stof(argv(LADDER_CNT+1));
222 if(thiscnt > top_scores[LADDER_SIZE-1])
223 for (j = 0; j < LADDER_SIZE; ++j) // for each place in ladder
225 if(thiscnt > top_scores[j])
227 for (k = LADDER_SIZE-1; k >= j; --k)
229 top_uids[k] = top_uids[k-1];
230 top_scores[k] = top_scores[k-1];
232 top_uids[j] = thisuid;
233 top_scores[j] = thiscnt;
239 s = "^3-----------------------\n\n";
241 s = strcat(s, "Pos ^3|");
242 s = strcat(s, " ^7Total ^3|");
243 for (i = 1; i <= LADDER_CNT; ++i)
245 s = strcat(s, " ^7", race_placeName(i), " ^3|");
247 s = strcat(s, " ^7Speed awards ^3| ^7Name");
249 s = strcat(s, "\n^3----+--------");
250 for (i = 1; i <= min(9, LADDER_CNT); ++i)
252 s = strcat(s, "+-----");
255 for (i = 1; i <= LADDER_CNT - 9; ++i)
257 s = strcat(s, "+------");
261 s = strcat(s, "+--------------+--------------------\n");
263 for (i = 0; i < LADDER_SIZE; ++i)
265 temp_s = db_get(TemporaryDB, strcat("ladder", top_uids[i]));
266 tokenize_console(temp_s);
267 if (argv(LADDER_CNT+1) == "") // total is 0, skip
269 s = strcat(s, strpad(4, race_placeName(i+1)), "^3| ^7"); // pos
270 s = strcat(s, strpad(7, argv(LADDER_CNT+1)), "^3| ^7"); // total
271 for (j = 1; j <= min(9, LADDER_CNT); ++j)
273 s = strcat(s, strpad(4, argv(j)), "^3| ^7"); // 1st, 2nd, 3rd etc cnt
276 for (j = 10; j <= LADDER_CNT; ++j)
278 s = strcat(s, strpad(4, argv(j)), " ^3| ^7"); // 1st, 2nd, 3rd etc cnt
282 s = strcat(s, strpad(13, argv(0)), "^3| ^7"); // speed award cnt
283 s = strcat(s, uid2name(top_uids[i]), "\n"); // name
286 MapInfo_ClearTemps();
289 return "No ladder on this server!\n";
291 return strcat("Top ", ftos(LADDER_SIZE), " ladder rankings:\n", s);