]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blobdiff - qcsrc/common/mapinfo.qc
rewrite settemp system to handle "quit" right
[xonotic/xonotic-data.pk3dir.git] / qcsrc / common / mapinfo.qc
index cca716a339abb4bc3cd78bbc2af6b7af2fd224a5..699a132fde2e97d62df9e3e8a9e97a479468ade7 100644 (file)
@@ -49,6 +49,7 @@ void MapInfo_Cache_Store()
        // now store all the stuff
        bufstr_set(_MapInfo_Cache_Buf_IndexToMapData,   i, MapInfo_Map_bspname);
        bufstr_set(_MapInfo_Cache_Buf_IndexToMapData, ++i, MapInfo_Map_title);
+       bufstr_set(_MapInfo_Cache_Buf_IndexToMapData, ++i, MapInfo_Map_titlestring);
        bufstr_set(_MapInfo_Cache_Buf_IndexToMapData, ++i, MapInfo_Map_description);
        bufstr_set(_MapInfo_Cache_Buf_IndexToMapData, ++i, MapInfo_Map_author);
        bufstr_set(_MapInfo_Cache_Buf_IndexToMapData, ++i, ftos(MapInfo_Map_supportedGametypes));
@@ -71,11 +72,13 @@ float MapInfo_Cache_Retrieve(string map)
        // now retrieve all the stuff
        MapInfo_Map_bspname = bufstr_get(_MapInfo_Cache_Buf_IndexToMapData, i);
        MapInfo_Map_title = bufstr_get(_MapInfo_Cache_Buf_IndexToMapData, ++i);
+       MapInfo_Map_titlestring = bufstr_get(_MapInfo_Cache_Buf_IndexToMapData, ++i);
        MapInfo_Map_description = bufstr_get(_MapInfo_Cache_Buf_IndexToMapData, ++i);
        MapInfo_Map_author = bufstr_get(_MapInfo_Cache_Buf_IndexToMapData, ++i);
        MapInfo_Map_supportedGametypes = stof(bufstr_get(_MapInfo_Cache_Buf_IndexToMapData, ++i));
        MapInfo_Map_supportedFeatures = stof(bufstr_get(_MapInfo_Cache_Buf_IndexToMapData, ++i));
        MapInfo_Map_flags = stof(bufstr_get(_MapInfo_Cache_Buf_IndexToMapData, ++i));
+
        return 1;
 }
 
@@ -324,6 +327,10 @@ float _MapInfo_Generate(string pFilename) // 0: failure, 1: ok ent, 2: ok bsp
                                        { }
                                else if(startsWith(v, "weapon_"))
                                        MapInfo_Map_supportedFeatures |= MAPINFO_FEATURE_WEAPONS;
+                               else if(startsWith(v, "turret_"))
+                                       MapInfo_Map_supportedFeatures |= MAPINFO_FEATURE_TURRETS;
+                               else if(startsWith(v, "vehicle_"))
+                                       MapInfo_Map_supportedFeatures |= MAPINFO_FEATURE_VEHICLES;
                                else if(v == "target_music" || v == "trigger_music")
                                        _MapInfo_Map_worldspawn_music = string_null; // don't use regular BGM
                        }
@@ -379,6 +386,7 @@ float _MapInfo_Generate(string pFilename) // 0: failure, 1: ok ent, 2: ok bsp
 void _MapInfo_Map_Reset()
 {
        MapInfo_Map_title = "<TITLE>";
+       MapInfo_Map_titlestring = "<TITLE>";
        MapInfo_Map_description = "<DESCRIPTION>";
        MapInfo_Map_author = "<AUTHOR>";
        MapInfo_Map_supportedGametypes = 0;
@@ -797,8 +805,33 @@ void _MapInfo_Parse_Settemp(string pFilename, string acl, float type, string s,
        }
 }
 
+float MapInfo_isRedundant(string fn, string t)
+{
+       // normalize file name
+       fn = strreplace("_", "-", fn);
+
+       // normalize visible title
+       t = strreplace(": ", "-", t);
+       t = strreplace(":", "-", t);
+       t = strreplace(" ", "-", t);
+       t = strreplace("_", "-", t);
+       t = strreplace("'", "-", t);
+
+       if(!strcasecmp(fn, t))
+               return TRUE;
+
+       // we allow the visible title to have punctuation the file name does
+       // not, but not vice versa
+       t = strreplace("-", "", t);
+
+       if(!strcasecmp(fn, t))
+               return TRUE;
+
+       return FALSE;
+}
+
 // load info about a map by name into the MapInfo_Map_* globals
