hedgewars/uScript.pas
changeset 15950 77f1973611ec
parent 15908 4c0f8dbf6c13
child 15968 91c487e7d11d
equal deleted inserted replaced
15949:668c88b31dd6 15950:77f1973611ec
   454 
   454 
   455 // sets weapon to the desired ammo type
   455 // sets weapon to the desired ammo type
   456 function lc_setweapon(L : Plua_State) : LongInt; Cdecl;
   456 function lc_setweapon(L : Plua_State) : LongInt; Cdecl;
   457 var at: LongInt;
   457 var at: LongInt;
   458 const
   458 const
   459     call = 'SetWeapon';
   459     callStr = 'SetWeapon';
   460     params = 'ammoType';
   460     paramsStr = 'ammoType';
   461 begin
   461 begin
   462     // no point to run this without any CurrentHedgehog
   462     // no point to run this without any CurrentHedgehog
   463     if (CurrentHedgehog <> nil) and (CheckLuaParamCount(L, 1, call, params)) then
   463     if (CurrentHedgehog <> nil) and (CheckLuaParamCount(L, 1, callStr, paramsStr)) then
   464         begin
   464         begin
   465         at:= LuaToAmmoTypeOrd(L, 1, call, params);
   465         at:= LuaToAmmoTypeOrd(L, 1, callStr, paramsStr);
   466         if at >= 0 then
   466         if at >= 0 then
   467             ParseCommand('setweap ' + char(at), true, true);
   467             ParseCommand('setweap ' + char(at), true, true);
   468         end;
   468         end;
   469     lc_setweapon:= 0;
   469     lc_setweapon:= 0;
   470 end;
   470 end;
   471 
   471 
   472 // enable/disable cinematic effects
   472 // enable/disable cinematic effects
   473 function lc_setcinematicmode(L : Plua_State) : LongInt; Cdecl;
   473 function lc_setcinematicmode(L : Plua_State) : LongInt; Cdecl;
   474 const
   474 const
   475     call = 'SetCinematicMode';
   475     callStr = 'SetCinematicMode';
   476     params = 'enable';
   476     paramsStr = 'enable';
   477 begin
   477 begin
   478     if (CheckLuaParamCount(L, 1, call, params)) then
   478     if (CheckLuaParamCount(L, 1, callStr, paramsStr)) then
   479         begin
   479         begin
   480         CinematicScript:= lua_toboolean(L, 1);
   480         CinematicScript:= lua_toboolean(L, 1);
   481         end;
   481         end;
   482     lc_setcinematicmode:= 0;
   482     lc_setcinematicmode:= 0;
   483 end;
   483 end;
   484 
   484 
   485 // no parameter means reset to default (and 0 means unlimited)
   485 // no parameter means reset to default (and 0 means unlimited)
   486 function lc_setmaxbuilddistance(L : Plua_State) : LongInt; Cdecl;
   486 function lc_setmaxbuilddistance(L : Plua_State) : LongInt; Cdecl;
   487 var np: LongInt;
   487 var np: LongInt;
   488 const
   488 const
   489     call = 'SetMaxBuildDistance';
   489     callStr = 'SetMaxBuildDistance';
   490     params = '[ distInPx ]';
   490     paramsStr = '[ distInPx ]';
   491 begin
   491 begin
   492     if CheckAndFetchParamCountRange(L, 0, 1, call, params, np) then
   492     if CheckAndFetchParamCountRange(L, 0, 1, callStr, paramsStr, np) then
   493         begin
   493         begin
   494         if np = 0 then
   494         if np = 0 then
   495             begin
   495             begin
   496             // no args? reset
   496             // no args? reset
   497             cBuildMaxDist:= cDefaultBuildMaxDist;
   497             cBuildMaxDist:= cDefaultBuildMaxDist;
   506 function lc_setnextweapon(L : Plua_State) : LongInt; Cdecl;
   506 function lc_setnextweapon(L : Plua_State) : LongInt; Cdecl;
   507 var at          : LongInt;
   507 var at          : LongInt;
   508     nextAmmo    : TAmmo;
   508     nextAmmo    : TAmmo;
   509     s, a, cs, fa: LongInt;
   509     s, a, cs, fa: LongInt;
   510 const
   510 const
   511     call = 'SetNextWeapon';
   511     callStr = 'SetNextWeapon';
   512     params = '';
   512     paramsStr = '';
   513 begin
   513 begin
   514     if (CurrentHedgehog <> nil) and (CheckLuaParamCount(L, 0, call, params)) then
   514     if (CurrentHedgehog <> nil) and (CheckLuaParamCount(L, 0, callStr, paramsStr)) then
   515         begin
   515         begin
   516         at:= -1;
   516         at:= -1;
   517         with CurrentHedgehog^ do
   517         with CurrentHedgehog^ do
   518             begin
   518             begin
   519             cs:= 0; // current slot
   519             cs:= 0; // current slot
   584     lc_hidemission:= 0;
   584     lc_hidemission:= 0;
   585 end;
   585 end;
   586 
   586 
   587 function lc_setammotexts(L : Plua_State) : LongInt; Cdecl;
   587 function lc_setammotexts(L : Plua_State) : LongInt; Cdecl;
   588 const
   588 const
   589     call = 'SetAmmoTexts';
   589     callStr = 'SetAmmoTexts';
   590     params = 'ammoType, name, caption, description [, showExtra]';
   590     paramsStr = 'ammoType, name, caption, description [, showExtra]';
   591 var n: integer;
   591 var n: integer;
   592     showExtra: boolean;
   592     showExtra: boolean;
   593 begin
   593 begin
   594     if CheckAndFetchParamCount(L, 4, 5, call, params, n) then
   594     if CheckAndFetchParamCount(L, 4, 5, callStr, paramsStr, n) then
   595         begin
   595         begin
   596         if n = 5 then
   596         if n = 5 then
   597             showExtra:= lua_toboolean(L, 5)
   597             showExtra:= lua_toboolean(L, 5)
   598         else
   598         else
   599             showExtra:= true;
   599             showExtra:= true;
   600         SetAmmoTexts(TAmmoType(LuaToAmmoTypeOrd(L, 1, call, params)), lua_tostringA(L, 2), lua_tostringA(L, 3), lua_tostringA(L, 4), showExtra);
   600         SetAmmoTexts(TAmmoType(LuaToAmmoTypeOrd(L, 1, callStr, paramsStr)), lua_tostringA(L, 2), lua_tostringA(L, 3), lua_tostringA(L, 4), showExtra);
   601         end;
   601         end;
   602     lc_setammotexts:= 0;
   602     lc_setammotexts:= 0;
   603 end;
   603 end;
   604 
   604 
   605 function lc_setammodescriptionappendix(L : Plua_State) : LongInt; Cdecl;
   605 function lc_setammodescriptionappendix(L : Plua_State) : LongInt; Cdecl;
   606 const
   606 const
   607     call = 'SetAmmoDescriptionAppendix';
   607     callStr = 'SetAmmoDescriptionAppendix';
   608     params = 'ammoType, descAppend';
   608     paramsStr = 'ammoType, descAppend';
   609 var
   609 var
   610     ammoType: TAmmoType;
   610     ammoType: TAmmoType;
   611     descAppend: ansistring;
   611     descAppend: ansistring;
   612 begin
   612 begin
   613     if CheckLuaParamCount(L, 2, call, params) then
   613     if CheckLuaParamCount(L, 2, callStr, paramsStr) then
   614         begin
   614         begin
   615         ammoType := TAmmoType(LuaToAmmoTypeOrd(L, 1, call, params));
   615         ammoType := TAmmoType(LuaToAmmoTypeOrd(L, 1, callStr, paramsStr));
   616         descAppend := lua_tostringA(L, 2);
   616         descAppend := lua_tostringA(L, 2);
   617         trluaammoa[Ammoz[ammoType].NameId] := descAppend;
   617         trluaammoa[Ammoz[ammoType].NameId] := descAppend;
   618         end;
   618         end;
   619     lc_setammodescriptionappendix := 0;
   619     lc_setammodescriptionappendix := 0;
   620 end;
   620 end;
   665 end;
   665 end;
   666 
   666 
   667 function lc_addcaption(L : Plua_State) : LongInt; Cdecl;
   667 function lc_addcaption(L : Plua_State) : LongInt; Cdecl;
   668 var cg: LongInt;
   668 var cg: LongInt;
   669 const
   669 const
   670     call = 'AddCaption';
   670     callStr = 'AddCaption';
   671     params = 'text [, color, captiongroup]';
   671     paramsStr = 'text [, color, captiongroup]';
   672 begin
   672 begin
   673     if CheckAndFetchParamCount(L, 1, 3, call, params, cg) then
   673     if CheckAndFetchParamCount(L, 1, 3, callStr, paramsStr, cg) then
   674         begin
   674         begin
   675         if cg = 1 then
   675         if cg = 1 then
   676             AddCaption(lua_tostringA(L, 1), capcolDefault, capgrpMessage)
   676             AddCaption(lua_tostringA(L, 1), capcolDefault, capgrpMessage)
   677         else
   677         else
   678             begin
   678             begin
   679             cg:= LuaToCapGroupOrd(L, 3, call, params);
   679             cg:= LuaToCapGroupOrd(L, 3, callStr, paramsStr);
   680             if cg >= 0 then
   680             if cg >= 0 then
   681                 AddCaption(lua_tostringA(L, 1), Trunc(lua_tonumber(L, 2)) shr 8, TCapGroup(cg));
   681                 AddCaption(lua_tostringA(L, 1), Trunc(lua_tonumber(L, 2)) shr 8, TCapGroup(cg));
   682             end
   682             end
   683         end;
   683         end;
   684     lc_addcaption:= 0;
   684     lc_addcaption:= 0;
   844 var gear : PGear;
   844 var gear : PGear;
   845     x, y, s, t: LongInt;
   845     x, y, s, t: LongInt;
   846     dx, dy: hwFloat;
   846     dx, dy: hwFloat;
   847     gt: TGearType;
   847     gt: TGearType;
   848 const
   848 const
   849     call = 'AddGear';
   849     callStr = 'AddGear';
   850     params = 'x, y, gearType, state, dx, dy, timer';
   850     paramsStr = 'x, y, gearType, state, dx, dy, timer';
   851 begin
   851 begin
   852     if CheckLuaParamCount(L, 7, call, params) then
   852     if CheckLuaParamCount(L, 7, callStr, paramsStr) then
   853         begin
   853         begin
   854         t:= LuaToGearTypeOrd(L, 3, call, params);
   854         t:= LuaToGearTypeOrd(L, 3, callStr, paramsStr);
   855         if t >= 0 then
   855         if t >= 0 then
   856             begin
   856             begin
   857             gt:= TGearType(t);
   857             gt:= TGearType(t);
   858             x:= Trunc(lua_tonumber(L, 1));
   858             x:= Trunc(lua_tonumber(L, 1));
   859             y:= Trunc(lua_tonumber(L, 2));
   859             y:= Trunc(lua_tonumber(L, 2));
   891     x, y, s, n, layer: LongInt;
   891     x, y, s, n, layer: LongInt;
   892     c: Boolean;
   892     c: Boolean;
   893     vgt: TVisualGearType;
   893     vgt: TVisualGearType;
   894     uid: Longword;
   894     uid: Longword;
   895 const
   895 const
   896     call = 'AddVisualGear';
   896     callStr = 'AddVisualGear';
   897     params = 'x, y, visualGearType, state, critical [, layer]';
   897     paramsStr = 'x, y, visualGearType, state, critical [, layer]';
   898 begin
   898 begin
   899     uid:= 0;
   899     uid:= 0;
   900     if CheckAndFetchParamCount(L, 5, 6, call, params, n) then
   900     if CheckAndFetchParamCount(L, 5, 6, callStr, paramsStr, n) then
   901         begin
   901         begin
   902         s:= LuaToVisualGearTypeOrd(L, 3, call, params);
   902         s:= LuaToVisualGearTypeOrd(L, 3, callStr, paramsStr);
   903         if s >= 0 then
   903         if s >= 0 then
   904             begin
   904             begin
   905             vgt:= TVisualGearType(s);
   905             vgt:= TVisualGearType(s);
   906             x:= Trunc(lua_tonumber(L, 1));
   906             x:= Trunc(lua_tonumber(L, 1));
   907             y:= Trunc(lua_tonumber(L, 2));
   907             y:= Trunc(lua_tonumber(L, 2));
  1814 
  1814 
  1815 function lc_addammo(L : Plua_State) : LongInt; Cdecl;
  1815 function lc_addammo(L : Plua_State) : LongInt; Cdecl;
  1816 var gear : PGear;
  1816 var gear : PGear;
  1817     at, n, c: LongInt;
  1817     at, n, c: LongInt;
  1818 const
  1818 const
  1819     call = 'AddAmmo';
  1819     callStr = 'AddAmmo';
  1820     params = 'gearUid, ammoType [, ammoCount]';
  1820     paramsStr = 'gearUid, ammoType [, ammoCount]';
  1821 begin
  1821 begin
  1822     if CheckAndFetchParamCount(L, 2, 3, call, params, n) then
  1822     if CheckAndFetchParamCount(L, 2, 3, callStr, paramsStr, n) then
  1823         begin
  1823         begin
  1824         at:= LuaToAmmoTypeOrd(L, 2, call, params);
  1824         at:= LuaToAmmoTypeOrd(L, 2, callStr, paramsStr);
  1825         if (at >= 0) and (TAmmoType(at) <> amNothing) then
  1825         if (at >= 0) and (TAmmoType(at) <> amNothing) then
  1826             begin
  1826             begin
  1827             gear:= GearByUID(Trunc(lua_tonumber(L, 1)));
  1827             gear:= GearByUID(Trunc(lua_tonumber(L, 1)));
  1828             if (gear <> nil) and (gear^.Hedgehog <> nil) then
  1828             if (gear <> nil) and (gear^.Hedgehog <> nil) then
  1829                 if n = 2 then
  1829                 if n = 2 then
  1843 function lc_getammocount(L : Plua_State) : LongInt; Cdecl;
  1843 function lc_getammocount(L : Plua_State) : LongInt; Cdecl;
  1844 var gear : PGear;
  1844 var gear : PGear;
  1845     ammo : PAmmo;
  1845     ammo : PAmmo;
  1846     at   : LongInt;
  1846     at   : LongInt;
  1847 const
  1847 const
  1848     call = 'GetAmmoCount';
  1848     callStr = 'GetAmmoCount';
  1849     params = 'gearUid, ammoType';
  1849     paramsStr = 'gearUid, ammoType';
  1850 begin
  1850 begin
  1851     if CheckLuaParamCount(L, 2, call, params) then
  1851     if CheckLuaParamCount(L, 2, callStr, paramsStr) then
  1852         begin
  1852         begin
  1853         gear:= GearByUID(Trunc(lua_tonumber(L, 1)));
  1853         gear:= GearByUID(Trunc(lua_tonumber(L, 1)));
  1854         if (gear <> nil) and (gear^.Hedgehog <> nil) then
  1854         if (gear <> nil) and (gear^.Hedgehog <> nil) then
  1855             begin
  1855             begin
  1856             at:= LuaToAmmoTypeOrd(L, 2, call, params);
  1856             at:= LuaToAmmoTypeOrd(L, 2, callStr, paramsStr);
  1857             if at >= 0 then
  1857             if at >= 0 then
  1858                 begin
  1858                 begin
  1859                 ammo:= GetAmmoEntry(gear^.Hedgehog^, TAmmoType(at));
  1859                 ammo:= GetAmmoEntry(gear^.Hedgehog^, TAmmoType(at));
  1860                 if ammo^.AmmoType = amNothing then
  1860                 if ammo^.AmmoType = amNothing then
  1861                     lua_pushnumber(L, 0)
  1861                     lua_pushnumber(L, 0)
  1953 
  1953 
  1954 function lc_seteffect(L : Plua_State) : LongInt; Cdecl;
  1954 function lc_seteffect(L : Plua_State) : LongInt; Cdecl;
  1955 var gear: PGear;
  1955 var gear: PGear;
  1956     t   : LongInt;
  1956     t   : LongInt;
  1957 const
  1957 const
  1958     call = 'SetEffect';
  1958     callStr = 'SetEffect';
  1959     params = 'gearUid, effect, effectState';
  1959     paramsStr = 'gearUid, effect, effectState';
  1960 begin
  1960 begin
  1961     if CheckLuaParamCount(L, 3, call, params) then
  1961     if CheckLuaParamCount(L, 3, callStr, paramsStr) then
  1962         begin
  1962         begin
  1963         t:= LuaToHogEffectOrd(L, 2, call, params);
  1963         t:= LuaToHogEffectOrd(L, 2, callStr, paramsStr);
  1964         if t >= 0 then
  1964         if t >= 0 then
  1965             begin
  1965             begin
  1966             gear := GearByUID(Trunc(lua_tonumber(L, 1)));
  1966             gear := GearByUID(Trunc(lua_tonumber(L, 1)));
  1967             if (gear <> nil) and (gear^.Hedgehog <> nil) then
  1967             if (gear <> nil) and (gear^.Hedgehog <> nil) then
  1968                 gear^.Hedgehog^.Effects[THogEffect(t)]:= Trunc(lua_tonumber(L, 3));
  1968                 gear^.Hedgehog^.Effects[THogEffect(t)]:= Trunc(lua_tonumber(L, 3));
  1973 
  1973 
  1974 function lc_geteffect(L : Plua_State) : LongInt; Cdecl;
  1974 function lc_geteffect(L : Plua_State) : LongInt; Cdecl;
  1975 var gear : PGear;
  1975 var gear : PGear;
  1976     t    : LongInt;
  1976     t    : LongInt;
  1977 const
  1977 const
  1978     call = 'GetEffect';
  1978     callStr = 'GetEffect';
  1979     params = 'gearUid, effect';
  1979     paramsStr = 'gearUid, effect';
  1980 begin
  1980 begin
  1981     if CheckLuaParamCount(L, 2, call, params) then
  1981     if CheckLuaParamCount(L, 2, callStr, paramsStr) then
  1982         begin
  1982         begin
  1983         t:= LuaToHogEffectOrd(L, 2, call, params);
  1983         t:= LuaToHogEffectOrd(L, 2, callStr, paramsStr);
  1984         if t >= 0 then
  1984         if t >= 0 then
  1985             begin
  1985             begin
  1986             gear:= GearByUID(Trunc(lua_tonumber(L, 1)));
  1986             gear:= GearByUID(Trunc(lua_tonumber(L, 1)));
  1987             if (gear <> nil) and (gear^.Hedgehog <> nil) then
  1987             if (gear <> nil) and (gear^.Hedgehog <> nil) then
  1988                 lua_pushnumber(L, gear^.Hedgehog^.Effects[THogEffect(t)])
  1988                 lua_pushnumber(L, gear^.Hedgehog^.Effects[THogEffect(t)])
  2066 end;
  2066 end;
  2067 
  2067 
  2068 function lc_endturn(L : Plua_State) : LongInt; Cdecl;
  2068 function lc_endturn(L : Plua_State) : LongInt; Cdecl;
  2069 var n: LongInt;
  2069 var n: LongInt;
  2070 const
  2070 const
  2071     call = 'EndTurn';
  2071     callStr = 'EndTurn';
  2072     params = '[noTaunts]';
  2072     paramsStr = '[noTaunts]';
  2073 begin
  2073 begin
  2074     if CheckAndFetchParamCount(L, 0, 1, call, params, n) then
  2074     if CheckAndFetchParamCount(L, 0, 1, callStr, paramsStr, n) then
  2075         if n >= 1 then
  2075         if n >= 1 then
  2076             LuaNoEndTurnTaunts:= lua_toboolean(L, 1);
  2076             LuaNoEndTurnTaunts:= lua_toboolean(L, 1);
  2077     LuaEndTurnRequested:= true;
  2077     LuaEndTurnRequested:= true;
  2078     lc_endturn:= 0
  2078     lc_endturn:= 0
  2079 end;
  2079 end;
  2080 
  2080 
  2081 function lc_retreat(L : Plua_State) : LongInt; Cdecl;
  2081 function lc_retreat(L : Plua_State) : LongInt; Cdecl;
  2082 var n, time: LongInt;
  2082 var n, time: LongInt;
  2083     respectFactor: Boolean;
  2083     respectFactor: Boolean;
  2084 const
  2084 const
  2085     call = 'Retreat';
  2085     callStr = 'Retreat';
  2086     params = 'time [, respectGetAwayTimeFactor]';
  2086     paramsStr = 'time [, respectGetAwayTimeFactor]';
  2087 begin
  2087 begin
  2088     if CheckAndFetchParamCount(L, 1, 2, call, params, n) then
  2088     if CheckAndFetchParamCount(L, 1, 2, callStr, paramsStr, n) then
  2089         begin
  2089         begin
  2090         IsGetAwayTime:= true;
  2090         IsGetAwayTime:= true;
  2091         AttackBar:= 0;
  2091         AttackBar:= 0;
  2092         time:= Trunc(lua_tonumber(L, 1));
  2092         time:= Trunc(lua_tonumber(L, 1));
  2093         if n = 2 then
  2093         if n = 2 then
  2119 var statInfo : TStatInfoType;
  2119 var statInfo : TStatInfoType;
  2120     i, n     : LongInt;
  2120     i, n     : LongInt;
  2121     color, tn: shortstring;
  2121     color, tn: shortstring;
  2122     needsTn  : boolean;
  2122     needsTn  : boolean;
  2123 const
  2123 const
  2124     call = 'SendStat';
  2124     callStr = 'SendStat';
  2125     params = 'statInfoType, color [, teamname]';
  2125     paramsStr = 'statInfoType, color [, teamname]';
  2126 begin
  2126 begin
  2127     if CheckAndFetchParamCount(L, 2, 3, call, params, n) then
  2127     if CheckAndFetchParamCount(L, 2, 3, callStr, paramsStr, n) then
  2128         begin
  2128         begin
  2129         i:= LuaToStatInfoTypeOrd(L, 1, call, params);
  2129         i:= LuaToStatInfoTypeOrd(L, 1, callStr, paramsStr);
  2130         if i >= 0 then
  2130         if i >= 0 then
  2131             begin
  2131             begin
  2132             statInfo:= TStatInfoType(i);
  2132             statInfo:= TStatInfoType(i);
  2133             needsTn:= ((statInfo = siPlayerKills) or (statInfo = siClanHealth));
  2133             needsTn:= ((statInfo = siPlayerKills) or (statInfo = siClanHealth));
  2134             // check if param count is correct for the used statInfo
  2134             // check if param count is correct for the used statInfo
  2135             if (n = 3) <> needsTn then
  2135             if (n = 3) <> needsTn then
  2136                 begin
  2136                 begin
  2137                 if n = 3 then
  2137                 if n = 3 then
  2138                     LuaCallError(EnumToStr(statInfo) + ' does not support the teamname parameter', call, params)
  2138                     LuaCallError(EnumToStr(statInfo) + ' does not support the teamname parameter', callStr, paramsStr)
  2139                 else
  2139                 else
  2140                     LuaCallError(EnumToStr(statInfo) + ' requires the teamname parameter', call, params);
  2140                     LuaCallError(EnumToStr(statInfo) + ' requires the teamname parameter', callStr, paramsStr);
  2141                 end
  2141                 end
  2142             else // count is correct!
  2142             else // count is correct!
  2143                 begin
  2143                 begin
  2144                 if needsTn then
  2144                 if needsTn then
  2145                     begin
  2145                     begin
  2237 function lc_playsound(L : Plua_State) : LongInt; Cdecl;
  2237 function lc_playsound(L : Plua_State) : LongInt; Cdecl;
  2238 var gear: PGear;
  2238 var gear: PGear;
  2239     n, s: LongInt;
  2239     n, s: LongInt;
  2240     instaVoice: boolean;
  2240     instaVoice: boolean;
  2241 const
  2241 const
  2242     call = 'PlaySound';
  2242     callStr = 'PlaySound';
  2243     params = 'soundId [, hhGearUid [, instaVoice]]';
  2243     paramsStr = 'soundId [, hhGearUid [, instaVoice]]';
  2244 begin
  2244 begin
  2245     if CheckAndFetchParamCountRange(L, 1, 3, call, params, n) then
  2245     if CheckAndFetchParamCountRange(L, 1, 3, callStr, paramsStr, n) then
  2246         begin
  2246         begin
  2247         s:= LuaToSoundOrd(L, 1, call, params);
  2247         s:= LuaToSoundOrd(L, 1, callStr, paramsStr);
  2248         if s >= 0 then
  2248         if s >= 0 then
  2249             begin
  2249             begin
  2250             // no gear specified
  2250             // no gear specified
  2251             if n = 1 then
  2251             if n = 1 then
  2252                 PlaySound(TSound(s), false, true)
  2252                 PlaySound(TSound(s), false, true)
  2270 end;
  2270 end;
  2271 
  2271 
  2272 function lc_playmusicsound(L : Plua_State) : LongInt; Cdecl;
  2272 function lc_playmusicsound(L : Plua_State) : LongInt; Cdecl;
  2273 var s: LongInt;
  2273 var s: LongInt;
  2274 const
  2274 const
  2275     call = 'PlayMusicSound';
  2275     callStr = 'PlayMusicSound';
  2276     params = 'soundId';
  2276     paramsStr = 'soundId';
  2277 begin
  2277 begin
  2278     if CheckLuaParamCount(L, 1, call, params) then
  2278     if CheckLuaParamCount(L, 1, callStr, paramsStr) then
  2279         begin
  2279         begin
  2280         s:= LuaToSoundOrd(L, 1, call, params);
  2280         s:= LuaToSoundOrd(L, 1, callStr, paramsStr);
  2281         if s >= 0 then
  2281         if s >= 0 then
  2282             PlayMusicSound(TSound(s))
  2282             PlayMusicSound(TSound(s))
  2283         end;
  2283         end;
  2284     lc_playmusicsound:= 0;
  2284     lc_playmusicsound:= 0;
  2285 end;
  2285 end;
  2286 
  2286 
  2287 function lc_stopmusicsound(L : Plua_State) : LongInt; Cdecl;
  2287 function lc_stopmusicsound(L : Plua_State) : LongInt; Cdecl;
  2288 var s: LongInt;
  2288 var s: LongInt;
  2289 const
  2289 const
  2290     call = 'StopMusicSound';
  2290     callStr = 'StopMusicSound';
  2291     params = 'soundId';
  2291     paramsStr = 'soundId';
  2292 begin
  2292 begin
  2293     if CheckLuaParamCount(L, 1, call, params) then
  2293     if CheckLuaParamCount(L, 1, callStr, paramsStr) then
  2294         begin
  2294         begin
  2295         s:= LuaToSoundOrd(L, 1, call, params);
  2295         s:= LuaToSoundOrd(L, 1, callStr, paramsStr);
  2296         if s >= 0 then
  2296         if s >= 0 then
  2297             StopMusicSound(TSound(s))
  2297             StopMusicSound(TSound(s))
  2298         end;
  2298         end;
  2299     lc_stopmusicsound:= 0;
  2299     lc_stopmusicsound:= 0;
  2300 end;
  2300 end;
  2302 
  2302 
  2303 function lc_setsoundmask(L : Plua_State) : LongInt; Cdecl;
  2303 function lc_setsoundmask(L : Plua_State) : LongInt; Cdecl;
  2304 var s: LongInt;
  2304 var s: LongInt;
  2305     soundState: boolean;
  2305     soundState: boolean;
  2306 const
  2306 const
  2307     call = 'SetSoundMask';
  2307     callStr = 'SetSoundMask';
  2308     params = 'soundId, isMasked';
  2308     paramsStr = 'soundId, isMasked';
  2309 begin
  2309 begin
  2310     if CheckLuaParamCount(L, 2, call, params) then
  2310     if CheckLuaParamCount(L, 2, callStr, paramsStr) then
  2311         begin
  2311         begin
  2312         s:= LuaToSoundOrd(L, 1, call, params);
  2312         s:= LuaToSoundOrd(L, 1, callStr, paramsStr);
  2313         if s <> Ord(sndNone) then
  2313         if s <> Ord(sndNone) then
  2314             begin
  2314             begin
  2315             soundState:= lua_toboolean(L, 2);
  2315             soundState:= lua_toboolean(L, 2);
  2316             MaskedSounds[TSound(s)]:= soundState;
  2316             MaskedSounds[TSound(s)]:= soundState;
  2317             end;
  2317             end;
  2856 end;
  2856 end;
  2857 
  2857 
  2858 function lc_setammo(L : Plua_State) : LongInt; Cdecl;
  2858 function lc_setammo(L : Plua_State) : LongInt; Cdecl;
  2859 var np, at: LongInt;
  2859 var np, at: LongInt;
  2860 const
  2860 const
  2861     call = 'SetAmmo';
  2861     callStr = 'SetAmmo';
  2862     params = 'ammoType, count, probability, delay [, numberInCrate]';
  2862     paramsStr = 'ammoType, count, probability, delay [, numberInCrate]';
  2863 begin
  2863 begin
  2864     if CheckAndFetchParamCount(L, 4, 5, call, params, np) then
  2864     if CheckAndFetchParamCount(L, 4, 5, callStr, paramsStr, np) then
  2865         begin
  2865         begin
  2866         at:= LuaToAmmoTypeOrd(L, 1, call, params);
  2866         at:= LuaToAmmoTypeOrd(L, 1, callStr, paramsStr);
  2867         if at >= 0 then
  2867         if at >= 0 then
  2868             begin
  2868             begin
  2869             if np = 4 then
  2869             if np = 4 then
  2870                 ScriptSetAmmo(TAmmoType(at), Trunc(lua_tonumber(L, 2)), Trunc(lua_tonumber(L, 3)), Trunc(lua_tonumber(L, 4)), 1)
  2870                 ScriptSetAmmo(TAmmoType(at), Trunc(lua_tonumber(L, 2)), Trunc(lua_tonumber(L, 3)), Trunc(lua_tonumber(L, 4)), 1)
  2871             else
  2871             else
  2877 
  2877 
  2878 
  2878 
  2879 function lc_getammo(L : Plua_State) : LongInt; Cdecl;
  2879 function lc_getammo(L : Plua_State) : LongInt; Cdecl;
  2880 var i, at, rawProb, probLevel: LongInt;
  2880 var i, at, rawProb, probLevel: LongInt;
  2881 const
  2881 const
  2882     call = 'GetAmmo';
  2882     callStr = 'GetAmmo';
  2883     params = 'ammoType';
  2883     paramsStr = 'ammoType';
  2884 begin
  2884 begin
  2885     lc_getammo:= 0;
  2885     lc_getammo:= 0;
  2886     if CheckLuaParamCount(L, 1, call, params) then
  2886     if CheckLuaParamCount(L, 1, callStr, paramsStr) then
  2887         begin
  2887         begin
  2888         at:= LuaToAmmoTypeOrd(L, 1, call, params);
  2888         at:= LuaToAmmoTypeOrd(L, 1, callStr, paramsStr);
  2889         if at >= 0 then
  2889         if at >= 0 then
  2890             begin
  2890             begin
  2891             // Ammo count
  2891             // Ammo count
  2892             i:= InitialAmmoCounts[TAmmoType(at)];
  2892             i:= InitialAmmoCounts[TAmmoType(at)];
  2893             if i = AMMO_INFINITE then
  2893             if i = AMMO_INFINITE then
  2911 
  2911 
  2912 
  2912 
  2913 function lc_setammodelay(L : Plua_State) : LongInt; Cdecl;
  2913 function lc_setammodelay(L : Plua_State) : LongInt; Cdecl;
  2914 var at, delay: LongInt;
  2914 var at, delay: LongInt;
  2915 const
  2915 const
  2916     call = 'SetAmmoDelay';
  2916     callStr = 'SetAmmoDelay';
  2917     params = 'ammoType, delay';
  2917     paramsStr = 'ammoType, delay';
  2918 begin
  2918 begin
  2919     if CheckLuaParamCount(L, 2, call, params) then
  2919     if CheckLuaParamCount(L, 2, callStr, paramsStr) then
  2920         begin
  2920         begin
  2921         at:= LuaToAmmoTypeOrd(L, 1, call, params);
  2921         at:= LuaToAmmoTypeOrd(L, 1, callStr, paramsStr);
  2922         delay:= Trunc(lua_tonumber(L, 2));
  2922         delay:= Trunc(lua_tonumber(L, 2));
  2923         if (at >= 0) and (TAmmoType(at) <> amNothing) then
  2923         if (at >= 0) and (TAmmoType(at) <> amNothing) then
  2924             begin
  2924             begin
  2925             ScriptSetAmmoDelay(TAmmoType(at), delay);
  2925             ScriptSetAmmoDelay(TAmmoType(at), delay);
  2926             // Unselect weapon if neccessary
  2926             // Unselect weapon if neccessary
  3063     lf    : Word;
  3063     lf    : Word;
  3064     tint  : LongWord;
  3064     tint  : LongWord;
  3065     i, n : LongInt;
  3065     i, n : LongInt;
  3066     placed, behind, flipHoriz, flipVert : boolean;
  3066     placed, behind, flipHoriz, flipVert : boolean;
  3067 const
  3067 const
  3068     call = 'PlaceSprite';
  3068     callStr = 'PlaceSprite';
  3069     params = 'x, y, sprite, frameIdx, tint, behind, flipHoriz, flipVert [, landFlag, ... ]';
  3069     paramsStr = 'x, y, sprite, frameIdx, tint, behind, flipHoriz, flipVert [, landFlag, ... ]';
  3070 begin
  3070 begin
  3071     placed:= false;
  3071     placed:= false;
  3072     if CheckAndFetchLuaParamMinCount(L, 4, call, params, n) then
  3072     if CheckAndFetchLuaParamMinCount(L, 4, callStr, paramsStr, n) then
  3073         begin
  3073         begin
  3074         if not lua_isnoneornil(L, 5) then
  3074         if not lua_isnoneornil(L, 5) then
  3075             tint := Trunc(lua_tonumber(L, 5))
  3075             tint := Trunc(lua_tonumber(L, 5))
  3076         else tint := $FFFFFFFF;
  3076         else tint := $FFFFFFFF;
  3077         if not lua_isnoneornil(L, 6) then
  3077         if not lua_isnoneornil(L, 6) then
  3087 
  3087 
  3088         // accept any amount of landflags, loop is never executed if n<9
  3088         // accept any amount of landflags, loop is never executed if n<9
  3089         for i:= 9 to n do
  3089         for i:= 9 to n do
  3090             lf:= lf or Trunc(lua_tonumber(L, i));
  3090             lf:= lf or Trunc(lua_tonumber(L, i));
  3091 
  3091 
  3092         n:= LuaToSpriteOrd(L, 3, call, params);
  3092         n:= LuaToSpriteOrd(L, 3, callStr, paramsStr);
  3093         if n >= 0 then
  3093         if n >= 0 then
  3094             begin
  3094             begin
  3095             spr:= TSprite(n);
  3095             spr:= TSprite(n);
  3096             if SpritesData[spr].Surface = nil then
  3096             if SpritesData[spr].Surface = nil then
  3097                 LuaError(call + ': ' + EnumToStr(spr) + ' cannot be placed! (required information not loaded)' )
  3097                 LuaError(callStr + ': ' + EnumToStr(spr) + ' cannot be placed! (required information not loaded)' )
  3098             else
  3098             else
  3099                 placed:= ForcePlaceOnLand(
  3099                 placed:= ForcePlaceOnLand(
  3100                     Trunc(lua_tonumber(L, 1)) - SpritesData[spr].Width div 2,
  3100                     Trunc(lua_tonumber(L, 1)) - SpritesData[spr].Width div 2,
  3101                     Trunc(lua_tonumber(L, 2)) - SpritesData[spr].Height div 2,
  3101                     Trunc(lua_tonumber(L, 2)) - SpritesData[spr].Height div 2,
  3102                     spr, Trunc(lua_tonumber(L, 4)), lf, tint, behind, flipHoriz, flipVert);
  3102                     spr, Trunc(lua_tonumber(L, 4)), lf, tint, behind, flipHoriz, flipVert);
  3111 var spr   : TSprite;
  3111 var spr   : TSprite;
  3112     lf    : Word;
  3112     lf    : Word;
  3113     i, n : LongInt;
  3113     i, n : LongInt;
  3114     eraseOnLFMatch, onlyEraseLF, flipHoriz, flipVert : boolean;
  3114     eraseOnLFMatch, onlyEraseLF, flipHoriz, flipVert : boolean;
  3115 const
  3115 const
  3116     call = 'EraseSprite';
  3116     callStr = 'EraseSprite';
  3117     params = 'x, y, sprite, frameIdx, eraseOnLFMatch, onlyEraseLF, flipHoriz, flipVert [, landFlag, ... ]';
  3117     paramsStr = 'x, y, sprite, frameIdx, eraseOnLFMatch, onlyEraseLF, flipHoriz, flipVert [, landFlag, ... ]';
  3118 begin
  3118 begin
  3119     if CheckAndFetchLuaParamMinCount(L, 4, call, params, n) then
  3119     if CheckAndFetchLuaParamMinCount(L, 4, callStr, paramsStr, n) then
  3120         begin
  3120         begin
  3121         if not lua_isnoneornil(L, 5) then
  3121         if not lua_isnoneornil(L, 5) then
  3122             eraseOnLFMatch := lua_toboolean(L, 5)
  3122             eraseOnLFMatch := lua_toboolean(L, 5)
  3123         else eraseOnLFMatch := false;
  3123         else eraseOnLFMatch := false;
  3124         if not lua_isnoneornil(L, 6) then
  3124         if not lua_isnoneornil(L, 6) then
  3134 
  3134 
  3135         // accept any amount of landflags, loop is never executed if n<9
  3135         // accept any amount of landflags, loop is never executed if n<9
  3136         for i:= 9 to n do
  3136         for i:= 9 to n do
  3137             lf:= lf or Trunc(lua_tonumber(L, i));
  3137             lf:= lf or Trunc(lua_tonumber(L, i));
  3138 
  3138 
  3139         n:= LuaToSpriteOrd(L, 3, call, params);
  3139         n:= LuaToSpriteOrd(L, 3, callStr, paramsStr);
  3140         if n >= 0 then
  3140         if n >= 0 then
  3141             begin
  3141             begin
  3142             spr:= TSprite(n);
  3142             spr:= TSprite(n);
  3143             if SpritesData[spr].Surface = nil then
  3143             if SpritesData[spr].Surface = nil then
  3144                 LuaError(call + ': ' + EnumToStr(spr) + ' cannot be placed! (required information not loaded)' )
  3144                 LuaError(callStr + ': ' + EnumToStr(spr) + ' cannot be placed! (required information not loaded)' )
  3145             else
  3145             else
  3146                 EraseLand(
  3146                 EraseLand(
  3147                     Trunc(lua_tonumber(L, 1)) - SpritesData[spr].Width div 2,
  3147                     Trunc(lua_tonumber(L, 1)) - SpritesData[spr].Width div 2,
  3148                     Trunc(lua_tonumber(L, 2)) - SpritesData[spr].Height div 2,
  3148                     Trunc(lua_tonumber(L, 2)) - SpritesData[spr].Height div 2,
  3149                     spr, Trunc(lua_tonumber(L, 4)), lf, eraseOnLFMatch, onlyEraseLF, flipHoriz, flipVert);
  3149                     spr, Trunc(lua_tonumber(L, 4)), lf, eraseOnLFMatch, onlyEraseLF, flipHoriz, flipVert);
  3386 end;
  3386 end;
  3387 
  3387 
  3388 function lc_getammoname(L : Plua_state) : LongInt; Cdecl;
  3388 function lc_getammoname(L : Plua_state) : LongInt; Cdecl;
  3389 var np, at: LongInt;
  3389 var np, at: LongInt;
  3390     ignoreOverwrite: Boolean;
  3390     ignoreOverwrite: Boolean;
  3391 const call = 'GetAmmoName';
  3391 const callStr = 'GetAmmoName';
  3392       params = 'ammoType [, ignoreOverwrite ]';
  3392       paramsStr = 'ammoType [, ignoreOverwrite ]';
  3393 begin
  3393 begin
  3394     if CheckAndFetchParamCountRange(L, 1, 2, call, params, np) then
  3394     if CheckAndFetchParamCountRange(L, 1, 2, callStr, paramsStr, np) then
  3395         begin
  3395         begin
  3396         at:= LuaToAmmoTypeOrd(L, 1, call, params);
  3396         at:= LuaToAmmoTypeOrd(L, 1, callStr, paramsStr);
  3397         ignoreOverwrite := false;
  3397         ignoreOverwrite := false;
  3398         if np > 1 then
  3398         if np > 1 then
  3399             ignoreOverwrite := lua_toboolean(L, 2);
  3399             ignoreOverwrite := lua_toboolean(L, 2);
  3400         if at >= 0 then
  3400         if at >= 0 then
  3401             if (not ignoreOverwrite) and (length(trluaammo[Ammoz[TAmmoType(at)].NameId]) > 0) then
  3401             if (not ignoreOverwrite) and (length(trluaammo[Ammoz[TAmmoType(at)].NameId]) > 0) then
  3410 
  3410 
  3411 function lc_getammotimer(L : Plua_state) : LongInt; Cdecl;
  3411 function lc_getammotimer(L : Plua_state) : LongInt; Cdecl;
  3412 var at: LongInt;
  3412 var at: LongInt;
  3413     weapon: PAmmo;
  3413     weapon: PAmmo;
  3414     gear: PGear;
  3414     gear: PGear;
  3415 const call = 'GetAmmoTimer';
  3415 const callStr = 'GetAmmoTimer';
  3416       params = 'gearUid, ammoType';
  3416       paramsStr = 'gearUid, ammoType';
  3417 begin
  3417 begin
  3418     if CheckLuaParamCount(L, 2, call, params) then
  3418     if CheckLuaParamCount(L, 2, callStr, paramsStr) then
  3419         begin
  3419         begin
  3420         gear:= GearByUID(Trunc(lua_tonumber(L, 1)));
  3420         gear:= GearByUID(Trunc(lua_tonumber(L, 1)));
  3421         if (gear <> nil) and (gear^.Hedgehog <> nil) then
  3421         if (gear <> nil) and (gear^.Hedgehog <> nil) then
  3422             begin
  3422             begin
  3423             at:= LuaToAmmoTypeOrd(L, 2, call, params);
  3423             at:= LuaToAmmoTypeOrd(L, 2, callStr, paramsStr);
  3424             weapon:= GetAmmoEntry(gear^.Hedgehog^, TAmmoType(at));
  3424             weapon:= GetAmmoEntry(gear^.Hedgehog^, TAmmoType(at));
  3425             if (Ammoz[TAmmoType(at)].Ammo.Propz and ammoprop_Timerable) <> 0 then
  3425             if (Ammoz[TAmmoType(at)].Ammo.Propz and ammoprop_Timerable) <> 0 then
  3426                 lua_pushnumber(L, weapon^.Timer)
  3426                 lua_pushnumber(L, weapon^.Timer)
  3427             else
  3427             else
  3428                 lua_pushnil(L);
  3428                 lua_pushnil(L);
  3598 
  3598 
  3599 // stuff for lua tests
  3599 // stuff for lua tests
  3600 function lc_endluatest(L : Plua_State) : LongInt; Cdecl;
  3600 function lc_endluatest(L : Plua_State) : LongInt; Cdecl;
  3601 var rstring: shortstring;
  3601 var rstring: shortstring;
  3602 const
  3602 const
  3603     call = 'EndLuaTest';
  3603     callStr = 'EndLuaTest';
  3604     params = 'TEST_SUCCESSFUL or TEST_FAILED';
  3604     paramsStr = 'TEST_SUCCESSFUL or TEST_FAILED';
  3605 begin
  3605 begin
  3606     if CheckLuaParamCount(L, 1, call, params) then
  3606     if CheckLuaParamCount(L, 1, callStr, paramsStr) then
  3607         begin
  3607         begin
  3608 
  3608 
  3609         case Trunc(lua_tonumber(L, 1)) of
  3609         case Trunc(lua_tonumber(L, 1)) of
  3610             HaltTestSuccess : rstring:= 'Success';
  3610             HaltTestSuccess : rstring:= 'Success';
  3611             HaltTestFailed: rstring:= 'FAILED';
  3611             HaltTestFailed: rstring:= 'FAILED';
  3612         else
  3612         else
  3613             begin
  3613             begin
  3614             LuaCallError('Parameter must be either ' + params, call, params);
  3614             LuaCallError('Parameter must be either ' + paramsStr, callStr, paramsStr);
  3615             exit(0);
  3615             exit(0);
  3616             end;
  3616             end;
  3617         end;
  3617         end;
  3618 
  3618 
  3619         if cTestLua then
  3619         if cTestLua then