# HG changeset patch # User Wuzzy # Date 1460546228 -7200 # Node ID e1bae42efacde4a674cde14f75d4aa4dd814a028 # Parent c17e5ac9f76db7f7a63f128a1c46c6eecaaaac40 TechRacer: Show racing times and ranking in stats screen diff -r c17e5ac9f76d -r e1bae42efacd share/hedgewars/Data/Scripts/Multiplayer/TechRacer.lua --- a/share/hedgewars/Data/Scripts/Multiplayer/TechRacer.lua Wed Apr 13 13:16:01 2016 +0200 +++ b/share/hedgewars/Data/Scripts/Multiplayer/TechRacer.lua Wed Apr 13 13:17:08 2016 +0200 @@ -457,14 +457,46 @@ -- end game if its at round limit if roundNumber >= roundLimit then - for i = 0, (numhhs-1) do - if GetHogClan(hhs[i]) ~= bestClan then - SetEffect(hhs[i], heResurrectable, 0) - SetHealth(hhs[i],0) + gameOver = true + TurnTimeLeft = 10000000 + + -- Sort the scores for the ranking list + local unfinishedArray = {} + local sortedTeams = {} + local k = 1 + for i = 0, TeamsCount-1 do + if teamScore[i] ~= -1 and teamNameArr[i] ~= " " then + sortedTeams[k] = {} + sortedTeams[k].name = teamNameArr[i] + sortedTeams[k].score = teamScore[i] + k = k + 1 + else + table.insert(unfinishedArray, string.format(loc("%s did not finish the race."), teamNameArr[i])) end end - gameOver = true - TurnTimeLeft = 1 + table.sort(sortedTeams, function(team1, team2) return team1.score < team2.score end) + + -- Write all the stats! + + for i = 1, #sortedTeams do + SendStat(siPointType, loc("milliseconds")) + SendStat(siPlayerKills, sortedTeams[i].score, sortedTeams[i].name) + end + + if #sortedTeams >= 1 then + SendStat(siGameResult, string.format(loc("%s wins!"), sortedTeams[1].name)) + SendStat(siCustomAchievement, string.format(loc("%s wins with a best time of %.1fs."), sortedTeams[1].name, (sortedTeams[1].score/1000))) + for i=1,#unfinishedArray do + SendStat(siCustomAchievement, unfinishedArray[i]) + end + else + SendStat(siGameResult, loc("Round draw")) + SendStat(siCustomAchievement, loc("Nobody managed to finish the race. What a shame!")) + SendStat(siCustomAchievement, loc("Maybe you should try an easier TechRacer map.")) + end + + -- Game over + EndGame() end end @@ -915,6 +947,7 @@ end function onGameStart() + SendHealthStatsOff() trackTeams()