CTF: Fix Lua errors when using kamikaze or tardis
authorWuzzy <Wuzzy2@mail.ru>
Thu, 08 Mar 2018 02:03:23 +0100
changeset 13109 e0ec37c8104d
parent 13108 cf2a58dccc4a
child 13110 b14cac8ac56c
CTF: Fix Lua errors when using kamikaze or tardis
ChangeLog.txt
share/hedgewars/Data/Scripts/Multiplayer/Capture_the_Flag.lua
--- a/ChangeLog.txt	Thu Mar 08 01:22:00 2018 +0100
+++ b/ChangeLog.txt	Thu Mar 08 02:03:23 2018 +0100
@@ -49,9 +49,10 @@
  + Battalion (King Mode): If the king dies, the hogs die normally instead of disappearing
  + Space Invasion: Add a default Space Invasion game scheme
  + HedgeEditor: Show cursor coordinates in top left corner
- + Control, Capture the Flag: Always remove TimeBox and Resurrector
+ + Control: Always remove TimeBox and Resurrector
  * Battalion: Some texts in the mission panel were wrong and misleading
  * Construction Mode: Remove drill strike if added by weapon scheme (it's broken)
+ * Capture the Flag: Properly place flag when using kamikaze or TimeBox
 
 A Space Adventure:
  + Precise Shooting: Display collected ammo
--- a/share/hedgewars/Data/Scripts/Multiplayer/Capture_the_Flag.lua	Thu Mar 08 01:22:00 2018 +0100
+++ b/share/hedgewars/Data/Scripts/Multiplayer/Capture_the_Flag.lua	Thu Mar 08 02:03:23 2018 +0100
@@ -417,14 +417,6 @@
 
 	for i = 0, 1 do
 
-		-- if someone uses kamikaze downwards, this can happen as the hog won't respawn
-		if (LAND_HEIGHT - fSpawnY[i]) < 0 then
-			tempG = AddGear(0, 0, gtTarget, 0, 0, 0, 0)
-     			FindPlace(tempG, true, 0, LAND_WIDTH, true)
-			fSpawnX[i], fSpawnY[i] = GetGearPosition(tempG)
-			DeleteGear(tempG)
-		end
-
 		fGear[i] = AddVisualGear(fSpawnX[i],fSpawnY[i],vgtCircle,0,true)
 		fCirc[i] = AddVisualGear(fSpawnX[i],fSpawnY[i],vgtCircle,0,true)
 		fSpawnC[i] = AddVisualGear(fSpawnX[i],fSpawnY[i],vgtCircle,0,true)
@@ -515,8 +507,10 @@
 		end
 	end]]
 
-	fPlaced[0] = false
-	fPlaced[1] = false
+	for i=0, 1 do
+		fPlaced[i] = false
+		fCaptures[i] = 0
+	end
 
 	--zxc = AddVisualGear(fSpawnX[i],fSpawnY[i],vgtCircle,0,true)
 
@@ -524,12 +518,12 @@
 	--SetVisualGearValues(zxc, 1000,1000, 20, 255, 1,    10,                     0,         200,        1,      GetClanColor(0))
 					--minO,max0 -glowyornot	--pulsate timer	 -- fuckall      -- radius -- width  -- colour
 	for h=1, numhhs do
-		-- Tardis causes too many unexpected situations, so we forbid it
-		AddAmmo(hhs[h], amTardis, 0)
 		-- Hogs are resurrected for free, so this is pointless
 		AddAmmo(hhs[h], amResurrector, 0)
 	end
 
+	updateScores()
+
 end
 
 
@@ -593,7 +587,7 @@
 			i = 1
 		end
 
-		if TurnTimeLeft == 0 then
+		if TurnTimeLeft == 0 and GetX(CurrentHedgehog) then
 			fSpawnX[i] = GetX(CurrentHedgehog)
 			fSpawnY[i] = GetY(CurrentHedgehog)
 		end
@@ -654,6 +648,13 @@
 	end
 end
 
+function onHogAttack(ammoType)
+	if not gameStarted and ammoType == amTardis then
+		local i = GetHogClan(CurrentHedgehog)
+		fSpawnX[i] = GetX(CurrentHedgehog)
+		fSpawnY[i] = GetY(CurrentHedgehog)
+	end
+end
 
 function onGearAdd(gear)
 
@@ -678,6 +679,10 @@
 
 	if GetGearType(gear) == gtHedgehog then
 		InABetterPlaceNow(gear)
+	elseif GetGearType(gear) == gtKamikaze and not gameStarted then
+		local i = GetHogClan(CurrentHedgehog)
+		fSpawnX[i] = GetX(CurrentHedgehog)
+		fSpawnY[i] = GetY(CurrentHedgehog)
 	end
 
 end