Xonotic QuakeC
The free, fast arena FPS with crisp movement and a wide array of weapons
mapinfo.qh File Reference
#include "util.qh"
Include dependency graph for mapinfo.qh:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

class  Gametype

Macros

#define MAPINFO_SETTEMP_ACL_SYSTEM   "-g_mapinfo_* -rcon_* -_* -g_ban* +*"
#define MAPINFO_SETTEMP_ACL_USER   cvar_string("g_mapinfo_settemp_acl")
#define REGISTER_GAMETYPE(NAME, inst)

Functions

vector _GametypeFlags_FromGametype (int a)
float _MapInfo_FilterGametype (vector gametypeFlags, float features, float pFlagsRequired, float pFlagsForbidden, float pAbortOnGenerate)
string _MapInfo_FindArenaFile (string pFilename, string extension)
string _MapInfo_GetDefaultEx (Gametype t)
float _MapInfo_GetTeamPlayBool (Gametype t)
void _MapInfo_Parse_Settemp (string pFilename, string acl, float type, string s, float recurse)
bool _MapInfo_ParseArena (string arena_filename, int fh, string pFilename, Gametype pGametypeToSet, bool isdefi, bool isgenerator)
string MapInfo_BSPName_ByID (float i)
void MapInfo_Cache_Create ()
void MapInfo_Cache_Destroy ()
void MapInfo_Cache_Invalidate ()
float MapInfo_CheckMap (string s)
void MapInfo_ClearTemps ()
int MapInfo_CurrentFeatures ()
Gametype MapInfo_CurrentGametype ()
void MapInfo_Enumerate ()
float MapInfo_FilterGametype (Gametype gametypeFlags, float features, float pFlagsRequired, float pFlagsForbidden, float pAbortOnGenerate)
void MapInfo_FilterString (string sf)
float MapInfo_FindName (string s)
string MapInfo_FixName (string s)
int MapInfo_ForbiddenFlags ()
bool MapInfo_Get_ByID (int i)
int MapInfo_Get_ByName (string s, float allowGenerate, Gametype gametypeToSet)
string MapInfo_ListAllAllowedMaps (float pFlagsRequired, float pFlagsForbidden)
string MapInfo_ListAllowedMaps (Gametype type, float pFlagsRequired, float pFlagsForbidden)
void MapInfo_LoadMap (string s, float reinit)
void MapInfo_LoadMapSettings (string s)
int MapInfo_RequiredFlags ()
void MapInfo_Shutdown ()
void MapInfo_SwitchGameType (Gametype t)
string MapInfo_Type_Description (Gametype t)
Gametype MapInfo_Type_FromString (string t, bool dowarn, bool is_q3compat)
string MapInfo_Type_ToString (Gametype t)
string MapInfo_Type_ToText (Gametype t)
bool MapReadSizes (string map)
 STATIC_INIT (Gametypes_renumber)

Variables

const int GAMETYPE_FLAG_1V1 = BIT(6)
const int GAMETYPE_FLAG_HIDELIMITS = BIT(4)
const int GAMETYPE_FLAG_PREFERRED = BIT(2)
const int GAMETYPE_FLAG_PRIORITY = BIT(3)
const int GAMETYPE_FLAG_TEAMPLAY = BIT(0)
const int GAMETYPE_FLAG_USEPOINTS = BIT(1)
const int GAMETYPE_FLAG_WEAPONARENA = BIT(5)
vector gametype_flags
int map_maxplayers
int map_minplayers
float MapInfo_count
const int MAPINFO_FEATURE_MONSTERS = 8
const int MAPINFO_FEATURE_TURRETS = 4
const int MAPINFO_FEATURE_VEHICLES = 2
const int MAPINFO_FEATURE_WEAPONS = 1
float MapInfo_FindName_firstResult
string MapInfo_FindName_match
const int MAPINFO_FLAG_DONOTWANT = 8
const int MAPINFO_FLAG_FORBIDDEN = 2
const int MAPINFO_FLAG_FRUSTRATING = 4
const int MAPINFO_FLAG_HIDDEN = 1
Gametype MapInfo_LoadedGametype
string MapInfo_Map_author
string MapInfo_Map_bspname
string MapInfo_Map_clientstuff
string MapInfo_Map_description
int MapInfo_Map_flags
string MapInfo_Map_fog
vector MapInfo_Map_maxs
vector MapInfo_Map_mins
int MapInfo_Map_supportedFeatures
vector MapInfo_Map_supportedGametypes
string MapInfo_Map_title
string MapInfo_Map_titlestring
float MapInfo_progress
vector MAPINFO_TYPE_ALL

Macro Definition Documentation

◆ MAPINFO_SETTEMP_ACL_SYSTEM

#define MAPINFO_SETTEMP_ACL_SYSTEM   "-g_mapinfo_* -rcon_* -_* -g_ban* +*"

Definition at line 237 of file mapinfo.qh.

Referenced by _MapInfo_Parse_Settemp().

◆ MAPINFO_SETTEMP_ACL_USER

#define MAPINFO_SETTEMP_ACL_USER   cvar_string("g_mapinfo_settemp_acl")

Definition at line 236 of file mapinfo.qh.

Referenced by CampaignPreInit(), and MapInfo_Get_ByName_NoFallbacks().

◆ REGISTER_GAMETYPE

Function Documentation

◆ _GametypeFlags_FromGametype()

vector _GametypeFlags_FromGametype ( int a)

Definition at line 20 of file mapinfo.qc.

21{
22 if (REGISTRY_MAX(Gametypes) > 24)
23 if (a >= 24)
24 {
25 a -= 24;
26 if (REGISTRY_MAX(Gametypes) > 48)
27 if (a >= 24)
28 {
29 a -= 24;
30 return '0 0 1' * BIT(a);
31 }
32 return '0 1 0' * BIT(a);
33 }
34 return '1 0 0' * BIT(a);
35}
#define BIT(n)
Only ever assign into the first 24 bits in QC (so max is BIT(23)).
Definition bits.qh:8
#define REGISTRY_MAX(id)
Definition registry.qh:17

References BIT, REGISTRY_MAX, and vector.

Referenced by STATIC_INIT().

◆ _MapInfo_FilterGametype()

