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