Don't reduce InitialHealth below 1
authorWuzzy <Wuzzy2@mail.ru>
Fri, 30 Nov 2018 17:09:08 +0100
changeset 14349 d35e0fdb70f6
parent 14348 ffebbcc40c9b
child 14350 31717e1436cd
Don't reduce InitialHealth below 1
ChangeLog.txt
hedgewars/uGears.pas
--- a/ChangeLog.txt	Thu Nov 29 20:37:40 2018 +0100
+++ b/ChangeLog.txt	Fri Nov 30 17:09:08 2018 +0100
@@ -41,6 +41,7 @@
  * Fix hog sometimes getting stuck in land if roping very fast
  * Fix seduction not stopping if hog took damage before attack was complete
  * Limit hedgehog health to 268435455 to prevent some bugs
+ * Fix rare possibility that hog is resurrected and starts with 0 or negative health
 
 Game, controls and commands:
  + Add new key to show mission panel (default: M)
--- a/hedgewars/uGears.pas	Thu Nov 29 20:37:40 2018 +0100
+++ b/hedgewars/uGears.pas	Fri Nov 30 17:09:08 2018 +0100
@@ -128,11 +128,12 @@
         if Gear^.Kind = gtHedgehog then
             begin
             tmp:= 0;
+            // Deal poison damage (when not frozen)
             if (Gear^.Hedgehog^.Effects[hePoisoned] <> 0) and (Gear^.Hedgehog^.Effects[heFrozen] = 0) then
                 begin
                 inc(tmp, ModifyDamage(Gear^.Hedgehog^.Effects[hePoisoned], Gear));
                 if (GameFlags and gfResetHealth) <> 0 then
-                    dec(Gear^.Hedgehog^.InitialHealth)  // does not need a minimum check since <= 1 basically disables it
+                    dec(Gear^.Hedgehog^.InitialHealth);
                 end;
             // Apply SD health decrease as soon as SD starts
             if (TotalRoundsPre > cSuddenDTurns - 1) then
@@ -141,6 +142,7 @@
                 if (GameFlags and gfResetHealth) <> 0 then
                     dec(Gear^.Hedgehog^.InitialHealth, cHealthDecrease)
                 end;
+            // Reduce king health when he is alone in team
             if Gear^.Hedgehog^.King then
                 begin
                 flag:= false;
@@ -156,6 +158,10 @@
                         dec(Gear^.Hedgehog^.InitialHealth, 5)
                     end
                 end;
+            // Initial health must never be below 1 because hog might be resurrected
+            if Gear^.Hedgehog^.InitialHealth < 1 then
+                Gear^.Hedgehog^.InitialHealth:= 1;
+            // Set real damage
             if tmp > 0 then
                 begin
                 // SD damage never reduces health below 1