# HG changeset patch # User nemo # Date 1383160397 14400 # Node ID 2d8cae3c0855a0e657bf729a806c234095466027 # Parent 18422d205080c0f5858c126392ad11da7f6f4fbf use gameticks instead of turn timer. untested. also replaced tabs with spaces diff -r 18422d205080 -r 2d8cae3c0855 share/hedgewars/Data/Maps/TrophyRace/map.lua --- a/share/hedgewars/Data/Maps/TrophyRace/map.lua Wed Oct 30 00:18:10 2013 +0400 +++ b/share/hedgewars/Data/Maps/TrophyRace/map.lua Wed Oct 30 15:13:17 2013 -0400 @@ -41,128 +41,132 @@ -- worst time (per round) local worsttime = 0 +local startTime = 0; function onGameInit() - GameFlags = gfSolidLand + gfInvulnerable - TurnTime = maxtime - CaseFreq = 0 - MinesNum = 0 - Explosives = 0 - Delay = 500 - SuddenDeathTurns = 99999 -- "disable" sudden death - Theme = 'Olympics' + GameFlags = gfSolidLand + gfInvulnerable + TurnTime = maxtime + CaseFreq = 0 + MinesNum = 0 + Explosives = 0 + Delay = 500 + SuddenDeathTurns = 99999 -- "disable" sudden death + Theme = 'Olympics' end function onGameStart() - ShowMission(loc("TrophyRace"), "", loc("Use your rope to get from start to finish as fast as you can!"), -amRope, 0) - started = true - p=1820 - for i = 0, numhhs - 1 do - p = p + 50 - SetGearPosition(hhs[i], p, 0) - end - - for i=0, ClansCount-1 do - clantimes[i] = 0 - end + ShowMission(loc("TrophyRace"), "", loc("Use your rope to get from start to finish as fast as you can!"), -amRope, 0) + started = true + p=1820 + for i = 0, numhhs - 1 do + p = p + 50 + SetGearPosition(hhs[i], p, 0) + end + + for i=0, ClansCount-1 do + clantimes[i] = 0 + end end function onAmmoStoreInit() - SetAmmo(amRope, 9, 2, 0) + SetAmmo(amRope, 9, 2, 0) end function onGameTick20() - if CurrentHedgehog ~= nil and TurnTimeLeft <= 20 and TurnTimeLeft > 0 then - SetHealth(CurrentHedgehog, 0) - x, y = GetGearPosition(CurrentHedgehog) - AddGear(x, y, gtShell, 0, 0, 0, 0) - worsttime = 99999 - worsthog = nil - elseif TurnTimeLeft > maxtime - 25 and CurrentHedgehog ~= nil then - if lasthog ~= nil then - SetGearPosition(lasthog, p , 0) - end - reached = false + if startTime = 0 and TurnTimeLeft < maxtime then + startTime = GameTime + end + if CurrentHedgehog ~= nil and TurnTimeLeft <= 20 and TurnTimeLeft > 0 then + SetHealth(CurrentHedgehog, 0) + x, y = GetGearPosition(CurrentHedgehog) + AddGear(x, y, gtShell, 0, 0, 0, 0) + worsttime = 99999 + worsthog = nil + elseif TurnTimeLeft > maxtime - 25 and CurrentHedgehog ~= nil then + if lasthog ~= nil then + SetGearPosition(lasthog, p , 0) + end + reached = false SetGearVelocity(CurrentHedgehog, 1, 0) - SetGearPosition(CurrentHedgehog, start_area[1] + start_area[3] / 2, start_area[2] + start_area[4] / 2) + SetGearPosition(CurrentHedgehog, start_area[1] + start_area[3] / 2, start_area[2] + start_area[4] / 2) ParseCommand("setweap " .. string.char(amRope)) - lasthog = CurrentHedgehog - elseif CurrentHedgehog ~= nil then - x, y = GetGearPosition(CurrentHedgehog) - if not reached and x > goal_area[1] and x < goal_area[1] + goal_area[3] and y > goal_area[2] and y < goal_area[2] + goal_area[4] then -- hog is within goal rectangle - reached = true - local ttime = maxtime - TurnTimeLeft - --give it a sound;) - if ttime < besttime then - PlaySound (sndHomerun) - else - PlaySound (sndHellish) - end - for i = 0, numhhs - 1 do - if hhs[i] == CurrentHedgehog then - times[numhhs] = ttime - end - end - - local hscore = "| |" - local clan = GetHogClan(CurrentHedgehog) - if ttime < clantimes[clan] or clantimes[clan] == 0 then - clantimes[clan] = ttime - end - - if ttime < besttime then - besttime = ttime - besthog = CurrentHedgehog + lasthog = CurrentHedgehog + elseif CurrentHedgehog ~= nil then + x, y = GetGearPosition(CurrentHedgehog) + if not reached and x > goal_area[1] and x < goal_area[1] + goal_area[3] and y > goal_area[2] and y < goal_area[2] + goal_area[4] then -- hog is within goal rectangle + reached = true + local ttime = GameTime-startTime + startTime = 0 + --give it a sound;) + if ttime < besttime then + PlaySound (sndHomerun) + else + PlaySound (sndHellish) + end + for i = 0, numhhs - 1 do + if hhs[i] == CurrentHedgehog then + times[numhhs] = ttime + end + end + + local hscore = "| |" + local clan = GetHogClan(CurrentHedgehog) + if ttime < clantimes[clan] or clantimes[clan] == 0 then + clantimes[clan] = 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: ") - end - if ttime > worsttime then - worsttime = ttime - worsthog = CurrentHedgehog - end - hscore = hscore .. GetHogName(besthog) .. " - " .. (besttime / 1000) .. " s | |" .. loc("Best laps per team: ") - - if clan == ClansCount -1 then - -- Time for elimination - worst hog is out and the worst hog vars are reset. - SetHealth(worsthog, 0) - --Place a grenade to make inactive slowest hog active - x, y = GetGearPosition(worsthog) - AddGear(x, y, gtShell, 0, 0, 0, 0) - worsttime = 0 - worsthog = nil - end - - for i=0, ClansCount -1 do - local tt = "" .. (clantimes[i] / 1000) .. " s" - if clantimes[i] == 0 then - tt = "--" - end - hscore = hscore .. "|" .. string.format(loc("Team %d: "), i+1) .. tt - end - - ShowMission(loc("TrophyRace"), "", loc("You've reached the goal!| |Time: ") .. (ttime / 1000) .. " s" .. hscore, 0, 0) - TurnTimeLeft = 0 - end - end + hscore = hscore .. loc("NEW fastest lap: ") + else + hscore = hscore .. loc("Fastest lap: ") + end + if ttime > worsttime then + worsttime = ttime + worsthog = CurrentHedgehog + end + hscore = hscore .. GetHogName(besthog) .. " - " .. (besttime / 1000) .. " s | |" .. loc("Best laps per team: ") + + if clan == ClansCount -1 then + -- Time for elimination - worst hog is out and the worst hog vars are reset. + SetHealth(worsthog, 0) + --Place a grenade to make inactive slowest hog active + x, y = GetGearPosition(worsthog) + AddGear(x, y, gtShell, 0, 0, 0, 0) + worsttime = 0 + worsthog = nil + end + + for i=0, ClansCount -1 do + local tt = "" .. (clantimes[i] / 1000) .. " s" + if clantimes[i] == 0 then + tt = "--" + end + hscore = hscore .. "|" .. string.format(loc("Team %d: "), i+1) .. tt + end + + ShowMission(loc("TrophyRace"), "", loc("You've reached the goal!| |Time: ") .. (ttime / 1000) .. " s" .. hscore, 0, 0) + TurnTimeLeft = 0 + end + end end function onGearAdd(gear) - if GetGearType(gear) == gtHedgehog then - hhs[numhhs] = gear - times[numhhs] = 0 - numhhs = numhhs + 1 - end --- elseif GetGearType(gear) == gtRope then -- rope is shot + if GetGearType(gear) == gtHedgehog then + hhs[numhhs] = gear + times[numhhs] = 0 + numhhs = numhhs + 1 + end +-- elseif GetGearType(gear) == gtRope then -- rope is shot end --function onGearDelete(gear) --- if GetGearType(gear) == gtRope then -- rope deletion - hog didn't manage to rerope --- --TurnTimeLeft = 0 -- end turn or not? hm... --- lasthog = CurrentHedgehog --- --- end +-- if GetGearType(gear) == gtRope then -- rope deletion - hog didn't manage to rerope +-- --TurnTimeLeft = 0 -- end turn or not? hm... +-- lasthog = CurrentHedgehog +-- +-- end --end function onAchievementsDeclaration()