hedgewars/uScript.pas
changeset 10903 c9a0cdee4267
parent 10901 fbf6fbe66092
child 10978 54a49174dbec
equal deleted inserted replaced
10901:fbf6fbe66092 10903:c9a0cdee4267
  2250 
  2250 
  2251 function lc_erasesprite(L : Plua_State) : LongInt; Cdecl;
  2251 function lc_erasesprite(L : Plua_State) : LongInt; Cdecl;
  2252 var spr   : TSprite;
  2252 var spr   : TSprite;
  2253     lf    : Word;
  2253     lf    : Word;
  2254     i, n : LongInt;
  2254     i, n : LongInt;
  2255     eraseOnLFMatch, flipHoriz, flipVert : boolean;
  2255     eraseOnLFMatch, onlyEraseLF, flipHoriz, flipVert : boolean;
  2256 const
  2256 const
  2257     call = 'EraseSprite';
  2257     call = 'EraseSprite';
  2258     params = 'x, y, sprite, frameIdx, eraseOnLFMatch, flipHoriz, flipVert, [, landFlag, ... ]';
  2258     params = 'x, y, sprite, frameIdx, eraseOnLFMatch, flipHoriz, flipVert, [, landFlag, ... ]';
  2259 begin
  2259 begin
  2260     if CheckAndFetchLuaParamMinCount(L, 4, call, params, n) then
  2260     if CheckAndFetchLuaParamMinCount(L, 4, call, params, n) then
  2261         begin
  2261         begin
  2262         if not lua_isnoneornil(L, 5) then
  2262         if not lua_isnoneornil(L, 5) then
  2263 	        eraseOnLFMatch := lua_toboolean(L, 5)
  2263 	        eraseOnLFMatch := lua_toboolean(L, 5)
  2264         else eraseOnLFMatch := false;
  2264         else eraseOnLFMatch := false;
  2265         if not lua_isnoneornil(L, 6) then
  2265         if not lua_isnoneornil(L, 6) then
  2266 	        flipHoriz := lua_toboolean(L, 6)
  2266 	        onlyEraseLF := lua_toboolean(L, 6)
       
  2267         else onlyEraseLF := false;
       
  2268         if not lua_isnoneornil(L, 7) then
       
  2269 	        flipHoriz := lua_toboolean(L, 7)
  2267         else flipHoriz := false;
  2270         else flipHoriz := false;
  2268         if not lua_isnoneornil(L, 7) then
  2271         if not lua_isnoneornil(L, 8) then
  2269 	        flipVert := lua_toboolean(L, 7)
  2272 	        flipVert := lua_toboolean(L, 8)
  2270         else flipVert := false;
  2273         else flipVert := false;
  2271         lf:= 0;
  2274         lf:= 0;
  2272 
  2275 
  2273         // accept any amount of landflags, loop is never executed if n>6
  2276         // accept any amount of landflags, loop is never executed if n>6
  2274         for i:= 8 to n do
  2277         for i:= 9 to n do
  2275             lf:= lf or lua_tointeger(L, i);
  2278             lf:= lf or lua_tointeger(L, i);
  2276 
  2279 
  2277         n:= LuaToSpriteOrd(L, 3, call, params);
  2280         n:= LuaToSpriteOrd(L, 3, call, params);
  2278         if n >= 0 then
  2281         if n >= 0 then
  2279             begin
  2282             begin
  2282                 LuaError(call + ': ' + EnumToStr(spr) + ' cannot be placed! (required information not loaded)' )
  2285                 LuaError(call + ': ' + EnumToStr(spr) + ' cannot be placed! (required information not loaded)' )
  2283             else
  2286             else
  2284                 EraseLand(
  2287                 EraseLand(
  2285                     lua_tointeger(L, 1) - SpritesData[spr].Width div 2,
  2288                     lua_tointeger(L, 1) - SpritesData[spr].Width div 2,
  2286                     lua_tointeger(L, 2) - SpritesData[spr].Height div 2,
  2289                     lua_tointeger(L, 2) - SpritesData[spr].Height div 2,
  2287                     spr, lua_tointeger(L, 4), lf, eraseOnLFMatch, flipHoriz, flipVert);
  2290                     spr, lua_tointeger(L, 4), lf, eraseOnLFMatch, onlyEraseLF, flipHoriz, flipVert);
  2288             end;
  2291             end;
  2289         end;
  2292         end;
  2290     lc_erasesprite:= 0
  2293     lc_erasesprite:= 0
  2291 end;
  2294 end;
  2292 
  2295