Lua API: Add HealHog to heal hog with visual effects + message
authorWuzzy <Wuzzy2@mail.ru>
Fri, 09 Feb 2018 12:52:05 +0100
changeset 12944 0112ef349ddc
parent 12943 b075ad6112c9
child 12945 39b7b3ed619e
Lua API: Add HealHog to heal hog with visual effects + message
ChangeLog.txt
hedgewars/uScript.pas
--- a/ChangeLog.txt	Fri Feb 09 12:08:12 2018 +0100
+++ b/ChangeLog.txt	Fri Feb 09 12:52:05 2018 +0100
@@ -37,6 +37,7 @@
  + New call: GetWind(): Returns current wind (approximation) from -100 to 100
  + New call: GetTeamName(teamIdx): Returns name of team with given index (starts at 0)
  + New call: SpawnSupplyCrate(x, y, content, [, amount]): Spawn ammo or utility crate, depending on content
+ + New call: HealHog(gearUid, healthBoost[, showMessage[, tint]]): Heal hedgehog with graphical effects and message
  + New callback: onEndTurn(): Called at the end of a turn (when gears have settled)
  * Fix call: SetWeapon(amNothing) now unselects weapon
  * Fix global: TotalRounds was stuck at -1 for several turns
--- a/hedgewars/uScript.pas	Fri Feb 09 12:08:12 2018 +0100
+++ b/hedgewars/uScript.pas	Fri Feb 09 12:52:05 2018 +0100
@@ -1764,6 +1764,33 @@
     lc_sethealth:= 0
 end;
 
+function lc_healhog(L : Plua_State) : LongInt; Cdecl;
+var gear : PGear;
+    healthBoost, n: LongInt;
+begin
+    if CheckAndFetchParamCountRange(L, 2, 4, 'HealHog', 'gearUid, healthBoost [, showMessage [, tint]]', n) then
+        begin
+        gear:= GearByUID(Trunc(lua_tonumber(L, 1)));
+        healthBoost:= Trunc(lua_tonumber(L, 2));
+        if (gear <> nil) and (gear^.Kind = gtHedgehog) and (gear^.Hedgehog <> nil) and (healthBoost >= 1) then
+            begin
+            gear^.Health:= gear^.Health + healthBoost;
+
+            RenderHealth(gear^.Hedgehog^);
+            RecountTeamHealth(gear^.Hedgehog^.Team);
+            if n = 4 then
+                HHHeal(gear^.Hedgehog, healthBoost, lua_toboolean(L, 3), Trunc(lua_tonumber(L, 4)))
+            else if n = 3 then
+                HHHeal(gear^.Hedgehog, healthBoost, lua_toboolean(L, 3))
+            else if n = 2 then
+                HHHeal(gear^.Hedgehog, healthBoost, true);
+            Gear^.Active:= true;
+            AllInactive:= false
+            end
+        end;
+    lc_healhog:= 0
+end;
+
 function lc_settimer(L : Plua_State) : LongInt; Cdecl;
 var gear : PGear;
 begin
@@ -3683,6 +3710,7 @@
 lua_register(luaState, _P'AddHog', @lc_addhog);
 lua_register(luaState, _P'AddAmmo', @lc_addammo);
 lua_register(luaState, _P'GetAmmoCount', @lc_getammocount);
+lua_register(luaState, _P'HealHog', @lc_healhog);
 lua_register(luaState, _P'SetHealth', @lc_sethealth);
 lua_register(luaState, _P'GetHealth', @lc_gethealth);
 lua_register(luaState, _P'SetEffect', @lc_seteffect);