# HG changeset patch
# User sheepluva
# Date 1461871702 -7200
# Node ID b58dd09ea950c07d29c4700e9bd16a6b366b4ec1
# Parent  abcdb7bc2620244780a6f5a1a396b5605bfa4d8a# Parent  c21278c4218d6cbdb4ee6b1e0670ec4b31812cdd
merge target practice patch by Wuzzy

diff -r abcdb7bc2620 -r b58dd09ea950 share/hedgewars/Data/Scripts/TargetPractice.lua
--- a/share/hedgewars/Data/Scripts/TargetPractice.lua	Thu Apr 28 21:15:08 2016 +0200
+++ b/share/hedgewars/Data/Scripts/TargetPractice.lua	Thu Apr 28 21:28:22 2016 +0200
@@ -150,12 +150,7 @@
 	end
 
 	_G.onNewTurn = function()
-		-- TODO: Remove the else branch when 0.9.21 has been released
-		if SetWeapon ~= nil then
-			SetWeapon(params.ammoType)
-		else
-			ParseCommand("/setweap "..string.char(params.ammoType))
-		end
+		SetWeapon(params.ammoType)
 	end
 
 	_G.spawnTarget = function()
@@ -165,6 +160,8 @@
 		y = targets[scored+1].y
 
 		SetGearPosition(gear, x, y)
+
+		return gear
 	end
 
 	_G.onGameTick20 = function()
@@ -229,6 +226,18 @@
 		end
 	end
 
+	_G.onGearDelete = function(gear)
+		if GetGearType(gear) == gtTarget and band(GetState(gear), gstDrowning) ~= 0 then
+			AddCaption(loc("You lost your target, try again!", 0xFFFFFFFF, capgrpGameState))
+			local newTarget = spawnTarget()
+			local x, y = GetGearPosition(newTarget)
+			local success = PlaceSprite(x, y + 24, sprAmGirder, 0, 0xFFFFFFFF, false, false, false)
+			if not success then
+				WriteLnToConsole("ERROR: Failed to spawn girder under respawned target!")
+			end
+		end
+	end
+
 	_G.generateStats = function()
 		local accuracy = (scored/shots)*100
 		local end_score_targets = scored * math.ceil(6000/#targets)
@@ -254,7 +263,7 @@
 			end
 			end_score_overall = end_score_targets
 		end
+		SendStat(siPointType, loc("point(s)"))
 		SendStat(siPlayerKills, tostring(end_score_overall), loc(params.teamName))
-		SendStat(siPointType, loc("points"))
 	end
 end