]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blobdiff - qcsrc/common/mapinfo.qc
Merge remote-tracking branch 'origin/terencehill/g_changeteam_banned_fix'
[xonotic/xonotic-data.pk3dir.git] / qcsrc / common / mapinfo.qc
index 33889827e36deebad5975fc15b7cc171b79ff708..aad95a1fe5421c38ae4169ae282bb8c42978e079 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
                        }
@@ -347,9 +354,11 @@ float _MapInfo_Generate(string pFilename) // 0: failure, 1: ok ent, 2: ok bsp
                MapInfo_Map_supportedGametypes |= MAPINFO_TYPE_DEATHMATCH;      // DM always works
                MapInfo_Map_supportedGametypes |= MAPINFO_TYPE_RUNEMATCH;       // Rune always works
                MapInfo_Map_supportedGametypes |= MAPINFO_TYPE_LMS;             // LMS always works
+               MapInfo_Map_supportedGametypes |= MAPINFO_TYPE_KEEPAWAY;                // Keepaway always works
 
                if(spawnpoints >= 8  && diameter > 4096) {
                        MapInfo_Map_supportedGametypes |= MAPINFO_TYPE_TEAM_DEATHMATCH;
+                       MapInfo_Map_supportedGametypes |= MAPINFO_TYPE_FREEZETAG;
                        MapInfo_Map_supportedGametypes |= MAPINFO_TYPE_CA;
                }
                if(                     diameter < 4096)
@@ -377,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;
@@ -406,6 +416,11 @@ string _MapInfo_GetDefault(float t)
                case MAPINFO_TYPE_ONSLAUGHT:       return "20 0";
                case MAPINFO_TYPE_NEXBALL:         return "5 20 0";
                case MAPINFO_TYPE_CTS:             return "20 0 0";
+               case MAPINFO_TYPE_FREEZETAG:       return "10 20 0";
+               // NOTE: DO NOT ADD ANY MORE GAME TYPES HERE
+               // THIS IS JUST LEGACY SUPPORT FOR NEXUIZ MAPS
+               // ONLY ADD NEW STUFF TO _MapInfo_GetDefaultEx
+               // THIS FUNCTION WILL EVENTUALLY BE REMOVED
                default:                           return "";
        }
 }
@@ -462,6 +477,16 @@ void _MapInfo_Map_ApplyGametype(string s, float pWantedType, float pThisType, fl
                s = cdr(s);
        }
 
+       /* keepaway wuz here
+       if(pWantedType == MAPINFO_TYPE_KEEPAWAY)
+       {
+               sa = car(s);
+               if(sa != "")
+                       cvar_set("fraglimit", sa);
+               s = cdr(s);
+       }
+       */
+       
        // rc = timelimit timelimit_qualification laps laps_teamplay
        if(pWantedType == MAPINFO_TYPE_RACE)
        {
@@ -526,6 +551,8 @@ string _MapInfo_GetDefaultEx(float t)
                case MAPINFO_TYPE_ONSLAUGHT:       return "timelimit=20";
                case MAPINFO_TYPE_NEXBALL:         return "timelimit=20 pointlimit=5 leadlimit=0";
                case MAPINFO_TYPE_CTS:             return "timelimit=20 skill=-1";
+               case MAPINFO_TYPE_FREEZETAG:       return "timelimit=20 pointlimit=10 teams=2 leadlimit=0";
+               case MAPINFO_TYPE_KEEPAWAY:        return "timelimit=20 pointlimit=30";
                default:                           return "";
        }
 }
@@ -650,6 +677,8 @@ float MapInfo_Type_FromString(string t)
        else if(t == "rc")      return MAPINFO_TYPE_RACE;
        else if(t == "nexball") return MAPINFO_TYPE_NEXBALL;
        else if(t == "cts")     return MAPINFO_TYPE_CTS;
+       else if(t == "freezetag")       return MAPINFO_TYPE_FREEZETAG;
+       else if(t == "keepaway") return MAPINFO_TYPE_KEEPAWAY;
        else if(t == "all")     return MAPINFO_TYPE_ALL;
        else                    return 0;
 }
@@ -670,6 +699,8 @@ string MapInfo_Type_ToString(float t)
        else if(t == MAPINFO_TYPE_RACE)            return "rc";
        else if(t == MAPINFO_TYPE_NEXBALL)         return "nexball";
        else if(t == MAPINFO_TYPE_CTS)             return "cts";
+       else if(t == MAPINFO_TYPE_FREEZETAG)       return "freezetag";
+       else if(t == MAPINFO_TYPE_KEEPAWAY)        return "keepaway";
        else if(t == MAPINFO_TYPE_ALL)             return "all";
        else                                       return "";
 }
@@ -774,12 +805,37 @@ 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;
-       float fh, fh2;
+       float fh;
        float r, f, n, i, p;
        string acl;
 
@@ -845,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");
 
@@ -852,12 +916,8 @@ float MapInfo_Get_ByName(string pFilename, float pAllowGenerate, float pGametype
                                if(MapInfo_Map_supportedGametypes & i)
                                        fputs(fh, sprintf("gametype %s // defaults: %s\n", MapInfo_Type_ToString(i), _MapInfo_GetDefaultEx(i)));
 
-                       fh2 = fopen(strcat("scripts/", pFilename, ".arena"), FILE_READ);
-                       if(fh2 >= 0)
-                       {
-                               fclose(fh2);
+                       if(fexists(strcat("scripts/", pFilename, ".arena")))
                                fputs(fh, "settemp_for_type all sv_q3acompat_machineshotgunswap 1\n");
-                       }
 
                        fputs(fh, "// optional: fog density red green blue alpha mindist maxdist\n");
                        fputs(fh, "// optional: settemp_for_type (all|gametypename) cvarname value\n");
@@ -907,6 +967,9 @@ 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");
                }
