Play "Flawless" voice when completing the rope or saucer training perfectly
authorWuzzy <Wuzzy2@mail.ru>
Tue, 22 Jan 2019 23:42:23 +0100
changeset 14668 38836d6c5c8a
parent 14667 6b70c109389f
child 14669 fd22b6d474e7
Play "Flawless" voice when completing the rope or saucer training perfectly
share/hedgewars/Data/Missions/Training/Basic_Training_-_Flying_Saucer.lua
share/hedgewars/Data/Missions/Training/Basic_Training_-_Rope.lua
--- a/share/hedgewars/Data/Missions/Training/Basic_Training_-_Flying_Saucer.lua	Wed Jan 23 00:30:12 2019 +0300
+++ b/share/hedgewars/Data/Missions/Training/Basic_Training_-_Flying_Saucer.lua	Tue Jan 22 23:42:23 2019 +0100
@@ -27,6 +27,7 @@
 local Player = nil -- Pointer to hog created in: onGameInit
 local Target = nil -- Pointer to target hog
 local Objective = false -- Get to the target
+local Flawless = true -- Track flawless victory
 
 local TargetNumber = 0 -- The current target number
 local GrenadeThrown = false -- Used for the Boom Target
@@ -204,7 +205,11 @@
 	end
 	SetState(Player, band(GetState(Player), bnot(gstHHDriven)))
 	SetState(Player, bor(GetState(Player), gstWinner))
-	PlaySound(sndVictory, Player)
+	if Flawless then
+		PlaySound(sndFlawless, Player)
+	else
+		PlaySound(sndVictory, Player)
+	end
 	SaveMissionVar("Won", "true")
 
 	SendStat(siGameResult, loc("You have finished the Flying Saucer Training!"))
@@ -564,6 +569,7 @@
 
 function onGearDamage(Gear)
 	if Gear == Player then
+		Flawless = false
 		CleanUpGears()
 		GrenadeThrown = false
 		Check = false
@@ -572,6 +578,7 @@
 
 function onGearResurrect(Gear, VGear)
 	if Gear == Player then
+		Flawless = false
 		AddCaption(loc("Oh no! You have died. Try again!"), capcolDefault, capgrpMessage2)
 		ResetCurrentTarget()
 		if VGear then
@@ -581,6 +588,7 @@
 end
 
 function onSkipTurn()
+	Flawless = false
 	AddCaption(loc("Try again!"), capcolDefault, capgrpMessage2)
 	ResetCurrentTarget()
 end
--- a/share/hedgewars/Data/Missions/Training/Basic_Training_-_Rope.lua	Wed Jan 23 00:30:12 2019 +0300
+++ b/share/hedgewars/Data/Missions/Training/Basic_Training_-_Rope.lua	Tue Jan 22 23:42:23 2019 +0100
@@ -41,6 +41,7 @@
 local wasFirstTurn = false	-- first turn msg was displayed
 local gameOver = false		-- game over (only victory possible)
 local currentTarget = 0		-- current target ID. First target = 1
+local flawless = true		-- flawless if no damage taken and no mistake made
 
 local cpX, cpY = 208, 1384	-- hog checkpoint, initialized with start coords
 
@@ -233,6 +234,7 @@
 				GetFlightTime(CurrentHedgehog) == 0 and (not ropeGear) and
 				math.abs(dX) < 5 and math.abs(dY) < 5 and
 				(x < 3417 or y > 471) then
+			flawless = false
 			AddCaption(loc("Your rope is gone! Try again!"))
 			resetFinalChallenge()
 			PlaySound(sndWarp)
@@ -262,6 +264,7 @@
 function onGearResurrect(gear, vGear)
 	-- Teleport hog to previous checkpoint
 	if gear == hog then
+		flawless = false
 		SetGearPosition(hog, cpX, cpY)
 		if vGear then
 			SetVisualGearValues(vGear, GetX(hog), GetY(hog))
@@ -274,6 +277,12 @@
 	end
 end
 
+function onGearDamage(gear)
+	if gear == hog then
+		flawless = false
+	end
+end
+
 function onGearDelete(gear)
 	if GetGearType(gear) == gtTarget then
 		-- Update checkpoint
@@ -331,7 +340,11 @@
 			SaveMissionVar("Won", "true")
 			ShowMission(loc("Basic Rope Training"), loc("Training complete!"),
 			loc("Congratulations!"), 0, 0)
-			PlaySound(sndVictory, hog)
+			if flawless then
+				PlaySound(sndFlawless, hog)
+			else
+				PlaySound(sndVictory, hog)
+			end
 			AddAmmo(hog, amBaseballBat, 0)
 			AddAmmo(hog, amGrenade, 0)
 			AddAmmo(hog, amRope, 0)