]> icculus.org git repositories - divverent/nexuiz.git/blob - data/qcsrc/server/gamecommand.qc
experimental feature (sv_)cmd cvar_changes, should list all changed cvars of the...
[divverent/nexuiz.git] / data / qcsrc / server / gamecommand.qc
1 string GotoMap(string m);
2
3 #if 0
4 // TODO make this algorithm work (no idea why it is failing), it would be much faster
5 float FullTraceFraction(vector a, vector mi, vector ma, vector b)
6 {
7         vector c;
8         float d;
9         if(a_z > b_z)
10                 return 0;
11         tracebox(a, mi, ma, b, MOVE_WORLDONLY, world);
12         if(trace_startsolid)
13         {
14                 // a leaves solid, then hits trace_endpos
15                 // where does a leave solid?
16                 c = trace_endpos;
17                 tracebox(c, mi, ma, a, MOVE_WORLDONLY, world);
18                 // a to trace_endpos is solid
19                 // trace_endpos to c is not solid
20                 d = trace_endpos_z - a_z;
21                 return FullTraceFraction(c + '0 0 1', mi, ma, b) + d;
22         }
23         else
24         {
25                 // a hits trace_endpos
26                 return FullTraceFraction(trace_endpos + '0 0 1', mi, ma, b);
27         }
28 }
29
30 float RoughMapAtPoint(float x, float y, float w, float h)
31 {
32         vector a, b, mi, ma;
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' * world.mins_z;
36         b = '1 0 0' * x + '0 1 0' * y + '0 0 1' * world.maxs_z;
37         return floor(FullTraceFraction(a, mi, ma, b) / (world.maxs_z - world.mins_z) * 255);
38 }
39 #else
40 float RoughMapAtPoint(float x, float y, float w, float h)
41 {
42         vector o, mi, ma;
43         float i, r;
44         vector dz;
45         mi = '0 0 0';
46         dz = ((world.maxs_z - world.mins_z) / 64) * '0 0 1';
47         ma = '1 0 0' * w + '0 1 0' * h + dz;
48         o = '1 0 0' * x + '0 1 0' * y + '0 0 1' * world.mins_z;
49         
50         r = 0;
51         for(i = 0; i < 51; ++i)
52         {
53                 tracebox(o + dz * i, mi, ma, o + dz * i, MOVE_WORLDONLY, world);
54                 if(trace_startsolid)
55                         ++r;
56         }
57         return r * 5; // 0 .. 255
58 }
59 #endif
60
61 string doublehex = "000102030405060708090A0B0C0D0E0F101112131415161718191A1B1C1D1E1F202122232425262728292A2B2C2D2E2F303132333435363738393A3B3C3D3E3F404142434445464748494A4B4C4D4E4F505152535455565758595A5B5C5D5E5F606162636465666768696A6B6C6D6E6F707172737475767778797A7B7C7D7E7F808182838485868788898A8B8C8D8E8F909192939495969798999A9B9C9D9E9FA0A1A2A3A4A5A6A7A8A9AAABACADAEAFB0B1B2B3B4B5B6B7B8B9BABBBCBDBEBFC0C1C2C3C4C5C6C7C8C9CACBCCCDCECFD0D1D2D3D4D5D6D7D8D9DADBDCDDDEDFE0E1E2E3E4E5E6E7E8E9EAEBECEDEEEFF0F1F2F3F4F5F6F7F8F9FAFBFCFDFEFF";
62
63 void RoughMap()
64 {
65         float x0, y0, w, h;
66         float m, n;
67         float x, y;
68         float l;
69         float f;
70         float i;
71         string si;
72         string fn;
73
74         m = 256;
75         n = 256;
76
77         x0 = world.mins_x;
78         y0 = world.mins_y;
79         w = (world.maxs_x - x0) / m;
80         h = (world.maxs_y - y0) / n;
81         // TODO fix aspect
82         w = h = max(w, h);
83
84         /*
85         m = min(m, ceil((world.maxs_x - x0) / w));
86         n = min(n, ceil((world.maxs_y - y0) / h));
87         */
88
89         fn = strcat("maps/", mapname, ".xpm");
90         f = fopen(fn, FILE_WRITE);
91         if(f < 0)
92         {
93                 print("Error writing ", fn, "\n");
94                 return;
95         }
96         print("Writing to ", fn, "...\n");
97         fputs(f, "/* XPM */\n");
98         fputs(f, "static char *RoughMap[] = {\n");
99         fputs(f, "/* columns rows colors chars-per-pixel */\n");
100         fputs(f, strcat("\"", ftos(m), " ", ftos(n), " 256 2\",\n"));
101         for(i = 0; i < 256; ++i)
102         {
103                 si = substring(doublehex, i*2, 2);
104                 fputs(f, strcat("\"", si, " c #", si, si, si, "\",\n"));
105         }
106         for(y = n-1; y >= 0; --y)
107         {
108                 fputs(f, "\"");
109                 for(x = 0; x < m; ++x)
110                 {
111                         l = RoughMapAtPoint(x0 + x * w, y0 + y * h, w, h);
112                         fputs(f, substring(doublehex, 2 * l, 2));
113                 }
114                 if(y == 0)
115                         fputs(f, "\"\n");
116                 else
117                 {
118                         fputs(f, "\",\n");
119                         print(ftos(y), " lines left\n");
120                 }
121         }
122         fputs(f, "};\n");
123         print("Finished. Please edit data/", fn, " with an image editing application and place it with the name XXX in the TGA format in the same folder as the BSP file.\n");
124 }
125
126 void EffectIndexDump()
127 {
128         float d;
129         float fh;
130         string s;
131
132         d = db_create();
133
134         print("begin of effects list\n");
135         db_put(d, "TE_GUNSHOT", "1"); print("effect TE_GUNSHOT is ", ftos(particleeffectnum("TE_GUNSHOT")), "\n");
136         db_put(d, "TE_GUNSHOTQUAD", "1"); print("effect TE_GUNSHOTQUAD is ", ftos(particleeffectnum("TE_GUNSHOTQUAD")), "\n");
137         db_put(d, "TE_SPIKE", "1"); print("effect TE_SPIKE is ", ftos(particleeffectnum("TE_SPIKE")), "\n");
138         db_put(d, "TE_SPIKEQUAD", "1"); print("effect TE_SPIKEQUAD is ", ftos(particleeffectnum("TE_SPIKEQUAD")), "\n");
139         db_put(d, "TE_SUPERSPIKE", "1"); print("effect TE_SUPERSPIKE is ", ftos(particleeffectnum("TE_SUPERSPIKE")), "\n");
140         db_put(d, "TE_SUPERSPIKEQUAD", "1"); print("effect TE_SUPERSPIKEQUAD is ", ftos(particleeffectnum("TE_SUPERSPIKEQUAD")), "\n");
141         db_put(d, "TE_WIZSPIKE", "1"); print("effect TE_WIZSPIKE is ", ftos(particleeffectnum("TE_WIZSPIKE")), "\n");
142         db_put(d, "TE_KNIGHTSPIKE", "1"); print("effect TE_KNIGHTSPIKE is ", ftos(particleeffectnum("TE_KNIGHTSPIKE")), "\n");
143         db_put(d, "TE_EXPLOSION", "1"); print("effect TE_EXPLOSION is ", ftos(particleeffectnum("TE_EXPLOSION")), "\n");
144         db_put(d, "TE_EXPLOSIONQUAD", "1"); print("effect TE_EXPLOSIONQUAD is ", ftos(particleeffectnum("TE_EXPLOSIONQUAD")), "\n");
145         db_put(d, "TE_TAREXPLOSION", "1"); print("effect TE_TAREXPLOSION is ", ftos(particleeffectnum("TE_TAREXPLOSION")), "\n");
146         db_put(d, "TE_TELEPORT", "1"); print("effect TE_TELEPORT is ", ftos(particleeffectnum("TE_TELEPORT")), "\n");
147         db_put(d, "TE_LAVASPLASH", "1"); print("effect TE_LAVASPLASH is ", ftos(particleeffectnum("TE_LAVASPLASH")), "\n");
148         db_put(d, "TE_SMALLFLASH", "1"); print("effect TE_SMALLFLASH is ", ftos(particleeffectnum("TE_SMALLFLASH")), "\n");
149         db_put(d, "TE_FLAMEJET", "1"); print("effect TE_FLAMEJET is ", ftos(particleeffectnum("TE_FLAMEJET")), "\n");
150         db_put(d, "EF_FLAME", "1"); print("effect EF_FLAME is ", ftos(particleeffectnum("EF_FLAME")), "\n");
151         db_put(d, "TE_BLOOD", "1"); print("effect TE_BLOOD is ", ftos(particleeffectnum("TE_BLOOD")), "\n");
152         db_put(d, "TE_SPARK", "1"); print("effect TE_SPARK is ", ftos(particleeffectnum("TE_SPARK")), "\n");
153         db_put(d, "TE_PLASMABURN", "1"); print("effect TE_PLASMABURN is ", ftos(particleeffectnum("TE_PLASMABURN")), "\n");
154         db_put(d, "TE_TEI_G3", "1"); print("effect TE_TEI_G3 is ", ftos(particleeffectnum("TE_TEI_G3")), "\n");
155         db_put(d, "TE_TEI_SMOKE", "1"); print("effect TE_TEI_SMOKE is ", ftos(particleeffectnum("TE_TEI_SMOKE")), "\n");
156         db_put(d, "TE_TEI_BIGEXPLOSION", "1"); print("effect TE_TEI_BIGEXPLOSION is ", ftos(particleeffectnum("TE_TEI_BIGEXPLOSION")), "\n");
157         db_put(d, "TE_TEI_PLASMAHIT", "1"); print("effect TE_TEI_PLASMAHIT is ", ftos(particleeffectnum("TE_TEI_PLASMAHIT")), "\n");
158         db_put(d, "EF_STARDUST", "1"); print("effect EF_STARDUST is ", ftos(particleeffectnum("EF_STARDUST")), "\n");
159         db_put(d, "TR_ROCKET", "1"); print("effect TR_ROCKET is ", ftos(particleeffectnum("TR_ROCKET")), "\n");
160         db_put(d, "TR_GRENADE", "1"); print("effect TR_GRENADE is ", ftos(particleeffectnum("TR_GRENADE")), "\n");
161         db_put(d, "TR_BLOOD", "1"); print("effect TR_BLOOD is ", ftos(particleeffectnum("TR_BLOOD")), "\n");
162         db_put(d, "TR_WIZSPIKE", "1"); print("effect TR_WIZSPIKE is ", ftos(particleeffectnum("TR_WIZSPIKE")), "\n");
163         db_put(d, "TR_SLIGHTBLOOD", "1"); print("effect TR_SLIGHTBLOOD is ", ftos(particleeffectnum("TR_SLIGHTBLOOD")), "\n");
164         db_put(d, "TR_KNIGHTSPIKE", "1"); print("effect TR_KNIGHTSPIKE is ", ftos(particleeffectnum("TR_KNIGHTSPIKE")), "\n");
165         db_put(d, "TR_VORESPIKE", "1"); print("effect TR_VORESPIKE is ", ftos(particleeffectnum("TR_VORESPIKE")), "\n");
166         db_put(d, "TR_NEHAHRASMOKE", "1"); print("effect TR_NEHAHRASMOKE is ", ftos(particleeffectnum("TR_NEHAHRASMOKE")), "\n");
167         db_put(d, "TR_NEXUIZPLASMA", "1"); print("effect TR_NEXUIZPLASMA is ", ftos(particleeffectnum("TR_NEXUIZPLASMA")), "\n");
168         db_put(d, "TR_GLOWTRAIL", "1"); print("effect TR_GLOWTRAIL is ", ftos(particleeffectnum("TR_GLOWTRAIL")), "\n");
169         db_put(d, "SVC_PARTICLE", "1"); print("effect SVC_PARTICLE is ", ftos(particleeffectnum("SVC_PARTICLE")), "\n");
170
171         fh = fopen("effectinfo.txt", FILE_READ);
172         while((s = fgets(fh)))
173         {
174                 tokenize(s);
175                 if(argv(0) == "effect")
176                 {
177                         if(db_get(d, argv(1)) != "1")
178                         {
179                                 if(particleeffectnum(argv(1)) >= 0)
180                                         print("effect ", argv(1), " is ", ftos(particleeffectnum(argv(1))), "\n");
181                                 db_put(d, argv(1), "1");
182                         }
183                 }
184         }
185         print("end of effects list\n");
186
187         db_close(d);
188 }
189
190 void make_mapinfo_Think()
191 {
192         if(MapInfo_FilterGametype(MAPINFO_TYPE_ALL, 0, 1))
193         {
194                 print("Done rebuiling mapinfos.\n");
195                 MapInfo_FilterGametype(MapInfo_CurrentGametype(), MapInfo_CurrentFeatures(), 0);
196                 remove(self);
197         }
198         else
199         {
200                 self.think = make_mapinfo_Think;
201                 self.nextthink = time;
202         }
203 }
204
205 void GameCommand(string command)
206 {
207         float argc;
208         entity client;
209         float entno;
210         argc = tokenize(command);
211
212         if(argv(0) == "help" || argc == 0)
213         {
214                 print("Usage: sv_cmd COMMAND..., where possible commands are:\n");
215                 print("  adminmsg clientnumber \"message\"\n");
216                 print("  teamstatus\n");
217                 print("  printstats\n");
218                 print("  make_mapinfo\n");
219                 print("  gametype dm|ctf|...\n");
220                 print("  savedb filename\n");
221                 print("  dumpdb filename\n");
222                 print("  loaddb filename\n");
223                 print("  allready\n");
224                 print("  effectindexdump\n");
225                 print("  roughmap\n");
226                 GameCommand_Vote("help", world);
227                 GameCommand_Ban("help");
228                 GameCommand_Generic("help");
229                 return;
230         }
231
232         if(GameCommand_Vote(command, world))
233                 return;
234
235         if(GameCommand_Ban(command))
236                 return;
237
238         if(GameCommand_Generic(command))
239                 return;
240
241         if(argv(0) == "printstats")
242         {
243                 DumpStats(FALSE);
244                 return;
245         }
246
247         if(argv(0) == "make_mapinfo")
248         {
249                 entity e;
250                 e = spawn();
251                 e.classname = "make_mapinfo";
252                 e.think = make_mapinfo_Think;
253                 e.nextthink = time;
254                 MapInfo_Enumerate();
255                 return;
256         }
257
258         if(argv(0) == "warp") if(argc == 2) if(cvar("g_campaign"))
259         {
260                 CampaignLevelWarp(stof(argv(1)));
261                 return;
262         }
263
264         if(argv(0) == "gotomap") if(argc == 2)
265         {
266                 print(GotoMap(argv(1)), "\n");
267                 return;
268         }
269
270         if(argv(0) == "gametype") if(argc == 2)
271         {
272                 float t, tsave;
273                 string s;
274                 s = argv(1);
275                 t = MapInfo_Type_FromString(s);
276                 tsave = MapInfo_CurrentGametype();
277                 if(t)
278                 {
279                         MapInfo_SwitchGameType(t);
280                         MapInfo_FilterGametype(MapInfo_CurrentGametype(), MapInfo_CurrentFeatures(), 0);
281                         if(MapInfo_count > 0)
282                         {
283                                 bprint("Game type successfully switched to ", s, "\n");
284                         }
285                         else
286                         {
287                                 bprint("Cannot use this game type: no map for it found\n");
288                                 MapInfo_SwitchGameType(tsave);
289                                 MapInfo_FilterGametype(MapInfo_CurrentGametype(), MapInfo_CurrentFeatures(), 0);
290                         }
291                 }
292                 else
293                         bprint("Game type switch to ", s, " failed: this type does not exist!\n");
294                 return;
295         }
296
297         if(argv(0) == "adminmsg") if(argc == 3)
298         {
299                 entno = stof(argv(1));
300                 client = world;
301                 if(entno <= maxclients)
302                         client = edict_num(entno);
303                 if(client.flags & FL_CLIENT)
304                 {
305                         centerprint_atprio(client, CENTERPRIO_ADMIN, strcat("^3SERVER ADMIN:\n\n^7", argv(2)));
306                         sprint(client, strcat("\{1}\{13}^3SERVER ADMIN^7: ", argv(2), "\n"));
307                         print("Message sent to ", client.netname, "\n");
308                 }
309                 else
310                         print("Client not found\n");
311                 return;
312         }
313
314         if(argv(0) == "savedb") if(argc == 2)
315         {
316                 db_save(ServerProgsDB, argv(1));
317                 print("DB saved.\n");
318                 return;
319         }
320
321         if(argv(0) == "dumpdb") if(argc == 2)
322         {
323                 db_dump(ServerProgsDB, argv(1));
324                 print("DB dumped.\n");
325                 return;
326         }
327
328         if(argv(0) == "loaddb") if(argc == 2)
329         {
330                 db_close(ServerProgsDB);
331                 ServerProgsDB = db_load(argv(1));
332                 print("DB loaded.\n");
333                 return;
334         }
335         if (argv(0) == "nospectators")
336         {
337                 blockSpectators = 1;
338                 local entity plr;
339                 FOR_EACH_CLIENT(plr) //give every spectator <g_maxplayers_spectator_blocktime> seconds time to become a player
340                 {
341                         if(plr.classname == "spectator" || plr.classname == "observer")
342                         {
343                                 plr.spectatortime = time;
344                                 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"));
345                         }
346                 }
347                 bprint(strcat("^7All spectators will be automatically kicked when not joining the game after ", ftos(cvar("g_maxplayers_spectator_blocktime")), " seconds!\n"));
348                 return;
349         }
350         if (argv(0) == "lockteams")
351         {
352                 if(teamplay)
353                 {
354                         lockteams = 1;
355                         bprint("^1The teams are now locked.\n");
356                 }
357                 else
358                         bprint("That command can only be used in a team-based gamemode.\n");
359                 return;
360         }
361         if (argv(0) == "unlockteams")
362         {
363                 if(teamplay)
364                 {
365                         lockteams = 0;
366                         bprint("^1The teams are now unlocked.\n");
367                 }
368                 else
369                         bprint("That command can only be used in a team-based gamemode.\n");
370                 return;
371         }
372         if (argv(0) == "movetoteam") if(argc == 3)
373         {
374                 entno = stof(argv(1));
375                 client = world;
376                 if(entno <= maxclients)
377                         client = edict_num(entno);
378                 if(client.flags & FL_CLIENT)
379                 {
380                         float lt;
381                         lt = lockteams;
382                         lockteams = 0;
383
384                         self = client;
385                         SV_ParseClientCommand(strcat("selectteam ", argv(2)));
386
387                         lockteams = lt;
388                 }
389                 else
390                         print("Client not found\n");
391                 return;
392         }
393         if (argv(0) == "teamstatus")
394         {
395                 Score_NicePrint(world);
396                 return;
397         }
398         if (argv(0) == "allready")
399         {
400                 ReadyRestart();
401                 return;
402         }
403         if (argv(0) == "effectindexdump")
404         {
405                 EffectIndexDump();
406                 return;
407         }
408         if (argv(0) == "roughmap")
409         {
410                 RoughMap();
411                 return;
412         }
413         if (argv(0) == "cvar_changes")
414         {
415                 print(cvar_changes);
416                 return;
417         }
418
419         print("Invalid command. For a list of supported commands, try sv_cmd help.\n");
420 }
421