bug #336
authornemo
Sun, 11 Mar 2012 11:39:45 -0400
changeset 6765 8fcd2508c49f
parent 6764 e56ff0231540
child 6766 31ba56a8ec43
bug #336
hedgewars/GSHandlers.inc
hedgewars/uConsts.pas
hedgewars/uGearsUtils.pas
--- 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
--- a/hedgewars/uConsts.pas	Sat Mar 10 23:00:39 2012 -0500
+++ b/hedgewars/uConsts.pas	Sun Mar 11 11:39:45 2012 -0400
@@ -263,7 +263,7 @@
 
     AMMO_INFINITE = 100;
 
-    EXPLAllDamageInRadius = $00000001;
+    //EXPLAllDamageInRadius = $00000001;  Completely unused for ages
     EXPLAutoSound         = $00000002;
     EXPLNoDamage          = $00000004;
     EXPLDoNotTouchHH      = $00000008;
--- a/hedgewars/uGearsUtils.pas	Sat Mar 10 23:00:39 2012 -0500
+++ b/hedgewars/uGearsUtils.pas	Sun Mar 11 11:39:45 2012 -0400
@@ -47,7 +47,7 @@
 procedure doMakeExplosion(X, Y, Radius: LongInt; AttackingHog: PHedgehog; Mask: Longword; const Tint: LongWord);
 var Gear: PGear;
     dmg, dmgRadius, dmgBase: LongInt;
-    fX, fY: hwFloat;
+    fX, fY, tdX, tdY: hwFloat;
     vg: PVisualGear;
     i, cnt: LongInt;
 begin
@@ -64,11 +64,12 @@
     end;
 if (Mask and EXPLAutoSound) <> 0 then PlaySound(sndExplosion);
 
-if (Mask and EXPLAllDamageInRadius) = 0 then
+(*if (Mask and EXPLAllDamageInRadius) = 0 then
     dmgRadius:= Radius shl 1
 else
     dmgRadius:= Radius;
-dmgBase:= dmgRadius + cHHRadius div 2;
+dmgBase:= dmgRadius + cHHRadius div 2;*)
+dmgBase:= Radius shl 1 + cHHRadius div 2;
 fX:= int2hwFloat(X);
 fY:= int2hwFloat(Y);
 Gear:= GearsList;
@@ -94,8 +95,10 @@
                 gtExplosives,
                 gtStructure: begin
 // Run the calcs only once we know we have a type that will need damage
-                        if hwRound(hwAbs(Gear^.X-fX)+hwAbs(Gear^.Y-fY)) < dmgBase then
-                            dmg:= dmgBase - max(hwRound(Distance(Gear^.X - fX, Gear^.Y - fY)),Gear^.Radius);
+                        tdX:= Gear^.X-fX;
+                        tdY:= Gear^.Y-fY;
+                        if hwRound(hwAbs(tdX)+hwAbs(tdY)) < dmgBase then
+                            dmg:= dmgBase - max(hwRound(Distance(tdX, tdY)),Gear^.Radius);
                         if dmg > 1 then
                             begin
                             dmg:= ModifyDamage(min(dmg div 2, Radius), Gear);
@@ -110,8 +113,8 @@
                             if ((Mask and EXPLDoNotTouchAny) = 0) and (((Mask and EXPLDoNotTouchHH) = 0) or (Gear^.Kind <> gtHedgehog)) then
                                 begin
                                 DeleteCI(Gear);
-                                Gear^.dX:= Gear^.dX + SignAs(_0_005 * dmg + cHHKick, Gear^.X - fX)/(Gear^.Density/_3);
-                                Gear^.dY:= Gear^.dY + SignAs(_0_005 * dmg + cHHKick, Gear^.Y - fY)/(Gear^.Density/_3);
+                                Gear^.dX:= Gear^.dX + SignAs(_0_005 * dmg + cHHKick, tdX)/(Gear^.Density/_3);
+                                Gear^.dY:= Gear^.dY + SignAs(_0_005 * dmg + cHHKick, tdY)/(Gear^.Density/_3);
 
                                 Gear^.State:= (Gear^.State or gstMoving) and (not gstLoser);
                                 if not Gear^.Invulnerable then
@@ -126,8 +129,10 @@
                         end;
                 gtGrave: begin
 // Run the calcs only once we know we have a type that will need damage
-                        if hwRound(hwAbs(Gear^.X-fX)+hwAbs(Gear^.Y-fY)) < dmgBase then
-                            dmg:= dmgBase - hwRound(Distance(Gear^.X - fX, Gear^.Y - fY));
+                        tdX:= Gear^.X-fX;
+                        tdY:= Gear^.Y-fY;
+                        if hwRound(hwAbs(tdX)+hwAbs(tdY)) < dmgBase then
+                            dmg:= dmgBase - hwRound(Distance(tdX, tdY));
                         if dmg > 1 then
                             begin
                             dmg:= ModifyDamage(min(dmg div 2, Radius), Gear);