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