]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/common/mapinfo.qh
Registrize mapinfo generation and twobasemodes
[xonotic/xonotic-data.pk3dir.git] / qcsrc / common / mapinfo.qh
1 #pragma once
2
3 bool autocvar_developer_mapper;
4
5 #define LOG_MAPWARN(...) MACRO_BEGIN { if (autocvar_developer_mapper) LOG_WARN(__VA_ARGS__); } MACRO_END
6 #define LOG_MAPWARNF(...) MACRO_BEGIN { if (autocvar_developer_mapper) LOG_WARNF(__VA_ARGS__); } MACRO_END
7
8 #include "util.qh"
9
10 // info about a map that MapInfo loads
11 string MapInfo_Map_bspname;
12 string MapInfo_Map_title;
13 string MapInfo_Map_titlestring; // either bspname: title or just title, depending on whether bspname is redundant
14 string MapInfo_Map_description;
15 string MapInfo_Map_author;
16 string MapInfo_Map_clientstuff; // not in cache, only for map load
17 string MapInfo_Map_fog; // not in cache, only for map load
18 int MapInfo_Map_supportedGametypes;
19 int MapInfo_Map_supportedFeatures;
20 int MapInfo_Map_flags;
21 vector MapInfo_Map_mins; // these are '0 0 0' if not supported!
22 vector MapInfo_Map_maxs; // these are '0 0 0' if not specified!
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     /** game type defaults */
40     ATTRIB(Gametype, model2, string);
41     /** game type description */
42     ATTRIB(Gametype, gametype_description, string);
43
44     ATTRIB(Gametype, m_mutators, string);
45     METHOD(Gametype, m_parse_mapinfo, bool(string k, string v))
46     {
47         return false;
48     }
49     METHOD(Gametype, m_generate_mapinfo, void(Gametype this, string v))
50     {
51         TC(Gametype, this);
52     }
53     METHOD(Gametype, m_isTwoBaseMode, bool())
54     {
55         return false;
56     }
57
58     METHOD(Gametype, describe, string(Gametype this))
59     {
60         TC(Gametype, this);
61         return this.gametype_description;
62     }
63
64     METHOD(Gametype, display, void(Gametype this, void(string name, string icon) returns))
65     {
66         TC(Gametype, this);
67         returns(this.message, strcat("gametype_", this.mdl));
68     }
69
70     METHOD(Gametype, gametype_init, void(Gametype this, string hname, string sname, string g_name, bool gteamplay, string mutators, string defaults, string gdescription))
71     {
72         this.netname = g_name;
73         this.mdl = sname;
74         this.message = hname;
75         this.team = gteamplay;
76         this.m_mutators = cons(sname, mutators);
77         this.model2 = defaults;
78         this.gametype_description = gdescription;
79
80         // same as `1 << m_id`
81         MAPINFO_TYPE_ALL |= this.items = this.m_flags = (MAPINFO_TYPE_ALL + 1);
82     }
83 ENDCLASS(Gametype)
84
85 REGISTRY(Gametypes, 24)
86 #define Gametypes_from(i) _Gametypes_from(i, NULL)
87 REGISTER_REGISTRY(Gametypes)
88 REGISTRY_CHECK(Gametypes)
89 #define REGISTER_GAMETYPE(NAME, inst) REGISTER(Gametypes, MAPINFO_TYPE, NAME, m_id, inst)
90
91 #define IS_GAMETYPE(NAME) (MapInfo_LoadedGametype == MAPINFO_TYPE_##NAME)
92
93 CLASS(Deathmatch, Gametype)
94     INIT(Deathmatch)
95     {
96         this.gametype_init(this, _("Deathmatch"),"dm","g_dm",false,"","timelimit=20 pointlimit=30 leadlimit=0",_("Score as many frags as you can"));
97     }
98 ENDCLASS(Deathmatch)
99 REGISTER_GAMETYPE(DEATHMATCH, NEW(Deathmatch));
100
101 CLASS(LastManStanding, Gametype)
102     INIT(LastManStanding)
103     {
104         this.gametype_init(this, _("Last Man Standing"),"lms","g_lms",false,"","timelimit=20 lives=9 leadlimit=0",_("Survive and kill until the enemies have no lives left"));
105     }
106 ENDCLASS(LastManStanding)
107 REGISTER_GAMETYPE(LMS, NEW(LastManStanding));
108
109 CLASS(Race, Gametype)
110     INIT(Race)
111     {
112         this.gametype_init(this, _("Race"),"rc","g_race",false,"","timelimit=20 qualifying_timelimit=5 laplimit=7 teamlaplimit=15 leadlimit=0",_("Race against other players to the finish line"));
113     }
114     METHOD(Race, m_parse_mapinfo, bool(string k, string v))
115     {
116         if (!k) {
117             cvar_set("g_race_qualifying_timelimit", cvar_defstring("g_race_qualifying_timelimit"));
118             return true;
119         }
120         switch (k) {
121             case "qualifying_timelimit":
122                 cvar_set("g_race_qualifying_timelimit", v);
123                 return true;
124         }
125         return false;
126     }
127     METHOD(Race, m_generate_mapinfo, void(Gametype this, string v))
128     {
129         if(v == "trigger_race_checkpoint")
130             MapInfo_Map_supportedGametypes |= this.m_flags;
131     }
132     METHOD(Race, m_isTwoBaseMode, bool())
133     {
134         return true;
135     }
136 ENDCLASS(Race)
137 REGISTER_GAMETYPE(RACE, NEW(Race));
138 #define g_race IS_GAMETYPE(RACE)
139
140 CLASS(RaceCTS, Gametype)
141     INIT(RaceCTS)
142     {
143         this.gametype_init(this, _("Race CTS"),"cts","g_cts",false,"cloaked","timelimit=20",_("Race for fastest time."));
144     }
145     METHOD(RaceCTS, m_generate_mapinfo, void(Gametype this, string v))
146     {
147         if(v == "target_startTimer")
148             MapInfo_Map_supportedGametypes |= this.m_flags;
149     }
150 ENDCLASS(RaceCTS)
151 REGISTER_GAMETYPE(CTS, NEW(RaceCTS));
152 #define g_cts IS_GAMETYPE(CTS)
153
154 CLASS(TeamDeathmatch, Gametype)
155     INIT(TeamDeathmatch)
156     {
157         this.gametype_init(this, _("Team Deathmatch"),"tdm","g_tdm",true,"","timelimit=20 pointlimit=50 teams=2 leadlimit=0",_("Help your team score the most frags against the enemy team"));
158     }
159     METHOD(TeamDeathmatch, m_parse_mapinfo, bool(string k, string v))
160     {
161         if (!k) {
162             cvar_set("g_tdm_teams", cvar_defstring("g_tdm_teams"));
163             return true;
164         }
165         switch (k) {
166             case "teams":
167                 cvar_set("g_tdm_teams", v);
168                 return true;
169         }
170         return false;
171     }
172 ENDCLASS(TeamDeathmatch)
173 REGISTER_GAMETYPE(TEAM_DEATHMATCH, NEW(TeamDeathmatch));
174 #define g_tdm IS_GAMETYPE(TEAM_DEATHMATCH)
175
176 CLASS(CaptureTheFlag, Gametype)
177     INIT(CaptureTheFlag)
178     {
179         this.gametype_init(this, _("Capture the Flag"),"ctf","g_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"));
180     }
181     METHOD(CaptureTheFlag, m_generate_mapinfo, void(Gametype this, string v))
182     {
183         if(v == "item_flag_team2" || v == "team_CTF_blueflag")
184             MapInfo_Map_supportedGametypes |= this.m_flags;
185     }
186     METHOD(CaptureTheFlag, m_isTwoBaseMode, bool())
187     {
188         return true;
189     }
190 ENDCLASS(CaptureTheFlag)
191 REGISTER_GAMETYPE(CTF, NEW(CaptureTheFlag));
192 #define g_ctf IS_GAMETYPE(CTF)
193
194 CLASS(ClanArena, Gametype)
195     INIT(ClanArena)
196     {
197         this.gametype_init(this, _("Clan Arena"),"ca","g_ca",true,"","timelimit=20 pointlimit=10 teams=2 leadlimit=0",_("Kill all enemy teammates to win the round"));
198     }
199     METHOD(ClanArena, m_parse_mapinfo, bool(string k, string v))
200     {
201         if (!k) {
202             cvar_set("g_ca_teams", cvar_defstring("g_ca_teams"));
203             return true;
204         }
205         switch (k) {
206             case "teams":
207                 cvar_set("g_ca_teams", v);
208                 return true;
209         }
210         return false;
211     }
212 ENDCLASS(ClanArena)
213 REGISTER_GAMETYPE(CA, NEW(ClanArena));
214 #define g_ca IS_GAMETYPE(CA)
215
216 CLASS(Domination, Gametype)
217     INIT(Domination)
218     {
219         this.gametype_init(this, _("Domination"),"dom","g_domination",true,"","timelimit=20 pointlimit=200 teams=2 leadlimit=0",_("Capture and defend all the control points to win"));
220     }
221     METHOD(Domination, m_parse_mapinfo, bool(string k, string v))
222     {
223         if (!k) {
224             cvar_set("g_domination_default_teams", cvar_defstring("g_domination_default_teams"));
225             return true;
226         }
227         switch (k) {
228             case "teams":
229                 cvar_set("g_domination_default_teams", v);
230                 return true;
231         }
232         return false;
233     }
234     METHOD(Domination, m_generate_mapinfo, void(Gametype this, string v))
235     {
236         if(v == "dom_controlpoint")
237             MapInfo_Map_supportedGametypes |= this.m_flags;
238     }
239 ENDCLASS(Domination)
240 REGISTER_GAMETYPE(DOMINATION, NEW(Domination));
241
242 CLASS(KeyHunt, Gametype)
243     INIT(KeyHunt)
244     {
245         this.gametype_init(this, _("Key Hunt"),"kh","g_keyhunt",true,"","timelimit=20 pointlimit=1000 teams=3 leadlimit=0",_("Gather all the keys to win the round"));
246     }
247     METHOD(KeyHunt, m_parse_mapinfo, bool(string k, string v))
248     {
249         if (!k) {
250             cvar_set("g_keyhunt_teams", cvar_defstring("g_keyhunt_teams"));
251             return true;
252         }
253         switch (k) {
254             case "teams":
255                 cvar_set("g_keyhunt_teams", v);
256                 return true;
257         }
258         return false;
259     }
260 ENDCLASS(KeyHunt)
261 REGISTER_GAMETYPE(KEYHUNT, NEW(KeyHunt));
262
263 CLASS(Assault, Gametype)
264     INIT(Assault)
265     {
266         this.gametype_init(this, _("Assault"),"as","g_assault",true,"","timelimit=20",_("Destroy obstacles to find and destroy the enemy power core before time runs out"));
267     }
268     METHOD(Assault, m_generate_mapinfo, void(Gametype this, string v))
269     {
270         if(v == "target_assault_roundend")
271             MapInfo_Map_supportedGametypes |= this.m_flags;
272     }
273     METHOD(Assault, m_isTwoBaseMode, bool())
274     {
275         return true;
276     }
277 ENDCLASS(Assault)
278 REGISTER_GAMETYPE(ASSAULT, NEW(Assault));
279 #define g_assault IS_GAMETYPE(ASSAULT)
280
281 CLASS(Onslaught, Gametype)
282     INIT(Onslaught)
283     {
284         this.gametype_init(this, _("Onslaught"),"ons","g_onslaught",true,"","pointlimit=1 timelimit=20",_("Capture control points to reach and destroy the enemy generator"));
285     }
286     METHOD(Onslaught, m_generate_mapinfo, void(Gametype this, string v))
287     {
288         if(v == "onslaught_generator")
289             MapInfo_Map_supportedGametypes |= this.m_flags;
290     }
291 ENDCLASS(Onslaught)
292 REGISTER_GAMETYPE(ONSLAUGHT, NEW(Onslaught));
293
294 CLASS(NexBall, Gametype)
295     INIT(NexBall)
296     {
297         this.gametype_init(this, _("Nexball"),"nb","g_nexball",true,"","timelimit=20 pointlimit=5 leadlimit=0",_("Shoot and kick the ball into the enemies goal, keep your goal clean"));
298     }
299     METHOD(NexBall, m_generate_mapinfo, void(Gametype this, string v))
300     {
301         if(substring(v, 0, 8) == "nexball_" || substring(v, 0, 4) == "ball")
302             MapInfo_Map_supportedGametypes |= this.m_flags;
303     }
304     METHOD(NexBall, m_isTwoBaseMode, bool())
305     {
306         return true;
307     }
308 ENDCLASS(NexBall)
309 REGISTER_GAMETYPE(NEXBALL, NEW(NexBall));
310 #define g_nexball IS_GAMETYPE(NEXBALL)
311
312 CLASS(FreezeTag, Gametype)
313     INIT(FreezeTag)
314     {
315         this.gametype_init(this, _("Freeze Tag"),"ft","g_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"));
316     }
317     METHOD(FreezeTag, m_parse_mapinfo, bool(string k, string v))
318     {
319         if (!k) {
320             cvar_set("g_freezetag_teams", cvar_defstring("g_freezetag_teams"));
321             return true;
322         }
323         switch (k) {
324             case "teams":
325                 cvar_set("g_freezetag_teams", v);
326                 return true;
327         }
328         return false;
329     }
330 ENDCLASS(FreezeTag)
331 REGISTER_GAMETYPE(FREEZETAG, NEW(FreezeTag));
332 #define g_freezetag IS_GAMETYPE(FREEZETAG)
333
334 CLASS(Keepaway, Gametype)
335     INIT(Keepaway)
336     {
337         this.gametype_init(this, _("Keepaway"),"ka","g_keepaway",true,"","timelimit=20 pointlimit=30",_("Hold the ball to get points for kills"));
338     }
339 ENDCLASS(Keepaway)
340 REGISTER_GAMETYPE(KEEPAWAY, NEW(Keepaway));
341
342 CLASS(Invasion, Gametype)
343     INIT(Invasion)
344     {
345         this.gametype_init(this, _("Invasion"),"inv","g_invasion",false,"","pointlimit=50 teams=0",_("Survive against waves of monsters"));
346     }
347     METHOD(Invasion, m_parse_mapinfo, bool(string k, string v))
348     {
349         switch (k) {
350             case "teams":
351                 cvar_set("g_invasion_teams", v);
352                 return true;
353         }
354         return false;
355     }
356     METHOD(Invasion, m_generate_mapinfo, void(Gametype this, string v))
357     {
358         if(v == "invasion_spawnpoint")
359             MapInfo_Map_supportedGametypes |= this.m_flags;
360     }
361 ENDCLASS(Invasion)
362 REGISTER_GAMETYPE(INVASION, NEW(Invasion));
363
364 const int MAPINFO_FEATURE_WEAPONS       = 1; // not defined for instagib-only maps
365 const int MAPINFO_FEATURE_VEHICLES      = 2;
366 const int MAPINFO_FEATURE_TURRETS       = 4;
367 const int MAPINFO_FEATURE_MONSTERS      = 8;
368
369 const int MAPINFO_FLAG_HIDDEN           = 1; // not in lsmaps/menu/vcall/etc., can just be changed to manually
370 const int MAPINFO_FLAG_FORBIDDEN        = 2; // don't even allow the map by a cvar setting that allows hidden maps
371 const int MAPINFO_FLAG_FRUSTRATING      = 4; // this map is near impossible to play, enable at your own risk
372 const int MAPINFO_FLAG_NOAUTOMAPLIST    = 8; // do not include when automatically building maplist (counts as hidden for maplist building purposes)
373
374 float MapInfo_count;
375
376 // load MapInfo_count; generate mapinfo for maps that miss them, and clear the
377 // cache; you need to call MapInfo_FilterGametype afterwards!
378 void MapInfo_Enumerate();
379
380 // filter the info by game type mask (updates MapInfo_count)
381 float MapInfo_progress;
382 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)
383 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)
384 void MapInfo_FilterString(string sf); // filter _MapInfo_filtered (created by MapInfo_FilterGametype) with keyword
385 int MapInfo_CurrentFeatures(); // retrieves currently required features from cvars
386 Gametype MapInfo_CurrentGametype(); // retrieves current gametype from cvars
387 int MapInfo_ForbiddenFlags(); // retrieves current flags from cvars
388 int MapInfo_RequiredFlags(); // retrieves current flags from cvars
389
390 // load info about the i-th map into the MapInfo_Map_* globals
391 float MapInfo_Get_ByID(float i); // 1 on success, 0 on failure
392 string MapInfo_BSPName_ByID(float i);
393
394 // load info about a map by name into the MapInfo_Map_* globals
395 int MapInfo_Get_ByName(string s, float allowGenerate, Gametype gametypeToSet); // 1 on success, 0 on failure, 2 if it autogenerated a mapinfo file
396
397 // look for a map by a prefix, returns the actual map name on success, string_null on failure or ambigous match
398 string MapInfo_FindName_match; // the name of the map that was found
399 float MapInfo_FindName_firstResult; // -1 if none were found, index of first one if not unique but found (FindName then returns -1)
400 float MapInfo_FindName(string s);
401 string MapInfo_FixName(string s);
402
403 // play a map
404 float MapInfo_CheckMap(string s); // returns 0 if the map can't be played with the current settings
405 void MapInfo_LoadMap(string s, float reinit);
406
407 // list all maps for the current game type
408 string MapInfo_ListAllowedMaps(Gametype type, float pFlagsRequired, float pFlagsForbidden);
409 // list all allowed maps (for any game type)
410 string MapInfo_ListAllAllowedMaps(float pFlagsRequired, float pFlagsForbidden);
411
412 // gets a gametype from a string
413 string _MapInfo_GetDefaultEx(Gametype t);
414 float _MapInfo_GetTeamPlayBool(Gametype t);
415 Gametype MapInfo_Type_FromString(string t);
416 string MapInfo_Type_Description(Gametype t);
417 string MapInfo_Type_ToString(Gametype t);
418 string MapInfo_Type_ToText(Gametype t);
419 void MapInfo_SwitchGameType(Gametype t);
420
421 // to be called from worldspawn to set up cvars
422 void MapInfo_LoadMapSettings(string s);
423 Gametype MapInfo_LoadedGametype; // game type that was active during map load
424
425 void MapInfo_Cache_Destroy(); // disable caching
426 void MapInfo_Cache_Create(); // enable caching
427 void MapInfo_Cache_Invalidate(); // delete cache if any, but keep enabled
428
429 void MapInfo_ClearTemps(); // call this when done with mapinfo for this frame
430
431 void MapInfo_Shutdown(); // call this in the shutdown handler
432
433 #define MAPINFO_SETTEMP_ACL_USER cvar_string("g_mapinfo_settemp_acl")
434 #define MAPINFO_SETTEMP_ACL_SYSTEM "-g_mapinfo_* -rcon_* -_* -g_ban* +*"