Lua API: Add IsHogHidden
authorWuzzy <Wuzzy2@mail.ru>
Tue, 31 Jul 2018 01:00:27 +0200
changeset 13582 66460d5f0d9b
parent 13581 e5761b37e99c
child 13583 145ee99575d4
Lua API: Add IsHogHidden
ChangeLog.txt
hedgewars/uScript.pas
--- a/ChangeLog.txt	Tue Jul 31 00:12:19 2018 +0200
+++ b/ChangeLog.txt	Tue Jul 31 01:00:27 2018 +0200
@@ -72,6 +72,7 @@
  + New call: GetAmmo(ammoType): Returns ammo configuration (corresponds to SetAmmo)
  + New call: GetVampiric(): Returns true if vampirism is currently active
  + New call: GetLaserSight(): Returns true if laser sight (as utility) is currenctly active (ignoring sniper rifle)
+ + New call: IsHogHidden(gear): Returns true if hog is hidden
  + New parameter: SetAmmoTexts: 5th param. showExtra: Set to false to hide texts like “Not yet available”
  + New parameter: ShowMission: 6th param. forceDisplay: Set to true to prevent this particular mission panel to be hidden manually by player
  + New Lua library: Achievements
--- a/hedgewars/uScript.pas	Tue Jul 31 00:12:19 2018 +0200
+++ b/hedgewars/uScript.pas	Tue Jul 31 01:00:27 2018 +0200
@@ -2942,6 +2942,36 @@
     lc_restorehog := 0;
 end;
 
+function lc_ishoghidden(L: Plua_State): LongInt; Cdecl;
+var i, h: LongInt;
+    uid: LongWord;
+    gear: PGear;
+begin
+    if CheckLuaParamCount(L, 1, 'IsHogHidden', 'gearUid') then
+        begin
+        uid:= LongWord(Trunc(lua_tonumber(L, 1)));
+        gear:= GearByUID(uid);
+        if (gear <> nil) and (gear^.hedgehog <> nil) then
+            begin
+            lua_pushboolean(L, false);
+            lc_ishoghidden:= 1;
+            exit;
+            end
+        else
+            if TeamsCount > 0 then
+                for i:= 0 to Pred(TeamsCount) do
+                    for h:= 0 to cMaxHHIndex do
+                        if (TeamsArray[i]^.Hedgehogs[h].GearHidden <> nil) and (TeamsArray[i]^.Hedgehogs[h].GearHidden^.uid = uid) then
+                            begin
+                            lua_pushboolean(L, true);
+                            lc_ishoghidden:= 1;
+                            exit;
+                            end
+        end;
+    lua_pushnil(L);
+    lc_ishoghidden:= 1;
+end;
+
 // boolean TestRectForObstacle(x1, y1, x2, y2, landOnly)
 function lc_testrectforobstacle(L : Plua_State) : LongInt; Cdecl;
 var rtn: Boolean;
@@ -3955,6 +3985,7 @@
 // register functions
 lua_register(luaState, _P'HideHog', @lc_hidehog);
 lua_register(luaState, _P'RestoreHog', @lc_restorehog);
+lua_register(luaState, _P'IsHogHidden', @lc_ishoghidden);
 lua_register(luaState, _P'SaveCampaignVar', @lc_savecampaignvar);
 lua_register(luaState, _P'GetCampaignVar', @lc_getcampaignvar);
 lua_register(luaState, _P'band', @lc_band);