Lua API: Make the last 2 params optional in the SpawnFake*Crate functions
authorWuzzy <Wuzzy2@mail.ru>
Sun, 09 Dec 2018 16:54:22 +0100
changeset 14414 c2cd3f64b9f7
parent 14413 e335b3120f59
child 14415 d670e4efe1ed
Lua API: Make the last 2 params optional in the SpawnFake*Crate functions
ChangeLog.txt
hedgewars/uScript.pas
--- a/ChangeLog.txt	Sun Dec 09 04:09:38 2018 +0300
+++ b/ChangeLog.txt	Sun Dec 09 16:54:22 2018 +0100
@@ -3,6 +3,9 @@
 =============== 1.0.0 (unreleased) =================
  + New chat command: “/help room” (shows room chat commands within the game)
 
+Lua API:
+ + Params explode, poison in the SpawnFake*Crate functions now optional and default to false
+
 ====================== 0.9.25 ======================
 HIGHLIGHTS:
  + Complete overhaul of Continental supplies
--- a/hedgewars/uScript.pas	Sun Dec 09 04:09:38 2018 +0300
+++ b/hedgewars/uScript.pas	Sun Dec 09 16:54:22 2018 +0100
@@ -686,11 +686,20 @@
 
 function lc_spawnfakehealthcrate(L: Plua_State) : LongInt; Cdecl;
 var gear: PGear;
-begin
-    if CheckLuaParamCount(L, 4,'SpawnFakeHealthCrate', 'x, y, explode, poison') then
+    explode, poison: boolean;
+    n: LongInt;
+begin
+    if CheckAndFetchParamCountRange(L, 2, 4, 'SpawnFakeHealthCrate', 'x, y [, explode [, poison]]', n) then
         begin
+        explode:= false;
+        poison:= false;
+        if (n >= 3) and (not lua_isnil(L, 3)) then
+            explode:= lua_toboolean(L, 3);
+        if (n = 4) and (not lua_isnil(L, 4)) then
+            poison:= lua_toboolean(L, 4);
+
         gear := SpawnFakeCrateAt(Trunc(lua_tonumber(L, 1)), Trunc(lua_tonumber(L, 2)),
-        HealthCrate, lua_toboolean(L, 3), lua_toboolean(L, 4));
+        HealthCrate, explode, poison);
         if gear <> nil then
              lua_pushnumber(L, gear^.uid)
         else lua_pushnil(L)
@@ -702,11 +711,20 @@
 
 function lc_spawnfakeammocrate(L: PLua_State): LongInt; Cdecl;
 var gear: PGear;
-begin
-    if CheckLuaParamCount(L, 4,'SpawnFakeAmmoCrate', 'x, y, explode, poison') then
+    explode, poison: boolean;
+    n: LongInt;
+begin
+    if CheckAndFetchParamCountRange(L, 2, 4, 'SpawnFakeAmmoCrate', 'x, y [, explode [, poison]]', n) then
         begin
+        explode:= false;
+        poison:= false;
+        if (n >= 3) and (not lua_isnil(L, 3)) then
+            explode:= lua_toboolean(L, 3);
+        if (n = 4) and (not lua_isnil(L, 4)) then
+            poison:= lua_toboolean(L, 4);
+
         gear := SpawnFakeCrateAt(Trunc(lua_tonumber(L, 1)), Trunc(lua_tonumber(L, 2)),
-        AmmoCrate, lua_toboolean(L, 3), lua_toboolean(L, 4));
+        AmmoCrate, explode, poison);
         if gear <> nil then
              lua_pushnumber(L, gear^.uid)
         else lua_pushnil(L)
@@ -718,11 +736,20 @@
 
 function lc_spawnfakeutilitycrate(L: PLua_State): LongInt; Cdecl;
 var gear: PGear;
-begin
-    if CheckLuaParamCount(L, 4,'SpawnFakeUtilityCrate', 'x, y, explode, poison') then
+    explode, poison: boolean;
+    n: LongInt;
+begin
+    if CheckAndFetchParamCountRange(L, 2, 4, 'SpawnFakeUtilityCrate', 'x, y [, explode [, poison]]', n) then
         begin
+        explode:= false;
+        poison:= false;
+        if (n >= 3) and (not lua_isnil(L, 3)) then
+            explode:= lua_toboolean(L, 3);
+        if (n = 4) and (not lua_isnil(L, 4)) then
+            poison:= lua_toboolean(L, 4);
+
         gear := SpawnFakeCrateAt(Trunc(lua_tonumber(L, 1)), Trunc(lua_tonumber(L, 2)),
-        UtilityCrate, lua_toboolean(L, 3), lua_toboolean(L, 4));
+        UtilityCrate, explode, poison);
         if gear <> nil then
              lua_pushnumber(L, gear^.uid)
         else lua_pushnil(L)