- Various small fixes
authorunc0rr
Wed, 06 Jun 2007 21:27:12 +0000
changeset 538 74219eadab5e
parent 537 4d2e60623e44
child 539 6a9bf1852bbc
- Various small fixes - Current hh moves like others (fixes some issues of new collision system)
hedgewars/GSHandlers.inc
hedgewars/HHHandlers.inc
hedgewars/uCollisions.pas
hedgewars/uFloat.pas
hedgewars/uGears.pas
--- a/hedgewars/GSHandlers.inc	Mon Jun 04 21:29:05 2007 +0000
+++ b/hedgewars/GSHandlers.inc	Wed Jun 06 21:27:12 2007 +0000
@@ -1177,10 +1177,11 @@
    HHGear:= PHedgehog(Gear^.Hedgehog)^.Gear;
    Msg:= Gear^.Message and not gm_Switch;
    DeleteGear(Gear);
-   OnUsedAmmo(PHedgehog(Gear^.Hedgehog)^);
+   OnUsedAmmo(PHedgehog(HHGear^.Hedgehog)^);
+   ApplyAmmoChanges(PHedgehog(HHGear^.Hedgehog)^);
 
    HHGear:= CurrentTeam^.Hedgehogs[CurrentTeam^.CurrHedgehog].Gear;
-   ApplyAmmoChanges(PHedgehog(Gear^.Hedgehog)^);
+   ApplyAmmoChanges(PHedgehog(HHGear^.Hedgehog)^);
    HHGear^.Message:= Msg;
    exit
    end;
--- a/hedgewars/HHHandlers.inc	Mon Jun 04 21:29:05 2007 +0000
+++ b/hedgewars/HHHandlers.inc	Wed Jun 06 21:27:12 2007 +0000
@@ -254,6 +254,76 @@
 
 procedure doStepHedgehog(Gear: PGear); forward;
 ////////////////////////////////////////////////////////////////////////////////
