Lua API: Add Explode function
authorWuzzy <Wuzzy2@mail.ru>
Thu, 22 Mar 2018 19:25:38 +0100
changeset 13275 969aacfa229c
parent 13274 a772b6c9387f
child 13276 4b9c5cf49c9f
Lua API: Add Explode function
ChangeLog.txt
hedgewars/uScript.pas
--- a/ChangeLog.txt	Thu Mar 22 18:40:21 2018 +0100
+++ b/ChangeLog.txt	Thu Mar 22 19:25:38 2018 +0100
@@ -114,6 +114,7 @@
  + New call: SetTeamLabel(teamname[, label]): Set an arbitrary label for a team, will be displayed next to the team bar
  + New call: SetSoundMask(soundId, isMasked): Allows to disable playing a sound effect from engine
  + New call: SkipTurn(): Force current hedgehog to skip turn
+ + New call: Explode(x, y, radius[, options]): Cause an explosion
  + New param: PlaySound accepts 3rd parameter for voices: instaVoice: If true, sound plays instantly instead of being queued
  + New callback: onEndTurn(): Called at the end of a turn (when gears have settled)
  + New callback: onSkipTurn(): Called when a hog skips turn
--- a/hedgewars/uScript.pas	Thu Mar 22 18:40:21 2018 +0100
+++ b/hedgewars/uScript.pas	Thu Mar 22 19:25:38 2018 +0100
@@ -2953,6 +2953,26 @@
     lc_setlasersight:= 0;
 end;
 
+function lc_explode(L : Plua_state) : LongInt; Cdecl;
+var mask: LongWord;
+    n: LongInt;
+begin
+    if CheckAndFetchParamCount(L, 3, 4, 'Explode', 'x, y, radius[, options]', n) then
+        if CurrentHedgehog <> nil then
+            begin
+            mask:= EXPLAutoSound;
+            if (n = 4) then
+                mask:= Trunc(lua_tonumber(L, 4));
+            doMakeExplosion(Trunc(lua_tonumber(L, 1)), Trunc(lua_tonumber(L, 2)), Trunc(lua_tonumber(L, 3)), CurrentHedgehog, mask);
+            lua_pushboolean(L, true);
+            end
+        else
+            lua_pushboolean(L, false)
+    else
+        lua_pushboolean(L, false);
+    lc_explode:= 1;
+end;
+
 function lc_startghostpoints(L : Plua_State) : LongInt; Cdecl;
 begin
     if CheckLuaParamCount(L, 1, 'StartGhostPoints', 'count') then
@@ -3764,6 +3784,15 @@
 ScriptSetInteger('lfNotHHObjMask'  , lfNotHHObjMask);
 ScriptSetInteger('lfAllObjMask'    , lfAllObjMask);
 
+// explosion constants
+ScriptSetInteger('EXPLAutoSound'    , EXPLAutoSound);
+ScriptSetInteger('EXPLNoDamage'     , EXPLNoDamage);
+ScriptSetInteger('EXPLDoNotTouchHH' , EXPLDoNotTouchHH);
+ScriptSetInteger('EXPLDontDraw'     , EXPLDontDraw);
+ScriptSetInteger('EXPLNoGfx'        , EXPLNoGfx);
+ScriptSetInteger('EXPLPoisoned'     , EXPLPoisoned);
+ScriptSetInteger('EXPLDoNotTouchAny', EXPLDoNotTouchAny);
+
 // register functions
 lua_register(luaState, _P'HideHog', @lc_hidehog);
 lua_register(luaState, _P'RestoreHog', @lc_restorehog);
@@ -3903,6 +3932,7 @@
 lua_register(luaState, _P'GetAmmoName', @lc_getammoname);
 lua_register(luaState, _P'SetVampiric', @lc_setvampiric);
 lua_register(luaState, _P'SetLaserSight', @lc_setlasersight);
+lua_register(luaState, _P'Explode', @lc_explode);
 // drawn map functions
 lua_register(luaState, _P'AddPoint', @lc_addPoint);
 lua_register(luaState, _P'FlushPoints', @lc_flushPoints);