Updated the Tracker to handle hog hiding and restoring.
authorHenek
Sat, 26 Nov 2011 16:47:36 +0100
changeset 6438 b3a8718ac2a0
parent 6436 f1a42ba9cab2
child 6439 cb7d84d3ebb4
Updated the Tracker to handle hog hiding and restoring.
share/hedgewars/Data/Scripts/Tracker.lua
--- a/share/hedgewars/Data/Scripts/Tracker.lua	Sat Nov 26 16:18:44 2011 +0100
+++ b/share/hedgewars/Data/Scripts/Tracker.lua	Sat Nov 26 16:47:36 2011 +0100
@@ -32,19 +32,17 @@
         end
     end
     if trackingTeams and GetGearType(gear) == gtHedgehog then
-        for team, hogs in pairs(teams) do
-            if team == GetHogTeamName(gear) then
-                if table.maxn(hogs) == 1 then
-                    hogs = nil
-                else
-                    for k, hog in ipairs(hogs) do
-                        if hog == gear then
-                            table.remove(hogs, k)
-                            break
-                        end
+    	hogs = teams[GetHogTeamName(gear)]
+        if hogs ~= nil then
+            if table.maxn(hogs) == 1 then
+                hogs = nil
+            else
+				for k, hog in ipairs(hogs) do
+                    if hog == gear then
+                        table.remove(hogs, k)
+                        break
                     end
                 end
-                break
             end
         end
     elseif resurrecting and GetGearType(gear) == gtResurrector then
@@ -60,25 +58,6 @@
     end
 end
 
--- Not needed?
--- Registers when a gear is resurrected
---function trackResurrection(gear)
---    if trackingTeams then
---        if GetGearType(gear) == gtHedgehog then
---            found = false
---            for team, hogs in pairs(teams) do
---                if team == GetHogTeamName(gear) then
---                    table.insert(hogs, gear)
---                    found = true
---                end
---            end
---            if not found then
---                teams[GetHogTeamName(gear)] = { gear }
---            end
---        end
---    end
---end
-
 -- Start to keep track of teams
 function trackTeams()
     if not trackingTeams then
@@ -97,6 +76,46 @@
     end
 end
 
+-- Registers when a hog is hidden
+function trackHiding(gear)
+    for k, g in ipairs(gears) do
+        if g == gear then
+            table.remove(gears, k)
+            break
+        end
+    end
+	
+    if trackingTeams then
+    	hogs = teams[GetHogTeamName(gear)]
+    	
+        if hogs ~= nil then
+            if table.maxn(hogs) == 1 then
+                hogs = nil
+            else
+                for k, hog in ipairs(hogs) do
+                    if hog == gear then
+                        table.remove(hogs, k)
+                        break
+                    end
+                end
+            end
+        end
+    end
+end
+
+-- Registers when a hog is restored
+function trackRestoring(gear)
+	table.insert(gears, gear)
+
+    if trackingTeams then
+        team = GetHogTeamName(gear)
+        if teams[team] == nil then
+            teams[team] = {}
+        end
+        table.insert(teams[team], gear)
+    end
+end
+
 -- Get a value for a specific gear
 function getGearValue(gear, key)
     if gearValues[gear] ~= nil then