Fix cake taking >200s to explode when it's completely stuck and can't move (bug 194)
authorWuzzy <almikes@aol.com>
Wed, 04 Oct 2017 15:37:42 +0200
changeset 12646 f30b70976577
parent 12645 36a650c0a885
child 12647 ee7815bc5874
Fix cake taking >200s to explode when it's completely stuck and can't move (bug #194)
ChangeLog.txt
hedgewars/uGearsHandlersMess.pas
hedgewars/uGearsList.pas
--- a/ChangeLog.txt	Wed Oct 04 15:28:32 2017 +0200
+++ b/ChangeLog.txt	Wed Oct 04 15:37:42 2017 +0200
@@ -45,6 +45,7 @@
  * Fixed enemy saying "Missed” when giving poison without direct damage
  * Fixed hedgehogs not saying “Stupid” and not displaying announcer message for inflicting self-harm
  * Fixed incorrect time box tooltip when in Sudden Death
+ * Fixed cake taking over 200 seconds to explode when its stuck and can't move
  * Remove buggy /finish chat command
  * Various other fixes
 
--- a/hedgewars/uGearsHandlersMess.pas	Wed Oct 04 15:28:32 2017 +0200
+++ b/hedgewars/uGearsHandlersMess.pas	Wed Oct 04 15:37:42 2017 +0200
@@ -3294,7 +3294,7 @@
     if Gear^.Health mod 100 = 0 then
         Gear^.PortalCounter:= 0;
     // This is not seconds, but at least it is *some* feedback
-    if (Gear^.Health = 0) or ((Gear^.Message and gmAttack) <> 0) then
+    if (Gear^.Health <= 0) or ((Gear^.Message and gmAttack) <> 0) then
         begin
         FollowGear := Gear;
         Gear^.RenderTimer := false;
@@ -3329,12 +3329,14 @@
     AllInactive := false;
 
     inc(Gear^.Tag);
-    if Gear^.Tag < 100 then
+    // Animation delay. Skipped if cake only dropped a very short distance.
+    if (Gear^.Tag < 100) and (Gear^.FlightTime > 1) then
         exit;
     Gear^.Tag := 0;
 
-    if Gear^.Pos = 6 then
-        begin
+    if (Gear^.Pos = 6) or (Gear^.FlightTime <= 1) then
+        begin
+        Gear^.Pos := 6;
         cakeData:= PCakeData(Gear^.Data);
         with cakeData^ do
             begin
@@ -3345,6 +3347,13 @@
                 end;
             CakeI := 0;
             end;
+        (* This is called frequently if the cake is completely stuck.
+           With this a stuck cake takes equally long to explode then
+           a normal cake. Removing this code just makes the cake walking
+           for a few seconds longer. *)
+        if (Gear^.FlightTime <= 1) and (Gear^.Health > 2) then
+            dec(Gear^.Health);
+        Gear^.FlightTime := 0;
         Gear^.doStep := @doStepCakeWalk
         end
     else
@@ -3356,6 +3365,8 @@
     AllInactive := false;
 
     Gear^.dY := Gear^.dY + cGravity;
+    // FlightTime remembers the drop time
+    inc(Gear^.FlightTime);
     if TestCollisionYwithGear(Gear, 1) <> 0 then
         Gear^.doStep := @doStepCakeUp
     else
--- a/hedgewars/uGearsList.pas	Wed Oct 04 15:28:32 2017 +0200
+++ b/hedgewars/uGearsList.pas	Wed Oct 04 15:37:42 2017 +0200
@@ -580,6 +580,8 @@
                 gear^.Z:= cOnHHZ;
                 gear^.RenderTimer:= false;
                 gear^.DirAngle:= -90 * hwSign(Gear^.dX);
+                gear^.FlightTime:= 100; // (roughly) ticks spent dropping, used to skip getting up anim when stuck.
+                                        // Initially set to a high value so cake has at least one getting up anim.
                 if not dX.isNegative then
                     gear^.Angle:= 1
                 else