From: Mario <mario@smbclan.net>
Date: Sat, 29 Sep 2018 06:33:29 +0000 (+1000)
Subject: Add a property to tell when gamemodes are supposed to be forced supported (TDM on... 
X-Git-Tag: xonotic-v0.8.5~1821
X-Git-Url: https://git.rm.cloudns.org/?a=commitdiff_plain;h=0edde87771462b5782fc058cce40167d3506ca9c;p=xonotic%2Fxonotic-data.pk3dir.git

Add a property to tell when gamemodes are supposed to be forced supported (TDM on DM maps)
---

diff --git a/qcsrc/common/mapinfo.qc b/qcsrc/common/mapinfo.qc
index 859ec51d5..17093f88e 100644
--- a/qcsrc/common/mapinfo.qc
+++ b/qcsrc/common/mapinfo.qc
@@ -1067,13 +1067,7 @@ int MapInfo_Get_ByName(string pFilename, float pAllowGenerate, Gametype pGametyp
 {
 	int r = MapInfo_Get_ByName_NoFallbacks(pFilename, pAllowGenerate, pGametypeToSet);
 
-	if(cvar("g_tdm_on_dm_maps"))
-	{
-		// if this is set, all DM maps support TDM too
-		if (!(MapInfo_Map_supportedGametypes & MAPINFO_TYPE_TEAM_DEATHMATCH.m_flags))
-			if(MapInfo_Map_supportedGametypes & MAPINFO_TYPE_DEATHMATCH.m_flags)
-				_MapInfo_Map_ApplyGametypeEx ("", pGametypeToSet, MAPINFO_TYPE_TEAM_DEATHMATCH);
-	}
+	FOREACH(Gametypes, it.m_isForcedSupported(it), _MapInfo_Map_ApplyGametypeEx("", pGametypeToSet, it));
 
 	if(pGametypeToSet)
 	{
diff --git a/qcsrc/common/mapinfo.qh b/qcsrc/common/mapinfo.qh
index 4addd2400..63723afd7 100644
--- a/qcsrc/common/mapinfo.qh
+++ b/qcsrc/common/mapinfo.qh
@@ -57,6 +57,10 @@ CLASS(Gametype, Object)
     {
         return false;
     }
+    METHOD(Gametype, m_isForcedSupported, bool(Gametype this))
+    {
+        return false;
+    }
 
     METHOD(Gametype, describe, string(Gametype this))
     {
@@ -202,6 +206,16 @@ CLASS(TeamDeathmatch, Gametype)
             return true;
         return false;
     }
+    METHOD(TeamDeathmatch, m_isForcedSupported, bool(Gametype this))
+    {
+        if(cvar("g_tdm_on_dm_maps"))
+        {
+            // if this is set, all DM maps support TDM too
+            if(!(MapInfo_Map_supportedGametypes & this.m_flags) && (MapInfo_Map_supportedGametypes & MAPINFO_TYPE_DEATHMATCH.m_flags))
+                return true; // TODO: references another gametype (alternatively, we could check which gamemodes are always enabled and append this if any are supported)
+        }
+        return false;
+    }
     METHOD(TeamDeathmatch, m_setTeams, void(string sa))
     {
         cvar_set("g_tdm_teams", sa);