]> git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blobdiff - qcsrc/common/mapinfo.qc
Fix display of maps with missing previews, add a new option (enabled by default)...
[xonotic/xonotic-data.pk3dir.git] / qcsrc / common / mapinfo.qc
index 29538b621a4f8f586a0066803c36985fd5a5187c..1a03102186c774203956e03f98e13ec1dd2020a9 100644 (file)
@@ -9,6 +9,8 @@
     #include <common/monsters/_mod.qh>
 #endif
 
+bool autocvar_g_mapinfo_arena_compat = true;
+
 #ifdef MENUQC
 #define WARN_COND false
 #else
@@ -299,6 +301,22 @@ float _MapInfo_Generate(string pFilename) // 0: failure, 1: ok ent, 2: ok bsp
        mapMins = '0 0 0';
        mapMaxs = '0 0 0';
 
+       // try for a .arena or .defi file if no .mapinfo exists
+       bool isdefi = false;
+       string arena_fn = _MapInfo_FindArenaFile(pFilename, ".arena");
+       int arena_fh = fopen(arena_fn, FILE_READ);
+       if(arena_fh < 0)
+       {
+               isdefi = true;
+               arena_fn = _MapInfo_FindArenaFile(pFilename, ".defi");
+               arena_fh = fopen(arena_fn, FILE_READ);
+       }
+       if(arena_fh >= 0)
+       {
+               _MapInfo_ParseArena(arena_fn, arena_fh, pFilename, NULL, isdefi, true);
+               fclose(arena_fh);
+       }
+
        for (;;)
        {
                if (!((s = fgets(fh))))
@@ -761,7 +779,7 @@ float MapInfo_isRedundant(string fn, string t)
        return false;
 }
 
-bool _MapInfo_ParseArena(string arena_filename, int fh, string pFilename, Gametype pGametypeToSet, bool isdefi)
+bool _MapInfo_ParseArena(string arena_filename, int fh, string pFilename, Gametype pGametypeToSet, bool isdefi, bool isgenerator)
 {
        // NOTE: .arena files can hold more than 1 map's information!
        // to handle this, we're going to store gathered information in local variables and save it if we encounter the correct map name
@@ -809,10 +827,15 @@ bool _MapInfo_ParseArena(string arena_filename, int fh, string pFilename, Gamety
                                if(stored_Map_title != "")
                                        MapInfo_Map_title = stored_Map_title;
                                MapInfo_Map_author = stored_Map_author;
-                               FOREACH(Gametypes, it.m_flags & stored_supportedGametypes,
+                               if(isgenerator)
+                                       MapInfo_Map_supportedGametypes = stored_supportedGametypes;
+                               else
                                {
-                                       _MapInfo_Map_ApplyGametype ("", pGametypeToSet, it, true);
-                               });
+                                       FOREACH(Gametypes, it.m_flags & stored_supportedGametypes,
+                                       {
+                                               _MapInfo_Map_ApplyGametype ("", pGametypeToSet, it, true);
+                                       });
+                               }
                                return true; // no need to continue through the file, we have our map!
                        }
                        else
@@ -898,20 +921,20 @@ string(string filename) whichpack = #503;
 #endif
 string _MapInfo_FindArenaFile(string pFilename, string extension)
 {
-       string base_pack = whichpack(strcat("maps/", pFilename, ".bsp"));
        string fallback = strcat("scripts/", pFilename, extension);
+       if(!checkextension("DP_QC_FS_SEARCH_PACKFILE"))
+               return fallback;
+       string base_pack = whichpack(strcat("maps/", pFilename, ".bsp"));
        if(base_pack == "") // this map isn't packaged!
                return fallback;
 
-       int glob = search_begin(strcat("scripts/*", extension), true, true);
+       int glob = search_packfile_begin(strcat("scripts/*", extension), true, true, base_pack);
        if(glob < 0)
                return fallback;
        int n = search_getsize(glob);
        for(int j = 0; j < n; ++j)
        {
                string file = search_getfilename(glob, j);
-               if(whichpack(file) != base_pack)
-                       continue; // not in the same pk3!
 
                int fh = fopen(file, FILE_READ);
                if(fh < 0)
@@ -967,21 +990,24 @@ float MapInfo_Get_ByName_NoFallbacks(string pFilename, int pAllowGenerate, Gamet
        fh = fopen(fn, FILE_READ);
        if(fh < 0)
        {
-               bool isdefi = false;
-               // try for a .arena or .defi file if no .mapinfo exists
-               fn = _MapInfo_FindArenaFile(pFilename, ".arena");
-               fh = fopen(fn, FILE_READ);
-               if(fh < 0)
+               if(autocvar_g_mapinfo_arena_compat)
                {
-                       isdefi = true;
-                       fn = _MapInfo_FindArenaFile(pFilename, ".defi");
+                       // try for .arena or .defi files if no .mapinfo exists
+                       bool isdefi = false;
+                       fn = _MapInfo_FindArenaFile(pFilename, ".arena");
                        fh = fopen(fn, FILE_READ);
-               }
-               if(fh >= 0)
-               {
-                       _MapInfo_Map_Reset();
-                       if(_MapInfo_ParseArena(fn, fh, pFilename, pGametypeToSet, isdefi))
-                               goto mapinfo_handled; // skip generation
+                       if(fh < 0)
+                       {
+                               isdefi = true;
+                               fn = _MapInfo_FindArenaFile(pFilename, ".defi");
+                               fh = fopen(fn, FILE_READ);
+                       }
+                       if(fh >= 0)
+                       {
+                               _MapInfo_Map_Reset();
+                               if(_MapInfo_ParseArena(fn, fh, pFilename, pGametypeToSet, isdefi, false))
+                                       goto mapinfo_handled; // skip generation
+                       }
                }
 
                fn = strcat("maps/autogenerated/", pFilename, ".mapinfo");