float _MapInfo_FilterGametype ( vector gametypeFlags,
float features,
float pFlagsRequired,
float pFlagsForbidden,
float pAbortOnGenerate )

References vector.

◆ _MapInfo_FindArenaFile()

string _MapInfo_FindArenaFile ( string pFilename,
string extension )

Definition at line 1002 of file mapinfo.qc.

1003{
1004 // A valid arena file with the "default" name may have been created as a map-specific
1005 // override of an arena file with a different name (possibly multi-map) in the pk3
1006 // (occasionally in the wild such file exists in the pk3 but isn't valid for a map in the pk3).
1007 // Therefore we try the "default" name first.
1008 string afile = _MapInfo_CheckArenaFile(strcat("scripts/", pFilename, extension), pFilename);
1009 if (afile != ""
1010 || !checkextension("DP_QC_FS_SEARCH_PACKFILE"))
1011 return afile;
1012
1013 string base_pack = whichpack(strcat("maps/", pFilename, ".bsp"));
1014 if(base_pack == "") // this map isn't packaged!
1015 return "";
1016 int glob = search_packfile_begin(strcat("scripts/*", extension), true, true, base_pack);
1017 if(glob < 0) // there's no matching file in the pack
1018 return "";
1019 int n = search_getsize(glob);
1020 for(int j = 0; j < n; ++j)
1021 {
1022 afile = search_getfilename(glob, j);
1023 if(_MapInfo_CheckArenaFile(afile, pFilename) != "")
1024 {
1025 search_end(glob);
1026 return afile;
1027 }
1028 }
1029 search_end(glob);
1030
1031 return ""; // if we get here, a valid .arena file could not be found
1032}
string _MapInfo_CheckArenaFile(string pFilename, string pMapname)
Definition mapinfo.qc:972
string search_getfilename(float handle, float num)
float search_getsize(float handle)
float checkextension(string ext)
void search_end(float handle)
strcat(_("^F4Countdown stopped!"), "\n^BG", _("Teams are too unbalanced."))

References _MapInfo_CheckArenaFile(), checkextension(), search_end(), search_getfilename(), search_getsize(), and strcat().

Referenced by _MapInfo_Generate(), MapInfo_Get_ByName_NoFallbacks(), and spawnfunc().

◆ _MapInfo_GetDefaultEx()

string _MapInfo_GetDefaultEx ( Gametype t)

Definition at line 533 of file mapinfo.qc.

534{
535 return t ? t.model2 : "";
536}

Referenced by _MapInfo_Map_ApplyGametypeEx().

◆ _MapInfo_GetTeamPlayBool()

float _MapInfo_GetTeamPlayBool ( Gametype t)

Definition at line 538 of file mapinfo.qc.

539{
540 return t ? t.team : false;
541}
bool team
does this gametype support teamplay?
Definition mapinfo.qh:46

References Gametype::team.

Referenced by MapHasRightSize(), NET_HANDLE(), and XonoticGametypeList_drawListBoxItem().

◆ _MapInfo_Parse_Settemp()

void _MapInfo_Parse_Settemp ( string pFilename,
string acl,
float type,
string s,
float recurse )

Definition at line 666 of file mapinfo.qc.

667{
668 string t;
669 float o;
670 // tabs are invalid, treat them as "empty"
671 s = strreplace("\t", "", s);
672
673 t = car(s); s = cdr(s);
674
675 // limited support of "" and comments
676 // remove trailing and leading " of t
677 if(substring(t, 0, 1) == "\"")
678 {
679 if(substring(t, -1, 1) == "\"")
680 t = substring(t, 1, -2);
681 }
682
683 // remove leading " of s
684 if(substring(s, 0, 1) == "\"")
685 {
686 s = substring(s, 1, -1);
687 }
688 // remove trailing " of s, and all that follows (cvar description)
689 o = strstrofs(s, "\"", 0);
690 if(o >= 0)
691 s = substring(s, 0, o);
692
693 // remove // comments
694 o = strstrofs(s, "//", 0);
695 if(o >= 0)
696 s = substring(s, 0, o);
697
698 // remove trailing spaces
699 while(substring(s, -1, 1) == " ")
700 s = substring(s, 0, -2);
701
702 if(t == "#include")
703 {
704 if(recurse > 0)
705 {
706 float fh = fopen(s, FILE_READ);
707 if(fh < 0)
708 {
709 if(WARN_COND)
710 LOG_WARN("Map ", pFilename, " references not existing config file ", s);
711 }
712 else
713 {
714 while((s = fgets(fh)))
715 {
716 s = strreplace("\t", "", s); // treat tabs as "empty", perform here first to ensure coments are detected
717 // catch different sorts of comments
718 if(s == "") // empty lines
719 continue;
720 if(substring(s, 0, 1) == "#") // UNIX style
721 continue;
722 if(substring(s, 0, 2) == "//") // C++ style
723 continue;
724 if(substring(s, 0, 1) == "_") // q3map style
725 continue;
726
727 if(substring(s, 0, 4) == "set ")
728 s = substring(s, 4, -1);
729 if(substring(s, 0, 5) == "seta ")
730 s = substring(s, 5, -1);
731
732 _MapInfo_Parse_Settemp(pFilename, acl, type, s, recurse - 1);
733 }
734 fclose(fh);
735 }
736 }
737 else if(WARN_COND)
738 LOG_WARN("Map ", pFilename, " uses too many levels of inclusion");
739 }
740 else if(t == ""
741 || !cvar_value_issafe(t)
742 || !cvar_value_issafe(s)
744 {
745 if (WARN_COND)
746 LOG_WARN("Map ", pFilename, " contains a potentially harmful setting, ignored");
747 }
748 else if(matchacl(acl, t) <= 0)
749 {
750 if (WARN_COND)
751 LOG_WARN("Map ", pFilename, " contains a denied setting, ignored");
752 }
753 else
754 {
755 if(type == 0) // server set
756 {
757 LOG_TRACE("Applying temporary setting ", t, " := ", s);
758 cvar_settemp(t, s);
759 }
760 else
761 {
762 LOG_TRACE("Applying temporary client setting ", t, " := ", s);
764 MapInfo_Map_clientstuff, "cl_cmd settemp \"", t, "\" \"", s, "\"\n"
765 );
766 }
767 }
768}
float matchacl(string acl, string str)
Definition util.qc:1437
float cvar_settemp(string tmp_cvar, string tmp_value)
Definition util.qc:807
const float FILE_READ
ERASEABLE bool cvar_value_issafe(string s)
Definition cvar.qh:11
#define strstrofs
#define LOG_TRACE(...)
Definition log.qh:76
#define LOG_WARN(...)
Definition log.qh:61
void _MapInfo_Parse_Settemp(string pFilename, string acl, float type, string s, float recurse)
Definition mapinfo.qc:666
#define WARN_COND
Definition mapinfo.qc:15
#define MAPINFO_SETTEMP_ACL_SYSTEM
Definition mapinfo.qh:237
string MapInfo_Map_clientstuff
Definition mapinfo.qh:11
string fgets(float fhandle)
void fclose(float fhandle)
string substring(string s, float start, float length)
float fopen(string filename, float mode)
ERASEABLE string car(string s)
returns first word
Definition string.qh:259
ERASEABLE string cdr(string s)
returns all but first word
Definition string.qh:268

