share/hedgewars/Data/Scripts/Multiplayer/Mutant.lua
changeset 15269 96fbf9bb960a
parent 15069 e16f906224fd
child 15458 19e987301674
--- a/share/hedgewars/Data/Scripts/Multiplayer/Mutant.lua	Thu Jul 25 11:58:40 2019 -0400
+++ b/share/hedgewars/Data/Scripts/Multiplayer/Mutant.lua	Thu Jul 25 18:40:06 2019 +0200
@@ -57,6 +57,9 @@
 local hogsLimit = 1
 
 local teamsDead = {}
+local teamsDeleted = {}
+local hogLimitHit = false
+local cnthhs
 
 local circles = {}
 local circleFrame = -1
@@ -143,7 +146,7 @@
 end
 
 
-function limitHogs(gear)
+function limitHogsTeam(gear)
     cnthhs = cnthhs + 1
     if cnthhs > 1 then
         hogLimitHit = true
@@ -153,6 +156,13 @@
     end
 end
 
+function limitHogsClan(gear)
+    hogLimitHit = true
+    SetEffect(gear, heResurrectable, 0)
+    setGearValue(gear, "excess", true)
+    DeleteGear(gear)
+end
+
 function onGameStart()
     if ClansCount >= 2 then
         SendHealthStatsOff()
@@ -163,14 +173,35 @@
     teamScan()
     runOnHogs(saveStuff)
 
+    -- Enforce team and hog limits
     hogLimitHit = false
+
+    -- Rule 1: One team per clan
+    if TeamsCount > ClansCount then
+        local usedClans = {}
+        for i=0, TeamsCount - 1 do
+            local teamName = GetTeamName(i)
+            local clanNumber = GetTeamClan(teamName)
+            if not usedClans[clanNumber] then
+                usedClans[clanNumber] = true
+            else
+                runOnHogsInTeam(limitHogsClan, teamName)
+                teamsDeleted[teamName] = true
+                setTeamValue(teamName, "Score", getTeamValue(teamName, "Score") -99999)
+            end
+        end
+    end
+
+    -- Rule 2: One hog per team
     for i=0 , TeamsCount - 1 do
         cnthhs = 0
-        runOnHogsInTeam(limitHogs, GetTeamName(i))
+        runOnHogsInTeam(limitHogsTeam, GetTeamName(i))
     end
     if hogLimitHit then
+        -- TODO: Update warning message to include excess teams as well
         WriteLnToChat(loc("Only one hog per team allowed! Excess hogs will be removed."))
     end
+    trackTeams()
     showStartingInfo()
 end
 
@@ -234,7 +265,6 @@
 
 function onNewTurn()
 
-    trackTeams()
     killsCounter = 0
 
     if mutant == nil and TotalRounds >= 0 then
@@ -244,7 +274,10 @@
     checkScore()
 
     for i=0, TeamsCount-1 do
-        SendStat(siClanHealth, getTeamValue(GetTeamName(i), "Score"), GetTeamName(i))
+        local teamName = GetTeamName(i)
+        if not teamsDeleted[teamName] then
+            SendStat(siClanHealth, getTeamValue(teamName, "Score"), teamName)
+        end
     end
 
     giveWeapons(CurrentHedgehog)
@@ -612,7 +645,7 @@
 function teamScan()
 
         for j=0, TeamsCount-1 do
-            teamName = GetTeamName(j)
+            local teamName = GetTeamName(j)
             teamsDead[teamName] = false
             setTeamValue(teamName, "Score",0)
             setTeamValue(teamName, "Suicides",0)