Skip to content

Commit

Permalink
Level sets can inherit BSPs & default.avarascript
Browse files Browse the repository at this point in the history
Also added a new KOTH level for testing.
  • Loading branch information
rherriman committed Dec 14, 2023
1 parent 209f0b2 commit 91f8e1d
Show file tree
Hide file tree
Showing 12 changed files with 433 additions and 21 deletions.
331 changes: 331 additions & 0 deletions levels/avaraline-quirks-mode/alf/layout/moonlight.alf

Large diffs are not rendered by default.

14 changes: 14 additions & 0 deletions levels/avaraline-quirks-mode/alf/moonlight.alf
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<map>
<include alf="layout/moonlight.alf" />

<set
pReqPointMultiplier="1"
pHillX="0"
pHillY="4"
pHillZ="0"
pHillW="15"
pHillD="15"
pHillH="2"
/>
<include alf="logic/koth.alf" />
</map>
10 changes: 5 additions & 5 deletions levels/avaraline-quirks-mode/alf/telecaster-captures.alf
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
pCaptureD="captureSize"
pCaptureH="captureSize"
pCaptureVizX="0"
pCaptureVizY="1.75"
pCaptureVizY="mGoodyOffset"
pCaptureVizZ="0"
/>
<include alf="logic/capture-point.alf" />
Expand All @@ -35,7 +35,7 @@
pCaptureD="captureSize"
pCaptureH="captureSize"
pCaptureVizX="-outerCaptureX"
pCaptureVizY="outerCaptureY + 1.75"
pCaptureVizY="outerCaptureY + mGoodyOffset"
pCaptureVizZ="-outerCaptureZ"
/>
<Hologram cx="-outerCaptureX" y="outerCaptureY + 0.05" cz="-outerCaptureZ" angle="45" shape="bspGroundStar" scale="0.5" color="#260019" />
Expand All @@ -50,7 +50,7 @@
pCaptureD="captureSize"
pCaptureH="captureSize"
pCaptureVizX="outerCaptureX"
pCaptureVizY="outerCaptureY + 1.75"
pCaptureVizY="outerCaptureY + mGoodyOffset"
pCaptureVizZ="outerCaptureZ"
/>
<Hologram cx="outerCaptureX" y="outerCaptureY + 0.05" cz="outerCaptureZ" angle="45" shape="bspGroundStar" scale="0.5" color="#260019" />
Expand All @@ -65,7 +65,7 @@
pCaptureD="captureSize"
pCaptureH="captureSize"
pCaptureVizX="-outerCaptureZ"
pCaptureVizY="outerCaptureY + 1.75"
pCaptureVizY="outerCaptureY + mGoodyOffset"
pCaptureVizZ="outerCaptureX"
/>
<Hologram cx="-outerCaptureZ" y="outerCaptureY + 0.05" cz="outerCaptureX" angle="45" shape="bspGroundStar" scale="0.5" color="#260019" />
Expand All @@ -80,7 +80,7 @@
pCaptureD="captureSize"
pCaptureH="captureSize"
pCaptureVizX="outerCaptureZ"
pCaptureVizY="outerCaptureY + 1.75"
pCaptureVizY="outerCaptureY + mGoodyOffset"
pCaptureVizZ="-outerCaptureX"
/>
<Hologram cx="outerCaptureZ" y="outerCaptureY + 0.05" cz="-outerCaptureX" angle="45" shape="bspGroundStar" scale="0.5" color="#260019" />
Expand Down
2 changes: 1 addition & 1 deletion levels/avaraline-quirks-mode/alf/watery-keep.alf
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@
<Hologram shape="bspVines" y="9.5" isAmbient="true" scale="0.75" color="#808e5a" color.1="#b1c28c" cx="-24.995" cz="10.625" angle="90" />

<!-- "WATER" -->
<Field watch="playerMask" deltaY="0.055" shape="3002" color="#ffffff" color.1="#000000" x="-18.75" z="55" w="12.5" d="10" h="6" cx="0" cz="0" angle="0" />
<Field watch="playerMask" deltaY="0.055" shape="bspWateryKeepWater" color="#ffffff" color.1="#000000" x="-18.75" z="55" w="12.5" d="10" h="6" cx="0" cz="0" angle="0" />
<Field deltaY="0" visible="true" color="hsla(323, 6%, 41%, 1)" color.1="#000000" x="0" z="0" w="30" d="30" h="0" y="9" />
<Field deltaY="0" visible="true" color="hsla(323, 6%, 41%, 1)" color.1="#000000" x="-17.5" z="-10" w="5" d="20" h="0" y="9" />
<Field deltaY="0" visible="true" color="hsla(323, 6%, 41%, 1)" color.1="#000000" x="-17.5" z="10" w="5" d="20" h="0" y="9" />
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
5 changes: 3 additions & 2 deletions levels/avaraline-quirks-mode/default.avarascript
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,9 @@ mXLgMissile = 6
mXXLgMissile = 8

