]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blobdiff - qcsrc/common/mapinfo.qc
fix starting the gametype
[xonotic/xonotic-data.pk3dir.git] / qcsrc / common / mapinfo.qc
index 862f7b98ab82c76308cebb8e08f4ac29420a500b..895639e54dc25a4d836fd32eb1170cd93757d244 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;
@@ -350,6 +350,7 @@ float _MapInfo_Generate(string pFilename) // 0: failure, 1: ok ent, 2: ok bsp
 
                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 +407,7 @@ 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";
                default:                           return "";
        }
 }
@@ -526,13 +528,14 @@ 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";
                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 +653,7 @@ 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 == "all")     return MAPINFO_TYPE_ALL;
        else                    return 0;
 }
@@ -670,6 +674,7 @@ 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_ALL)             return "all";
        else                                       return "";
 }
@@ -804,69 +809,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 +912,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 +1035,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 +1139,8 @@ 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
                return MAPINFO_TYPE_DEATHMATCH;
 }
@@ -1165,6 +1181,7 @@ 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";
                default: return "";
        }
@@ -1187,6 +1204,7 @@ 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");
 }
 
 void MapInfo_LoadMap(string s)
@@ -1225,6 +1243,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 +1258,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
                {