ok. this should avoid calling switch inappropriately. also, add skip to trophyrace and add the per-team achievement reporting.
authornemo
Thu, 31 Oct 2013 21:04:39 -0400
changeset 9664 1e528c58e41d
parent 9663 1fa74f92555d
child 9665 bfd62e380327
ok. this should avoid calling switch inappropriately. also, add skip to trophyrace and add the per-team achievement reporting.
hedgewars/uGearsHedgehog.pas
share/hedgewars/Data/Maps/TrophyRace/map.lua
--- a/hedgewars/uGearsHedgehog.pas	Thu Oct 31 20:50:20 2013 -0400
+++ b/hedgewars/uGearsHedgehog.pas	Thu Oct 31 21:04:39 2013 -0400
@@ -114,9 +114,9 @@
             LoadHedgehogHat(HHGear^.Hedgehog^, Hat);
         end;
     // Try again in the next slot
-    if CurAmmoType = prevAmmo then
+    if (CurAmmoType = prevAmmo) and (slot < cMaxSlotIndex) then 
         begin
-        if slot < cMaxSlotIndex then inc(slot);
+        inc(slot);
         HHGear^.MsgParam:= slot;
         ChangeAmmo(HHGear)
         end
--- a/share/hedgewars/Data/Maps/TrophyRace/map.lua	Thu Oct 31 20:50:20 2013 -0400
+++ b/share/hedgewars/Data/Maps/TrophyRace/map.lua	Thu Oct 31 21:04:39 2013 -0400
@@ -29,16 +29,17 @@
 -- active hog reached the goal?
 local reached = false
 
--- hog with best time
-local besthog = nil
-local besthogteam = ""
-
 -- hog with worst time (per round)
 local worsthog = nil
 
+local besthog = nil
+
 -- best time
 local besttime = maxtime + 1
 
+-- best time per team
+local bestTimes = {}
+
 -- worst time (per round)
 local worsttime = 0
 local startTime = 0;
@@ -69,14 +70,15 @@
 end
 
 function onAmmoStoreInit()
-    SetAmmo(amRope, 9, 2, 0)
+    SetAmmo(amRope, 9, 1, 0)
+    SetAmmo(amSkip, 9, 1, 0)
 end
 
 function onGameTick()
     if startTime == 0 and TurnTimeLeft < maxtime then
         startTime = GameTime
     end
-    if CurrentHedgehog ~= nil and TurnTimeLeft == 0 then
+    if CurrentHedgehog ~= nil and TurnTimeLeft == 1 then
         SetHealth(CurrentHedgehog, 0)
         x, y = GetGearPosition(CurrentHedgehog)
         AddGear(x, y, gtShell, 0, 0, 0, 0)
@@ -84,7 +86,7 @@
         worsthog = nil
     elseif TurnTimeLeft == maxtime-1 and CurrentHedgehog ~= nil then
         if lasthog ~= nil then 
-        SetGearPosition(lasthog, p , 0)
+            SetGearPosition(lasthog, p , 0)
         end
         reached = false
         SetGearVelocity(CurrentHedgehog, 1, 0)
@@ -114,10 +116,13 @@
             if ttime < clantimes[clan] or clantimes[clan] == 0 then
                 clantimes[clan] = ttime
             end
+            local teamname = GetHogTeamName(CurrentHedgehog)
+            if bestTimes[teamname] == nil or bestTimes[teamname] > ttime then
+                bestTimes[teamname] = ttime
+            end
             if ttime < besttime then
                 besttime = ttime
                 besthog = CurrentHedgehog
-                besthogteam = GetHogTeamName(besthog)
                 hscore = hscore .. loc("NEW fastest lap: ")
             else
                 hscore = hscore .. loc("Fastest lap: ")
@@ -170,7 +175,7 @@
 --end
 
 function onAchievementsDeclaration()
-    if besthog ~= nil then
-      DeclareAchievement("rope race", besthogteam, "TrophyRace", besttime)
+    for team,time in pairs(realBestTimes) do
+      DeclareAchievement("rope race", team, "TrophyRace", time)
     end
 end