@@ -926,6 +989,7 @@ float MapInfo_Get_ByName(string pFilename, float pAllowGenerate, float pGametype
                {
                        t = car(s); s = cdr(s);
                        f = MapInfo_Type_FromString(t);
+                       print("Map ", pFilename, " contains the legacy 'type' keyword which is deprecated and will be removed in the future. Please migrate the mapinfo file to 'gametype'.\n");
                        if(f)
                                _MapInfo_Map_ApplyGametype (s, pGametypeToSet, f, TRUE);
                        else
@@ -1025,20 +1089,42 @@ 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))
                {
-                       print("Can't select the requested game type. Trying anyway with stupid settings.\n");
-                       _MapInfo_Map_ApplyGametypeEx("", pGametypeToSet, MAPINFO_TYPE_DEATHMATCH);
+                       error("Can't select the requested game type. This should never happen as the caller should prevent it!\n");
+                       //_MapInfo_Map_ApplyGametypeEx("", pGametypeToSet, MAPINFO_TYPE_DEATHMATCH);
+                       //return;
                }
        }
 
-       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)
@@ -1132,6 +1218,10 @@ float MapInfo_CurrentGametype()
                return MAPINFO_TYPE_NEXBALL;
        else if(cvar("g_cts"))
                return MAPINFO_TYPE_CTS;
+       else if(cvar("g_freezetag"))
+               return MAPINFO_TYPE_FREEZETAG;
+       else if(cvar("g_keepaway"))
+               return MAPINFO_TYPE_KEEPAWAY;
        else
                return MAPINFO_TYPE_DEATHMATCH;
 }
@@ -1172,7 +1262,9 @@ string MapInfo_GetGameTypeCvar(float t)
                case MAPINFO_TYPE_ONSLAUGHT: return "g_onslaught";
                case MAPINFO_TYPE_RACE: return "g_race";
                case MAPINFO_TYPE_NEXBALL: return "g_nexball";
+               case MAPINFO_TYPE_FREEZETAG: return "g_freezetag";
                case MAPINFO_TYPE_CTS: return "g_cts";
+               case MAPINFO_TYPE_KEEPAWAY:             return "g_keepaway";
                default: return "";
        }
 }
@@ -1194,6 +1286,8 @@ void MapInfo_SwitchGameType(float t)
        cvar_set("g_race",       (t == MAPINFO_TYPE_RACE)            ? "1" : "0");
        cvar_set("g_nexball",    (t == MAPINFO_TYPE_NEXBALL)         ? "1" : "0");
        cvar_set("g_cts",        (t == MAPINFO_TYPE_CTS)             ? "1" : "0");
+       cvar_set("g_freezetag",  (t == MAPINFO_TYPE_FREEZETAG)       ? "1" : "0");
+       cvar_set("g_keepaway",   (t == MAPINFO_TYPE_KEEPAWAY)        ? "1" : "0");
 }
 
 void MapInfo_LoadMap(string s)
@@ -1223,6 +1317,24 @@ string MapInfo_ListAllowedMaps(float pRequiredFlags, float pForbiddenFlags)
        return substring(out, 1, strlen(out) - 1);
 }
 
+string MapInfo_ListAllAllowedMaps(float pRequiredFlags, float pForbiddenFlags)
+{
+       string out;
+       float i;
+
+       // to make absolutely sure:
+       MapInfo_Enumerate();
+       MapInfo_FilterGametype(MAPINFO_TYPE_ALL, 0, pRequiredFlags, pForbiddenFlags, 0);
+
+       out = "";
+       for(i = 0; i < MapInfo_count; ++i)
+               out = strcat(out, " ", _MapInfo_GlobItem(MapInfo_FilterList_Lookup(i)));
+
+       MapInfo_FilterGametype(MapInfo_CurrentGametype(), MapInfo_CurrentFeatures(), pRequiredFlags, pForbiddenFlags, 0);
+
+       return substring(out, 1, strlen(out) - 1);
+}
+
 void MapInfo_LoadMapSettings(string s) // to be called from worldspawn
 {
        float t, t0;
@@ -1232,6 +1344,8 @@ void MapInfo_LoadMapSettings(string s) // to be called from worldspawn
                {
                        print("Mapinfo system is not functional at all. Assuming deathmatch.\n");
                        MapInfo_Map_supportedGametypes = MAPINFO_TYPE_DEATHMATCH;
+                       _MapInfo_Map_ApplyGametypeEx("", t0, t0);
+                       return; // do not call Get_ByName!
                }
 
                t = 1;
@@ -1245,12 +1359,9 @@ void MapInfo_LoadMapSettings(string s) // to be called from worldspawn
                if(cvar("g_mapinfo_allow_unsupported_modes_and_let_stuff_break"))
                {
                        print("EMERGENCY: can't play the selected map in the given game mode. Working with only the override settings.\n");
-                       cvar_set("timelimit", "0");
-                       cvar_set("fraglimit", "0");
-                       cvar_set("g_tdm_teams", "2");
-                       cvar_set("g_keyhunt_teams", "3");
-                       cvar_set("g_race_qualifying_timelimit", "0");
-                       cvar_set("leadlimit", "0");
+                       cvar_settemp_restore();
+                       _MapInfo_Map_ApplyGametypeEx("", t0, t0);
+                       return; // do not call Get_ByName!
                }
                else
                {
@@ -1266,6 +1377,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;