-entity MapInfo_Type_first;
-entity MapInfo_Type_last;
-.entity enemy; // internal next pointer
-
-.int items; // game type ID
-.string netname; // game type name as in cvar (with g_ prefix)
-.string mdl; // game type short name
-.string message; // human readable name
-.int team; // does this gametype support teamplay?
-.string model2; // game type defaults
-.string gametype_description; // game type description
-
-#define REGISTER_GAMETYPE(hname,sname,g_name,NAME,gteamplay,defaults,gdescription) \
- int MAPINFO_TYPE_##NAME; \
- entity MapInfo_Type##g_name; \
- void RegisterGametypes_##g_name() \
- { \
- MAPINFO_TYPE_##NAME = MAPINFO_TYPE_ALL + 1; \
- MAPINFO_TYPE_ALL |= MAPINFO_TYPE_##NAME; \
- MapInfo_Type##g_name = spawn(); \
- MapInfo_Type##g_name.items = MAPINFO_TYPE_##NAME; \
- MapInfo_Type##g_name.netname = #g_name; \
- MapInfo_Type##g_name.mdl = #sname; \
- MapInfo_Type##g_name.message = hname; \
- MapInfo_Type##g_name.team = gteamplay; \
- MapInfo_Type##g_name.model2 = defaults; \
- MapInfo_Type##g_name.gametype_description = gdescription; \
- if(!MapInfo_Type_first) \
- MapInfo_Type_first = MapInfo_Type##g_name; \
- if(MapInfo_Type_last) \
- MapInfo_Type_last.enemy = MapInfo_Type##g_name; \
- MapInfo_Type_last = MapInfo_Type##g_name; \
- } \
- ACCUMULATE_FUNCTION(RegisterGametypes, RegisterGametypes_##g_name)
-
-#define IS_GAMETYPE(NAME) \
- (MapInfo_LoadedGametype == MAPINFO_TYPE_##NAME)
-
-REGISTER_GAMETYPE(_("Deathmatch"),dm,g_dm,DEATHMATCH,false,"timelimit=20 pointlimit=30 leadlimit=0",_("Kill all enemies"));
-#define g_dm IS_GAMETYPE(DEATHMATCH)
-
-REGISTER_GAMETYPE(_("Last Man Standing"),lms,g_lms,LMS,false,"timelimit=20 lives=9 leadlimit=0",_("Survive and kill until the enemies have no lives left"));
-#define g_lms IS_GAMETYPE(LMS)
-
-REGISTER_GAMETYPE(_("Race"),rc,g_race,RACE,false,"timelimit=20 qualifying_timelimit=5 laplimit=7 teamlaplimit=15 leadlimit=0",_("Race against other players to the finish line"));
+.int m_flags;
+
+CLASS(Gametype, Object)
+ ATTRIB(Gametype, m_id, int, 0);
+ /** game type ID */
+ ATTRIB(Gametype, items, int, 0);
+ /** game type name as in cvar (with g_ prefix) */
+ ATTRIB(Gametype, netname, string);
+ /** game type short name */
+ ATTRIB(Gametype, mdl, string);
+ /** human readable name */
+ ATTRIB(Gametype, message, string);
+ /** does this gametype support teamplay? */
+ ATTRIB(Gametype, team, bool, false);
+ /** game type defaults */
+ ATTRIB(Gametype, model2, string);
+ /** game type description */
+ ATTRIB(Gametype, gametype_description, string);
+#ifdef CSQC
+ ATTRIB(Gametype, m_modicons, void(vector pos, vector mySize));
+ ATTRIB(Gametype, m_modicons_reset, void());
+#endif
+
+ ATTRIB(Gametype, m_mutators, string);
+ METHOD(Gametype, m_parse_mapinfo, bool(string k, string v))
+ {
+ return false;
+ }
+ METHOD(Gametype, m_generate_mapinfo, void(Gametype this, string v))
+ {
+ TC(Gametype, this);
+ }
+ METHOD(Gametype, m_isTwoBaseMode, bool())
+ {
+ return false;
+ }
+ METHOD(Gametype, m_isAlwaysSupported, bool(Gametype this, int spawnpoints, float diameter))
+ {
+ return false;
+ }
+
+ METHOD(Gametype, describe, string(Gametype this))
+ {
+ TC(Gametype, this);
+ return this.gametype_description;
+ }
+
+ METHOD(Gametype, display, void(Gametype this, void(string name, string icon) returns))
+ {
+ TC(Gametype, this);
+ returns(this.message, strcat("gametype_", this.mdl));
+ }
+
+ METHOD(Gametype, gametype_init, void(Gametype this, string hname, string sname, string g_name, bool gteamplay, string mutators, string defaults, string gdescription))
+ {
+ this.netname = g_name;
+ this.mdl = sname;
+ this.message = hname;
+ this.team = gteamplay;
+ this.m_mutators = cons(sname, mutators);
+ this.model2 = defaults;
+ this.gametype_description = gdescription;
+
+ // same as `1 << m_id`
+ MAPINFO_TYPE_ALL |= this.items = this.m_flags = (MAPINFO_TYPE_ALL + 1);
+ }
+ENDCLASS(Gametype)
+
+REGISTRY(Gametypes, 24)
+#define Gametypes_from(i) _Gametypes_from(i, NULL)
+REGISTER_REGISTRY(Gametypes)
+REGISTRY_CHECK(Gametypes)
+#define REGISTER_GAMETYPE(NAME, inst) REGISTER(Gametypes, MAPINFO_TYPE, NAME, m_id, inst)
+
+#define IS_GAMETYPE(NAME) (MapInfo_LoadedGametype == MAPINFO_TYPE_##NAME)
+
+CLASS(Deathmatch, Gametype)
+ INIT(Deathmatch)
+ {
+ this.gametype_init(this, _("Deathmatch"),"dm","g_dm",false,"","timelimit=20 pointlimit=30 leadlimit=0",_("Score as many frags as you can"));
+ }
+ METHOD(Deathmatch, m_isAlwaysSupported, bool(Gametype this, int spawnpoints, float diameter))
+ {
+ return true;
+ }
+ENDCLASS(Deathmatch)
+REGISTER_GAMETYPE(DEATHMATCH, NEW(Deathmatch));
+
+CLASS(LastManStanding, Gametype)
+ INIT(LastManStanding)
+ {
+ 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"));
+ }
+ METHOD(LastManStanding, m_isAlwaysSupported, bool(Gametype this, int spawnpoints, float diameter))
+ {
+ return true;
+ }
+ENDCLASS(LastManStanding)
+REGISTER_GAMETYPE(LMS, NEW(LastManStanding));
+
+#ifdef CSQC
+void HUD_Mod_Race(vector pos, vector mySize);
+#endif
+CLASS(Race, Gametype)
+ INIT(Race)
+ {
+ 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"));
+ }
+ METHOD(Race, m_parse_mapinfo, bool(string k, string v))
+ {
+ if (!k) {
+ cvar_set("g_race_qualifying_timelimit", cvar_defstring("g_race_qualifying_timelimit"));
+ return true;
+ }
+ switch (k) {
+ case "qualifying_timelimit":
+ cvar_set("g_race_qualifying_timelimit", v);
+ return true;
+ }
+ return false;
+ }
+ METHOD(Race, m_generate_mapinfo, void(Gametype this, string v))
+ {
+ if(v == "trigger_race_checkpoint")
+ MapInfo_Map_supportedGametypes |= this.m_flags;
+ }
+ METHOD(Race, m_isTwoBaseMode, bool())
+ {
+ return true;
+ }
+#ifdef CSQC
+ ATTRIB(Race, m_modicons, void(vector pos, vector mySize), HUD_Mod_Race);
+#endif
+ENDCLASS(Race)
+REGISTER_GAMETYPE(RACE, NEW(Race));