-float MapInfo_Get_ByName(string pFilename, float pAllowGenerate, float pGametypeToSet)
+float MapInfo_Get_ByName_NoFallbacks(string pFilename, float pAllowGenerate, float pGametypeToSet)
 {
        string fn;
        string s, t;
@@ -868,6 +901,14 @@ float MapInfo_Get_ByName(string pFilename, float pAllowGenerate, float pGametype
                                fputs(fh, "has weapons\n");
                        else
                                fputs(fh, "// uncomment this if you added weapon pickups: has weapons\n");
+                       if(MapInfo_Map_supportedFeatures & MAPINFO_FEATURE_TURRETS)
+                               fputs(fh, "has turrets\n");
+                       else
+                               fputs(fh, "// uncomment this if you added turrets: has turrets\n");
+                       if(MapInfo_Map_supportedFeatures & MAPINFO_FEATURE_VEHICLES)
+                               fputs(fh, "has weapons\n");
+                       else
+                               fputs(fh, "// uncomment this if you added vehicles: has vehicles\n");
                        if(MapInfo_Map_flags & MAPINFO_FLAG_FRUSTRATING)
                                fputs(fh, "frustrating\n");
 
@@ -926,6 +967,8 @@ float MapInfo_Get_ByName(string pFilename, float pAllowGenerate, float pGametype
                {
                        t = car(s); s = cdr(s);
                        if     (t == "weapons") MapInfo_Map_supportedFeatures |= MAPINFO_FEATURE_WEAPONS;
+                       else if(t == "turrets") MapInfo_Map_supportedFeatures |= MAPINFO_FEATURE_TURRETS;
+                       else if(t == "vehicles") MapInfo_Map_supportedFeatures |= MAPINFO_FEATURE_VEHICLES;
                        else if(t == "new_toys") MapInfo_Map_supportedFeatures |= MAPINFO_FEATURE_WEAPONS;
                        else
                                dprint("Map ", pFilename, " supports unknown feature ", t, ", ignored\n");
@@ -1046,6 +1089,31 @@ float MapInfo_Get_ByName(string pFilename, float pAllowGenerate, float pGametype
        }
        fclose(fh);
 
+       if(MapInfo_Map_title == "<TITLE>")
+               MapInfo_Map_titlestring = MapInfo_Map_bspname;
+       else if(MapInfo_isRedundant(MapInfo_Map_bspname, MapInfo_Map_title))
+               MapInfo_Map_titlestring = MapInfo_Map_title;
+       else
+               MapInfo_Map_titlestring = sprintf(_("%s: %s"), MapInfo_Map_bspname, MapInfo_Map_title);
+
+       MapInfo_Cache_Store();
+       if(MapInfo_Map_supportedGametypes != 0)
+               return r;
+       dprint("Map ", pFilename, " supports no game types, ignored\n");
+       return 0;
+}
+float MapInfo_Get_ByName(string pFilename, float pAllowGenerate, float pGametypeToSet)
+{
+       float r = MapInfo_Get_ByName_NoFallbacks(pFilename, pAllowGenerate, pGametypeToSet);
+
+       if(cvar("g_tdm_on_dm_maps"))
+       {
+               // if this is set, all DM maps support TDM too
+               if not(MapInfo_Map_supportedGametypes & MAPINFO_TYPE_TEAM_DEATHMATCH)
+                       if(MapInfo_Map_supportedGametypes & MAPINFO_TYPE_DEATHMATCH)
+                               _MapInfo_Map_ApplyGametypeEx ("", pGametypeToSet, MAPINFO_TYPE_TEAM_DEATHMATCH);
+       }
+
        if(pGametypeToSet)
        {
                if(!(MapInfo_Map_supportedGametypes & pGametypeToSet))
@@ -1056,11 +1124,7 @@ float MapInfo_Get_ByName(string pFilename, float pAllowGenerate, float pGametype
                }
        }
 
-       MapInfo_Cache_Store();
-       if(MapInfo_Map_supportedGametypes != 0)
-               return r;
-       dprint("Map ", pFilename, " supports no game types, ignored\n");
-       return 0;
+       return r;
 }
 
 float MapInfo_FindName(string s)
@@ -1226,7 +1290,7 @@ void MapInfo_SwitchGameType(float t)
        cvar_set("g_keepaway",   (t == MAPINFO_TYPE_KEEPAWAY)        ? "1" : "0");
 }
 
-void MapInfo_LoadMap(string s)
+void MapInfo_LoadMap(string s, float reinit)
 {
        MapInfo_Map_supportedGametypes = 0;
        // we shouldn't need this, as LoadMapSettings already fixes the gametype
@@ -1235,7 +1299,12 @@ void MapInfo_LoadMap(string s)
        //      print("EMERGENCY: can't play the selected map in the given game mode. Falling back to DM.\n");
        //      MapInfo_SwitchGameType(MAPINFO_TYPE_DEATHMATCH);
        //}
-       localcmd(strcat("\nsettemp_restore\nchangelevel ", s, "\n"));
+       
+       cvar_settemp_restore();
+       if(reinit)
+               localcmd(strcat("\nmap ", s, "\n"));
+       else
+               localcmd(strcat("\nchangelevel ", s, "\n"));
 }
 
 string MapInfo_ListAllowedMaps(float pRequiredFlags, float pForbiddenFlags)
@@ -1313,6 +1382,7 @@ void MapInfo_ClearTemps()
 {
        MapInfo_Map_bspname = string_null;
        MapInfo_Map_title = string_null;
+       MapInfo_Map_titlestring = string_null;
        MapInfo_Map_description = string_null;
        MapInfo_Map_author = string_null;
        MapInfo_Map_clientstuff = string_null;