From d3ad75e188cd80ff8b77095e364a48eb859b466a Mon Sep 17 00:00:00 2001 From: Marco Cawthorne Date: Sun, 25 Jun 2023 22:33:49 -0700 Subject: [PATCH] Ported Nuclide's mapcycle code over. --- client.qc | 16 +----------- mapcycle.qc | 75 +++++++++++++++++++++++++++++++++++++++++++++++++++++ progs.src | 1 + world.qc | 1 + 4 files changed, 78 insertions(+), 15 deletions(-) create mode 100644 mapcycle.qc diff --git a/client.qc b/client.qc index 40acdc6..4c6873f 100644 --- a/client.qc +++ b/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"); }; diff --git a/mapcycle.qc b/mapcycle.qc new file mode 100644 index 0000000..7bf1576 --- /dev/null +++ b/mapcycle.qc @@ -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); +} \ No newline at end of file diff --git a/progs.src b/progs.src index 34b9d8c..8f12942 100644 --- a/progs.src +++ b/progs.src @@ -5,6 +5,7 @@ subs.qc combat.qc items.qc weapons.qc +mapcycle.qc world.qc client.qc spectate.qc diff --git a/world.qc b/world.qc index 9719094..142b1ff 100644 --- a/world.qc +++ b/world.qc @@ -198,6 +198,7 @@ World Types: void() worldspawn = { lastspawn = world; + Mapcycle_Init(); InitBodyQue (); // custom map attributes