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");
31 // HUGE SET - stored in a string
32 string HugeSetOfIntegers_empty()
36 float HugeSetOfIntegers_get(string pArr, float i)
38 return stof(substring(pArr, i * 4, 4));
40 float HugeSetOfIntegers_length(string pArr)
42 return strlen(pArr) / 4;
44 string HugeSetOfIntegers_concat(string a1, string a2)
46 return strcat(a1, a2);
48 string HugeSetOfIntegers_insert(string a1, float n, string a2)
49 // special concat function to build up large lists in less time by binary concatenation
52 s = strcat(" ", ftos(n));
53 return strcat(a1, substring(s, strlen(s) - 4, 4), a2);
57 // generic string stuff
58 float startsWith(string haystack, string needle)
60 return substring(haystack, 0, strlen(needle)) == needle;
62 float startsWithNocase(string haystack, string needle)
64 return strcasecmp(substring(haystack, 0, strlen(needle)), needle) == 0;
66 string extractRestOfLine(string haystack, string needle)
68 if(startsWith(haystack, needle))
69 return substring(haystack, strlen(needle), strlen(haystack) - strlen(needle));
75 o = strstrofs(s, " ", 0);
78 return substring(s, 0, o);
83 o = strstrofs(s, " ", 0);
86 return substring(s, o + 1, strlen(s) - (o + 1));
89 float _MapInfo_Cache_Active;
90 float _MapInfo_Cache_DB_NameToIndex;
91 float _MapInfo_Cache_Buf_IndexToMapData;
93 void MapInfo_Cache_Destroy()
95 if(!_MapInfo_Cache_Active)
98 db_close(_MapInfo_Cache_DB_NameToIndex);
99 buf_del(_MapInfo_Cache_Buf_IndexToMapData);
100 _MapInfo_Cache_Active = 0;
103 void MapInfo_Cache_Create()
105 MapInfo_Cache_Destroy();
106 _MapInfo_Cache_DB_NameToIndex = db_create();
107 _MapInfo_Cache_Buf_IndexToMapData = buf_create();
108 _MapInfo_Cache_Active = 1;
111 void MapInfo_Cache_Invalidate()
113 if(!_MapInfo_Cache_Active)
116 MapInfo_Cache_Create();
119 void MapInfo_Cache_Store()
123 if(!_MapInfo_Cache_Active)
126 s = db_get(_MapInfo_Cache_DB_NameToIndex, MapInfo_Map_bspname);
127 if(!s) // empty string is NOT valid here!
129 i = buf_getsize(_MapInfo_Cache_Buf_IndexToMapData);
130 db_put(_MapInfo_Cache_DB_NameToIndex, MapInfo_Map_bspname, ftos(i));
135 // now store all the stuff
136 bufstr_set(_MapInfo_Cache_Buf_IndexToMapData, i, MapInfo_Map_bspname);
137 bufstr_set(_MapInfo_Cache_Buf_IndexToMapData, ++i, MapInfo_Map_title);
138 bufstr_set(_MapInfo_Cache_Buf_IndexToMapData, ++i, MapInfo_Map_description);
139 bufstr_set(_MapInfo_Cache_Buf_IndexToMapData, ++i, MapInfo_Map_author);
140 bufstr_set(_MapInfo_Cache_Buf_IndexToMapData, ++i, ftos(MapInfo_Map_supportedGametypes));
141 bufstr_set(_MapInfo_Cache_Buf_IndexToMapData, ++i, ftos(MapInfo_Map_supportedFeatures));
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));
166 // GLOB HANDLING (for all BSP files)
167 float _MapInfo_globopen;
168 float _MapInfo_globcount;
169 float _MapInfo_globhandle;
170 string _MapInfo_GlobItem(float i)
173 s = search_getfilename(_MapInfo_globhandle, i);
174 return substring(s, 5, strlen(s) - 9); // without maps/ and .bsp
177 void MapInfo_Enumerate()
179 if(_MapInfo_globopen)
180 search_end(_MapInfo_globhandle);
181 MapInfo_Cache_Invalidate();
182 _MapInfo_globhandle = search_begin("maps/*.bsp", TRUE, TRUE);
183 _MapInfo_globcount = search_getsize(_MapInfo_globhandle);
184 _MapInfo_globopen = 1;
187 // filter the info by game type mask (updates MapInfo_count)
190 string _MapInfo_filtered;
191 float MapInfo_FilterList_Lookup(float i)
193 return MapInfo_FilterList_Lookup(i);
196 string MapInfo_FilterGametype_Recursive(float pGametype, float pFeatures, float pBegin, float pEnd, float pAbortOnGenerate)
202 return HugeSetOfIntegers_empty();
204 m = floor((pBegin + pEnd) / 2);
206 l = MapInfo_FilterGametype_Recursive(pGametype, pFeatures, pBegin, m, pAbortOnGenerate);
208 return string_null; // BAIL OUT
209 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.
212 MapInfo_progress = m / _MapInfo_globcount;
213 return string_null; // BAIL OUT
215 valid = (((MapInfo_Map_supportedGametypes & pGametype) != 0) && ((MapInfo_Map_supportedFeatures & pFeatures) == pFeatures));
216 r = MapInfo_FilterGametype_Recursive(pGametype, pFeatures, m + 1, pEnd, pAbortOnGenerate);
218 return string_null; // BAIL OUT
221 return HugeSetOfIntegers_insert(l, m, r);
223 return HugeSetOfIntegers_concat(l, r);
226 float MapInfo_FilterGametype(float pGametype, float pFeatures, float pAbortOnGenerate)
228 if(_MapInfo_filtered)
229 strunzone(_MapInfo_filtered);
230 _MapInfo_filtered = MapInfo_FilterGametype_Recursive(pGametype, pFeatures, 0, _MapInfo_globcount, pAbortOnGenerate);
231 if not(_MapInfo_filtered)
233 dprint("Autogenerated a .mapinfo, doing the rest later.\n");
236 _MapInfo_filtered = strzone(_MapInfo_filtered);
237 MapInfo_count = HugeSetOfIntegers_length(_MapInfo_filtered);
238 MapInfo_ClearTemps();
242 void MapInfo_Filter_Free()
244 if(_MapInfo_filtered)
246 strunzone(_MapInfo_filtered);
247 _MapInfo_filtered = string_null;
251 float _MapInfo_filtered;
252 float _MapInfo_filtered_allocated;
253 float MapInfo_FilterList_Lookup(float i)
255 return stof(bufstr_get(_MapInfo_filtered, i));
258 float MapInfo_FilterGametype(float pGametype, float pFeatures, float pAbortOnGenerate)
261 if not(_MapInfo_filtered_allocated)
263 _MapInfo_filtered_allocated = 1;
264 _MapInfo_filtered = buf_create();
267 for(i = 0, j = -1; i < _MapInfo_globcount; ++i)
269 if(MapInfo_Get_ByName(_MapInfo_GlobItem(i), 1, 0) == 2) // if we generated one... BAIL OUT and let the caller continue in the next frame.
272 dprint("Autogenerated a .mapinfo, doing the rest later.\n");
273 MapInfo_progress = i / _MapInfo_globcount;
276 if(((MapInfo_Map_supportedGametypes & pGametype) != 0) && ((MapInfo_Map_supportedFeatures & pFeatures) == pFeatures))
277 bufstr_set(_MapInfo_filtered, ++j, ftos(i));
279 MapInfo_count = j + 1;
280 MapInfo_ClearTemps();
284 void MapInfo_Filter_Free()
286 if(_MapInfo_filtered_allocated)
288 buf_del(_MapInfo_filtered);
289 _MapInfo_filtered_allocated = 0;
294 // load info about the i-th map into the MapInfo_Map_* globals
295 string MapInfo_BSPName_ByID(float i)
297 return _MapInfo_GlobItem(MapInfo_FilterList_Lookup(i));
300 string unquote(string s)
305 for(i = 0; i < l; ++i)
308 ch = substring(s, i, 1);
309 if(ch != " ") if(ch != "\"")
311 for(j = strlen(s) - i - 1; j > 0; --j)
313 ch = substring(s, i+j, 1);
314 if(ch != " ") if(ch != "\"")
315 return substring(s, i, j+1);
317 return substring(s, i, 1);
323 float MapInfo_Get_ByID(float i)
325 if(MapInfo_Get_ByName(MapInfo_BSPName_ByID(i), 0, 0))
330 float _MapInfo_Generate(string pFilename) // 0: failure, 1: ok ent, 2: ok bsp
340 float diameter, spawnpoints;
342 vector mapMins, mapMaxs;
345 fn = strcat("maps/", pFilename, ".ent");
346 fh = fopen(fn, FILE_READ);
350 fn = strcat("maps/", pFilename, ".bsp");
351 fh = fopen(fn, FILE_READ);
355 print("Analyzing ", fn, " to generate initial mapinfo; please edit that file later\n");
358 MapInfo_Map_supportedGametypes = 0;
363 if not((s = fgets(fh)))
365 if(inWorldspawn == 1)
366 if(startsWith(s, "}"))
372 if(k == "classname" && v == "worldspawn")
374 else if(k == "author")
375 MapInfo_Map_author = v;
376 else if(k == "_description")
377 MapInfo_Map_description = v;
378 else if(k == "message")
380 i = strstrofs(v, " by ", 0);
381 if(MapInfo_Map_author == "<AUTHOR>" && i >= 0)
383 MapInfo_Map_title = substring(v, 0, i);
384 MapInfo_Map_author = substring(v, i + 4, strlen(v) - (i + 4));
387 MapInfo_Map_title = v;
394 o = stov(strcat("'", v, "'"));
395 mapMins_x = min(mapMins_x, o_x);
396 mapMins_y = min(mapMins_y, o_y);
397 mapMins_z = min(mapMins_z, o_z);
398 mapMaxs_x = max(mapMaxs_x, o_x);
399 mapMaxs_y = max(mapMaxs_y, o_y);
400 mapMaxs_z = max(mapMaxs_z, o_z);
402 else if(k == "classname")
404 if(v == "dom_controlpoint")
405 MapInfo_Map_supportedGametypes |= MAPINFO_TYPE_DOMINATION;
406 else if(v == "item_flag_team2")
407 MapInfo_Map_supportedGametypes |= MAPINFO_TYPE_CTF;
408 else if(v == "team_CTF_blueflag")
409 MapInfo_Map_supportedGametypes |= MAPINFO_TYPE_CTF;
410 else if(v == "runematch_spawn_point")
411 MapInfo_Map_supportedGametypes |= MAPINFO_TYPE_RUNEMATCH;
412 else if(v == "target_assault_roundend")
413 MapInfo_Map_supportedGametypes |= MAPINFO_TYPE_ASSAULT;
414 else if(v == "onslaught_generator")
415 MapInfo_Map_supportedGametypes |= MAPINFO_TYPE_ONSLAUGHT;
416 else if(v == "info_player_team1")
418 else if(v == "info_player_team2")
420 else if(v == "info_player_start")
422 else if(v == "info_player_deathmatch")
424 else if(v == "weapon_nex")
426 else if(v == "weapon_railgun")
428 else if(startsWith(v, "weapon_"))
429 MapInfo_Map_supportedFeatures |= MAPINFO_FEATURE_WEAPONS;
435 print(fn, " ended still in worldspawn, BUG\n");
438 diameter = vlen(mapMaxs - mapMins);
440 twoBaseModes = MapInfo_Map_supportedGametypes & (MAPINFO_TYPE_CTF | MAPINFO_TYPE_ASSAULT);
441 if(twoBaseModes && (MapInfo_Map_supportedGametypes == twoBaseModes))
443 // we have a CTF-only or Assault-only map. Don't add other modes then,
444 // as the map is too symmetric for them.
448 MapInfo_Map_supportedGametypes |= MAPINFO_TYPE_DEATHMATCH; // DM always works
449 MapInfo_Map_supportedGametypes |= MAPINFO_TYPE_LMS; // LMS always works
451 if(spawnpoints >= 8 && diameter > 4096)
452 MapInfo_Map_supportedGametypes |= MAPINFO_TYPE_TEAM_DEATHMATCH;
454 MapInfo_Map_supportedGametypes |= MAPINFO_TYPE_ARENA;
455 if(spawnpoints >= 12 && diameter > 5120)
456 MapInfo_Map_supportedGametypes |= MAPINFO_TYPE_KEYHUNT;
459 dprint("-> diameter ", ftos(diameter));
460 dprint("; spawnpoints ", ftos(spawnpoints));
461 dprint("; modes ", ftos(MapInfo_Map_supportedGametypes), "\n");
468 void _MapInfo_Map_Reset()
470 MapInfo_Map_title = "<TITLE>";
471 MapInfo_Map_description = "<DESCRIPTION>";
472 MapInfo_Map_author = "<AUTHOR>";
473 MapInfo_Map_supportedGametypes = 0;
474 MapInfo_Map_supportedFeatures = 0;
477 void _MapInfo_Map_ApplyGametype(string s, float pWantedType, float pThisType)
480 MapInfo_Map_supportedGametypes |= pThisType;
481 if(!(pThisType & pWantedType))
484 cvar_set("fraglimit", car(s));
487 cvar_set("timelimit", car(s));
490 if(pWantedType == MAPINFO_TYPE_TEAM_DEATHMATCH)
492 sa = car(s); if(sa == "") sa = "2";
493 cvar_set("g_tdm_teams", sa);
497 if(pWantedType == MAPINFO_TYPE_KEYHUNT)
499 sa = car(s); if(sa == "") sa = "3";
500 cvar_set("g_keyhunt_teams", sa);
504 if(pWantedType == MAPINFO_TYPE_CTF)
506 sa = car(s); if(sa == "") sa = "10";
507 if(cvar("g_ctf_win_mode") != 2)
508 cvar_set("fraglimit", sa);
513 float MapInfo_Type_FromString(string t)
515 if (t == "dm") return MAPINFO_TYPE_DEATHMATCH;
516 else if(t == "tdm") return MAPINFO_TYPE_TEAM_DEATHMATCH;
517 else if(t == "dom") return MAPINFO_TYPE_DOMINATION;
518 else if(t == "ctf") return MAPINFO_TYPE_CTF;
519 else if(t == "rune") return MAPINFO_TYPE_RUNEMATCH;
520 else if(t == "lms") return MAPINFO_TYPE_LMS;
521 else if(t == "arena") return MAPINFO_TYPE_ARENA;
522 else if(t == "kh") return MAPINFO_TYPE_KEYHUNT;
523 else if(t == "as") return MAPINFO_TYPE_ASSAULT;
524 else if(t == "ons") return MAPINFO_TYPE_ONSLAUGHT;
525 else if(t == "all") return MAPINFO_TYPE_ALL;
529 // load info about a map by name into the MapInfo_Map_* globals
530 float MapInfo_Get_ByName(string pFilename, float pAllowGenerate, float pGametypeToSet)
537 if(pGametypeToSet == 0)
538 if(MapInfo_Cache_Retrieve(pFilename))
543 MapInfo_Map_bspname = pFilename;
545 // default all generic fields so they have "good" values in case something fails
546 fn = strcat("maps/", pFilename, ".mapinfo");
547 fh = fopen(fn, FILE_READ);
552 _MapInfo_Map_Reset();
553 r = _MapInfo_Generate(pFilename);
556 fh = fopen(fn, FILE_WRITE);
557 fputs(fh, strcat("title ", MapInfo_Map_title, "\n"));
558 fputs(fh, strcat("description ", MapInfo_Map_description, "\n"));
559 fputs(fh, strcat("author ", MapInfo_Map_author, "\n"));
560 if(MapInfo_Map_supportedFeatures & MAPINFO_FEATURE_WEAPONS) fputs(fh, "has weapons\n");
561 if(MapInfo_Map_supportedGametypes & MAPINFO_TYPE_DEATHMATCH) fputs(fh, "type dm 30 20\n");
562 if(MapInfo_Map_supportedGametypes & MAPINFO_TYPE_TEAM_DEATHMATCH) fputs(fh, "type tdm 50 20 2\n");
563 if(MapInfo_Map_supportedGametypes & MAPINFO_TYPE_DOMINATION) fputs(fh, "type dom 200 20\n");
564 if(MapInfo_Map_supportedGametypes & MAPINFO_TYPE_CTF) fputs(fh, "type ctf 300 20 10\n");
565 if(MapInfo_Map_supportedGametypes & MAPINFO_TYPE_RUNEMATCH) fputs(fh, "type rune 200 20\n");
566 if(MapInfo_Map_supportedGametypes & MAPINFO_TYPE_LMS) fputs(fh, "type lms 9 20\n");
567 if(MapInfo_Map_supportedGametypes & MAPINFO_TYPE_ARENA) fputs(fh, "type arena 10 20\n");
568 if(MapInfo_Map_supportedGametypes & MAPINFO_TYPE_KEYHUNT) fputs(fh, "type kh 1000 20 3\n");
569 if(MapInfo_Map_supportedGametypes & MAPINFO_TYPE_ASSAULT) fputs(fh, "type as 20\n");
570 if(MapInfo_Map_supportedGametypes & MAPINFO_TYPE_ONSLAUGHT) fputs(fh, "type ons 20\n");
572 fh2 = fopen(strcat("scripts/", pFilename, ".arena"), FILE_READ);
576 fputs(fh, "settemp_for_type all sv_q3acompat_machineshotgunswap 1\n");
582 fh = fopen(fn, FILE_READ);
584 error("... but I just wrote it!");
587 _MapInfo_Map_Reset();
590 if not((s = fgets(fh)))
593 // catch different sorts of comments
594 if(s == "") // empty lines
596 if(substring(s, 0, 1) == "#") // UNIX style
598 if(substring(s, 0, 2) == "//") // C++ style
600 if(substring(s, 0, 1) == "_") // q3map style
603 t = car(s); s = cdr(s);
605 MapInfo_Map_title = s;
606 else if(t == "description")
607 MapInfo_Map_description = s;
608 else if(t == "author")
609 MapInfo_Map_author = s;
612 t = car(s); s = cdr(s);
613 if (t == "weapons") MapInfo_Map_supportedFeatures |= MAPINFO_FEATURE_WEAPONS;
615 dprint("Map ", pFilename, " supports unknown feature ", t, ", ignored\n");
619 t = car(s); s = cdr(s);
620 f = MapInfo_Type_FromString(t);
622 _MapInfo_Map_ApplyGametype (s, pGametypeToSet, f);
624 dprint("Map ", pFilename, " supports unknown game type ", t, ", ignored\n");
626 else if(t == "settemp_for_type")
628 t = car(s); s = cdr(s);
629 if((f = MapInfo_Type_FromString(t)))
631 if(f & pGametypeToSet)
633 t = car(s); s = cdr(s);
634 if(strstrofs(t, "\"", 0) >= 0)
635 print("Map ", pFilename, " contains a potentially harmful setting, ignored\n");
636 else if(strstrofs(t, "\\", 0) >= 0)
637 print("Map ", pFilename, " contains a potentially harmful setting, ignored\n");
638 else if(strstrofs(t, ";", 0) >= 0)
639 print("Map ", pFilename, " contains a potentially harmful setting, ignored\n");
640 else if(strstrofs(s, "\"", 0) >= 0)
641 print("Map ", pFilename, " contains a potentially harmful setting, ignored\n");
642 else if(strstrofs(s, "\\", 0) >= 0)
643 print("Map ", pFilename, " contains a potentially harmful setting, ignored\n");
644 else if(strstrofs(s, ";", 0) >= 0)
645 print("Map ", pFilename, " contains a potentially harmful setting, ignored\n");
648 dprint("Applying temporary setting ", t, " := ", s, "\n");
655 dprint("Map ", pFilename, " has a setting for unknown game type ", t, ", ignored\n");
659 dprint("Map ", pFilename, " provides unknown info item ", t, ", ignored\n");
663 if(!(MapInfo_Map_supportedGametypes & pGametypeToSet))
664 error("Can't select the requested game type. Bailing out.");
665 MapInfo_Cache_Store();
666 if(MapInfo_Map_supportedGametypes != 0)
668 dprint("Map ", pFilename, " supports no game types, ignored\n");
672 float MapInfo_FindName(string s)
674 // if there is exactly one map of prefix s, return it
675 // if not, return the null string
676 // note that DP sorts glob results... so I can use a binary search
680 // invariants: r is behind s, l-1 is equal or before
683 m = floor((l + r) / 2);
684 MapInfo_FindName_match = _MapInfo_GlobItem(MapInfo_FilterList_Lookup(m));
685 cmp = strcasecmp(MapInfo_FindName_match, s);
687 return m; // found and good
689 l = m + 1; // l-1 is before s
693 MapInfo_FindName_match = _MapInfo_GlobItem(MapInfo_FilterList_Lookup(l));
694 MapInfo_FindName_firstResult = l;
695 // r == l, so: l is behind s, l-1 is before
696 // SO: if there is any, l is the one with the right prefix
697 // and l+1 may be one too
698 if(l == MapInfo_count)
700 MapInfo_FindName_match = string_null;
701 MapInfo_FindName_firstResult = -1;
702 return -1; // no MapInfo_FindName_match, behind last item
704 if(!startsWithNocase(MapInfo_FindName_match, s))
706 MapInfo_FindName_match = string_null;
707 MapInfo_FindName_firstResult = -1;
708 return -1; // wrong prefix
710 if(l == MapInfo_count - 1)
711 return l; // last one, nothing can follow => unique
712 if(startsWithNocase(_MapInfo_GlobItem(MapInfo_FilterList_Lookup(l + 1)), s))
714 MapInfo_FindName_match = string_null;
715 return -1; // ambigous MapInfo_FindName_match
720 string MapInfo_FixName(string s)
723 return MapInfo_FindName_match;
726 float MapInfo_CurrentFeatures()
730 if(!(cvar("g_lms") || cvar("g_instagib") || cvar("g_minstagib") || cvar("g_nixnex") || cvar("g_rocketarena")))
731 req |= MAPINFO_FEATURE_WEAPONS;
735 float MapInfo_CurrentGametype()
737 if(cvar("g_domination"))
738 return MAPINFO_TYPE_DOMINATION;
739 else if(cvar("g_ctf"))
740 return MAPINFO_TYPE_CTF;
741 else if(cvar("g_runematch"))
742 return MAPINFO_TYPE_RUNEMATCH;
743 else if(cvar("g_tdm"))
744 return MAPINFO_TYPE_TEAM_DEATHMATCH;
745 else if(cvar("g_assault"))
746 return MAPINFO_TYPE_ASSAULT;
747 else if(cvar("g_lms"))
748 return MAPINFO_TYPE_LMS;
749 else if(cvar("g_arena"))
750 return MAPINFO_TYPE_ARENA;
751 else if(cvar("g_keyhunt"))
752 return MAPINFO_TYPE_KEYHUNT;
753 else if(cvar("g_onslaught"))
754 return MAPINFO_TYPE_ONSLAUGHT;
756 return MAPINFO_TYPE_DEATHMATCH;
759 float _MapInfo_CheckMap(string s) // returns 0 if the map can't be played with the current settings, 1 otherwise
761 if(!MapInfo_Get_ByName(s, 1, 0))
763 if((MapInfo_Map_supportedGametypes & MapInfo_CurrentGametype()) == 0)
765 if((MapInfo_Map_supportedFeatures & MapInfo_CurrentFeatures()) != MapInfo_CurrentFeatures())
770 float MapInfo_CheckMap(string s) // returns 0 if the map can't be played with the current settings, 1 otherwise
773 r = _MapInfo_CheckMap(s);
774 MapInfo_ClearTemps();
778 void MapInfo_SwitchGameType(float t)
780 cvar_set("gamecfg", "0");
781 cvar_set("g_dm", (t == MAPINFO_TYPE_DEATHMATCH) ? "1" : "0");
782 cvar_set("g_tdm", (t == MAPINFO_TYPE_TEAM_DEATHMATCH) ? "1" : "0");
783 cvar_set("g_domination", (t == MAPINFO_TYPE_DOMINATION) ? "1" : "0");
784 cvar_set("g_ctf", (t == MAPINFO_TYPE_CTF) ? "1" : "0");
785 cvar_set("g_runematch", (t == MAPINFO_TYPE_RUNEMATCH) ? "1" : "0");
786 cvar_set("g_lms", (t == MAPINFO_TYPE_LMS) ? "1" : "0");
787 cvar_set("g_arena", (t == MAPINFO_TYPE_ARENA) ? "1" : "0");
788 cvar_set("g_keyhunt", (t == MAPINFO_TYPE_KEYHUNT) ? "1" : "0");
789 cvar_set("g_assault", (t == MAPINFO_TYPE_ASSAULT) ? "1" : "0");
790 cvar_set("g_onslaught", (t == MAPINFO_TYPE_ONSLAUGHT) ? "1" : "0");
793 void MapInfo_LoadMap(string s)
795 MapInfo_Map_supportedGametypes = 0;
796 if(!MapInfo_CheckMap(s))
798 print("EMERGENCY: can't play the selected map in the given game mode. Falling back to DM.\n");
799 MapInfo_SwitchGameType(MAPINFO_TYPE_DEATHMATCH);
801 localcmd(strcat("\nsettemp_restore\nchangelevel ", s, "\n"));
804 string MapInfo_ListAllowedMaps()
809 // to make absolutely sure:
811 MapInfo_FilterGametype(MapInfo_CurrentGametype(), MapInfo_CurrentFeatures(), 0);
814 for(i = 0; i < MapInfo_count; ++i)
815 out = strcat(out, " ", _MapInfo_GlobItem(MapInfo_FilterList_Lookup(i)));
816 return substring(out, 1, strlen(out) - 1);
819 void MapInfo_LoadMapSettings(string s) // to be called from worldspawn
822 if(!_MapInfo_CheckMap(s)) // with underscore, it keeps temps
824 if(MapInfo_Map_supportedGametypes <= 0)
825 error("Mapinfo system is not functional at all. BAILED OUT.\n");
828 while(!(MapInfo_Map_supportedGametypes & 1))
831 MapInfo_Map_supportedGametypes = floor(MapInfo_Map_supportedGametypes / 2);
833 // t is now a supported mode!
834 print("EMERGENCY: can't play the selected map in the given game mode. Falling back to a supported mode.\n");
835 MapInfo_SwitchGameType(t);
837 cvar_settemp_restore();
838 MapInfo_Get_ByName(s, 1, MapInfo_CurrentGametype());
839 MapInfo_ClearTemps();
842 void MapInfo_ClearTemps()
844 MapInfo_Map_bspname = string_null;
845 MapInfo_Map_title = string_null;
846 MapInfo_Map_description = string_null;
847 MapInfo_Map_author = string_null;
848 MapInfo_Map_supportedGametypes = 0;
849 MapInfo_Map_supportedFeatures = 0;
852 void MapInfo_Shutdown()
854 MapInfo_ClearTemps();
855 MapInfo_Filter_Free();
856 MapInfo_Cache_Destroy();
857 if(_MapInfo_globopen)
859 search_end(_MapInfo_globhandle);
860 _MapInfo_globhandle = -1;
861 _MapInfo_globopen = FALSE;