References _MapInfo_Parse_Settemp(), car(), cdr(), cvar_settemp(), cvar_value_issafe(), fclose(), fgets(), FILE_READ, fopen(), LOG_TRACE, LOG_WARN, MapInfo_Map_clientstuff, MAPINFO_SETTEMP_ACL_SYSTEM, matchacl(), strcat(), strstrofs, substring(), and WARN_COND.

Referenced by _MapInfo_Parse_Settemp(), CampaignPreInit(), and MapInfo_Get_ByName_NoFallbacks().

◆ _MapInfo_ParseArena()

bool _MapInfo_ParseArena ( string arena_filename,
int fh,
string pFilename,
Gametype pGametypeToSet,
bool isdefi,
bool isgenerator )

Definition at line 820 of file mapinfo.qc.

821{
822 // NOTE: .arena files can hold more than 1 map's information!
823 // to handle this, we're going to store gathered information in local variables and save it if we encounter the correct map name
824 bool in_brackets = false; // testing a potential mapinfo section (within brackets)
825 bool dosave = false;
826 string stored_Map_description = "";
827 string stored_Map_title = "";
828 string stored_Map_author = "";
829 vector stored_supportedGametypes = '0 0 0';
830 int stored_supportedFeatures = 0;
831 int stored_flags = 0;
832 string t, s;
833
834 if (isgenerator)
835 LOG_INFO("Generating ", pFilename, ".mapinfo: analyzing ", arena_filename);
836
837 for (;;)
838 {
839 if (!((s = fgets(fh))))
840 break;
841
842 // catch different sorts of comments
843 if(s == "") // empty lines
844 continue;
845 if(substring(s, 0, 2) == "//") // C++ style
846 continue;
847 if(strstrofs(s, "{", 0) >= 0)
848 {
849 if(in_brackets)
850 return false; // edge case? already in a bracketed section!
851 in_brackets = true;
852 continue;
853 }
854 else if(!in_brackets)
855 {
856 // if we're not inside a bracket, don't process map info
857 continue;
858 }
859 if(strstrofs(s, "}", 0) >= 0)
860 {
861 if(!in_brackets)
862 return false; // no starting bracket! let the mapinfo generation system handle it
863 in_brackets = false;
864 if(dosave)
865 {
866 MapInfo_Map_description = stored_Map_description;
867 if(stored_Map_title != "")
868 MapInfo_Map_title = stored_Map_title;
869 if(stored_Map_author != "") // write the usual "<AUTHOR>" if we have nothing better
870 MapInfo_Map_author = stored_Map_author;
871 // might have .arena AND .defi for the same map so these bitfields are OR'd
872 if(isgenerator)
873 MapInfo_Map_supportedGametypes |= stored_supportedGametypes;
874 else
875 {
876 FOREACH(Gametypes, it.gametype_flags & stored_supportedGametypes,
877 {
878 _MapInfo_Map_ApplyGametype ("", pGametypeToSet, it, true);
879 });
880 }
881 MapInfo_Map_supportedFeatures |= stored_supportedFeatures;
882 MapInfo_Map_flags |= stored_flags;
883 return true; // no need to continue through the file, we have our map!
884 }
885 else
886 {
887 // discard any gathered locals, we're not using the correct map!
888 stored_Map_description = "";
889 stored_Map_title = "";
890 stored_Map_author = "";
891 stored_supportedGametypes = '0 0 0';
892 stored_supportedFeatures = 0;
893 stored_flags = 0;
894 continue;
895 }
896 }
897
898 s = strreplace("\t", " ", s);
899
900 float p = strstrofs(s, "//", 0);
901 if(p >= 0)
902 s = substring(s, 0, p);
903
904 // perform an initial trim to ensure the first argument is properly obtained
905 // remove leading spaces
906 while(substring(s, 0, 1) == " ")
907 s = substring(s, 1, -1);
908
909 t = car(s); s = cdr(s);
910 t = strtolower(t); // apparently some q3 maps use capitalized parameters
911
912 // remove trailing spaces
913 while(substring(t, -1, 1) == " ")
914 t = substring(t, 0, -2);
915
916 // remove trailing spaces
917 while(substring(s, -1, 1) == " ")
918 s = substring(s, 0, -2);
919 // remove leading spaces
920 while(substring(s, 0, 1) == " ")
921 s = substring(s, 1, -1);
922 // limited support of ""
923 // remove trailing and leading " of s
924 if(substring(s, 0, 1) == "\"")
925 {
926 if(substring(s, -1, 1) == "\"")
927 s = substring(s, 1, -2);
928 }
929 if(t == "longname")
930 stored_Map_title = s;
931 else if(t == "author")
932 stored_Map_author = s;
933 else if(t == "type")
934 {
935 // if there is a valid gametype in this .arena file, include it in the menu
936 stored_supportedFeatures |= MAPINFO_FEATURE_WEAPONS;
937 // type in quake 3 holds all the supported gametypes, so we must loop through all of them
938 // TODO: handle support here better to include more Xonotic teamplay modes
939 string types = s;
940 types = strreplace("team", "tdm ft", types);
941 types = strreplace("ffa", "dm lms ka", types);
942 types = strreplace("tourney", "duel", types); // QL used duel so the following check must support it
943 if(strstrofs(types, "duel", 0) < 0 && strstrofs(types, "tdm", 0) >= 0) // larger team map, support additional gametypes!
944 types = cons(types, "ca kh");
945 FOREACH_WORD(types, true,
946 {
947 Gametype f = MapInfo_Type_FromString(it, false, true);
948 if(f)
949 stored_supportedGametypes |= f.gametype_flags;
950 });
951 }
952 else if(t == "style" && isdefi)
953 {
954 // we have a defrag map on our hands, add CTS!
955 // TODO: styles
956 stored_supportedGametypes |= MAPINFO_TYPE_CTS.gametype_flags;
957 }
958 else if(t == "map")
959 {
960 if(strtolower(s) == strtolower(pFilename))
961 dosave = true; // yay, found our map!
962 }
963 else if(t == "quote")
964 stored_Map_description = s;
965 // TODO: fraglimit
966 }
967
968 // if the map wasn't found in the .arena, fall back to generated .mapinfo
969 return false;
970}
string strtolower(string s)
#define FOREACH_WORD(words, cond, body)
Definition iter.qh:33
#define FOREACH(list, cond, body)
Definition iter.qh:19
#define LOG_INFO(...)
Definition log.qh:65
Gametype MapInfo_Type_FromString(string gtype, bool dowarn, bool is_q3compat)
Definition mapinfo.qc:620
vector MapInfo_Map_supportedGametypes
Definition mapinfo.qh:13
int MapInfo_Map_supportedFeatures
Definition mapinfo.qh:14
string MapInfo_Map_title
Definition mapinfo.qh:7
string MapInfo_Map_author
Definition mapinfo.qh:10
const int MAPINFO_FEATURE_WEAPONS
Definition mapinfo.qh:156
int MapInfo_Map_flags
Definition mapinfo.qh:15
string MapInfo_Map_description
Definition mapinfo.qh:9
vector
Definition self.qh:92
ERASEABLE string cons(string a, string b)
Definition string.qh:276