+procedure doStepHedgehogMoving(Gear: PGear);
+var prevState: Longword;
+begin
+prevState:= Gear^.State;
+if not TestCollisionYKick(Gear, 1) then
+   begin
+   if (Gear^.dY.isNegative) and TestCollisionYKick(Gear, -1) then Gear^.dY:= _0;
+   Gear^.State:= Gear^.State or gstFalling or gstMoving;
+   Gear^.dY:= Gear^.dY + cGravity
+   end else
+   if (not Gear^.dY.isNegative) then
+   begin
+   CheckHHDamage(Gear);
+   if ((hwAbs(Gear^.dX) + hwAbs(Gear^.dY)) < _0_55)
+      and ((Gear^.State and gstHHJumping) <> 0) then SetLittle(Gear^.dX);
+
+   Gear^.State:= Gear^.State and not (gstFalling or gstHHJumping or gstHHHJump);
+
+   if Gear^.dY > _0 then Gear^.dY:= _0;
+   if ((Gear^.State and gstMoving) <> 0) then Gear^.dX:= Gear^.dX * Gear^.Friction
+   end;
+
+if (Gear^.State <> 0) then DeleteCI(Gear);
+                
+if (Gear^.State and gstMoving) <> 0 then
+   if TestCollisionXKick(Gear, hwSign(Gear^.dX)) then
+      if ((Gear^.State and gstFalling) = 0) then
+         if hwAbs(Gear^.dX) > _0_01 then
+            if not TestCollisionXwithXYShift(Gear, int2hwFloat(hwSign(Gear^.dX)) - Gear^.dX, -1, hwSign(Gear^.dX)) then begin Gear^.X:= Gear^.X + Gear^.dX; Gear^.dX:= Gear^.dX * _0_96; Gear^.Y:= Gear^.Y - _1 end else
+            if not TestCollisionXwithXYShift(Gear, int2hwFloat(hwSign(Gear^.dX)) - Gear^.dX, -2, hwSign(Gear^.dX)) then begin Gear^.X:= Gear^.X + Gear^.dX; Gear^.dX:= Gear^.dX * _0_93; Gear^.Y:= Gear^.Y - _2 end else
+            if not TestCollisionXwithXYShift(Gear, int2hwFloat(hwSign(Gear^.dX)) - Gear^.dX, -3, hwSign(Gear^.dX)) then begin Gear^.X:= Gear^.X + Gear^.dX; Gear^.dX:= Gear^.dX * _0_9 ; Gear^.Y:= Gear^.Y - _3 end else
+            if not TestCollisionXwithXYShift(Gear, int2hwFloat(hwSign(Gear^.dX)) - Gear^.dX, -4, hwSign(Gear^.dX)) then begin Gear^.X:= Gear^.X + Gear^.dX; Gear^.dX:= Gear^.dX * _0_87; Gear^.Y:= Gear^.Y - _4 end else
+            if not TestCollisionXwithXYShift(Gear, int2hwFloat(hwSign(Gear^.dX)) - Gear^.dX, -5, hwSign(Gear^.dX)) then begin Gear^.X:= Gear^.X + Gear^.dX; Gear^.dX:= Gear^.dX * _0_84; Gear^.Y:= Gear^.Y - _5 end else
+            if hwAbs(Gear^.dX) > _0_02 then Gear^.dX:= -Gear^.Elasticity * Gear^.dX
+                                   else begin
+                                        Gear^.State:= Gear^.State and not gstMoving;
+                                        SetLittle(Gear^.dX)
+                                        end
+            else begin
+                 Gear^.State:= Gear^.State and not gstMoving;
+                 SetLittle(Gear^.dX)
+                 end
+         else if hwAbs(Gear^.dX) > cLittle then Gear^.dX:= -Gear^.Elasticity * Gear^.dX
+                                           else SetLittle(Gear^.dX);
+
+if ((Gear^.State and gstFalling) = 0)and
+   (hwAbs(Gear^.dX) + hwAbs(Gear^.dY) < _0_03) then
+   begin
+   Gear^.State:= Gear^.State and not gstMoving;
+   SetLittle(Gear^.dX);
+   Gear^.dY:= _0
+   end else Gear^.State:= Gear^.State or gstMoving;
+
+if (Gear^.State and gstMoving) <> 0 then
+   begin
+   Gear^.State:= Gear^.State and not gstAnimation;
+   Gear^.X:= Gear^.X + Gear^.dX;
+   Gear^.Y:= Gear^.Y + Gear^.dY;
+   if (not Gear^.dY.isNegative) and
+      (not TestCollisionYKick(Gear, 1)) and
+       TestCollisionYwithXYShift(Gear, 0, 1, 1) then
+      begin
+      CheckHHDamage(Gear);
+      Gear^.dY:= _0;
+      Gear^.Y:= Gear^.Y + _1
+      end;
+   CheckGearDrowning(Gear)
+   end
+end;
+
 procedure doStepHedgehogDriven(Gear: PGear);
 var t: PGear;
 begin
@@ -303,24 +373,20 @@
          Gear^.dX:= SignAs(_0_02, Gear^.dX)
          end;
    Gear^.Message:= Gear^.Message and not (gm_LJump or gm_HJump);
-   if TestCollisionXwithGear(Gear, hwSign(Gear^.dX)) then SetLittle(Gear^.dX);
-   Gear^.X:= Gear^.X + Gear^.dX;
-   Gear^.dY:= Gear^.dY + cGravity;
-   if (Gear^.dY.isNegative)and TestCollisionYwithGear(Gear, -1) then Gear^.dY:= _0;
-   Gear^.Y:= Gear^.Y + Gear^.dY;
-   if (not Gear^.dY.isNegative)and TestCollisionYwithGear(Gear, 1) then
+
+
+   if ((Gear^.State and gstHHJumping) <> 0) and
+      TestCollisionXwithGear(Gear, hwSign(Gear^.dX)) then SetLittle(Gear^.dX);
+
+   doStepHedgehogMoving(Gear);
+   
+   if (Gear^.State and (gstFalling or gstMoving)) = 0 then
       begin
