3 #include <common/util.qh>
4 #include <common/weapons/_all.qh>
7 #include <common/util.qh>
8 #include <common/monsters/_mod.qh>
11 int autocvar_g_mapinfo_q3compat = 1;
14 bool autocvar_g_mapinfo_ignore_warnings;
15 #define WARN_COND (!autocvar_g_mapinfo_ignore_warnings && MapInfo_Map_bspname == mi_shortname)
17 #define WARN_COND false
20 // generic string stuff
22 int _MapInfo_Cache_Active;
23 int _MapInfo_Cache_DB_NameToIndex;
24 int _MapInfo_Cache_Buf_IndexToMapData;
26 void MapInfo_Cache_Destroy()
28 if(!_MapInfo_Cache_Active)
31 db_close(_MapInfo_Cache_DB_NameToIndex);
32 buf_del(_MapInfo_Cache_Buf_IndexToMapData);
33 _MapInfo_Cache_Active = 0;
36 void MapInfo_Cache_Create()
38 MapInfo_Cache_Destroy();
39 _MapInfo_Cache_DB_NameToIndex = db_create();
40 _MapInfo_Cache_Buf_IndexToMapData = buf_create();
41 _MapInfo_Cache_Active = 1;
44 void MapInfo_Cache_Invalidate()
46 if(!_MapInfo_Cache_Active)
49 MapInfo_Cache_Create();
52 void MapInfo_Cache_Store()
56 if(!_MapInfo_Cache_Active)
59 s = db_get(_MapInfo_Cache_DB_NameToIndex, MapInfo_Map_bspname);
62 i = buf_getsize(_MapInfo_Cache_Buf_IndexToMapData);
63 db_put(_MapInfo_Cache_DB_NameToIndex, MapInfo_Map_bspname, ftos(i));
68 // now store all the stuff
69 bufstr_set(_MapInfo_Cache_Buf_IndexToMapData, i, MapInfo_Map_bspname);
70 bufstr_set(_MapInfo_Cache_Buf_IndexToMapData, ++i, MapInfo_Map_title);
71 bufstr_set(_MapInfo_Cache_Buf_IndexToMapData, ++i, MapInfo_Map_titlestring);
72 bufstr_set(_MapInfo_Cache_Buf_IndexToMapData, ++i, MapInfo_Map_description);
73 bufstr_set(_MapInfo_Cache_Buf_IndexToMapData, ++i, MapInfo_Map_author);
74 bufstr_set(_MapInfo_Cache_Buf_IndexToMapData, ++i, ftos(MapInfo_Map_supportedGametypes));
75 bufstr_set(_MapInfo_Cache_Buf_IndexToMapData, ++i, ftos(MapInfo_Map_supportedFeatures));
76 bufstr_set(_MapInfo_Cache_Buf_IndexToMapData, ++i, ftos(MapInfo_Map_flags));
79 float MapInfo_Cache_Retrieve(string map)
83 if(!_MapInfo_Cache_Active)
86 s = db_get(_MapInfo_Cache_DB_NameToIndex, map);
91 // now retrieve all the stuff
92 MapInfo_Map_bspname = bufstr_get(_MapInfo_Cache_Buf_IndexToMapData, i);
93 MapInfo_Map_title = bufstr_get(_MapInfo_Cache_Buf_IndexToMapData, ++i);
94 MapInfo_Map_titlestring = bufstr_get(_MapInfo_Cache_Buf_IndexToMapData, ++i);
95 MapInfo_Map_description = bufstr_get(_MapInfo_Cache_Buf_IndexToMapData, ++i);
96 MapInfo_Map_author = bufstr_get(_MapInfo_Cache_Buf_IndexToMapData, ++i);
97 MapInfo_Map_supportedGametypes = stof(bufstr_get(_MapInfo_Cache_Buf_IndexToMapData, ++i));
98 MapInfo_Map_supportedFeatures = stof(bufstr_get(_MapInfo_Cache_Buf_IndexToMapData, ++i));
99 MapInfo_Map_flags = stof(bufstr_get(_MapInfo_Cache_Buf_IndexToMapData, ++i));
104 // GLOB HANDLING (for all BSP files)
105 float _MapInfo_globopen;
106 float _MapInfo_globcount;
107 float _MapInfo_globhandle;
108 string _MapInfo_GlobItem(float i)
111 if(!_MapInfo_globopen)
113 s = search_getfilename(_MapInfo_globhandle, i);
114 return substring(s, 5, strlen(s) - 9); // without maps/ and .bsp
117 void MapInfo_Enumerate()
119 if(_MapInfo_globopen)
121 search_end(_MapInfo_globhandle);
122 _MapInfo_globopen = 0;
124 MapInfo_Cache_Invalidate();
125 _MapInfo_globhandle = search_begin("maps/*.bsp", true, true);
126 if(_MapInfo_globhandle >= 0)
128 _MapInfo_globcount = search_getsize(_MapInfo_globhandle);
129 _MapInfo_globopen = 1;
132 _MapInfo_globcount = 0;
135 // filter the info by game type mask (updates MapInfo_count)
137 float _MapInfo_filtered;
138 float _MapInfo_filtered_allocated;
139 float MapInfo_FilterList_Lookup(float i)
141 return stof(bufstr_get(_MapInfo_filtered, i));
144 void _MapInfo_FilterList_swap(float i, float j, entity pass)
147 h = bufstr_get(_MapInfo_filtered, i);
148 bufstr_set(_MapInfo_filtered, i, bufstr_get(_MapInfo_filtered, j));
149 bufstr_set(_MapInfo_filtered, j, h);
152 float _MapInfo_FilterList_cmp(float i, float j, entity pass)
155 a = _MapInfo_GlobItem(stof(bufstr_get(_MapInfo_filtered, i)));
156 b = _MapInfo_GlobItem(stof(bufstr_get(_MapInfo_filtered, j)));
157 return strcasecmp(a, b);
160 float MapInfo_FilterGametype(Gametype pGametype, int pFeatures, int pFlagsRequired, int pFlagsForbidden, bool pAbortOnGenerate)
162 return _MapInfo_FilterGametype(pGametype.m_flags, pFeatures, pFlagsRequired, pFlagsForbidden, pAbortOnGenerate);
164 float _MapInfo_FilterGametype(int pGametype, int pFeatures, int pFlagsRequired, int pFlagsForbidden, bool pAbortOnGenerate)
167 if (!_MapInfo_filtered_allocated)
169 _MapInfo_filtered_allocated = 1;
170 _MapInfo_filtered = buf_create();
173 for(i = 0, j = -1; i < _MapInfo_globcount; ++i)
175 if(MapInfo_Get_ByName(_MapInfo_GlobItem(i), 1, NULL) == 2) // if we generated one... BAIL OUT and let the caller continue in the next frame.
178 LOG_TRACE("Autogenerated a .mapinfo, doing the rest later.");
179 MapInfo_progress = i / _MapInfo_globcount;
182 if((MapInfo_Map_supportedGametypes & pGametype) != 0)
183 if((MapInfo_Map_supportedFeatures & pFeatures) == pFeatures)
184 if((MapInfo_Map_flags & pFlagsForbidden) == 0)
185 if((MapInfo_Map_flags & pFlagsRequired) == pFlagsRequired)
186 bufstr_set(_MapInfo_filtered, ++j, ftos(i));
188 MapInfo_count = j + 1;
189 MapInfo_ClearTemps();
191 // sometimes the glob isn't sorted nicely, so fix it here...
192 heapsort(MapInfo_count, _MapInfo_FilterList_swap, _MapInfo_FilterList_cmp, NULL);
196 void MapInfo_FilterString(string sf)
198 // this function further filters _MapInfo_filtered, which is prepared by MapInfo_FilterGametype by string
202 for(i = 0, j = -1; i < MapInfo_count; ++i)
204 if (MapInfo_Get_ByID(i))
206 // prepare for keyword filter
207 if (MapInfo_Map_title && strstrofs(MapInfo_Map_title, "<TITLE>", 0) == -1)
208 title = MapInfo_Map_title;
210 title = MapInfo_Map_bspname;
212 if((strstrofs(strtolower(title), strtolower(sf), 0)) >= 0)
213 bufstr_set(_MapInfo_filtered, ++j, bufstr_get(_MapInfo_filtered, i));
216 MapInfo_count = j + 1;
217 MapInfo_ClearTemps();
219 // sometimes the glob isn't sorted nicely, so fix it here...
220 heapsort(MapInfo_count, _MapInfo_FilterList_swap, _MapInfo_FilterList_cmp, NULL);
223 void MapInfo_Filter_Free()
225 if(_MapInfo_filtered_allocated)
227 buf_del(_MapInfo_filtered);
228 _MapInfo_filtered_allocated = 0;
232 // load info about the i-th map into the MapInfo_Map_* globals
233 string MapInfo_BSPName_ByID(float i)
235 return _MapInfo_GlobItem(MapInfo_FilterList_Lookup(i));
238 string unquote(string s)
241 for(float i = 0; i < l; ++i)
243 string ch = substring(s, i, 1);
244 if((ch != " ") && (ch != "\""))
246 for(float j = l - i - 1; j > 0; --j)
248 ch = substring(s, i+j, 1);
249 if(ch != " ") if(ch != "\"")
250 return substring(s, i, j+1);
252 return substring(s, i, 1);
258 bool MapInfo_Get_ByID(int i)
260 return MapInfo_Get_ByName(MapInfo_BSPName_ByID(i), 0, NULL) ? true : false;
263 string _MapInfo_Map_worldspawn_music;
265 float _MapInfo_Generate(string pFilename) // 0: failure, 1: ok ent, 2: ok bsp
274 float diameter, spawnpoints;
276 bool is_q3df_map = false;
277 vector mapMins, mapMaxs;
279 if(autocvar_g_mapinfo_q3compat >= 2) // generate mapinfo using arena data
281 // try for .arena or .defi files, as they may have more accurate information
282 // supporting .arena AND .defi for the same map
283 bool success = false;
285 fn = _MapInfo_FindArenaFile(pFilename, ".arena");
286 if(fn != "" && (fh = fopen(fn, FILE_READ)) >= 0)
288 success = _MapInfo_ParseArena(fn, fh, pFilename, NULL, false, true);
291 fn = _MapInfo_FindArenaFile(pFilename, ".defi");
292 if(fn != "" && (fh = fopen(fn, FILE_READ)) >= 0)
294 success |= _MapInfo_ParseArena(fn, fh, pFilename, NULL, true, true);
297 if (success && autocvar_g_mapinfo_q3compat == 3)
298 return 3; // skip entity analysis
302 fn = strcat("maps/", pFilename, ".ent");
303 fh = fopen(fn, FILE_READ);
307 fn = strcat("maps/", pFilename, ".bsp");
308 fh = fopen(fn, FILE_READ);
312 LOG_INFO("Generating ", pFilename, ".mapinfo: analyzing ", fn);
317 _MapInfo_Map_worldspawn_music = "";
323 if (!((s = fgets(fh))))
325 if(inWorldspawn == 1)
326 if(startsWith(s, "}"))
332 if(k == "classname" && v == "worldspawn")
334 else if(k == "author")
335 MapInfo_Map_author = v;
336 else if(k == "_description")
337 MapInfo_Map_description = v;
338 else if(k == "music")
339 _MapInfo_Map_worldspawn_music = v;
340 else if(k == "noise")
341 _MapInfo_Map_worldspawn_music = v;
342 else if(k == "message" && (!MapInfo_Map_title || MapInfo_Map_title == "<TITLE>") && v != "")
343 MapInfo_Map_title = v;
349 o = stov(strcat("'", v, "'"));
350 mapMins.x = min(mapMins.x, o.x);
351 mapMins.y = min(mapMins.y, o.y);
352 mapMins.z = min(mapMins.z, o.z);
353 mapMaxs.x = max(mapMaxs.x, o.x);
354 mapMaxs.y = max(mapMaxs.y, o.y);
355 mapMaxs.z = max(mapMaxs.z, o.z);
357 else if(k == "race_place")
362 else if(k == "classname")
364 if(v == "info_player_team1")
366 else if(v == "info_player_team2")
368 else if(v == "info_player_start")
370 else if(v == "info_player_deathmatch")
372 else if(v == "weapon_nex")
374 else if(v == "weapon_railgun")
376 else if(startsWith(v, "weapon_"))
377 MapInfo_Map_supportedFeatures |= MAPINFO_FEATURE_WEAPONS;
378 else if(startsWith(v, "turret_"))
379 MapInfo_Map_supportedFeatures |= MAPINFO_FEATURE_TURRETS;
380 else if(startsWith(v, "vehicle_"))
381 MapInfo_Map_supportedFeatures |= MAPINFO_FEATURE_VEHICLES;
382 else if(startsWith(v, "monster_"))
383 MapInfo_Map_supportedFeatures |= MAPINFO_FEATURE_MONSTERS;
384 else if(v == "target_music" || v == "trigger_music")
385 _MapInfo_Map_worldspawn_music = string_null; // don't use regular BGM
386 else if(v == "target_stopTimer")
387 is_q3df_map = true; // don't support standard gametypes UNLESS we found them in .arena
389 FOREACH(Gametypes, true, it.m_generate_mapinfo(it, v));
395 LOG_WARN(fn, " ended still in worldspawn, BUG");
398 diameter = vlen(mapMaxs - mapMins);
400 int twoBaseModes = 0;
401 FOREACH(Gametypes, it.m_isTwoBaseMode(), twoBaseModes |= it.m_flags);
402 if(twoBaseModes && (twoBaseModes &= MapInfo_Map_supportedGametypes))
404 // we have a symmetrical map, don't add the modes without bases
406 else if(!is_q3df_map)
408 FOREACH(Gametypes, it.m_isAlwaysSupported(it, spawnpoints, diameter), MapInfo_Map_supportedGametypes |= it.m_flags);
411 if(MapInfo_Map_supportedGametypes & MAPINFO_TYPE_RACE.m_flags)
414 MapInfo_Map_supportedGametypes &= ~MAPINFO_TYPE_RACE.m_flags;
415 MapInfo_Map_supportedGametypes |= MAPINFO_TYPE_CTS.m_flags;
418 LOG_TRACE("-> diameter ", ftos(diameter));
419 LOG_TRACE("; spawnpoints ", ftos(spawnpoints));
420 LOG_TRACE("; modes ", ftos(MapInfo_Map_supportedGametypes));
427 void _MapInfo_Map_Reset()
429 MapInfo_Map_title = "<TITLE>";
430 MapInfo_Map_titlestring = "<TITLE>";
431 MapInfo_Map_description = "<DESCRIPTION>";
432 MapInfo_Map_author = "<AUTHOR>";
433 MapInfo_Map_supportedGametypes = 0;
434 MapInfo_Map_supportedFeatures = 0;
435 MapInfo_Map_flags = 0;
436 MapInfo_Map_clientstuff = "";
437 MapInfo_Map_fog = "";
438 MapInfo_Map_mins = '0 0 0';
439 MapInfo_Map_maxs = '0 0 0';
442 string _MapInfo_GetDefault(Gametype t)
444 return t.m_legacydefaults;
447 void _MapInfo_Map_ApplyGametype(string s, Gametype pWantedType, Gametype pThisType, int load_default)
450 MapInfo_Map_supportedGametypes |= pThisType.m_flags;
451 if(!(pThisType.m_flags & pWantedType.m_flags))
455 _MapInfo_Map_ApplyGametype(_MapInfo_GetDefault(pThisType), pWantedType, pThisType, false);
457 if(!pWantedType.frags) // these modes don't use fraglimit
459 cvar_set("fraglimit", "0");
465 cvar_set("fraglimit", sa);
471 cvar_set("timelimit", sa);
474 if(pWantedType.m_setTeams)
478 pWantedType.m_setTeams(sa);
482 // rc = timelimit timelimit_qualification laps laps_teamplay
483 if(pWantedType == MAPINFO_TYPE_RACE)
485 cvar_set("fraglimit", "0"); // special case!
487 sa = car(s); if(sa == "") sa = cvar_string("timelimit");
488 cvar_set("g_race_qualifying_timelimit", sa);
493 if(cvar("g_race_teams") < 2)
494 cvar_set("fraglimit", sa);
499 if(cvar("g_race_teams") >= 2)
500 cvar_set("fraglimit", sa);
504 if(!pWantedType.frags) // these modes don't use fraglimit
506 cvar_set("leadlimit", "0");
512 cvar_set("leadlimit", sa);
517 string _MapInfo_GetDefaultEx(Gametype t)
519 return t ? t.model2 : "";
522 float _MapInfo_GetTeamPlayBool(Gametype t)
524 return t ? t.team : false;
527 void _MapInfo_Map_ApplyGametypeEx(string s, Gametype pWantedType, Gametype pThisType)
529 MapInfo_Map_supportedGametypes |= pThisType.m_flags;
530 if (!(pThisType.m_flags & pWantedType.m_flags))
533 // reset all the cvars to their defaults
535 cvar_set("timelimit", cvar_defstring("timelimit"));
536 cvar_set("leadlimit", cvar_defstring("leadlimit"));
537 cvar_set("fraglimit", cvar_defstring("fraglimit"));
538 FOREACH(Gametypes, true, it.m_parse_mapinfo(string_null, string_null));
540 string fraglimit_normal = string_null;
541 string fraglimit_teams = string_null;
543 for (s = strcat(_MapInfo_GetDefaultEx(pWantedType), " ", s); s != ""; s = cdr(s)) {
545 if (sa == "") continue;
546 int p = strstrofs(sa, "=", 0);
549 LOG_WARNF("Invalid gametype setting in mapinfo for gametype %s: %s", MapInfo_Type_ToString(pWantedType), sa);
552 string k = substring(sa, 0, p);
553 string v = substring(sa, p + 1, -1);
558 cvar_set("timelimit", v);
563 cvar_set("leadlimit", v);
572 fraglimit_normal = v;
575 case "teampointlimit":
587 FOREACH(Gametypes, true, handled |= it.m_parse_mapinfo(k, v));
588 if (!handled && WARN_COND)
589 LOG_WARNF("Invalid gametype setting in mapinfo for gametype %s: %s", MapInfo_Type_ToString(pWantedType), sa);
592 if (pWantedType == MAPINFO_TYPE_RACE && cvar("g_race_teams") >= 2)
595 cvar_set("fraglimit", fraglimit_teams);
600 cvar_set("fraglimit", fraglimit_normal);
604 Gametype MapInfo_Type_FromString(string gtype, bool dowarn, bool is_q3compat)
606 string replacement = "";
610 case "nexball": replacement = "nb"; break;
611 case "freezetag": replacement = "ft"; break;
612 case "keepaway": replacement = "ka"; break;
613 case "invasion": replacement = "inv"; break;
614 case "assault": replacement = "as"; break;
615 case "race": replacement = "rc"; break;
616 // Q3/QL compat, see DoesQ3ARemoveThisEntity() in quake3.qc for complete lists
617 case "ffa": replacement = "dm"; break;
618 case "cctf": // from ThreeWave, maps with this should all have "ctf" too
619 case "oneflag": replacement = "ctf"; break;
620 case "tourney": replacement = "duel"; break;
621 case "arena": // which Q3 mod is this from? In Nexuiz it was 'duel with rounds'.
622 if(is_q3compat) { replacement = "ca"; } break;
624 if (replacement != "")
626 if (dowarn && WARN_COND)
627 LOG_WARNF("MapInfo_Type_FromString (probably %s): using deprecated name '%s'. Should use '%s'.", MapInfo_Map_bspname, gtype, replacement);
630 FOREACH(Gametypes, it.mdl == gtype, return it);
634 string MapInfo_Type_Description(Gametype t)
636 return t ? t.gametype_description : "";
639 string MapInfo_Type_ToString(Gametype t)
641 return t ? t.mdl : "";
644 string MapInfo_Type_ToText(Gametype t)
646 /* xgettext:no-c-format */
647 return t ? t.message : _("@!#%'n Tuba Throwing");
650 void _MapInfo_Parse_Settemp(string pFilename, string acl, float type, string s, float recurse)
654 // tabs are invalid, treat them as "empty"
655 s = strreplace("\t", "", s);
657 t = car(s); s = cdr(s);
659 // limited support of "" and comments
660 // remove trailing and leading " of t
661 if(substring(t, 0, 1) == "\"")
663 if(substring(t, -1, 1) == "\"")
664 t = substring(t, 1, -2);
667 // remove leading " of s
668 if(substring(s, 0, 1) == "\"")
670 s = substring(s, 1, -1);
672 // remove trailing " of s, and all that follows (cvar description)
673 o = strstrofs(s, "\"", 0);
675 s = substring(s, 0, o);
677 // remove // comments
678 o = strstrofs(s, "//", 0);
680 s = substring(s, 0, o);
682 // remove trailing spaces
683 while(substring(s, -1, 1) == " ")
684 s = substring(s, 0, -2);
690 float fh = fopen(s, FILE_READ);
694 LOG_WARN("Map ", pFilename, " references not existing config file ", s);
698 while((s = fgets(fh)))
700 s = strreplace("\t", "", s); // treat tabs as "empty", perform here first to ensure coments are detected
701 // catch different sorts of comments
702 if(s == "") // empty lines
704 if(substring(s, 0, 1) == "#") // UNIX style
706 if(substring(s, 0, 2) == "//") // C++ style
708 if(substring(s, 0, 1) == "_") // q3map style
711 if(substring(s, 0, 4) == "set ")
712 s = substring(s, 4, -1);
713 if(substring(s, 0, 5) == "seta ")
714 s = substring(s, 5, -1);
716 _MapInfo_Parse_Settemp(pFilename, acl, type, s, recurse - 1);
722 LOG_WARN("Map ", pFilename, " uses too many levels of inclusion");
725 || !cvar_value_issafe(t)
726 || !cvar_value_issafe(s)
727 || matchacl(MAPINFO_SETTEMP_ACL_SYSTEM, t) <= 0)
730 LOG_WARN("Map ", pFilename, " contains a potentially harmful setting, ignored");
732 else if(matchacl(acl, t) <= 0)
735 LOG_WARN("Map ", pFilename, " contains a denied setting, ignored");
739 if(type == 0) // server set
741 LOG_TRACE("Applying temporary setting ", t, " := ", s);
743 if(cvar("g_campaign"))
744 cvar_set(t, s); // this is a wrapper and is always temporary anyway; no need to backup old values then
751 LOG_TRACE("Applying temporary client setting ", t, " := ", s);
752 MapInfo_Map_clientstuff = strcat(
753 MapInfo_Map_clientstuff, "cl_cmd settemp \"", t, "\" \"", s, "\"\n"
759 /// Removes author string from title (if found)
760 /// and copies it to MapInfo_Map_author if that wasn't set.
761 string MapInfo_title_sans_author(string title)
765 if ((offset = strstrofs(title, " by ", 0)) >= 0)
767 if (MapInfo_Map_author == "<AUTHOR>")
768 MapInfo_Map_author = substring(title, offset + 4, strlen(title) - (offset + 4));
769 title = substring(title, 0, offset);
772 return title != "" ? title : "<TITLE>";
775 bool MapInfo_isRedundant(string fn, string t)
777 // normalize file name
778 fn = strreplace("_", "", fn);
779 fn = strreplace("-", "", fn);
781 // normalize visible title
782 t = strreplace(":", "", t);
783 t = strreplace(" ", "", t);
784 t = strreplace("_", "", t);
785 t = strreplace("-", "", t);
786 t = strreplace("'", "", t);
787 t = strdecolorize(t);
789 // we allow the visible title to have punctuation the file name does
790 // not, but not vice versa
791 if(!strcasecmp(fn, t))
797 bool _MapInfo_ParseArena(string arena_filename, int fh, string pFilename, Gametype pGametypeToSet, bool isdefi, bool isgenerator)
799 // NOTE: .arena files can hold more than 1 map's information!
800 // to handle this, we're going to store gathered information in local variables and save it if we encounter the correct map name
801 bool in_brackets = false; // testing a potential mapinfo section (within brackets)
803 string stored_Map_description = "";
804 string stored_Map_title = "";
805 string stored_Map_author = "";
806 int stored_supportedGametypes = 0;
807 int stored_supportedFeatures = 0;
808 int stored_flags = 0;
812 LOG_INFO("Generating ", pFilename, ".mapinfo: analyzing ", arena_filename);
816 if (!((s = fgets(fh))))
819 // catch different sorts of comments
820 if(s == "") // empty lines
822 if(substring(s, 0, 2) == "//") // C++ style
824 if(strstrofs(s, "{", 0) >= 0)
827 return false; // edge case? already in a bracketed section!
831 else if(!in_brackets)
833 // if we're not inside a bracket, don't process map info
836 if(strstrofs(s, "}", 0) >= 0)
839 return false; // no starting bracket! let the mapinfo generation system handle it
843 MapInfo_Map_description = stored_Map_description;
844 if(stored_Map_title != "")
845 MapInfo_Map_title = stored_Map_title;
846 MapInfo_Map_author = stored_Map_author;
847 // might have .arena AND .defi for the same map so these bitfields are OR'd
849 MapInfo_Map_supportedGametypes |= stored_supportedGametypes;
852 FOREACH(Gametypes, it.m_flags & stored_supportedGametypes,
854 _MapInfo_Map_ApplyGametype ("", pGametypeToSet, it, true);
857 MapInfo_Map_supportedFeatures |= stored_supportedFeatures;
858 MapInfo_Map_flags |= stored_flags;
859 return true; // no need to continue through the file, we have our map!
863 // discard any gathered locals, we're not using the correct map!
864 stored_Map_description = "";
865 stored_Map_title = "";
866 stored_Map_author = "";
867 stored_supportedGametypes = 0;
868 stored_supportedFeatures = 0;
874 s = strreplace("\t", " ", s);
876 float p = strstrofs(s, "//", 0);
878 s = substring(s, 0, p);
880 // perform an initial trim to ensure the first argument is properly obtained
881 // remove leading spaces
882 while(substring(s, 0, 1) == " ")
883 s = substring(s, 1, -1);
885 t = car(s); s = cdr(s);
886 t = strtolower(t); // apparently some q3 maps use capitalized parameters
888 // remove trailing spaces
889 while(substring(t, -1, 1) == " ")
890 t = substring(t, 0, -2);
892 // remove trailing spaces
893 while(substring(s, -1, 1) == " ")
894 s = substring(s, 0, -2);
895 // remove leading spaces
896 while(substring(s, 0, 1) == " ")
897 s = substring(s, 1, -1);
898 // limited support of ""
899 // remove trailing and leading " of s
900 if(substring(s, 0, 1) == "\"")
902 if(substring(s, -1, 1) == "\"")
903 s = substring(s, 1, -2);
906 stored_Map_title = s;
907 else if(t == "author")
908 stored_Map_author = s;
911 // if there is a valid gametype in this .arena file, include it in the menu
912 stored_supportedFeatures |= MAPINFO_FEATURE_WEAPONS;
913 // type in quake 3 holds all the supported gametypes, so we must loop through all of them
914 // TODO: handle support here better to include more Xonotic teamplay modes
916 types = strreplace("team", "tdm ft", types);
917 types = strreplace("ffa", "dm lms ka", types);
918 types = strreplace("tourney", "duel", types); // QL used duel so the following check must support it
919 if(strstrofs(types, "duel", 0) < 0 && strstrofs(types, "tdm", 0) >= 0) // larger team map, support additional gamemodes!
920 types = cons(types, "ca kh");
921 FOREACH_WORD(types, true,
923 Gametype f = MapInfo_Type_FromString(it, false, true);
925 stored_supportedGametypes |= f.m_flags;
928 else if(t == "style" && isdefi)
930 // we have a defrag map on our hands, add CTS!
932 stored_supportedGametypes |= MAPINFO_TYPE_CTS.m_flags;
936 if(strtolower(s) == strtolower(pFilename))
937 dosave = true; // yay, found our map!
939 else if(t == "quote")
940 stored_Map_description = s;
944 // if the map wasn't found in the .arena, fall back to generated .mapinfo
948 string _MapInfo_CheckArenaFile(string pFilename, string pMapname)
950 // returns the file name if valid, otherwise returns ""
951 // a string is returned to optimise the use cases where a filename is also returned
952 int fh = fopen(pFilename, FILE_READ);
955 for(string s; (s = fgets(fh)); )
957 s = strreplace("\t", "", s);
958 while(substring(s, 0, 1) == " ")
959 s = substring(s, 1, -1);
960 if(substring(s, 0, 2) == "//")
964 int offset = strstrofs(s, "map", 0);
967 if(strstrofs(strtolower(s), strcat("\"", strtolower(pMapname), "\""), offset) >= 0) // quake 3 is case insensitive
970 return pFilename; // FOUND IT!
975 return ""; // file did not contain a "map" field matching our map name
978 string _MapInfo_FindArenaFile(string pFilename, string extension)
980 string fallback = strcat("scripts/", pFilename, extension);
981 if(!checkextension("DP_QC_FS_SEARCH_PACKFILE"))
982 return _MapInfo_CheckArenaFile(fallback, pFilename);
983 string base_pack = whichpack(strcat("maps/", pFilename, ".bsp"));
984 if(base_pack == "") // this map isn't packaged!
985 return _MapInfo_CheckArenaFile(fallback, pFilename);
987 int glob = search_packfile_begin(strcat("scripts/*", extension), true, true, base_pack);
989 return _MapInfo_CheckArenaFile(fallback, pFilename);
990 int n = search_getsize(glob);
991 for(int j = 0; j < n; ++j)
993 string file = search_getfilename(glob, j);
994 if(_MapInfo_CheckArenaFile(file, pFilename) != "")
1002 return ""; // if we get here, a valid .arena file could not be found
1005 // load info about a map by name into the MapInfo_Map_* globals
1006 float MapInfo_Get_ByName_NoFallbacks(string pFilename, int pAllowGenerate, Gametype pGametypeToSet)
1015 acl = MAPINFO_SETTEMP_ACL_USER;
1017 if(strstrofs(pFilename, "/", 0) >= 0)
1019 LOG_WARN("Invalid character in map name, ignored");
1023 if(pGametypeToSet == NULL)
1024 if(MapInfo_Cache_Retrieve(pFilename))
1029 MapInfo_Map_bspname = pFilename;
1031 // default all generic fields so they have "good" values in case something fails
1032 fn = strcat("maps/", pFilename, ".mapinfo");
1033 fh = fopen(fn, FILE_READ);
1036 if(autocvar_g_mapinfo_q3compat == 1) // use arena data instead of generating a mapinfo file
1038 // supporting .arena AND .defi for the same map
1039 bool success = false;
1040 fn = _MapInfo_FindArenaFile(pFilename, ".arena");
1041 if(fn != "" && (fh = fopen(fn, FILE_READ)) >= 0)
1043 _MapInfo_Map_Reset();
1044 success = _MapInfo_ParseArena(fn, fh, pFilename, pGametypeToSet, false, false);
1047 fn = _MapInfo_FindArenaFile(pFilename, ".defi");
1048 if(fn != "" && (fh = fopen(fn, FILE_READ)) >= 0)
1051 _MapInfo_Map_Reset();
1052 success |= _MapInfo_ParseArena(fn, fh, pFilename, pGametypeToSet, true, false);
1056 goto mapinfo_handled; // skip generation
1059 fn = strcat("maps/autogenerated/", pFilename, ".mapinfo");
1060 fh = fopen(fn, FILE_READ);
1065 _MapInfo_Map_Reset();
1066 r = _MapInfo_Generate(pFilename);
1069 MapInfo_Map_title = MapInfo_title_sans_author(MapInfo_Map_title);
1070 fh = fopen(fn, FILE_WRITE);
1071 fputs(fh, strcat("title ", MapInfo_Map_title, "\n"));
1072 fputs(fh, strcat("description ", MapInfo_Map_description, "\n"));
1073 fputs(fh, strcat("author ", MapInfo_Map_author, "\n"));
1074 if(_MapInfo_Map_worldspawn_music != "")
1076 if(strcasecmp(substring(_MapInfo_Map_worldspawn_music, -4, 4), ".wav") == 0 || strcasecmp(substring(_MapInfo_Map_worldspawn_music, -4, 4), ".ogg") == 0)
1077 fputs(fh, strcat("cdtrack ", substring(_MapInfo_Map_worldspawn_music, 0, -4), "\n"));
1079 fputs(fh, strcat("cdtrack ", _MapInfo_Map_worldspawn_music, "\n"));
1083 n = tokenize_console(cvar_string("g_cdtracks_remaplist"));
1084 s = strcat(" ", cvar_string("g_cdtracks_dontusebydefault"), " ");
1087 i = floor(random() * n);
1088 if(strstrofs(s, strcat(" ", argv(i), " "), 0) < 0)
1091 fputs(fh, strcat("cdtrack ", ftos(i + 1), "\n"));
1093 if(MapInfo_Map_supportedFeatures & MAPINFO_FEATURE_WEAPONS)
1094 fputs(fh, "has weapons\n");
1096 fputs(fh, "// uncomment this if you added weapon pickups: has weapons\n");
1097 if(MapInfo_Map_supportedFeatures & MAPINFO_FEATURE_TURRETS)
1098 fputs(fh, "has turrets\n");
1100 fputs(fh, "// uncomment this if you added turrets: has turrets\n");
1101 if(MapInfo_Map_supportedFeatures & MAPINFO_FEATURE_VEHICLES)
1102 fputs(fh, "has vehicles\n");
1104 fputs(fh, "// uncomment this if you added vehicles: has vehicles\n");
1105 if(MapInfo_Map_flags & MAPINFO_FLAG_FRUSTRATING)
1106 fputs(fh, "frustrating\n");
1108 FOREACH(Gametypes, MapInfo_Map_supportedGametypes & it.m_flags, {
1109 fputs(fh, sprintf("gametype %s // defaults: %s\n", MapInfo_Type_ToString(it), _MapInfo_GetDefaultEx(it)));
1112 fputs(fh, "// optional: fog density red green blue alpha mindist maxdist\n");
1113 fputs(fh, "// optional: settemp_for_type (all|gametypename) cvarname value\n");
1114 fputs(fh, "// optional: clientsettemp_for_type (all|gametypename) cvarname value\n");
1115 fputs(fh, "// optional: size mins_x mins_y mins_z maxs_x maxs_y maxs_z\n");
1116 fputs(fh, "// optional: hidden\n");
1121 fh = fopen(fn, FILE_READ);
1123 error("... but I just wrote it!");
1127 LOG_WARN("autogenerated mapinfo file ", fn, " has been loaded; please edit that file and move it to maps/", pFilename, ".mapinfo");
1130 _MapInfo_Map_Reset();
1133 if (!((s = fgets(fh))))
1136 // catch different sorts of comments
1137 if(s == "") // empty lines
1139 if(substring(s, 0, 1) == "#") // UNIX style
1141 if(substring(s, 0, 2) == "//") // C++ style
1143 if(substring(s, 0, 1) == "_") // q3map style
1146 float p = strstrofs(s, "//", 0);
1148 s = substring(s, 0, p);
1150 t = car(s); s = cdr(s);
1152 MapInfo_Map_title = s;
1153 else if(t == "description")
1154 MapInfo_Map_description = s;
1155 else if(t == "author")
1156 MapInfo_Map_author = s;
1159 t = car(s); // s = cdr(s);
1160 if (t == "weapons") MapInfo_Map_supportedFeatures |= MAPINFO_FEATURE_WEAPONS;
1161 else if(t == "turrets") MapInfo_Map_supportedFeatures |= MAPINFO_FEATURE_TURRETS;
1162 else if(t == "vehicles") MapInfo_Map_supportedFeatures |= MAPINFO_FEATURE_VEHICLES;
1163 else if(t == "monsters") MapInfo_Map_supportedFeatures |= MAPINFO_FEATURE_MONSTERS;
1164 else if(t == "new_toys") MapInfo_Map_supportedFeatures |= MAPINFO_FEATURE_WEAPONS;
1166 LOG_WARN("Map ", pFilename, " supports unknown feature ", t, ", ignored");
1168 else if(t == "hidden")
1170 MapInfo_Map_flags |= MAPINFO_FLAG_HIDDEN;
1172 else if(t == "forbidden")
1174 MapInfo_Map_flags |= MAPINFO_FLAG_FORBIDDEN;
1176 else if(t == "frustrating")
1178 MapInfo_Map_flags |= MAPINFO_FLAG_FRUSTRATING;
1180 else if(t == "donotwant" || t == "noautomaplist")
1182 MapInfo_Map_flags |= MAPINFO_FLAG_DONOTWANT;
1184 else if(t == "gameversion_min")
1186 if (cvar("gameversion") < stof(s))
1187 MapInfo_Map_flags |= MAPINFO_FLAG_DONOTWANT;
1189 else if(t == "type")
1191 t = car(s); s = cdr(s);
1192 Gametype f = MapInfo_Type_FromString(t, true, false);
1194 //LOG_WARN("Map ", pFilename, " contains the legacy 'type' keyword which is deprecated and will be removed in the future. Please migrate the mapinfo file to 'gametype'.");
1196 _MapInfo_Map_ApplyGametype (s, pGametypeToSet, f, true);
1198 LOG_DEBUG("Map ", pFilename, " supports unknown game type ", t, ", ignored");
1200 else if(t == "gametype")
1202 t = car(s); s = cdr(s);
1203 Gametype f = MapInfo_Type_FromString(t, true, false);
1205 _MapInfo_Map_ApplyGametypeEx (s, pGametypeToSet, f);
1207 LOG_DEBUG("Map ", pFilename, " supports unknown game type ", t, ", ignored");
1209 else if(t == "size")
1211 float a, b, c, d, e;
1212 t = car(s); s = cdr(s); a = stof(t);
1213 t = car(s); s = cdr(s); b = stof(t);
1214 t = car(s); s = cdr(s); c = stof(t);
1215 t = car(s); s = cdr(s); d = stof(t);
1216 t = car(s); s = cdr(s); e = stof(t);
1220 LOG_WARN("Map ", pFilename, " contains an incorrect size line (not enough params), syntax: size mins_x mins_y mins_z maxs_x maxs_y maxs_z");
1224 t = car(s); s = cdr(s); f = stof(t);
1228 LOG_WARN("Map ", pFilename, " contains an incorrect size line (too many params), syntax: size mins_x mins_y mins_z maxs_x maxs_y maxs_z");
1232 if(a >= d || b >= e || c >= f)
1235 LOG_WARN("Map ", pFilename, " contains an incorrect size line, mins have to be < maxs");
1239 MapInfo_Map_mins.x = a;
1240 MapInfo_Map_mins.y = b;
1241 MapInfo_Map_mins.z = c;
1242 MapInfo_Map_maxs.x = d;
1243 MapInfo_Map_maxs.y = e;
1244 MapInfo_Map_maxs.z = f;
1249 else if(t == "settemp_for_type")
1251 t = car(s); s = cdr(s);
1252 bool all = t == "all";
1254 if(all || (f = MapInfo_Type_FromString(t, true, false)))
1256 if((all ? MAPINFO_TYPE_ALL : f.m_flags) & pGametypeToSet.m_flags)
1258 _MapInfo_Parse_Settemp(pFilename, acl, 0, s, 1);
1263 LOG_DEBUG("Map ", pFilename, " has a setting for unknown game type ", t, ", ignored");
1266 else if(t == "clientsettemp_for_type")
1268 t = car(s); s = cdr(s);
1269 bool all = t == "all";
1271 if(all || (f = MapInfo_Type_FromString(t, true, false)))
1273 if((all ? MAPINFO_TYPE_ALL : f.m_flags) & pGametypeToSet.m_flags)
1275 _MapInfo_Parse_Settemp(pFilename, acl, 1, s, 1);
1280 LOG_DEBUG("Map ", pFilename, " has a client setting for unknown game type ", t, ", ignored");
1285 if (!cvar_value_issafe(s))
1288 LOG_WARN("Map ", pFilename, " contains a potentially harmful fog setting, ignored");
1291 MapInfo_Map_fog = s;
1293 else if(t == "cdtrack")
1295 t = car(s); s = cdr(s);
1296 // We do this only if pGametypeToSet even though this
1297 // content is theoretically game type independent,
1298 // because MapInfo_Map_clientstuff contains otherwise
1299 // game type dependent stuff. That way this value stays
1300 // empty when not setting a game type to not set any
1301 // false expectations.
1304 if (!cvar_value_issafe(t))
1307 LOG_WARN("Map ", pFilename, " contains a potentially harmful cdtrack, ignored");
1310 MapInfo_Map_clientstuff = strcat(
1311 MapInfo_Map_clientstuff, "cd loop \"", t, "\"\n"
1316 LOG_WARN("Map ", pFilename, " provides unknown info item ", t, ", ignored");
1320 LABEL(mapinfo_handled)
1322 // if the map is currently loaded we can read worldspawn fields directly
1323 if (pFilename == mi_shortname)
1325 if (MapInfo_Map_title == "<TITLE>")
1326 if (world.message != "")
1327 MapInfo_Map_title = world.message;
1330 // Could skip removing author from title when it's source is .mapinfo
1331 // but must always do it for world.message and .arena/.defi as VQ3 didn't support author
1332 // so mappers tended to put it in world.message and/or longname.
1333 MapInfo_Map_title = MapInfo_title_sans_author(MapInfo_Map_title); // may set author if not set
1335 if(MapInfo_Map_title == "<TITLE>")
1336 MapInfo_Map_titlestring = strcat("^2", MapInfo_Map_bspname);
1337 else if(MapInfo_isRedundant(MapInfo_Map_bspname, MapInfo_Map_title))
1338 MapInfo_Map_titlestring = strcat("^2", MapInfo_Map_title);
1340 MapInfo_Map_titlestring = sprintf("^2%s ^7// ^2%s", MapInfo_Map_bspname, MapInfo_Map_title);
1342 MapInfo_Cache_Store();
1343 if(MapInfo_Map_supportedGametypes != 0)
1346 LOG_WARN("Map ", pFilename, " supports no game types, ignored");
1349 int MapInfo_Get_ByName(string pFilename, float pAllowGenerate, Gametype pGametypeToSet)
1351 int r = MapInfo_Get_ByName_NoFallbacks(pFilename, pAllowGenerate, pGametypeToSet);
1353 FOREACH(Gametypes, it.m_isForcedSupported(it), _MapInfo_Map_ApplyGametypeEx("", pGametypeToSet, it));
1357 if(!(MapInfo_Map_supportedGametypes & pGametypeToSet.m_flags))
1359 error("Can't select the requested game type. This should never happen as the caller should prevent it!\n");
1360 //_MapInfo_Map_ApplyGametypeEx("", pGametypeToSet, MAPINFO_TYPE_DEATHMATCH);
1368 bool MapReadSizes(string map)
1370 // TODO: implement xonotic#28 / xonvote 172 (sizes in mapinfo)
1371 string readsize_msg = strcat("MapReadSizes ", map);
1372 float fh = fopen(strcat("maps/", map, ".sizes"), FILE_READ);
1375 map_minplayers = stoi(fgets(fh));
1376 map_maxplayers = stoi(fgets(fh));
1378 LOG_TRACEF(readsize_msg, ": ok, min %d max %d", map_minplayers, map_maxplayers);
1381 LOG_TRACE(readsize_msg, ": not found");
1385 float MapInfo_FindName(string s)
1387 // if there is exactly one map of prefix s, return it
1388 // if not, return the null string
1389 // note that DP sorts glob results... so I can use a binary search
1393 // invariants: r is behind s, l-1 is equal or before
1396 m = floor((l + r) / 2);
1397 MapInfo_FindName_match = _MapInfo_GlobItem(MapInfo_FilterList_Lookup(m));
1398 cmp = strcasecmp(MapInfo_FindName_match, s);
1400 return m; // found and good
1402 l = m + 1; // l-1 is before s
1406 MapInfo_FindName_match = _MapInfo_GlobItem(MapInfo_FilterList_Lookup(l));
1407 MapInfo_FindName_firstResult = l;
1408 // r == l, so: l is behind s, l-1 is before
1409 // SO: if there is any, l is the one with the right prefix
1410 // and l+1 may be one too
1411 if(l == MapInfo_count)
1413 MapInfo_FindName_match = string_null;
1414 MapInfo_FindName_firstResult = -1;
1415 return -1; // no MapInfo_FindName_match, behind last item
1417 if(!startsWithNocase(MapInfo_FindName_match, s))
1419 MapInfo_FindName_match = string_null;
1420 MapInfo_FindName_firstResult = -1;
1421 return -1; // wrong prefix
1423 if(l == MapInfo_count - 1)
1424 return l; // last one, nothing can follow => unique
1425 if(startsWithNocase(_MapInfo_GlobItem(MapInfo_FilterList_Lookup(l + 1)), s))
1427 MapInfo_FindName_match = string_null;
1428 return -1; // ambigous MapInfo_FindName_match
1433 string MapInfo_FixName(string s)
1435 MapInfo_FindName(s);
1436 return MapInfo_FindName_match;
1439 int MapInfo_CurrentFeatures()
1442 // TODO: find a better way to check if weapons are required on the map
1443 if(!(cvar("g_instagib") || cvar("g_overkill") || cvar("g_nix") || cvar("g_weaponarena") || !cvar("g_pickup_items") || !cvar("g_melee_only")
1444 || cvar("g_race") || cvar("g_cts") || cvar("g_nexball") || cvar("g_ca") || cvar("g_freezetag") || cvar("g_lms")))
1445 req |= MAPINFO_FEATURE_WEAPONS;
1449 Gametype MapInfo_CurrentGametype()
1451 Gametype prev = MapInfo_Type_FromString(cvar_string("gamecfg"), false, false);
1452 FOREACH(Gametypes, cvar(it.netname) && it != prev, return it);
1453 return prev ? prev : MAPINFO_TYPE_DEATHMATCH;
1456 float _MapInfo_CheckMap(string s, bool gametype_only) // returns 0 if the map can't be played with the current settings, 1 otherwise
1458 if(!MapInfo_Get_ByName(s, 1, NULL))
1460 if((MapInfo_Map_supportedGametypes & MapInfo_CurrentGametype().m_flags) == 0)
1464 if((MapInfo_Map_supportedFeatures & MapInfo_CurrentFeatures()) != MapInfo_CurrentFeatures())
1469 float MapInfo_CheckMap(string s) // returns 0 if the map can't be played with the current settings, 1 otherwise
1472 r = _MapInfo_CheckMap(s, false);
1473 MapInfo_ClearTemps();
1477 void MapInfo_SwitchGameType(Gametype t)
1479 FOREACH(Gametypes, true, cvar_set(it.netname, (it == t) ? "1" : "0"));
1482 void MapInfo_LoadMap(string s, float reinit)
1484 MapInfo_Map_supportedGametypes = 0;
1485 // we shouldn't need this, as LoadMapSettings already fixes the gametype
1486 //if(!MapInfo_CheckMap(s))
1488 // print("EMERGENCY: can't play the selected map in the given game mode. Falling back to DM.\n");
1489 // MapInfo_SwitchGameType(MAPINFO_TYPE_DEATHMATCH.m_flags);
1492 LOG_INFO("Switching to map ", s);
1494 cvar_settemp_restore();
1496 localcmd(strcat("\nmap ", s, "\n"));
1498 localcmd(strcat("\nchangelevel ", s, "\n"));
1501 string MapInfo_ListAllowedMaps(Gametype type, float pRequiredFlags, float pForbiddenFlags)
1505 // to make absolutely sure:
1506 MapInfo_Enumerate();
1507 MapInfo_FilterGametype(type, MapInfo_CurrentFeatures(), pRequiredFlags, pForbiddenFlags, 0);
1510 for(float i = 0; i < MapInfo_count; ++i)
1511 out = strcat(out, " ", _MapInfo_GlobItem(MapInfo_FilterList_Lookup(i)));
1512 return substring(out, 1, strlen(out) - 1);
1515 string MapInfo_ListAllAllowedMaps(float pRequiredFlags, float pForbiddenFlags)
1519 // to make absolutely sure:
1520 MapInfo_Enumerate();
1521 _MapInfo_FilterGametype(MAPINFO_TYPE_ALL, 0, pRequiredFlags, pForbiddenFlags, 0);
1524 for(float i = 0; i < MapInfo_count; ++i)
1525 out = strcat(out, " ", _MapInfo_GlobItem(MapInfo_FilterList_Lookup(i)));
1527 MapInfo_FilterGametype(MapInfo_CurrentGametype(), MapInfo_CurrentFeatures(), pRequiredFlags, pForbiddenFlags, 0);
1529 return substring(out, 1, strlen(out) - 1);
1532 void MapInfo_LoadMapSettings_SaveGameType(Gametype t)
1534 MapInfo_SwitchGameType(t);
1535 cvar_set("gamecfg", t.mdl);
1536 MapInfo_LoadedGametype = t;
1539 void MapInfo_LoadMapSettings(string s) // to be called from worldspawn
1541 Gametype t = MapInfo_CurrentGametype();
1542 MapInfo_LoadMapSettings_SaveGameType(t);
1544 if(!_MapInfo_CheckMap(s, true)) // with underscore, it keeps temps
1546 if(cvar("g_mapinfo_allow_unsupported_modes_and_let_stuff_break"))
1548 LOG_SEVERE("can't play the selected map in the given game mode. Working with only the override settings.");
1549 _MapInfo_Map_ApplyGametypeEx("", t, t);
1550 return; // do not call Get_ByName!
1553 if(MapInfo_Map_supportedGametypes == 0)
1555 RandomSelection_Init();
1556 FOREACH(Gametypes, it.m_priority == 2,
1558 MapInfo_Map_supportedGametypes |= it.m_flags;
1559 RandomSelection_AddEnt(it, 1, 1);
1561 if(RandomSelection_chosen_ent)
1562 t = RandomSelection_chosen_ent;
1563 LOG_SEVEREF("Mapinfo system is not functional at all. Falling back to a preferred mode (%s).", t.mdl);
1564 MapInfo_LoadMapSettings_SaveGameType(t);
1565 _MapInfo_Map_ApplyGametypeEx("", t, t);
1566 return; // do not call Get_ByName!
1570 // find the lowest bit in the supported gametypes
1571 // unnecessary now that we select one at random
1573 while(!(MapInfo_Map_supportedGametypes & 1))
1576 MapInfo_Map_supportedGametypes = floor(MapInfo_Map_supportedGametypes >> 1);
1579 RandomSelection_Init();
1580 Gametype t_prev = t;
1581 FOREACH(Gametypes, MapInfo_Map_supportedGametypes & it.m_flags,
1583 RandomSelection_AddEnt(it, 1, it.m_priority);
1585 if(RandomSelection_chosen_ent)
1586 t = RandomSelection_chosen_ent;
1588 // t is now a supported mode!
1589 LOG_WARNF("can't play the selected map in the given game mode (%s). Falling back to a supported mode (%s).", t_prev.mdl, t.mdl);
1590 MapInfo_LoadMapSettings_SaveGameType(t);
1592 if(!_MapInfo_CheckMap(s, false)) { // with underscore, it keeps temps
1593 LOG_WARNF("the selected map lacks features required by current settings; playing anyway.");
1595 MapInfo_Get_ByName(s, 1, t);
1598 void MapInfo_ClearTemps()
1600 MapInfo_Map_bspname = string_null;
1601 MapInfo_Map_title = string_null;
1602 MapInfo_Map_titlestring = string_null;
1603 MapInfo_Map_description = string_null;
1604 MapInfo_Map_author = string_null;
1605 MapInfo_Map_clientstuff = string_null;
1606 MapInfo_Map_supportedGametypes = 0;
1607 MapInfo_Map_supportedFeatures = 0;
1610 void MapInfo_Shutdown()
1612 MapInfo_ClearTemps();
1613 MapInfo_Filter_Free();
1614 MapInfo_Cache_Destroy();
1615 if(_MapInfo_globopen)
1617 search_end(_MapInfo_globhandle);
1618 _MapInfo_globhandle = -1;
1619 _MapInfo_globopen = false;
1623 int MapInfo_ForbiddenFlags()
1625 int f = MAPINFO_FLAG_FORBIDDEN;
1628 if (!cvar("g_maplist_allow_hidden"))
1630 f |= MAPINFO_FLAG_HIDDEN;
1632 if (!cvar("g_maplist_allow_frustrating"))
1633 f |= MAPINFO_FLAG_FRUSTRATING;
1638 int MapInfo_RequiredFlags()
1642 if(cvar("g_maplist_allow_frustrating") > 1)
1643 f |= MAPINFO_FLAG_FRUSTRATING;