References car(), cdr(), cons(), fgets(), FOREACH, FOREACH_WORD, LOG_INFO, MAPINFO_FEATURE_WEAPONS, MapInfo_Map_author, MapInfo_Map_description, MapInfo_Map_flags, MapInfo_Map_supportedFeatures, MapInfo_Map_supportedGametypes, MapInfo_Map_title, MapInfo_Type_FromString(), strstrofs, strtolower(), substring(), and vector.

Referenced by _MapInfo_Generate(), and MapInfo_Get_ByName_NoFallbacks().

◆ MapInfo_BSPName_ByID()

string MapInfo_BSPName_ByID ( float i)

◆ MapInfo_Cache_Create()

void MapInfo_Cache_Create ( )

Definition at line 53 of file mapinfo.qc.

54{
59}
#define buf_create
ERASEABLE int db_create()
Definition map.qh:25
int _MapInfo_Cache_DB_NameToIndex
Definition mapinfo.qc:40
void MapInfo_Cache_Destroy()
Definition mapinfo.qc:43
int _MapInfo_Cache_Buf_IndexToMapData
Definition mapinfo.qc:41
int _MapInfo_Cache_Active
Definition mapinfo.qc:39

References _MapInfo_Cache_Active, _MapInfo_Cache_Buf_IndexToMapData, _MapInfo_Cache_DB_NameToIndex, buf_create, db_create(), and MapInfo_Cache_Destroy().

Referenced by MapInfo_Cache_Invalidate(), and preMenuInit().

◆ MapInfo_Cache_Destroy()

void MapInfo_Cache_Destroy ( )

◆ MapInfo_Cache_Invalidate()

void MapInfo_Cache_Invalidate ( )

Definition at line 61 of file mapinfo.qc.

62{
64 return;
65
67}
void MapInfo_Cache_Create()
Definition mapinfo.qc:53

References _MapInfo_Cache_Active, and MapInfo_Cache_Create().

Referenced by MapInfo_Enumerate().

◆ MapInfo_CheckMap()

float MapInfo_CheckMap ( string s)

Definition at line 1502 of file mapinfo.qc.

1503{
1504 float r = _MapInfo_CheckMap(s, false);
1506 return r;
1507}
float _MapInfo_CheckMap(string s, bool gametype_only)
Definition mapinfo.qc:1489
void MapInfo_ClearTemps()
Definition mapinfo.qc:1630

References _MapInfo_CheckMap(), and MapInfo_ClearTemps().

Referenced by DoNextMapOverride(), GenericCommand_maplist(), getmaplist(), GotoMap(), Map_Check(), MapList_LoadMap(), MapVote_AddVotable(), MapVote_Suggest(), and ValidateMap().

◆ MapInfo_ClearTemps()

◆ MapInfo_CurrentFeatures()

int MapInfo_CurrentFeatures ( )

Definition at line 1472 of file mapinfo.qc.

1473{
1474 int req = 0;
1475 // TODO: find a better way to check if weapons are required on the map
1476 if(!(cvar("g_instagib") || cvar("g_overkill") || cvar("g_nix") || cvar("g_weaponarena") || !cvar("g_pickup_items") || !cvar("g_melee_only")
1477 || cvar("g_race") || cvar("g_cts") || cvar("g_nexball") || cvar("g_ca") || cvar("g_freezetag") || cvar("g_lms")))
1479 return req;
1480}
float cvar(string name)

References cvar(), and MAPINFO_FEATURE_WEAPONS.

Referenced by _MapInfo_CheckMap(), GameTypeVote_SetGametype(), GenericCommand_maplist(), GotoFirstMap(), InstantAction_LoadMap(), make_mapinfo_Think(), MapInfo_ListAllAllowedMaps(), MapInfo_ListAllowedMaps(), MapVote_Start(), MapVote_Think(), RestoreGame(), spawnfunc(), spawnfunc(), and XonoticMapList_refilter().

◆ MapInfo_CurrentGametype()

◆ MapInfo_Enumerate()

void MapInfo_Enumerate ( )

◆ MapInfo_FilterGametype()

float MapInfo_FilterGametype ( Gametype gametypeFlags,
float features,
float pFlagsRequired,
float pFlagsForbidden,
float pAbortOnGenerate )

◆ MapInfo_FilterString()

void MapInfo_FilterString ( string sf)

Definition at line 212 of file mapinfo.qc.

