1 string GotoMap(string m);
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)
11 tracebox(a, mi, ma, b, MOVE_WORLDONLY, world);
14 // a leaves solid, then hits trace_endpos
15 // where does a leave solid?
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;
25 // a hits trace_endpos
26 return FullTraceFraction(trace_endpos + '0 0 1', mi, ma, b);
30 float RoughMapAtPoint(float x, float y, float w, float h)
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);
40 float RoughMapAtPoint(float x, float y, float w, float h, float zmin, float zsize)
46 dz = (zsize / 256) * '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' * zmin;
50 if(x < world.mins_x - w)
52 if(y < world.mins_y - h)
60 for(i = 0; i < 255; ++i)
62 tracebox(o + dz * i, mi, ma, o + dz * i, MOVE_WORLDONLY, world);
70 string doublehex = "000102030405060708090A0B0C0D0E0F101112131415161718191A1B1C1D1E1F202122232425262728292A2B2C2D2E2F303132333435363738393A3B3C3D3E3F404142434445464748494A4B4C4D4E4F505152535455565758595A5B5C5D5E5F606162636465666768696A6B6C6D6E6F707172737475767778797A7B7C7D7E7F808182838485868788898A8B8C8D8E8F909192939495969798999A9B9C9D9E9FA0A1A2A3A4A5A6A7A8A9AAABACADAEAFB0B1B2B3B4B5B6B7B8B9BABBBCBDBEBFC0C1C2C3C4C5C6C7C8C9CACBCCCDCECFD0D1D2D3D4D5D6D7D8D9DADBDCDDDEDFE0E1E2E3E4E5E6E7E8E9EAEBECEDEEEFF0F1F2F3F4F5F6F7F8F9FAFBFCFDFEFF";
75 // size: pixel width/height
76 // maxs: cell width/height
89 self.mins = mi_picmin;
90 self.maxs_x = (mi_picmax_x - mi_picmin_x) / self.size_x;
91 self.maxs_y = (mi_picmax_y - mi_picmin_y) / self.size_y;
92 self.maxs_z = mi_max_z - mi_min_z;
93 print("Picture mins/maxs: ", ftos(self.maxs_x), " and ", ftos(self.maxs_y), " should match\n");
94 self.netname = strzone(strcat("gfx/", mi_shortname, "_mini.xpm"));
97 self.cnt = fopen(self.netname, FILE_READ);
100 print(self.netname, " already exists, aborting (you may want to specify --force)\n");
104 localcmd("defer 1 \"sv_cmd roughmap --force --loop\"\n");
106 localcmd("defer 1 \"sv_cmd roughmap --loop\"\n");
113 self.cnt = fopen(self.netname, FILE_WRITE);
116 print("Error writing ", self.netname, "\n");
121 print("Writing to ", self.netname, "...\n");
122 fputs(self.cnt, "/* XPM */\n");
123 fputs(self.cnt, "static char *RoughMap[] = {\n");
124 fputs(self.cnt, "/* columns rows colors chars-per-pixel */\n");
125 fputs(self.cnt, strcat("\"", ftos(self.size_x), " ", ftos(self.size_y), " 256 2\",\n"));
126 for(i = 0; i < 256; ++i)
128 si = substring(doublehex, i*2, 2);
129 fputs(self.cnt, strcat("\"", si, " c #", si, si, si, "\",\n"));
132 self.nextthink = time;
134 else if(self.frame <= self.size_y)
136 // write a pixel line
137 fputs(self.cnt, "\"");
138 for(x = 0; x < self.size_x; ++x)
140 l = RoughMapAtPoint(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);
141 fputs(self.cnt, substring(doublehex, 2 * l, 2));
143 if(self.frame == self.size_y)
144 fputs(self.cnt, "\"\n");
147 fputs(self.cnt, "\",\n");
148 print(ftos(self.size_y - self.frame), " lines left\n");
151 self.nextthink = time;
156 fputs(self.cnt, "};\n");
158 print("Finished. Please edit data/", self.netname, " with an image editing application and place it in the TGA format in the gfx folder.\n");
162 localcmd("defer 1 \"sv_cmd roughmap --force --loop\"\n");
164 localcmd("defer 1 \"sv_cmd roughmap --loop\"\n");
172 void RoughMap(float argc)
177 roughmapper = spawn();
178 roughmapper.classname = "roughmapper";
179 roughmapper.think = RoughMap_Think;
180 roughmapper.nextthink = time;
181 roughmapper.count = 0;
183 for(i = 1; i < argc; ++i)
185 if(argv(i) == "--force")
186 roughmapper.count |= 1;
187 if(argv(i) == "--loop")
188 roughmapper.count |= 2;
192 void EffectIndexDump()
200 print("begin of effects list\n");
201 db_put(d, "TE_GUNSHOT", "1"); print("effect TE_GUNSHOT is ", ftos(particleeffectnum("TE_GUNSHOT")), "\n");
202 db_put(d, "TE_GUNSHOTQUAD", "1"); print("effect TE_GUNSHOTQUAD is ", ftos(particleeffectnum("TE_GUNSHOTQUAD")), "\n");
203 db_put(d, "TE_SPIKE", "1"); print("effect TE_SPIKE is ", ftos(particleeffectnum("TE_SPIKE")), "\n");
204 db_put(d, "TE_SPIKEQUAD", "1"); print("effect TE_SPIKEQUAD is ", ftos(particleeffectnum("TE_SPIKEQUAD")), "\n");
205 db_put(d, "TE_SUPERSPIKE", "1"); print("effect TE_SUPERSPIKE is ", ftos(particleeffectnum("TE_SUPERSPIKE")), "\n");
206 db_put(d, "TE_SUPERSPIKEQUAD", "1"); print("effect TE_SUPERSPIKEQUAD is ", ftos(particleeffectnum("TE_SUPERSPIKEQUAD")), "\n");
207 db_put(d, "TE_WIZSPIKE", "1"); print("effect TE_WIZSPIKE is ", ftos(particleeffectnum("TE_WIZSPIKE")), "\n");
208 db_put(d, "TE_KNIGHTSPIKE", "1"); print("effect TE_KNIGHTSPIKE is ", ftos(particleeffectnum("TE_KNIGHTSPIKE")), "\n");
209 db_put(d, "TE_EXPLOSION", "1"); print("effect TE_EXPLOSION is ", ftos(particleeffectnum("TE_EXPLOSION")), "\n");
210 db_put(d, "TE_EXPLOSIONQUAD", "1"); print("effect TE_EXPLOSIONQUAD is ", ftos(particleeffectnum("TE_EXPLOSIONQUAD")), "\n");
211 db_put(d, "TE_TAREXPLOSION", "1"); print("effect TE_TAREXPLOSION is ", ftos(particleeffectnum("TE_TAREXPLOSION")), "\n");
212 db_put(d, "TE_TELEPORT", "1"); print("effect TE_TELEPORT is ", ftos(particleeffectnum("TE_TELEPORT")), "\n");
213 db_put(d, "TE_LAVASPLASH", "1"); print("effect TE_LAVASPLASH is ", ftos(particleeffectnum("TE_LAVASPLASH")), "\n");
214 db_put(d, "TE_SMALLFLASH", "1"); print("effect TE_SMALLFLASH is ", ftos(particleeffectnum("TE_SMALLFLASH")), "\n");
215 db_put(d, "TE_FLAMEJET", "1"); print("effect TE_FLAMEJET is ", ftos(particleeffectnum("TE_FLAMEJET")), "\n");
216 db_put(d, "EF_FLAME", "1"); print("effect EF_FLAME is ", ftos(particleeffectnum("EF_FLAME")), "\n");
217 db_put(d, "TE_BLOOD", "1"); print("effect TE_BLOOD is ", ftos(particleeffectnum("TE_BLOOD")), "\n");
218 db_put(d, "TE_SPARK", "1"); print("effect TE_SPARK is ", ftos(particleeffectnum("TE_SPARK")), "\n");
219 db_put(d, "TE_PLASMABURN", "1"); print("effect TE_PLASMABURN is ", ftos(particleeffectnum("TE_PLASMABURN")), "\n");
220 db_put(d, "TE_TEI_G3", "1"); print("effect TE_TEI_G3 is ", ftos(particleeffectnum("TE_TEI_G3")), "\n");
221 db_put(d, "TE_TEI_SMOKE", "1"); print("effect TE_TEI_SMOKE is ", ftos(particleeffectnum("TE_TEI_SMOKE")), "\n");
222 db_put(d, "TE_TEI_BIGEXPLOSION", "1"); print("effect TE_TEI_BIGEXPLOSION is ", ftos(particleeffectnum("TE_TEI_BIGEXPLOSION")), "\n");
223 db_put(d, "TE_TEI_PLASMAHIT", "1"); print("effect TE_TEI_PLASMAHIT is ", ftos(particleeffectnum("TE_TEI_PLASMAHIT")), "\n");
224 db_put(d, "EF_STARDUST", "1"); print("effect EF_STARDUST is ", ftos(particleeffectnum("EF_STARDUST")), "\n");
225 db_put(d, "TR_ROCKET", "1"); print("effect TR_ROCKET is ", ftos(particleeffectnum("TR_ROCKET")), "\n");
226 db_put(d, "TR_GRENADE", "1"); print("effect TR_GRENADE is ", ftos(particleeffectnum("TR_GRENADE")), "\n");
227 db_put(d, "TR_BLOOD", "1"); print("effect TR_BLOOD is ", ftos(particleeffectnum("TR_BLOOD")), "\n");
228 db_put(d, "TR_WIZSPIKE", "1"); print("effect TR_WIZSPIKE is ", ftos(particleeffectnum("TR_WIZSPIKE")), "\n");
229 db_put(d, "TR_SLIGHTBLOOD", "1"); print("effect TR_SLIGHTBLOOD is ", ftos(particleeffectnum("TR_SLIGHTBLOOD")), "\n");
230 db_put(d, "TR_KNIGHTSPIKE", "1"); print("effect TR_KNIGHTSPIKE is ", ftos(particleeffectnum("TR_KNIGHTSPIKE")), "\n");
231 db_put(d, "TR_VORESPIKE", "1"); print("effect TR_VORESPIKE is ", ftos(particleeffectnum("TR_VORESPIKE")), "\n");
232 db_put(d, "TR_NEHAHRASMOKE", "1"); print("effect TR_NEHAHRASMOKE is ", ftos(particleeffectnum("TR_NEHAHRASMOKE")), "\n");
233 db_put(d, "TR_NEXUIZPLASMA", "1"); print("effect TR_NEXUIZPLASMA is ", ftos(particleeffectnum("TR_NEXUIZPLASMA")), "\n");
234 db_put(d, "TR_GLOWTRAIL", "1"); print("effect TR_GLOWTRAIL is ", ftos(particleeffectnum("TR_GLOWTRAIL")), "\n");
235 db_put(d, "SVC_PARTICLE", "1"); print("effect SVC_PARTICLE is ", ftos(particleeffectnum("SVC_PARTICLE")), "\n");
237 fh = fopen("effectinfo.txt", FILE_READ);
238 while((s = fgets(fh)))
241 if(argv(0) == "effect")
243 if(db_get(d, argv(1)) != "1")
245 if(particleeffectnum(argv(1)) >= 0)
246 print("effect ", argv(1), " is ", ftos(particleeffectnum(argv(1))), "\n");
247 db_put(d, argv(1), "1");
251 print("end of effects list\n");
256 void make_mapinfo_Think()
258 if(MapInfo_FilterGametype(MAPINFO_TYPE_ALL, 0, 1))
260 print("Done rebuiling mapinfos.\n");
261 MapInfo_FilterGametype(MapInfo_CurrentGametype(), MapInfo_CurrentFeatures(), 0);
266 self.think = make_mapinfo_Think;
267 self.nextthink = time;
271 void GameCommand(string command)
276 argc = tokenize(command);
278 if(argv(0) == "help" || argc == 0)
280 print("Usage: sv_cmd COMMAND..., where possible commands are:\n");
281 print(" adminmsg clientnumber \"message\"\n");
282 print(" teamstatus\n");
283 print(" printstats\n");
284 print(" make_mapinfo\n");
285 print(" gametype dm|ctf|...\n");
286 print(" savedb filename\n");
287 print(" dumpdb filename\n");
288 print(" loaddb filename\n");
289 print(" allready\n");
290 print(" effectindexdump\n");
291 print(" roughmap\n");
292 GameCommand_Vote("help", world);
293 GameCommand_Ban("help");
294 GameCommand_Generic("help");
298 if(GameCommand_Vote(command, world))
301 if(GameCommand_Ban(command))
304 if(GameCommand_Generic(command))
307 if(argv(0) == "printstats")
313 if(argv(0) == "make_mapinfo")
317 e.classname = "make_mapinfo";
318 e.think = make_mapinfo_Think;
324 if(argv(0) == "warp") if(argc == 2) if(cvar("g_campaign"))
326 CampaignLevelWarp(stof(argv(1)));
330 if(argv(0) == "gotomap") if(argc == 2)
332 print(GotoMap(argv(1)), "\n");
336 if(argv(0) == "gametype") if(argc == 2)
341 t = MapInfo_Type_FromString(s);
342 tsave = MapInfo_CurrentGametype();
345 MapInfo_SwitchGameType(t);
346 MapInfo_FilterGametype(MapInfo_CurrentGametype(), MapInfo_CurrentFeatures(), 0);
347 if(MapInfo_count > 0)
349 bprint("Game type successfully switched to ", s, "\n");
353 bprint("Cannot use this game type: no map for it found\n");
354 MapInfo_SwitchGameType(tsave);
355 MapInfo_FilterGametype(MapInfo_CurrentGametype(), MapInfo_CurrentFeatures(), 0);
359 bprint("Game type switch to ", s, " failed: this type does not exist!\n");
363 if(argv(0) == "adminmsg") if(argc == 3)
365 entno = stof(argv(1));
367 if(entno <= maxclients)
368 client = edict_num(entno);
369 if(client.flags & FL_CLIENT)
371 centerprint_atprio(client, CENTERPRIO_ADMIN, strcat("^3SERVER ADMIN:\n\n^7", argv(2)));
372 sprint(client, strcat("\{1}\{13}^3SERVER ADMIN^7: ", argv(2), "\n"));
373 print("Message sent to ", client.netname, "\n");
376 print("Client not found\n");
380 if(argv(0) == "savedb") if(argc == 2)
382 db_save(ServerProgsDB, argv(1));
383 print("DB saved.\n");
387 if(argv(0) == "dumpdb") if(argc == 2)
389 db_dump(ServerProgsDB, argv(1));
390 print("DB dumped.\n");
394 if(argv(0) == "loaddb") if(argc == 2)
396 db_close(ServerProgsDB);
397 ServerProgsDB = db_load(argv(1));
398 print("DB loaded.\n");
401 if (argv(0) == "nospectators")
405 FOR_EACH_CLIENT(plr) //give every spectator <g_maxplayers_spectator_blocktime> seconds time to become a player
407 if(plr.classname == "spectator" || plr.classname == "observer")
409 plr.spectatortime = time;
410 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"));
413 bprint(strcat("^7All spectators will be automatically kicked when not joining the game after ", ftos(cvar("g_maxplayers_spectator_blocktime")), " seconds!\n"));
416 if (argv(0) == "lockteams")
421 bprint("^1The teams are now locked.\n");
424 bprint("That command can only be used in a team-based gamemode.\n");
427 if (argv(0) == "unlockteams")
432 bprint("^1The teams are now unlocked.\n");
435 bprint("That command can only be used in a team-based gamemode.\n");
438 if (argv(0) == "movetoteam") if(argc == 3)
440 entno = stof(argv(1));
442 if(entno <= maxclients)
443 client = edict_num(entno);
444 if(client.flags & FL_CLIENT)
451 SV_ParseClientCommand(strcat("selectteam ", argv(2)));
456 print("Client not found\n");
459 if (argv(0) == "teamstatus")
461 Score_NicePrint(world);
464 if (argv(0) == "allready")
469 if (argv(0) == "effectindexdump")
474 if (argv(0) == "roughmap")
479 if (argv(0) == "cvar_changes")
485 print("Invalid command. For a list of supported commands, try sv_cmd help.\n");