share/hedgewars/Data/Missions/Challenge/Basic_Training_-_Sniper_Rifle.lua
changeset 12729 4e0e59255856
parent 12728 745d5c9a3abc
child 12730 2c4a07eb2112
equal deleted inserted replaced
12728:745d5c9a3abc 12729:4e0e59255856
    39 -- Used to calculate final target score
    39 -- Used to calculate final target score
    40 local score_bonus = 0
    40 local score_bonus = 0
    41 
    41 
    42 local cinematic = false
    42 local cinematic = false
    43 
    43 
       
    44 -- Timer of dynamite (shorter than usual)
       
    45 local dynamiteTimer = 2000
    44 -- Number of dynamite gears currently in game
    46 -- Number of dynamite gears currently in game
    45 local dynamiteCounter = 0
    47 local dynamiteCounter = 0
       
    48 -- Table of dynamite gears, indexed by gear ID
       
    49 local dynamiteGears = {}
    46 
    50 
    47 -- Position for delayed targets
    51 -- Position for delayed targets
    48 local delayedTargetTargetX, delayedTargetY
    52 local delayedTargetTargetX, delayedTargetY
    49 
    53 
    50 -- This is a custom function to make it easier to
    54 -- This is a custom function to make it easier to
    70 function blowUp(x, y, follow)
    74 function blowUp(x, y, follow)
    71 	if cinematic == false then
    75 	if cinematic == false then
    72 		cinematic = true
    76 		cinematic = true
    73 		SetCinematicMode(true)
    77 		SetCinematicMode(true)
    74 	end
    78 	end
    75 	local dyna = AddGear(x, y, gtDynamite, 0, 0, 0, 0)
    79 	-- Spawn dynamite with short timer
       
    80 	local dyna = AddGear(x, y, gtDynamite, 0, 0, 0, dynamiteTimer)
       
    81 	-- Fix dynamite animation due to non-default timer
       
    82 	SetTag(dyna, div(5000-dynamiteTimer, 166))
    76 	if follow then
    83 	if follow then
    77 		FollowGear(dyna)
    84 		FollowGear(dyna)
    78 	end
    85 	end
    79 end
    86 end
    80 
    87 
   195 	if target and GetCurAmmoType() == amSniperRifle then
   202 	if target and GetCurAmmoType() == amSniperRifle then
   196 		FollowGear(target)
   203 		FollowGear(target)
   197 	end
   204 	end
   198 end
   205 end
   199 
   206 
       
   207 -- Insta-blow up dynamite with precise key
       
   208 function onPrecise()
       
   209 	for gear, _ in pairs(dynamiteGears) do
       
   210 		SetTimer(gear, 0)
       
   211 	end
       
   212 end
       
   213 
   200 -- This function is called when a new gear is added.
   214 -- This function is called when a new gear is added.
   201 -- We use it to count the number of shots, which we
   215 -- We use it to count the number of shots, which we
   202 -- in turn use to calculate the final score and stats
   216 -- in turn use to calculate the final score and stats
   203 function onGearAdd(gear)
   217 function onGearAdd(gear)
   204 	if GetGearType(gear) == gtSniperRifleShot then
   218 	if GetGearType(gear) == gtSniperRifleShot then
   205 		shots = shots + 1
   219 		shots = shots + 1
   206 	elseif GetGearType(gear) == gtDynamite then
   220 	elseif GetGearType(gear) == gtDynamite then
   207 		dynamiteCounter = dynamiteCounter + 1
   221 		dynamiteCounter = dynamiteCounter + 1
       
   222 		dynamiteGears[gear] = true
   208 	end
   223 	end
   209 end
   224 end
   210 
   225 
   211 -- This function is called before a gear is destroyed.
   226 -- This function is called before a gear is destroyed.
   212 -- We use it to count the number of targets destroyed.
   227 -- We use it to count the number of targets destroyed.
   219 	end
   234 	end
   220 
   235 
   221 	if (gt == gtDynamite) then
   236 	if (gt == gtDynamite) then
   222 		-- Dynamite blow-up, used to continue the game.
   237 		-- Dynamite blow-up, used to continue the game.
   223 		dynamiteCounter = dynamiteCounter - 1
   238 		dynamiteCounter = dynamiteCounter - 1
       
   239 		dynamiteGears[gear] = nil
   224 
   240 
   225 		-- Wait for all dynamites to be destroyed before we continue.
   241 		-- Wait for all dynamites to be destroyed before we continue.
   226 		-- Most cut scenes spawn multiple dynamites.
   242 		-- Most cut scenes spawn multiple dynamites.
   227 		if dynamiteCounter == 0 then
   243 		if dynamiteCounter == 0 then
   228 			if cinematic then
   244 			if cinematic then