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