Refactor health gain effects and message into util fuction HHHeal
authorWuzzy <Wuzzy2@mail.ru>
Fri, 09 Feb 2018 11:30:04 +0100
changeset 12942 a84a05719454
parent 12941 b9904380ce26
child 12943 b075ad6112c9
Refactor health gain effects and message into util fuction HHHeal
hedgewars/uGearsHedgehog.pas
hedgewars/uGearsUtils.pas
--- a/hedgewars/uGearsHedgehog.pas	Fri Feb 09 10:48:24 2018 +0100
+++ b/hedgewars/uGearsHedgehog.pas	Fri Feb 09 11:30:04 2018 +0100
@@ -726,10 +726,7 @@
 
 ////////////////////////////////////////////////////////////////////////////////
 procedure PickUp(HH, Gear: PGear);
-var s: ansistring;
-    i: LongInt;
-    vga: PVisualGear;
-    ag, gi: PGear;
+var ag, gi: PGear;
 begin
 if Gear^.State and gstFrozen <> 0 then exit;
 
@@ -778,23 +775,9 @@
                     PlaySound(sndShotgunReload);
                     inc(HH^.Health, Gear^.Health);
                     HH^.Hedgehog^.Effects[hePoisoned] := 0;
-                    s:= IntToStr(Gear^.Health);
-                    AddCaption(FormatA(trmsg[sidHealthGain], s), HH^.Hedgehog^.Team^.Clan^.Color, capgrpAmmoinfo);
                     RenderHealth(HH^.Hedgehog^);
                     RecountTeamHealth(HH^.Hedgehog^.Team);
-
-                    i:= 0;
-                    while (i < Gear^.Health) and (i <= 1000) do
-                        begin
-                        vga:= AddVisualGear(hwRound(HH^.X), hwRound(HH^.Y), vgtStraightShot);
-                        if vga <> nil then
-                            with vga^ do
-                                begin
-                                Tint:= $00FF00FF;
-                                State:= ord(sprHealth)
-                                end;
-                        inc(i, 5);
-                        end;
+                    HHHeal(HH^.Hedgehog, Gear^.Health, true);
                     end;
      end
 end;
--- a/hedgewars/uGearsUtils.pas	Fri Feb 09 10:48:24 2018 +0100
+++ b/hedgewars/uGearsUtils.pas	Fri Feb 09 11:30:04 2018 +0100
@@ -31,6 +31,8 @@
 procedure ApplyDamage(Gear: PGear; AttackerHog: PHedgehog; Damage: Longword; Source: TDamageSource);
 procedure spawnHealthTagForHH(HHGear: PGear; dmg: Longword);
 procedure HHHurt(Hedgehog: PHedgehog; Source: TDamageSource);
+procedure HHHeal(Hedgehog: PHedgehog; healthBoost: Longword; showMessage: boolean; vgTint: Longword);
+procedure HHHeal(Hedgehog: PHedgehog; healthBoost: Longword; showMessage: boolean);
 procedure CheckHHDamage(Gear: PGear);
 procedure CalcRotationDirAngle(Gear: PGear);
 procedure ResurrectHedgehog(var gear: PGear);
@@ -263,8 +265,7 @@
 end;
 
 procedure ApplyDamage(Gear: PGear; AttackerHog: PHedgehog; Damage: Longword; Source: TDamageSource);
-var s: ansistring;
-    vampDmg, tmpDmg, i: Longword;
+var vampDmg, tmpDmg, i: Longword;
     vg: PVisualGear;
 begin
     if Damage = 0 then
@@ -288,22 +289,9 @@
                     // was considering pulsing on attack, Tiy thinks it should be permanent while in play
                     //CurrentHedgehog^.Gear^.State:= CurrentHedgehog^.Gear^.State or gstVampiric;
                     inc(CurrentHedgehog^.Gear^.Health,vampDmg);
-                    s:= IntToStr(vampDmg);
-                    AddCaption(FormatA(trmsg[sidHealthGain], s), CurrentHedgehog^.Team^.Clan^.Color, capgrpAmmoinfo);
                     RenderHealth(CurrentHedgehog^);
                     RecountTeamHealth(CurrentHedgehog^.Team);
-                    i:= 0;
-                    while (i < vampDmg) and (i < 1000) do
-                        begin
-                        vg:= AddVisualGear(hwRound(CurrentHedgehog^.Gear^.X), hwRound(CurrentHedgehog^.Gear^.Y), vgtStraightShot);
-                        if vg <> nil then
-                            with vg^ do
-                                begin
-                                Tint:= $FF0000FF;
-                                State:= ord(sprHealth)
-                                end;
-                        inc(i, 5);
-                        end;
+                    HHHeal(CurrentHedgehog, vampDmg, true, $FF0000FF);
                     end
                 end;
             if (GameFlags and gfKarma <> 0) and (GameFlags and gfInvulnerable = 0) and
@@ -355,6 +343,7 @@
 HHGear^.Active:= true;
 end;
 
+// Play effects for hurt hedgehog
 procedure HHHurt(Hedgehog: PHedgehog; Source: TDamageSource);
 begin
 if Hedgehog^.Effects[heFrozen] <> 0 then exit;
@@ -379,6 +368,48 @@
     end
 end;
 
+{-
+Show heal particles and message at hog gear.
+Hedgehog: Hedgehog which gets the health boost
+healthBoost: Amount of added health added
+showMessage: Whether to show announcer message
+vgTint: Tint of heal particle
+-}
+procedure HHHeal(Hedgehog: PHedgehog; healthBoost: Longword; showMessage: boolean; vgTint: Longword);
+var i: LongInt;
+    vg: PVisualGear;
+    s: ansistring;
+begin
+    if healthBoost < 1 then
+        exit;
+
+    if showMessage then
+        begin
+        s:= IntToStr(healthBoost);
+        AddCaption(FormatA(trmsg[sidHealthGain], s), Hedgehog^.Team^.Clan^.Color, capgrpAmmoinfo)
+        end;
+
+    i:= 0;
+    // One particle for every 5 HP. Max. 200 particles
+    while (i < healthBoost) and (i < 1000) do
+        begin
+        vg:= AddVisualGear(hwRound(Hedgehog^.Gear^.X), hwRound(Hedgehog^.Gear^.Y), vgtStraightShot);
+        if vg <> nil then
+            with vg^ do
+                begin
+                Tint:= vgTint;
+                State:= ord(sprHealth)
+                end;
+        inc(i, 5)
+        end;
+end;
+
+// Shorthand for the same above, but with tint implied
+procedure HHHeal(Hedgehog: PHedgehog; healthBoost: Longword; showMessage: boolean);
+begin
+    HHHeal(Hedgehog, healthBoost, showMessage, $00FF00FF);
+end;
+
 procedure CheckHHDamage(Gear: PGear);
 var
     dmg: LongInt;