share/hedgewars/Data/Scripts/Multiplayer/Mutant.lua
changeset 15274 96fbf9bb960a
parent 15074 e16f906224fd
child 15463 19e987301674
equal deleted inserted replaced
15273:07836d6bac21 15274:96fbf9bb960a
    55 
    55 
    56 local winScore = 15
    56 local winScore = 15
    57 local hogsLimit = 1
    57 local hogsLimit = 1
    58 
    58 
    59 local teamsDead = {}
    59 local teamsDead = {}
       
    60 local teamsDeleted = {}
       
    61 local hogLimitHit = false
       
    62 local cnthhs
    60 
    63 
    61 local circles = {}
    64 local circles = {}
    62 local circleFrame = -1
    65 local circleFrame = -1
    63 
    66 
    64 -- Variables for custom achievements
    67 -- Variables for custom achievements
   141     -- King Mode messes with game too much
   144     -- King Mode messes with game too much
   142     DisableGameFlags(gfKing)
   145     DisableGameFlags(gfKing)
   143 end
   146 end
   144 
   147 
   145 
   148 
   146 function limitHogs(gear)
   149 function limitHogsTeam(gear)
   147     cnthhs = cnthhs + 1
   150     cnthhs = cnthhs + 1
   148     if cnthhs > 1 then
   151     if cnthhs > 1 then
   149         hogLimitHit = true
   152         hogLimitHit = true
   150         SetEffect(gear, heResurrectable, 0)
   153         SetEffect(gear, heResurrectable, 0)
   151         setGearValue(gear, "excess", true)
   154         setGearValue(gear, "excess", true)
   152         DeleteGear(gear)
   155         DeleteGear(gear)
   153     end
   156     end
   154 end
   157 end
   155 
   158 
       
   159 function limitHogsClan(gear)
       
   160     hogLimitHit = true
       
   161     SetEffect(gear, heResurrectable, 0)
       
   162     setGearValue(gear, "excess", true)
       
   163     DeleteGear(gear)
       
   164 end
       
   165 
   156 function onGameStart()
   166 function onGameStart()
   157     if ClansCount >= 2 then
   167     if ClansCount >= 2 then
   158         SendHealthStatsOff()
   168         SendHealthStatsOff()
   159         SendAchievementsStatsOff()
   169         SendAchievementsStatsOff()
   160     end
   170     end
   161     SendRankingStatsOff()
   171     SendRankingStatsOff()
   162     trackTeams()
   172     trackTeams()
   163     teamScan()
   173     teamScan()
   164     runOnHogs(saveStuff)
   174     runOnHogs(saveStuff)
   165 
   175 
       
   176     -- Enforce team and hog limits
   166     hogLimitHit = false
   177     hogLimitHit = false
       
   178 
       
   179     -- Rule 1: One team per clan
       
   180     if TeamsCount > ClansCount then
       
   181         local usedClans = {}
       
   182         for i=0, TeamsCount - 1 do
       
   183             local teamName = GetTeamName(i)
       
   184             local clanNumber = GetTeamClan(teamName)
       
   185             if not usedClans[clanNumber] then
       
   186                 usedClans[clanNumber] = true
       
   187             else
       
   188                 runOnHogsInTeam(limitHogsClan, teamName)
       
   189                 teamsDeleted[teamName] = true
       
   190                 setTeamValue(teamName, "Score", getTeamValue(teamName, "Score") -99999)
       
   191             end
       
   192         end
       
   193     end
       
   194 
       
   195     -- Rule 2: One hog per team
   167     for i=0 , TeamsCount - 1 do
   196     for i=0 , TeamsCount - 1 do
   168         cnthhs = 0
   197         cnthhs = 0
   169         runOnHogsInTeam(limitHogs, GetTeamName(i))
   198         runOnHogsInTeam(limitHogsTeam, GetTeamName(i))
   170     end
   199     end
   171     if hogLimitHit then
   200     if hogLimitHit then
       
   201         -- TODO: Update warning message to include excess teams as well
   172         WriteLnToChat(loc("Only one hog per team allowed! Excess hogs will be removed."))
   202         WriteLnToChat(loc("Only one hog per team allowed! Excess hogs will be removed."))
   173     end
   203     end
       
   204     trackTeams()
   174     showStartingInfo()
   205     showStartingInfo()
   175 end
   206 end
   176 
   207 
   177 
   208 
   178 
   209 
   232     circleFrame = 0
   263     circleFrame = 0
   233 end
   264 end
   234 
   265 
   235 function onNewTurn()
   266 function onNewTurn()
   236 
   267 
   237     trackTeams()
       
   238     killsCounter = 0
   268     killsCounter = 0
   239 
   269 
   240     if mutant == nil and TotalRounds >= 0 then
   270     if mutant == nil and TotalRounds >= 0 then
   241         AddCaption( loc("First killer will mutate"), capcolDefault, capgrpGameState )
   271         AddCaption( loc("First killer will mutate"), capcolDefault, capgrpGameState )
   242     end
   272     end
   243 
   273 
   244     checkScore()
   274     checkScore()
   245 
   275 
   246     for i=0, TeamsCount-1 do
   276     for i=0, TeamsCount-1 do
   247         SendStat(siClanHealth, getTeamValue(GetTeamName(i), "Score"), GetTeamName(i))
   277         local teamName = GetTeamName(i)
       
   278         if not teamsDeleted[teamName] then
       
   279             SendStat(siClanHealth, getTeamValue(teamName, "Score"), teamName)
       
   280         end
   248     end
   281     end
   249 
   282 
   250     giveWeapons(CurrentHedgehog)
   283     giveWeapons(CurrentHedgehog)
   251     drawCircles()
   284     drawCircles()
   252     setAIHints()
   285     setAIHints()
   610 end
   643 end
   611 
   644 
   612 function teamScan()
   645 function teamScan()
   613 
   646 
   614         for j=0, TeamsCount-1 do
   647         for j=0, TeamsCount-1 do
   615             teamName = GetTeamName(j)
   648             local teamName = GetTeamName(j)
   616             teamsDead[teamName] = false
   649             teamsDead[teamName] = false
   617             setTeamValue(teamName, "Score",0)
   650             setTeamValue(teamName, "Score",0)
   618             setTeamValue(teamName, "Suicides",0)
   651             setTeamValue(teamName, "Suicides",0)
   619             setTeamValue(teamName, "Skips",0)
   652             setTeamValue(teamName, "Skips",0)
   620             setTeamValue(teamName, "Crates",0)
   653             setTeamValue(teamName, "Crates",0)