added GetGearRaduis and minor Tracker things
authorHenek
Sat, 22 Jan 2011 22:31:05 +0100
changeset 4869 7a720b5d2247
parent 4868 652139f230c7
child 4870 c02406028e02
added GetGearRaduis and minor Tracker things
hedgewars/uScript.pas
share/hedgewars/Data/Scripts/Tracker.lua
--- a/hedgewars/uScript.pas	Sat Jan 22 22:39:35 2011 +0300
+++ b/hedgewars/uScript.pas	Sat Jan 22 22:31:05 2011 +0100
@@ -1164,6 +1164,25 @@
         lua_pushboolean(L, hasBorder);
     lc_maphasborder:= 1
 end;
+
+function lc_getgearradius(L : Plua_State) : LongInt; Cdecl;
+var gear : PGear;
+begin
+    if lua_gettop(L) <> 1 then
+        begin
+        LuaError('Lua: Wrong number of parameters passed to GetGearRadius!');
+        lua_pushnil(L); // return value on stack (nil)
+        end
+    else
+        begin
+        gear:= GearByUID(lua_tointeger(L, 1));
+        if gear <> nil then
+            lua_pushinteger(L, gear^.Radius)
+        else
+            lua_pushnil(L);
+        end;
+    lc_getgearradius:= 1
+end;
 ///////////////////
 
 procedure ScriptPrintStack;
@@ -1571,6 +1590,7 @@
 lua_register(luaState, 'CampaignLock', @lc_campaignlock);
 lua_register(luaState, 'CampaignUnlock', @lc_campaignunlock);
 lua_register(luaState, 'GetGearElasticity', @lc_getgearelasticity);
+lua_register(luaState, 'GetGearRadius', @lc_getgearradius);
 lua_register(luaState, 'GetGearMessage', @lc_getgearmessage);
 lua_register(luaState, 'SetGearMessage', @lc_setgearmessage);
 lua_register(luaState, 'GetRandom', @lc_getrandom);
--- a/share/hedgewars/Data/Scripts/Tracker.lua	Sat Jan 22 22:39:35 2011 +0300
+++ b/share/hedgewars/Data/Scripts/Tracker.lua	Sat Jan 22 22:31:05 2011 +0100
@@ -224,6 +224,27 @@
     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