hedgewars/uScript.pas
branchqmlfrontend
changeset 10922 999d95494fe7
parent 10903 c9a0cdee4267
child 10978 54a49174dbec
--- a/hedgewars/uScript.pas	Mon May 04 17:48:57 2015 +0300
+++ b/hedgewars/uScript.pas	Mon May 04 17:49:15 2015 +0300
@@ -2202,19 +2202,32 @@
 function lc_placesprite(L : Plua_State) : LongInt; Cdecl;
 var spr   : TSprite;
     lf    : Word;
+    tint  : LongWord;
     i, n : LongInt;
-    placed: boolean;
+    placed, behind, flipHoriz, flipVert : boolean;
 const
     call = 'PlaceSprite';
-    params = 'x, y, sprite, frameIdx [, landFlag, ... ]';
+    params = 'x, y, sprite, frameIdx, tint, behind, flipHoriz, flipVert, [, landFlag, ... ]';
 begin
     placed:= false;
     if CheckAndFetchLuaParamMinCount(L, 4, call, params, n) then
         begin
+        if not lua_isnoneornil(L, 5) then
+	        tint := lua_tointeger(L, 5)
+        else tint := $FFFFFFFF;
+        if not lua_isnoneornil(L, 6) then
+	        behind := lua_toboolean(L, 6)
+        else behind := false;
+        if not lua_isnoneornil(L, 7) then
+	        flipHoriz := lua_toboolean(L, 7)
+        else flipHoriz := false;
+        if not lua_isnoneornil(L, 8) then
+	        flipVert := lua_toboolean(L, 8)
+        else flipVert := false;
         lf:= 0;
 
-        // accept any amount of landflags, loop is never executed if n>5
-        for i:= 5 to n do
+        // accept any amount of landflags, loop is never executed if n>6
+        for i:= 9 to n do
             lf:= lf or lua_tointeger(L, i);
 
         n:= LuaToSpriteOrd(L, 3, call, params);
@@ -2227,7 +2240,7 @@
                 placed:= ForcePlaceOnLand(
                     lua_tointeger(L, 1) - SpritesData[spr].Width div 2,
                     lua_tointeger(L, 2) - SpritesData[spr].Height div 2,
-                    spr, lua_tointeger(L, 4), lf);
+                    spr, lua_tointeger(L, 4), lf, tint, behind, flipHoriz, flipVert);
             end;
         end;
 
@@ -2235,6 +2248,51 @@
     lc_placesprite:= 1
 end;
 
+function lc_erasesprite(L : Plua_State) : LongInt; Cdecl;
+var spr   : TSprite;
+    lf    : Word;
+    i, n : LongInt;
+    eraseOnLFMatch, onlyEraseLF, flipHoriz, flipVert : boolean;
+const
+    call = 'EraseSprite';
+    params = 'x, y, sprite, frameIdx, eraseOnLFMatch, flipHoriz, flipVert, [, landFlag, ... ]';
+begin
+    if CheckAndFetchLuaParamMinCount(L, 4, call, params, n) then
+        begin
+        if not lua_isnoneornil(L, 5) then
+	        eraseOnLFMatch := lua_toboolean(L, 5)
+        else eraseOnLFMatch := false;
+        if not lua_isnoneornil(L, 6) then
+	        onlyEraseLF := lua_toboolean(L, 6)
+        else onlyEraseLF := false;
+        if not lua_isnoneornil(L, 7) then
+	        flipHoriz := lua_toboolean(L, 7)
+        else flipHoriz := false;
+        if not lua_isnoneornil(L, 8) then
+	        flipVert := lua_toboolean(L, 8)
+        else flipVert := false;
+        lf:= 0;
+
+        // accept any amount of landflags, loop is never executed if n>6
+        for i:= 9 to n do
+            lf:= lf or lua_tointeger(L, i);
+
+        n:= LuaToSpriteOrd(L, 3, call, params);
+        if n >= 0 then
+            begin
+            spr:= TSprite(n);
+            if SpritesData[spr].Surface = nil then
+                LuaError(call + ': ' + EnumToStr(spr) + ' cannot be placed! (required information not loaded)' )
+            else
+                EraseLand(
+                    lua_tointeger(L, 1) - SpritesData[spr].Width div 2,
+                    lua_tointeger(L, 2) - SpritesData[spr].Height div 2,
+                    spr, lua_tointeger(L, 4), lf, eraseOnLFMatch, onlyEraseLF, flipHoriz, flipVert);
+            end;
+        end;
+    lc_erasesprite:= 0
+end;
+
 function lc_placegirder(L : Plua_State) : LongInt; Cdecl;
 var placed: boolean;
 begin
@@ -3156,6 +3214,7 @@
 lua_register(luaState, _P'MapHasBorder', @lc_maphasborder);
 lua_register(luaState, _P'GetHogHat', @lc_gethoghat);
 lua_register(luaState, _P'SetHogHat', @lc_sethoghat);
+lua_register(luaState, _P'EraseSprite', @lc_erasesprite);
 lua_register(luaState, _P'PlaceSprite', @lc_placesprite);
 lua_register(luaState, _P'PlaceGirder', @lc_placegirder);
 lua_register(luaState, _P'GetCurAmmoType', @lc_getcurammotype);