3 bool autocvar_developer_mapper;
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
13 CLASS(Gametype, Object)
14 ATTRIB(Gametype, m_id, int, 0);
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);
30 ATTRIB(Gametype, m_mutators, string);
31 METHOD(Gametype, m_parse_mapinfo, bool(string k, string v))
36 METHOD(Gametype, describe, string(Gametype this))
39 return this.gametype_description;
42 METHOD(Gametype, display, void(Gametype this, void(string name, string icon) returns))
45 returns(this.message, strcat("gametype_", this.mdl));
48 METHOD(Gametype, gametype_init, void(Gametype this, string hname, string sname, string g_name, bool gteamplay, string mutators, string defaults, string gdescription))
50 this.netname = g_name;
53 this.team = gteamplay;
54 this.m_mutators = cons(sname, mutators);
55 this.model2 = defaults;
56 this.gametype_description = gdescription;
58 // same as `1 << m_id`
59 MAPINFO_TYPE_ALL |= this.items = this.m_flags = (MAPINFO_TYPE_ALL + 1);
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)
69 #define IS_GAMETYPE(NAME) (MapInfo_LoadedGametype == MAPINFO_TYPE_##NAME)
71 CLASS(Deathmatch, Gametype)
74 this.gametype_init(this, _("Deathmatch"),"dm","g_dm",false,"","timelimit=20 pointlimit=30 leadlimit=0",_("Score as many frags as you can"));
77 REGISTER_GAMETYPE(DEATHMATCH, NEW(Deathmatch));
79 CLASS(LastManStanding, Gametype)
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"));
84 ENDCLASS(LastManStanding)
85 REGISTER_GAMETYPE(LMS, NEW(LastManStanding));
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"));
92 METHOD(Race, m_parse_mapinfo, bool(string k, string v))
95 cvar_set("g_race_qualifying_timelimit", cvar_defstring("g_race_qualifying_timelimit"));
99 case "qualifying_timelimit":
100 cvar_set("g_race_qualifying_timelimit", v);
106 REGISTER_GAMETYPE(RACE, NEW(Race));
107 #define g_race IS_GAMETYPE(RACE)
109 CLASS(RaceCTS, Gametype)
112 this.gametype_init(this, _("Race CTS"),"cts","g_cts",false,"cloaked","timelimit=20",_("Race for fastest time."));
115 REGISTER_GAMETYPE(CTS, NEW(RaceCTS));
116 #define g_cts IS_GAMETYPE(CTS)
118 CLASS(TeamDeathmatch, Gametype)
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"));
123 METHOD(TeamDeathmatch, m_parse_mapinfo, bool(string k, string v))
126 cvar_set("g_tdm_teams", cvar_defstring("g_tdm_teams"));
131 cvar_set("g_tdm_teams", v);
136 ENDCLASS(TeamDeathmatch)
137 REGISTER_GAMETYPE(TEAM_DEATHMATCH, NEW(TeamDeathmatch));
138 #define g_tdm IS_GAMETYPE(TEAM_DEATHMATCH)
140 CLASS(CaptureTheFlag, Gametype)
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"));
145 ENDCLASS(CaptureTheFlag)
146 REGISTER_GAMETYPE(CTF, NEW(CaptureTheFlag));
147 #define g_ctf IS_GAMETYPE(CTF)
149 CLASS(ClanArena, Gametype)
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"));
154 METHOD(ClanArena, m_parse_mapinfo, bool(string k, string v))
157 cvar_set("g_ca_teams", cvar_defstring("g_ca_teams"));
162 cvar_set("g_ca_teams", v);
168 REGISTER_GAMETYPE(CA, NEW(ClanArena));
169 #define g_ca IS_GAMETYPE(CA)
171 CLASS(Domination, Gametype)
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"));
176 METHOD(Domination, m_parse_mapinfo, bool(string k, string v))
179 cvar_set("g_domination_default_teams", cvar_defstring("g_domination_default_teams"));
184 cvar_set("g_domination_default_teams", v);
190 REGISTER_GAMETYPE(DOMINATION, NEW(Domination));
192 CLASS(KeyHunt, Gametype)
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"));
197 METHOD(KeyHunt, m_parse_mapinfo, bool(string k, string v))
200 cvar_set("g_keyhunt_teams", cvar_defstring("g_keyhunt_teams"));
205 cvar_set("g_keyhunt_teams", v);
211 REGISTER_GAMETYPE(KEYHUNT, NEW(KeyHunt));
213 CLASS(Assault, Gametype)
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"));
219 REGISTER_GAMETYPE(ASSAULT, NEW(Assault));
220 #define g_assault IS_GAMETYPE(ASSAULT)
222 CLASS(Onslaught, Gametype)
225 this.gametype_init(this, _("Onslaught"),"ons","g_onslaught",true,"","pointlimit=1 timelimit=20",_("Capture control points to reach and destroy the enemy generator"));
228 REGISTER_GAMETYPE(ONSLAUGHT, NEW(Onslaught));
230 CLASS(NexBall, Gametype)
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"));
236 REGISTER_GAMETYPE(NEXBALL, NEW(NexBall));
237 #define g_nexball IS_GAMETYPE(NEXBALL)
239 CLASS(FreezeTag, Gametype)
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"));
244 METHOD(FreezeTag, m_parse_mapinfo, bool(string k, string v))
247 cvar_set("g_freezetag_teams", cvar_defstring("g_freezetag_teams"));
252 cvar_set("g_freezetag_teams", v);
258 REGISTER_GAMETYPE(FREEZETAG, NEW(FreezeTag));
259 #define g_freezetag IS_GAMETYPE(FREEZETAG)
261 CLASS(Keepaway, Gametype)
264 this.gametype_init(this, _("Keepaway"),"ka","g_keepaway",true,"","timelimit=20 pointlimit=30",_("Hold the ball to get points for kills"));
267 REGISTER_GAMETYPE(KEEPAWAY, NEW(Keepaway));
269 CLASS(Invasion, Gametype)
272 this.gametype_init(this, _("Invasion"),"inv","g_invasion",false,"","pointlimit=50 teams=0",_("Survive against waves of monsters"));
274 METHOD(Invasion, m_parse_mapinfo, bool(string k, string v))
278 cvar_set("g_invasion_teams", v);
284 REGISTER_GAMETYPE(INVASION, NEW(Invasion));
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;
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)
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!
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();
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
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);
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
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);
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);
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);
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);
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
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
365 void MapInfo_ClearTemps(); // call this when done with mapinfo for this frame
367 void MapInfo_Shutdown(); // call this in the shutdown handler
369 #define MAPINFO_SETTEMP_ACL_USER cvar_string("g_mapinfo_settemp_acl")
370 #define MAPINFO_SETTEMP_ACL_SYSTEM "-g_mapinfo_* -rcon_* -_* -g_ban* +*"