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!
127 i = buf_getsize(_MapInfo_Cache_Buf_IndexToMapData);
128 db_put(_MapInfo_Cache_DB_NameToIndex, MapInfo_Map_bspname, ftos(i));
133 // now store all the stuff
134 bufstr_set(_MapInfo_Cache_Buf_IndexToMapData, i++, MapInfo_Map_bspname);
135 bufstr_set(_MapInfo_Cache_Buf_IndexToMapData, i++, MapInfo_Map_title);
136 bufstr_set(_MapInfo_Cache_Buf_IndexToMapData, i++, MapInfo_Map_description);
137 bufstr_set(_MapInfo_Cache_Buf_IndexToMapData, i++, MapInfo_Map_author);
138 bufstr_set(_MapInfo_Cache_Buf_IndexToMapData, i++, ftos(MapInfo_Map_supportedGametypes));
139 bufstr_set(_MapInfo_Cache_Buf_IndexToMapData, i++, ftos(MapInfo_Map_supportedFeatures));
140 bufstr_set(_MapInfo_Cache_Buf_IndexToMapData, i++, ftos(MapInfo_Map_diameter));
141 bufstr_set(_MapInfo_Cache_Buf_IndexToMapData, i++, ftos(MapInfo_Map_spawnpoints));
144 float MapInfo_Cache_Retrieve(string map)
148 if(!_MapInfo_Cache_Active)
151 s = db_get(_MapInfo_Cache_DB_NameToIndex, map);
156 // now retrieve all the stuff
157 MapInfo_Map_bspname = bufstr_get(_MapInfo_Cache_Buf_IndexToMapData, i++);
158 MapInfo_Map_title = bufstr_get(_MapInfo_Cache_Buf_IndexToMapData, i++);
159 MapInfo_Map_description = bufstr_get(_MapInfo_Cache_Buf_IndexToMapData, i++);
160 MapInfo_Map_author = bufstr_get(_MapInfo_Cache_Buf_IndexToMapData, i++);
161 MapInfo_Map_supportedGametypes = stof(bufstr_get(_MapInfo_Cache_Buf_IndexToMapData, i++));
162 MapInfo_Map_supportedFeatures = stof(bufstr_get(_MapInfo_Cache_Buf_IndexToMapData, i++));
163 MapInfo_Map_diameter = stof(bufstr_get(_MapInfo_Cache_Buf_IndexToMapData, i++));
164 MapInfo_Map_spawnpoints = stof(bufstr_get(_MapInfo_Cache_Buf_IndexToMapData, i++));
168 // GLOB HANDLING (for all BSP files)
169 float _MapInfo_globopen;
170 float _MapInfo_globcount;
171 float _MapInfo_globhandle;
172 string _MapInfo_GlobItem(float i)
175 s = search_getfilename(_MapInfo_globhandle, i);
176 return substring(s, 5, strlen(s) - 9); // without maps/ and .bsp
179 void MapInfo_Enumerate()
181 if(_MapInfo_globopen)
182 search_end(_MapInfo_globhandle);
183 MapInfo_Cache_Invalidate();
184 _MapInfo_globhandle = search_begin("maps/*.bsp", TRUE, TRUE);
185 _MapInfo_globcount = search_getsize(_MapInfo_globhandle);
186 _MapInfo_globopen = 1;
189 // filter the info by game type mask (updates MapInfo_count)
190 string _MapInfo_filtered;
191 string MapInfo_FilterGametype_Recursive(float pGametype, float pFeatures, float pBegin, float pEnd, float pAbortOnGenerate)
197 return HugeSetOfIntegers_empty();
199 m = floor((pBegin + pEnd) / 2);
201 l = MapInfo_FilterGametype_Recursive(pGametype, pFeatures, pBegin, m, pAbortOnGenerate);
203 return string_null; // BAIL OUT
204 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.
206 return string_null; // BAIL OUT
207 valid = (((MapInfo_Map_supportedGametypes & pGametype) != 0) && ((MapInfo_Map_supportedFeatures & pFeatures) == pFeatures));
208 r = MapInfo_FilterGametype_Recursive(pGametype, pFeatures, m + 1, pEnd, pAbortOnGenerate);
210 return string_null; // BAIL OUT
213 return HugeSetOfIntegers_insert(l, m, r);
215 return HugeSetOfIntegers_concat(l, r);
217 float MapInfo_FilterGametype(float pGametype, float pFeatures, float pAbortOnGenerate)
219 if(_MapInfo_filtered)
220 strunzone(_MapInfo_filtered);
221 _MapInfo_filtered = MapInfo_FilterGametype_Recursive(pGametype, pFeatures, 0, _MapInfo_globcount, pAbortOnGenerate);
222 if not(_MapInfo_filtered)
224 dprint("Autogenerated a .mapinfo, doing the rest later.\n");
227 _MapInfo_filtered = strzone(_MapInfo_filtered);
228 MapInfo_count = HugeSetOfIntegers_length(_MapInfo_filtered);
229 //print("Filter ", ftos(pGametype), "/", ftos(pFeatures), " has ", ftos(MapInfo_count), "\n");
234 // load info about the i-th map into the MapInfo_Map_* globals
235 string MapInfo_BSPName_ByID(float i)
237 return _MapInfo_GlobItem(HugeSetOfIntegers_get(_MapInfo_filtered, i));
240 string unquote(string s)
245 for(i = 0; i < l; ++i)
248 ch = substring(s, i, 1);
249 if(ch != " ") if(ch != "\"")
251 for(j = strlen(s) - i - 1; j > 0; --j)
253 ch = substring(s, i+j, 1);
254 if(ch != " ") if(ch != "\"")
255 return substring(s, i, j+1);
257 return substring(s, i, 1);
263 float MapInfo_Get_ByID(float i)
265 if(MapInfo_Get_ByName(MapInfo_BSPName_ByID(i), 0, 0))
270 float _MapInfo_Generate(string pFilename) // 0: failure, 1: ok ent, 2: ok bsp
281 vector mapMins, mapMaxs;
284 fn = strcat("maps/", pFilename, ".ent");
285 fh = fopen(fn, FILE_READ);
289 fn = strcat("maps/", pFilename, ".bsp");
290 fh = fopen(fn, FILE_READ);
294 print("Analyzing ", fn, " to generate initial mapinfo; please edit that file later\n");
297 MapInfo_Map_supportedGametypes = 0;
301 if not((s = fgets(fh)))
303 if(inWorldspawn == 1)
304 if(startsWith(s, "}"))
310 if(k == "classname" && v == "worldspawn")
312 else if(k == "author")
313 MapInfo_Map_author = v;
314 else if(k == "message")
316 i = strstrofs(v, " by ", 0);
317 if(MapInfo_Map_author == "He-Who-Must-Not-Be-Named" && i >= 0)
319 MapInfo_Map_title = substring(v, 0, i);
320 MapInfo_Map_author = substring(v, i + 4, strlen(v) - (i + 4));
323 MapInfo_Map_title = v;
330 o = stov(strcat("'", v, "'"));
331 mapMins_x = min(mapMins_x, o_x);
332 mapMins_y = min(mapMins_y, o_y);
333 mapMins_z = min(mapMins_z, o_z);
334 mapMaxs_x = max(mapMaxs_x, o_x);
335 mapMaxs_y = max(mapMaxs_y, o_y);
336 mapMaxs_z = max(mapMaxs_z, o_z);
338 else if(k == "classname")
340 if(v == "dom_controlpoint")
341 MapInfo_Map_supportedGametypes |= MAPINFO_TYPE_DOMINATION;
342 else if(v == "item_flag_team2")
343 MapInfo_Map_supportedGametypes |= MAPINFO_TYPE_CTF;
344 else if(v == "team_CTF_blueflag")
345 MapInfo_Map_supportedGametypes |= MAPINFO_TYPE_CTF;
346 else if(v == "runematch_spawn_point")
347 MapInfo_Map_supportedGametypes |= MAPINFO_TYPE_RUNEMATCH;
348 else if(v == "target_assault_roundend")
349 MapInfo_Map_supportedGametypes |= MAPINFO_TYPE_ASSAULT;
350 else if(v == "onslaught_generator")
351 MapInfo_Map_supportedGametypes |= MAPINFO_TYPE_ONSLAUGHT;
352 else if(v == "info_player_team1")
353 ++MapInfo_Map_spawnpoints;
354 else if(v == "info_player_team2")
355 ++MapInfo_Map_spawnpoints;
356 else if(v == "info_player_start")
357 ++MapInfo_Map_spawnpoints;
358 else if(v == "info_player_deathmatch")
359 ++MapInfo_Map_spawnpoints;
360 else if(v == "weapon_nex")
362 else if(v == "weapon_railgun")
364 else if(startsWith(v, "weapon_"))
365 MapInfo_Map_supportedFeatures |= MAPINFO_FEATURE_WEAPONS;
371 print(fn, " ended still in worldspawn, BUG\n");
374 MapInfo_Map_diameter = vlen(mapMaxs - mapMins);
376 twoBaseModes = MapInfo_Map_supportedGametypes & (MAPINFO_TYPE_CTF | MAPINFO_TYPE_ASSAULT);
377 if(twoBaseModes && (MapInfo_Map_supportedGametypes == twoBaseModes))
379 // we have a CTF-only or Assault-only map. Don't add other modes then,
380 // as the map is too symmetric for them.
384 MapInfo_Map_supportedGametypes |= MAPINFO_TYPE_DEATHMATCH; // DM always works
385 MapInfo_Map_supportedGametypes |= MAPINFO_TYPE_LMS; // LMS always works
387 if(MapInfo_Map_spawnpoints >= 8 && MapInfo_Map_diameter > 4096)
388 MapInfo_Map_supportedGametypes |= MAPINFO_TYPE_TEAM_DEATHMATCH;
389 if( MapInfo_Map_diameter < 4096)
390 MapInfo_Map_supportedGametypes |= MAPINFO_TYPE_ARENA;
391 if(MapInfo_Map_spawnpoints >= 12 && MapInfo_Map_diameter > 5120)
392 MapInfo_Map_supportedGametypes |= MAPINFO_TYPE_KEYHUNT;
400 void _MapInfo_Map_Reset()
402 MapInfo_Map_title = "Untitled1";
403 MapInfo_Map_description = "Bleh.";
404 MapInfo_Map_author = "He-Who-Must-Not-Be-Named";
405 MapInfo_Map_supportedGametypes = 0;
406 MapInfo_Map_supportedFeatures = 0;
407 MapInfo_Map_diameter = 0;
408 MapInfo_Map_spawnpoints = 0;
411 void _MapInfo_Map_ApplyGametype(string s, float pWantedType, float pThisType)
413 MapInfo_Map_supportedGametypes |= pThisType;
414 if(!(pThisType & pWantedType))
417 cvar_set("fraglimit", car(s));
420 cvar_set("timelimit", car(s));
423 if(pWantedType == MAPINFO_TYPE_TEAM_DEATHMATCH)
425 cvar_set("g_tdm_teams", car(s));
429 if(pWantedType == MAPINFO_TYPE_KEYHUNT)
431 cvar_set("g_keyhunt_teams", car(s));
436 float MapInfo_Type_FromString(string t)
438 if (t == "dm") return MAPINFO_TYPE_DEATHMATCH;
439 else if(t == "tdm") return MAPINFO_TYPE_TEAM_DEATHMATCH;
440 else if(t == "dom") return MAPINFO_TYPE_DOMINATION;
441 else if(t == "ctf") return MAPINFO_TYPE_CTF;
442 else if(t == "rune") return MAPINFO_TYPE_RUNEMATCH;
443 else if(t == "lms") return MAPINFO_TYPE_LMS;
444 else if(t == "arena") return MAPINFO_TYPE_ARENA;
445 else if(t == "kh") return MAPINFO_TYPE_KEYHUNT;
446 else if(t == "as") return MAPINFO_TYPE_ASSAULT;
447 else if(t == "ons") return MAPINFO_TYPE_ONSLAUGHT;
448 else if(t == "all") return MAPINFO_TYPE_ALL;
452 // load info about a map by name into the MapInfo_Map_* globals
453 float MapInfo_Get_ByName(string pFilename, float pAllowGenerate, float pGametypeToSet)
460 if(pGametypeToSet == 0)
461 if(MapInfo_Cache_Retrieve(pFilename))
466 MapInfo_Map_bspname = pFilename;
468 // default all generic fields so they have "good" values in case something fails
469 fn = strcat("maps/", pFilename, ".mapinfo");
470 fh = fopen(fn, FILE_READ);
475 _MapInfo_Map_Reset();
476 r = _MapInfo_Generate(pFilename);
479 fh = fopen(fn, FILE_WRITE);
480 fputs(fh, strcat("title ", MapInfo_Map_title, "\n"));
481 fputs(fh, strcat("description ", MapInfo_Map_description, "\n"));
482 fputs(fh, strcat("author ", MapInfo_Map_author, "\n"));
483 fputs(fh, strcat("_diameter ", ftos(MapInfo_Map_diameter), "\n"));
484 fputs(fh, strcat("_spawnpoints ", ftos(MapInfo_Map_spawnpoints), "\n"));
485 if(MapInfo_Map_supportedFeatures & MAPINFO_FEATURE_WEAPONS) fputs(fh, "has weapons\n");
486 if(MapInfo_Map_supportedGametypes & MAPINFO_TYPE_DEATHMATCH) fputs(fh, "type dm 30 20\n");
487 if(MapInfo_Map_supportedGametypes & MAPINFO_TYPE_TEAM_DEATHMATCH) fputs(fh, "type tdm 50 20 2\n");
488 if(MapInfo_Map_supportedGametypes & MAPINFO_TYPE_DOMINATION) fputs(fh, "type dom 200 20\n");
489 if(MapInfo_Map_supportedGametypes & MAPINFO_TYPE_CTF) fputs(fh, "type ctf 300 20\n");
490 if(MapInfo_Map_supportedGametypes & MAPINFO_TYPE_RUNEMATCH) fputs(fh, "type rune 200 20\n");
491 if(MapInfo_Map_supportedGametypes & MAPINFO_TYPE_LMS) fputs(fh, "type lms 9 20\n");
492 if(MapInfo_Map_supportedGametypes & MAPINFO_TYPE_ARENA) fputs(fh, "type arena 10 20\n");
493 if(MapInfo_Map_supportedGametypes & MAPINFO_TYPE_KEYHUNT) fputs(fh, "type kh 1000 20 3\n");
494 if(MapInfo_Map_supportedGametypes & MAPINFO_TYPE_ASSAULT) fputs(fh, "type as 20\n");
495 if(MapInfo_Map_supportedGametypes & MAPINFO_TYPE_ONSLAUGHT) fputs(fh, "type ons 20\n");
497 fh2 = fopen(strcat("scripts/", pFilename, ".arena"), FILE_READ);
501 fputs(fh, "settemp_for_type all sv_q3acompat_machineshotgunswap 1\n");
507 fh = fopen(fn, FILE_READ);
509 error("... but I just wrote it!");
512 _MapInfo_Map_Reset();
515 if not((s = fgets(fh)))
517 t = car(s); s = cdr(s);
519 MapInfo_Map_title = s;
520 else if(t == "description")
521 MapInfo_Map_description = s;
522 else if(t == "author")
523 MapInfo_Map_author = s;
524 else if(t == "_diameter")
525 MapInfo_Map_diameter = stof(s);
526 else if(t == "_spawnpoints")
527 MapInfo_Map_spawnpoints = stof(s);
530 t = car(s); s = cdr(s);
531 if (t == "weapons") MapInfo_Map_supportedFeatures |= MAPINFO_FEATURE_WEAPONS;
533 dprint("Map ", pFilename, " supports unknown feature ", t, ", ignored\n");
537 t = car(s); s = cdr(s);
538 f = MapInfo_Type_FromString(t);
540 _MapInfo_Map_ApplyGametype (s, pGametypeToSet, f);
542 dprint("Map ", pFilename, " supports unknown game type ", t, ", ignored\n");
544 else if(t == "settemp_for_type")
546 t = car(s); s = cdr(s);
547 if((f = MapInfo_Type_FromString(t)))
549 if(f & pGametypeToSet)
551 t = car(s); s = cdr(s);
552 if(strstrofs(t, "\"", 0) >= 0)
553 print("Map ", pFilename, " contains a potentially harmful setting, ignored\n");
554 else if(strstrofs(t, "\\", 0) >= 0)
555 print("Map ", pFilename, " contains a potentially harmful setting, ignored\n");
556 else if(strstrofs(t, ";", 0) >= 0)
557 print("Map ", pFilename, " contains a potentially harmful setting, ignored\n");
558 else if(strstrofs(s, "\"", 0) >= 0)
559 print("Map ", pFilename, " contains a potentially harmful setting, ignored\n");
560 else if(strstrofs(s, "\\", 0) >= 0)
561 print("Map ", pFilename, " contains a potentially harmful setting, ignored\n");
562 else if(strstrofs(s, ";", 0) >= 0)
563 print("Map ", pFilename, " contains a potentially harmful setting, ignored\n");
566 dprint("Applying temporary setting ", t, " := ", s, "\n");
573 dprint("Map ", pFilename, " has a setting for unknown game type ", t, ", ignored\n");
577 dprint("Map ", pFilename, " provides unknown info item ", t, ", ignored\n");
581 if(!(MapInfo_Map_supportedGametypes & pGametypeToSet))
582 error("Can't select the requested game type. Bailing out.");
583 MapInfo_Cache_Store();
584 if(MapInfo_Map_supportedGametypes != 0)
586 dprint("Map ", pFilename, " supports no game types, ignored\n");
590 float MapInfo_FindName(string s)
592 // if there is exactly one map of prefix s, return it
593 // if not, return the null string
594 // note that DP sorts glob results... so I can use a binary search
598 // invariants: r is behind s, l-1 is equal or before
601 m = floor((l + r) / 2);
602 MapInfo_FindName_match = _MapInfo_GlobItem(HugeSetOfIntegers_get(_MapInfo_filtered, m));
603 cmp = strcasecmp(MapInfo_FindName_match, s);
605 return m; // found and good
607 l = m + 1; // l-1 is before s
611 MapInfo_FindName_match = _MapInfo_GlobItem(HugeSetOfIntegers_get(_MapInfo_filtered, l));
612 MapInfo_FindName_firstResult = l;
613 // r == l, so: l is behind s, l-1 is before
614 // SO: if there is any, l is the one with the right prefix
615 // and l+1 may be one too
616 if(l == MapInfo_count)
618 MapInfo_FindName_match = string_null;
619 MapInfo_FindName_firstResult = -1;
620 return -1; // no MapInfo_FindName_match, behind last item
622 if(!startsWithNocase(MapInfo_FindName_match, s))
624 MapInfo_FindName_match = string_null;
625 MapInfo_FindName_firstResult = -1;
626 return -1; // wrong prefix
628 if(l == MapInfo_count - 1)
629 return l; // last one, nothing can follow => unique
630 if(startsWithNocase(_MapInfo_GlobItem(HugeSetOfIntegers_get(_MapInfo_filtered, l + 1)), s))
632 MapInfo_FindName_match = string_null;
633 return -1; // ambigous MapInfo_FindName_match
638 string MapInfo_FixName(string s)
641 return MapInfo_FindName_match;
644 float MapInfo_CurrentFeatures()
648 if(!(cvar("g_instagib") || cvar("g_minstagib") || cvar("g_nixnex") || cvar("g_rocketarena")))
649 req |= MAPINFO_FEATURE_WEAPONS;
653 float MapInfo_CurrentGametype()
655 if(cvar("g_domination"))
656 return MAPINFO_TYPE_DOMINATION;
657 else if(cvar("g_ctf"))
658 return MAPINFO_TYPE_CTF;
659 else if(cvar("g_runematch"))
660 return MAPINFO_TYPE_RUNEMATCH;
661 else if(cvar("g_tdm"))
662 return MAPINFO_TYPE_TEAM_DEATHMATCH;
663 else if(cvar("g_assault"))
664 return MAPINFO_TYPE_ASSAULT;
665 else if(cvar("g_lms"))
666 return MAPINFO_TYPE_LMS;
667 else if(cvar("g_arena"))
668 return MAPINFO_TYPE_ARENA;
669 else if(cvar("g_keyhunt"))
670 return MAPINFO_TYPE_KEYHUNT;
671 else if(cvar("g_onslaught"))
672 return MAPINFO_TYPE_ONSLAUGHT;
674 return MAPINFO_TYPE_DEATHMATCH;
677 float MapInfo_CheckMap(string s) // returns 0 if the map can't be played with the current settings, 1 otherwise
679 if(!MapInfo_Get_ByName(s, 1, 0))
681 if((MapInfo_Map_supportedGametypes & MapInfo_CurrentGametype()) == 0)
683 if((MapInfo_Map_supportedFeatures & MapInfo_CurrentFeatures()) != MapInfo_CurrentFeatures())
688 void MapInfo_SwitchGameType(float t)
690 cvar_set("gamecfg", "0");
691 cvar_set("g_dm", (t == MAPINFO_TYPE_DEATHMATCH) ? "1" : "0");
692 cvar_set("g_tdm", (t == MAPINFO_TYPE_TEAM_DEATHMATCH) ? "1" : "0");
693 cvar_set("g_domination", (t == MAPINFO_TYPE_DOMINATION) ? "1" : "0");
694 cvar_set("g_ctf", (t == MAPINFO_TYPE_CTF) ? "1" : "0");
695 cvar_set("g_runematch", (t == MAPINFO_TYPE_RUNEMATCH) ? "1" : "0");
696 cvar_set("g_lms", (t == MAPINFO_TYPE_LMS) ? "1" : "0");
697 cvar_set("g_arena", (t == MAPINFO_TYPE_ARENA) ? "1" : "0");
698 cvar_set("g_keyhunt", (t == MAPINFO_TYPE_KEYHUNT) ? "1" : "0");
699 cvar_set("g_assault", (t == MAPINFO_TYPE_ASSAULT) ? "1" : "0");
700 cvar_set("g_onslaught", (t == MAPINFO_TYPE_ONSLAUGHT) ? "1" : "0");
703 void MapInfo_LoadMap(string s)
705 MapInfo_Map_supportedGametypes = 0;
706 if(!MapInfo_CheckMap(s))
708 print("EMERGENCY: can't play the selected map in the given game mode. Falling back to DM.\n");
709 MapInfo_SwitchGameType(MAPINFO_TYPE_DEATHMATCH);
711 localcmd(strcat("\nsettemp_restore\nchangelevel ", s, "\n"));
714 string MapInfo_ListAllowedMaps()
719 // to make absolutely sure:
721 MapInfo_FilterGametype(MapInfo_CurrentGametype(), MapInfo_CurrentFeatures(), 0);
724 for(i = 0; i < MapInfo_count; ++i)
725 out = strcat(out, " ", _MapInfo_GlobItem(HugeSetOfIntegers_get(_MapInfo_filtered, i)));
726 return substring(out, 1, strlen(out) - 1);
729 void MapInfo_LoadMapSettings(string s) // to be called from worldspawn
732 if(!MapInfo_CheckMap(s))
734 if(MapInfo_Map_supportedGametypes <= 0)
735 error("Mapinfo system is not functional at all. BAILED OUT.\n");
738 while(!(MapInfo_Map_supportedGametypes & 1))
741 MapInfo_Map_supportedGametypes = floor(MapInfo_Map_supportedGametypes / 2);
743 // t is now a supported mode!
744 print("EMERGENCY: can't play the selected map in the given game mode. Falling back to a supported mode.\n");
745 MapInfo_SwitchGameType(t);
747 cvar_settemp_restore();
748 MapInfo_Get_ByName(s, 1, MapInfo_CurrentGametype());