Sniper rifle mission: Faster dynamite blow-up, also skip with precise
authorWuzzy <Wuzzy2@mail.ru>
Sat, 21 Oct 2017 18:38:28 +0200
changeset 12734 4e0e59255856
parent 12733 745d5c9a3abc
child 12735 2c4a07eb2112
Sniper rifle mission: Faster dynamite blow-up, also skip with precise
ChangeLog.txt
share/hedgewars/Data/Missions/Challenge/Basic_Training_-_Sniper_Rifle.lua
--- a/ChangeLog.txt	Sat Oct 21 18:21:27 2017 +0200
+++ b/ChangeLog.txt	Sat Oct 21 18:38:28 2017 +0200
@@ -257,6 +257,7 @@
  + Rewrote some help texts in basic rope training
  + Graphical effect (black bars) while in cut scenes
  + Change description and icon for baseball bat in Knockball mission map
+ + Sniper rifle target practice: Dynamite blows up quicker, can also skip with precise key
  * TrophyRace: Fix hedgehogs not being eliminated anymore after one hog skipped or ran out of time
  * Portal Mind Challenge was cleaned up and reworked (especially less awful wording)
  * Fixed Target Practice missions getting stuck when a target dropped into water
--- a/share/hedgewars/Data/Missions/Challenge/Basic_Training_-_Sniper_Rifle.lua	Sat Oct 21 18:21:27 2017 +0200
+++ b/share/hedgewars/Data/Missions/Challenge/Basic_Training_-_Sniper_Rifle.lua	Sat Oct 21 18:38:28 2017 +0200
@@ -41,8 +41,12 @@
 
 local cinematic = false
 
+-- Timer of dynamite (shorter than usual)
+local dynamiteTimer = 2000
 -- Number of dynamite gears currently in game
 local dynamiteCounter = 0
+-- Table of dynamite gears, indexed by gear ID
+local dynamiteGears = {}
 
 -- Position for delayed targets
 local delayedTargetTargetX, delayedTargetY
@@ -72,7 +76,10 @@
 		cinematic = true
 		SetCinematicMode(true)
 	end
-	local dyna = AddGear(x, y, gtDynamite, 0, 0, 0, 0)
+	-- Spawn dynamite with short timer
+	local dyna = AddGear(x, y, gtDynamite, 0, 0, 0, dynamiteTimer)
+	-- Fix dynamite animation due to non-default timer
+	SetTag(dyna, div(5000-dynamiteTimer, 166))
 	if follow then
 		FollowGear(dyna)
 	end
@@ -197,6 +204,13 @@
 	end
 end
 
+-- Insta-blow up dynamite with precise key
+function onPrecise()
+	for gear, _ in pairs(dynamiteGears) do
+		SetTimer(gear, 0)
+	end
+end
+
 -- This function is called when a new gear is added.
 -- We use it to count the number of shots, which we
 -- in turn use to calculate the final score and stats
@@ -205,6 +219,7 @@
 		shots = shots + 1
 	elseif GetGearType(gear) == gtDynamite then
 		dynamiteCounter = dynamiteCounter + 1
+		dynamiteGears[gear] = true
 	end
 end
 
@@ -221,6 +236,7 @@
 	if (gt == gtDynamite) then
 		-- Dynamite blow-up, used to continue the game.
 		dynamiteCounter = dynamiteCounter - 1
+		dynamiteGears[gear] = nil
 
 		-- Wait for all dynamites to be destroyed before we continue.
 		-- Most cut scenes spawn multiple dynamites.