share/hedgewars/Data/Maps/TrophyRace/map.lua
changeset 9664 1e528c58e41d
parent 9659 e9c00dd31b07
child 9685 7d925e82e572
equal deleted inserted replaced
9663:1fa74f92555d 9664:1e528c58e41d
    27 local lasthog = nil
    27 local lasthog = nil
    28 
    28 
    29 -- active hog reached the goal?
    29 -- active hog reached the goal?
    30 local reached = false
    30 local reached = false
    31 
    31 
    32 -- hog with best time
       
    33 local besthog = nil
       
    34 local besthogteam = ""
       
    35 
       
    36 -- hog with worst time (per round)
    32 -- hog with worst time (per round)
    37 local worsthog = nil
    33 local worsthog = nil
    38 
    34 
       
    35 local besthog = nil
       
    36 
    39 -- best time
    37 -- best time
    40 local besttime = maxtime + 1
    38 local besttime = maxtime + 1
       
    39 
       
    40 -- best time per team
       
    41 local bestTimes = {}
    41 
    42 
    42 -- worst time (per round)
    43 -- worst time (per round)
    43 local worsttime = 0
    44 local worsttime = 0
    44 local startTime = 0;
    45 local startTime = 0;
    45 
    46 
    67         clantimes[i] = 0
    68         clantimes[i] = 0
    68     end
    69     end
    69 end
    70 end
    70 
    71 
    71 function onAmmoStoreInit()
    72 function onAmmoStoreInit()
    72     SetAmmo(amRope, 9, 2, 0)
    73     SetAmmo(amRope, 9, 1, 0)
       
    74     SetAmmo(amSkip, 9, 1, 0)
    73 end
    75 end
    74 
    76 
    75 function onGameTick()
    77 function onGameTick()
    76     if startTime == 0 and TurnTimeLeft < maxtime then
    78     if startTime == 0 and TurnTimeLeft < maxtime then
    77         startTime = GameTime
    79         startTime = GameTime
    78     end
    80     end
    79     if CurrentHedgehog ~= nil and TurnTimeLeft == 0 then
    81     if CurrentHedgehog ~= nil and TurnTimeLeft == 1 then
    80         SetHealth(CurrentHedgehog, 0)
    82         SetHealth(CurrentHedgehog, 0)
    81         x, y = GetGearPosition(CurrentHedgehog)
    83         x, y = GetGearPosition(CurrentHedgehog)
    82         AddGear(x, y, gtShell, 0, 0, 0, 0)
    84         AddGear(x, y, gtShell, 0, 0, 0, 0)
    83         worsttime = 99999
    85         worsttime = 99999
    84         worsthog = nil
    86         worsthog = nil
    85     elseif TurnTimeLeft == maxtime-1 and CurrentHedgehog ~= nil then
    87     elseif TurnTimeLeft == maxtime-1 and CurrentHedgehog ~= nil then
    86         if lasthog ~= nil then 
    88         if lasthog ~= nil then 
    87         SetGearPosition(lasthog, p , 0)
    89             SetGearPosition(lasthog, p , 0)
    88         end
    90         end
    89         reached = false
    91         reached = false
    90         SetGearVelocity(CurrentHedgehog, 1, 0)
    92         SetGearVelocity(CurrentHedgehog, 1, 0)
    91         SetGearPosition(CurrentHedgehog, start_area[1] + start_area[3] / 2, start_area[2] + start_area[4] / 2)
    93         SetGearPosition(CurrentHedgehog, start_area[1] + start_area[3] / 2, start_area[2] + start_area[4] / 2)
    92         ParseCommand("setweap " .. string.char(amRope))
    94         ParseCommand("setweap " .. string.char(amRope))
   112             local hscore = "| |"
   114             local hscore = "| |"
   113             local clan = GetHogClan(CurrentHedgehog)
   115             local clan = GetHogClan(CurrentHedgehog)
   114             if ttime < clantimes[clan] or clantimes[clan] == 0 then
   116             if ttime < clantimes[clan] or clantimes[clan] == 0 then
   115                 clantimes[clan] = ttime
   117                 clantimes[clan] = ttime
   116             end
   118             end
       
   119             local teamname = GetHogTeamName(CurrentHedgehog)
       
   120             if bestTimes[teamname] == nil or bestTimes[teamname] > ttime then
       
   121                 bestTimes[teamname] = ttime
       
   122             end
   117             if ttime < besttime then
   123             if ttime < besttime then
   118                 besttime = ttime
   124                 besttime = ttime
   119                 besthog = CurrentHedgehog
   125                 besthog = CurrentHedgehog
   120                 besthogteam = GetHogTeamName(besthog)
       
   121                 hscore = hscore .. loc("NEW fastest lap: ")
   126                 hscore = hscore .. loc("NEW fastest lap: ")
   122             else
   127             else
   123                 hscore = hscore .. loc("Fastest lap: ")
   128                 hscore = hscore .. loc("Fastest lap: ")
   124             end
   129             end
   125             if ttime > worsttime then
   130             if ttime > worsttime then
   168 --        
   173 --        
   169 --    end
   174 --    end
   170 --end
   175 --end
   171 
   176 
   172 function onAchievementsDeclaration()
   177 function onAchievementsDeclaration()
   173     if besthog ~= nil then
   178     for team,time in pairs(realBestTimes) do
   174       DeclareAchievement("rope race", besthogteam, "TrophyRace", besttime)
   179       DeclareAchievement("rope race", team, "TrophyRace", time)
   175     end
   180     end
   176 end
   181 end