]> git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/server/command/getreplies.qc
Update Luma simple items. Minor color changes
[xonotic/xonotic-data.pk3dir.git] / qcsrc / server / command / getreplies.qc
1 // =========================================================
2 //  Reply messages for common commands, re-worked by Samual
3 //  Last updated: December 30th, 2011
4 // =========================================================
5
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.
10
11 // See common.qc for their proper commands
12
13 string getrecords(float page) // 50 records per page
14 {
15         float rec = 0, r, i;
16         string h, s;
17
18         s = "";
19
20         if (g_ctf)
21         {
22                 for (i = page * 200; i < MapInfo_count && i < page * 200 + 200; ++i)
23                 {
24                         if (MapInfo_Get_ByID(i))
25                         {
26                                 r = stof(db_get(ServerProgsDB, strcat(MapInfo_Map_bspname, "/captimerecord/time")));
27
28                                 if (!r)
29                                         continue;
30
31                                 // TODO: uid2name
32                                 h = db_get(ServerProgsDB, strcat(MapInfo_Map_bspname, "/captimerecord/netname"));
33                                 s = strcat(s, strpad(32, MapInfo_Map_bspname), " ", strpad(-6, ftos_decimals(r, 2)), " ", h, "\n");
34                                 ++rec;
35                         }
36                 }
37         }
38
39         if (g_race)
40         {
41                 for (i = page * 200; i < MapInfo_count && i < page * 200 + 200; ++i)
42                 {
43                         if (MapInfo_Get_ByID(i))
44                         {
45                                 r = race_readTime(MapInfo_Map_bspname, 1);
46
47                                 if (!r)
48                                         continue;
49
50                                 h = race_readName(MapInfo_Map_bspname, 1);
51                                 s = strcat(s, strpad(32, MapInfo_Map_bspname), " ", strpad(-8, TIME_ENCODED_TOSTRING(r)), " ", h, "\n");
52                                 ++rec;
53                         }
54                 }
55         }
56
57         if (g_cts)
58         {
59                 for (i = page * 200; i < MapInfo_count && i < page * 200 + 200; ++i)
60                 {
61                         if (MapInfo_Get_ByID(i))
62                         {
63                                 r = race_readTime(MapInfo_Map_bspname, 1);
64
65                                 if (!r)
66                                         continue;
67
68                                 h = race_readName(MapInfo_Map_bspname, 1);
69                                 s = strcat(s, strpad(32, MapInfo_Map_bspname), " ", strpad(-8, TIME_ENCODED_TOSTRING(r)), " ", h, "\n");
70                                 ++rec;
71                         }
72                 }
73         }
74
75         MapInfo_ClearTemps();
76
77         if(s == "" && page == 0)
78                 return "No records are available on this server.\n";
79         else
80                 return s;
81 }
82
83 string getrankings()
84 {
85         float t, i;
86         string n, s, p, map;
87
88         map = GetMapname();
89
90         s = "";
91         for (i = 1; i <= RANKINGS_CNT; ++i)
92         {
93                 t = race_readTime(map, i);
94
95                 if (t == 0)
96                         continue;
97
98                 n = race_readName(map, i);
99                 p = count_ordinal(i);
100                 s = strcat(s, strpad(8, p), " ", strpad(-8, TIME_ENCODED_TOSTRING(t)), " ", n, "\n");
101         }
102
103         MapInfo_ClearTemps();
104
105         if (s == "")
106                 return strcat("No records are available for the map: ", map, "\n");
107         else
108                 return strcat("Records for ", map, ":\n", s);
109 }
110
111 string getladder()
112 {
113         float i, j, k, uidcnt = 0, thiscnt;
114         string s, temp_s, rr, myuid, thisuid;
115
116         if(g_cts)
117                 rr = CTS_RECORD;
118         else
119                 rr = RACE_RECORD;
120
121         for(k = 0; k < MapInfo_count; ++k)
122         {
123                 if(MapInfo_Get_ByID(k))
124                 {
125                         for(i = 0; i <= LADDER_CNT; ++i) // i = 0 because it is the speed award
126                         {
127                                 if(i == 0) // speed award
128                                 {
129                                         if(stof(db_get(ServerProgsDB, strcat(MapInfo_Map_bspname, rr, "speed/speed"))) == 0)
130                                                 continue;
131
132                                         myuid = db_get(ServerProgsDB, strcat(MapInfo_Map_bspname, rr, "speed/crypto_idfp"));
133                                 }
134                                 else // normal record, if it exists (else break)
135                                 {
136                                         if(race_readTime(MapInfo_Map_bspname, i) == 0)
137                                                 continue;
138
139                                         myuid = race_readUID(MapInfo_Map_bspname, i);
140                                 }
141
142                                 // string s contains:
143                                 // arg 0 = # of speed recs
144                                 // arg 1 = # of 1st place recs
145                                 // arg 2 = # of 2nd place recs
146                                 // ... etc
147                                 // LADDER_CNT+1 = total points
148
149                                 temp_s = db_get(TemporaryDB, strcat("ladder", myuid));
150
151                                 if(temp_s == "")
152                                 {
153                                         db_put(TemporaryDB, strcat("uid", ftos(uidcnt)), myuid);
154                                         ++uidcnt;
155
156                                         for(j = 0; j <= LADDER_CNT + 1; ++j)
157                                         {
158                                                 if(j != LADDER_CNT + 1)
159                                                         temp_s = strcat(temp_s, "0 ");
160                                                 else
161                                                         temp_s = strcat(temp_s, "0");
162                                         }
163                                 }
164
165                                 tokenize_console(temp_s);
166                                 s = "";
167
168                                 if(i == 0) // speed award
169                                 {
170                                         for(j = 0; j <= LADDER_CNT; ++j) // loop over each arg in the string
171                                         {
172                                                 if(j == 0) // speed award
173                                                         s = strcat(s, ftos(stof(argv(j)) +1)); // add 1 to speed rec count and write
174                                                 else
175                                                         s = strcat(s, " ", argv(j)); // just copy over everything else
176                                         }
177                                 }
178                                 else // record
179                                 {
180                                         for(j = 0; j <= LADDER_CNT; ++j) // loop over each arg in the string
181                                         {
182                                                 if(j == 0)
183                                                         s = strcat(s, argv(j)); // speed award, dont prefix with " "
184                                                 else if(j == i) // wanted rec!
185                                                         s = strcat(s, " ", ftos(stof(argv(j)) +1)); // update argv(j)
186                                                 else
187                                                         s = strcat(s, " ", argv(j)); // just copy over everything else
188                                         }
189                                 }
190
191                                 // total points are (by default) calculated like this:
192                                 // speedrec = floor(100 / 10) = 10 points
193                                 // 1st place = floor(100 / 1) = 100 points
194                                 // 2nd place = floor(100 / 2) = 50 points
195                                 // 3rd place = floor(100 / 3) = 33 points
196                                 // 4th place = floor(100 / 4) = 25 points
197                                 // 5th place = floor(100 / 5) = 20 points
198                                 // ... etc
199
200                                 if(i == 0)
201                                         s = strcat(s, " ", ftos(stof(argv(LADDER_CNT+1)) + LADDER_FIRSTPOINT / 10)); // speed award, add LADDER_FIRSTPOINT / 10 points
202                                 else
203                                         s = strcat(s, " ", ftos(stof(argv(LADDER_CNT+1)) + floor(LADDER_FIRSTPOINT / i))); // record, add LADDER_FIRSTPOINT / i points
204
205                                 db_put(TemporaryDB, strcat("ladder", myuid), s);
206                         }
207                 }
208         }
209
210         for(i = 0; i <= uidcnt; ++i) // for each known uid
211         {
212                 thisuid = db_get(TemporaryDB, strcat("uid", ftos(i)));
213                 temp_s = db_get(TemporaryDB, strcat("ladder", thisuid));
214                 tokenize_console(temp_s);
215                 thiscnt = stof(argv(LADDER_CNT+1));
216
217                 if(thiscnt > top_scores[LADDER_SIZE-1])
218                 {
219                         for(j = 0; j < LADDER_SIZE; ++j) // for each place in ladder
220                         {
221                                 if(thiscnt > top_scores[j])
222                                 {
223                                         for(k = LADDER_SIZE-1; k >= j; --k)
224                                         {
225                                                 top_uids[k] = top_uids[k-1];
226                                                 top_scores[k] = top_scores[k-1];
227                                         }
228
229                                         top_uids[j] = thisuid;
230                                         top_scores[j] = thiscnt;
231                                         break;
232                                 }
233                         }
234                 }
235         }
236
237         s = "^3-----------------------\n\n";
238
239         s = strcat(s, "Pos ^3|");
240         s = strcat(s, " ^7Total  ^3|");
241
242         for(i = 1; i <= LADDER_CNT; ++i)
243                 { s = strcat(s, " ^7", count_ordinal(i), " ^3|"); }
244
245         s = strcat(s, " ^7Speed awards ^3| ^7Name");
246         s = strcat(s, "\n^3----+--------");
247
248         for(i = 1; i <= min(9, LADDER_CNT); ++i)
249                 { s = strcat(s, "+-----"); }
250
251         #if LADDER_CNT > 9
252         for(i = 1; i <= LADDER_CNT - 9; ++i)
253                 { s = strcat(s, "+------"); }
254         #endif
255
256         s = strcat(s, "+--------------+--------------------\n");
257
258         for(i = 0; i < LADDER_SIZE; ++i)
259         {
260                 temp_s = db_get(TemporaryDB, strcat("ladder", top_uids[i]));
261                 tokenize_console(temp_s);
262
263                 if(argv(LADDER_CNT+1) == "") // total is 0, skip
264                         continue;
265
266                 s = strcat(s, strpad(4, count_ordinal(i+1)), "^3| ^7"); // pos
267                 s = strcat(s, strpad(7, argv(LADDER_CNT+1)), "^3| ^7"); // total
268
269                 for(j = 1; j <= min(9, LADDER_CNT); ++j)
270                         { s = strcat(s, strpad(4, argv(j)), "^3| ^7"); } // 1st, 2nd, 3rd etc cnt
271
272                 #if LADDER_CNT > 9
273                 for(j = 10; j <= LADDER_CNT; ++j)
274                         { s = strcat(s, strpad(4, argv(j)), " ^3| ^7"); } // 1st, 2nd, 3rd etc cnt
275                 #endif
276
277                 s = strcat(s, strpad(13, argv(0)), "^3| ^7"); // speed award cnt
278                 s = strcat(s, uid2name(top_uids[i]), "\n"); // name
279         }
280
281         MapInfo_ClearTemps();
282
283         if(s == "")
284                 return "No ladder on this server!\n";
285         else
286                 return strcat("Top ", ftos(LADDER_SIZE), " ladder rankings:\n", s);
287 }
288
289 string getmaplist()
290 {
291         string maplist = "", col;
292         float i, argc;
293
294         argc = tokenize_console(autocvar_g_maplist);
295         for(i = 0; i < argc; ++i)
296         {
297                 if(MapInfo_CheckMap(argv(i)))
298                 {
299                         if(mod(i, 2)) { col = "^2"; }
300                         else { col = "^3"; }
301                         maplist = sprintf("%s%s%s ", maplist, col, argv(i));
302                 }
303         }
304
305         MapInfo_ClearTemps();
306         return sprintf("^7Maps in list: %s\n", maplist);
307 }
308
309
310 string getlsmaps()
311 {
312         string lsmaps = "", col;
313         float i, newmaps = 0;
314
315         for(i = 0; i < MapInfo_count; ++i)
316         {
317                 if((MapInfo_Get_ByID(i)) && !(MapInfo_Map_flags & MapInfo_ForbiddenFlags()))
318                 {
319                         // todo: Check by play count of maps for other game types?
320                         if(
321                                 (g_race && !stof(db_get(ServerProgsDB, strcat(MapInfo_Map_bspname, RACE_RECORD, "time"))))
322                                 ||
323                                 (g_cts && !stof(db_get(ServerProgsDB, strcat(MapInfo_Map_bspname, CTS_RECORD, "time"))))
324                         )
325                         {
326                                 newmaps = TRUE;
327                                 if(mod(i, 2)) { col = "^4*"; }
328                                 else { col = "^5*"; }
329                         }
330                         else
331                         {
332                                 if(mod(i, 2)) { col = "^2"; }
333                                 else { col = "^3"; }
334                         }
335
336                         lsmaps = sprintf("%s%s%s ", lsmaps, col, MapInfo_Map_bspname);
337                 }
338         }
339
340         MapInfo_ClearTemps();
341         return sprintf("^7Maps available%s: %s\n", (newmaps ? " (New maps have asterisks marked in blue)" : ""), lsmaps);
342 }
343
344 string getmonsterlist()
345 {
346         string monsterlist = "", col;
347         float i;
348
349         for(i = MON_FIRST; i <= MON_LAST; ++i)
350         {
351                 if(mod(i, 2)) { col = "^2"; }
352                 else { col = "^3"; }
353                 monsterlist = sprintf("%s%s%s ", monsterlist, col, (get_monsterinfo(i)).netname);
354         }
355
356         return sprintf("^7Monsters available: %s\n", monsterlist);
357 }