hedgewars/uScript.pas
changeset 5906 ed9676dc8cb4
parent 5900 37516a3bdb0e
child 5932 5164d17b6374
child 5964 44d2dc3b438f
equal deleted inserted replaced
5713:190d6bb075c5 5906:ed9676dc8cb4
    34 procedure ScriptPrintStack;
    34 procedure ScriptPrintStack;
    35 procedure ScriptClearStack;
    35 procedure ScriptClearStack;
    36 
    36 
    37 procedure ScriptLoad(name : shortstring);
    37 procedure ScriptLoad(name : shortstring);
    38 procedure ScriptOnGameInit;
    38 procedure ScriptOnGameInit;
       
    39 procedure ScriptOnScreenResize();
    39 
    40 
    40 procedure ScriptCall(fname : shortstring);
    41 procedure ScriptCall(fname : shortstring);
    41 function ScriptCall(fname : shortstring; par1: LongInt) : LongInt;
    42 function ScriptCall(fname : shortstring; par1: LongInt) : LongInt;
    42 function ScriptCall(fname : shortstring; par1, par2: LongInt) : LongInt;
    43 function ScriptCall(fname : shortstring; par1, par2: LongInt) : LongInt;
    43 function ScriptCall(fname : shortstring; par1, par2, par3: LongInt) : LongInt;
    44 function ScriptCall(fname : shortstring; par1, par2, par3: LongInt) : LongInt;
  1500         LuaError('Lua: Wrong number of parameters passed to GetCurAmmoType!')
  1501         LuaError('Lua: Wrong number of parameters passed to GetCurAmmoType!')
  1501     else
  1502     else
  1502         lua_pushinteger(L, ord(CurrentHedgehog^.CurAmmoType));
  1503         lua_pushinteger(L, ord(CurrentHedgehog^.CurAmmoType));
  1503     lc_getcurammotype := 1;
  1504     lc_getcurammotype := 1;
  1504 end;
  1505 end;
       
  1506 
       
  1507 // boolean TestRectForObstacle(x1, y1, x2, y2, landOnly)
       
  1508 function lc_testrectforobstacle(L : Plua_State) : LongInt; Cdecl;
       
  1509 var rtn: Boolean;
       
  1510 begin
       
  1511     if lua_gettop(L) <> 5 then
       
  1512         begin
       
  1513         LuaError('Lua: Wrong number of parameters passed to TestRectForObstacle!');
       
  1514         lua_pushnil(L); // return value on stack (nil)
       
  1515         end
       
  1516     else
       
  1517         begin
       
  1518         rtn:= TestRectancleForObstacle(
       
  1519                     lua_tointeger(L, 1),
       
  1520                     lua_tointeger(L, 2),
       
  1521                     lua_tointeger(L, 3),
       
  1522                     lua_tointeger(L, 4),
       
  1523                     lua_toboolean(L, 5)
       
  1524                     );
       
  1525         lua_pushboolean(L, rtn);
       
  1526         end;
       
  1527     lc_testrectforobstacle:= 1
       
  1528 end;
  1505 ///////////////////
  1529 ///////////////////
  1506 
  1530 
  1507 procedure ScriptPrintStack;
  1531 procedure ScriptPrintStack;
  1508 var n, i : LongInt;
  1532 var n, i : LongInt;
  1509 begin
  1533 begin
  1622 
  1646 
  1623 ScriptSetInteger('ClansCount', ClansCount);
  1647 ScriptSetInteger('ClansCount', ClansCount);
  1624 ScriptSetInteger('TeamsCount', TeamsCount)
  1648 ScriptSetInteger('TeamsCount', TeamsCount)
  1625 end;
  1649 end;
  1626 
  1650 
       
  1651 
       
  1652 // Update values of screen dimensions and allow script to react to resolution change
       
  1653 procedure ScriptOnScreenResize();
       
  1654 begin
       
  1655 ScriptSetInteger('ScreenHeight', cScreenHeight);
       
  1656 ScriptSetInteger('ScreenWidth', cScreenWidth);
       
  1657 ScriptCall('onScreenResize');
       
  1658 end;
       
  1659 
       
  1660 
  1627 procedure ScriptLoad(name : shortstring);
  1661 procedure ScriptLoad(name : shortstring);
  1628 var ret : LongInt;
  1662 var ret : LongInt;
  1629       s : shortstring;
  1663       s : shortstring;
  1630 begin
  1664 begin
  1631 s:= UserPathz[ptData] + '/' + name;
  1665 s:= UserPathz[ptData] + '/' + name;
  1796 luaopen_table(luaState);
  1830 luaopen_table(luaState);
  1797 
  1831 
  1798 // import some variables
  1832 // import some variables
  1799 ScriptSetInteger('LAND_WIDTH', LAND_WIDTH);
  1833 ScriptSetInteger('LAND_WIDTH', LAND_WIDTH);
  1800 ScriptSetInteger('LAND_HEIGHT', LAND_HEIGHT);
  1834 ScriptSetInteger('LAND_HEIGHT', LAND_HEIGHT);
  1801 
       
  1802 ScriptSetString('L', cLocale);
  1835 ScriptSetString('L', cLocale);
  1803 
  1836 
  1804 // import game flags
  1837 // import game flags
  1805 ScriptSetInteger('gfForts', gfForts);
  1838 ScriptSetInteger('gfForts', gfForts);
  1806 ScriptSetInteger('gfMultiWeapon', gfMultiWeapon);
  1839 ScriptSetInteger('gfMultiWeapon', gfMultiWeapon);
  1970 lua_register(luaState, 'MapHasBorder', @lc_maphasborder);
  2003 lua_register(luaState, 'MapHasBorder', @lc_maphasborder);
  1971 lua_register(luaState, 'GetHogHat', @lc_gethoghat);
  2004 lua_register(luaState, 'GetHogHat', @lc_gethoghat);
  1972 lua_register(luaState, 'SetHogHat', @lc_sethoghat);
  2005 lua_register(luaState, 'SetHogHat', @lc_sethoghat);
  1973 lua_register(luaState, 'PlaceGirder', @lc_placegirder);
  2006 lua_register(luaState, 'PlaceGirder', @lc_placegirder);
  1974 lua_register(luaState, 'GetCurAmmoType', @lc_getcurammotype);
  2007 lua_register(luaState, 'GetCurAmmoType', @lc_getcurammotype);
       
  2008 lua_register(luaState, 'TestRectForObstacle', @lc_testrectforobstacle);
  1975 
  2009 
  1976 
  2010 
  1977 ScriptClearStack; // just to be sure stack is empty
  2011 ScriptClearStack; // just to be sure stack is empty
  1978 ScriptLoaded:= false;
  2012 ScriptLoaded:= false;
  1979 end;
  2013 end;