hedgewars/GSHandlers.inc
changeset 6765 8fcd2508c49f
parent 6761 e95f7509a5c5
child 6785 a8aa5984185f
--- a/hedgewars/GSHandlers.inc	Sat Mar 10 23:00:39 2012 -0500
+++ b/hedgewars/GSHandlers.inc	Sun Mar 11 11:39:45 2012 -0400
@@ -2972,7 +2972,8 @@
 procedure doStepCakeDown(Gear: PGear);
 var 
     gi: PGear;
-    dmg: LongInt;
+    dmg, dmgBase: LongInt;
+    fX, fY, tdX, tdY: hwFloat;
 begin
     AllInactive := false;
 
@@ -2983,17 +2984,34 @@
 
     if Gear^.Pos = 0 then
         begin
+///////////// adapted from doMakeExplosion ///////////////////////////
+        //fX:= Gear^.X;
+        //fY:= Gear^.Y;
+        //fX.QWordValue:= fX.QWordValue and $FFFFFFFF00000000;
+        //fY.QWordValue:= fY.QWordValue and $FFFFFFFF00000000;
+        fX:= int2hwFloat(hwRound(Gear^.X));
+        fY:= int2hwFloat(hwRound(Gear^.Y));
+        dmgBase:= cakeDmg shl 1 + cHHRadius div 2;
         gi := GearsList;
         while gi <> nil do
             begin
-            dmg := cakeDmg * 2 - hwRound(Distance(gi^.X - Gear^.X, gi^.Y - Gear^.Y));
-            if (dmg > 1) and (gi^.Kind = gtHedgehog) then
-                if (CurrentHedgehog^.Gear = gi) and (not gi^.Invulnerable) then
-                    gi^.State := gi^.State or gstLoser
-            else
-                gi^.State := gi^.State or gstWinner;
+            if gi^.Kind = gtHedgehog then
+                begin
+                dmg:= 0;
+                tdX:= gi^.X-fX;
+                tdY:= gi^.Y-fY;
+                if hwRound(hwAbs(tdX)+hwAbs(tdY)) < dmgBase then
+                    dmg:= dmgBase - max(hwRound(Distance(tdX, tdY)),gi^.Radius);
+                if (dmg > 1) then dmg:= ModifyDamage(min(dmg div 2, cakeDmg), gi);
+                if (dmg > 1) then
+                    if (CurrentHedgehog^.Gear = gi) and (not gi^.Invulnerable) then
+                        gi^.State := gi^.State or gstLoser
+                    else
+                        gi^.State := gi^.State or gstWinner;
+                end;
             gi := gi^.NextGear
             end;
+//////////////////////////////////////////////////////////////////////
         Gear^.doStep := @doStepCakeExpl;
         PlaySound(sndCake)
         end