]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/common/mapinfo.qh
Add a mutator hook to control whether the race timer HUD panel is shown
[xonotic/xonotic-data.pk3dir.git] / qcsrc / common / mapinfo.qh
1 #pragma once
2
3 #include "util.qh"
4
5 // info about a map that MapInfo loads
6 string MapInfo_Map_bspname;
7 string MapInfo_Map_title;
8 string MapInfo_Map_titlestring; // either bspname: title or just title, depending on whether bspname is redundant
9 string MapInfo_Map_description;
10 string MapInfo_Map_author;
11 string MapInfo_Map_clientstuff; // not in cache, only for map load
12 string MapInfo_Map_fog; // not in cache, only for map load
13 int MapInfo_Map_supportedGametypes;
14 int MapInfo_Map_supportedFeatures;
15 int MapInfo_Map_flags;
16 vector MapInfo_Map_mins; // these are '0 0 0' if not supported!
17 vector MapInfo_Map_maxs; // these are '0 0 0' if not specified!
18
19 const int GAMETYPE_FLAG_TEAMPLAY        = BIT(0); // teamplay based
20 const int GAMETYPE_FLAG_USEPOINTS       = BIT(1); // gametype has point-based scoring
21 const int GAMETYPE_FLAG_PREFERRED       = BIT(2); // preferred (when available) in random selections
22 const int GAMETYPE_FLAG_PRIORITY        = BIT(3); // priority selection when preferred gametype isn't available in random selections
23
24 int MAPINFO_TYPE_ALL;
25 .int m_flags;
26
27 CLASS(Gametype, Object)
28     ATTRIB(Gametype, m_id, int, 0);
29     /** game type ID */
30     ATTRIB(Gametype, items, int, 0);
31     /** game type name as in cvar (with g_ prefix) */
32     ATTRIB(Gametype, netname, string);
33     /** game type short name */
34     ATTRIB(Gametype, mdl, string);
35     /** human readable name */
36     ATTRIB(Gametype, message, string);
37     /** does this gametype support teamplay? */
38     ATTRIB(Gametype, team, bool, false);
39     /** does this gametype use a point limit? */
40     ATTRIB(Gametype, frags, bool, true);
41     /** game type defaults */
42     ATTRIB(Gametype, model2, string);
43     /** game type description */
44     ATTRIB(Gametype, gametype_description, string);
45     /** game type priority in random selections */
46     ATTRIB(Gametype, m_priority, int, 0);
47 #ifdef CSQC
48     ATTRIB(Gametype, m_modicons, void(vector pos, vector mySize));
49     ATTRIB(Gametype, m_modicons_reset, void());
50     ATTRIB(Gametype, m_modicons_export, void(int fh));
51 #endif
52
53     /** DO NOT USE, this is compatibility for legacy maps! */
54     ATTRIB(Gametype, m_legacydefaults, string, "");
55
56     ATTRIB(Gametype, m_mutators, string);
57     METHOD(Gametype, m_parse_mapinfo, bool(string k, string v))
58     {
59         return false;
60     }
61     METHOD(Gametype, m_generate_mapinfo, void(Gametype this, string v))
62     {
63         TC(Gametype, this);
64     }
65     METHOD(Gametype, m_isTwoBaseMode, bool())
66     {
67         return false;
68     }
69     METHOD(Gametype, m_isAlwaysSupported, bool(Gametype this, int spawnpoints, float diameter))
70     {
71         return false;
72     }
73     METHOD(Gametype, m_isForcedSupported, bool(Gametype this))
74     {
75         return false;
76     }
77     METHOD(Gametype, m_configuremenu, void(Gametype this, entity menu, void(entity me, string pLabel, float pMin, float pMax, float pStep, string pCvar, string tCvar, string pTooltip) returns))
78     {
79         TC(Gametype, this);
80         returns(menu, _("Frag limit:"),      5,  100,  5, "fraglimit_override",        string_null,                    _("The amount of frags needed before the match will end"));
81     }
82
83     METHOD(Gametype, describe, string(Gametype this))
84     {
85         TC(Gametype, this);
86         return this.gametype_description;
87     }
88
89     METHOD(Gametype, display, void(Gametype this, void(string name, string icon) returns))
90     {
91         TC(Gametype, this);
92         returns(this.message, strcat("gametype_", this.mdl));
93     }
94
95     METHOD(Gametype, gametype_init, void(Gametype this, string hname, string sname, string g_name, int gflags, string mutators, string defaults, string gdescription))
96     {
97         this.netname = g_name;
98         this.mdl = sname;
99         this.message = hname;
100         this.team = (gflags & GAMETYPE_FLAG_TEAMPLAY);
101         this.m_mutators = cons(sname, mutators);
102         this.model2 = defaults;
103         this.gametype_description = gdescription;
104         this.frags = (gflags & GAMETYPE_FLAG_USEPOINTS);
105         this.m_priority = ((gflags & GAMETYPE_FLAG_PREFERRED) ? 2 : ((gflags & GAMETYPE_FLAG_PRIORITY) ? 1 : 0));
106
107         // same as `1 << m_id`
108         MAPINFO_TYPE_ALL |= this.items = this.m_flags = (MAPINFO_TYPE_ALL + 1);
109     }
110 ENDCLASS(Gametype)
111
112 REGISTRY(Gametypes, 24)
113 REGISTER_REGISTRY(Gametypes)
114 REGISTRY_SORT(Gametypes);
115 REGISTRY_CHECK(Gametypes)
116
117 REGISTRY_DEFINE_GET(Gametypes, NULL)
118 #define REGISTER_GAMETYPE(NAME, inst) REGISTER(Gametypes, MAPINFO_TYPE, NAME, m_id, inst)
119
120 #define IS_GAMETYPE(NAME) (MapInfo_LoadedGametype == MAPINFO_TYPE_##NAME)
121
122 const int MAPINFO_FEATURE_WEAPONS       = 1; // not defined for instagib-only maps
123 const int MAPINFO_FEATURE_VEHICLES      = 2;
124 const int MAPINFO_FEATURE_TURRETS       = 4;
125 const int MAPINFO_FEATURE_MONSTERS      = 8;
126
127 const int MAPINFO_FLAG_HIDDEN           = 1; // not in lsmaps/menu/vcall/etc., can just be changed to manually
128 const int MAPINFO_FLAG_FORBIDDEN        = 2; // don't even allow the map by a cvar setting that allows hidden maps
129 const int MAPINFO_FLAG_FRUSTRATING      = 4; // this map is near impossible to play, enable at your own risk
130 const int MAPINFO_FLAG_NOAUTOMAPLIST    = 8; // do not include when automatically building maplist (counts as hidden for maplist building purposes)
131
132 float MapInfo_count;
133
134 // load MapInfo_count; generate mapinfo for maps that miss them, and clear the
135 // cache; you need to call MapInfo_FilterGametype afterwards!
136 void MapInfo_Enumerate();
137
138 // filter the info by game type mask (updates MapInfo_count)
139 float MapInfo_progress;
140 float MapInfo_FilterGametype(Gametype gametypeFlags, float features, float pFlagsRequired, float pFlagsForbidden, float pAbortOnGenerate); // 1 on success, 0 on temporary failure (call it again next frame then; use MapInfo_progress as progress indicator)
141 float _MapInfo_FilterGametype(int gametypeFlags, float features, float pFlagsRequired, float pFlagsForbidden, float pAbortOnGenerate); // 1 on success, 0 on temporary failure (call it again next frame then; use MapInfo_progress as progress indicator)
142 void MapInfo_FilterString(string sf); // filter _MapInfo_filtered (created by MapInfo_FilterGametype) with keyword
143 int MapInfo_CurrentFeatures(); // retrieves currently required features from cvars
144 Gametype MapInfo_CurrentGametype(); // retrieves current gametype from cvars
145 int MapInfo_ForbiddenFlags(); // retrieves current flags from cvars
146 int MapInfo_RequiredFlags(); // retrieves current flags from cvars
147
148 // load info about the i-th map into the MapInfo_Map_* globals
149 float MapInfo_Get_ByID(float i); // 1 on success, 0 on failure
150 string MapInfo_BSPName_ByID(float i);
151
152 // load info about a map by name into the MapInfo_Map_* globals
153 int MapInfo_Get_ByName(string s, float allowGenerate, Gametype gametypeToSet); // 1 on success, 0 on failure, 2 if it autogenerated a mapinfo file
154
155 // look for a map by a prefix, returns the actual map name on success, string_null on failure or ambigous match
156 string MapInfo_FindName_match; // the name of the map that was found
157 float MapInfo_FindName_firstResult; // -1 if none were found, index of first one if not unique but found (FindName then returns -1)
158 float MapInfo_FindName(string s);
159 string MapInfo_FixName(string s);
160
161 // play a map
162 float MapInfo_CheckMap(string s); // returns 0 if the map can't be played with the current settings
163 void MapInfo_LoadMap(string s, float reinit);
164
165 // list all maps for the current game type
166 string MapInfo_ListAllowedMaps(Gametype type, float pFlagsRequired, float pFlagsForbidden);
167 // list all allowed maps (for any game type)
168 string MapInfo_ListAllAllowedMaps(float pFlagsRequired, float pFlagsForbidden);
169
170 // gets a gametype from a string
171 string _MapInfo_GetDefaultEx(Gametype t);
172 float _MapInfo_GetTeamPlayBool(Gametype t);
173 Gametype MapInfo_Type_FromString(string t);
174 string MapInfo_Type_Description(Gametype t);
175 string MapInfo_Type_ToString(Gametype t);
176 string MapInfo_Type_ToText(Gametype t);
177 void MapInfo_SwitchGameType(Gametype t);
178
179 // to be called from worldspawn to set up cvars
180 void MapInfo_LoadMapSettings(string s);
181 Gametype MapInfo_LoadedGametype; // game type that was active during map load
182
183 void MapInfo_Cache_Destroy(); // disable caching
184 void MapInfo_Cache_Create(); // enable caching
185 void MapInfo_Cache_Invalidate(); // delete cache if any, but keep enabled
186
187 void _MapInfo_Parse_Settemp(string pFilename, string acl, float type, string s, float recurse);
188
189 void MapInfo_ClearTemps(); // call this when done with mapinfo for this frame
190
191 void MapInfo_Shutdown(); // call this in the shutdown handler
192
193 #define MAPINFO_SETTEMP_ACL_USER cvar_string("g_mapinfo_settemp_acl")
194 #define MAPINFO_SETTEMP_ACL_SYSTEM "-g_mapinfo_* -rcon_* -_* -g_ban* +*"