merge
authorXeli
Sat, 26 Nov 2011 17:42:31 +0100
changeset 6439 cb7d84d3ebb4
parent 6437 4ed58839b13b (current diff)
parent 6438 b3a8718ac2a0 (diff)
child 6440 1fa9dc94c93f
merge
--- a/share/hedgewars/Data/Scripts/Tracker.lua	Sat Nov 26 17:40:25 2011 +0100
+++ b/share/hedgewars/Data/Scripts/Tracker.lua	Sat Nov 26 17:42:31 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