-      CheckHHDamage(Gear);
-      if ((hwAbs(Gear^.dX) + hwAbs(Gear^.dY)) < _0_55)
-         and ((Gear^.State and gstHHJumping) <> 0) then SetLittle(Gear^.dX);
-      Gear^.State:= Gear^.State and not (gstFalling or gstHHJumping or gstHHHJump);
       AddGearCI(Gear);
-      StepTicks:= 300;
-      Gear^.dY:= _0
+      StepTicks:= 300
       end;
-   CheckGearDrowning(Gear);
    exit
-   end ;//else if Gear^.CollIndex = High(Longword) then AddIntersectorsCR(Gear);
+   end;
 
    HedgehogChAngle(Gear);
    if StepTicks > 0 then dec(StepTicks);
@@ -332,64 +398,10 @@
 var prevState: Longword;
 begin
 prevState:= Gear^.State;
-if not TestCollisionYKick(Gear, 1) then
-   begin
-   if (Gear^.dY.isNegative) and TestCollisionYKick(Gear, -1) then Gear^.dY:= _0;
-   Gear^.State:= Gear^.State or gstFalling or gstMoving;
-   Gear^.dY:= Gear^.dY + cGravity
-   end else begin
-   CheckHHDamage(Gear);
-   if ((hwAbs(Gear^.dX) + hwAbs(Gear^.dY)) < _0_55)
-      and ((Gear^.State and gstHHJumping) <> 0) then SetLittle(Gear^.dX);
-   Gear^.State:= Gear^.State and not (gstFalling or gstHHJumping);
-   if Gear^.dY > _0 then Gear^.dY:= _0;
-   if ((Gear^.State and gstMoving) <> 0) then Gear^.dX:= Gear^.dX * Gear^.Friction
-   end;
-
-if (Gear^.State <> 0) then DeleteCI(Gear);
 
-if (Gear^.State and gstMoving) <> 0 then
-   if TestCollisionXKick(Gear, hwSign(Gear^.dX)) then
-      if ((Gear^.State and gstFalling) = 0) then
-         if hwAbs(Gear^.dX) > _0_01 then
-            if not TestCollisionXwithXYShift(Gear, int2hwFloat(hwSign(Gear^.dX)) - Gear^.dX, -1, hwSign(Gear^.dX)) then begin Gear^.X:= Gear^.X + Gear^.dX; Gear^.dX:= Gear^.dX * _0_96; Gear^.Y:= Gear^.Y - _1 end else
-            if not TestCollisionXwithXYShift(Gear, int2hwFloat(hwSign(Gear^.dX)) - Gear^.dX, -2, hwSign(Gear^.dX)) then begin Gear^.X:= Gear^.X + Gear^.dX; Gear^.dX:= Gear^.dX * _0_93; Gear^.Y:= Gear^.Y - _2 end else
-            if not TestCollisionXwithXYShift(Gear, int2hwFloat(hwSign(Gear^.dX)) - Gear^.dX, -3, hwSign(Gear^.dX)) then begin Gear^.X:= Gear^.X + Gear^.dX; Gear^.dX:= Gear^.dX * _0_9 ; Gear^.Y:= Gear^.Y - _3 end else
-            if not TestCollisionXwithXYShift(Gear, int2hwFloat(hwSign(Gear^.dX)) - Gear^.dX, -4, hwSign(Gear^.dX)) then begin Gear^.X:= Gear^.X + Gear^.dX; Gear^.dX:= Gear^.dX * _0_87; Gear^.Y:= Gear^.Y - _4 end else
-            if not TestCollisionXwithXYShift(Gear, int2hwFloat(hwSign(Gear^.dX)) - Gear^.dX, -5, hwSign(Gear^.dX)) then begin Gear^.X:= Gear^.X + Gear^.dX; Gear^.dX:= Gear^.dX * _0_84; Gear^.Y:= Gear^.Y - _5 end else
-            if hwAbs(Gear^.dX) > _0_02 then Gear^.dX:= -Gear^.Elasticity * Gear^.dX
-                                   else begin
-                                        Gear^.State:= Gear^.State and not gstMoving;
-                                        SetLittle(Gear^.dX)
-                                        end
-            else begin
-                 Gear^.State:= Gear^.State and not gstMoving;
-                 SetLittle(Gear^.dX)
-                 end
-         else Gear^.dX:= -Gear^.Elasticity * Gear^.dX;
+doStepHedgehogMoving(Gear);
 
