FindPlace in lua now returns null for failure to find a place, and accepts a 5th parameter to try finding a place without considering proximity (note that this can place a gear right next to mines).
--- a/hedgewars/uScript.pas Wed Dec 22 10:09:39 2010 -0500
+++ b/hedgewars/uScript.pas Wed Dec 22 11:59:35 2010 -0500
@@ -827,9 +827,11 @@
function lc_findplace(L : Plua_State) : LongInt; Cdecl;
var gear: PGear;
fall: boolean;
+ tryhard: boolean;
left, right: LongInt;
begin
- if lua_gettop(L) <> 4 then
+ tryhard:= false;
+ if (lua_gettop(L) <> 4) and (lua_gettop(L) <> 5) then
LuaError('Lua: Wrong number of parameters passed to FindPlace!')
else
begin
@@ -837,10 +839,13 @@
fall:= lua_toboolean(L, 2);
left:= lua_tointeger(L, 3);
right:= lua_tointeger(L, 4);
+ if lua_gettop(L) = 5 then tryhard:= lua_toboolean(L, 5);
if gear <> nil then
- FindPlace(gear, fall, left, right)
+ FindPlace(gear, fall, left, right, tryhard);
+ if gear <> nil then lua_pushinteger(L, gear^.uid)
+ else lua_pushnil(L);
end;
- lc_findplace:= 0
+ lc_findplace:= 1
end;
function lc_playsound(L : Plua_State) : LongInt; Cdecl;