]> git.rm.cloudns.org Git - xonotic/xonotic-data.pk3dir.git/commitdiff
Support custom func_door and func_plat sounds on Q3A maps
authorbones_was_here <bones_was_here@xonotic.au>
Fri, 15 Sep 2023 06:42:57 +0000 (16:42 +1000)
committerbones_was_here <bones_was_here@xonotic.au>
Fri, 15 Sep 2023 07:11:45 +0000 (17:11 +1000)
This adds FindFileInMapPack(), a very simple version of
_MapInfo_FindArenaFile().

qcsrc/common/mapobjects/func/door.qc
qcsrc/common/mapobjects/func/plat.qc
qcsrc/server/main.qc

index 418bdda9aeb53558280e8e2b81bbc8f4442b3209..ba2e53d27d027c2a01bbcd38736fec993665b60b 100644 (file)
@@ -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
index 4e4aa632ba7e562eda844200f371d15d2a1d4c38..23b9eb5b1725eee170cfd1ab7ab5c020bca102b3 100644 (file)
@@ -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 != "")
index 0d36ea47ede68762063b9780ac487f3053c13582..bee15d6cc867c685687ef5edf487914d4e4bc026 100644 (file)
@@ -468,6 +468,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