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