share/hedgewars/Data/Maps/TrophyRace/map.lua
changeset 9657 2d8cae3c0855
parent 9411 d95ac9992529
child 9658 c97e8ecc7457
equal deleted inserted replaced
9656:18422d205080 9657:2d8cae3c0855
    39 -- best time
    39 -- best time
    40 local besttime = maxtime + 1
    40 local besttime = maxtime + 1
    41 
    41 
    42 -- worst time (per round)
    42 -- worst time (per round)
    43 local worsttime = 0
    43 local worsttime = 0
       
    44 local startTime = 0;
    44 
    45 
    45 function onGameInit()
    46 function onGameInit()
    46 	GameFlags = gfSolidLand + gfInvulnerable
    47     GameFlags = gfSolidLand + gfInvulnerable
    47 	TurnTime = maxtime
    48     TurnTime = maxtime
    48 	CaseFreq = 0
    49     CaseFreq = 0
    49 	MinesNum = 0
    50     MinesNum = 0
    50 	Explosives = 0
    51     Explosives = 0
    51 	Delay = 500
    52     Delay = 500
    52 	SuddenDeathTurns = 99999 -- "disable" sudden death
    53     SuddenDeathTurns = 99999 -- "disable" sudden death
    53 	Theme = 'Olympics'
    54     Theme = 'Olympics'
    54 end
    55 end
    55 
    56 
    56 function onGameStart()
    57 function onGameStart()
    57 	ShowMission(loc("TrophyRace"), "", loc("Use your rope to get from start to finish as fast as you can!"), -amRope, 0)
    58     ShowMission(loc("TrophyRace"), "", loc("Use your rope to get from start to finish as fast as you can!"), -amRope, 0)
    58 	started = true
    59     started = true
    59 	p=1820
    60     p=1820
    60 	for i = 0, numhhs - 1 do
    61     for i = 0, numhhs - 1 do
    61 	p = p + 50	
    62     p = p + 50    
    62 	SetGearPosition(hhs[i], p, 0)
    63     SetGearPosition(hhs[i], p, 0)
    63 	end
    64     end
    64 	
    65     
    65 	for i=0, ClansCount-1 do
    66     for i=0, ClansCount-1 do
    66 		clantimes[i] = 0
    67         clantimes[i] = 0
    67 	end
    68     end
    68 end
    69 end
    69 
    70 
    70 function onAmmoStoreInit()
    71 function onAmmoStoreInit()
    71 	SetAmmo(amRope, 9, 2, 0)
    72     SetAmmo(amRope, 9, 2, 0)
    72 end
    73 end
    73 
    74 
    74 function onGameTick20()
    75 function onGameTick20()
    75 	if CurrentHedgehog ~= nil and TurnTimeLeft <= 20 and TurnTimeLeft > 0 then
    76     if startTime = 0 and TurnTimeLeft < maxtime then
    76 		SetHealth(CurrentHedgehog, 0)
    77         startTime = GameTime
    77 		x, y = GetGearPosition(CurrentHedgehog)
    78     end
    78 		AddGear(x, y, gtShell, 0, 0, 0, 0)
    79     if CurrentHedgehog ~= nil and TurnTimeLeft <= 20 and TurnTimeLeft > 0 then
    79 		worsttime = 99999
    80         SetHealth(CurrentHedgehog, 0)
    80 		worsthog = nil
    81         x, y = GetGearPosition(CurrentHedgehog)
    81 	elseif TurnTimeLeft > maxtime - 25 and CurrentHedgehog ~= nil then
    82         AddGear(x, y, gtShell, 0, 0, 0, 0)
    82 		if lasthog ~= nil then 
    83         worsttime = 99999
    83 		SetGearPosition(lasthog, p , 0)
    84         worsthog = nil
    84 		end
    85     elseif TurnTimeLeft > maxtime - 25 and CurrentHedgehog ~= nil then
    85 		reached = false
    86         if lasthog ~= nil then 
       
    87         SetGearPosition(lasthog, p , 0)
       
    88         end
       
    89         reached = false
    86         SetGearVelocity(CurrentHedgehog, 1, 0)
    90         SetGearVelocity(CurrentHedgehog, 1, 0)
    87 		SetGearPosition(CurrentHedgehog, start_area[1] + start_area[3] / 2, start_area[2] + start_area[4] / 2)
    91         SetGearPosition(CurrentHedgehog, start_area[1] + start_area[3] / 2, start_area[2] + start_area[4] / 2)
    88         ParseCommand("setweap " .. string.char(amRope))
    92         ParseCommand("setweap " .. string.char(amRope))
    89 		lasthog = CurrentHedgehog
    93         lasthog = CurrentHedgehog
    90 	elseif CurrentHedgehog ~= nil then
    94     elseif CurrentHedgehog ~= nil then
    91 		x, y = GetGearPosition(CurrentHedgehog)
    95         x, y = GetGearPosition(CurrentHedgehog)
    92 		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
    96         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
    93 			reached = true
    97             reached = true
    94 			local ttime = maxtime - TurnTimeLeft
    98             local ttime = GameTime-startTime
    95 			--give it a sound;)
    99             startTime = 0
    96 			if ttime < besttime then
   100             --give it a sound;)
    97 				PlaySound (sndHomerun)
   101             if ttime < besttime then
    98 			else
   102                 PlaySound (sndHomerun)
    99 				PlaySound (sndHellish)
   103             else
   100 			end
   104                 PlaySound (sndHellish)
   101 			for i = 0, numhhs - 1 do
   105             end
   102 				if hhs[i] == CurrentHedgehog then
   106             for i = 0, numhhs - 1 do
   103 					times[numhhs] = ttime
   107                 if hhs[i] == CurrentHedgehog then
   104 				end
   108                     times[numhhs] = ttime
   105 			end
   109                 end
   106 				
   110             end
   107 			local hscore = "| |"
   111                 
   108 			local clan = GetHogClan(CurrentHedgehog)
   112             local hscore = "| |"
   109 			if ttime < clantimes[clan] or clantimes[clan] == 0 then
   113             local clan = GetHogClan(CurrentHedgehog)
   110 				clantimes[clan] = ttime
   114             if ttime < clantimes[clan] or clantimes[clan] == 0 then
   111 			end
   115                 clantimes[clan] = ttime
   112 			
   116             end
   113 			if ttime < besttime then
   117             if ttime < besttime then
   114 				besttime = ttime
   118                 besttime = ttime
   115 				besthog = CurrentHedgehog
   119                 besthog = CurrentHedgehog
   116                 besthogteam = GetHogTeamName(besthog)
   120                 besthogteam = GetHogTeamName(besthog)
   117 				hscore = hscore .. loc("NEW fastest lap: ")
   121                 hscore = hscore .. loc("NEW fastest lap: ")
   118 			else
   122             else
   119 				hscore = hscore .. loc("Fastest lap: ")
   123                 hscore = hscore .. loc("Fastest lap: ")
   120 			end
   124             end
   121 			if ttime > worsttime then
   125             if ttime > worsttime then
   122 				worsttime = ttime
   126                 worsttime = ttime
   123 				worsthog = CurrentHedgehog
   127                 worsthog = CurrentHedgehog
   124 			end
   128             end
   125 			hscore = hscore .. GetHogName(besthog) .. " - " .. (besttime / 1000) .. " s | |" .. loc("Best laps per team: ")
   129             hscore = hscore .. GetHogName(besthog) .. " - " .. (besttime / 1000) .. " s | |" .. loc("Best laps per team: ")
   126 			
   130             
   127 			if clan == ClansCount -1 then
   131             if clan == ClansCount -1 then
   128 				-- Time for elimination - worst hog is out and the worst hog vars are reset.
   132                 -- Time for elimination - worst hog is out and the worst hog vars are reset.
   129 				SetHealth(worsthog, 0)
   133                 SetHealth(worsthog, 0)
   130 				--Place a grenade to make inactive slowest hog active
   134                 --Place a grenade to make inactive slowest hog active
   131 				x, y = GetGearPosition(worsthog)
   135                 x, y = GetGearPosition(worsthog)
   132 				AddGear(x, y, gtShell, 0, 0, 0, 0)
   136                 AddGear(x, y, gtShell, 0, 0, 0, 0)
   133 				worsttime = 0
   137                 worsttime = 0
   134 				worsthog = nil
   138                 worsthog = nil
   135 				end
   139                 end
   136 			
   140             
   137 			for i=0, ClansCount -1 do
   141             for i=0, ClansCount -1 do
   138 				local tt = "" .. (clantimes[i] / 1000) .. " s"
   142                 local tt = "" .. (clantimes[i] / 1000) .. " s"
   139 				if clantimes[i] == 0 then
   143                 if clantimes[i] == 0 then
   140 					tt = "--"
   144                     tt = "--"
   141 				end
   145                 end
   142 				hscore = hscore .. "|" .. string.format(loc("Team %d: "), i+1) .. tt
   146                 hscore = hscore .. "|" .. string.format(loc("Team %d: "), i+1) .. tt
   143 			end
   147             end
   144 			
   148             
   145 			ShowMission(loc("TrophyRace"), "", loc("You've reached the goal!| |Time: ") .. (ttime / 1000) .. " s" .. hscore, 0, 0)
   149             ShowMission(loc("TrophyRace"), "", loc("You've reached the goal!| |Time: ") .. (ttime / 1000) .. " s" .. hscore, 0, 0)
   146 			TurnTimeLeft = 0
   150             TurnTimeLeft = 0
   147 		end
   151         end
   148 	end
   152     end
   149 end
   153 end
   150 
   154 
   151 function onGearAdd(gear)
   155 function onGearAdd(gear)
   152 	if GetGearType(gear) == gtHedgehog then
   156     if GetGearType(gear) == gtHedgehog then
   153 		hhs[numhhs] = gear
   157         hhs[numhhs] = gear
   154 		times[numhhs] = 0
   158         times[numhhs] = 0
   155 		numhhs = numhhs + 1
   159         numhhs = numhhs + 1
   156 	end
   160     end
   157 --	elseif GetGearType(gear) == gtRope then -- rope is shot
   161 --    elseif GetGearType(gear) == gtRope then -- rope is shot
   158 end
   162 end
   159 
   163 
   160 --function onGearDelete(gear)
   164 --function onGearDelete(gear)
   161 --	if GetGearType(gear) == gtRope then -- rope deletion - hog didn't manage to rerope
   165 --    if GetGearType(gear) == gtRope then -- rope deletion - hog didn't manage to rerope
   162 --		--TurnTimeLeft = 0 -- end turn or not? hm...
   166 --        --TurnTimeLeft = 0 -- end turn or not? hm...
   163 --		lasthog = CurrentHedgehog
   167 --        lasthog = CurrentHedgehog
   164 --		
   168 --        
   165 --	end
   169 --    end
   166 --end
   170 --end
   167 
   171 
   168 function onAchievementsDeclaration()
   172 function onAchievementsDeclaration()
   169     if besthog ~= nil then
   173     if besthog ~= nil then
   170       DeclareAchievement("rope race", besthogteam, "TrophyRace", besttime)
   174       DeclareAchievement("rope race", besthogteam, "TrophyRace", besttime)