]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/common/mapinfo.qh
Mapinfo: decentralise mapinfo parsing
[xonotic/xonotic-data.pk3dir.git] / qcsrc / common / mapinfo.qh
1 #ifndef MAPINFO_H
2 #define MAPINFO_H
3
4 #include "util.qh"
5
6 CLASS(Gametype, Object)
7     ATTRIB(Gametype, m_id, int, 0)
8     /** game type ID */
9     ATTRIB(Gametype, items, int, 0)
10     /** game type name as in cvar (with g_ prefix) */
11     ATTRIB(Gametype, netname, string, string_null)
12     /** game type short name */
13     ATTRIB(Gametype, mdl, string, string_null)
14     /** human readable name */
15     ATTRIB(Gametype, message, string, string_null)
16     /** does this gametype support teamplay? */
17     ATTRIB(Gametype, team, bool, false)
18     /** game type defaults */
19     ATTRIB(Gametype, model2, string, string_null)
20     /** game type description */
21     ATTRIB(Gametype, gametype_description, string, string_null)
22
23     ATTRIB(Gametype, m_parse_mapinfo, bool(string k, string v), func_null)
24
25     METHOD(Gametype, describe, string(entity this)) { return this.gametype_description; }
26
27     METHOD(Gametype, display, void(entity this, void(string name, string icon) returns)) {
28         returns(this.message, strcat("gametype_", this.mdl));
29     }
30
31     CONSTRUCTOR(Gametype, string hname, string sname, string g_name, bool gteamplay, string defaults, string gdescription)
32     {
33         CONSTRUCT(Gametype);
34         this.netname = g_name;
35         this.mdl = sname;
36         this.message = hname;
37         this.team = gteamplay;
38         this.model2 = defaults;
39         this.gametype_description = gdescription;
40     }
41 ENDCLASS(Gametype)
42
43 REGISTRY(Gametypes, BIT(4))
44 REGISTER_REGISTRY(RegisterGametypes)
45 int MAPINFO_TYPE_ALL;
46 #define REGISTER_GAMETYPE(hname, sname, g_name, NAME, gteamplay, defaults, gdescription)                    \
47     int MAPINFO_TYPE_##NAME;                                                                                \
48     bool NAME##_mapinfo(string k, string v) { return = false; }                                             \
49     REGISTER(RegisterGametypes, MAPINFO_TYPE, Gametypes, g_name, m_id,                                      \
50         NEW(Gametype, hname, #sname, #g_name, gteamplay, defaults, gdescription)                            \
51     ) {                                                                                                     \
52         /* same as `1 << m_id` */                                                                           \
53         MAPINFO_TYPE_##NAME = MAPINFO_TYPE_ALL + 1; MAPINFO_TYPE_ALL |= MAPINFO_TYPE_##NAME;                \
54         this.items = MAPINFO_TYPE_##NAME;                                                                   \
55         this.m_parse_mapinfo = NAME##_mapinfo;                                                              \
56     }                                                                                                       \
57     [[accumulate]] bool NAME##_mapinfo(string k, string v)
58
59 #define IS_GAMETYPE(NAME) \
60     (MapInfo_LoadedGametype == MAPINFO_TYPE_##NAME)
61
62 REGISTER_GAMETYPE(_("Deathmatch"),dm,g_dm,DEATHMATCH,false,"timelimit=20 pointlimit=30 leadlimit=0",_("Score as many frags as you can."));
63
64 REGISTER_GAMETYPE(_("Last Man Standing"),lms,g_lms,LMS,false,"timelimit=20 lives=9 leadlimit=0",_("Survive and kill until the enemies have no lives left."));
65
66 REGISTER_GAMETYPE(_("Race"),rc,g_race,RACE,false,"timelimit=20 qualifying_timelimit=5 laplimit=7 teamlaplimit=15 leadlimit=0",_("Race against other players to the finish line."))
67 {
68     if (!k) {
69         cvar_set("g_race_qualifying_timelimit", cvar_defstring("g_race_qualifying_timelimit"));
70         return true;
71     }
72     switch (k) {
73         case "qualifying_timelimit":
74             cvar_set("g_race_qualifying_timelimit", v);
75             return true;
76     }
77 }
78 #define g_race IS_GAMETYPE(RACE)
79
80 REGISTER_GAMETYPE(_("Race CTS"),cts,g_cts,CTS,false,"timelimit=20",_("Race for fastest time."));
81 #define g_cts IS_GAMETYPE(CTS)
82
83 REGISTER_GAMETYPE(_("Team Deathmatch"),tdm,g_tdm,TEAM_DEATHMATCH,true,"timelimit=20 pointlimit=50 teams=2 leadlimit=0",_("Help your team score the most frags against the enemy team."))
84 {
85     if (!k) {
86         cvar_set("g_tdm_teams", cvar_defstring("g_tdm_teams"));
87         return true;
88     }
89     switch (k) {
90         case "teams":
91             cvar_set("g_tdm_teams", v);
92             return true;
93     }
94 }
95 #define g_tdm IS_GAMETYPE(TEAM_DEATHMATCH)
96
97 REGISTER_GAMETYPE(_("Capture the Flag"),ctf,g_ctf,CTF,true,"timelimit=20 caplimit=10 leadlimit=6",_("Find and bring the enemy flag to your base to capture it, defend your base from the other team."));
98 #define g_ctf IS_GAMETYPE(CTF)
99
100 REGISTER_GAMETYPE(_("Clan Arena"),ca,g_ca,CA,true,"timelimit=20 pointlimit=10 teams=2 leadlimit=0",_("Kill all enemy teammates to win the round."))
101 {
102     if (!k) {
103         cvar_set("g_ca_teams", cvar_defstring("g_ca_teams"));
104         return true;
105     }
106     switch (k) {
107         case "teams":
108             cvar_set("g_ca_teams", v);
109             return true;
110     }
111 }
112 #define g_ca IS_GAMETYPE(CA)
113
114 REGISTER_GAMETYPE(_("Domination"),dom,g_domination,DOMINATION,true,"timelimit=20 pointlimit=200 teams=2 leadlimit=0",_("Capture and defend all the control points to win."))
115 {
116     if (!k) {
117         cvar_set("g_domination_default_teams", cvar_defstring("g_domination_default_teams"));
118         return true;
119     }
120     switch (k) {
121         case "teams":
122             cvar_set("g_domination_default_teams", v);
123             return true;
124     }
125 }
126
127 REGISTER_GAMETYPE(_("Key Hunt"),kh,g_keyhunt,KEYHUNT,true,"timelimit=20 pointlimit=1000 teams=3 leadlimit=0",_("Gather all the keys to win the round."))
128 {
129     if (!k) {
130         cvar_set("g_keyhunt_teams", cvar_defstring("g_keyhunt_teams"));
131         return true;
132     }
133     switch (k) {
134         case "teams":
135             cvar_set("g_keyhunt_teams", v);
136             return true;
137     }
138 }
139
140 REGISTER_GAMETYPE(_("Assault"),as,g_assault,ASSAULT,true,"timelimit=20",_("Destroy obstacles to find and destroy the enemy power core before time runs out."));
141 #define g_assault IS_GAMETYPE(ASSAULT)
142
143 REGISTER_GAMETYPE(_("Onslaught"),ons,g_onslaught,ONSLAUGHT,true,"pointlimit=1 timelimit=20",_("Capture control points to reach and destroy the enemy generator."));
144
145 REGISTER_GAMETYPE(_("Nexball"),nb,g_nexball,NEXBALL,true,"timelimit=20 pointlimit=5 leadlimit=0",_("Shoot and kick the ball into the enemies goal, keep your goal clean."));
146 #define g_nexball IS_GAMETYPE(NEXBALL)
147
148 REGISTER_GAMETYPE(_("Freeze Tag"),ft,g_freezetag,FREEZETAG,true,"timelimit=20 pointlimit=10 teams=2 leadlimit=0",_("Kill enemies to freeze them, stand next to teammates to revive them, freeze the most enemies to win."))
149 {
150     if (!k) {
151         cvar_set("g_freezetag_teams", cvar_defstring("g_freezetag_teams"));
152         return true;
153     }
154     switch (k) {
155         case "teams":
156             cvar_set("g_freezetag_teams", v);
157             return true;
158     }
159 }
160 #define g_freezetag IS_GAMETYPE(FREEZETAG)
161
162 REGISTER_GAMETYPE(_("Keepaway"),ka,g_keepaway,KEEPAWAY,true,"timelimit=20 pointlimit=30",_("Hold the ball to get points for kills."));
163
164 REGISTER_GAMETYPE(_("Invasion"),inv,g_invasion,INVASION,false,"pointlimit=50 teams=0",_("Survive against waves of monsters."))
165 {
166     switch (k) {
167         case "teams":
168             cvar_set("g_invasion_teams", v);
169             return true;
170     }
171 }
172
173 const int MAPINFO_FEATURE_WEAPONS       = 1; // not defined for instagib-only maps
174 const int MAPINFO_FEATURE_VEHICLES      = 2;
175 const int MAPINFO_FEATURE_TURRETS       = 4;
176 const int MAPINFO_FEATURE_MONSTERS      = 8;
177
178 const int MAPINFO_FLAG_HIDDEN           = 1; // not in lsmaps/menu/vcall/etc., can just be changed to manually
179 const int MAPINFO_FLAG_FORBIDDEN        = 2; // don't even allow the map by a cvar setting that allows hidden maps
180 const int MAPINFO_FLAG_FRUSTRATING      = 4; // this map is near impossible to play, enable at your own risk
181 const int MAPINFO_FLAG_NOAUTOMAPLIST    = 8; // do not include when automatically building maplist (counts as hidden for maplist building purposes)
182
183 float MapInfo_count;
184
185 // info about a map that MapInfo loads
186 string MapInfo_Map_bspname;
187 string MapInfo_Map_title;
188 string MapInfo_Map_titlestring; // either bspname: title or just title, depending on whether bspname is redundant
189 string MapInfo_Map_description;
190 string MapInfo_Map_author;
191 string MapInfo_Map_clientstuff; // not in cache, only for map load
192 string MapInfo_Map_fog; // not in cache, only for map load
193 int MapInfo_Map_supportedGametypes;
194 int MapInfo_Map_supportedFeatures;
195 int MapInfo_Map_flags;
196 vector MapInfo_Map_mins; // these are '0 0 0' if not supported!
197 vector MapInfo_Map_maxs; // these are '0 0 0' if not specified!
198
199 // load MapInfo_count; generate mapinfo for maps that miss them, and clear the
200 // cache; you need to call MapInfo_FilterGametype afterwards!
201 void MapInfo_Enumerate();
202
203 // filter the info by game type mask (updates MapInfo_count)
204 float MapInfo_progress;
205 float MapInfo_FilterGametype(float gametype, 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)
206 void MapInfo_FilterString(string sf); // filter _MapInfo_filtered (created by MapInfo_FilterGametype) with keyword
207 int MapInfo_CurrentFeatures(); // retrieves currently required features from cvars
208 int MapInfo_CurrentGametype(); // retrieves current gametype from cvars
209 int MapInfo_ForbiddenFlags(); // retrieves current flags from cvars
210 int MapInfo_RequiredFlags(); // retrieves current flags from cvars
211
212 // load info about the i-th map into the MapInfo_Map_* globals
213 float MapInfo_Get_ByID(float i); // 1 on success, 0 on failure
214 string MapInfo_BSPName_ByID(float i);
215
216 // load info about a map by name into the MapInfo_Map_* globals
217 float MapInfo_Get_ByName(string s, float allowGenerate, float gametypeToSet); // 1 on success, 0 on failure, 2 if it autogenerated a mapinfo file
218
219 // look for a map by a prefix, returns the actual map name on success, string_null on failure or ambigous match
220 string MapInfo_FindName_match; // the name of the map that was found
221 float MapInfo_FindName_firstResult; // -1 if none were found, index of first one if not unique but found (FindName then returns -1)
222 float MapInfo_FindName(string s);
223 string MapInfo_FixName(string s);
224
225 // play a map
226 float MapInfo_CheckMap(string s); // returns 0 if the map can't be played with the current settings
227 void MapInfo_LoadMap(string s, float reinit);
228
229 // list all maps for the current game type
230 string MapInfo_ListAllowedMaps(float type, float pFlagsRequired, float pFlagsForbidden);
231 // list all allowed maps (for any game type)
232 string MapInfo_ListAllAllowedMaps(float pFlagsRequired, float pFlagsForbidden);
233
234 // gets a gametype from a string
235 string _MapInfo_GetDefaultEx(float t);
236 float _MapInfo_GetTeamPlayBool(float t);
237 float MapInfo_Type_FromString(string t);
238 string MapInfo_Type_Description(float t);
239 string MapInfo_Type_ToString(float t);
240 string MapInfo_Type_ToText(float t);
241 void MapInfo_SwitchGameType(int t);
242
243 // to be called from worldspawn to set up cvars
244 void MapInfo_LoadMapSettings(string s);
245 float MapInfo_LoadedGametype; // game type that was active during map load
246
247 void MapInfo_Cache_Destroy(); // disable caching
248 void MapInfo_Cache_Create(); // enable caching
249 void MapInfo_Cache_Invalidate(); // delete cache if any, but keep enabled
250
251 void MapInfo_ClearTemps(); // call this when done with mapinfo for this frame
252
253 void MapInfo_Shutdown(); // call this in the shutdown handler
254
255 #define MAPINFO_SETTEMP_ACL_USER cvar_string("g_mapinfo_settemp_acl")
256 #define MAPINFO_SETTEMP_ACL_SYSTEM "-g_mapinfo_* -rcon_* -_* -g_ban* +*"
257 #endif