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