share/hedgewars/Data/Scripts/Multiplayer/Capture_the_Flag.lua
changeset 15010 5188ecbf726f
parent 14599 50f511588635
child 15088 d59da429d22c
equal deleted inserted replaced
15009:0ebecd424fc7 15010:5188ecbf726f
   135 local fGearTimer = 0
   135 local fGearTimer = 0
   136 
   136 
   137 ------------------------
   137 ------------------------
   138 --flag methods
   138 --flag methods
   139 ------------------------
   139 ------------------------
       
   140 
       
   141 local RankTeams = function(teamList)
       
   142 	local teamRank = function(a, b)
       
   143 		if a.score ~= b.score then
       
   144 			return a.score > b.score
       
   145 		else
       
   146 			return a.clan > b.clan
       
   147 		end
       
   148 	end
       
   149 	table.sort(teamList, teamRank)
       
   150 	local rank, plusRank, score, clan
       
   151 	for i=1, #teamList do
       
   152 		if i == 1 then
       
   153 			rank = 1
       
   154 			plusRank = 1
       
   155 			score = teamList[i].score
       
   156 			clan = teamList[i].clan
       
   157 		end
       
   158 		if (teamList[i].score < score) then
       
   159 			rank = rank + plusRank
       
   160 			plusRank = 1
       
   161 		end
       
   162 		if (teamList[i].score == score and teamList[i].clan ~= clan) then
       
   163 			plusRank = plusRank + 1
       
   164 		end
       
   165 		teamList[i].rank = rank
       
   166 		score = teamList[i].score
       
   167 		clan = teamList[i].clan
       
   168 	end
       
   169 
       
   170 	for i=1, #teamList do
       
   171 		SendStat(siPointType, "!POINTS")
       
   172 		SendStat(siTeamRank, tostring(teamList[i].rank))
       
   173 		SendStat(siPlayerKills, tostring(teamList[i].score), teamList[i].name)
       
   174 	end
       
   175 end
   140 
   176 
   141 function CheckScore(clanID)
   177 function CheckScore(clanID)
   142 
   178 
   143 	if fCaptures[clanID] == captureLimit then
   179 	if fCaptures[clanID] == captureLimit then
   144 		gameOver = true
   180 		gameOver = true
   163 		for i=0, TeamsCount-1 do
   199 		for i=0, TeamsCount-1 do
   164 			local name = GetTeamName(i)
   200 			local name = GetTeamName(i)
   165 			local clan = GetTeamClan(name)
   201 			local clan = GetTeamClan(name)
   166 			table.insert(teamList, { score = fCaptures[clan], name = name, clan = clan })
   202 			table.insert(teamList, { score = fCaptures[clan], name = name, clan = clan })
   167 		end
   203 		end
   168 		local teamRank = function(a, b)
   204 		RankTeams(teamList)
   169 			return a.score > b.score
       
   170 		end
       
   171 		table.sort(teamList, teamRank)
       
   172 
       
   173 		for i=1, #teamList do
       
   174 			SendStat(siPointType, "!POINTS")
       
   175 			SendStat(siPlayerKills, tostring(teamList[i].score), teamList[i].name)
       
   176 		end
       
   177 
   205 
   178 		if mostCaptures >= 2 then
   206 		if mostCaptures >= 2 then
   179 			SendStat(siCustomAchievement, string.format(loc("%s (%s) has captured the flag %d times."), mostCapturesHogName, mostCapturesHogTeam, mostCaptures))
   207 			SendStat(siCustomAchievement, string.format(loc("%s (%s) has captured the flag %d times."), mostCapturesHogName, mostCapturesHogTeam, mostCaptures))
   180 		end
   208 		end
   181 	end
   209 	end