368 SetHealth(gear, 0) |
368 SetHealth(gear, 0) |
369 end |
369 end |
370 |
370 |
371 function renderScores() |
371 function renderScores() |
372 for i=0, TeamsCount-1 do |
372 for i=0, TeamsCount-1 do |
373 if teams[i]~= nil then |
373 local name = GetTeamName(i) |
374 SetTeamLabel(teams[i], string.format(loc("%d | %d"), getTeamValue(teams[i], "Score"), getTeamValue(teams[i], "DeadHogs"))) |
374 SetTeamLabel(name, string.format(loc("%d | %d"), getTeamValue(name, "Score"), getTeamValue(name, "DeadHogs"))) |
375 end |
375 end |
|
376 end |
|
377 |
|
378 function createEndGameStats() |
|
379 SendStat(siGraphTitle, loc("Score graph")) |
|
380 |
|
381 local teamsSorted = {} |
|
382 for i=0, TeamsCount-1, 1 do |
|
383 teamsSorted[i+1] = GetTeamName(i) |
|
384 end |
|
385 |
|
386 -- Achievements stuff |
|
387 local achievements = 0 |
|
388 --- Most kills per turn |
|
389 if recordKills >= 3 then |
|
390 SendStat(siMaxStepKills, string.format("%d %s (%s)", recordKills, recordKillsHogName, recordKillsTeamName)) |
|
391 achievements = achievements + 1 |
|
392 end |
|
393 --- Most crates collected |
|
394 if recordCrates >= 5 then |
|
395 SendStat(siCustomAchievement, string.format(loc("%s (%s) was the greediest hedgehog and collected %d crates."), recordCratesHogName, recordCratesTeamName, recordCrates)) |
|
396 achievements = achievements + 1 |
|
397 end |
|
398 --- Most suicides |
|
399 if recordSuicides >= 5 then |
|
400 SendStat(siCustomAchievement, string.format(loc("%s (%s) hate life and suicided %d times."), recordSuicidesHogName, recordSuicidesTeamName, recordSuicides)) |
|
401 achievements = achievements + 1 |
|
402 end |
|
403 --- Most deaths |
|
404 if recordDeaths >= 5 then |
|
405 SendStat(siCustomAchievement, string.format(loc("Poor %s (%s) died %d times."), recordDeathsHogName, recordDeathsTeamName, recordDeaths)) |
|
406 achievements = achievements + 1 |
|
407 end |
|
408 --- Most skips |
|
409 if recordSkips >= 3 then |
|
410 SendStat(siMaxTurnSkips, string.format("%d %s (%s)", recordSkips, recordSkipsHogName, recordSkipsTeamName)) |
|
411 achievements = achievements + 1 |
|
412 end |
|
413 --- Total damage |
|
414 if totalDamage >= 900 then |
|
415 SendStat(siCustomAchievement, string.format(loc("%d damage was dealt in this game."), totalDamage)) |
|
416 achievements = achievements + 1 |
|
417 end |
|
418 --- Total kills |
|
419 if totalKills >= 20 or (achievements <= 0 and totalKills >= 1) then |
|
420 SendStat(siKilledHHs, tostring(totalKills)) |
|
421 achievements = achievements + 1 |
|
422 end |
|
423 |
|
424 -- Score and stats stuff |
|
425 local showScore = "" |
|
426 table.sort(teamsSorted, function(team1, team2) return getTeamValue(team1, "Score") > getTeamValue(team2, "Score") end) |
|
427 for i=1, TeamsCount do |
|
428 SendStat(siPointType, loc("point(s)")) |
|
429 local score = getTeamValue(teamsSorted[i], "Score") |
|
430 local deaths = getTeamValue(teamsSorted[i], "DeadHogs") |
|
431 SendStat(siPlayerKills, score, teamsSorted[i]) |
|
432 |
|
433 showScore = showScore .. string.format(loc("%s: %d (deaths: %d)"), teamsSorted[i], score, deaths) .. "|" |
|
434 end |
|
435 |
|
436 if getTeamValue(teamsSorted[1], "Score") == getTeamValue(teamsSorted[2], "Score") then |
|
437 -- The first two teams have the same score! Round is drawn. |
|
438 return nil |
|
439 else |
|
440 |
|
441 ShowMission(loc("Mutant"), |
|
442 loc("Final result"), |
|
443 string.format(loc("Winner: %s"), teamsSorted[1]) .. "| |" .. loc("Scores:") .. " |" .. |
|
444 showScore, 0, 15000) |
|
445 |
|
446 -- return winning team |
|
447 return teamsSorted[1] |
376 end |
448 end |
377 end |
449 end |
378 |
450 |
379 function checkScore() |
451 function checkScore() |
380 local showScore = "" |
|
381 local lowest_score_team = nil |
452 local lowest_score_team = nil |
382 local min_score=nil |
453 local min_score=nil |
383 local winTeam = nil |
454 local winTeam = nil |
384 |
455 |
385 local only_low_score = true |
456 local only_low_score = true |
386 |
457 |
387 for i=0, TeamsCount-1 do |
458 for i=0, TeamsCount-1 do |
388 if teams[i]~=nil then |
459 local teamName = GetTeamName(i) |
389 local curr_score = getTeamValue(teams[i], "Score") |
460 if not teamsDead[teamName] then |
390 |
461 local curr_score = getTeamValue(teamName, "Score") |
391 runOnHogsInTeam(removeFeeder, teams[i]) |
462 |
392 |
463 runOnHogsInTeam(removeFeeder, teamName) |
393 showScore = showScore .. string.format(loc("%s: %d (deaths: %d)"), teams[i], curr_score, getTeamValue(teams[i], "DeadHogs")) .. "|" |
|
394 |
464 |
395 if curr_score >= winScore then |
465 if curr_score >= winScore then |
396 gameOver = true |
466 gameOver = true |
397 winTeam = teams[i] |
467 winTeam = teamName |
398 end |
468 end |
399 |
469 |
400 if min_score==nil then |
470 if min_score==nil then |
401 min_score= curr_score |
471 min_score= curr_score |
402 lowest_score_team = teams[i] |
472 lowest_score_team = teamName |
403 else |
473 else |
404 if curr_score <= min_score then |
474 if curr_score <= min_score then |
405 if curr_score == min_score then |
475 if curr_score == min_score then |
406 if getTeamValue(teams[i], "DeadHogs") == getTeamValue(lowest_score_team, "DeadHogs") then |
476 if getTeamValue(teamName, "DeadHogs") == getTeamValue(lowest_score_team, "DeadHogs") then |
407 only_low_score = false |
477 only_low_score = false |
408 else |
478 else |
409 if getTeamValue(teams[i], "DeadHogs") > getTeamValue(lowest_score_team, "DeadHogs") then |
479 if getTeamValue(teamName, "DeadHogs") > getTeamValue(lowest_score_team, "DeadHogs") then |
410 lowest_score_team = teams[i] |
480 lowest_score_team = teamName |
411 end |
481 end |
412 only_low_score = true |
482 only_low_score = true |
413 end |
483 end |
414 |
484 |
415 else |
485 else |
416 min_score= curr_score |
486 min_score= curr_score |
417 lowest_score_team = teams[i] |
487 lowest_score_team = teamName |
418 only_low_score = true |
488 only_low_score = true |
419 end |
489 end |
420 end |
490 end |
421 end |
491 end |
422 end |
492 end |
423 end |
493 end |
424 |
494 |
425 if gameOver then |
495 if gameOver then |
426 EndTurn(true) |
496 EndTurn(true) |
427 |
497 |
428 teamsSorted = {} |
|
429 |
|
430 for i=0, TeamsCount-1 do |
498 for i=0, TeamsCount-1 do |
431 if teams[i]~=winTeam then |
499 local teamName = GetTeamName(i) |
432 runOnHogsInTeam(armageddon, teams[i]) |
500 if teamName~=winTeam then |
433 end |
501 runOnHogsInTeam(armageddon, teamName) |
434 teamsSorted[i+1] = teams[i] |
502 end |
435 end |
503 end |
436 |
504 |
437 -- Achievements stuff |
505 createEndGameStats() |
438 local achievements = 0 |
|
439 --- Most kills per turn |
|
440 if recordKills >= 3 then |
|
441 SendStat(siMaxStepKills, string.format("%d %s (%s)", recordKills, recordKillsHogName, recordKillsTeamName)) |
|
442 achievements = achievements + 1 |
|
443 end |
|
444 --- Most crates collected |
|
445 if recordCrates >= 5 then |
|
446 SendStat(siCustomAchievement, string.format(loc("%s (%s) was the greediest hedgehog and collected %d crates."), recordCratesHogName, recordCratesTeamName, recordCrates)) |
|
447 achievements = achievements + 1 |
|
448 end |
|
449 --- Most suicides |
|
450 if recordSuicides >= 5 then |
|
451 SendStat(siCustomAchievement, string.format(loc("%s (%s) hate life and suicided %d times."), recordSuicidesHogName, recordSuicidesTeamName, recordSuicides)) |
|
452 achievements = achievements + 1 |
|
453 end |
|
454 --- Most deaths |
|
455 if recordDeaths >= 5 then |
|
456 SendStat(siCustomAchievement, string.format(loc("Poor %s (%s) died %d times."), recordDeathsHogName, recordDeathsTeamName, recordDeaths)) |
|
457 achievements = achievements + 1 |
|
458 end |
|
459 --- Most skips |
|
460 if recordSkips >= 3 then |
|
461 SendStat(siMaxTurnSkips, string.format("%d %s (%s)", recordSkips, recordSkipsHogName, recordSkipsTeamName)) |
|
462 achievements = achievements + 1 |
|
463 end |
|
464 --- Total damage |
|
465 if totalDamage >= 900 then |
|
466 SendStat(siCustomAchievement, string.format(loc("%d damage was dealt in this game."), totalDamage)) |
|
467 achievements = achievements + 1 |
|
468 end |
|
469 --- Total kills |
|
470 if totalKills >= 20 or achievements <= 0 then |
|
471 SendStat(siKilledHHs, tostring(totalKills)) |
|
472 achievements = achievements + 1 |
|
473 end |
|
474 |
|
475 -- Score and stats stuff |
|
476 table.sort(teamsSorted, function(team1, team2) return getTeamValue(team1, "Score") < getTeamValue(team2, "Score") end) |
|
477 for i=TeamsCount, 1, -1 do |
|
478 SendStat(siPointType, loc("point(s)")) |
|
479 SendStat(siPlayerKills, getTeamValue(teamsSorted[i], "Score"), teamsSorted[i]) |
|
480 end |
|
481 |
|
482 ShowMission( loc("Mutant"), |
|
483 loc("Final result"), |
|
484 string.format(loc("Winner: %s"), winTeam) .. "| |" .. loc("Scores:") .. " |" .. |
|
485 showScore, 0, 15000) |
|
486 else |
506 else |
487 |
507 |
488 if only_low_score then |
508 if only_low_score then |
489 runOnHogsInTeam(setFeeder, lowest_score_team) |
509 runOnHogsInTeam(setFeeder, lowest_score_team) |
490 end |
510 end |