Highlander: Fix all hogs getting teleport after hog placement phase
authorWuzzy <Wuzzy2@mail.ru>
Sun, 08 Jul 2018 02:46:59 +0200
changeset 13461 7a0a56c52fd2
parent 13460 38814954a248
child 13462 b587cdb03bac
child 13484 38f9097b6bbc
Highlander: Fix all hogs getting teleport after hog placement phase
ChangeLog.txt
share/hedgewars/Data/Scripts/Multiplayer/Highlander.lua
--- a/ChangeLog.txt	Sun Jul 08 02:06:08 2018 +0200
+++ b/ChangeLog.txt	Sun Jul 08 02:46:59 2018 +0200
@@ -6,6 +6,9 @@
  * Fix hog being unable to walk after using sniper rifle without firing both shots
  * Fix teleport tooltip claiming it doesn't end turn in hog placing phase with inf. attack
 
+Highlander:
+ * Fix all hogs getting teleport after hog placement phase
+
 Continental supplies:
  + Continents are now selected before the game starts
  + Continents give hog different start health
--- a/share/hedgewars/Data/Scripts/Multiplayer/Highlander.lua	Sun Jul 08 02:06:08 2018 +0200
+++ b/share/hedgewars/Data/Scripts/Multiplayer/Highlander.lua	Sun Jul 08 02:46:59 2018 +0200
@@ -68,7 +68,7 @@
 local atktot = 0
 local utiltot = 0
 
-local someHog = nil -- just for looking up the weps
+local teleportConverted = false -- used for special handling of teleport when gfPlaceHog is active
 
 -- Script parameter stuff
 
@@ -179,7 +179,11 @@
 
 function ConvertValues(gear)
 	for w,c in pairs(wepArray) do
-		AddAmmo(gear, w, getGearValue(gear,w) )
+		-- Add hog ammo loadout, but don't touch teleport if in hog placement phase.
+		-- If in hog placement phase, teleport will be touched later (see onNewTurn).
+		if not (GetGameFlag(gfPlaceHog) and TotalRounds == -1 and (w == amTeleport)) then
+			AddAmmo(gear, w, getGearValue(gear,w) )
+		end
 	end
 end
 
@@ -265,7 +269,7 @@
 			utilChoices[i] = 0
 			if i ~= 7 then
 				wepArray[i] = 0
-				c = GetAmmoCount(someHog, i)
+				c = GetAmmo(i)
 				if c > 8 then
 					c = 9
 				end
@@ -301,7 +305,7 @@
 
 			-- re-assign ammo to this guy, so that his entire ammo set will
 			-- be visible during another player's turn
-			if lastHog ~= nil then
+			if lastHog ~= nil and GetHealth(lastHog) then
 				ConvertValues(lastHog)
 			end
 
@@ -318,15 +322,21 @@
 
 function onNewTurn()
 	CheckForHogSwitch()
+
+	-- If hog placement phase is over, set the hog's actual teleport loadout
+	if GetGameFlag(gfPlaceHog) and TotalRounds == 0 and not teleportConverted then
+		runOnHogs(function(gear)
+			AddAmmo(gear, amTeleport, getGearValue(gear, amTeleport))
+		end)
+		-- This makes sure this code is only run once
+		teleportConverted = true
+	end
 end
 
 function onGearAdd(gear)
 
 	if (GetGearType(gear) == gtHedgehog) then
 		trackGear(gear)
-		if someHog == nil then
-			someHog = gear
-		end
 	end
 
 end