--- a/hedgewars/uScript.pas Sat Aug 07 23:04:43 2010 -0400
+++ b/hedgewars/uScript.pas Sat Aug 07 23:32:43 2010 -0400
@@ -117,6 +117,22 @@
lc_hidemission:= 0;
end;
+function lc_spawnhealthcrate(L: Plua_State) : LongInt; Cdecl;
+var x, y: LongInt;
+begin
+ if lua_gettop(L) <> 2 then begin
+ LuaError('Lua: Wrong number of parameters passed to SpawnHealthCrate!');
+ lua_pushnil(L);
+ end
+ else begin
+ x:= lua_tointeger(L, 1);
+ y:= lua_tointeger(L, 2);
+ cCaseFactor := 0;
+ SpawnHealthCrate(x, y);
+ end;
+ lc_spawnhealthCrate := 1;
+end;
+
function lc_addgear(L : Plua_State) : LongInt; Cdecl;
var gear : PGear;
x, y, s, t: LongInt;
@@ -220,6 +236,44 @@
lc_gethogname:= 1
end;
+function lc_gettimer(L : Plua_State) : LongInt; Cdecl;
+var gear : PGear;
+begin
+ if lua_gettop(L) <> 1 then
+ begin
+ LuaError('Lua: Wrong number of parameters passed to GetTimer!');
+ lua_pushnil(L); // return value on stack (nil)
+ end
+ else
+ begin
+ gear:= GearByUID(lua_tointeger(L, 1));
+ if gear <> nil then
+ lua_pushnumber(L, gear^.Timer)
+ else
+ lua_pushnil(L);
+ end;
+ lc_gettimer:= 1
+end;
+
+function lc_gethealth(L : Plua_State) : LongInt; Cdecl;
+var gear : PGear;
+begin
+ if lua_gettop(L) <> 1 then
+ begin
+ LuaError('Lua: Wrong number of parameters passed to GetHealth!');
+ lua_pushnil(L); // return value on stack (nil)
+ end
+ else
+ begin
+ gear:= GearByUID(lua_tointeger(L, 1));
+ if gear <> nil then
+ lua_pushnumber(L, gear^.Health)
+ else
+ lua_pushnil(L);
+ end;
+ lc_gethealth:= 1
+end;
+
function lc_getx(L : Plua_State) : LongInt; Cdecl;
var gear : PGear;
begin
@@ -325,11 +379,30 @@
else
begin
gear:= GearByUID(lua_tointeger(L, 1));
- if gear <> nil then gear^.Health:= lua_tointeger(L, 2)
+ if gear <> nil then
+ begin
+ gear^.Health:= lua_tointeger(L, 2);
+ SetAllToActive;
+ end
end;
lc_sethealth:= 0
end;
+function lc_settimer(L : Plua_State) : LongInt; Cdecl;
+var gear : PGear;
+begin
+ if lua_gettop(L) <> 2 then
+ begin
+ LuaError('Lua: Wrong number of parameters passed to SetTimer!');
+ end
+ else
+ begin
+ gear:= GearByUID(lua_tointeger(L, 1));
+ if gear <> nil then gear^.Timer:= lua_tointeger(L, 2)
+ end;
+ lc_settimer:= 0
+end;
+
function lc_setstate(L : Plua_State) : LongInt; Cdecl;
var gear : PGear;
begin
@@ -340,7 +413,11 @@
else
begin
gear:= GearByUID(lua_tointeger(L, 1));
- if gear <> nil then gear^.State:= lua_tointeger(L, 2)
+ if gear <> nil then
+ begin
+ gear^.State:= lua_tointeger(L, 2);
+ SetAllToActive;
+ end
end;
lc_setstate:= 0
end;
@@ -373,7 +450,11 @@
else
begin
gear:= GearByUID(lua_tointeger(L, 1));
- if gear <> nil then gear^.Tag:= lua_tointeger(L, 2)
+ if gear <> nil then
+ begin
+ gear^.Tag:= lua_tointeger(L, 2);
+ SetAllToActive;
+ end
end;
lc_settag:= 0
end;
@@ -487,6 +568,7 @@
y:= lua_tointeger(L, 3);
gear^.X:= int2hwfloat(x);
gear^.Y:= int2hwfloat(y);
+ SetAllToActive;
end
end;
lc_setgearposition:= 0
@@ -755,6 +837,7 @@
luaopen_base(luaState);
luaopen_string(luaState);
luaopen_math(luaState);
+luaopen_table(luaState);
// import some variables
ScriptSetInteger('LAND_WIDTH', LAND_WIDTH);
@@ -795,6 +878,7 @@
// register functions
lua_register(luaState, 'AddGear', @lc_addgear);
+lua_register(luaState, 'SpawnHealthCrate', @lc_spawnhealthcrate);
lua_register(luaState, 'WriteLnToConsole', @lc_writelntoconsole);
lua_register(luaState, 'GetGearType', @lc_getgeartype);
lua_register(luaState, 'EndGame', @lc_endgame);
@@ -820,6 +904,9 @@
lua_register(luaState, 'SetState', @lc_setstate);
lua_register(luaState, 'GetState', @lc_getstate);
lua_register(luaState, 'SetTag', @lc_settag);
+lua_register(luaState, 'SetTimer', @lc_settimer);
+lua_register(luaState, 'GetTimer', @lc_gettimer);
+lua_register(luaState, 'GetHealth', @lc_gethealth);
ScriptClearStack; // just to be sure stack is empty