1 #include "../../common/command/command.qh"
2 #include "getreplies.qh"
7 #include "../../common/constants.qh"
8 #include "../../common/mapinfo.qh"
9 #include "../../common/util.qh"
11 #include "../../common/monsters/all.qh"
13 // =========================================================
14 // Reply messages for common commands, re-worked by Samual
15 // Last updated: December 30th, 2011
16 // =========================================================
18 // These strings are set usually during init in g_world.qc,
19 // or also by some game modes or other functions manually,
20 // and their purpose is to output information to clients
21 // without using any extra processing time.
23 // See common.qc for their proper commands
25 string getrecords(float page) // 50 records per page
34 for (i = page * 200; i < MapInfo_count && i < page * 200 + 200; ++i)
36 if (MapInfo_Get_ByID(i))
38 r = stof(db_get(ServerProgsDB, strcat(MapInfo_Map_bspname, "/captimerecord/time")));
44 h = db_get(ServerProgsDB, strcat(MapInfo_Map_bspname, "/captimerecord/netname"));
45 s = strcat(s, strpad(32, MapInfo_Map_bspname), " ", strpad(-6, ftos_decimals(r, 2)), " ", h, "\n");
53 for (i = page * 200; i < MapInfo_count && i < page * 200 + 200; ++i)
55 if (MapInfo_Get_ByID(i))
57 r = race_readTime(MapInfo_Map_bspname, 1);
62 h = race_readName(MapInfo_Map_bspname, 1);
63 s = strcat(s, strpad(32, MapInfo_Map_bspname), " ", strpad(-8, TIME_ENCODED_TOSTRING(r)), " ", h, "\n");
71 for (i = page * 200; i < MapInfo_count && i < page * 200 + 200; ++i)
73 if (MapInfo_Get_ByID(i))
75 r = race_readTime(MapInfo_Map_bspname, 1);
80 h = race_readName(MapInfo_Map_bspname, 1);
81 s = strcat(s, strpad(32, MapInfo_Map_bspname), " ", strpad(-8, TIME_ENCODED_TOSTRING(r)), " ", h, "\n");
89 if(s == "" && page == 0)
90 return "No records are available on this server.\n";
103 for (i = 1; i <= RANKINGS_CNT; ++i)
105 t = race_readTime(map, i);
110 n = race_readName(map, i);
111 p = count_ordinal(i);
112 s = strcat(s, strpad(8, p), " ", strpad(-8, TIME_ENCODED_TOSTRING(t)), " ", n, "\n");
115 MapInfo_ClearTemps();
118 return strcat("No records are available for the map: ", map, "\n");
120 return strcat("Records for ", map, ":\n", s);
125 int i, j, k, uidcnt = 0, thiscnt;
126 string s, temp_s, rr, myuid, thisuid;
128 rr = (g_cts) ? CTS_RECORD : RACE_RECORD;
130 for(k = 0; k < MapInfo_count; ++k)
132 if(MapInfo_Get_ByID(k))
134 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));
162 db_put(TemporaryDB, strcat("uid", ftos(uidcnt)), myuid);
165 for(j = 0; j <= LADDER_CNT + 1; ++j)
167 if(j != LADDER_CNT + 1)
168 temp_s = strcat(temp_s, "0 ");
170 temp_s = strcat(temp_s, "0");
174 tokenize_console(temp_s);
177 if(i == 0) // speed award
179 for(j = 0; j <= LADDER_CNT; ++j) // loop over each arg in the string
181 if(j == 0) // speed award
182 s = strcat(s, ftos(stof(argv(j)) +1)); // add 1 to speed rec count and write
184 s = strcat(s, " ", argv(j)); // just copy over everything else
189 for(j = 0; j <= LADDER_CNT; ++j) // loop over each arg in the string
192 s = strcat(s, argv(j)); // speed award, dont prefix with " "
193 else if(j == i) // wanted rec!
194 s = strcat(s, " ", ftos(stof(argv(j)) +1)); // update argv(j)
196 s = strcat(s, " ", argv(j)); // just copy over everything else
200 // total points are (by default) calculated like this:
201 // speedrec = floor(100 / 10) = 10 points
202 // 1st place = floor(100 / 1) = 100 points
203 // 2nd place = floor(100 / 2) = 50 points
204 // 3rd place = floor(100 / 3) = 33 points
205 // 4th place = floor(100 / 4) = 25 points
206 // 5th place = floor(100 / 5) = 20 points
210 s = strcat(s, " ", ftos(stof(argv(LADDER_CNT+1)) + LADDER_FIRSTPOINT / 10)); // speed award, add LADDER_FIRSTPOINT / 10 points
212 s = strcat(s, " ", ftos(stof(argv(LADDER_CNT+1)) + floor(LADDER_FIRSTPOINT / i))); // record, add LADDER_FIRSTPOINT / i points
214 db_put(TemporaryDB, strcat("ladder", myuid), s);
219 for(i = 0; i <= uidcnt; ++i) // for each known uid
221 thisuid = db_get(TemporaryDB, strcat("uid", ftos(i)));
222 temp_s = db_get(TemporaryDB, strcat("ladder", thisuid));
223 tokenize_console(temp_s);
224 thiscnt = stof(argv(LADDER_CNT+1));
226 if(thiscnt > top_scores[LADDER_SIZE-1])
228 for(j = 0; j < LADDER_SIZE; ++j) // for each place in ladder
230 if(thiscnt > top_scores[j])
232 for(k = LADDER_SIZE-1; k >= j; --k)
234 top_uids[k] = top_uids[k-1];
235 top_scores[k] = top_scores[k-1];
238 top_uids[j] = thisuid;
239 top_scores[j] = thiscnt;
246 s = "^3-----------------------\n\n";
248 s = strcat(s, "Pos ^3|");
249 s = strcat(s, " ^7Total ^3|");
251 for(i = 1; i <= LADDER_CNT; ++i)
252 { s = strcat(s, " ^7", count_ordinal(i), " ^3|"); }
254 s = strcat(s, " ^7Speed awards ^3| ^7Name");
255 s = strcat(s, "\n^3----+--------");
257 for(i = 1; i <= min(9, LADDER_CNT); ++i)
258 { s = strcat(s, "+-----"); }
261 for(i = 1; i <= LADDER_CNT - 9; ++i)
262 { s = strcat(s, "+------"); }
265 s = strcat(s, "+--------------+--------------------\n");
267 for(i = 0; i < LADDER_SIZE; ++i)
269 temp_s = db_get(TemporaryDB, strcat("ladder", top_uids[i]));
270 tokenize_console(temp_s);
272 if(argv(LADDER_CNT+1) == "") // total is 0, skip
275 s = strcat(s, strpad(4, count_ordinal(i+1)), "^3| ^7"); // pos
276 s = strcat(s, strpad(7, argv(LADDER_CNT+1)), "^3| ^7"); // total
278 for(j = 1; j <= min(9, LADDER_CNT); ++j)
279 { s = strcat(s, strpad(4, argv(j)), "^3| ^7"); } // 1st, 2nd, 3rd etc cnt
282 for(j = 10; j <= LADDER_CNT; ++j)
283 { s = strcat(s, strpad(4, argv(j)), " ^3| ^7"); } // 1st, 2nd, 3rd etc cnt
286 s = strcat(s, strpad(13, argv(0)), "^3| ^7"); // speed award cnt
287 s = strcat(s, uid2name(top_uids[i]), "\n"); // name
290 MapInfo_ClearTemps();
293 return "No ladder on this server!\n";
295 return strcat("Top ", ftos(LADDER_SIZE), " ladder rankings:\n", s);
300 string maplist = "", col;
303 argc = tokenize_console(autocvar_g_maplist);
304 for(i = 0; i < argc; ++i)
306 if(MapInfo_CheckMap(argv(i)))
308 if(i % 2) { col = "^2"; }
310 maplist = sprintf("%s%s%s ", maplist, col, argv(i));
314 MapInfo_ClearTemps();
315 return sprintf("^7Maps in list: %s\n", maplist);
321 string lsmaps = "", col;
322 float i, newmaps = 0;
324 for(i = 0; i < MapInfo_count; ++i)
326 if((MapInfo_Get_ByID(i)) && !(MapInfo_Map_flags & MapInfo_ForbiddenFlags()))
328 // todo: Check by play count of maps for other game types?
330 (g_race && !stof(db_get(ServerProgsDB, strcat(MapInfo_Map_bspname, RACE_RECORD, "time"))))
332 (g_cts && !stof(db_get(ServerProgsDB, strcat(MapInfo_Map_bspname, CTS_RECORD, "time"))))
336 if(i % 2) { col = "^4*"; }
337 else { col = "^5*"; }
341 if(i % 2) { col = "^2"; }
345 lsmaps = sprintf("%s%s%s ", lsmaps, col, MapInfo_Map_bspname);
349 MapInfo_ClearTemps();
350 return sprintf("^7Maps available (%d)%s: %s\n", tokenize_console(lsmaps), (newmaps ? " (New maps have asterisks marked in blue)" : ""), lsmaps);
353 string getmonsterlist()
355 string monsterlist = "", col;
357 for(int i = MON_FIRST; i <= MON_LAST; ++i)
359 if(i % 2) { col = "^2"; }
361 monsterlist = sprintf("%s%s%s ", monsterlist, col, (get_monsterinfo(i)).netname);
364 return sprintf("^7Monsters available: %s\n", monsterlist);