-if ((Gear^.State and gstFalling) = 0)and
-   (hwAbs(Gear^.dX) + hwAbs(Gear^.dY) < _0_03) then
-   begin
-   Gear^.State:= Gear^.State and not gstMoving;
-   SetLittle(Gear^.dX);
-   Gear^.dY:= _0
-   end else Gear^.State:= Gear^.State or gstMoving;
-
-if (Gear^.State and gstMoving) <> 0 then
-   begin
-   Gear^.State:= Gear^.State and not gstAnimation;
-   Gear^.X:= Gear^.X + Gear^.dX;
-   Gear^.Y:= Gear^.Y + Gear^.dY;
-   if (not Gear^.dY.isNegative) and
-      (not TestCollisionYKick(Gear, 1)) and
-       TestCollisionYwithXYShift(Gear, 0, 1, 1) then
-      begin
-      CheckHHDamage(Gear);
-      Gear^.dY:= _0;
-      Gear^.Y:= Gear^.Y + _1
-      end;
-   end else
+if (Gear^.State and gstMoving) = 0 then
    if Gear^.Health = 0 then
       begin
       if AllInactive then
@@ -406,8 +418,7 @@
 
 AllInactive:= false;
 
-if (not CheckGearDrowning(Gear)) and
-   ((Gear^.State and gstMoving) = 0) then
+if ((Gear^.State and gstMoving) = 0) then
    if ((Gear^.State and gstAnimation) = 0) and
       (prevState <> Gear^.State) then
       begin
--- a/hedgewars/uCollisions.pas	Mon Jun 04 21:29:05 2007 +0000
+++ b/hedgewars/uCollisions.pas	Wed Jun 06 21:27:12 2007 +0000
@@ -189,12 +189,11 @@
      inc(y)
    until (y > i);
    end;
-TestCollisionXKick:= false;
+TestCollisionXKick:= flag;
 
 if flag then
    begin
-   if hwAbs(Gear^.dX) < cHHKick then exit(true);
-   if Count = 0 then exit;
+   if hwAbs(Gear^.dX) < cHHKick then exit;
    mx:= hwRound(Gear^.X);
    my:= hwRound(Gear^.Y);
 
@@ -213,8 +212,8 @@
                   Active:= true
                   end;
              DeleteCI(cGear);
-             exit
-             end else exit(true)
+             exit(false)
+             end
    end
 end;
 
@@ -238,12 +237,11 @@
      inc(x)
    until (x > i);
    end;
-TestCollisionYKick:= false;
+TestCollisionYKick:= flag;
 
 if flag then
    begin
    if hwAbs(Gear^.dX) < cHHKick then exit(true);
-   if Count = 0 then exit;
    mx:= hwRound(Gear^.X);
    my:= hwRound(Gear^.Y);
 
@@ -257,13 +255,13 @@
              with cGear^ do
                   begin
                   dX:= Gear^.dX;
-                  dY:= Gear^.dY;
+                  dY:= Gear^.dY * _0_5;
                   State:= State or gstMoving;
                   Active:= true
                   end;
              DeleteCI(cGear);
