]> icculus.org git repositories - divverent/nexuiz.git/blob - data/qcsrc/server/gamecommand.qc
fixed important code I killed while trying to kill just debug stuff
[divverent/nexuiz.git] / data / qcsrc / server / gamecommand.qc
1 string GotoMap(string m);
2
3 float FullTraceFraction(vector a, vector mi, vector ma, vector b)
4 {
5         vector c;
6         float white, black;
7
8         white = 0.001;
9         black = 0.001;
10
11         c = a;
12
13         // float n, m;
14         // n = m = 0;
15
16         while(vlen(c - b) > 1)
17         {
18                 //++m;
19
20                 tracebox(c, mi, ma, b, MOVE_WORLDONLY, world);
21                 //++n;
22
23                 if(!trace_startsolid)
24                 {
25                         black += vlen(trace_endpos - c);
26                         c = trace_endpos;
27                 }
28
29                 /* n += */ tracebox_inverted(c, mi, ma, b, MOVE_WORLDONLY, world);
30
31                 white += vlen(trace_endpos - c);
32                 c = trace_endpos;
33         }
34
35         //dprint("FullTraceFraction: ", ftos(n), " total traces, ", ftos(m), " iterations\n");
36
37         return white / (black + white);
38 }
39
40 float RadarMapAtPoint_Trace(float x, float y, float w, float h, float zmin, float zsize, float q)
41 {
42         vector a, b, mi, ma;
43
44         mi = '0 0 0';
45         ma = '1 0 0' * w + '0 1 0' * h;
46         a = '1 0 0' * x + '0 1 0' * y + '0 0 1' * zmin;
47         b = '1 0 0' * x + '0 1 0' * y + '0 0 1' * (zsize + zmin);
48
49         return FullTraceFraction(a, mi, ma, b);
50 }
51 float RadarMapAtPoint_Block(float x, float y, float w, float h, float zmin, float zsize, float q)
52 {
53         vector o, mi, ma;
54         float i, r;
55         vector dz;
56
57         q = 256 * q - 1;
58         // 256q-1 is the ideal sample count to map equal amount of sample values to one pixel value
59
60         mi = '0 0 0';
61         dz = (zsize / q) * '0 0 1';
62         ma = '1 0 0' * w + '0 1 0' * h + dz;
63         o = '1 0 0' * x + '0 1 0' * y + '0 0 1' * zmin;
64
65         if(x < world.absmin_x - w)
66                 return 0;
67         if(y < world.absmin_y - h)
68                 return 0;
69         if(x > world.absmax_x)
70                 return 0;
71         if(y > world.absmax_y)
72                 return 0;
73         
74         r = 0;
75         for(i = 0; i < q; ++i)
76         {
77                 tracebox(o + dz * i, mi, ma, o + dz * i, MOVE_WORLDONLY, world);
78                 if(trace_startsolid)
79                         ++r;
80         }
81         return r / q;
82 }
83 float RadarMapAtPoint_Sample(float x, float y, float w, float h, float zmin, float zsize, float q)
84 {
85         vector a, b, mi, ma;
86
87         q *= 4; // choose q so it matches the regular algorithm in speed
88
89         q = 256 * q - 1;
90         // 256q-1 is the ideal sample count to map equal amount of sample values to one pixel value
91
92         mi = '0 0 0';
93         ma = '1 0 0' * w + '0 1 0' * h;
94         a = '1 0 0' * x + '0 1 0' * y + '0 0 1' * zmin;
95         b = '1 0 0' * w + '0 1 0' * h + '0 0 1' * zsize;
96         
97         float c, i;
98         c = 0;
99
100         for(i = 0; i < q; ++i)
101         {
102                 vector v;
103                 v_x = a_x + random() * b_x;
104                 v_y = a_y + random() * b_y;
105                 v_z = a_z + random() * b_z;
106                 traceline(v, v, MOVE_WORLDONLY, world);
107                 if(trace_startsolid)
108                         ++c;
109         }
110
111         return c / q;
112 }
113
114 // FF is contained twice, to map 256 to FF too
115 // removes the need to bound()
116 string doublehex = "000102030405060708090A0B0C0D0E0F101112131415161718191A1B1C1D1E1F202122232425262728292A2B2C2D2E2F303132333435363738393A3B3C3D3E3F404142434445464748494A4B4C4D4E4F505152535455565758595A5B5C5D5E5F606162636465666768696A6B6C6D6E6F707172737475767778797A7B7C7D7E7F808182838485868788898A8B8C8D8E8F909192939495969798999A9B9C9D9E9FA0A1A2A3A4A5A6A7A8A9AAABACADAEAFB0B1B2B3B4B5B6B7B8B9BABBBCBDBEBFC0C1C2C3C4C5C6C7C8C9CACBCCCDCECFD0D1D2D3D4D5D6D7D8D9DADBDCDDDEDFE0E1E2E3E4E5E6E7E8E9EAEBECEDEEEFF0F1F2F3F4F5F6F7F8F9FAFBFCFDFEFFFF";
117
118 float RADAR_WIDTH_MAX = 2048;
119 float RADAR_HEIGHT_MAX = 2048;
120 float sharpen_buffer[RADAR_WIDTH_MAX * 3];
121
122 void sharpen_set(float x, float v)
123 {
124         sharpen_buffer[x + 2 * RADAR_WIDTH_MAX] = v;
125 }
126
127 float sharpen_getpixel(float x, float y)
128 {
129         if(x < 0)
130                 return 0;
131         if(x >= RADAR_WIDTH_MAX)
132                 return 0;
133         if(y < 0)
134                 return 0;
135         if(y > 2)
136                 return 0;
137         return sharpen_buffer[x + y * RADAR_WIDTH_MAX];
138 }
139
140 float sharpen_get(float x, float a)
141 {
142         float sum;
143         sum = sharpen_getpixel(x, 1);
144         if(a == 0)
145                 return sum;
146         sum *= (8 + 1/a);
147         sum -= sharpen_getpixel(x - 1, 0);
148         sum -= sharpen_getpixel(x - 1, 1);
149         sum -= sharpen_getpixel(x - 1, 2);
150         sum -= sharpen_getpixel(x + 1, 0);
151         sum -= sharpen_getpixel(x + 1, 1);
152         sum -= sharpen_getpixel(x + 1, 2);
153         sum -= sharpen_getpixel(x, 0);
154         sum -= sharpen_getpixel(x, 2);
155         return bound(0, sum * a, 1);
156 }
157
158 void sharpen_shift(float w)
159 {
160         float i;
161         for(i = 0; i < w; ++i)
162         {
163                 sharpen_buffer[i] = sharpen_buffer[i + RADAR_WIDTH_MAX];
164                 sharpen_buffer[i + RADAR_WIDTH_MAX] = sharpen_buffer[i + 2 * RADAR_WIDTH_MAX];
165                 sharpen_buffer[i + 2 * RADAR_WIDTH_MAX] = 0;
166         }
167 }
168
169 void sharpen_init(float w)
170 {
171         float i;
172         for(i = 0; i < w; ++i)
173         {
174                 sharpen_buffer[i] = 0;
175                 sharpen_buffer[i + RADAR_WIDTH_MAX] = 0;
176                 sharpen_buffer[i + 2 * RADAR_WIDTH_MAX] = 0;
177         }
178 }
179
180 entity radarmapper;
181 void RadarMap_Next()
182 {
183         if(radarmapper.count & 4)
184         {
185                 localcmd("quit\n");
186         }
187         else if(radarmapper.count & 2)
188         {
189                 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"));
190                 GotoNextMap();
191         }
192         remove(radarmapper);
193         radarmapper = world;
194 }
195
196 // rough map entity
197 //   cnt: current line
198 //   size: pixel width/height
199 //   maxs: cell width/height
200 //   frame: counter
201 void RadarMap_Think()
202 {
203         float i, x, l;
204         string si;
205
206         if(self.frame == 0)
207         {
208                 // initialize
209                 get_mi_min_max_texcoords(1);
210                 self.mins = mi_picmin;
211                 self.maxs_x = (mi_picmax_x - mi_picmin_x) / self.size_x;
212                 self.maxs_y = (mi_picmax_y - mi_picmin_y) / self.size_y;
213                 self.maxs_z = mi_max_z - mi_min_z;
214                 print("Picture mins/maxs: ", ftos(self.maxs_x), " and ", ftos(self.maxs_y), " should match\n");
215                 self.netname = strzone(strcat("gfx/", mi_shortname, "_radar.xpm"));
216                 if(!(self.count & 1))
217                 {
218                         self.cnt = fopen(self.netname, FILE_READ);
219                         if(self.cnt < 0)
220                                 self.cnt = fopen(strcat("gfx/", mi_shortname, "_radar.tga"), FILE_READ);
221                         if(self.cnt < 0)
222                                 self.cnt = fopen(strcat("gfx/", mi_shortname, "_radar.png"), FILE_READ);
223                         if(self.cnt < 0)
224                                 self.cnt = fopen(strcat("gfx/", mi_shortname, "_radar.jpg"), FILE_READ);
225                         if(self.cnt < 0)
226                                 self.cnt = fopen(strcat("gfx/", mi_shortname, "_mini.tga"), FILE_READ);
227                         if(self.cnt < 0)
228                                 self.cnt = fopen(strcat("gfx/", mi_shortname, "_mini.png"), FILE_READ);
229                         if(self.cnt < 0)
230                                 self.cnt = fopen(strcat("gfx/", mi_shortname, "_mini.jpg"), FILE_READ);
231                         if(self.cnt >= 0)
232                         {
233                                 fclose(self.cnt);
234
235                                 print(self.netname, " already exists, aborting (you may want to specify --force)\n");
236                                 RadarMap_Next();
237                                 return;
238                         }
239                 }
240                 self.cnt = fopen(self.netname, FILE_WRITE);
241                 if(self.cnt < 0)
242                 {
243                         print("Error writing ", self.netname, "\n");
244                         remove(self);
245                         radarmapper = world;
246                         return;
247                 }
248                 print("Writing to ", self.netname, "...\n");
249                 fputs(self.cnt, "/* XPM */\n");
250                 fputs(self.cnt, "static char *RadarMap[] = {\n");
251                 fputs(self.cnt, "/* columns rows colors chars-per-pixel */\n");
252                 fputs(self.cnt, strcat("\"", ftos(self.size_x), " ", ftos(self.size_y), " 256 2\",\n"));
253                 for(i = 0; i < 256; ++i)
254                 {
255                         si = substring(doublehex, i*2, 2);
256                         fputs(self.cnt, strcat("\"", si, " c #", si, si, si, "\",\n"));
257                 }
258                 self.frame += 1;
259                 self.nextthink = time;
260                 sharpen_init(self.size_x);
261         }
262         else if(self.frame <= self.size_y)
263         {
264                 // fill the sharpen buffer with this line
265                 sharpen_shift(self.size_x);
266                 i = self.count & 24;
267
268                 switch(i)
269                 {
270                         case 0:
271                         default:
272                                 for(x = 0; x < self.size_x; ++x)
273                                 {
274                                         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);
275                                         sharpen_set(x, l);
276                                 }
277                                 break;
278                         case 8:
279                                 for(x = 0; x < self.size_x; ++x)
280                                 {
281                                         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);
282                                         sharpen_set(x, l);
283                                 }
284                                 break;
285                         case 16:
286                                 for(x = 0; x < self.size_x; ++x)
287                                 {
288                                         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);
289                                         sharpen_set(x, l);
290                                 }
291                                 break;
292                 }
293
294                 // do we have enough lines?
295                 if(self.frame >= 2)
296                 {
297                         // write a pixel line
298                         fputs(self.cnt, "\"");
299                         for(x = 0; x < self.size_x; ++x)
300                         {
301                                 l = sharpen_get(x, self.ltime);
302                                 fputs(self.cnt, substring(doublehex, 2 * floor(l * 256.0), 2));
303                         }
304                         if(self.frame == self.size_y)
305                                 fputs(self.cnt, "\"\n");
306                         else
307                         {
308                                 fputs(self.cnt, "\",\n");
309                                 print(ftos(self.size_y - self.frame), " lines left\n");
310                         }
311                 }
312
313                 // is this the last line? then write back the missing line
314                 if(self.frame == self.size_y)
315                 {
316                         sharpen_shift(self.size_x);
317                         // write a pixel line
318                         fputs(self.cnt, "\"");
319                         for(x = 0; x < self.size_x; ++x)
320                         {
321                                 l = sharpen_get(x, self.ltime);
322                                 fputs(self.cnt, substring(doublehex, 2 * floor(l * 256.0), 2));
323                         }
324                         if(self.frame == self.size_y)
325                                 fputs(self.cnt, "\"\n");
326                         else
327                         {
328                                 fputs(self.cnt, "\",\n");
329                                 print(ftos(self.size_y - self.frame), " lines left\n");
330                         }
331                 }
332
333                 self.frame += 1;
334                 self.nextthink = time;
335         }
336         else
337         {
338                 // close the file
339                 fputs(self.cnt, "};\n");
340                 fclose(self.cnt);
341                 print("Finished. Please edit data/", self.netname, " with an image editing application and place it in the TGA format in the gfx folder.\n");
342                 RadarMap_Next();
343         }
344 }
345
346 void RadarMap(float argc)
347 {
348         if(radarmapper)
349                 return;
350         float i;
351         radarmapper = spawn();
352         radarmapper.classname = "radarmapper";
353         radarmapper.think = RadarMap_Think;
354         radarmapper.nextthink = time;
355         radarmapper.count = 0;
356         radarmapper.ltime = 1;
357         radarmapper.size_x = 512;
358         radarmapper.size_y = 512;
359         radarmapper.size_z = 1;
360
361         for(i = 1; i < argc; ++i)
362         {
363                 if(argv(i) == "--force")
364                         radarmapper.count |= 1;
365                 else if(argv(i) == "--loop")
366                         radarmapper.count |= 2;
367                 else if(argv(i) == "--quit")
368                         radarmapper.count |= 4;
369                 else if(argv(i) == "--block")
370                 {
371                         radarmapper.count &~= 24;
372                 }
373                 else if(argv(i) == "--trace")
374                 {
375                         radarmapper.count &~= 24;
376                         radarmapper.count |= 8;
377                 }
378                 else if(argv(i) == "--sample")
379                 {
380                         radarmapper.count &~= 24;
381                         radarmapper.count |= 16;
382                 }
383                 else if(argv(i) == "--flags") // for the recursive call
384                 {
385                         ++i;
386                         radarmapper.count = stof(argv(i));
387                 }
388                 else if(argv(i) == "--sharpen") // for the recursive call
389                 {
390                         ++i;
391                         radarmapper.ltime = stof(argv(i));
392                 }
393                 else if(argv(i) == "--res") // resolution
394                 {
395                         ++i;
396                         radarmapper.size_x = stof(argv(i));
397                         ++i;
398                         radarmapper.size_y = stof(argv(i));
399                 }
400                 else if(argv(i) == "--qual") // quality multiplier
401                 {
402                         ++i;
403                         radarmapper.size_z = stof(argv(i));
404                 }
405                 else
406                 {
407                         remove(radarmapper);
408                         radarmapper = world;
409                         print("Usage: sv_cmd radarmap [--force] [--loop] [--quit] [--block | --trace | --sample] [--sharpen N] [--res W H] [--qual Q]\n");
410                         print("The quality factor Q is roughly proportional to the time taken.\n");
411                         print("--trace supports no quality factor; its result should look like --block with infinite quality factor.\n");
412                         print("--block \n");
413                         return;
414                 }
415         }
416
417         print("Radarmap entity spawned.\n");
418 }
419
420 void BBox()
421 {
422         print("Original size: ", ftos(world.absmin_x), " ", ftos(world.absmin_y), " ", ftos(world.absmin_z));
423         print(" ", ftos(world.absmax_x), " ", ftos(world.absmax_y), " ", ftos(world.absmax_z), "\n");
424         print("Currently set size: ", ftos(world.mins_x), " ", ftos(world.mins_y), " ", ftos(world.mins_z));
425         print(" ", ftos(world.maxs_x), " ", ftos(world.maxs_y), " ", ftos(world.maxs_z), "\n");
426         print("Solid bounding box size:");
427
428         tracebox('1 0 0' * world.absmin_x,
429                  '0 1 0' * world.absmin_y + '0 0 1' * world.absmin_z,
430                  '0 1 0' * world.absmax_y + '0 0 1' * world.absmax_z,
431                  '1 0 0' * world.absmax_x,
432                          MOVE_WORLDONLY,
433                          world);
434         if(trace_startsolid)
435                 print(" ", ftos(world.absmin_x));
436         else
437                 print(" ", ftos(trace_endpos_x));
438
439         tracebox('0 1 0' * world.absmin_y,
440                  '1 0 0' * world.absmin_x + '0 0 1' * world.absmin_z,
441                  '1 0 0' * world.absmax_x + '0 0 1' * world.absmax_z,
442                  '0 1 0' * world.absmax_y,
443                          MOVE_WORLDONLY,
444                          world);
445         if(trace_startsolid)
446                 print(" ", ftos(world.absmin_y));
447         else
448                 print(" ", ftos(trace_endpos_y));
449
450         tracebox('0 0 1' * world.absmin_z,
451                  '1 0 0' * world.absmin_x + '0 1 0' * world.absmin_y,
452                  '1 0 0' * world.absmax_x + '0 1 0' * world.absmax_y,
453                  '0 0 1' * world.absmax_z,
454                          MOVE_WORLDONLY,
455                          world);
456         if(trace_startsolid)
457                 print(" ", ftos(world.absmin_z));
458         else
459                 print(" ", ftos(trace_endpos_z));
460
461         tracebox('1 0 0' * world.absmax_x,
462                  '0 1 0' * world.absmin_y + '0 0 1' * world.absmin_z,
463                  '0 1 0' * world.absmax_y + '0 0 1' * world.absmax_z,
464                  '1 0 0' * world.absmin_x,
465                          MOVE_WORLDONLY,
466                          world);
467         if(trace_startsolid)
468                 print(" ", ftos(world.absmax_x));
469         else
470                 print(" ", ftos(trace_endpos_x));
471
472         tracebox('0 1 0' * world.absmax_y,
473                  '1 0 0' * world.absmin_x + '0 0 1' * world.absmin_z,
474                  '1 0 0' * world.absmax_x + '0 0 1' * world.absmax_z,
475                  '0 1 0' * world.absmin_y,
476                          MOVE_WORLDONLY,
477                          world);
478         if(trace_startsolid)
479                 print(" ", ftos(world.absmax_y));
480         else
481                 print(" ", ftos(trace_endpos_y));
482
483         tracebox('0 0 1' * world.absmax_z,
484                  '1 0 0' * world.absmin_x + '0 1 0' * world.absmin_y,
485                  '1 0 0' * world.absmax_x + '0 1 0' * world.absmax_y,
486                  '0 0 1' * world.absmin_z,
487                          MOVE_WORLDONLY,
488                          world);
489         if(trace_startsolid)
490                 print(" ", ftos(world.absmax_z));
491         else
492                 print(" ", ftos(trace_endpos_z));
493
494         print("\n");
495 }
496
497 void EffectIndexDump()
498 {
499         float d;
500         float fh;
501         string s;
502
503         d = db_create();
504
505         print("begin of effects list\n");
506         db_put(d, "TE_GUNSHOT", "1"); print("effect TE_GUNSHOT is ", ftos(particleeffectnum("TE_GUNSHOT")), "\n");
507         db_put(d, "TE_GUNSHOTQUAD", "1"); print("effect TE_GUNSHOTQUAD is ", ftos(particleeffectnum("TE_GUNSHOTQUAD")), "\n");
508         db_put(d, "TE_SPIKE", "1"); print("effect TE_SPIKE is ", ftos(particleeffectnum("TE_SPIKE")), "\n");
509         db_put(d, "TE_SPIKEQUAD", "1"); print("effect TE_SPIKEQUAD is ", ftos(particleeffectnum("TE_SPIKEQUAD")), "\n");
510         db_put(d, "TE_SUPERSPIKE", "1"); print("effect TE_SUPERSPIKE is ", ftos(particleeffectnum("TE_SUPERSPIKE")), "\n");
511         db_put(d, "TE_SUPERSPIKEQUAD", "1"); print("effect TE_SUPERSPIKEQUAD is ", ftos(particleeffectnum("TE_SUPERSPIKEQUAD")), "\n");
512         db_put(d, "TE_WIZSPIKE", "1"); print("effect TE_WIZSPIKE is ", ftos(particleeffectnum("TE_WIZSPIKE")), "\n");
513         db_put(d, "TE_KNIGHTSPIKE", "1"); print("effect TE_KNIGHTSPIKE is ", ftos(particleeffectnum("TE_KNIGHTSPIKE")), "\n");
514         db_put(d, "TE_EXPLOSION", "1"); print("effect TE_EXPLOSION is ", ftos(particleeffectnum("TE_EXPLOSION")), "\n");
515         db_put(d, "TE_EXPLOSIONQUAD", "1"); print("effect TE_EXPLOSIONQUAD is ", ftos(particleeffectnum("TE_EXPLOSIONQUAD")), "\n");
516         db_put(d, "TE_TAREXPLOSION", "1"); print("effect TE_TAREXPLOSION is ", ftos(particleeffectnum("TE_TAREXPLOSION")), "\n");
517         db_put(d, "TE_TELEPORT", "1"); print("effect TE_TELEPORT is ", ftos(particleeffectnum("TE_TELEPORT")), "\n");
518         db_put(d, "TE_LAVASPLASH", "1"); print("effect TE_LAVASPLASH is ", ftos(particleeffectnum("TE_LAVASPLASH")), "\n");
519         db_put(d, "TE_SMALLFLASH", "1"); print("effect TE_SMALLFLASH is ", ftos(particleeffectnum("TE_SMALLFLASH")), "\n");
520         db_put(d, "TE_FLAMEJET", "1"); print("effect TE_FLAMEJET is ", ftos(particleeffectnum("TE_FLAMEJET")), "\n");
521         db_put(d, "EF_FLAME", "1"); print("effect EF_FLAME is ", ftos(particleeffectnum("EF_FLAME")), "\n");
522         db_put(d, "TE_BLOOD", "1"); print("effect TE_BLOOD is ", ftos(particleeffectnum("TE_BLOOD")), "\n");
523         db_put(d, "TE_SPARK", "1"); print("effect TE_SPARK is ", ftos(particleeffectnum("TE_SPARK")), "\n");
524         db_put(d, "TE_PLASMABURN", "1"); print("effect TE_PLASMABURN is ", ftos(particleeffectnum("TE_PLASMABURN")), "\n");
525         db_put(d, "TE_TEI_G3", "1"); print("effect TE_TEI_G3 is ", ftos(particleeffectnum("TE_TEI_G3")), "\n");
526         db_put(d, "TE_TEI_SMOKE", "1"); print("effect TE_TEI_SMOKE is ", ftos(particleeffectnum("TE_TEI_SMOKE")), "\n");
527         db_put(d, "TE_TEI_BIGEXPLOSION", "1"); print("effect TE_TEI_BIGEXPLOSION is ", ftos(particleeffectnum("TE_TEI_BIGEXPLOSION")), "\n");
528         db_put(d, "TE_TEI_PLASMAHIT", "1"); print("effect TE_TEI_PLASMAHIT is ", ftos(particleeffectnum("TE_TEI_PLASMAHIT")), "\n");
529         db_put(d, "EF_STARDUST", "1"); print("effect EF_STARDUST is ", ftos(particleeffectnum("EF_STARDUST")), "\n");
530         db_put(d, "TR_ROCKET", "1"); print("effect TR_ROCKET is ", ftos(particleeffectnum("TR_ROCKET")), "\n");
531         db_put(d, "TR_GRENADE", "1"); print("effect TR_GRENADE is ", ftos(particleeffectnum("TR_GRENADE")), "\n");
532         db_put(d, "TR_BLOOD", "1"); print("effect TR_BLOOD is ", ftos(particleeffectnum("TR_BLOOD")), "\n");
533         db_put(d, "TR_WIZSPIKE", "1"); print("effect TR_WIZSPIKE is ", ftos(particleeffectnum("TR_WIZSPIKE")), "\n");
534         db_put(d, "TR_SLIGHTBLOOD", "1"); print("effect TR_SLIGHTBLOOD is ", ftos(particleeffectnum("TR_SLIGHTBLOOD")), "\n");
535         db_put(d, "TR_KNIGHTSPIKE", "1"); print("effect TR_KNIGHTSPIKE is ", ftos(particleeffectnum("TR_KNIGHTSPIKE")), "\n");
536         db_put(d, "TR_VORESPIKE", "1"); print("effect TR_VORESPIKE is ", ftos(particleeffectnum("TR_VORESPIKE")), "\n");
537         db_put(d, "TR_NEHAHRASMOKE", "1"); print("effect TR_NEHAHRASMOKE is ", ftos(particleeffectnum("TR_NEHAHRASMOKE")), "\n");
538         db_put(d, "TR_NEXUIZPLASMA", "1"); print("effect TR_NEXUIZPLASMA is ", ftos(particleeffectnum("TR_NEXUIZPLASMA")), "\n");
539         db_put(d, "TR_GLOWTRAIL", "1"); print("effect TR_GLOWTRAIL is ", ftos(particleeffectnum("TR_GLOWTRAIL")), "\n");
540         db_put(d, "SVC_PARTICLE", "1"); print("effect SVC_PARTICLE is ", ftos(particleeffectnum("SVC_PARTICLE")), "\n");
541
542         fh = fopen("effectinfo.txt", FILE_READ);
543         while((s = fgets(fh)))
544         {
545                 tokenize_insane(s); // tokenize_sane would hit the loop counter :(
546                 if(argv(0) == "effect")
547                 {
548                         if(db_get(d, argv(1)) != "1")
549                         {
550                                 if(particleeffectnum(argv(1)) >= 0)
551                                         print("effect ", argv(1), " is ", ftos(particleeffectnum(argv(1))), "\n");
552                                 db_put(d, argv(1), "1");
553                         }
554                 }
555         }
556         print("end of effects list\n");
557
558         db_close(d);
559 }
560
561 void make_mapinfo_Think()
562 {
563         if(MapInfo_FilterGametype(MAPINFO_TYPE_ALL, 0, 0, 0, 1))
564         {
565                 print("Done rebuiling mapinfos.\n");
566                 MapInfo_FilterGametype(MapInfo_CurrentGametype(), MapInfo_CurrentFeatures(), 0, (g_maplist_allow_hidden ? MAPINFO_FLAG_HIDDEN : 0), 0);
567                 remove(self);
568         }
569         else
570         {
571                 self.think = make_mapinfo_Think;
572                 self.nextthink = time;
573         }
574 }
575
576 void GameCommand(string command)
577 {
578         float argc;
579         entity client;
580         float entno;
581         argc = tokenize_sane(command);
582
583         if(argv(0) == "help" || argc == 0)
584         {
585                 print("Usage: sv_cmd COMMAND..., where possible commands are:\n");
586                 print("  adminmsg clientnumber \"message\"\n");
587                 print("  teamstatus\n");
588                 print("  printstats\n");
589                 print("  make_mapinfo\n");
590                 print("  gametype dm|ctf|...\n");
591                 print("  savedb filename\n");
592                 print("  dumpdb filename\n");
593                 print("  loaddb filename\n");
594                 print("  allready\n");
595                 print("  effectindexdump\n");
596                 print("  radarmap [--force] [--quit | --loop] [sharpness]\n");
597                 print("  bbox\n");
598                 print("  cvar_changes\n");
599                 print("  find classname\n");
600                 GameCommand_Vote("help", world);
601                 GameCommand_Ban("help");
602                 GameCommand_Generic("help");
603                 return;
604         }
605
606         if(GameCommand_Vote(command, world))
607                 return;
608
609         if(GameCommand_Ban(command))
610                 return;
611
612         if(GameCommand_Generic(command))
613                 return;
614
615         if(argv(0) == "printstats")
616         {
617                 DumpStats(FALSE);
618                 return;
619         }
620
621         if(argv(0) == "make_mapinfo")
622         {
623                 entity e;
624                 e = spawn();
625                 e.classname = "make_mapinfo";
626                 e.think = make_mapinfo_Think;
627                 e.nextthink = time;
628                 MapInfo_Enumerate();
629                 return;
630         }
631
632         if(argv(0) == "warp") if(argc == 2) if(cvar("g_campaign"))
633         {
634                 CampaignLevelWarp(stof(argv(1)));
635                 return;
636         }
637
638         if(argv(0) == "gotomap") if(argc == 2)
639         {
640                 print(GotoMap(argv(1)), "\n");
641                 return;
642         }
643
644         if(argv(0) == "gametype") if(argc == 2)
645         {
646                 float t, tsave;
647                 string s;
648                 s = argv(1);
649                 t = MapInfo_Type_FromString(s);
650                 tsave = MapInfo_CurrentGametype();
651                 if(t)
652                 {
653                         MapInfo_SwitchGameType(t);
654                         MapInfo_FilterGametype(MapInfo_CurrentGametype(), MapInfo_CurrentFeatures(), 0, MAPINFO_FLAG_HIDDEN, 0);
655                         if(MapInfo_count > 0)
656                         {
657                                 bprint("Game type successfully switched to ", s, "\n");
658                                 MapInfo_FilterGametype(MapInfo_CurrentGametype(), MapInfo_CurrentFeatures(), 0, (g_maplist_allow_hidden ? MAPINFO_FLAG_HIDDEN : 0), 0);
659                         }
660                         else
661                         {
662                                 bprint("Cannot use this game type: no map for it found\n");
663                                 MapInfo_SwitchGameType(tsave);
664                                 MapInfo_FilterGametype(MapInfo_CurrentGametype(), MapInfo_CurrentFeatures(), 0, (g_maplist_allow_hidden ? MAPINFO_FLAG_HIDDEN : 0), 0);
665                         }
666                 }
667                 else
668                         bprint("Game type switch to ", s, " failed: this type does not exist!\n");
669                 return;
670         }
671
672         if(argv(0) == "adminmsg") if(argc == 3)
673         {
674                 entno = stof(argv(1));
675                 client = world;
676                 if(entno <= maxclients)
677                         client = edict_num(entno);
678                 if(client.flags & FL_CLIENT)
679                 {
680                         centerprint_atprio(client, CENTERPRIO_ADMIN, strcat("^3SERVER ADMIN:\n\n^7", argv(2)));
681                         sprint(client, strcat("\{1}\{13}^3SERVER ADMIN^7: ", argv(2), "\n"));
682                         print("Message sent to ", client.netname, "\n");
683                 }
684                 else
685                         print("Client not found\n");
686                 return;
687         }
688
689         if(argv(0) == "savedb") if(argc == 2)
690         {
691                 db_save(ServerProgsDB, argv(1));
692                 print("DB saved.\n");
693                 return;
694         }
695
696         if(argv(0) == "dumpdb") if(argc == 2)
697         {
698                 db_dump(ServerProgsDB, argv(1));
699                 print("DB dumped.\n");
700                 return;
701         }
702
703         if(argv(0) == "loaddb") if(argc == 2)
704         {
705                 db_close(ServerProgsDB);
706                 ServerProgsDB = db_load(argv(1));
707                 print("DB loaded.\n");
708                 return;
709         }
710         if (argv(0) == "nospectators")
711         {
712                 blockSpectators = 1;
713                 local entity plr;
714                 FOR_EACH_CLIENT(plr) //give every spectator <g_maxplayers_spectator_blocktime> seconds time to become a player
715                 {
716                         if(plr.classname == "spectator" || plr.classname == "observer")
717                         {
718                                 plr.spectatortime = time;
719                                 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"));
720                         }
721                 }
722                 bprint(strcat("^7All spectators will be automatically kicked when not joining the game after ", ftos(cvar("g_maxplayers_spectator_blocktime")), " seconds!\n"));
723                 return;
724         }
725         if (argv(0) == "lockteams")
726         {
727                 if(teamplay)
728                 {
729                         lockteams = 1;
730                         bprint("^1The teams are now locked.\n");
731                 }
732                 else
733                         bprint("That command can only be used in a team-based gamemode.\n");
734                 return;
735         }
736         if (argv(0) == "unlockteams")
737         {
738                 if(teamplay)
739                 {
740                         lockteams = 0;
741                         bprint("^1The teams are now unlocked.\n");
742                 }
743                 else
744                         bprint("That command can only be used in a team-based gamemode.\n");
745                 return;
746         }
747         if (argv(0) == "movetoteam") if(argc == 3)
748         {
749                 entno = stof(argv(1));
750                 client = world;
751                 if(entno <= maxclients)
752                         client = edict_num(entno);
753                 if(client.flags & FL_CLIENT)
754                 {
755                         float lt;
756                         lt = lockteams;
757                         lockteams = 0;
758
759                         self = client;
760                         SV_ParseClientCommand(strcat("selectteam ", argv(2)));
761
762                         lockteams = lt;
763                 }
764                 else
765                         print("Client not found\n");
766                 return;
767         }
768         if (argv(0) == "teamstatus")
769         {
770                 Score_NicePrint(world);
771                 return;
772         }
773         if (argv(0) == "allready")
774         {
775                 ReadyRestart();
776                 return;
777         }
778         if (argv(0) == "effectindexdump")
779         {
780                 EffectIndexDump();
781                 return;
782         }
783         if (argv(0) == "radarmap")
784         {
785                 RadarMap(argc);
786                 return;
787         }
788         if (argv(0) == "bbox")
789         {
790                 BBox();
791                 return;
792         }
793         if (argv(0) == "cvar_changes")
794         {
795                 print(cvar_changes);
796                 return;
797         }
798         if (argv(0) == "find") if(argc == 2)
799         {
800                 for(client = world; (client = find(client, classname, argv(1))); )
801                         print(etos(client), "\n");
802                 return;
803         }
804         if (argv(0) == "records")
805         {
806                 strunzone(records_reply);
807                 records_reply = strzone(getrecords());
808                 print(records_reply);
809                 return;
810         }
811
812         print("Invalid command. For a list of supported commands, try sv_cmd help.\n");
813 }
814