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