// Custom assets.
bspFlag = 3000
bspSwirl = 3001
bspFlag = 3500
bspSwirl = 3501
bspWateryKeepWater = 3502
snWaves = 3000
snWaves2 = 3001
snWaterStep = 3002
Expand Down
5 changes: 5 additions & 0 deletions levels/avaraline-quirks-mode/set.json
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,11 @@
"Name": "I/O [4MKF]",
"Message": "Garbage in, garbage out. Four minute killfest version."
},
{
"Alf": "moonlight.alf",
"Name": "Moonlight [KOTH]",
"Message": ""
},
{
"Alf": "majuscule-4mkf.alf",
"Name": "Majuscule [4MKF]",
Expand Down
60 changes: 52 additions & 8 deletions src/compat/Resource.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -86,14 +86,14 @@ bool IsEquals(const std::string& str1, const std::string& str2) {
Handle FindResource(SDL_RWops *file, OSType theType, short theID, std::string name) {
uint32_t dataOffset = SDL_ReadBE32(file);
uint32_t mapOffset = SDL_ReadBE32(file);
// uint32_t dataLen =
// uint32_t dataLen =
SDL_ReadBE32(file);
// uint32_t mapLen =
// uint32_t mapLen =
SDL_ReadBE32(file);

SDL_RWseek(file, mapOffset + 22, 0);

//uint16_t forkAttrs =
//uint16_t forkAttrs =
SDL_ReadBE16(file);

uint16_t typeListOffset = SDL_ReadBE16(file);
Expand Down Expand Up @@ -250,7 +250,7 @@ const char* PathForLevelSet(std::string set) {

void LevelDirListing() {
cf_dir_t dir;
char ldir[PATH_MAX];
char ldir[PATH_MAX];
BundlePath(LEVELDIR, ldir);
cf_dir_open(&dir, ldir);

Expand Down Expand Up @@ -350,17 +350,32 @@ void LoadHullFromSetJSON(HullConfigRecord *hull, short resId) {

bool GetBSPPath(int resId, char* dest) {
std::stringstream relPath;
bool found = false;

// first check for the resource in the levelset directory
// First, check for the resource in the levelset directory.
relPath << LEVELDIR << PATHSEP << currentLevelDir << PATHSEP;
relPath << BSPSDIR << PATHSEP << resId << BSPSEXT;
BundlePath(relPath, dest);
bool found = false;
std::ifstream testFile(dest);
if (!testFile.fail()) {
found = true;
}
// haven't found the BSP file yet, try the top-level bsps directory

// Haven't found the BSP file yet, fall back and check required packages.
if (!found) {
for (auto &pkg : currentExtPkgDirs) {
relPath.str("");
relPath << LEVELDIR << PATHSEP << pkg << PATHSEP;
relPath << BSPSDIR << PATHSEP << resId << BSPSEXT;
BundlePath(relPath, dest);
std::ifstream testFile(dest);
if (!testFile.fail()) {
found = true;
}
}
}

// Still haven't found the BSP file, finally try the base BSP directory.
if (!found) {
relPath.str("");
relPath << currentBaseDir << PATHSEP << BSPSDIR << PATHSEP << resId << BSPSEXT;
Expand Down Expand Up @@ -449,6 +464,35 @@ std::string GetDefaultScript() {
return "";
}

std::vector<std::string> GetExternalScripts() {
std::vector<std::string> scripts = {};
std::stringstream buffa;

// Note that we are retrieving the scripts in reverse order, here!
for (auto pkg = currentExtPkgDirs.rbegin(); pkg != currentExtPkgDirs.rend(); ++pkg) {
buffa.str("");
buffa << LEVELDIR << PATHSEP << *pkg << PATHSEP;
buffa << DEFAULTSCRIPT;
char temp[PATH_MAX];
BundlePath(buffa.str().c_str(), temp);
std::ifstream t(temp);
if (t.good()) {
std::string defaultscript;
t.seekg(0, std::ios::end);
defaultscript.reserve(t.tellg());
t.seekg(0, std::ios::beg);

defaultscript.assign((std::istreambuf_iterator<char>(t)),
std::istreambuf_iterator<char>());
scripts.push_back(defaultscript);
} else {
SDL_Log("There was an error opening %s", temp);
}
}

return scripts;
}

std::string GetBaseScript() {
std::stringstream buffa;
buffa << currentBaseDir << PATHSEP << DEFAULTSCRIPT;
Expand Down Expand Up @@ -521,7 +565,7 @@ void LoadOggFile(short resId, std::string filename, SoundCash &cash) {

int error;
stb_vorbis *v = stb_vorbis_open_filename(fullpath, &error, NULL);

//stb_vorbis_info info = stb_vorbis_get_info(v);
//SDL_Log("%d channels, %d samples/sec\n", info.channels, info.sample_rate);

Expand Down
1 change: 1 addition & 0 deletions src/compat/Resource.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ nlohmann::json GetBSPJSON(int resId);
bool HasBSP(int resId);
std::string GetALFPath(std::string alfname);
std::string GetDefaultScript();
std::vector<std::string> GetExternalScripts();
std::string GetBaseScript();
void LoadHullFromSetJSON(HullConfigRecord *hull, short resId);
void LoadDefaultOggFiles();
Expand Down
26 changes: 21 additions & 5 deletions src/level/Parser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1054,12 +1054,28 @@ void AllocParser() {
stackP = stackMem;

currentActor = NULL;

// Load default script from "base" resource pack (Avara, Aftershock).
std::string base = GetBaseScript();
if (base.length() > 0)
RunThis((StringPtr)base.c_str());
if (base.length() > 0) {
RunThis((StringPtr)base.c_str());
}

// Load default script from "external" resource packs required by the
// current level set. (If multiple are defined, they are loaded in
// *reverse* order.)
std::vector<std::string> ext = GetExternalScripts();
for (auto &extScript : ext) {
if (extScript.length() > 0) {
RunThis((StringPtr)extScript.c_str());
}
}

// Load default script for the current level set.
std::string def = GetDefaultScript();
if (def.length() > 0)
RunThis((StringPtr)def.c_str());
if (def.length() > 0) {
RunThis((StringPtr)def.c_str());
}
}

void DeallocParser() {
Expand All @@ -1069,7 +1085,7 @@ void DeallocParser() {
variableBase->Dispose();
if (programBase)
programBase->Dispose();

stackP = NULL;
symTable = NULL;
variableBase = NULL;
Expand Down

0 comments on commit 91f8e1d

Please sign in to comment.