213{
214 // this function further filters _MapInfo_filtered, which is prepared by MapInfo_FilterGametype by string
215 float i, j;
216 string title;
217
218 for(i = 0, j = -1; i < MapInfo_count; ++i)
219 {
220 if (MapInfo_Get_ByID(i))
221 {
222 // prepare for keyword filter
223 if (MapInfo_Map_title && strstrofs(MapInfo_Map_title, "<TITLE>", 0) == -1)
224 title = MapInfo_Map_title;
225 else
226 title = MapInfo_Map_bspname;
227 // keyword filter
228 if((strstrofs(strtolower(title), strtolower(sf), 0)) >= 0)
229 bufstr_set(_MapInfo_filtered, ++j, bufstr_get(_MapInfo_filtered, i));
230 }
231 }
232 MapInfo_count = j + 1;
234
235 // sometimes the glob isn't sorted nicely, so fix it here...
237}
bool MapInfo_Get_ByID(int i)
Definition mapinfo.qc:274
void _MapInfo_FilterList_swap(float i, float j, entity pass)
Definition mapinfo.qc:161
float _MapInfo_FilterList_cmp(float i, float j, entity pass)
Definition mapinfo.qc:168
float _MapInfo_filtered
Definition mapinfo.qc:154
float MapInfo_count
Definition mapinfo.qh:166
#define NULL
Definition post.qh:14
ERASEABLE void heapsort(int n, swapfunc_t swap, comparefunc_t cmp, entity pass)
Definition sort.qh:9

References _MapInfo_filtered, _MapInfo_FilterList_cmp(), _MapInfo_FilterList_swap(), heapsort(), MapInfo_ClearTemps(), MapInfo_count, MapInfo_Get_ByID(), MapInfo_Map_bspname, MapInfo_Map_title, NULL, strstrofs, and strtolower().

Referenced by XonoticMapList_refilter().

◆ MapInfo_FindName()

float MapInfo_FindName ( string s)

Definition at line 1418 of file mapinfo.qc.

1419{
1420 // if there is exactly one map of prefix s, return it
1421 // if not, return the null string
1422 // note that DP sorts glob results... so I can use a binary search
1423 float l, r, m, cmp;
1424 l = 0;
1425 r = MapInfo_count;
1426 // invariants: r is behind s, l-1 is equal or before
1427 while(l != r)
1428 {
1429 m = floor((l + r) / 2);
1432 if(cmp == 0)
1433 return m; // found and good
1434 if(cmp < 0)
1435 l = m + 1; // l-1 is before s
1436 else
1437 r = m; // behind s
1438 }
1441 // r == l, so: l is behind s, l-1 is before
1442 // SO: if there is any, l is the one with the right prefix
1443 // and l+1 may be one too
1444 if(l == MapInfo_count)
1445 {
1448 return -1; // no MapInfo_FindName_match, behind last item
1449 }
1451 {
1454 return -1; // wrong prefix
1455 }
1456 if(l == MapInfo_count - 1)
1457 return l; // last one, nothing can follow => unique
1459 {
1461 return -1; // ambigous MapInfo_FindName_match
1462 }
1463 return l;
1464}
#define strcasecmp
string MapInfo_FindName_match
Definition mapinfo.qh:195
float MapInfo_FindName_firstResult
Definition mapinfo.qh:196
float floor(float f)
ERASEABLE bool startsWithNocase(string haystack, string needle)
Definition string.qh:239

References _MapInfo_GlobItem(), floor(), MapInfo_count, MapInfo_FilterList_Lookup(), MapInfo_FindName_firstResult, MapInfo_FindName_match, startsWithNocase(), strcasecmp, and string_null.

Referenced by MapInfo_FixName(), XonoticMapList_keyDown(), and XonoticMapList_refilter().

◆ MapInfo_FixName()

string MapInfo_FixName ( string s)

Definition at line 1466 of file mapinfo.qc.

1467{
1470}
float MapInfo_FindName(string s)
Definition mapinfo.qc:1418

References MapInfo_FindName(), and MapInfo_FindName_match.

Referenced by GameTypeVote_MapInfo_FixName(), and ValidateMap().

◆ MapInfo_ForbiddenFlags()

int MapInfo_ForbiddenFlags ( )

Definition at line 1655 of file mapinfo.qc.

1656{
1657 int f = MAPINFO_FLAG_FORBIDDEN;
1658
1659#ifdef GAMEQC
1660 if (!cvar("g_maplist_allow_hidden"))
1661#endif
1663
1664 if (!cvar("g_maplist_allow_frustrating"))
1666
1667 return f;
1668}
const int MAPINFO_FLAG_FORBIDDEN
Definition mapinfo.qh:162
const int MAPINFO_FLAG_HIDDEN
Definition mapinfo.qh:161
const int MAPINFO_FLAG_FRUSTRATING
Definition mapinfo.qh:163

References cvar(), MAPINFO_FLAG_FORBIDDEN, MAPINFO_FLAG_FRUSTRATING, and MAPINFO_FLAG_HIDDEN.

Referenced by GameTypeVote_MapInfo_FixName(), GameTypeVote_SetGametype(), GenericCommand_maplist(), getlsmaps(), GotoFirstMap(), InstantAction_LoadMap(), make_mapinfo_Think(), MapList_Add_All(), Maplist_Init(), MapVote_Start(), MapVote_Think(), RestoreGame(), spawnfunc(), spawnfunc(), and XonoticMapList_refilter().

◆ MapInfo_Get_ByID()

bool MapInfo_Get_ByID ( int i)

Definition at line 274 of file mapinfo.qc.

275{
276 return MapInfo_Get_ByName(MapInfo_BSPName_ByID(i), 0, NULL) ? true : false;
277}
#define true
Definition csprogsdefs.qh:5
string MapInfo_BSPName_ByID(float i)
Definition mapinfo.qc:249
int MapInfo_Get_ByName(string pFilename, float pAllowGenerate, Gametype pGametypeToSet)
Definition mapinfo.qc:1382

References MapInfo_BSPName_ByID(), MapInfo_Get_ByName(), NULL, and true.

Referenced by getladder(), getlsmaps(), MapInfo_FilterString(), MUTATOR_HOOKFUNCTION(), MUTATOR_HOOKFUNCTION(), MUTATOR_HOOKFUNCTION(), XonoticMapInfoDialog_loadMapInfo(), and XonoticMapList_drawListBoxItem().

