From: bones_was_here Date: Wed, 26 Oct 2022 15:34:30 +0000 (+1000) Subject: Support custom func_door and func_plat sounds on Q3A maps X-Git-Url: https://git.rm.cloudns.org/?a=commitdiff_plain;h=7683d227ea7993402224b94021491191fbd0129d;p=xonotic%2Fxonotic-data.pk3dir.git Support custom func_door and func_plat sounds on Q3A maps This adds FindFileInMapPack(), a very simple version of _MapInfo_FindArenaFile(). --- diff --git a/qcsrc/common/mapobjects/func/door.qc b/qcsrc/common/mapobjects/func/door.qc index 40a6b1a1f..ac1e0bee4 100644 --- a/qcsrc/common/mapobjects/func/door.qc +++ b/qcsrc/common/mapobjects/func/door.qc @@ -679,14 +679,28 @@ void door_init_shared(entity this) if (q3compat) { - // CPMA adds these fields for overriding the engine sounds + // CPMA adds these fields for overriding the Q3 default sounds string s = GetField_fullspawndata(this, "sound_start", true); string e = GetField_fullspawndata(this, "sound_end", true); if (s) this.noise2 = strzone(s); + else + { + // PK3s supporting Q3A sometimes include custom sounds at Q3 default paths + s = "sound/movers/doors/dr1_strt.wav"; + if (FindFileInMapPack(s)) + this.noise2 = s; + } + if (e) this.noise1 = strzone(e); + else + { + e = "sound/movers/doors/dr1_end.wav"; + if (FindFileInMapPack(e)) + this.noise1 = e; + } } // sound when door stops moving diff --git a/qcsrc/common/mapobjects/func/plat.qc b/qcsrc/common/mapobjects/func/plat.qc index 9dd3ac732..08faae9eb 100644 --- a/qcsrc/common/mapobjects/func/plat.qc +++ b/qcsrc/common/mapobjects/func/plat.qc @@ -98,14 +98,28 @@ spawnfunc(func_plat) if (q3compat) { - // CPMA adds these fields for overriding the engine sounds + // CPMA adds these fields for overriding the Q3 default sounds string s = GetField_fullspawndata(this, "sound_start", true); string e = GetField_fullspawndata(this, "sound_end", true); if (s) this.noise = strzone(s); + else + { + // PK3s supporting Q3A sometimes include custom sounds at Q3 default paths + s = "sound/movers/plats/pt1_strt.wav"; + if (FindFileInMapPack(s)) + this.noise = s; + } + if (e) this.noise1 = strzone(e); + else + { + e = "sound/movers/plats/pt1_end.wav"; + if (FindFileInMapPack(e)) + this.noise1 = e; + } } if(this.noise && this.noise != "") diff --git a/qcsrc/server/main.qc b/qcsrc/server/main.qc index 2b29422b8..59f2012ff 100644 --- a/qcsrc/server/main.qc +++ b/qcsrc/server/main.qc @@ -453,6 +453,32 @@ string GetField_fullspawndata(entity e, string f, ...) return v; } +/* +============= +FindFileInMapPack + +Returns the first matching VFS file path that exists in the current map's pack. +Returns string_null if no files match or the map isn't packaged. +============= +*/ +string FindFileInMapPack(string pattern) +{ + if(!checkextension("DP_QC_FS_SEARCH_PACKFILE")) + return string_null; + + string base_pack = whichpack(strcat("maps/", mapname, ".bsp")); + if(base_pack == "" || !base_pack) // this map isn't packaged or there was an error + return string_null; + + int glob = search_packfile_begin(pattern, true, true, base_pack); + if(glob < 0) + return string_null; + + string file = search_getfilename(glob, 0); + search_end(glob); + return file; +} + void WarpZone_PostInitialize_Callback() { // create waypoint links for warpzones