forked from id/quake-qw-qc
Ported Nuclide's mapcycle code over.
This commit is contained in:
parent
0e20a29227
commit
d3ad75e188
4 changed files with 78 additions and 15 deletions
16
client.qc
16
client.qc
|
@ -160,21 +160,7 @@ entity() FindIntermission =
|
|||
|
||||
void() GotoNextMap =
|
||||
{
|
||||
local string newmap;
|
||||
|
||||
//ZOID: 12-13-96, samelevel is overloaded, only 1 works for same level
|
||||
|
||||
if (cvar("samelevel") == 1) // if samelevel is set, stay on same level
|
||||
changelevel (mapname);
|
||||
else {
|
||||
// configurable map lists, see if the current map exists as a
|
||||
// serverinfo/localinfo var
|
||||
newmap = infokey(world, mapname);
|
||||
if (newmap != "")
|
||||
changelevel (newmap);
|
||||
else
|
||||
changelevel (nextmap);
|
||||
}
|
||||
localcmd("nextmap\n");
|
||||
};
|
||||
|
||||
|
||||
|
|
75
mapcycle.qc
Normal file
75
mapcycle.qc
Normal file
|
@ -0,0 +1,75 @@
|
|||
/* public domain, do whatever you please. */
|
||||
typedef float filestream;
|
||||
|
||||
/* builtins used */
|
||||
filestream(string filename, float mode) fopen = #110;
|
||||
void(filestream fhandle) fclose = #111;
|
||||
string(filestream fhandle) fgets = #112;
|
||||
string(string, optional string, optional string, optional string, optional string, optional string, optional string, optional string) strcat = #115;
|
||||
string(string filename, optional enumflags:float{WP_REFERENCEPACKAGE,WP_FULLPACKAGEPATH} flags) whichpack = #503;
|
||||
void(string text,...) print = #339;
|
||||
void(string cmd) readcmd = #0:readcmd;
|
||||
string(string fmt, ...) sprintf = #627;
|
||||
string(string cvarname) cvar_string = #448;
|
||||
|
||||
/* constants */
|
||||
const float FILE_READ = 0;
|
||||
|
||||
void
|
||||
Mapcycle_Load(string filename)
|
||||
{
|
||||
filestream fs_mapcycle;
|
||||
string temp;
|
||||
float mapcount = 0;
|
||||
string lastmap = "";
|
||||
float map_next = 0;
|
||||
|
||||
fs_mapcycle = fopen(filename, FILE_READ);
|
||||
|
||||
if (fs_mapcycle < 0) {
|
||||
print(strcat("^1could not load ", filename, "\n"));
|
||||
return;
|
||||
}
|
||||
|
||||
/* read the lines in, see if the map exists and define an enumerated alias */
|
||||
while ((temp = fgets(fs_mapcycle))) {
|
||||
if not (whichpack(strcat("maps/", temp, ".bsp")))
|
||||
continue;
|
||||
|
||||
readcmd(sprintf("alias m%d \"map %s;alias nextmap m%d\"\n", mapcount, temp, mapcount + 1));
|
||||
|
||||
if (mapname == lastmap)
|
||||
map_next = mapcount;
|
||||
|
||||
lastmap = temp;
|
||||
mapcount++;
|
||||
}
|
||||
|
||||
fclose(fs_mapcycle);
|
||||
|
||||
if (mapcount <= 0)
|
||||
return;
|
||||
|
||||
/* override the last map so that it goes back to m0 */
|
||||
readcmd(sprintf("alias m%d \"map %s;alias nextmap m0\"\n", mapcount - 1, lastmap));
|
||||
|
||||
/* the current map in the list will decide the nextmap */
|
||||
readcmd(sprintf("alias nextmap m%d\n", map_next));
|
||||
|
||||
print(sprintf("mapcycle initialized with %d entries.\n", mapcount));
|
||||
}
|
||||
|
||||
void
|
||||
Mapcycle_Init(void)
|
||||
{
|
||||
string cycleFile = autocvar(mapcycle_file, "mapcycle.txt");
|
||||
|
||||
/* in case some server admin wants a map to continously loop */
|
||||
if not (cycleFile) {
|
||||
print("mapcycle disabled via cvar. skipping\n");
|
||||
return;
|
||||
}
|
||||
|
||||
print("--------- Initializing MapCycle ----------\n");
|
||||
Mapcycle_Load(cycleFile);
|
||||
}
|
|
@ -5,6 +5,7 @@ subs.qc
|
|||
combat.qc
|
||||
items.qc
|
||||
weapons.qc
|
||||
mapcycle.qc
|
||||
world.qc
|
||||
client.qc
|
||||
spectate.qc
|
||||
|
|
1
world.qc
1
world.qc
|
@ -198,6 +198,7 @@ World Types:
|
|||
void() worldspawn =
|
||||
{
|
||||
lastspawn = world;
|
||||
Mapcycle_Init();
|
||||
InitBodyQue ();
|
||||
|
||||
// custom map attributes
|
||||
|
|
Loading…
Reference in a new issue