]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blobdiff - qcsrc/common/mapinfo.qc
Merge branch 'samual/keepaway' into fruitiex/freezetag_vs_keepaway
[xonotic/xonotic-data.pk3dir.git] / qcsrc / common / mapinfo.qc
index 6e43c5961063e432f36a9d4ea972b2839c4a8066..35a827f90035438c33b7a6ce60b25d19e5629008 100644 (file)
@@ -231,7 +231,7 @@ float _MapInfo_Generate(string pFilename) // 0: failure, 1: ok ent, 2: ok bsp
        }
        if(fh < 0)
                return 0;
-       print("Analyzing ", fn, " to generate initial mapinfo; please edit that file later\n");
+       print("Analyzing ", fn, " to generate initial mapinfo\n");
 
        inWorldspawn = 2;
        MapInfo_Map_flags = 0;
@@ -347,9 +347,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)
@@ -406,6 +408,8 @@ 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";
+               case MAPINFO_TYPE_KEEPAWAY:        return "30 20 0";
                default:                           return "";
        }
 }
@@ -462,6 +466,14 @@ void _MapInfo_Map_ApplyGametype(string s, float pWantedType, float pThisType, fl
                s = cdr(s);
        }
 
+       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)
        {
@@ -525,14 +537,16 @@ string _MapInfo_GetDefaultEx(float t)
                case MAPINFO_TYPE_RACE:            return "timelimit=20 qualifying_timelimit=5 laplimit=7 teamlaplimit=15 leadlimit=0";
                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";
+               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 "";
        }
 }
 
 void _MapInfo_Map_ApplyGametypeEx(string s, float pWantedType, float pThisType)
 {
-       string sa, k, v, spre;
+       string sa, k, v;
        float p;
        string fraglimit_normal;
        string fraglimit_caps;
@@ -650,6 +664,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 +686,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 "";
 }
