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