◆ MapInfo_Get_ByName()

int MapInfo_Get_ByName ( string s,
float allowGenerate,
Gametype gametypeToSet )

Definition at line 1382 of file mapinfo.qc.

1383{
1384 int r = MapInfo_Get_ByName_NoFallbacks(pFilename, pAllowGenerate, pGametypeToSet);
1385
1386 FOREACH(Gametypes, it.m_isForcedSupported(it), _MapInfo_Map_ApplyGametypeEx("", pGametypeToSet, it));
1387
1388 if(pGametypeToSet)
1389 {
1390 if(!(MapInfo_Map_supportedGametypes & pGametypeToSet.gametype_flags))
1391 {
1392 error("Can't select the requested gametype. This should never happen as the caller should prevent it!\n");
1393 //_MapInfo_Map_ApplyGametypeEx("", pGametypeToSet, MAPINFO_TYPE_DEATHMATCH);
1394 //return;
1395 }
1396 }
1397
1398 return r;
1399}
void _MapInfo_Map_ApplyGametypeEx(string s, Gametype pWantedType, Gametype pThisType)
Definition mapinfo.qc:543
float MapInfo_Get_ByName_NoFallbacks(string pFilename, int pAllowGenerate, Gametype pGametypeToSet)
Definition mapinfo.qc:1035
#define error
Definition pre.qh:6

References _MapInfo_Map_ApplyGametypeEx(), error, FOREACH, MapInfo_Get_ByName_NoFallbacks(), and MapInfo_Map_supportedGametypes.

Referenced by _MapInfo_CheckMap(), _MapInfo_FilterGametype(), GameTypeVote_AvailabilityStatus(), get_mi_min_max(), MapInfo_Get_ByID(), MapInfo_LoadMapSettings(), and SendWelcomeMessage().

◆ MapInfo_ListAllAllowedMaps()

string MapInfo_ListAllAllowedMaps ( float pFlagsRequired,
float pFlagsForbidden )

Definition at line 1547 of file mapinfo.qc.

1548{
1549 string out;
1550
1551 // to make absolutely sure:
1553 _MapInfo_FilterGametype(MAPINFO_TYPE_ALL, 0, pRequiredFlags, pForbiddenFlags, 0);
1554
1555 out = "";
1556 for(float i = 0; i < MapInfo_count; ++i)
1558
1559 MapInfo_FilterGametype(MapInfo_CurrentGametype(), MapInfo_CurrentFeatures(), pRequiredFlags, pForbiddenFlags, 0);
1560
1561 return substring(out, 1, strlen(out) - 1);
1562}
#define strlen
float MapInfo_FilterGametype(Gametype pGametype, int pFeatures, int pFlagsRequired, int pFlagsForbidden, bool pAbortOnGenerate)
Definition mapinfo.qc:176
float _MapInfo_FilterGametype(vector pGametype, int pFeatures, int pFlagsRequired, int pFlagsForbidden, bool pAbortOnGenerate)
Definition mapinfo.qc:180
Gametype MapInfo_CurrentGametype()
Definition mapinfo.qc:1482
int MapInfo_CurrentFeatures()
Definition mapinfo.qc:1472
void MapInfo_Enumerate()
Definition mapinfo.qc:134
vector MAPINFO_TYPE_ALL
Definition mapinfo.qh:27

References _MapInfo_FilterGametype(), _MapInfo_GlobItem(), MapInfo_count, MapInfo_CurrentFeatures(), MapInfo_CurrentGametype(), MapInfo_Enumerate(), MapInfo_FilterGametype(), MapInfo_FilterList_Lookup(), MAPINFO_TYPE_ALL, strcat(), strlen, and substring().

◆ MapInfo_ListAllowedMaps()

string MapInfo_ListAllowedMaps ( Gametype type,
float pFlagsRequired,
float pFlagsForbidden )

Definition at line 1533 of file mapinfo.qc.

1534{
1535 string out;
1536
1537 // to make absolutely sure:
1539 MapInfo_FilterGametype(type, MapInfo_CurrentFeatures(), pRequiredFlags, pForbiddenFlags, 0);
1540
1541 out = "";
1542 for(float i = 0; i < MapInfo_count; ++i)
1544 return substring(out, 1, strlen(out) - 1);
1545}

References _MapInfo_GlobItem(), MapInfo_count, MapInfo_CurrentFeatures(), MapInfo_Enumerate(), MapInfo_FilterGametype(), MapInfo_FilterList_Lookup(), strcat(), strlen, and substring().

Referenced by GameTypeVote_SetGametype(), and Maplist_Init().

◆ MapInfo_LoadMap()

void MapInfo_LoadMap ( string s,
float reinit )

Definition at line 1514 of file mapinfo.qc.

1515{
1517 // we shouldn't need this, as LoadMapSettings already fixes the gametype
1518 //if(!MapInfo_CheckMap(s))
1519 //{
1520 // print("EMERGENCY: can't play the selected map in the given gametype. Falling back to DM.\n");
1521 // MapInfo_SwitchGameType(MAPINFO_TYPE_DEATHMATCH.gametype_flags);
1522 //}
1523
1524 LOG_INFO("Switching to map ", s);
1525
1527 if(reinit)
1528 localcmd(strcat("\nmap ", s, "\n"));
1529 else
1530 localcmd(strcat("\nchangelevel ", s, "\n"));
1531}
int cvar_settemp_restore()
Definition util.qc:845
void localcmd(string command,...)

References cvar_settemp_restore(), localcmd(), LOG_INFO, MapInfo_Map_supportedGametypes, and strcat().

Referenced by CampaignSetup(), InstantAction_LoadMap(), Map_Goto(), and MapList_LoadMap().

◆ MapInfo_LoadMapSettings()

void MapInfo_LoadMapSettings ( string s)

Definition at line 1571 of file mapinfo.qc.

