add a new lua library with misc tools and removed redundant tracker functions
authorHenek
Tue, 25 Jan 2011 20:32:58 +0100
changeset 4873 98dbb9b985e5
parent 4872 6b2fb9f0054a
child 4874 f508adb769b8
add a new lua library with misc tools and removed redundant tracker functions
share/hedgewars/Data/Scripts/Tracker.lua
share/hedgewars/Data/Scripts/Utils.lua
--- a/share/hedgewars/Data/Scripts/Tracker.lua	Mon Jan 24 23:48:44 2011 +0200
+++ b/share/hedgewars/Data/Scripts/Tracker.lua	Tue Jan 25 20:32:58 2011 +0100
@@ -224,27 +224,6 @@
     end
 end
 
--- Run a function on all gears within a box
-function runOnGearsInBox(func, x, y, w, h)
-    for k, gear in ipairs(gears) do
-        gx, gy = GetGearPosition(gear)
-        if gx >= x and gy >= y and gx <= x + w and gy <= y + h then
-            func(gear)
-        end
-    end
-end
-
--- Run a function on all gears within a circle
-function runOnGearsInCircle(func, x, y, r)
-    for k, gear in ipairs(gears) do
-        gx, gy = GetGearPosition(gear)
-        gr = GetGearRadius(gear)
-        if (r + gr) ^ 2 >= (x - gx) ^ 2 + (y - gy) ^ 2 then
-            func(gear)
-        end
-    end
-end
-
 -- Run a function on all tracked hogs
 function runOnHogs(func)
     for k, hogs in pairs(teams) do
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/share/hedgewars/Data/Scripts/Utils.lua	Tue Jan 25 20:32:58 2011 +0100
@@ -0,0 +1,22 @@
+-- Library for miscellaneous utilitiy functions
+
+-- Check if a gear is inside a box
+function gearIsInBox(gear, x, y, w, h)
+    gx, gy = GetGearPosition(gear)
+    if gx >= x and gy >= y and gx <= x + w and gy <= y + h then
+        return true
+    end
+    return false
+end
+
+-- Check if a gear is inside a circle
+function gearIsInCircle(gear, x, y, r, useRadius)
+    gx, gy = GetGearPosition(gear)
+    if useRadius then
+        r = r + GetGearRadius(gear)
+    end
+    if r ^ 2 >= (x - gx) ^ 2 + (y - gy) ^ 2 then
+        return true
+    end
+    return false
+end