#pragma once

#include <common/gametypes/gametype/deathmatch/deathmatch.qh>
#include <common/gametypes/gametype/tdm/tdm.qh>
#include <common/mapinfo.qh>

CLASS(tmayhem, Gametype)
	INIT(tmayhem)
	{
		this.gametype_init(this, _("Team Mayhem"),"tmayhem","g_tmayhem",GAMETYPE_FLAG_TEAMPLAY | GAMETYPE_FLAG_USEPOINTS,"","timelimit=20 pointlimit=1500 teams=2 leadlimit=0",_("Compete along with your team for the most damage dealt and frags in this chaotic mayhem"));
	}
	METHOD(tmayhem, m_parse_mapinfo, bool(string k, string v))
	{
		if (!k)
		{
			cvar_set("g_tmayhem_teams", cvar_defstring("g_tmayhem_teams"));
			return true;
		}
		switch (k)
		{
			case "teams":
				cvar_set("g_tmayhem_teams", v);
				return true;
		}
		return false;
	}
	METHOD(tmayhem, m_isAlwaysSupported, bool(Gametype this, int spawnpoints, float diameter))
	{
		return true;
	}
	METHOD(tmayhem, m_isForcedSupported, bool(Gametype this))
	{
		if(!(MapInfo_Map_supportedGametypes & this.gametype_flags) && (MapInfo_Map_supportedGametypes & MAPINFO_TYPE_DEATHMATCH.gametype_flags)){
			return true;
		}
		if(!(MapInfo_Map_supportedGametypes & this.gametype_flags) && (MapInfo_Map_supportedGametypes & MAPINFO_TYPE_TEAM_DEATHMATCH.gametype_flags)){
			return true;
		}
		return false;
	}
	METHOD(tmayhem, m_setTeams, void(string sa))
	{
		cvar_set("g_tmayhem_teams", sa);
	}
	METHOD(tmayhem, m_configuremenu, void(Gametype this, entity menu, void(entity me, string pLabel, float pMin, float pMax, float pStep, string pCvar, string tCvar, string pTooltip) returns))
	{
		TC(Gametype, this);
		returns(menu, _("Point limit:"),     200,  3000,  100, "g_tmayhem_point_limit",         "g_tmayhem_teams_override",         _("How much score is needed before the match will end"));
	}
	ATTRIB(tmayhem, m_legacydefaults, string, "1500 20 2 0");
ENDCLASS(tmayhem)
REGISTER_GAMETYPE(TEAM_MAYHEM, NEW(tmayhem));
#define g_tmayhem IS_GAMETYPE(TEAM_MAYHEM)