1572{
1575
1576 if(!_MapInfo_CheckMap(s, true)) // with underscore, it keeps temps
1577 {
1578 if(cvar("g_mapinfo_allow_unsupported_modes_and_let_stuff_break"))
1579 {
1580 LOG_SEVERE("can't play the selected map in the given gametype. Working with only the override settings.");
1582 return; // do not call Get_ByName!
1583 }
1584
1585 if(MapInfo_Map_supportedGametypes == '0 0 0')
1586 {
1588 FOREACH(Gametypes, it.m_priority == 2,
1589 {
1590 MapInfo_Map_supportedGametypes |= it.gametype_flags;
1591 RandomSelection_AddEnt(it, 1, 1);
1592 });
1595 LOG_SEVEREF("Mapinfo system is not functional at all. Falling back to a preferred mode (%s).", t.mdl);
1598 return; // do not call Get_ByName!
1599 }
1600
1601#if 0
1602 // find the lowest bit in the supported gametypes
1603 // unnecessary now that we select one at random
1604 int _t = 1;
1605 while(!(MapInfo_Map_supportedGametypes & 1))
1606 {
1607 _t <<= 1;
1609 }
1610#endif
1612 Gametype t_prev = t;
1613 FOREACH(Gametypes, MapInfo_Map_supportedGametypes & it.gametype_flags,
1614 {
1615 RandomSelection_AddEnt(it, 1, it.m_priority);
1616 });
1619
1620 // t is now a supported mode!
1621 LOG_WARNF("can't play the selected map in the given gametype (%s). Falling back to a supported mode (%s).", t_prev.mdl, t.mdl);
1623 }
1624 if(!_MapInfo_CheckMap(s, false)) { // with underscore, it keeps temps
1625 LOG_WARNF("the selected map lacks features required by current settings; playing anyway.");
1626 }
1627 MapInfo_Get_ByName(s, 1, t);
1628}
#define LOG_WARNF(...)
Definition log.qh:62
#define LOG_SEVEREF(...)
Definition log.qh:58
#define LOG_SEVERE(...)
Definition log.qh:57
void MapInfo_LoadMapSettings_SaveGameType(Gametype t)
Definition mapinfo.qc:1564
ERASEABLE void RandomSelection_Init()
Definition random.qc:4
entity RandomSelection_chosen_ent
Definition random.qh:5

References _MapInfo_CheckMap(), _MapInfo_Map_ApplyGametypeEx(), cvar(), floor(), FOREACH, LOG_SEVERE, LOG_SEVEREF, LOG_WARNF, MapInfo_CurrentGametype(), MapInfo_Get_ByName(), MapInfo_LoadMapSettings_SaveGameType(), MapInfo_Map_supportedGametypes, RandomSelection_chosen_ent, and RandomSelection_Init().

Referenced by InitGameplayMode().

◆ MapInfo_RequiredFlags()

int MapInfo_RequiredFlags ( )

◆ MapInfo_Shutdown()

◆ MapInfo_SwitchGameType()

void MapInfo_SwitchGameType ( Gametype t)

Definition at line 1509 of file mapinfo.qc.

1510{
1511 FOREACH(Gametypes, true, cvar_set(it.netname, (it == t) ? "1" : "0"));
1512}
void cvar_set(string name, string value)

References cvar_set(), and FOREACH.

Referenced by CampaignPreInit(), GameTypeVote_SetGametype(), InstantAction_LoadMap(), MapInfo_LoadMapSettings_SaveGameType(), target_changelevel_use(), and XonoticGametypeList_saveCvars().

◆ MapInfo_Type_Description()

string MapInfo_Type_Description ( Gametype t)

Definition at line 650 of file mapinfo.qc.

651{
652 return t ? t.m_description : "";
653}

Referenced by GameTypeVote_ReadOption(), and XonoticGametypeList_focusedItemChangeNotify().

◆ MapInfo_Type_FromString()

Gametype MapInfo_Type_FromString ( string t,
bool dowarn,
bool is_q3compat )

Definition at line 620 of file mapinfo.qc.

621{
622 string replacement = "";
623
624 switch (gtype)
625 {
626 case "nexball": replacement = "nb"; break;
627 case "freezetag": replacement = "ft"; break;
628 case "keepaway": replacement = "ka"; break;
629 case "invasion": replacement = "inv"; break;
630 case "assault": replacement = "as"; break;
631 case "race": replacement = "rc"; break;
632 // Q3/QL compat, see DoesQ3ARemoveThisEntity() in quake3.qc for complete lists
633 case "ffa": replacement = "dm"; break;
634 case "cctf": // from ThreeWave, maps with this should all have "ctf" too
635 case "oneflag": replacement = "ctf"; break;
636 case "tourney": replacement = "duel"; break;
637 case "arena": // which Q3 mod is this from? In Nexuiz it was 'duel with rounds'.
638 if(is_q3compat) { replacement = "ca"; } break;
639 }
640 if (replacement != "")
641 {
642 if (dowarn && WARN_COND)
643 LOG_WARNF("MapInfo_Type_FromString (probably %s): using deprecated name '%s'. Should use '%s'.", MapInfo_Map_bspname, gtype, replacement);
644 gtype = replacement;
645 }
646 FOREACH(Gametypes, it.mdl == gtype, return it);
647 return NULL;
648}

References FOREACH, LOG_WARNF, MapInfo_Map_bspname, NULL, and WARN_COND.

Referenced by _MapInfo_ParseArena(), Campaign_Invalid(), CampaignPreInit(), GameCommand_gametype(), GameTypeVote_AvailabilityStatus(), GameTypeVote_ReadOption(), GameTypeVote_Type_FromString(), MapInfo_CurrentGametype(), MapInfo_Get_ByName_NoFallbacks(), target_changelevel_use(), and XonoticServerInfoDialog_loadServerInfo().

◆ MapInfo_Type_ToString()

◆ MapInfo_Type_ToText()

◆ MapReadSizes()

bool MapReadSizes ( string map)

Definition at line 1401 of file mapinfo.qc.

1402{
1403 // TODO: implement xonotic#28 / xonvote 172 (sizes in mapinfo)
1404 string readsize_msg = strcat("MapReadSizes ", map);
1405 float fh = fopen(strcat("maps/", map, ".sizes"), FILE_READ);
1406 if(fh >= 0)
1407 {
1408 map_minplayers = stoi(fgets(fh));
1409 map_maxplayers = stoi(fgets(fh));
1410 fclose(fh);
1411 LOG_TRACEF(readsize_msg, ": ok, min %d max %d", map_minplayers, map_maxplayers);
1412 return true;
1413 }
1414 LOG_TRACE(readsize_msg, ": not found");
1415 return false;
1416}
#define stoi(s)
Definition int.qh:4
#define LOG_TRACEF(...)
Definition log.qh:77
int map_minplayers
Definition mapinfo.qh:190
int map_maxplayers
Definition mapinfo.qh:191

