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