]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/common/mapinfo.qh
4d65695ae41a9391d19b1f145440c1942bfc5e70
[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 const int GAMETYPE_FLAG_HIDELIMITS      = BIT(4); // don't display a score limit needed for winning the match in the scoreboard
24 const int GAMETYPE_FLAG_WEAPONARENA     = BIT(5); // gametype has a forced weapon arena, weapon arena mutators should disable themselves when this is set
25 const int GAMETYPE_FLAG_1V1             = BIT(6); // 1v1 gameplay
26
27 int MAPINFO_TYPE_ALL;
28 .int m_flags;
29
30 CLASS(Gametype, Object)
31     ATTRIB(Gametype, m_id, int, 0);
32     /** game type ID */
33     ATTRIB(Gametype, items, int, 0);
34     /** game type name as in cvar (with g_ prefix) */
35     ATTRIB(Gametype, netname, string);
36     /** game type short name */
37     ATTRIB(Gametype, mdl, string);
38     /** human readable name */
39     ATTRIB(Gametype, message, string);
40     /** does this gametype support teamplay? */
41     ATTRIB(Gametype, team, bool, false);
42     /** does this gametype use a point limit? */
43     ATTRIB(Gametype, frags, bool, true);
44     /** should this gametype display a score limit in the scoreboard? */
45     ATTRIB(Gametype, m_hidelimits, bool, false);
46     /** does this gametype enforce its own weapon arena? */
47     ATTRIB(Gametype, m_weaponarena, bool, false);
48     /** 1v1 gameplay? */
49     ATTRIB(Gametype, m_1v1, bool, false);
50     /** game type defaults */
51     ATTRIB(Gametype, model2, string);
52     /** game type description */
53     ATTRIB(Gametype, gametype_description, string);
54     /** game type priority in random selections */
55     ATTRIB(Gametype, m_priority, int, 0);
56 #ifdef CSQC
57     ATTRIB(Gametype, m_modicons, void(vector pos, vector mySize));
58     ATTRIB(Gametype, m_modicons_reset, void());
59     ATTRIB(Gametype, m_modicons_export, void(int fh));
60 #endif
61
62     /** DO NOT USE, this is compatibility for legacy maps! */
63     ATTRIB(Gametype, m_legacydefaults, string, "");
64
65     ATTRIB(Gametype, m_mutators, string);
66     METHOD(Gametype, m_parse_mapinfo, bool(string k, string v))
67     {
68         return false;
69     }
70     METHOD(Gametype, m_generate_mapinfo, void(Gametype this, string v))
71     {
72         TC(Gametype, this);
73     }
74     METHOD(Gametype, m_isTwoBaseMode, bool())
75     {
76         return false;
77     }
78     METHOD(Gametype, m_isAlwaysSupported, bool(Gametype this, int spawnpoints, float diameter))
79     {
80         return false;
81     }
82     METHOD(Gametype, m_isForcedSupported, bool(Gametype this))
83     {
84         return false;
85     }
86     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))
87     {
88         TC(Gametype, this);
89         returns(menu, _("Frag limit:"),      5,  100,  5, "fraglimit_override",        string_null,                    _("The amount of frags needed before the match will end"));
90     }
91
92     METHOD(Gametype, describe, string(Gametype this))
93     {
94         TC(Gametype, this);
95         return this.gametype_description;
96     }
97
98     METHOD(Gametype, display, void(Gametype this, void(string name, string icon) returns))
99     {
100         TC(Gametype, this);
101         returns(this.message, strcat("gametype_", this.mdl));
102     }
103
104     METHOD(Gametype, gametype_init, void(Gametype this, string hname, string sname, string g_name, int gflags, string mutators, string defaults, string gdescription))
105     {
106         this.netname = g_name;
107         this.mdl = sname;
108         this.message = hname;
109         this.team = (gflags & GAMETYPE_FLAG_TEAMPLAY);
110         this.m_mutators = cons(sname, mutators);
111         this.model2 = defaults;
112         this.gametype_description = gdescription;
113         this.frags = (gflags & GAMETYPE_FLAG_USEPOINTS);
114         this.m_priority = ((gflags & GAMETYPE_FLAG_PREFERRED) ? 2 : ((gflags & GAMETYPE_FLAG_PRIORITY) ? 1 : 0));
115         this.m_hidelimits = (gflags & GAMETYPE_FLAG_HIDELIMITS);
116         this.m_weaponarena = (gflags & GAMETYPE_FLAG_WEAPONARENA);
117         this.m_1v1 = (gflags & GAMETYPE_FLAG_1V1);
118
119         // same as `1 << m_id`
120         MAPINFO_TYPE_ALL |= this.items = this.m_flags = (MAPINFO_TYPE_ALL + 1);
121     }
122 ENDCLASS(Gametype)
123
124 REGISTRY(Gametypes, 32)
125 REGISTER_REGISTRY(Gametypes)
126 REGISTRY_SORT(Gametypes)
127 REGISTRY_CHECK(Gametypes)
128
129 REGISTRY_DEFINE_GET(Gametypes, NULL)
130 STATIC_INIT(Gametypes_renumber) { FOREACH(Gametypes, true, it.m_id = i); }
131 #define REGISTER_GAMETYPE(NAME, inst) REGISTER(Gametypes, MAPINFO_TYPE, NAME, m_id, inst)
132
133 #ifndef CSQC
134 // NOTE: ISGAMETYPE in csqc (temporary hack)
135 #define IS_GAMETYPE(NAME) (MapInfo_LoadedGametype == MAPINFO_TYPE_##NAME)
136 #endif
137
138 const int MAPINFO_FEATURE_WEAPONS       = 1; // not defined for instagib-only maps
139 const int MAPINFO_FEATURE_VEHICLES      = 2;
140 const int MAPINFO_FEATURE_TURRETS       = 4;
141 const int MAPINFO_FEATURE_MONSTERS      = 8;
142
143 const int MAPINFO_FLAG_HIDDEN           = 1; // not in lsmaps/menu/vcall/etc., can just be changed to manually
144 const int MAPINFO_FLAG_FORBIDDEN        = 2; // don't even allow the map by a cvar setting that allows hidden maps
145 const int MAPINFO_FLAG_FRUSTRATING      = 4; // this map is near impossible to play, enable at your own risk
146 const int MAPINFO_FLAG_DONOTWANT        = 8; // do not include in GUI voting screen or select in GotoNextMap()/GetNextMap(), unless added with `suggestmap` or required as a fallback
147
148 float MapInfo_count;
149
150 // load MapInfo_count; generate mapinfo for maps that miss them, and clear the
151 // cache; you need to call MapInfo_FilterGametype afterwards!
152 void MapInfo_Enumerate();
153
154 // filter the info by game type mask (updates MapInfo_count)
155 float MapInfo_progress;
156 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)
157 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)
158 void MapInfo_FilterString(string sf); // filter _MapInfo_filtered (created by MapInfo_FilterGametype) with keyword
159 int MapInfo_CurrentFeatures(); // retrieves currently required features from cvars
160 Gametype MapInfo_CurrentGametype(); // retrieves current gametype from cvars
161 int MapInfo_ForbiddenFlags(); // retrieves current flags from cvars
162 int MapInfo_RequiredFlags(); // retrieves current flags from cvars
163
164 // load info about the i-th map into the MapInfo_Map_* globals
165 bool MapInfo_Get_ByID(int i); // 1 on success, 0 on failure
166 string MapInfo_BSPName_ByID(float i);
167
168 // load info about a map by name into the MapInfo_Map_* globals
169 int MapInfo_Get_ByName(string s, float allowGenerate, Gametype gametypeToSet); // 1 on success, 0 on failure, 2 if it autogenerated a mapinfo file
170
171 // load map-specific player limits
172 int map_minplayers;
173 int map_maxplayers;
174 bool MapReadSizes(string map);
175
176 // look for a map by a prefix, returns the actual map name on success, string_null on failure or ambigous match
177 string MapInfo_FindName_match; // the name of the map that was found
178 float MapInfo_FindName_firstResult; // -1 if none were found, index of first one if not unique but found (FindName then returns -1)
179 float MapInfo_FindName(string s);
180 string MapInfo_FixName(string s);
181
182 // play a map
183 float MapInfo_CheckMap(string s); // returns 0 if the map can't be played with the current settings
184 void MapInfo_LoadMap(string s, float reinit);
185
186 // list all maps for the current game type
187 string MapInfo_ListAllowedMaps(Gametype type, float pFlagsRequired, float pFlagsForbidden);
188 // list all allowed maps (for any game type)
189 string MapInfo_ListAllAllowedMaps(float pFlagsRequired, float pFlagsForbidden);
190
191 // gets a gametype from a string
192 string _MapInfo_GetDefaultEx(Gametype t);
193 float _MapInfo_GetTeamPlayBool(Gametype t);
194 Gametype MapInfo_Type_FromString(string t, bool dowarn, bool is_q3compat);
195 string MapInfo_Type_Description(Gametype t);
196 string MapInfo_Type_ToString(Gametype t);
197 string MapInfo_Type_ToText(Gametype t);
198 void MapInfo_SwitchGameType(Gametype t);
199
200 // to be called from worldspawn to set up cvars
201 void MapInfo_LoadMapSettings(string s);
202 Gametype MapInfo_LoadedGametype; // game type that was active during map load
203
204 void MapInfo_Cache_Destroy(); // disable caching
205 void MapInfo_Cache_Create(); // enable caching
206 void MapInfo_Cache_Invalidate(); // delete cache if any, but keep enabled
207
208 bool _MapInfo_ParseArena(string arena_filename, int fh, string pFilename, Gametype pGametypeToSet, bool isdefi, bool isgenerator);
209
210 string _MapInfo_FindArenaFile(string pFilename, string extension);
211
212 void _MapInfo_Parse_Settemp(string pFilename, string acl, float type, string s, float recurse);
213
214 void MapInfo_ClearTemps(); // call this when done with mapinfo for this frame
215
216 void MapInfo_Shutdown(); // call this in the shutdown handler
217
218 #define MAPINFO_SETTEMP_ACL_USER cvar_string("g_mapinfo_settemp_acl")
219 #define MAPINFO_SETTEMP_ACL_SYSTEM "-g_mapinfo_* -rcon_* -_* -g_ban* +*"