@@ -804,69 +822,76 @@ float MapInfo_Get_ByName(string pFilename, float pAllowGenerate, float pGametype
        fh = fopen(fn, FILE_READ);
        if(fh < 0)
        {
-               if(!pAllowGenerate)
-                       return 0;
-               _MapInfo_Map_Reset();
-               r = _MapInfo_Generate(pFilename);
-               if(!r)
-                       return 0;
-               fh = fopen(fn, FILE_WRITE);
-               fputs(fh, strcat("title ", MapInfo_Map_title, "\n"));
-               fputs(fh, strcat("description ", MapInfo_Map_description, "\n"));
-               fputs(fh, strcat("author ", MapInfo_Map_author, "\n"));
-               if(_MapInfo_Map_worldspawn_music != "")
+               fn = strcat("maps/autogenerated/", pFilename, ".mapinfo");
+               fh = fopen(fn, FILE_READ);
+               if(fh < 0)
                {
-                       if(
-                               substring(_MapInfo_Map_worldspawn_music, strlen(_MapInfo_Map_worldspawn_music) - 4, 4) == ".wav"
-                               ||
-                               substring(_MapInfo_Map_worldspawn_music, strlen(_MapInfo_Map_worldspawn_music) - 4, 4) == ".ogg"
-                       )
-                               fputs(fh, strcat("cdtrack ", substring(_MapInfo_Map_worldspawn_music, 0, strlen(_MapInfo_Map_worldspawn_music) - 4), "\n"));
+                       if(!pAllowGenerate)
+                               return 0;
+                       _MapInfo_Map_Reset();
+                       r = _MapInfo_Generate(pFilename);
+                       if(!r)
+                               return 0;
+                       fh = fopen(fn, FILE_WRITE);
+                       fputs(fh, strcat("title ", MapInfo_Map_title, "\n"));
+                       fputs(fh, strcat("description ", MapInfo_Map_description, "\n"));
+                       fputs(fh, strcat("author ", MapInfo_Map_author, "\n"));
+                       if(_MapInfo_Map_worldspawn_music != "")
+                       {
+                               if(
+                                       substring(_MapInfo_Map_worldspawn_music, strlen(_MapInfo_Map_worldspawn_music) - 4, 4) == ".wav"
+                                       ||
+                                       substring(_MapInfo_Map_worldspawn_music, strlen(_MapInfo_Map_worldspawn_music) - 4, 4) == ".ogg"
+                               )
+                                       fputs(fh, strcat("cdtrack ", substring(_MapInfo_Map_worldspawn_music, 0, strlen(_MapInfo_Map_worldspawn_music) - 4), "\n"));
+                               else
+                                       fputs(fh, strcat("cdtrack ", _MapInfo_Map_worldspawn_music, "\n"));
+                       }
                        else
-                               fputs(fh, strcat("cdtrack ", _MapInfo_Map_worldspawn_music, "\n"));
-               }
-               else
-               {
-                       n = tokenize_console(cvar_string("g_cdtracks_remaplist"));
-                       s = strcat(" ", cvar_string("g_cdtracks_dontusebydefault"), " ");
-                       for(;;)
                        {
-                               i = floor(random() * n);
-                               if(strstrofs(s, strcat(" ", argv(i), " "), 0) < 0)
-                                       break;
+                               n = tokenize_console(cvar_string("g_cdtracks_remaplist"));
+                               s = strcat(" ", cvar_string("g_cdtracks_dontusebydefault"), " ");
+                               for(;;)
+                               {
+                                       i = floor(random() * n);
+                                       if(strstrofs(s, strcat(" ", argv(i), " "), 0) < 0)
+                                               break;
+                               }
+                               fputs(fh, strcat("cdtrack ", ftos(i + 1), "\n"));
                        }
-                       fputs(fh, strcat("cdtrack ", ftos(i + 1), "\n"));
-               }
-               if(MapInfo_Map_supportedFeatures & MAPINFO_FEATURE_WEAPONS)
-                       fputs(fh, "has weapons\n");
-               else
-                       fputs(fh, "// uncomment this if you added weapon pickups: has weapons\n");
-               if(MapInfo_Map_flags & MAPINFO_FLAG_FRUSTRATING)
-                       fputs(fh, "frustrating\n");
+                       if(MapInfo_Map_supportedFeatures & MAPINFO_FEATURE_WEAPONS)
+                               fputs(fh, "has weapons\n");
+                       else
+                               fputs(fh, "// uncomment this if you added weapon pickups: has weapons\n");
+                       if(MapInfo_Map_flags & MAPINFO_FLAG_FRUSTRATING)
+                               fputs(fh, "frustrating\n");
 
-               for(i = 1; i <= MapInfo_Map_supportedGametypes; i *= 2)
-                       if(MapInfo_Map_supportedGametypes & i)
-                               fputs(fh, sprintf("gametype %s\n", MapInfo_Type_ToString(i), " // ", _MapInfo_GetDefaultEx(i)));
+                       for(i = 1; i <= MapInfo_Map_supportedGametypes; i *= 2)
+                               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);
-                       fputs(fh, "settemp_for_type all sv_q3acompat_machineshotgunswap 1\n");
-               }
+                       fh2 = fopen(strcat("scripts/", pFilename, ".arena"), FILE_READ);
+                       if(fh2 >= 0)
+                       {
+                               fclose(fh2);
+                               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");
-               fputs(fh, "// optional: clientsettemp_for_type (all|gametypename) cvarname value\n");
-               fputs(fh, "// optional: size mins_x mins_y mins_z maxs_x maxs_y maxs_z\n");
-               fputs(fh, "// optional: hidden\n");
+                       fputs(fh, "// optional: fog density red green blue alpha mindist maxdist\n");
+                       fputs(fh, "// optional: settemp_for_type (all|gametypename) cvarname value\n");
+                       fputs(fh, "// optional: clientsettemp_for_type (all|gametypename) cvarname value\n");
+                       fputs(fh, "// optional: size mins_x mins_y mins_z maxs_x maxs_y maxs_z\n");
+                       fputs(fh, "// optional: hidden\n");
 
-               fclose(fh);
-               r = 2;
-               // return r;
-               fh = fopen(fn, FILE_READ);
-               if(fh < 0)
-                       error("... but I just wrote it!");
+                       fclose(fh);
+                       r = 2;
+                       // return r;
+                       fh = fopen(fn, FILE_READ);
+                       if(fh < 0)
+                               error("... but I just wrote it!");
+               }
+
+               print("WARNING: autogenerated mapinfo file ", fn, " has been loaded; please edit that file and move it to maps/", pFilename, ".mapinfo\n");
        }
 
        _MapInfo_Map_Reset();
@@ -900,6 +925,7 @@ 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 == "new_toys") MapInfo_Map_supportedFeatures |= MAPINFO_FEATURE_WEAPONS;
                        else
                                dprint("Map ", pFilename, " supports unknown feature ", t, ", ignored\n");
                }
@@ -1022,8 +1048,9 @@ float MapInfo_Get_ByName(string pFilename, float pAllowGenerate, float pGametype
        {
                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;
                }
        }
 
@@ -1125,6 +1152,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;
 }
@@ -1165,7 +1196,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 "";
        }
 }
@@ -1187,6 +1220,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)
@@ -1225,6 +1260,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;
@@ -1238,12 +1275,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
                {