Lua: Add IsHogAlive
authorWuzzy <Wuzzy2@mail.ru>
Fri, 31 May 2019 11:08:54 +0200
changeset 15084 424e3b132dd3
parent 15083 fb7a9b0119d3
child 15085 cd60866e6efb
Lua: Add IsHogAlive
ChangeLog.txt
hedgewars/uScript.pas
--- a/ChangeLog.txt	Thu May 30 18:31:02 2019 +0200
+++ b/ChangeLog.txt	Fri May 31 11:08:54 2019 +0200
@@ -160,6 +160,7 @@
  + New call: AddMissionTeam(color): Add mission team, i.e. the team selected by player in campaign/mission page
  + New call: AddMissionHog(health): Add a hedgehog for the mission team
  + New call: SetTeamPassive(teamname, isPassive): Mark a team as passive. Passive teams do not play and are treated like frozen teams.
+ + New call: IsHogAlive(gear): Returns true if gear is a hegehog which is alive, not about to die and not hidden
  + New return value: AddTeam/AddMissionTeam return <real team name>, <team index>
  + SetClanColor: Now accepts negative color argument for user clan color, like in AddTeam
  + AddTeam: Append “_qau” to voicepack name to enable automatic selection of voicepack language
--- a/hedgewars/uScript.pas	Thu May 30 18:31:02 2019 +0200
+++ b/hedgewars/uScript.pas	Fri May 31 11:08:54 2019 +0200
@@ -1475,6 +1475,28 @@
     lc_gethogfort:= 1
 end;
 
+function lc_ishogalive(L : Plua_State) : LongInt; Cdecl;
+var gear : PGear;
+begin
+    if CheckLuaParamCount(L, 1, 'IsHogAlive', 'gearUid') then
+        begin
+        gear:= GearByUID(Trunc(lua_tonumber(L, 1)));
+        if gear <> nil then
+            if gear^.Kind = gtHedgehog then
+                if (gear^.Health > 0) and (gear^.Health > gear^.Damage) and ((gear^.State and (gstDrowning or gstHHDeath)) = 0) and ((gear^.Message and gmDestroy) = 0) then
+                    lua_pushboolean(L, true)
+                else
+                    lua_pushboolean(L, false)
+            else
+                lua_pushboolean(L, false)
+        else
+            lua_pushboolean(L, false);
+        end
+    else
+        lua_pushnil(L); // return value on stack (nil)
+    lc_ishogalive:= 1
+end;
+
 function lc_ishoglocal(L : Plua_State) : LongInt; Cdecl;
 var gear : PGear;
 begin
@@ -4477,6 +4499,7 @@
 lua_register(luaState, _P'GetHogFlag', @lc_gethogflag);
 lua_register(luaState, _P'GetHogFort', @lc_gethogfort);
 lua_register(luaState, _P'GetHogGrave', @lc_gethoggrave);
+lua_register(luaState, _P'IsHogAlive', @lc_ishogalive);
 lua_register(luaState, _P'IsHogLocal', @lc_ishoglocal);
 lua_register(luaState, _P'GetHogTeamName', @lc_gethogteamname);
 lua_register(luaState, _P'SetHogTeamName', @lc_sethogteamname);