]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/server/gamecommand.qc
Merge commit '54e0ccd220df'
[xonotic/xonotic-data.pk3dir.git] / qcsrc / server / gamecommand.qc
1 string GotoMap(string m);
2 void race_DeleteTime(float pos);
3
4 float FullTraceFraction(vector a, vector mi, vector ma, vector b)
5 {
6         vector c;
7         float white, black;
8
9         white = 0.001;
10         black = 0.001;
11
12         c = a;
13
14         float n, m;
15         n = m = 0;
16
17         while(vlen(c - b) > 1)
18         {
19                 ++m;
20
21                 tracebox(c, mi, ma, b, MOVE_WORLDONLY, world);
22                 ++n;
23
24                 if(!trace_startsolid)
25                 {
26                         black += vlen(trace_endpos - c);
27                         c = trace_endpos;
28                 }
29
30                 n += tracebox_inverted(c, mi, ma, b, MOVE_WORLDONLY, world);
31
32                 white += vlen(trace_endpos - c);
33                 c = trace_endpos;
34         }
35
36         if(n > 200)
37                 dprint("HOLY SHIT! FullTraceFraction: ", ftos(n), " total traces, ", ftos(m), " iterations\n");
38
39         return white / (black + white);
40 }
41
42 float RadarMapAtPoint_Trace(float x, float y, float w, float h, float zmin, float zsize, float q)
43 {
44         vector a, b, mi, ma;
45
46         mi = '0 0 0';
47         ma = '1 0 0' * w + '0 1 0' * h;
48         a = '1 0 0' * x + '0 1 0' * y + '0 0 1' * zmin;
49         b = '1 0 0' * x + '0 1 0' * y + '0 0 1' * (zsize + zmin);
50
51         return FullTraceFraction(a, mi, ma, b);
52 }
53 float RadarMapAtPoint_LineBlock(float x, float y, float w, float h, float zmin, float zsize, float q)
54 {
55         vector o, mi, ma;
56         float i, r;
57         vector dz;
58
59         q = 256 * q - 1;
60         // 256q-1 is the ideal sample count to map equal amount of sample values to one pixel value
61
62         mi = '0 0 0';
63         dz = (zsize / q) * '0 0 1';
64         ma = '1 0 0' * w + '0 1 0' * h + dz;
65         o = '1 0 0' * x + '0 1 0' * y + '0 0 1' * zmin;
66
67         if(x < world.absmin_x - w)
68                 return 0;
69         if(y < world.absmin_y - h)
70                 return 0;
71         if(x > world.absmax_x)
72                 return 0;
73         if(y > world.absmax_y)
74                 return 0;
75
76         r = 0;
77         for(i = 0; i < q; ++i)
78         {
79                 vector v1, v2;
80                 v1 = v2 = o + dz * i + mi;
81                 v1_x += random() * (ma_x - mi_x);
82                 v1_y += random() * (ma_y - mi_y);
83                 v1_z += random() * (ma_z - mi_z);
84                 v2_x += random() * (ma_x - mi_x);
85                 v2_y += random() * (ma_y - mi_y);
86                 v2_z += random() * (ma_z - mi_z);
87                 traceline(v1, v2, MOVE_WORLDONLY, world);
88                 if(trace_startsolid || trace_fraction < 1)
89                         ++r;
90         }
91         return r / q;
92 }
93 float RadarMapAtPoint_Block(float x, float y, float w, float h, float zmin, float zsize, float q)
94 {
95         vector o, mi, ma;
96         float i, r;
97         vector dz;
98
99         q = 256 * q - 1;
100         // 256q-1 is the ideal sample count to map equal amount of sample values to one pixel value
101
102         mi = '0 0 0';
103         dz = (zsize / q) * '0 0 1';
104         ma = '1 0 0' * w + '0 1 0' * h + dz;
105         o = '1 0 0' * x + '0 1 0' * y + '0 0 1' * zmin;
106
107         if(x < world.absmin_x - w)
108                 return 0;
109         if(y < world.absmin_y - h)
110                 return 0;
111         if(x > world.absmax_x)
112                 return 0;
113         if(y > world.absmax_y)
114                 return 0;
115
116         r = 0;
117         for(i = 0; i < q; ++i)
118         {
119                 tracebox(o + dz * i, mi, ma, o + dz * i, MOVE_WORLDONLY, world);
120                 if(trace_startsolid)
121                         ++r;
122         }
123         return r / q;
124 }
125 float RadarMapAtPoint_Sample(float x, float y, float w, float h, float zmin, float zsize, float q)
126 {
127         vector a, b, mi, ma;
128
129         q *= 4; // choose q so it matches the regular algorithm in speed
130
131         q = 256 * q - 1;
132         // 256q-1 is the ideal sample count to map equal amount of sample values to one pixel value
133
134         mi = '0 0 0';
135         ma = '1 0 0' * w + '0 1 0' * h;
136         a = '1 0 0' * x + '0 1 0' * y + '0 0 1' * zmin;
137         b = '1 0 0' * w + '0 1 0' * h + '0 0 1' * zsize;
138
139         float c, i;
140         c = 0;
141
142         for(i = 0; i < q; ++i)
143         {
144                 vector v;
145                 v_x = a_x + random() * b_x;
146                 v_y = a_y + random() * b_y;
147                 v_z = a_z + random() * b_z;
148                 traceline(v, v, MOVE_WORLDONLY, world);
149                 if(trace_startsolid)
150                         ++c;
151         }
152
153         return c / q;
154 }
155
156 // FF is contained twice, to map 256 to FF too
157 // removes the need to bound()
158 string doublehex = "000102030405060708090A0B0C0D0E0F101112131415161718191A1B1C1D1E1F202122232425262728292A2B2C2D2E2F303132333435363738393A3B3C3D3E3F404142434445464748494A4B4C4D4E4F505152535455565758595A5B5C5D5E5F606162636465666768696A6B6C6D6E6F707172737475767778797A7B7C7D7E7F808182838485868788898A8B8C8D8E8F909192939495969798999A9B9C9D9E9FA0A1A2A3A4A5A6A7A8A9AAABACADAEAFB0B1B2B3B4B5B6B7B8B9BABBBCBDBEBFC0C1C2C3C4C5C6C7C8C9CACBCCCDCECFD0D1D2D3D4D5D6D7D8D9DADBDCDDDEDFE0E1E2E3E4E5E6E7E8E9EAEBECEDEEEFF0F1F2F3F4F5F6F7F8F9FAFBFCFDFEFFFF";
159
160 float RADAR_WIDTH_MAX = 2048;
161 float RADAR_HEIGHT_MAX = 2048;
162 float sharpen_buffer[RADAR_WIDTH_MAX * 3];
163
164 void sharpen_set(float x, float v)
165 {
166         sharpen_buffer[x + 2 * RADAR_WIDTH_MAX] = v;
167 }
168
169 float sharpen_getpixel(float x, float y)
170 {
171         if(x < 0)
172                 return 0;
173         if(x >= RADAR_WIDTH_MAX)
174                 return 0;
175         if(y < 0)
176                 return 0;
177         if(y > 2)
178                 return 0;
179         return sharpen_buffer[x + y * RADAR_WIDTH_MAX];
180 }
181
182 float sharpen_get(float x, float a)
183 {
184         float sum;
185         sum = sharpen_getpixel(x, 1);
186         if(a == 0)
187                 return sum;
188         sum *= (8 + 1/a);
189         sum -= sharpen_getpixel(x - 1, 0);
190         sum -= sharpen_getpixel(x - 1, 1);
191         sum -= sharpen_getpixel(x - 1, 2);
192         sum -= sharpen_getpixel(x + 1, 0);
193         sum -= sharpen_getpixel(x + 1, 1);
194         sum -= sharpen_getpixel(x + 1, 2);
195         sum -= sharpen_getpixel(x, 0);
196         sum -= sharpen_getpixel(x, 2);
197         return bound(0, sum * a, 1);
198 }
199
200 void sharpen_shift(float w)
201 {
202         float i;
203         for(i = 0; i < w; ++i)
204         {
205                 sharpen_buffer[i] = sharpen_buffer[i + RADAR_WIDTH_MAX];
206                 sharpen_buffer[i + RADAR_WIDTH_MAX] = sharpen_buffer[i + 2 * RADAR_WIDTH_MAX];
207                 sharpen_buffer[i + 2 * RADAR_WIDTH_MAX] = 0;
208         }
209 }
210
211 void sharpen_init(float w)
212 {
213         float i;
214         for(i = 0; i < w; ++i)
215         {
216                 sharpen_buffer[i] = 0;
217                 sharpen_buffer[i + RADAR_WIDTH_MAX] = 0;
218                 sharpen_buffer[i + 2 * RADAR_WIDTH_MAX] = 0;
219         }
220 }
221
222 entity radarmapper;
223 void RadarMap_Next()
224 {
225         if(radarmapper.count & 4)
226         {
227                 localcmd("quit\n");
228         }
229         else if(radarmapper.count & 2)
230         {
231                 localcmd(strcat("defer 1 \"sv_cmd radarmap --flags ", ftos(radarmapper.count), strcat(" --res ", ftos(radarmapper.size_x), " ", ftos(radarmapper.size_y), " --sharpen ", ftos(radarmapper.ltime), " --qual ", ftos(radarmapper.size_z)), "\"\n"));
232                 GotoNextMap();
233         }
234         remove(radarmapper);
235         radarmapper = world;
236 }
237
238 // rough map entity
239 //   cnt: current line
240 //   size: pixel width/height
241 //   maxs: cell width/height
242 //   frame: counter
243 void RadarMap_Think()
244 {
245         float i, x, l;
246         string si;
247
248         if(self.frame == 0)
249         {
250                 // initialize
251                 get_mi_min_max_texcoords(1);
252                 self.mins = mi_picmin;
253                 self.maxs_x = (mi_picmax_x - mi_picmin_x) / self.size_x;
254                 self.maxs_y = (mi_picmax_y - mi_picmin_y) / self.size_y;
255                 self.maxs_z = mi_max_z - mi_min_z;
256                 print("Picture mins/maxs: ", ftos(self.maxs_x), " and ", ftos(self.maxs_y), " should match\n");
257                 self.netname = strzone(strcat("gfx/", mi_shortname, "_radar.xpm"));
258                 if(!(self.count & 1))
259                 {
260                         self.cnt = fopen(self.netname, FILE_READ);
261                         if(self.cnt < 0)
262                                 self.cnt = fopen(strcat("gfx/", mi_shortname, "_radar.tga"), FILE_READ);
263                         if(self.cnt < 0)
264                                 self.cnt = fopen(strcat("gfx/", mi_shortname, "_radar.png"), FILE_READ);
265                         if(self.cnt < 0)
266                                 self.cnt = fopen(strcat("gfx/", mi_shortname, "_radar.jpg"), FILE_READ);
267                         if(self.cnt < 0)
268                                 self.cnt = fopen(strcat("gfx/", mi_shortname, "_mini.tga"), FILE_READ);
269                         if(self.cnt < 0)
270                                 self.cnt = fopen(strcat("gfx/", mi_shortname, "_mini.png"), FILE_READ);
271                         if(self.cnt < 0)
272                                 self.cnt = fopen(strcat("gfx/", mi_shortname, "_mini.jpg"), FILE_READ);
273                         if(self.cnt >= 0)
274                         {
275                                 fclose(self.cnt);
276
277                                 print(self.netname, " already exists, aborting (you may want to specify --force)\n");
278                                 RadarMap_Next();
279                                 return;
280                         }
281                 }
282                 self.cnt = fopen(self.netname, FILE_WRITE);
283                 if(self.cnt < 0)
284                 {
285                         print("Error writing ", self.netname, "\n");
286                         remove(self);
287                         radarmapper = world;
288                         return;
289                 }
290                 print("Writing to ", self.netname, "...\n");
291                 fputs(self.cnt, "/* XPM */\n");
292                 fputs(self.cnt, "static char *RadarMap[] = {\n");
293                 fputs(self.cnt, "/* columns rows colors chars-per-pixel */\n");
294                 fputs(self.cnt, strcat("\"", ftos(self.size_x), " ", ftos(self.size_y), " 256 2\",\n"));
295                 for(i = 0; i < 256; ++i)
296                 {
297                         si = substring(doublehex, i*2, 2);
298                         fputs(self.cnt, strcat("\"", si, " c #", si, si, si, "\",\n"));
299                 }
300                 self.frame += 1;
301                 self.nextthink = time;
302                 sharpen_init(self.size_x);
303         }
304         else if(self.frame <= self.size_y)
305         {
306                 // fill the sharpen buffer with this line
307                 sharpen_shift(self.size_x);
308                 i = self.count & 24;
309
310                 switch(i)
311                 {
312                         case 0:
313                         default:
314                                 for(x = 0; x < self.size_x; ++x)
315                                 {
316                                         l = RadarMapAtPoint_Block(self.mins_x + x * self.maxs_x, self.mins_y + (self.size_y - self.frame) * self.maxs_y, self.maxs_x, self.maxs_y, self.mins_z, self.maxs_z, self.size_z);
317                                         sharpen_set(x, l);
318                                 }
319                                 break;
320                         case 8:
321                                 for(x = 0; x < self.size_x; ++x)
322                                 {
323                                         l = RadarMapAtPoint_Trace(self.mins_x + x * self.maxs_x, self.mins_y + (self.size_y - self.frame) * self.maxs_y, self.maxs_x, self.maxs_y, self.mins_z, self.maxs_z, self.size_z);
324                                         sharpen_set(x, l);
325                                 }
326                                 break;
327                         case 16:
328                                 for(x = 0; x < self.size_x; ++x)
329                                 {
330                                         l = RadarMapAtPoint_Sample(self.mins_x + x * self.maxs_x, self.mins_y + (self.size_y - self.frame) * self.maxs_y, self.maxs_x, self.maxs_y, self.mins_z, self.maxs_z, self.size_z);
331                                         sharpen_set(x, l);
332                                 }
333                                 break;
334                         case 24:
335                                 for(x = 0; x < self.size_x; ++x)
336                                 {
337                                         l = RadarMapAtPoint_LineBlock(self.mins_x + x * self.maxs_x, self.mins_y + (self.size_y - self.frame) * self.maxs_y, self.maxs_x, self.maxs_y, self.mins_z, self.maxs_z, self.size_z);
338                                         sharpen_set(x, l);
339                                 }
340                                 break;
341                 }
342
343                 // do we have enough lines?
344                 if(self.frame >= 2)
345                 {
346                         // write a pixel line
347                         fputs(self.cnt, "\"");
348                         for(x = 0; x < self.size_x; ++x)
349                         {
350                                 l = sharpen_get(x, self.ltime);
351                                 fputs(self.cnt, substring(doublehex, 2 * floor(l * 256.0), 2));
352                         }
353                         if(self.frame == self.size_y)
354                                 fputs(self.cnt, "\"\n");
355                         else
356                         {
357                                 fputs(self.cnt, "\",\n");
358                                 print(ftos(self.size_y - self.frame), " lines left\n");
359                         }
360                 }
361
362                 // is this the last line? then write back the missing line
363                 if(self.frame == self.size_y)
364                 {
365                         sharpen_shift(self.size_x);
366                         // write a pixel line
367                         fputs(self.cnt, "\"");
368                         for(x = 0; x < self.size_x; ++x)
369                         {
370                                 l = sharpen_get(x, self.ltime);
371                                 fputs(self.cnt, substring(doublehex, 2 * floor(l * 256.0), 2));
372                         }
373                         if(self.frame == self.size_y)
374                                 fputs(self.cnt, "\"\n");
375                         else
376                         {
377                                 fputs(self.cnt, "\",\n");
378                                 print(ftos(self.size_y - self.frame), " lines left\n");
379                         }
380                 }
381
382                 self.frame += 1;
383                 self.nextthink = time;
384         }
385         else
386         {
387                 // close the file
388                 fputs(self.cnt, "};\n");
389                 fclose(self.cnt);
390                 print("Finished. Please edit data/", self.netname, " with an image editing application and place it in the TGA format in the gfx folder.\n");
391                 RadarMap_Next();
392         }
393 }
394
395 void RadarMap(float argc)
396 {
397         if(radarmapper)
398                 return;
399         float i;
400         radarmapper = spawn();
401         radarmapper.classname = "radarmapper";
402         radarmapper.think = RadarMap_Think;
403         radarmapper.nextthink = time;
404         radarmapper.count = 8; // default to the --trace method, as it is faster now
405         radarmapper.ltime = 1;
406         radarmapper.size_x = 512;
407         radarmapper.size_y = 512;
408         radarmapper.size_z = 1;
409
410         for(i = 1; i < argc; ++i)
411         {
412                 if(argv(i) == "--force")
413                         radarmapper.count |= 1;
414                 else if(argv(i) == "--loop")
415                         radarmapper.count |= 2;
416                 else if(argv(i) == "--quit")
417                         radarmapper.count |= 4;
418                 else if(argv(i) == "--block")
419                 {
420                         radarmapper.count &~= 24;
421                 }
422                 else if(argv(i) == "--trace")
423                 {
424                         radarmapper.count &~= 24;
425                         radarmapper.count |= 8;
426                 }
427                 else if(argv(i) == "--sample")
428                 {
429                         radarmapper.count &~= 24;
430                         radarmapper.count |= 16;
431                 }
432                 else if(argv(i) == "--lineblock")
433                 {
434                         radarmapper.count |= 24;
435                 }
436                 else if(argv(i) == "--flags") // for the recursive call
437                 {
438                         ++i;
439                         radarmapper.count = stof(argv(i));
440                 }
441                 else if(argv(i) == "--sharpen") // for the recursive call
442                 {
443                         ++i;
444                         radarmapper.ltime = stof(argv(i));
445                 }
446                 else if(argv(i) == "--res") // resolution
447                 {
448                         ++i;
449                         radarmapper.size_x = stof(argv(i));
450                         ++i;
451                         radarmapper.size_y = stof(argv(i));
452                 }
453                 else if(argv(i) == "--qual") // quality multiplier
454                 {
455                         ++i;
456                         radarmapper.size_z = stof(argv(i));
457                 }
458                 else
459                 {
460                         remove(radarmapper);
461                         radarmapper = world;
462                         print("Usage: sv_cmd radarmap [--force] [--loop] [--quit] [--block | --trace | --sample | --lineblock] [--sharpen N] [--res W H] [--qual Q]\n");
463                         print("The quality factor Q is roughly proportional to the time taken.\n");
464                         print("--trace supports no quality factor; its result should look like --block with infinite quality factor.\n");
465                         print("--block \n");
466                         return;
467                 }
468         }
469
470         print("Radarmap entity spawned.\n");
471 }
472
473 void BBox()
474 {
475         print("Original size: ", ftos(world.absmin_x), " ", ftos(world.absmin_y), " ", ftos(world.absmin_z));
476         print(" ", ftos(world.absmax_x), " ", ftos(world.absmax_y), " ", ftos(world.absmax_z), "\n");
477         print("Currently set size: ", ftos(world.mins_x), " ", ftos(world.mins_y), " ", ftos(world.mins_z));
478         print(" ", ftos(world.maxs_x), " ", ftos(world.maxs_y), " ", ftos(world.maxs_z), "\n");
479         print("Solid bounding box size:");
480
481         tracebox('1 0 0' * world.absmin_x,
482                  '0 1 0' * world.absmin_y + '0 0 1' * world.absmin_z,
483                  '0 1 0' * world.absmax_y + '0 0 1' * world.absmax_z,
484                  '1 0 0' * world.absmax_x,
485                          MOVE_WORLDONLY,
486                          world);
487         if(trace_startsolid)
488                 print(" ", ftos(world.absmin_x));
489         else
490                 print(" ", ftos(trace_endpos_x));
491
492         tracebox('0 1 0' * world.absmin_y,
493                  '1 0 0' * world.absmin_x + '0 0 1' * world.absmin_z,
494                  '1 0 0' * world.absmax_x + '0 0 1' * world.absmax_z,
495                  '0 1 0' * world.absmax_y,
496                          MOVE_WORLDONLY,
497                          world);
498         if(trace_startsolid)
499                 print(" ", ftos(world.absmin_y));
500         else
501                 print(" ", ftos(trace_endpos_y));
502
503         tracebox('0 0 1' * world.absmin_z,
504                  '1 0 0' * world.absmin_x + '0 1 0' * world.absmin_y,
505                  '1 0 0' * world.absmax_x + '0 1 0' * world.absmax_y,
506                  '0 0 1' * world.absmax_z,
507                          MOVE_WORLDONLY,
508                          world);
509         if(trace_startsolid)
510                 print(" ", ftos(world.absmin_z));
511         else
512                 print(" ", ftos(trace_endpos_z));
513
514         tracebox('1 0 0' * world.absmax_x,
515                  '0 1 0' * world.absmin_y + '0 0 1' * world.absmin_z,
516                  '0 1 0' * world.absmax_y + '0 0 1' * world.absmax_z,
517                  '1 0 0' * world.absmin_x,
518                          MOVE_WORLDONLY,
519                          world);
520         if(trace_startsolid)
521                 print(" ", ftos(world.absmax_x));
522         else
523                 print(" ", ftos(trace_endpos_x));
524
525         tracebox('0 1 0' * world.absmax_y,
526                  '1 0 0' * world.absmin_x + '0 0 1' * world.absmin_z,
527                  '1 0 0' * world.absmax_x + '0 0 1' * world.absmax_z,
528                  '0 1 0' * world.absmin_y,
529                          MOVE_WORLDONLY,
530                          world);
531         if(trace_startsolid)
532                 print(" ", ftos(world.absmax_y));
533         else
534                 print(" ", ftos(trace_endpos_y));
535
536         tracebox('0 0 1' * world.absmax_z,
537                  '1 0 0' * world.absmin_x + '0 1 0' * world.absmin_y,
538                  '1 0 0' * world.absmax_x + '0 1 0' * world.absmax_y,
539                  '0 0 1' * world.absmin_z,
540                          MOVE_WORLDONLY,
541                          world);
542         if(trace_startsolid)
543                 print(" ", ftos(world.absmax_z));
544         else
545                 print(" ", ftos(trace_endpos_z));
546
547         print("\n");
548 }
549
550 void EffectIndexDump()
551 {
552         float d;
553         float fh;
554         string s;
555
556         d = db_create();
557
558         print("begin of effects list\n");
559         db_put(d, "TE_GUNSHOT", "1"); print("effect TE_GUNSHOT is ", ftos(particleeffectnum("TE_GUNSHOT")), "\n");
560         db_put(d, "TE_GUNSHOTQUAD", "1"); print("effect TE_GUNSHOTQUAD is ", ftos(particleeffectnum("TE_GUNSHOTQUAD")), "\n");
561         db_put(d, "TE_SPIKE", "1"); print("effect TE_SPIKE is ", ftos(particleeffectnum("TE_SPIKE")), "\n");
562         db_put(d, "TE_SPIKEQUAD", "1"); print("effect TE_SPIKEQUAD is ", ftos(particleeffectnum("TE_SPIKEQUAD")), "\n");
563         db_put(d, "TE_SUPERSPIKE", "1"); print("effect TE_SUPERSPIKE is ", ftos(particleeffectnum("TE_SUPERSPIKE")), "\n");
564         db_put(d, "TE_SUPERSPIKEQUAD", "1"); print("effect TE_SUPERSPIKEQUAD is ", ftos(particleeffectnum("TE_SUPERSPIKEQUAD")), "\n");
565         db_put(d, "TE_WIZSPIKE", "1"); print("effect TE_WIZSPIKE is ", ftos(particleeffectnum("TE_WIZSPIKE")), "\n");
566         db_put(d, "TE_KNIGHTSPIKE", "1"); print("effect TE_KNIGHTSPIKE is ", ftos(particleeffectnum("TE_KNIGHTSPIKE")), "\n");
567         db_put(d, "TE_EXPLOSION", "1"); print("effect TE_EXPLOSION is ", ftos(particleeffectnum("TE_EXPLOSION")), "\n");
568         db_put(d, "TE_EXPLOSIONQUAD", "1"); print("effect TE_EXPLOSIONQUAD is ", ftos(particleeffectnum("TE_EXPLOSIONQUAD")), "\n");
569         db_put(d, "TE_TAREXPLOSION", "1"); print("effect TE_TAREXPLOSION is ", ftos(particleeffectnum("TE_TAREXPLOSION")), "\n");
570         db_put(d, "TE_TELEPORT", "1"); print("effect TE_TELEPORT is ", ftos(particleeffectnum("TE_TELEPORT")), "\n");
571         db_put(d, "TE_LAVASPLASH", "1"); print("effect TE_LAVASPLASH is ", ftos(particleeffectnum("TE_LAVASPLASH")), "\n");
572         db_put(d, "TE_SMALLFLASH", "1"); print("effect TE_SMALLFLASH is ", ftos(particleeffectnum("TE_SMALLFLASH")), "\n");
573         db_put(d, "TE_FLAMEJET", "1"); print("effect TE_FLAMEJET is ", ftos(particleeffectnum("TE_FLAMEJET")), "\n");
574         db_put(d, "EF_FLAME", "1"); print("effect EF_FLAME is ", ftos(particleeffectnum("EF_FLAME")), "\n");
575         db_put(d, "TE_BLOOD", "1"); print("effect TE_BLOOD is ", ftos(particleeffectnum("TE_BLOOD")), "\n");
576         db_put(d, "TE_SPARK", "1"); print("effect TE_SPARK is ", ftos(particleeffectnum("TE_SPARK")), "\n");
577         db_put(d, "TE_PLASMABURN", "1"); print("effect TE_PLASMABURN is ", ftos(particleeffectnum("TE_PLASMABURN")), "\n");
578         db_put(d, "TE_TEI_G3", "1"); print("effect TE_TEI_G3 is ", ftos(particleeffectnum("TE_TEI_G3")), "\n");
579         db_put(d, "TE_TEI_SMOKE", "1"); print("effect TE_TEI_SMOKE is ", ftos(particleeffectnum("TE_TEI_SMOKE")), "\n");
580         db_put(d, "TE_TEI_BIGEXPLOSION", "1"); print("effect TE_TEI_BIGEXPLOSION is ", ftos(particleeffectnum("TE_TEI_BIGEXPLOSION")), "\n");
581         db_put(d, "TE_TEI_PLASMAHIT", "1"); print("effect TE_TEI_PLASMAHIT is ", ftos(particleeffectnum("TE_TEI_PLASMAHIT")), "\n");
582         db_put(d, "EF_STARDUST", "1"); print("effect EF_STARDUST is ", ftos(particleeffectnum("EF_STARDUST")), "\n");
583         db_put(d, "TR_ROCKET", "1"); print("effect TR_ROCKET is ", ftos(particleeffectnum("TR_ROCKET")), "\n");
584         db_put(d, "TR_GRENADE", "1"); print("effect TR_GRENADE is ", ftos(particleeffectnum("TR_GRENADE")), "\n");
585         db_put(d, "TR_BLOOD", "1"); print("effect TR_BLOOD is ", ftos(particleeffectnum("TR_BLOOD")), "\n");
586         db_put(d, "TR_WIZSPIKE", "1"); print("effect TR_WIZSPIKE is ", ftos(particleeffectnum("TR_WIZSPIKE")), "\n");
587         db_put(d, "TR_SLIGHTBLOOD", "1"); print("effect TR_SLIGHTBLOOD is ", ftos(particleeffectnum("TR_SLIGHTBLOOD")), "\n");
588         db_put(d, "TR_KNIGHTSPIKE", "1"); print("effect TR_KNIGHTSPIKE is ", ftos(particleeffectnum("TR_KNIGHTSPIKE")), "\n");
589         db_put(d, "TR_VORESPIKE", "1"); print("effect TR_VORESPIKE is ", ftos(particleeffectnum("TR_VORESPIKE")), "\n");
590         db_put(d, "TR_NEHAHRASMOKE", "1"); print("effect TR_NEHAHRASMOKE is ", ftos(particleeffectnum("TR_NEHAHRASMOKE")), "\n");
591         db_put(d, "TR_NEXUIZPLASMA", "1"); print("effect TR_NEXUIZPLASMA is ", ftos(particleeffectnum("TR_NEXUIZPLASMA")), "\n");
592         db_put(d, "TR_GLOWTRAIL", "1"); print("effect TR_GLOWTRAIL is ", ftos(particleeffectnum("TR_GLOWTRAIL")), "\n");
593         db_put(d, "SVC_PARTICLE", "1"); print("effect SVC_PARTICLE is ", ftos(particleeffectnum("SVC_PARTICLE")), "\n");
594
595         fh = fopen("effectinfo.txt", FILE_READ);
596         while((s = fgets(fh)))
597         {
598                 tokenize(s); // tokenize_console would hit the loop counter :(
599                 if(argv(0) == "effect")
600                 {
601                         if(db_get(d, argv(1)) != "1")
602                         {
603                                 if(particleeffectnum(argv(1)) >= 0)
604                                         print("effect ", argv(1), " is ", ftos(particleeffectnum(argv(1))), "\n");
605                                 db_put(d, argv(1), "1");
606                         }
607                 }
608         }
609         print("end of effects list\n");
610
611         db_close(d);
612 }
613
614 void make_mapinfo_Think()
615 {
616         if(MapInfo_FilterGametype(MAPINFO_TYPE_ALL, 0, 0, 0, 1))
617         {
618                 print("Done rebuiling mapinfos.\n");
619                 MapInfo_FilterGametype(MapInfo_CurrentGametype(), MapInfo_CurrentFeatures(), MapInfo_RequiredFlags(), MapInfo_ForbiddenFlags(), 0);
620                 remove(self);
621         }
622         else
623         {
624                 self.think = make_mapinfo_Think;
625                 self.nextthink = time;
626         }
627 }
628
629 void GameCommand(string command)
630 {
631         float argc;
632         entity client, e;
633         vector v;
634         float entno, i, n;
635         string s;
636         argc = tokenize_console(command);
637
638         if(argv(0) == "help" || argc == 0)
639         {
640                 print("Usage: sv_cmd COMMAND..., where possible commands are:\n");
641                 print("  adminmsg clientnumber \"message\"\n");
642                 print("  teamstatus\n");
643                 print("  printstats\n");
644                 print("  make_mapinfo\n");
645                 print("  gametype dm|ctf|...\n");
646                 print("  savedb filename\n");
647                 print("  dumpdb filename\n");
648                 print("  loaddb filename\n");
649                 print("  allready\n");
650                 print("  effectindexdump\n");
651                 print("  radarmap [--force] [--quit | --loop] [sharpness]\n");
652                 print("  bbox\n");
653                 print("  cvar_changes\n");
654                 print("  find classname\n");
655                 GameCommand_Vote("help", world);
656                 GameCommand_Ban("help");
657                 GameCommand_Generic("help");
658                 return;
659         }
660
661         if(GameCommand_Vote(command, world))
662                 return;
663
664         if(GameCommand_Ban(command))
665                 return;
666
667         if(GameCommand_Generic(command))
668                 return;
669
670         if(argv(0) == "printstats")
671         {
672                 DumpStats(FALSE);
673                 return;
674         }
675
676         if(argv(0) == "make_mapinfo")
677         {
678                 e = spawn();
679                 e.classname = "make_mapinfo";
680                 e.think = make_mapinfo_Think;
681                 e.nextthink = time;
682                 MapInfo_Enumerate();
683                 return;
684         }
685
686         if(argv(0) == "gotomap") if(argc == 2)
687         {
688                 print(GotoMap(argv(1)), "\n");
689                 return;
690         }
691
692         if(argv(0) == "gametype") if(argc == 2)
693         {
694                 float t, tsave;
695                 s = argv(1);
696                 t = MapInfo_Type_FromString(s);
697                 tsave = MapInfo_CurrentGametype();
698                 if(t)
699                 {
700                         MapInfo_SwitchGameType(t);
701                         MapInfo_FilterGametype(MapInfo_CurrentGametype(), MapInfo_CurrentFeatures(), MapInfo_RequiredFlags(), MapInfo_ForbiddenFlags(), 0);
702                         if(MapInfo_count > 0)
703                         {
704                                 bprint("Game type successfully switched to ", s, "\n");
705                         }
706                         else
707                         {
708                                 bprint("Cannot use this game type: no map for it found\n");
709                                 MapInfo_SwitchGameType(tsave);
710                                 MapInfo_FilterGametype(MapInfo_CurrentGametype(), MapInfo_CurrentFeatures(), MapInfo_RequiredFlags(), MapInfo_ForbiddenFlags(), 0);
711                         }
712                 }
713                 else
714                         bprint("Game type switch to ", s, " failed: this type does not exist!\n");
715                 return;
716         }
717
718         if(argv(0) == "adminmsg")
719         if(argc == 3)
720         {
721                 entno = stof(argv(1));
722
723                 if((entno < 1) | (entno > maxclients)) {
724                         print("Player ", argv(1), " doesn't exist\n");
725                         return;
726                 }
727
728                 client = edict_num(entno);
729
730                 if(client.flags & FL_CLIENT)
731                 {
732                         centerprint_atprio(client, CENTERPRIO_ADMIN, strcat("^3", admin_name(), ":\n\n^7", argv(2)));
733                         sprint(client, strcat("\{1}\{13}^3", admin_name(), "^7: ", argv(2), "\n"));
734                         print("Message sent to ", client.netname, "\n");
735                 }
736                 else
737                         print("Client not found\n");
738
739                 return;
740         }
741
742         if(argv(0) == "savedb") if(argc == 2)
743         {
744                 db_save(ServerProgsDB, argv(1));
745                 print("DB saved.\n");
746                 return;
747         }
748
749         if(argv(0) == "dumpdb") if(argc == 2)
750         {
751                 db_dump(ServerProgsDB, argv(1));
752                 print("DB dumped.\n");
753                 return;
754         }
755
756         if(argv(0) == "loaddb") if(argc == 2)
757         {
758                 db_close(ServerProgsDB);
759                 ServerProgsDB = db_load(argv(1));
760                 print("DB loaded.\n");
761                 return;
762         }
763
764         if (argv(0) == "nospectators")
765         {
766                 blockSpectators = 1;
767                 local entity plr;
768                 FOR_EACH_CLIENT(plr) //give every spectator <g_maxplayers_spectator_blocktime> seconds time to become a player
769                 {
770                         if(plr.classname == "spectator" || plr.classname == "observer")
771                         {
772                                 plr.spectatortime = time;
773                                 sprint(plr, strcat("^7You have to become a player within the next ", ftos(cvar("g_maxplayers_spectator_blocktime")), " seconds, otherwise you will be kicked, because spectators aren't allowed at this time!\n"));
774                         }
775                 }
776                 bprint(strcat("^7All spectators will be automatically kicked when not joining the game after ", ftos(cvar("g_maxplayers_spectator_blocktime")), " seconds!\n"));
777                 return;
778         }
779
780         if (argv(0) == "lockteams")
781         {
782                 if(teams_matter)
783                 {
784                         lockteams = 1;
785                         bprint("^1The teams are now locked.\n");
786                 }
787                 else
788                         bprint("That command can only be used in a team-based gamemode.\n");
789                 return;
790         }
791
792         if (argv(0) == "unlockteams")
793         {
794                 if(teams_matter)
795                 {
796                         lockteams = 0;
797                         bprint("^1The teams are now unlocked.\n");
798                 }
799                 else
800                         bprint("That command can only be used in a team-based gamemode.\n");
801                 return;
802         }
803         if(argv(0) == "movetoteam")
804         if(argc == 3 || argc == 4) {
805 //      sv_cmd movetoteam  player_id  team_colour
806 //      sv_cmd movetoteam  player_id  team_colour  type_of_move
807
808 //      type of move
809 //      0 (00) automove centerprint, admin message
810 //      1 (01) automove centerprint, no admin message
811 //      2 (10) no centerprint, admin message
812 //      3 (11) no centerprint, no admin message
813
814                 if(!teams_matter) {  // death match
815                         print("Currently not playing a team game\n");
816                         return;
817                 }
818
819                 entno = stof(argv(1));
820
821                 // player_id is out of range
822                 if((entno < 1) | (entno > maxclients)) {
823                         print("Player ", argv(1), " doesn't exist\n");
824                         return;
825                 }
826
827                         client = edict_num(entno);
828
829                 // player entity is not a client
830                 if not(client.flags & FL_CLIENT) {
831                         print("Player ", argv(1), " doesn't exist\n");
832                         return;
833                 }
834
835                 // find the team to move the player to
836                 float team_colour;
837
838                 team_colour = ColourToNumber(argv(2));
839
840                 if(team_colour == client.team) {  // player already on the team
841                         print("Player ", argv(1), " (", client.netname, ") is already on the ", ColoredTeamName(client.team), "\n");
842                         return;
843                 } else if(team_colour == 0)  // auto team
844                         team_colour = NumberToTeamNumber(FindSmallestTeam(client, FALSE));
845
846                 switch(team_colour) {
847                         case COLOR_TEAM1:
848                                 if(c1 == -1) {
849                                         print("Sorry, there isn't a red team\n");
850                                         return;
851                 }
852                         break;
853
854                         case COLOR_TEAM2:
855                                 if(c2 == -1) {
856                                         print("Sorry, there isn't a blue team\n");
857                 return;
858         }
859                         break;
860
861                         case COLOR_TEAM3:
862                                 if(c3 == -1) {
863                                         print("Sorry, there isn't a yellow team\n");
864                                         return;
865                                 }
866                         break;
867
868                         case COLOR_TEAM4:
869                                 if(c4 == -1) {
870                                         print("Sorry, there isn't a pink team\n");
871                                         return;
872                                 }
873                         break;
874
875                         default:
876                                 print("Sorry, team ", argv(2), " doesn't exist\n");
877                                 return;
878                 }
879                 print("Player ", argv(1), " (", client.netname, ") has been moved to the ", ColoredTeamName(team_colour), "\n");
880
881                 MoveToTeam(client, team_colour, 6, stof(argv(3)));
882
883                 return;
884         }
885         if (argv(0) == "teamstatus")
886         {
887                 Score_NicePrint(world);
888                 return;
889         }
890         if (argv(0) == "allready")
891         {
892                 ReadyRestart();
893                 return;
894         }
895         if (argv(0) == "effectindexdump")
896         {
897                 EffectIndexDump();
898                 return;
899         }
900         if (argv(0) == "radarmap")
901         {
902                 RadarMap(argc);
903                 return;
904         }
905         if (argv(0) == "bbox")
906         {
907                 BBox();
908                 return;
909         }
910         if (argv(0) == "cvar_changes")
911         {
912                 print(cvar_changes);
913                 return;
914         }
915         if (argv(0) == "find") if(argc == 2)
916         {
917                 for(client = world; (client = find(client, classname, argv(1))); )
918                         print(etos(client), "\n");
919                 return;
920         }
921         if (argv(0) == "records")
922         {
923                 for (i = 0; i < 10; ++i)
924                         print(records_reply[i]);
925                 return;
926         }
927         if (argv(0) == "rankings")
928         {
929                 strunzone(rankings_reply);
930                 rankings_reply = strzone(getrankings());
931                 print(rankings_reply);
932                 return;
933         }
934
935         if(argv(0) == "cointoss")
936         {
937                 bprint("^3Throwing coin... Result: ");
938                 if (random() > 0.5)
939                         bprint("^1heads ^3!\n");
940                 else
941                         bprint("^1tails ^3!\n");
942                 return;
943         }
944
945         if(argv(0) == "__FORCE_READY_RESTART")
946         {
947                 reset_map(FALSE);
948                 return;
949         }
950
951         if(argv(0) == "debug_shotorg")
952         {
953                 debug_shotorg = stov(argv(1));
954                 return;
955         }
956
957         if(argv(0) == "gettaginfo") if(argc >= 4)
958         {
959                 e = spawn();
960                 if(argv(1) == "w")
961                         setmodel(e, (nextent(world)).weaponentity.model);
962                 else
963                         setmodel(e, argv(1));
964                 e.frame = stof(argv(2));
965                 i = gettagindex(e, argv(3));
966                 if(i)
967                 {
968                         v = gettaginfo(e, i);
969                         print("model ", e.model, " frame ", ftos(e.frame), " tag ", argv(3));
970                         print(" index = ", ftos(i));
971                         print(" vector = ", ftos(v_x), " ", ftos(v_y), " ", ftos(v_z), "\n");
972                         if(argc >= 6)
973                         {
974                                 v_y = -v_y;
975                                 localcmd(strcat(argv(4), vtos(v), argv(5), "\n"));
976                         }
977                 }
978                 else
979                         print("bone not found\n");
980                 remove(e);
981                 return;
982         }
983
984         if(argv(0) == "time")
985         {
986                 print("time = ", ftos(time), "\n");
987                 print("frame start = ", ftos(gettime(GETTIME_FRAMESTART)), "\n");
988                 print("realtime = ", ftos(gettime(GETTIME_REALTIME)), "\n");
989                 print("hires = ", ftos(gettime(GETTIME_HIRES)), "\n");
990                 print("uptime = ", ftos(gettime(GETTIME_UPTIME)), "\n");
991                 print("localtime = ", strftime(TRUE, "%a %b %e %H:%M:%S %Z %Y"), "\n");
992                 print("gmtime = ", strftime(FALSE, "%a %b %e %H:%M:%S %Z %Y"), "\n");
993                 return;
994         }
995
996         if(argv(0) == "tracebug")
997         {
998                 print("TEST CASE. If this returns the runaway loop counter error, possibly everything is oaky.\n");
999                 for(;;)
1000                 {
1001                         vector org, delta, start, end, p, q, q0, pos;
1002                         float safe, unsafe, dq, dqf;
1003
1004                         org = world.mins;
1005                         delta = world.maxs - world.mins;
1006
1007                         start_x = org_x + random() * delta_x;
1008                         start_y = org_y + random() * delta_y;
1009                         start_z = org_z + random() * delta_z;
1010
1011                         end_x = org_x + random() * delta_x;
1012                         end_y = org_y + random() * delta_y;
1013                         end_z = org_z + random() * delta_z;
1014
1015                         start = stov(vtos(start));
1016                         end = stov(vtos(end));
1017
1018                         tracebox(start, PL_MIN, PL_MAX, end, MOVE_NOMONSTERS, world);
1019                         if(!trace_startsolid)
1020                         {
1021                                 p = trace_endpos;
1022                                 tracebox(p, PL_MIN, PL_MAX, p, MOVE_NOMONSTERS, world);
1023                                 if(trace_startsolid || trace_fraction == 1)
1024                                 {
1025                                         rint(42); // do an engine breakpoint on VM_rint so you can get the trace that errnoeously returns startsolid
1026                                         tracebox(start, PL_MIN, PL_MAX, end, MOVE_NOMONSTERS, world);
1027                                         tracebox(p, PL_MIN, PL_MAX, q, MOVE_NOMONSTERS, world);
1028
1029                                         if(trace_startsolid)
1030                                         {
1031                                                 // how much do we need to back off?
1032                                                 safe = 1;
1033                                                 unsafe = 0;
1034                                                 for(;;)
1035                                                 {
1036                                                         pos = p * (1 - (safe + unsafe) * 0.5) + start * ((safe + unsafe) * 0.5);
1037                                                         tracebox(pos, PL_MIN, PL_MAX, pos, MOVE_NOMONSTERS, world);
1038                                                         if(trace_startsolid)
1039                                                         {
1040                                                                 if((safe + unsafe) * 0.5 == unsafe)
1041                                                                         break;
1042                                                                 unsafe = (safe + unsafe) * 0.5;
1043                                                         }
1044                                                         else
1045                                                         {
1046                                                                 if((safe + unsafe) * 0.5 == safe)
1047                                                                         break;
1048                                                                 safe = (safe + unsafe) * 0.5;
1049                                                         }
1050                                                 }
1051
1052                                                 print("safe distance to back off: ", ftos(safe * vlen(p - start)), "qu\n");
1053                                                 print("unsafe distance to back off: ", ftos(unsafe * vlen(p - start)), "qu\n");
1054
1055                                                 tracebox(p, PL_MIN + '0.1 0.1 0.1', PL_MAX - '0.1 0.1 0.1', p, MOVE_NOMONSTERS, world);
1056                                                 if(trace_startsolid)
1057                                                         print("trace_endpos much in solid when tracing from ", vtos(start), " to ", vtos(end), " endpos ", vtos(p), "\n");
1058                                                 else
1059                                                         print("trace_endpos just in solid when tracing from ", vtos(start), " to ", vtos(end), " endpos ", vtos(p), "\n");
1060                                                 break;
1061                                         }
1062
1063                                         q0 = p;
1064                                         dq = 0;
1065                                         dqf = 1;
1066                                         for(;;)
1067                                         {
1068                                                 q = p + normalize(end - p) * (dq + dqf);
1069                                                 if(q == q0)
1070                                                         break;
1071                                                 tracebox(p, PL_MIN, PL_MAX, q, MOVE_NOMONSTERS, world);
1072                                                 if(trace_startsolid)
1073                                                         error("THIS ONE cannot happen");
1074                                                 if(trace_fraction > 0)
1075                                                         dq += dqf * trace_fraction;
1076                                                 dqf *= 0.5;
1077                                                 q0 = q;
1078                                         }
1079                                         if(dq > 0)
1080                                         {
1081                                                 print("trace_endpos still before solid when tracing from ", vtos(start), " to ", vtos(end), " endpos ", vtos(p), "\n");
1082                                                 print("could go ", ftos(dq), " units further to ", vtos(q), "\n");
1083                                                 break;
1084                                         }
1085                                 }
1086                         }
1087                 }
1088         }
1089
1090         if(argv(0) == "tracebug2")
1091         {
1092                 e = nextent(world);
1093                 float f;
1094                 vector vv, dv;
1095                 tracebox(e.origin + '0 0 32', e.mins, e.maxs, e.origin + '0 0 -1024', MOVE_NORMAL, e);
1096                 vv = trace_endpos;
1097                 if(trace_fraction == 1)
1098                 {
1099                         print("not above ground, aborting\n");
1100                         return;
1101                 }
1102                 f = 0;
1103                 for(i = 0; i < 100000; ++i)
1104                 {
1105                         dv = randomvec();
1106                         if(dv_z > 0)
1107                                 dv = -1 * dv;
1108                         tracebox(vv, e.mins, e.maxs, vv + dv, MOVE_NORMAL, e);
1109                         if(trace_startsolid)
1110                                 print("bug 1\n");
1111                         if(trace_fraction == 1)
1112                         if(dv_z < f)
1113                         {
1114                                 print("bug 2: ", ftos(dv_x), " ", ftos(dv_y), " ", ftos(dv_z));
1115                                 print(" (", ftos(asin(dv_z / vlen(dv)) * 180 / M_PI), " degrees)\n");
1116                                 f = dv_z;
1117                         }
1118                 }
1119                 print("highest possible dist: ", ftos(f), "\n");
1120                 return;
1121         }
1122
1123         if(argv(0) == "tracewalk")
1124         {
1125                 e = nextent(world);
1126                 if(tracewalk(e, stov(argv(1)), e.mins, e.maxs, stov(argv(2)), MOVE_NORMAL))
1127                         print("can walk\n");
1128                 else
1129                         print("cannot walk\n");
1130                 return;
1131         }
1132
1133         if(argv(0) == "onslaught_updatelinks")
1134         {
1135                 onslaught_updatelinks();
1136                 print("ONS links updated\n");
1137                 return;
1138         }
1139
1140         if(argv(0) == "bot_cmd")
1141         {
1142                 local entity bot;
1143
1144                 if(argv(1) == "help")
1145                 {
1146                         if(argc==2)
1147                         {
1148                                 bot_list_commands();
1149                                 print("\nsv_cmd bot_cmd reset          #Clear the cmd queues of all bots\n");
1150                                 print("sv_cmd bot_cmd load <file>    #Load script file\n");
1151                                 print("\nUse sv_cmd bot_cmd help <command> for more\n\n");
1152                                 return;
1153                         }
1154
1155                         bot_cmdhelp(argv(2));
1156                         return;
1157                 }
1158
1159                 // Clear all bot queues
1160                 if(argv(1) == "reset")
1161                 {
1162                         bot_resetqueues();
1163                         return;
1164                 }
1165
1166                 // Load cmds from file
1167                 if(argv(1) == "load" && argc == 3)
1168                 {
1169                         float fh;
1170                         fh = fopen(argv(2), FILE_READ);
1171                         if(fh < 0)
1172                         {
1173                                 print("cannot open the file\n");
1174                                 return;
1175                         }
1176
1177                         i = 0;
1178                         while((s = fgets(fh)))
1179                         {
1180                                 argc = tokenize_console(s);
1181
1182                                 if(argc >= 3 && argv(0) == "sv_cmd" && argv(1) == "bot_cmd")
1183                                 {
1184                                         // let's start at token 2 so we can skip sv_cmd bot_cmd
1185                                         bot = find_bot_by_number(stof(argv(2)));
1186                                         if(bot == world)
1187                                                 bot = find_bot_by_name(argv(2));
1188                                         if(bot)
1189                                                 bot_queuecommand(bot, strcat(argv(3), " ", argv(4)));
1190                                 }
1191                                 else
1192                                         localcmd(strcat(s, "\n"));
1193
1194                                 ++i;
1195                         }
1196
1197                         print(ftos(i), " commands read\n");
1198
1199                         fclose(fh);
1200
1201                         return;
1202                 }
1203
1204                 if(argc < 3)
1205                 {
1206                         print("Usage: sv_cmd bot_cmd <bot name or number> <command> [argument]\n");
1207                         print("Examples: bot_cmd <id> cc \"say something\"\n");
1208                         print("          bot_cmd <id> presskey jump\n");
1209                         print("          .. or sv_cmd bot_cmd help <command> for more\n");
1210                         return;
1211                 }
1212
1213                 bot = find_bot_by_number(stof(argv(1)));
1214                 if(bot == world)
1215                         bot = find_bot_by_name(argv(1));
1216
1217                 if(bot)
1218                         bot_queuecommand(bot, strcat(argv(2), " ", argv(3)));
1219                 else
1220                         print(strcat("Error: Unable to find a bot with the name or number '",argv(1),"'\n"));
1221
1222                 return;
1223         }
1224
1225         if(argv(0) == "playerdemo")
1226         {
1227                 if(argv(1) == "read")
1228                 {
1229                         entno = stof(argv(2));
1230                         if((entno < 1) | (entno > maxclients)) {
1231                                 print("Player ", argv(2), " doesn't exist\n");
1232                                 return;
1233                         }
1234                         client = edict_num(entno);
1235                         if(clienttype(client) != CLIENTTYPE_BOT) {
1236                                 print("Player ", client.netname, " is not a bot\n");
1237                                 return;
1238                         }
1239                         self = client;
1240                         playerdemo_open_read(argv(3));
1241                         return;
1242                 }
1243                 else if(argv(1) == "write")
1244                 {
1245                         entno = stof(argv(2));
1246                         if((entno < 1) | (entno > maxclients)) {
1247                                 print("Player ", argv(2), " doesn't exist\n");
1248                                 return;
1249                         }
1250                         client = edict_num(entno);
1251                         self = client;
1252                         playerdemo_open_write(argv(3));
1253                         return;
1254                 }
1255                 else if(argv(1) == "auto_read_and_write")
1256                 {
1257                         s = argv(2);
1258                         n = stof(argv(3));
1259                         cvar_set("bot_number", ftos(n));
1260                         localcmd("wait; wait; wait\n");
1261                         for(i = 0; i < n; ++i)
1262                                 localcmd("sv_cmd playerdemo read ", ftos(i+2), " ", s, ftos(i+1), "\n");
1263                         localcmd("sv_cmd playerdemo write 1 ", ftos(n+1), "\n");
1264                         return;
1265                 }
1266                 else if(argv(1) == "auto_read")
1267                 {
1268                         s = argv(2);
1269                         n = stof(argv(3));
1270                         cvar_set("bot_number", ftos(n));
1271                         localcmd("wait; wait; wait\n");
1272                         for(i = 0; i < n; ++i)
1273                                 localcmd("sv_cmd playerdemo read ", ftos(i+2), " ", s, ftos(i+1), "\n");
1274                         return;
1275                 }
1276         }
1277
1278         if(argv(0) == "anticheat")
1279         {
1280                 entno = stof(argv(1));
1281                 if((entno < 1) | (entno > maxclients)) {
1282                         print("Player ", argv(1), " doesn't exist\n");
1283                         return;
1284                 }
1285                 client = edict_num(entno);
1286                 if(clienttype(client) != CLIENTTYPE_REAL && clienttype(client) != CLIENTTYPE_BOT) {
1287                         print("Player ", client.netname, " is not active\n");
1288                         return;
1289                 }
1290                 self = client;
1291                 anticheat_report();
1292                 return;
1293         }
1294
1295         if(argv(0) == "defer_clear")
1296         if(argc == 2)
1297         {
1298                 entno = stof(argv(1));
1299
1300                 // player_id is out of range
1301                 if((entno < 1) | (entno > maxclients)) {
1302                         print("Player ", argv(1), " doesn't exist\n");
1303                         return;
1304                 }
1305
1306                 client = edict_num(entno);
1307
1308                 if not(client.flags & FL_CLIENT) {
1309                         print("Player ", argv(1), " doesn't exist\n");
1310                         return;
1311                 }
1312
1313                 if(clienttype(client) == CLIENTTYPE_BOT) {
1314                         print("Player ", argv(1), " (", client.netname, ") is a bot\n");
1315                         return;
1316                 }
1317
1318                 stuffcmd(client, "defer clear\n");
1319                 print("defer clear stuffed to ", argv(1), " (", client.netname, ")\n");
1320                 return;
1321         }
1322
1323         if(argv(0) == "defer_clear_all")
1324         {
1325                 FOR_EACH_CLIENTSLOT(client)
1326                         GameCommand(strcat("defer_clear ", ftos(num_for_edict(client))));       
1327
1328                 return;
1329         }
1330         if(argv(0) == "delrec")
1331         {
1332                 race_DeleteTime(stof(argv(1)));
1333                 return;
1334         }
1335
1336         if(argv(0) == "showtraceline")
1337         {
1338                 vector src, dst;
1339                 src = stov(argv(1));
1340                 dst = stov(argv(2));
1341                 traceline(src, dst, MOVE_NORMAL, world);
1342                 trailparticles(world, particleeffectnum("TR_NEXUIZPLASMA"), src, trace_endpos);
1343                 trailparticles(world, particleeffectnum("TR_CRYLINKPLASMA"), trace_endpos, dst);
1344                 return;
1345         }
1346
1347         print("Invalid command. For a list of supported commands, try sv_cmd help.\n");
1348 }
1349