]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/common/mapinfo.qh
Add a method to the asymmetrical madness
[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 #ifdef CSQC
44     ATTRIB(Gametype, m_modicons, void(vector pos, vector mySize));
45 #endif
46
47     ATTRIB(Gametype, m_mutators, string);
48     METHOD(Gametype, m_parse_mapinfo, bool(string k, string v))
49     {
50         return false;
51     }
52     METHOD(Gametype, m_generate_mapinfo, void(Gametype this, string v))
53     {
54         TC(Gametype, this);
55     }
56     METHOD(Gametype, m_isTwoBaseMode, bool())
57     {
58         return false;
59     }
60     METHOD(Gametype, m_isAlwaysSupported, bool(Gametype this, int spawnpoints, float diameter))
61     {
62         return false;
63     }
64
65     METHOD(Gametype, describe, string(Gametype this))
66     {
67         TC(Gametype, this);
68         return this.gametype_description;
69     }
70
71     METHOD(Gametype, display, void(Gametype this, void(string name, string icon) returns))
72     {
73         TC(Gametype, this);
74         returns(this.message, strcat("gametype_", this.mdl));
75     }
76
77     METHOD(Gametype, gametype_init, void(Gametype this, string hname, string sname, string g_name, bool gteamplay, string mutators, string defaults, string gdescription))
78     {
79         this.netname = g_name;
80         this.mdl = sname;
81         this.message = hname;
82         this.team = gteamplay;
83         this.m_mutators = cons(sname, mutators);
84         this.model2 = defaults;
85         this.gametype_description = gdescription;
86
87         // same as `1 << m_id`
88         MAPINFO_TYPE_ALL |= this.items = this.m_flags = (MAPINFO_TYPE_ALL + 1);
89     }
90 ENDCLASS(Gametype)
91
92 REGISTRY(Gametypes, 24)
93 #define Gametypes_from(i) _Gametypes_from(i, NULL)
94 REGISTER_REGISTRY(Gametypes)
95 REGISTRY_CHECK(Gametypes)
96 #define REGISTER_GAMETYPE(NAME, inst) REGISTER(Gametypes, MAPINFO_TYPE, NAME, m_id, inst)
97
98 #define IS_GAMETYPE(NAME) (MapInfo_LoadedGametype == MAPINFO_TYPE_##NAME)
99
100 CLASS(Deathmatch, Gametype)
101     INIT(Deathmatch)
102     {
103         this.gametype_init(this, _("Deathmatch"),"dm","g_dm",false,"","timelimit=20 pointlimit=30 leadlimit=0",_("Score as many frags as you can"));
104     }
105     METHOD(Deathmatch, m_isAlwaysSupported, bool(Gametype this, int spawnpoints, float diameter))
106     {
107         return true;
108     }
109 ENDCLASS(Deathmatch)
110 REGISTER_GAMETYPE(DEATHMATCH, NEW(Deathmatch));
111
112 CLASS(LastManStanding, Gametype)
113     INIT(LastManStanding)
114     {
115         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"));
116     }
117     METHOD(LastManStanding, m_isAlwaysSupported, bool(Gametype this, int spawnpoints, float diameter))
118     {
119         return true;
120     }
121 ENDCLASS(LastManStanding)
122 REGISTER_GAMETYPE(LMS, NEW(LastManStanding));
123
124 #ifdef CSQC
125 void HUD_Mod_Race(vector pos, vector mySize);
126 #endif
127 CLASS(Race, Gametype)
128     INIT(Race)
129     {
130         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"));
131     }
132     METHOD(Race, m_parse_mapinfo, bool(string k, string v))
133     {
134         if (!k) {
135             cvar_set("g_race_qualifying_timelimit", cvar_defstring("g_race_qualifying_timelimit"));
136             return true;
137         }
138         switch (k) {
139             case "qualifying_timelimit":
140                 cvar_set("g_race_qualifying_timelimit", v);
141                 return true;
142         }
143         return false;
144     }
145     METHOD(Race, m_generate_mapinfo, void(Gametype this, string v))
146     {
147         if(v == "trigger_race_checkpoint")
148             MapInfo_Map_supportedGametypes |= this.m_flags;
149     }
150     METHOD(Race, m_isTwoBaseMode, bool())
151     {
152         return true;
153     }
154 #ifdef CSQC
155     ATTRIB(Race, m_modicons, void(vector pos, vector mySize), HUD_Mod_Race);
156 #endif
157 ENDCLASS(Race)
158 REGISTER_GAMETYPE(RACE, NEW(Race));
159 #define g_race IS_GAMETYPE(RACE)
160
161 CLASS(RaceCTS, Gametype)
162     INIT(RaceCTS)
163     {
164         this.gametype_init(this, _("Race CTS"),"cts","g_cts",false,"cloaked","timelimit=20",_("Race for fastest time."));
165     }
166     METHOD(RaceCTS, m_generate_mapinfo, void(Gametype this, string v))
167     {
168         if(v == "target_startTimer")
169             MapInfo_Map_supportedGametypes |= this.m_flags;
170     }
171 #ifdef CSQC
172     ATTRIB(RaceCTS, m_modicons, void(vector pos, vector mySize), HUD_Mod_Race);
173 #endif
174 ENDCLASS(RaceCTS)
175 REGISTER_GAMETYPE(CTS, NEW(RaceCTS));
176 #define g_cts IS_GAMETYPE(CTS)
177
178 CLASS(TeamDeathmatch, Gametype)
179     INIT(TeamDeathmatch)
180     {
181         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"));
182     }
183     METHOD(TeamDeathmatch, m_parse_mapinfo, bool(string k, string v))
184     {
185         if (!k) {
186             cvar_set("g_tdm_teams", cvar_defstring("g_tdm_teams"));
187             return true;
188         }
189         switch (k) {
190             case "teams":
191                 cvar_set("g_tdm_teams", v);
192                 return true;
193         }
194         return false;
195     }
196     METHOD(TeamDeathmatch, m_isAlwaysSupported, bool(Gametype this, int spawnpoints, float diameter))
197     {
198         if(spawnpoints >= 8 && diameter > 4096)
199             return true;
200         return false;
201     }
202 ENDCLASS(TeamDeathmatch)
203 REGISTER_GAMETYPE(TEAM_DEATHMATCH, NEW(TeamDeathmatch));
204 #define g_tdm IS_GAMETYPE(TEAM_DEATHMATCH)
205
206 #ifdef CSQC
207 void HUD_Mod_CTF(vector pos, vector mySize);
208 #endif
209 CLASS(CaptureTheFlag, Gametype)
210     INIT(CaptureTheFlag)
211     {
212         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"));
213     }
214     METHOD(CaptureTheFlag, m_generate_mapinfo, void(Gametype this, string v))
215     {
216         if(v == "item_flag_team2" || v == "team_CTF_blueflag")
217             MapInfo_Map_supportedGametypes |= this.m_flags;
218     }
219     METHOD(CaptureTheFlag, m_isTwoBaseMode, bool())
220     {
221         return true;
222     }
223 #ifdef CSQC
224     ATTRIB(CaptureTheFlag, m_modicons, void(vector pos, vector mySize), HUD_Mod_CTF);
225 #endif
226 ENDCLASS(CaptureTheFlag)
227 REGISTER_GAMETYPE(CTF, NEW(CaptureTheFlag));
228 #define g_ctf IS_GAMETYPE(CTF)
229
230 #ifdef CSQC
231 void HUD_Mod_CA(vector pos, vector mySize);
232 #endif
233 CLASS(ClanArena, Gametype)
234     INIT(ClanArena)
235     {
236         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"));
237     }
238     METHOD(ClanArena, m_parse_mapinfo, bool(string k, string v))
239     {
240         if (!k) {
241             cvar_set("g_ca_teams", cvar_defstring("g_ca_teams"));
242             return true;
243         }
244         switch (k) {
245             case "teams":
246                 cvar_set("g_ca_teams", v);
247                 return true;
248         }
249         return false;
250     }
251     METHOD(ClanArena, m_isAlwaysSupported, bool(Gametype this, int spawnpoints, float diameter))
252     {
253         if(spawnpoints >= 8 && diameter > 4096)
254             return true;
255         return false;
256     }
257 #ifdef CSQC
258     ATTRIB(ClanArena, m_modicons, void(vector pos, vector mySize), HUD_Mod_CA);
259 #endif
260 ENDCLASS(ClanArena)
261 REGISTER_GAMETYPE(CA, NEW(ClanArena));
262 #define g_ca IS_GAMETYPE(CA)
263
264 #ifdef CSQC
265 void HUD_Mod_Dom(vector pos, vector mySize);
266 #endif
267 CLASS(Domination, Gametype)
268     INIT(Domination)
269     {
270         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"));
271     }
272     METHOD(Domination, m_parse_mapinfo, bool(string k, string v))
273     {
274         if (!k) {
275             cvar_set("g_domination_default_teams", cvar_defstring("g_domination_default_teams"));
276             return true;
277         }
278         switch (k) {
279             case "teams":
280                 cvar_set("g_domination_default_teams", v);
281                 return true;
282         }
283         return false;
284     }
285     METHOD(Domination, m_generate_mapinfo, void(Gametype this, string v))
286     {
287         if(v == "dom_controlpoint")
288             MapInfo_Map_supportedGametypes |= this.m_flags;
289     }
290 #ifdef CSQC
291     ATTRIB(Domination, m_modicons, void(vector pos, vector mySize), HUD_Mod_Dom);
292 #endif
293 ENDCLASS(Domination)
294 REGISTER_GAMETYPE(DOMINATION, NEW(Domination));
295
296 #ifdef CSQC
297 void HUD_Mod_KH(vector pos, vector mySize);
298 #endif
299 CLASS(KeyHunt, Gametype)
300     INIT(KeyHunt)
301     {
302         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"));
303     }
304     METHOD(KeyHunt, m_parse_mapinfo, bool(string k, string v))
305     {
306         if (!k) {
307             cvar_set("g_keyhunt_teams", cvar_defstring("g_keyhunt_teams"));
308             return true;
309         }
310         switch (k) {
311             case "teams":
312                 cvar_set("g_keyhunt_teams", v);
313                 return true;
314         }
315         return false;
316     }
317     METHOD(KeyHunt, m_isAlwaysSupported, bool(Gametype this, int spawnpoints, float diameter))
318     {
319         if(spawnpoints >= 12 && diameter > 5120)
320             return true;
321         return false;
322     }
323 #ifdef CSQC
324     ATTRIB(KeyHunt, m_modicons, void(vector pos, vector mySize), HUD_Mod_KH);
325 #endif
326 ENDCLASS(KeyHunt)
327 REGISTER_GAMETYPE(KEYHUNT, NEW(KeyHunt));
328
329 CLASS(Assault, Gametype)
330     INIT(Assault)
331     {
332         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"));
333     }
334     METHOD(Assault, m_generate_mapinfo, void(Gametype this, string v))
335     {
336         if(v == "target_assault_roundend")
337             MapInfo_Map_supportedGametypes |= this.m_flags;
338     }
339     METHOD(Assault, m_isTwoBaseMode, bool())
340     {
341         return true;
342     }
343 ENDCLASS(Assault)
344 REGISTER_GAMETYPE(ASSAULT, NEW(Assault));
345 #define g_assault IS_GAMETYPE(ASSAULT)
346
347 CLASS(Onslaught, Gametype)
348     INIT(Onslaught)
349     {
350         this.gametype_init(this, _("Onslaught"),"ons","g_onslaught",true,"","pointlimit=1 timelimit=20",_("Capture control points to reach and destroy the enemy generator"));
351     }
352     METHOD(Onslaught, m_generate_mapinfo, void(Gametype this, string v))
353     {
354         if(v == "onslaught_generator")
355             MapInfo_Map_supportedGametypes |= this.m_flags;
356     }
357 ENDCLASS(Onslaught)
358 REGISTER_GAMETYPE(ONSLAUGHT, NEW(Onslaught));
359
360 #ifdef CSQC
361 void HUD_Mod_NexBall(vector pos, vector mySize);
362 #endif
363 CLASS(NexBall, Gametype)
364     INIT(NexBall)
365     {
366         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"));
367     }
368     METHOD(NexBall, m_generate_mapinfo, void(Gametype this, string v))
369     {
370         if(substring(v, 0, 8) == "nexball_" || substring(v, 0, 4) == "ball")
371             MapInfo_Map_supportedGametypes |= this.m_flags;
372     }
373     METHOD(NexBall, m_isTwoBaseMode, bool())
374     {
375         return true;
376     }
377 #ifdef CSQC
378     ATTRIB(NexBall, m_modicons, void(vector pos, vector mySize), HUD_Mod_NexBall);
379 #endif
380 ENDCLASS(NexBall)
381 REGISTER_GAMETYPE(NEXBALL, NEW(NexBall));
382 #define g_nexball IS_GAMETYPE(NEXBALL)
383
384 CLASS(FreezeTag, Gametype)
385     INIT(FreezeTag)
386     {
387         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"));
388     }
389     METHOD(FreezeTag, m_parse_mapinfo, bool(string k, string v))
390     {
391         if (!k) {
392             cvar_set("g_freezetag_teams", cvar_defstring("g_freezetag_teams"));
393             return true;
394         }
395         switch (k) {
396             case "teams":
397                 cvar_set("g_freezetag_teams", v);
398                 return true;
399         }
400         return false;
401     }
402     METHOD(FreezeTag, m_isAlwaysSupported, bool(Gametype this, int spawnpoints, float diameter))
403     {
404         if(spawnpoints >= 8 && diameter > 4096)
405             return true;
406         return false;
407     }
408 #ifdef CSQC
409     ATTRIB(FreezeTag, m_modicons, void(vector pos, vector mySize), HUD_Mod_CA);
410 #endif
411 ENDCLASS(FreezeTag)
412 REGISTER_GAMETYPE(FREEZETAG, NEW(FreezeTag));
413 #define g_freezetag IS_GAMETYPE(FREEZETAG)
414
415 #ifdef CSQC
416 void HUD_Mod_Keepaway(vector pos, vector mySize);
417 #endif
418 CLASS(Keepaway, Gametype)
419     INIT(Keepaway)
420     {
421         this.gametype_init(this, _("Keepaway"),"ka","g_keepaway",true,"","timelimit=20 pointlimit=30",_("Hold the ball to get points for kills"));
422     }
423     METHOD(Keepaway, m_isAlwaysSupported, bool(Gametype this, int spawnpoints, float diameter))
424     {
425         return true;
426     }
427 #ifdef CSQC
428     ATTRIB(Keepaway, m_modicons, void(vector pos, vector mySize), HUD_Mod_Keepaway);
429 #endif
430 ENDCLASS(Keepaway)
431 REGISTER_GAMETYPE(KEEPAWAY, NEW(Keepaway));
432
433 CLASS(Invasion, Gametype)
434     INIT(Invasion)
435     {
436         this.gametype_init(this, _("Invasion"),"inv","g_invasion",false,"","pointlimit=50 teams=0",_("Survive against waves of monsters"));
437     }
438     METHOD(Invasion, m_parse_mapinfo, bool(string k, string v))
439     {
440         switch (k) {
441             case "teams":
442                 cvar_set("g_invasion_teams", v);
443                 return true;
444         }
445         return false;
446     }
447     METHOD(Invasion, m_generate_mapinfo, void(Gametype this, string v))
448     {
449         if(v == "invasion_spawnpoint")
450             MapInfo_Map_supportedGametypes |= this.m_flags;
451     }
452 ENDCLASS(Invasion)
453 REGISTER_GAMETYPE(INVASION, NEW(Invasion));
454
455 const int MAPINFO_FEATURE_WEAPONS       = 1; // not defined for instagib-only maps
456 const int MAPINFO_FEATURE_VEHICLES      = 2;
457 const int MAPINFO_FEATURE_TURRETS       = 4;
458 const int MAPINFO_FEATURE_MONSTERS      = 8;
459
460 const int MAPINFO_FLAG_HIDDEN           = 1; // not in lsmaps/menu/vcall/etc., can just be changed to manually
461 const int MAPINFO_FLAG_FORBIDDEN        = 2; // don't even allow the map by a cvar setting that allows hidden maps
462 const int MAPINFO_FLAG_FRUSTRATING      = 4; // this map is near impossible to play, enable at your own risk
463 const int MAPINFO_FLAG_NOAUTOMAPLIST    = 8; // do not include when automatically building maplist (counts as hidden for maplist building purposes)
464
465 float MapInfo_count;
466
467 // load MapInfo_count; generate mapinfo for maps that miss them, and clear the
468 // cache; you need to call MapInfo_FilterGametype afterwards!
469 void MapInfo_Enumerate();
470
471 // filter the info by game type mask (updates MapInfo_count)
472 float MapInfo_progress;
473 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)
474 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)
475 void MapInfo_FilterString(string sf); // filter _MapInfo_filtered (created by MapInfo_FilterGametype) with keyword
476 int MapInfo_CurrentFeatures(); // retrieves currently required features from cvars
477 Gametype MapInfo_CurrentGametype(); // retrieves current gametype from cvars
478 int MapInfo_ForbiddenFlags(); // retrieves current flags from cvars
479 int MapInfo_RequiredFlags(); // retrieves current flags from cvars
480
481 // load info about the i-th map into the MapInfo_Map_* globals
482 float MapInfo_Get_ByID(float i); // 1 on success, 0 on failure
483 string MapInfo_BSPName_ByID(float i);
484
485 // load info about a map by name into the MapInfo_Map_* globals
486 int MapInfo_Get_ByName(string s, float allowGenerate, Gametype gametypeToSet); // 1 on success, 0 on failure, 2 if it autogenerated a mapinfo file
487
488 // look for a map by a prefix, returns the actual map name on success, string_null on failure or ambigous match
489 string MapInfo_FindName_match; // the name of the map that was found
490 float MapInfo_FindName_firstResult; // -1 if none were found, index of first one if not unique but found (FindName then returns -1)
491 float MapInfo_FindName(string s);
492 string MapInfo_FixName(string s);
493
494 // play a map
495 float MapInfo_CheckMap(string s); // returns 0 if the map can't be played with the current settings
496 void MapInfo_LoadMap(string s, float reinit);
497
498 // list all maps for the current game type
499 string MapInfo_ListAllowedMaps(Gametype type, float pFlagsRequired, float pFlagsForbidden);
500 // list all allowed maps (for any game type)
501 string MapInfo_ListAllAllowedMaps(float pFlagsRequired, float pFlagsForbidden);
502
503 // gets a gametype from a string
504 string _MapInfo_GetDefaultEx(Gametype t);
505 float _MapInfo_GetTeamPlayBool(Gametype t);
506 Gametype MapInfo_Type_FromString(string t);
507 string MapInfo_Type_Description(Gametype t);
508 string MapInfo_Type_ToString(Gametype t);
509 string MapInfo_Type_ToText(Gametype t);
510 void MapInfo_SwitchGameType(Gametype t);
511
512 // to be called from worldspawn to set up cvars
513 void MapInfo_LoadMapSettings(string s);
514 Gametype MapInfo_LoadedGametype; // game type that was active during map load
515
516 void MapInfo_Cache_Destroy(); // disable caching
517 void MapInfo_Cache_Create(); // enable caching
518 void MapInfo_Cache_Invalidate(); // delete cache if any, but keep enabled
519
520 void MapInfo_ClearTemps(); // call this when done with mapinfo for this frame
521
522 void MapInfo_Shutdown(); // call this in the shutdown handler
523
524 #define MAPINFO_SETTEMP_ACL_USER cvar_string("g_mapinfo_settemp_acl")
525 #define MAPINFO_SETTEMP_ACL_SYSTEM "-g_mapinfo_* -rcon_* -_* -g_ban* +*"