2 void cvar_settemp(string pKey, string pValue)
4 //localcmd(strcat("\nsettemp ", t, " \"", s, "\"\n"));
6 // duplicate what this alias does:
7 // alias settemp "settemp_list \"1 $1 $settemp_var $settemp_list\"; set $settemp_var \"${$1}\"; settemp_var ${settemp_var}x; $1 \"$2\""
9 cvar_set("settemp_list", strcat("1 ", pKey, " ", cvar_string("settemp_var"), " ", cvar_string("settemp_list")));
11 registercvar(cvar_string("settemp_var"), "", 0);
13 registercvar(cvar_string("settemp_var"), "");
15 cvar_set(cvar_string("settemp_var"), cvar_string(pKey));
16 cvar_set("settemp_var", strcat(cvar_string("settemp_var"), "x"));
17 cvar_set(pKey, pValue);
20 void cvar_settemp_restore()
22 // undo what cvar_settemp did
24 n = tokenize(cvar_string("settemp_list"));
25 for(i = 0; i < n - 3; i += 3)
26 cvar_set(argv(i + 1), cvar_string(argv(i + 2)));
27 cvar_set("settemp_list", "0");
30 // HUGE SET - stored in a string
31 string HugeSetOfIntegers_empty()
35 float HugeSetOfIntegers_get(string pArr, float i)
37 return stof(substring(pArr, i * 4, 4));
39 float HugeSetOfIntegers_length(string pArr)
41 return strlen(pArr) / 4;
43 string HugeSetOfIntegers_concat(string a1, string a2)
45 return strcat(a1, a2);
47 string HugeSetOfIntegers_insert(string a1, float n, string a2)
48 // special concat function to build up large lists in less time by binary concatenation
51 s = strcat(" ", ftos(n));
52 return strcat(a1, substring(s, strlen(s) - 4, 4), a2);
55 // generic string stuff
56 float startsWith(string haystack, string needle)
58 return substring(haystack, 0, strlen(needle)) == needle;
60 float startsWithNocase(string haystack, string needle)
62 return strcasecmp(substring(haystack, 0, strlen(needle)), needle) == 0;
64 string extractRestOfLine(string haystack, string needle)
66 if(startsWith(haystack, needle))
67 return substring(haystack, strlen(needle), strlen(haystack) - strlen(needle));
73 o = strstrofs(s, " ", 0);
76 return substring(s, 0, o);
81 o = strstrofs(s, " ", 0);
84 return substring(s, o + 1, strlen(s) - (o + 1));
87 float _MapInfo_Cache_Active;
88 float _MapInfo_Cache_DB_NameToIndex;
89 float _MapInfo_Cache_Buf_IndexToMapData;
91 void MapInfo_Cache_Destroy()
93 if(!_MapInfo_Cache_Active)
96 db_close(_MapInfo_Cache_DB_NameToIndex);
97 buf_del(_MapInfo_Cache_Buf_IndexToMapData);
98 _MapInfo_Cache_Active = 0;
101 void MapInfo_Cache_Create()
103 MapInfo_Cache_Destroy();
104 _MapInfo_Cache_DB_NameToIndex = db_create();
105 _MapInfo_Cache_Buf_IndexToMapData = buf_create();
106 _MapInfo_Cache_Active = 1;
109 void MapInfo_Cache_Invalidate()
111 if(!_MapInfo_Cache_Active)
114 MapInfo_Cache_Create();
117 void MapInfo_Cache_Store()
121 if(!_MapInfo_Cache_Active)
124 s = db_get(_MapInfo_Cache_DB_NameToIndex, MapInfo_Map_bspname);
125 if(!s) // empty string is NOT valid here!
126 i = buf_getsize(_MapInfo_Cache_Buf_IndexToMapData);
130 // now store all the stuff
131 bufstr_set(_MapInfo_Cache_Buf_IndexToMapData, i++, MapInfo_Map_bspname);
132 bufstr_set(_MapInfo_Cache_Buf_IndexToMapData, i++, MapInfo_Map_title);
133 bufstr_set(_MapInfo_Cache_Buf_IndexToMapData, i++, MapInfo_Map_description);
134 bufstr_set(_MapInfo_Cache_Buf_IndexToMapData, i++, MapInfo_Map_author);
135 bufstr_set(_MapInfo_Cache_Buf_IndexToMapData, i++, ftos(MapInfo_Map_supportedGametypes));
136 bufstr_set(_MapInfo_Cache_Buf_IndexToMapData, i++, ftos(MapInfo_Map_supportedFeatures));
137 bufstr_set(_MapInfo_Cache_Buf_IndexToMapData, i++, ftos(MapInfo_Map_diameter));
138 bufstr_set(_MapInfo_Cache_Buf_IndexToMapData, i++, ftos(MapInfo_Map_spawnpoints));
141 float MapInfo_Cache_Retrieve(string map)
145 if(!_MapInfo_Cache_Active)
148 s = db_get(_MapInfo_Cache_DB_NameToIndex, map);
153 // now retrieve all the stuff
154 MapInfo_Map_bspname = bufstr_get(_MapInfo_Cache_Buf_IndexToMapData, i++);
155 MapInfo_Map_title = bufstr_get(_MapInfo_Cache_Buf_IndexToMapData, i++);
156 MapInfo_Map_description = bufstr_get(_MapInfo_Cache_Buf_IndexToMapData, i++);
157 MapInfo_Map_author = bufstr_get(_MapInfo_Cache_Buf_IndexToMapData, i++);
158 MapInfo_Map_supportedGametypes = stof(bufstr_get(_MapInfo_Cache_Buf_IndexToMapData, i++));
159 MapInfo_Map_supportedFeatures = stof(bufstr_get(_MapInfo_Cache_Buf_IndexToMapData, i++));
160 MapInfo_Map_diameter = stof(bufstr_get(_MapInfo_Cache_Buf_IndexToMapData, i++));
161 MapInfo_Map_spawnpoints = stof(bufstr_get(_MapInfo_Cache_Buf_IndexToMapData, i++));
165 // GLOB HANDLING (for all BSP files)
166 float _MapInfo_globopen;
167 float _MapInfo_globcount;
168 float _MapInfo_globhandle;
169 string _MapInfo_GlobItem(float i)
172 s = search_getfilename(_MapInfo_globhandle, i);
173 return substring(s, 5, strlen(s) - 9); // without maps/ and .bsp
176 void MapInfo_Enumerate()
178 if(_MapInfo_globopen)
179 search_end(_MapInfo_globhandle);
180 MapInfo_Cache_Invalidate();
181 _MapInfo_globhandle = search_begin("maps/*.bsp", TRUE, TRUE);
182 _MapInfo_globcount = search_getsize(_MapInfo_globhandle);
183 _MapInfo_globopen = 1;
186 // filter the info by game type mask (updates MapInfo_count)
187 string _MapInfo_filtered;
188 string MapInfo_FilterGametype_Recursive(float pGametype, float pFeatures, float pBegin, float pEnd, float pAbortOnGenerate)
194 return HugeSetOfIntegers_empty();
196 m = floor((pBegin + pEnd) / 2);
198 l = MapInfo_FilterGametype_Recursive(pGametype, pFeatures, pBegin, m, pAbortOnGenerate);
200 return string_null; // BAIL OUT
201 if(MapInfo_Get_ByName(_MapInfo_GlobItem(m), 1, 0) == 2) // if we generated one... BAIL OUT and let the caller continue in the next frame.
203 return string_null; // BAIL OUT
204 valid = (((MapInfo_Map_supportedGametypes & pGametype) != 0) && ((MapInfo_Map_supportedFeatures & pFeatures) == pFeatures));
205 r = MapInfo_FilterGametype_Recursive(pGametype, pFeatures, m + 1, pEnd, pAbortOnGenerate);
207 return string_null; // BAIL OUT
210 return HugeSetOfIntegers_insert(l, m, r);
212 return HugeSetOfIntegers_concat(l, r);
214 float MapInfo_FilterGametype(float pGametype, float pFeatures, float pAbortOnGenerate)
216 if(_MapInfo_filtered)
217 strunzone(_MapInfo_filtered);
218 _MapInfo_filtered = MapInfo_FilterGametype_Recursive(pGametype, pFeatures, 0, _MapInfo_globcount, pAbortOnGenerate);
219 if not(_MapInfo_filtered)
221 dprint("Autogenerated a .mapinfo, doing the rest later.\n");
224 _MapInfo_filtered = strzone(_MapInfo_filtered);
225 MapInfo_count = HugeSetOfIntegers_length(_MapInfo_filtered);
226 //print("Filter ", ftos(pGametype), "/", ftos(pFeatures), " has ", ftos(MapInfo_count), "\n");
231 // load info about the i-th map into the MapInfo_Map_* globals
232 string MapInfo_BSPName_ByID(float i)
234 return _MapInfo_GlobItem(HugeSetOfIntegers_get(_MapInfo_filtered, i));
237 string unquote(string s)
242 for(i = 0; i < l; ++i)
245 ch = substring(s, i, 1);
246 if(ch != " ") if(ch != "\"")
248 for(j = strlen(s) - i - 1; j > 0; --j)
250 ch = substring(s, i+j, 1);
251 if(ch != " ") if(ch != "\"")
252 return substring(s, i, j+1);
254 return substring(s, i, 1);
260 float MapInfo_Get_ByID(float i)
263 if(MapInfo_Get_ByName(MapInfo_BSPName_ByID(i), 0, 0))
265 // TODO save in cache
271 float _MapInfo_Generate(string pFilename) // 0: failure, 1: ok ent, 2: ok bsp
282 vector mapMins, mapMaxs;
285 fn = strcat("maps/", pFilename, ".ent");
286 fh = fopen(fn, FILE_READ);
290 fn = strcat("maps/", pFilename, ".bsp");
291 fh = fopen(fn, FILE_READ);
295 print("Analyzing ", fn, " to generate initial mapinfo; please edit that file later\n");
298 MapInfo_Map_supportedGametypes = 0;
302 if not((s = fgets(fh)))
304 if(inWorldspawn == 1)
305 if(startsWith(s, "}"))
311 if(k == "classname" && v == "worldspawn")
313 else if(k == "author")
314 MapInfo_Map_author = v;
315 else if(k == "message")
317 i = strstrofs(v, " by ", 0);
318 if(MapInfo_Map_author == "He-Who-Must-Not-Be-Named" && i >= 0)
320 MapInfo_Map_title = substring(v, 0, i);
321 MapInfo_Map_author = substring(v, i + 4, strlen(v) - (i + 4));
324 MapInfo_Map_title = v;
331 o = stov(strcat("'", v, "'"));
332 mapMins_x = min(mapMins_x, o_x);
333 mapMins_y = min(mapMins_y, o_y);
334 mapMins_z = min(mapMins_z, o_z);
335 mapMaxs_x = max(mapMaxs_x, o_x);
336 mapMaxs_y = max(mapMaxs_y, o_y);
337 mapMaxs_z = max(mapMaxs_z, o_z);
339 else if(k == "classname")
341 if(v == "dom_controlpoint")
342 MapInfo_Map_supportedGametypes |= MAPINFO_TYPE_DOMINATION;
343 else if(v == "item_flag_team2")
344 MapInfo_Map_supportedGametypes |= MAPINFO_TYPE_CTF;
345 else if(v == "team_CTF_blueflag")
346 MapInfo_Map_supportedGametypes |= MAPINFO_TYPE_CTF;
347 else if(v == "runematch_spawn_point")
348 MapInfo_Map_supportedGametypes |= MAPINFO_TYPE_RUNEMATCH;
349 else if(v == "target_assault_roundend")
350 MapInfo_Map_supportedGametypes |= MAPINFO_TYPE_ASSAULT;
351 else if(v == "onslaught_generator")
352 MapInfo_Map_supportedGametypes |= MAPINFO_TYPE_ONSLAUGHT;
353 else if(v == "info_player_team1")
354 ++MapInfo_Map_spawnpoints;
355 else if(v == "info_player_team2")
356 ++MapInfo_Map_spawnpoints;
357 else if(v == "info_player_start")
358 ++MapInfo_Map_spawnpoints;
359 else if(v == "info_player_deathmatch")
360 ++MapInfo_Map_spawnpoints;
361 else if(v == "weapon_nex")
363 else if(v == "weapon_railgun")
365 else if(startsWith(v, "weapon_"))
366 MapInfo_Map_supportedFeatures |= MAPINFO_FEATURE_WEAPONS;
372 print(fn, " ended still in worldspawn, BUG\n");
375 MapInfo_Map_diameter = vlen(mapMaxs - mapMins);
377 twoBaseModes = MapInfo_Map_supportedGametypes & (MAPINFO_TYPE_CTF | MAPINFO_TYPE_ASSAULT);
378 if(twoBaseModes && (MapInfo_Map_supportedGametypes == twoBaseModes))
380 // we have a CTF-only or Assault-only map. Don't add other modes then,
381 // as the map is too symmetric for them.
385 MapInfo_Map_supportedGametypes |= MAPINFO_TYPE_DEATHMATCH; // DM always works
386 MapInfo_Map_supportedGametypes |= MAPINFO_TYPE_LMS; // LMS always works
388 if(MapInfo_Map_spawnpoints >= 8 && MapInfo_Map_diameter > 4096)
389 MapInfo_Map_supportedGametypes |= MAPINFO_TYPE_TEAM_DEATHMATCH;
390 if( MapInfo_Map_diameter < 4096)
391 MapInfo_Map_supportedGametypes |= MAPINFO_TYPE_ARENA;
392 if(MapInfo_Map_spawnpoints >= 12 && MapInfo_Map_diameter > 5120)
393 MapInfo_Map_supportedGametypes |= MAPINFO_TYPE_KEYHUNT;
401 void _MapInfo_Map_Reset()
403 MapInfo_Map_title = "Untitled1";
404 MapInfo_Map_description = "Bleh.";
405 MapInfo_Map_author = "He-Who-Must-Not-Be-Named";
406 MapInfo_Map_supportedGametypes = 0;
407 MapInfo_Map_supportedFeatures = 0;
408 MapInfo_Map_diameter = 0;
409 MapInfo_Map_spawnpoints = 0;
412 void _MapInfo_Map_ApplyGametype(string s, float pWantedType, float pThisType)
414 MapInfo_Map_supportedGametypes |= pThisType;
415 if(!(pThisType & pWantedType))
418 cvar_set("fraglimit", car(s));
421 cvar_set("timelimit", car(s));
424 if(pWantedType == MAPINFO_TYPE_TEAM_DEATHMATCH)
426 cvar_set("g_tdm_teams", car(s));
430 if(pWantedType == MAPINFO_TYPE_KEYHUNT)
432 cvar_set("g_keyhunt_teams", car(s));
437 float MapInfo_Type_FromString(string t)
439 if (t == "dm") return MAPINFO_TYPE_DEATHMATCH;
440 else if(t == "tdm") return MAPINFO_TYPE_TEAM_DEATHMATCH;
441 else if(t == "dom") return MAPINFO_TYPE_DOMINATION;
442 else if(t == "ctf") return MAPINFO_TYPE_CTF;
443 else if(t == "rune") return MAPINFO_TYPE_RUNEMATCH;
444 else if(t == "lms") return MAPINFO_TYPE_LMS;
445 else if(t == "arena") return MAPINFO_TYPE_ARENA;
446 else if(t == "kh") return MAPINFO_TYPE_KEYHUNT;
447 else if(t == "as") return MAPINFO_TYPE_ASSAULT;
448 else if(t == "ons") return MAPINFO_TYPE_ONSLAUGHT;
449 else if(t == "all") return MAPINFO_TYPE_ALL;
453 // load info about a map by name into the MapInfo_Map_* globals
454 float MapInfo_Get_ByName(string pFilename, float pAllowGenerate, float pGametypeToSet)
461 if(pGametypeToSet == 0)
462 if(MapInfo_Cache_Retrieve(pFilename))
467 MapInfo_Map_bspname = pFilename;
469 // default all generic fields so they have "good" values in case something fails
470 fn = strcat("maps/", pFilename, ".mapinfo");
471 fh = fopen(fn, FILE_READ);
476 _MapInfo_Map_Reset();
477 r = _MapInfo_Generate(pFilename);
480 fh = fopen(fn, FILE_WRITE);
481 fputs(fh, strcat("title ", MapInfo_Map_title, "\n"));
482 fputs(fh, strcat("description ", MapInfo_Map_description, "\n"));
483 fputs(fh, strcat("author ", MapInfo_Map_author, "\n"));
484 fputs(fh, strcat("_diameter ", ftos(MapInfo_Map_diameter), "\n"));
485 fputs(fh, strcat("_spawnpoints ", ftos(MapInfo_Map_spawnpoints), "\n"));
486 if(MapInfo_Map_supportedFeatures & MAPINFO_FEATURE_WEAPONS) fputs(fh, "has weapons\n");
487 if(MapInfo_Map_supportedGametypes & MAPINFO_TYPE_DEATHMATCH) fputs(fh, "type dm 30 20\n");
488 if(MapInfo_Map_supportedGametypes & MAPINFO_TYPE_TEAM_DEATHMATCH) fputs(fh, "type tdm 50 20 2\n");
489 if(MapInfo_Map_supportedGametypes & MAPINFO_TYPE_DOMINATION) fputs(fh, "type dom 200 20\n");
490 if(MapInfo_Map_supportedGametypes & MAPINFO_TYPE_CTF) fputs(fh, "type ctf 300 20\n");
491 if(MapInfo_Map_supportedGametypes & MAPINFO_TYPE_RUNEMATCH) fputs(fh, "type rune 200 20\n");
492 if(MapInfo_Map_supportedGametypes & MAPINFO_TYPE_LMS) fputs(fh, "type lms 9 20\n");
493 if(MapInfo_Map_supportedGametypes & MAPINFO_TYPE_ARENA) fputs(fh, "type arena 10 20\n");
494 if(MapInfo_Map_supportedGametypes & MAPINFO_TYPE_KEYHUNT) fputs(fh, "type kh 1000 20 3\n");
495 if(MapInfo_Map_supportedGametypes & MAPINFO_TYPE_ASSAULT) fputs(fh, "type as 20\n");
496 if(MapInfo_Map_supportedGametypes & MAPINFO_TYPE_ONSLAUGHT) fputs(fh, "type ons 20\n");
498 fh2 = fopen(strcat("scripts/", pFilename, ".arena"), FILE_READ);
502 fputs(fh, "settemp_for_type all sv_q3acompat_machineshotgunswap 1\n");
508 fh = fopen(fn, FILE_READ);
510 error("... but I just wrote it!");
513 _MapInfo_Map_Reset();
516 if not((s = fgets(fh)))
518 t = car(s); s = cdr(s);
520 MapInfo_Map_title = s;
521 else if(t == "description")
522 MapInfo_Map_description = s;
523 else if(t == "author")
524 MapInfo_Map_author = s;
525 else if(t == "_diameter")
526 MapInfo_Map_diameter = stof(s);
527 else if(t == "_spawnpoints")
528 MapInfo_Map_spawnpoints = stof(s);
531 t = car(s); s = cdr(s);
532 if (t == "weapons") MapInfo_Map_supportedFeatures |= MAPINFO_FEATURE_WEAPONS;
534 dprint("Map ", pFilename, " supports unknown feature ", t, ", ignored\n");
538 t = car(s); s = cdr(s);
539 f = MapInfo_Type_FromString(t);
541 _MapInfo_Map_ApplyGametype (s, pGametypeToSet, f);
543 dprint("Map ", pFilename, " supports unknown game type ", t, ", ignored\n");
545 else if(t == "settemp_for_type")
547 t = car(s); s = cdr(s);
548 if((f = MapInfo_Type_FromString(t)))
550 if(f & pGametypeToSet)
552 t = car(s); s = cdr(s);
553 if(strstrofs(t, "\"", 0) >= 0)
554 print("Map ", pFilename, " contains a potentially harmful setting, ignored\n");
555 else if(strstrofs(t, "\\", 0) >= 0)
556 print("Map ", pFilename, " contains a potentially harmful setting, ignored\n");
557 else if(strstrofs(t, ";", 0) >= 0)
558 print("Map ", pFilename, " contains a potentially harmful setting, ignored\n");
559 else if(strstrofs(s, "\"", 0) >= 0)
560 print("Map ", pFilename, " contains a potentially harmful setting, ignored\n");
561 else if(strstrofs(s, "\\", 0) >= 0)
562 print("Map ", pFilename, " contains a potentially harmful setting, ignored\n");
563 else if(strstrofs(s, ";", 0) >= 0)
564 print("Map ", pFilename, " contains a potentially harmful setting, ignored\n");
567 dprint("Applying temporary setting ", t, " := ", s, "\n");
574 dprint("Map ", pFilename, " has a setting for unknown game type ", t, ", ignored\n");
578 dprint("Map ", pFilename, " provides unknown info item ", t, ", ignored\n");
582 if(!(MapInfo_Map_supportedGametypes & pGametypeToSet))
583 error("Can't select the requested game type. Bailing out.");
584 MapInfo_Cache_Store();
585 if(MapInfo_Map_supportedGametypes != 0)
587 dprint("Map ", pFilename, " supports no game types, ignored\n");
591 float MapInfo_FindName(string s)
593 // if there is exactly one map of prefix s, return it
594 // if not, return the null string
595 // note that DP sorts glob results... so I can use a binary search
599 // invariants: r is behind s, l-1 is equal or before
602 m = floor((l + r) / 2);
603 MapInfo_FindName_match = _MapInfo_GlobItem(HugeSetOfIntegers_get(_MapInfo_filtered, m));
604 cmp = strcasecmp(MapInfo_FindName_match, s);
606 return m; // found and good
608 l = m + 1; // l-1 is before s
612 MapInfo_FindName_match = _MapInfo_GlobItem(HugeSetOfIntegers_get(_MapInfo_filtered, l));
613 MapInfo_FindName_firstResult = l;
614 // r == l, so: l is behind s, l-1 is before
615 // SO: if there is any, l is the one with the right prefix
616 // and l+1 may be one too
617 if(l == MapInfo_count)
619 MapInfo_FindName_match = string_null;
620 MapInfo_FindName_firstResult = -1;
621 return -1; // no MapInfo_FindName_match, behind last item
623 if(!startsWithNocase(MapInfo_FindName_match, s))
625 MapInfo_FindName_match = string_null;
626 MapInfo_FindName_firstResult = -1;
627 return -1; // wrong prefix
629 if(l == MapInfo_count - 1)
630 return l; // last one, nothing can follow => unique
631 if(startsWithNocase(_MapInfo_GlobItem(HugeSetOfIntegers_get(_MapInfo_filtered, l + 1)), s))
633 MapInfo_FindName_match = string_null;
634 return -1; // ambigous MapInfo_FindName_match
639 string MapInfo_FixName(string s)
642 return MapInfo_FindName_match;
645 float MapInfo_CurrentFeatures()
649 if(!(cvar("g_instagib") || cvar("g_minstagib") || cvar("g_nixnex") || cvar("g_rocketarena")))
650 req |= MAPINFO_FEATURE_WEAPONS;
654 float MapInfo_CurrentGametype()
656 if(cvar("g_domination"))
657 return MAPINFO_TYPE_DOMINATION;
658 else if(cvar("g_ctf"))
659 return MAPINFO_TYPE_CTF;
660 else if(cvar("g_runematch"))
661 return MAPINFO_TYPE_RUNEMATCH;
662 else if(cvar("g_tdm"))
663 return MAPINFO_TYPE_TEAM_DEATHMATCH;
664 else if(cvar("g_assault"))
665 return MAPINFO_TYPE_ASSAULT;
666 else if(cvar("g_lms"))
667 return MAPINFO_TYPE_LMS;
668 else if(cvar("g_arena"))
669 return MAPINFO_TYPE_ARENA;
670 else if(cvar("g_keyhunt"))
671 return MAPINFO_TYPE_KEYHUNT;
672 else if(cvar("g_onslaught"))
673 return MAPINFO_TYPE_ONSLAUGHT;
675 return MAPINFO_TYPE_DEATHMATCH;
678 float MapInfo_CheckMap(string s) // returns 0 if the map can't be played with the current settings, 1 otherwise
680 if(!MapInfo_Get_ByName(s, 1, 0))
682 if((MapInfo_Map_supportedGametypes & MapInfo_CurrentGametype()) == 0)
684 if((MapInfo_Map_supportedFeatures & MapInfo_CurrentFeatures()) != MapInfo_CurrentFeatures())
689 void MapInfo_SwitchGameType(float t)
691 cvar_set("gamecfg", "0");
692 cvar_set("g_dm", (t == MAPINFO_TYPE_DEATHMATCH) ? "1" : "0");
693 cvar_set("g_tdm", (t == MAPINFO_TYPE_TEAM_DEATHMATCH) ? "1" : "0");
694 cvar_set("g_domination", (t == MAPINFO_TYPE_DOMINATION) ? "1" : "0");
695 cvar_set("g_ctf", (t == MAPINFO_TYPE_CTF) ? "1" : "0");
696 cvar_set("g_runematch", (t == MAPINFO_TYPE_RUNEMATCH) ? "1" : "0");
697 cvar_set("g_lms", (t == MAPINFO_TYPE_LMS) ? "1" : "0");
698 cvar_set("g_arena", (t == MAPINFO_TYPE_ARENA) ? "1" : "0");
699 cvar_set("g_keyhunt", (t == MAPINFO_TYPE_KEYHUNT) ? "1" : "0");
700 cvar_set("g_assault", (t == MAPINFO_TYPE_ASSAULT) ? "1" : "0");
701 cvar_set("g_onslaught", (t == MAPINFO_TYPE_ONSLAUGHT) ? "1" : "0");
704 void MapInfo_LoadMap(string s)
706 MapInfo_Map_supportedGametypes = 0;
707 if(!MapInfo_CheckMap(s))
709 print("EMERGENCY: can't play the selected map in the given game mode. Falling back to DM.\n");
710 MapInfo_SwitchGameType(MAPINFO_TYPE_DEATHMATCH);
712 localcmd(strcat("\nsettemp_restore\nchangelevel ", s, "\n"));
715 string MapInfo_ListAllowedMaps()
720 // to make absolutely sure:
722 MapInfo_FilterGametype(MapInfo_CurrentGametype(), MapInfo_CurrentFeatures(), 0);
725 for(i = 0; i < MapInfo_count; ++i)
726 out = strcat(out, " ", _MapInfo_GlobItem(HugeSetOfIntegers_get(_MapInfo_filtered, i)));
727 return substring(out, 1, strlen(out) - 1);
730 void MapInfo_LoadMapSettings(string s) // to be called from worldspawn
733 if(!MapInfo_CheckMap(s))
735 if(MapInfo_Map_supportedGametypes <= 0)
736 error("Mapinfo system is not functional at all. BAILED OUT.\n");
739 while(!(MapInfo_Map_supportedGametypes & 1))
742 MapInfo_Map_supportedGametypes = floor(MapInfo_Map_supportedGametypes / 2);
744 // t is now a supported mode!
745 print("EMERGENCY: can't play the selected map in the given game mode. Falling back to a supported mode.\n");
746 MapInfo_SwitchGameType(t);
748 cvar_settemp_restore();
749 MapInfo_Get_ByName(s, 1, MapInfo_CurrentGametype());