387 roundNumber = roundNumber + 1 |
386 roundNumber = roundNumber + 1 |
388 |
387 |
389 local totalComment = "" |
388 local totalComment = "" |
390 for i = 0, (TeamsCount-1) do |
389 for i = 0, (TeamsCount-1) do |
391 if teamNameArr[i] ~= " " then |
390 if teamNameArr[i] ~= " " then |
392 if teamScore[i] ~= 1000000 then |
391 if teamScore[i] ~= MAX_TURN_TIME then |
393 teamComment[i] = string.format(loc("%s: %.1fs"), teamNameArr[i], (teamScore[i]/1000)) .. "|" |
392 teamComment[i] = string.format(loc("%s: %.1fs"), teamNameArr[i], (teamScore[i]/1000)) .. "|" |
394 else |
393 else |
395 teamComment[i] = string.format(loc("%s: Did not finish"), teamNameArr[i]) .. "|" |
394 teamComment[i] = string.format(loc("%s: Did not finish"), teamNameArr[i]) .. "|" |
396 end |
395 end |
397 totalComment = totalComment .. teamComment[i] |
396 totalComment = totalComment .. teamComment[i] |
411 if roundNumber >= roundLimit then |
410 if roundNumber >= roundLimit then |
412 -- Sort the scores for the ranking list |
411 -- Sort the scores for the ranking list |
413 local unfinishedArray = {} |
412 local unfinishedArray = {} |
414 local sortedTeams = {} |
413 local sortedTeams = {} |
415 local k = 1 |
414 local k = 1 |
|
415 local c = 1 |
|
416 local clanScores = {} |
|
417 local previousClan |
416 for i = 0, TeamsCount-1 do |
418 for i = 0, TeamsCount-1 do |
417 if teamScore[i] ~= 1000000 and teamNameArr[i] ~= " " then |
419 local clan = GetTeamClan(teamNameArr[i]) |
418 sortedTeams[k] = {} |
420 if not clanScores[clan+1] then |
419 sortedTeams[k].name = teamNameArr[i] |
421 clanScores[clan+1] = {} |
420 sortedTeams[k].score = teamScore[i] |
422 clanScores[clan+1].index = clan |
421 k = k + 1 |
423 clanScores[clan+1].score = teamScore[i] |
|
424 end |
|
425 if teamScore[i] ~= MAX_TURN_TIME and teamNameArr[i] ~= " " then |
|
426 sortedTeams[k] = {} |
|
427 sortedTeams[k].name = teamNameArr[i] |
|
428 sortedTeams[k].score = teamScore[i] |
|
429 sortedTeams[k].clan = clan |
|
430 k = k + 1 |
422 else |
431 else |
423 table.insert(unfinishedArray, string.format(loc("%s did not finish the race."), teamNameArr[i])) |
432 table.insert(unfinishedArray, string.format(loc("%s did not finish the race."), teamNameArr[i])) |
424 end |
433 end |
425 end |
434 end |
426 table.sort(sortedTeams, function(team1, team2) return team1.score < team2.score end) |
435 table.sort(sortedTeams, function(team1, team2) |
|
436 if team1.score == team2.score then |
|
437 return team1.clan < team2.clan |
|
438 else |
|
439 return team1.score < team2.score |
|
440 end |
|
441 end) |
|
442 table.sort(clanScores, function(clan1, clan2) return clan1.score < clan2.score end) |
|
443 local rank = 0 |
|
444 local rankPlus = 0 |
|
445 local prevScore |
|
446 local clanRanks = {} |
|
447 for c = 1, #clanScores do |
|
448 rankPlus = rankPlus + 1 |
|
449 if clanScores[c].score ~= prevScore then |
|
450 rank = rank + rankPlus |
|
451 rankPlus = 0 |
|
452 end |
|
453 prevScore = clanScores[c].score |
|
454 clanRanks[clanScores[c].index] = rank |
|
455 end |
427 |
456 |
428 -- Write all the stats! |
457 -- Write all the stats! |
429 |
|
430 for i = 1, #sortedTeams do |
458 for i = 1, #sortedTeams do |
431 SendStat(siPointType, loc("milliseconds")) |
459 SendStat(siPointType, loc("milliseconds")) |
|
460 SendStat(siTeamRank, tostring(clanRanks[GetTeamClan(sortedTeams[i].name)])) |
432 SendStat(siPlayerKills, sortedTeams[i].score, sortedTeams[i].name) |
461 SendStat(siPlayerKills, sortedTeams[i].score, sortedTeams[i].name) |
433 end |
462 end |
434 |
463 |
435 if #sortedTeams >= 1 then |
464 local roundDraw = false |
|
465 if #clanScores >= 2 and clanScores[1].score == clanScores[2].score and clanScores[1].score ~= MAX_TURN_TIME then |
|
466 roundDraw = true |
|
467 SendStat(siGameResult, loc("Round draw")) |
|
468 SendStat(siCustomAchievement, loc("The teams are tied for the fastest time.")) |
|
469 elseif #sortedTeams >= 1 then |
436 SendStat(siGameResult, string.format(loc("%s wins!"), sortedTeams[1].name)) |
470 SendStat(siGameResult, string.format(loc("%s wins!"), sortedTeams[1].name)) |
437 SendStat(siCustomAchievement, string.format(loc("%s wins with a best time of %.1fs."), sortedTeams[1].name, (sortedTeams[1].score/1000))) |
471 SendStat(siCustomAchievement, string.format(loc("%s wins with a best time of %.1fs."), sortedTeams[1].name, (sortedTeams[1].score/1000))) |
438 for i=1,#unfinishedArray do |
472 for i=1,#unfinishedArray do |
439 SendStat(siCustomAchievement, unfinishedArray[i]) |
473 SendStat(siCustomAchievement, unfinishedArray[i]) |
440 end |
474 end |
441 else |
475 else |
|
476 roundDraw = true |
442 SendStat(siGameResult, loc("Round draw")) |
477 SendStat(siGameResult, loc("Round draw")) |
443 SendStat(siCustomAchievement, loc("Nobody managed to finish the race. What a shame!")) |
478 SendStat(siCustomAchievement, loc("Nobody managed to finish the race. What a shame!")) |
444 SendStat(siCustomAchievement, loc("Maybe you should try an easier TechRacer map.")) |
479 SendStat(siCustomAchievement, loc("Maybe you should try an easier TechRacer map.")) |
445 end |
480 end |
446 |
481 |