4 #include "../../dpdefs/progsdefs.qc"
5 #include "../../dpdefs/dpextensions.qc"
6 #include "../sys-post.qh"
7 #include "../../common/constants.qh"
8 #include "../../common/util.qh"
9 #include "../../common/counting.qh"
10 #include "../../common/monsters/monsters.qh"
12 #include "../../common/mapinfo.qh"
13 #include "getreplies.qh"
17 // =========================================================
18 // Reply messages for common commands, re-worked by Samual
19 // Last updated: December 30th, 2011
20 // =========================================================
22 // These strings are set usually during init in g_world.qc,
23 // or also by some game modes or other functions manually,
24 // and their purpose is to output information to clients
25 // without using any extra processing time.
27 // See common.qc for their proper commands
29 string getrecords(float page) // 50 records per page
38 for (i = page * 200; i < MapInfo_count && i < page * 200 + 200; ++i)
40 if (MapInfo_Get_ByID(i))
42 r = stof(db_get(ServerProgsDB, strcat(MapInfo_Map_bspname, "/captimerecord/time")));
48 h = db_get(ServerProgsDB, strcat(MapInfo_Map_bspname, "/captimerecord/netname"));
49 s = strcat(s, strpad(32, MapInfo_Map_bspname), " ", strpad(-6, ftos_decimals(r, 2)), " ", h, "\n");
57 for (i = page * 200; i < MapInfo_count && i < page * 200 + 200; ++i)
59 if (MapInfo_Get_ByID(i))
61 r = race_readTime(MapInfo_Map_bspname, 1);
66 h = race_readName(MapInfo_Map_bspname, 1);
67 s = strcat(s, strpad(32, MapInfo_Map_bspname), " ", strpad(-8, TIME_ENCODED_TOSTRING(r)), " ", h, "\n");
75 for (i = page * 200; i < MapInfo_count && i < page * 200 + 200; ++i)
77 if (MapInfo_Get_ByID(i))
79 r = race_readTime(MapInfo_Map_bspname, 1);
84 h = race_readName(MapInfo_Map_bspname, 1);
85 s = strcat(s, strpad(32, MapInfo_Map_bspname), " ", strpad(-8, TIME_ENCODED_TOSTRING(r)), " ", h, "\n");
93 if(s == "" && page == 0)
94 return "No records are available on this server.\n";
107 for (i = 1; i <= RANKINGS_CNT; ++i)
109 t = race_readTime(map, i);
114 n = race_readName(map, i);
115 p = count_ordinal(i);
116 s = strcat(s, strpad(8, p), " ", strpad(-8, TIME_ENCODED_TOSTRING(t)), " ", n, "\n");
119 MapInfo_ClearTemps();
122 return strcat("No records are available for the map: ", map, "\n");
124 return strcat("Records for ", map, ":\n", s);
129 float i, j, k, uidcnt = 0, thiscnt;
130 string s, temp_s, rr, myuid, thisuid;
132 rr = (g_cts) ? CTS_RECORD : RACE_RECORD;
134 for(k = 0; k < MapInfo_count; ++k)
136 if(MapInfo_Get_ByID(k))
138 for(i = 0; i <= LADDER_CNT; ++i) // i = 0 because it is the speed award
140 if(i == 0) // speed award
142 if(stof(db_get(ServerProgsDB, strcat(MapInfo_Map_bspname, rr, "speed/speed"))) == 0)
145 myuid = db_get(ServerProgsDB, strcat(MapInfo_Map_bspname, rr, "speed/crypto_idfp"));
147 else // normal record, if it exists (else break)
149 if(race_readTime(MapInfo_Map_bspname, i) == 0)
152 myuid = race_readUID(MapInfo_Map_bspname, i);
155 // string s contains:
156 // arg 0 = # of speed recs
157 // arg 1 = # of 1st place recs
158 // arg 2 = # of 2nd place recs
160 // LADDER_CNT+1 = total points
162 temp_s = db_get(TemporaryDB, strcat("ladder", myuid));
166 db_put(TemporaryDB, strcat("uid", ftos(uidcnt)), myuid);
169 for(j = 0; j <= LADDER_CNT + 1; ++j)
171 if(j != LADDER_CNT + 1)
172 temp_s = strcat(temp_s, "0 ");
174 temp_s = strcat(temp_s, "0");
178 tokenize_console(temp_s);
181 if(i == 0) // speed award
183 for(j = 0; j <= LADDER_CNT; ++j) // loop over each arg in the string
185 if(j == 0) // speed award
186 s = strcat(s, ftos(stof(argv(j)) +1)); // add 1 to speed rec count and write
188 s = strcat(s, " ", argv(j)); // just copy over everything else
193 for(j = 0; j <= LADDER_CNT; ++j) // loop over each arg in the string
196 s = strcat(s, argv(j)); // speed award, dont prefix with " "
197 else if(j == i) // wanted rec!
198 s = strcat(s, " ", ftos(stof(argv(j)) +1)); // update argv(j)
200 s = strcat(s, " ", argv(j)); // just copy over everything else
204 // total points are (by default) calculated like this:
205 // speedrec = floor(100 / 10) = 10 points
206 // 1st place = floor(100 / 1) = 100 points
207 // 2nd place = floor(100 / 2) = 50 points
208 // 3rd place = floor(100 / 3) = 33 points
209 // 4th place = floor(100 / 4) = 25 points
210 // 5th place = floor(100 / 5) = 20 points
214 s = strcat(s, " ", ftos(stof(argv(LADDER_CNT+1)) + LADDER_FIRSTPOINT / 10)); // speed award, add LADDER_FIRSTPOINT / 10 points
216 s = strcat(s, " ", ftos(stof(argv(LADDER_CNT+1)) + floor(LADDER_FIRSTPOINT / i))); // record, add LADDER_FIRSTPOINT / i points
218 db_put(TemporaryDB, strcat("ladder", myuid), s);
223 for(i = 0; i <= uidcnt; ++i) // for each known uid
225 thisuid = db_get(TemporaryDB, strcat("uid", ftos(i)));
226 temp_s = db_get(TemporaryDB, strcat("ladder", thisuid));
227 tokenize_console(temp_s);
228 thiscnt = stof(argv(LADDER_CNT+1));
230 if(thiscnt > top_scores[LADDER_SIZE-1])
232 for(j = 0; j < LADDER_SIZE; ++j) // for each place in ladder
234 if(thiscnt > top_scores[j])
236 for(k = LADDER_SIZE-1; k >= j; --k)
238 top_uids[k] = top_uids[k-1];
239 top_scores[k] = top_scores[k-1];
242 top_uids[j] = thisuid;
243 top_scores[j] = thiscnt;
250 s = "^3-----------------------\n\n";
252 s = strcat(s, "Pos ^3|");
253 s = strcat(s, " ^7Total ^3|");
255 for(i = 1; i <= LADDER_CNT; ++i)
256 { s = strcat(s, " ^7", count_ordinal(i), " ^3|"); }
258 s = strcat(s, " ^7Speed awards ^3| ^7Name");
259 s = strcat(s, "\n^3----+--------");
261 for(i = 1; i <= min(9, LADDER_CNT); ++i)
262 { s = strcat(s, "+-----"); }
265 for(i = 1; i <= LADDER_CNT - 9; ++i)
266 { s = strcat(s, "+------"); }
269 s = strcat(s, "+--------------+--------------------\n");
271 for(i = 0; i < LADDER_SIZE; ++i)
273 temp_s = db_get(TemporaryDB, strcat("ladder", top_uids[i]));
274 tokenize_console(temp_s);
276 if(argv(LADDER_CNT+1) == "") // total is 0, skip
279 s = strcat(s, strpad(4, count_ordinal(i+1)), "^3| ^7"); // pos
280 s = strcat(s, strpad(7, argv(LADDER_CNT+1)), "^3| ^7"); // total
282 for(j = 1; j <= min(9, LADDER_CNT); ++j)
283 { s = strcat(s, strpad(4, argv(j)), "^3| ^7"); } // 1st, 2nd, 3rd etc cnt
286 for(j = 10; j <= LADDER_CNT; ++j)
287 { s = strcat(s, strpad(4, argv(j)), " ^3| ^7"); } // 1st, 2nd, 3rd etc cnt
290 s = strcat(s, strpad(13, argv(0)), "^3| ^7"); // speed award cnt
291 s = strcat(s, uid2name(top_uids[i]), "\n"); // name
294 MapInfo_ClearTemps();
297 return "No ladder on this server!\n";
299 return strcat("Top ", ftos(LADDER_SIZE), " ladder rankings:\n", s);
304 string maplist = "", col;
307 argc = tokenize_console(autocvar_g_maplist);
308 for(i = 0; i < argc; ++i)
310 if(MapInfo_CheckMap(argv(i)))
312 if(i % 2) { col = "^2"; }
314 maplist = sprintf("%s%s%s ", maplist, col, argv(i));
318 MapInfo_ClearTemps();
319 return sprintf("^7Maps in list: %s\n", maplist);
325 string lsmaps = "", col;
326 float i, newmaps = 0;
328 for(i = 0; i < MapInfo_count; ++i)
330 if((MapInfo_Get_ByID(i)) && !(MapInfo_Map_flags & MapInfo_ForbiddenFlags()))
332 // todo: Check by play count of maps for other game types?
334 (g_race && !stof(db_get(ServerProgsDB, strcat(MapInfo_Map_bspname, RACE_RECORD, "time"))))
336 (g_cts && !stof(db_get(ServerProgsDB, strcat(MapInfo_Map_bspname, CTS_RECORD, "time"))))
340 if(i % 2) { col = "^4*"; }
341 else { col = "^5*"; }
345 if(i % 2) { col = "^2"; }
349 lsmaps = sprintf("%s%s%s ", lsmaps, col, MapInfo_Map_bspname);
353 MapInfo_ClearTemps();
354 return sprintf("^7Maps available (%d)%s: %s\n", tokenize_console(lsmaps), (newmaps ? " (New maps have asterisks marked in blue)" : ""), lsmaps);
357 string getmonsterlist()
359 string monsterlist = "", col;
362 for(i = MON_FIRST; i <= MON_LAST; ++i)
364 if(i % 2) { col = "^2"; }
366 monsterlist = sprintf("%s%s%s ", monsterlist, col, (get_monsterinfo(i)).netname);
369 return sprintf("^7Monsters available: %s\n", monsterlist);