References fclose(), fgets(), FILE_READ, fopen(), LOG_TRACE, LOG_TRACEF, map_maxplayers, map_minplayers, stoi, and strcat().

Referenced by GameplayMode_DelayedInit(), and MapHasRightSize().

◆ STATIC_INIT()

STATIC_INIT ( Gametypes_renumber )

Definition at line 140 of file mapinfo.qh.

141{
142 FOREACH(Gametypes, true,
143 {
144 it.m_id = i;
145 vector set = it.gametype_flags = _GametypeFlags_FromGametype(it.m_id);
146 MAPINFO_TYPE_ALL |= set;
147 });
148}
vector _GametypeFlags_FromGametype(int a)
Definition mapinfo.qc:20

References _GametypeFlags_FromGametype(), FOREACH, MAPINFO_TYPE_ALL, STATIC_INIT, and vector.

Variable Documentation

◆ GAMETYPE_FLAG_1V1

const int GAMETYPE_FLAG_1V1 = BIT(6)

Definition at line 25 of file mapinfo.qh.

Referenced by Duel::Duel(), and Gametype::gametype_init().

◆ GAMETYPE_FLAG_HIDELIMITS

const int GAMETYPE_FLAG_HIDELIMITS = BIT(4)

Definition at line 23 of file mapinfo.qh.

Referenced by LastManStanding::LastManStanding(), and Gametype::gametype_init().

◆ GAMETYPE_FLAG_PREFERRED

const int GAMETYPE_FLAG_PREFERRED = BIT(2)

Definition at line 21 of file mapinfo.qh.

Referenced by Deathmatch::Deathmatch(), and Gametype::gametype_init().

◆ GAMETYPE_FLAG_PRIORITY

const int GAMETYPE_FLAG_PRIORITY = BIT(3)

◆ GAMETYPE_FLAG_TEAMPLAY

◆ GAMETYPE_FLAG_USEPOINTS

◆ GAMETYPE_FLAG_WEAPONARENA

const int GAMETYPE_FLAG_WEAPONARENA = BIT(5)

Definition at line 24 of file mapinfo.qh.

Referenced by NexBall::NexBall(), and Gametype::gametype_init().

◆ gametype_flags

◆ map_maxplayers

int map_maxplayers

◆ map_minplayers

int map_minplayers

◆ MapInfo_count

◆ MAPINFO_FEATURE_MONSTERS

const int MAPINFO_FEATURE_MONSTERS = 8

Definition at line 159 of file mapinfo.qh.

Referenced by _MapInfo_Generate(), and MapInfo_Get_ByName_NoFallbacks().

◆ MAPINFO_FEATURE_TURRETS

const int MAPINFO_FEATURE_TURRETS = 4

Definition at line 158 of file mapinfo.qh.

Referenced by _MapInfo_Generate(), and MapInfo_Get_ByName_NoFallbacks().

◆ MAPINFO_FEATURE_VEHICLES

const int MAPINFO_FEATURE_VEHICLES = 2

Definition at line 157 of file mapinfo.qh.

Referenced by _MapInfo_Generate(), and MapInfo_Get_ByName_NoFallbacks().

◆ MAPINFO_FEATURE_WEAPONS

const int MAPINFO_FEATURE_WEAPONS = 1

◆ MapInfo_FindName_firstResult

float MapInfo_FindName_firstResult

Definition at line 196 of file mapinfo.qh.

Referenced by MapInfo_FindName(), and XonoticMapList_keyDown().

◆ MapInfo_FindName_match

string MapInfo_FindName_match

Definition at line 195 of file mapinfo.qh.

Referenced by MapInfo_FindName(), and MapInfo_FixName().

◆ MAPINFO_FLAG_DONOTWANT

const int MAPINFO_FLAG_DONOTWANT = 8

Definition at line 164 of file mapinfo.qh.

Referenced by Map_Check(), and MapInfo_Get_ByName_NoFallbacks().

◆ MAPINFO_FLAG_FORBIDDEN

const int MAPINFO_FLAG_FORBIDDEN = 2

Definition at line 162 of file mapinfo.qh.

Referenced by MapInfo_ForbiddenFlags(), and MapInfo_Get_ByName_NoFallbacks().

◆ MAPINFO_FLAG_FRUSTRATING

const int MAPINFO_FLAG_FRUSTRATING = 4

◆ MAPINFO_FLAG_HIDDEN

const int MAPINFO_FLAG_HIDDEN = 1

Definition at line 161 of file mapinfo.qh.

Referenced by MapInfo_ForbiddenFlags(), and MapInfo_Get_ByName_NoFallbacks().

◆ MapInfo_LoadedGametype

◆ MapInfo_Map_author

◆ MapInfo_Map_bspname

◆ MapInfo_Map_clientstuff

◆ MapInfo_Map_description

◆ MapInfo_Map_flags

◆ MapInfo_Map_fog

string MapInfo_Map_fog

Definition at line 12 of file mapinfo.qh.

Referenced by _MapInfo_Map_Reset(), InitGameplayMode(), and MapInfo_Get_ByName_NoFallbacks().

◆ MapInfo_Map_maxs

vector MapInfo_Map_maxs

Definition at line 17 of file mapinfo.qh.

Referenced by _MapInfo_Map_Reset(), get_mi_min_max(), and MapInfo_Get_ByName_NoFallbacks().

◆ MapInfo_Map_mins

vector MapInfo_Map_mins

Definition at line 16 of file mapinfo.qh.

Referenced by _MapInfo_Map_Reset(), get_mi_min_max(), and MapInfo_Get_ByName_NoFallbacks().

◆ MapInfo_Map_supportedFeatures

◆ MapInfo_Map_supportedGametypes

◆ MapInfo_Map_title

◆ MapInfo_Map_titlestring

◆ MapInfo_progress

float MapInfo_progress

Definition at line 173 of file mapinfo.qh.

Referenced by _MapInfo_FilterGametype(), and preMenuInit().

◆ MAPINFO_TYPE_ALL