-             exit
-             end else exit(true)
+             exit(false)
+             end
    end
 end;
 
--- a/hedgewars/uFloat.pas	Mon Jun 04 21:29:05 2007 +0000
+++ b/hedgewars/uFloat.pas	Wed Jun 06 21:27:12 2007 +0000
@@ -61,6 +61,7 @@
 function AngleCos(const Angle: Longword): hwFloat;
 function SignAs(const num, signum: hwFloat): hwFloat;
 
+{$J-}
 const  _1div1024: hwFloat = (isNegative: false; QWordValue:     4194304);
       _1div10000: hwFloat = (isNegative: false; QWordValue:      429496);
       _1div50000: hwFloat = (isNegative: false; QWordValue:       85899);
@@ -119,7 +120,7 @@
           _10000: hwFloat = (isNegative: false; QWordValue:  4294967296 * 10000);
 
          cLittle: hwFloat = (isNegative: false; QWordValue:           1);
-         cHHKick: hwFloat = (isNegative: false; QWordValue:   128849018);
+         cHHKick: hwFloat = (isNegative: false; QWordValue:   128849018);  // _0_03
 {$ENDIF}
 
 {$IFNDEF FPC}
--- a/hedgewars/uGears.pas	Mon Jun 04 21:29:05 2007 +0000
+++ b/hedgewars/uGears.pas	Wed Jun 06 21:27:12 2007 +0000
@@ -447,7 +447,7 @@
              Surface);
 
 with PHedgehog(Gear^.Hedgehog)^ do
-     if (Gear^.State and not gstAnimation) = 0 then
+     if (Gear^.State{ and not gstAnimation}) = 0 then
         begin
         t:= hwRound(Gear^.Y) - cHHRadius - 10 + WorldDy;
         dec(t, HealthTag^.h + 2);
@@ -457,6 +457,7 @@
         dec(t, Team^.NameTag^.h + 2);
         DrawCentered(hwRound(Gear^.X) + WorldDx, t, Team^.NameTag, Surface)
         end else // Current hedgehog
+      if (Gear^.State and gstHHDriven) <> 0 then
         begin
         if bShowFinger and ((Gear^.State and gstHHDriven) <> 0) then
            DrawSprite(sprFinger, hwRound(Gear^.X) - 16 + WorldDx, hwRound(Gear^.Y) - 64 + WorldDy,
@@ -649,7 +650,7 @@
 while Gear <> nil do
       begin
       dmg:= dmgRadius - hwRound(Distance(Gear^.X - int2hwFloat(X), Gear^.Y - int2hwFloat(Y)));
-      if (dmg > 0) and
+      if (dmg > 1) and
          ((Gear^.State and gstNoDamage) = 0) then
          begin
          dmg:= dmg div 2;
@@ -698,7 +699,7 @@
 while t <> nil do
     begin
     dmg:= min(Gear^.Radius + t^.Radius - hwRound(Distance(Gear^.X - t^.X, Gear^.Y - t^.Y)), 25);
-    if dmg >= 0 then
+    if dmg > 0 then
        case t^.Kind of
            gtHedgehog,
                gtMine,
@@ -748,11 +749,11 @@
                           AddDamageTag(hwRound(t^.ar[i]^.X), hwRound(t^.ar[i]^.Y), Damage, t^.ar[i]);
                           inc(hh^.DamageGiven, Damage)
                           end;
+                       DeleteCI(t^.ar[i]);
                        t^.ar[i]^.dX:= Ammo^.dX * Power * _0_01;
                        t^.ar[i]^.dY:= Ammo^.dY * Power * _0_01;
                        t^.ar[i]^.Active:= true;
                        t^.ar[i]^.State:= t^.ar[i]^.State or gstMoving;
-                       DeleteCI(t^.ar[i]);
                        FollowGear:= t^.ar[i]
                        end;
            end