44 local delayTime = 0 |
44 local delayTime = 0 |
45 local airMineX = {} |
45 local airMineX = {} |
46 local airMineY = {} |
46 local airMineY = {} |
47 local airMine = {} |
47 local airMine = {} |
48 local init = true |
48 local init = true |
|
49 local multiplayerVictoryDelay = -1 |
|
50 local multiplayerWinningHogs = {} |
|
51 local multiplayerWins = 0 |
|
52 |
|
53 -- Placement positions of winning hogs |
|
54 local victoryPosses = { } |
|
55 do |
|
56 local m = 0 |
|
57 for y=108, 39, -32 do |
|
58 for x=1820+m, 1972-m, 22 do |
|
59 table.insert(victoryPosses, {x=x, y=y}) |
|
60 end |
|
61 m = m + 32 |
|
62 end |
|
63 end |
49 |
64 |
50 function onParameters() |
65 function onParameters() |
51 parseParams() |
66 parseParams() |
52 |
67 |
53 if params["speed"] ~= nil then |
68 if params["speed"] ~= nil then |
165 YouLost = false |
180 YouLost = false |
166 tauntNoo = false |
181 tauntNoo = false |
167 recordBroken = false |
182 recordBroken = false |
168 currTeam = GetHogTeamName(CurrentHedgehog) |
183 currTeam = GetHogTeamName(CurrentHedgehog) |
169 if CurrentHedgehog ~= nil then |
184 if CurrentHedgehog ~= nil then |
170 if CurrentHedgehog ~= dummyHog then |
185 if CurrentHedgehog ~= dummyHog or multiplayerWinningHogs[CurrentHedgehog] == true then |
171 SetGearPosition(CurrentHedgehog, 1951,32640) |
186 SetGearPosition(CurrentHedgehog, 1951,32640) |
172 if not HogsAreInvulnerable then SetEffect(CurrentHedgehog,heInvulnerable,0) end |
187 if not HogsAreInvulnerable then SetEffect(CurrentHedgehog,heInvulnerable,0) end |
173 AddVisualGear(1951,32640,vgtExplosion,0,false) |
188 AddVisualGear(1951,32640,vgtExplosion,0,false) |
174 SetState(CurrentHedgehog,band(GetState(CurrentHedgehog),bnot(gstInvisible))) |
189 SetState(CurrentHedgehog,band(GetState(CurrentHedgehog),bnot(gstInvisible))) |
175 SetWeapon(amRope) |
190 SetWeapon(amRope) |
176 ready = true |
191 ready = true |
177 else |
192 else |
178 dummySkip = GameTime+1 |
193 dummySkip = GameTime+1 |
179 end |
194 end |
|
195 end |
|
196 for hog, _ in pairs(multiplayerWinningHogs) do |
|
197 SetEffect(hog, heInvulnerable, 1) |
180 end |
198 end |
181 for f,i in pairs(Fire) do |
199 for f,i in pairs(Fire) do |
182 DeleteGear(f) |
200 DeleteGear(f) |
183 end |
201 end |
184 for s,i in pairs(Stars) do |
202 for s,i in pairs(Stars) do |
255 -- if g5 > 360 then g5 = 0 end |
273 -- if g5 > 360 then g5 = 0 end |
256 -- SetVisualGearValues(s, g1, g2, g3, g4, g5, g6, g7, g8, g9, g10) |
274 -- SetVisualGearValues(s, g1, g2, g3, g4, g5, g6, g7, g8, g9, g10) |
257 --end |
275 --end |
258 end |
276 end |
259 |
277 |
|
278 -- This will be executed if a player reached home in multiplayer |
|
279 if multiplayerVictoryDelay > 0 then |
|
280 multiplayerVictoryDelay = multiplayerVictoryDelay - 20 |
|
281 if multiplayerVictoryDelay <= 0 then |
|
282 -- If delay's over, the game will continue with the next hog |
|
283 if CurrentHedgehog then |
|
284 |
|
285 multiplayerWinningHogs[CurrentHedgehog] = true |
|
286 multiplayerWins = multiplayerWins + 1 |
|
287 |
|
288 local victoryX, victoryY |
|
289 if multiplayerWins <= #victoryPosses then |
|
290 victoryX, victoryY = victoryPosses[multiplayerWins].x, victoryPosses[multiplayerWins].y |
|
291 else |
|
292 victoryX, victoryY = victoryPosses[#victoryPosses].x, victoryPosses[#victoryPosses].y |
|
293 end |
|
294 SetGearPosition(CurrentHedgehog, victoryX, victoryY) |
|
295 SetEffect(CurrentHedgehog, heInvulnerable, 1) |
|
296 SetHealth(CurrentHedgehog, 1) |
|
297 |
|
298 if (deadHedgehogs + multiplayerWins) >= totalHedgehogs then |
|
299 makeFinalMultiPlayerStats() |
|
300 EndGame() |
|
301 onAchievementsDeclaration() |
|
302 else |
|
303 EndTurn(true) |
|
304 SetInputMask(0xFFFFFFFF) |
|
305 end |
|
306 return |
|
307 end |
|
308 end |
|
309 end |
|
310 |
260 if CurrentHedgehog ~= nil then x,y = GetGearPosition(CurrentHedgehog) end |
311 if CurrentHedgehog ~= nil then x,y = GetGearPosition(CurrentHedgehog) end |
261 if Cake ~= nil and CurrentHedgehog ~= nil then |
312 if Cake ~= nil and CurrentHedgehog ~= nil then |
262 local cx,cy = GetGearPosition(Cake) |
313 local cx,cy = GetGearPosition(Cake) |
263 if y < cy-1500 then |
314 if y < cy-1500 then |
264 DeleteGear(Cake) |
315 DeleteGear(Cake) |
352 teamName = GetHogTeamName(CurrentHedgehog), |
403 teamName = GetHogTeamName(CurrentHedgehog), |
353 distance = distanceFromWater |
404 distance = distanceFromWater |
354 } |
405 } |
355 end |
406 end |
356 end |
407 end |
|
408 local finishTime = (GameTime-startTime)/1000 |
|
409 local roundedFinishTime = math.ceil(math.floor(finishTime+0.5)) |
357 if isSinglePlayer then |
410 if isSinglePlayer then |
358 if distanceFromWater < 0 and not YouLost and not YouWon then |
411 if distanceFromWater < 0 and not YouLost and not YouWon then |
359 makeSinglePlayerLoserStats() |
412 makeSinglePlayerLoserStats() |
360 YouLost = true |
413 YouLost = true |
361 end |
414 end |
|
415 -- FIXME: Hog is also in winning box if it just walks into the chair from the left, touching it. Intentional? |
362 if not YouWon and not YouLost and gearIsInBox(CurrentHedgehog, 1920, 252, 50, 50) then |
416 if not YouWon and not YouLost and gearIsInBox(CurrentHedgehog, 1920, 252, 50, 50) then |
363 local finishTime = (GameTime-startTime)/1000 |
|
364 local roundedFinishTime = math.ceil(math.floor(finishTime+0.5)) |
|
365 AddCaption(loc("Victory!")) |
417 AddCaption(loc("Victory!")) |
366 ShowMission(loc("Climb Home"), |
418 ShowMission(loc("Climb Home"), |
367 loc("Made it!"), |
419 loc("Made it!"), |
368 string.format(loc("Ahhh, home, sweet home. Made it in %d seconds."), roundedFinishTime), |
420 string.format(loc("Ahhh, home, sweet home. Made it in %d seconds."), roundedFinishTime), |
369 -amRope, 0) |
421 -amRope, 0) |
378 |
430 |
379 EndGame() |
431 EndGame() |
380 onAchievementsDeclaration() |
432 onAchievementsDeclaration() |
381 YouWon = true |
433 YouWon = true |
382 end |
434 end |
383 elseif distanceFromWater < 0 and not YouLost then |
435 else |
384 makeMultiPlayerLoserStat(CurrentHedgehog) |
436 if distanceFromWater < 0 and not YouLost and not YouWon then |
385 deadHedgehogs = deadHedgehogs + 1 |
437 makeMultiPlayerLoserStat(CurrentHedgehog) |
386 YouLost = true |
438 deadHedgehogs = deadHedgehogs + 1 |
387 if deadHedgehogs >= totalHedgehogs then |
439 YouLost = true |
388 makeFinalMultiPlayerStats() |
440 if deadHedgehogs >= totalHedgehogs then |
389 EndGame() |
441 makeFinalMultiPlayerStats() |
390 onAchievementsDeclaration() |
442 EndGame() |
|
443 onAchievementsDeclaration() |
|
444 end |
|
445 end |
|
446 -- Check victory |
|
447 if not YouWon and not YouLost and gearIsInBox(CurrentHedgehog, 1920, 252, 50, 50) and |
|
448 -- Delay victory if MrMine is triggered |
|
449 (not MrMine or (MrMine and band(GetState(MrMine), gstAttacking) == 0)) then |
|
450 -- Player managed to reach home in multiplayer. |
|
451 -- Stop hog, disable controls, celebrate victory and continue the game after 4 seconds. |
|
452 AddCaption(string.format(loc("%s climbed home in %d seconds!"), GetHogName(CurrentHedgehog), roundedFinishTime)) |
|
453 SendStat(siCustomAchievement, string.format(loc("%s (%s) reached home in %.3f seconds."), GetHogName(CurrentHedgehog), GetHogTeamName(CurrentHedgehog), finishTime)) |
|
454 makeMultiPlayerWinnerStat(CurrentHedgehog) |
|
455 PlaySound(sndVictory, CurrentHedgehog) |
|
456 -- TODO: Unselect weapon. |
|
457 -- Note: SetWeapon(amNothing) does not work. :-( |
|
458 SetGearMessage(CurrentHedgehog, band(GetGearMessage(CurrentHedgehog), bnot(gmLeft+gmRight+gmUp+gmDown+gmHJump+gmLJump+gmPrecise))) |
|
459 SetInputMask(0x00) |
|
460 -- TODO: Add stupid winner grin. |
|
461 multiplayerVictoryDelay = 4000 |
|
462 YouWon = true |
391 end |
463 end |
392 end |
464 end |
393 |
465 |
394 if GameTime % 500 == 0 then |
466 if GameTime % 500 == 0 then |
395 if not isSinglePlayer then |
467 if not isSinglePlayer then |
539 |
611 |
540 if isSinglePlayer then |
612 if isSinglePlayer then |
541 makeSinglePlayerLoserStats() |
613 makeSinglePlayerLoserStats() |
542 else |
614 else |
543 deadHedgehogs = deadHedgehogs + 1 |
615 deadHedgehogs = deadHedgehogs + 1 |
544 if deadHedgehogs >= totalHedgehogs then |
616 if (deadHedgehogs + multiplayerWins) >= totalHedgehogs then |
545 makeFinalMultiPlayerStats() |
617 makeFinalMultiPlayerStats() |
546 EndGame() |
618 EndGame() |
547 onAchievementsDeclaration() |
619 onAchievementsDeclaration() |
548 end |
620 end |
549 makeMultiPlayerLoserStat(gear) |
621 makeMultiPlayerLoserStat(gear) |
604 if teamScoreStats[teamName] == nil then teamScoreStats[teamName] = {} end |
676 if teamScoreStats[teamName] == nil then teamScoreStats[teamName] = {} end |
605 table.insert(teamScoreStats[teamName], actualHeight) |
677 table.insert(teamScoreStats[teamName], actualHeight) |
606 --SendStat(siClanHealth, tostring(teamBests[teamName]), teamName) |
678 --SendStat(siClanHealth, tostring(teamBests[teamName]), teamName) |
607 end |
679 end |
608 |
680 |
|
681 function makeMultiPlayerWinnerStat(gear) |
|
682 return makeMultiPlayerLoserStat(gear) |
|
683 end |
|
684 |
609 function makeFinalMultiPlayerStats() |
685 function makeFinalMultiPlayerStats() |
610 local ranking = {} |
686 local ranking = {} |
611 for k,v in pairs(teamBests) do |
687 for k,v in pairs(teamBests) do |
612 table.insert(ranking, {name=k, score=v}) |
688 table.insert(ranking, {name=k, score=v}) |
613 end |
689 end |