hedgewars/uScript.pas
branchqmlfrontend
changeset 10922 999d95494fe7
parent 10903 c9a0cdee4267
child 10978 54a49174dbec
equal deleted inserted replaced
10908:1bd7a3a28b18 10922:999d95494fe7
  2200 end;
  2200 end;
  2201 
  2201 
  2202 function lc_placesprite(L : Plua_State) : LongInt; Cdecl;
  2202 function lc_placesprite(L : Plua_State) : LongInt; Cdecl;
  2203 var spr   : TSprite;
  2203 var spr   : TSprite;
  2204     lf    : Word;
  2204     lf    : Word;
       
  2205     tint  : LongWord;
  2205     i, n : LongInt;
  2206     i, n : LongInt;
  2206     placed: boolean;
  2207     placed, behind, flipHoriz, flipVert : boolean;
  2207 const
  2208 const
  2208     call = 'PlaceSprite';
  2209     call = 'PlaceSprite';
  2209     params = 'x, y, sprite, frameIdx [, landFlag, ... ]';
  2210     params = 'x, y, sprite, frameIdx, tint, behind, flipHoriz, flipVert, [, landFlag, ... ]';
  2210 begin
  2211 begin
  2211     placed:= false;
  2212     placed:= false;
  2212     if CheckAndFetchLuaParamMinCount(L, 4, call, params, n) then
  2213     if CheckAndFetchLuaParamMinCount(L, 4, call, params, n) then
  2213         begin
  2214         begin
       
  2215         if not lua_isnoneornil(L, 5) then
       
  2216 	        tint := lua_tointeger(L, 5)
       
  2217         else tint := $FFFFFFFF;
       
  2218         if not lua_isnoneornil(L, 6) then
       
  2219 	        behind := lua_toboolean(L, 6)
       
  2220         else behind := false;
       
  2221         if not lua_isnoneornil(L, 7) then
       
  2222 	        flipHoriz := lua_toboolean(L, 7)
       
  2223         else flipHoriz := false;
       
  2224         if not lua_isnoneornil(L, 8) then
       
  2225 	        flipVert := lua_toboolean(L, 8)
       
  2226         else flipVert := false;
  2214         lf:= 0;
  2227         lf:= 0;
  2215 
  2228 
  2216         // accept any amount of landflags, loop is never executed if n>5
  2229         // accept any amount of landflags, loop is never executed if n>6
  2217         for i:= 5 to n do
  2230         for i:= 9 to n do
  2218             lf:= lf or lua_tointeger(L, i);
  2231             lf:= lf or lua_tointeger(L, i);
  2219 
  2232 
  2220         n:= LuaToSpriteOrd(L, 3, call, params);
  2233         n:= LuaToSpriteOrd(L, 3, call, params);
  2221         if n >= 0 then
  2234         if n >= 0 then
  2222             begin
  2235             begin
  2225                 LuaError(call + ': ' + EnumToStr(spr) + ' cannot be placed! (required information not loaded)' )
  2238                 LuaError(call + ': ' + EnumToStr(spr) + ' cannot be placed! (required information not loaded)' )
  2226             else
  2239             else
  2227                 placed:= ForcePlaceOnLand(
  2240                 placed:= ForcePlaceOnLand(
  2228                     lua_tointeger(L, 1) - SpritesData[spr].Width div 2,
  2241                     lua_tointeger(L, 1) - SpritesData[spr].Width div 2,
  2229                     lua_tointeger(L, 2) - SpritesData[spr].Height div 2,
  2242                     lua_tointeger(L, 2) - SpritesData[spr].Height div 2,
  2230                     spr, lua_tointeger(L, 4), lf);
  2243                     spr, lua_tointeger(L, 4), lf, tint, behind, flipHoriz, flipVert);
  2231             end;
  2244             end;
  2232         end;
  2245         end;
  2233 
  2246 
  2234     lua_pushboolean(L, placed);
  2247     lua_pushboolean(L, placed);
  2235     lc_placesprite:= 1
  2248     lc_placesprite:= 1
       
  2249 end;
       
  2250 
       
  2251 function lc_erasesprite(L : Plua_State) : LongInt; Cdecl;
       
  2252 var spr   : TSprite;
       
  2253     lf    : Word;
       
  2254     i, n : LongInt;
       
  2255     eraseOnLFMatch, onlyEraseLF, flipHoriz, flipVert : boolean;
       
  2256 const
       
  2257     call = 'EraseSprite';
       
  2258     params = 'x, y, sprite, frameIdx, eraseOnLFMatch, flipHoriz, flipVert, [, landFlag, ... ]';
       
  2259 begin
       
  2260     if CheckAndFetchLuaParamMinCount(L, 4, call, params, n) then
       
  2261         begin
       
  2262         if not lua_isnoneornil(L, 5) then
       
  2263 	        eraseOnLFMatch := lua_toboolean(L, 5)
       
  2264         else eraseOnLFMatch := false;
       
  2265         if not lua_isnoneornil(L, 6) then
       
  2266 	        onlyEraseLF := lua_toboolean(L, 6)
       
  2267         else onlyEraseLF := false;
       
  2268         if not lua_isnoneornil(L, 7) then
       
  2269 	        flipHoriz := lua_toboolean(L, 7)
       
  2270         else flipHoriz := false;
       
  2271         if not lua_isnoneornil(L, 8) then
       
  2272 	        flipVert := lua_toboolean(L, 8)
       
  2273         else flipVert := false;
       
  2274         lf:= 0;
       
  2275 
       
  2276         // accept any amount of landflags, loop is never executed if n>6
       
  2277         for i:= 9 to n do
       
  2278             lf:= lf or lua_tointeger(L, i);
       
  2279 
       
  2280         n:= LuaToSpriteOrd(L, 3, call, params);
       
  2281         if n >= 0 then
       
  2282             begin
       
  2283             spr:= TSprite(n);
       
  2284             if SpritesData[spr].Surface = nil then
       
  2285                 LuaError(call + ': ' + EnumToStr(spr) + ' cannot be placed! (required information not loaded)' )
       
  2286             else
       
  2287                 EraseLand(
       
  2288                     lua_tointeger(L, 1) - SpritesData[spr].Width div 2,
       
  2289                     lua_tointeger(L, 2) - SpritesData[spr].Height div 2,
       
  2290                     spr, lua_tointeger(L, 4), lf, eraseOnLFMatch, onlyEraseLF, flipHoriz, flipVert);
       
  2291             end;
       
  2292         end;
       
  2293     lc_erasesprite:= 0
  2236 end;
  2294 end;
  2237 
  2295 
  2238 function lc_placegirder(L : Plua_State) : LongInt; Cdecl;
  2296 function lc_placegirder(L : Plua_State) : LongInt; Cdecl;
  2239 var placed: boolean;
  2297 var placed: boolean;
  2240 begin
  2298 begin
  3154 lua_register(luaState, _P'GetDataPath', @lc_getdatapath);
  3212 lua_register(luaState, _P'GetDataPath', @lc_getdatapath);
  3155 lua_register(luaState, _P'GetUserDataPath', @lc_getuserdatapath);
  3213 lua_register(luaState, _P'GetUserDataPath', @lc_getuserdatapath);
  3156 lua_register(luaState, _P'MapHasBorder', @lc_maphasborder);
  3214 lua_register(luaState, _P'MapHasBorder', @lc_maphasborder);
  3157 lua_register(luaState, _P'GetHogHat', @lc_gethoghat);
  3215 lua_register(luaState, _P'GetHogHat', @lc_gethoghat);
  3158 lua_register(luaState, _P'SetHogHat', @lc_sethoghat);
  3216 lua_register(luaState, _P'SetHogHat', @lc_sethoghat);
       
  3217 lua_register(luaState, _P'EraseSprite', @lc_erasesprite);
  3159 lua_register(luaState, _P'PlaceSprite', @lc_placesprite);
  3218 lua_register(luaState, _P'PlaceSprite', @lc_placesprite);
  3160 lua_register(luaState, _P'PlaceGirder', @lc_placegirder);
  3219 lua_register(luaState, _P'PlaceGirder', @lc_placegirder);
  3161 lua_register(luaState, _P'GetCurAmmoType', @lc_getcurammotype);
  3220 lua_register(luaState, _P'GetCurAmmoType', @lc_getcurammotype);
  3162 lua_register(luaState, _P'TestRectForObstacle', @lc_testrectforobstacle);
  3221 lua_register(luaState, _P'TestRectForObstacle', @lc_testrectforobstacle);
  3163 lua_register(luaState, _P'GetGravity', @lc_getgravity);
  3222 lua_register(luaState, _P'GetGravity', @lc_getgravity);