- Right way to handle rope ammo
- Most probably adds bugs, so needs testing and testing
--- a/hedgewars/GSHandlers.inc Fri Jan 30 19:26:32 2009 +0000
+++ b/hedgewars/GSHandlers.inc Sat Jan 31 11:58:09 2009 +0000
@@ -638,6 +638,39 @@
////////////////////////////////////////////////////////////////////////////////
+procedure doStepRope(Gear: PGear); forward;
+
+procedure doStepRopeAfterAttack(Gear: PGear);
+var HHGear: PGear;
+begin
+HHGear:= PHedgehog(Gear^.Hedgehog)^.Gear;
+if ((HHGear^.State and gstHHDriven) = 0)
+ or (CheckGearDrowning(HHGear))
+ or TestCollisionYwithGear(HHGear, 1) then
+ begin
+ DeleteGear(Gear);
+ exit
+ end;
+
+if TestCollisionXwithGear(HHGear, hwSign(HHGear^.dX)) then SetLittle(HHGear^.dX);
+if HHGear^.dY.isNegative and TestCollisionYwithGear(HHGear, -1) then HHGear^.dY:= _0;
+HHGear^.X:= HHGear^.X + HHGear^.dX;
+HHGear^.Y:= HHGear^.Y + HHGear^.dY;
+HHGear^.dY:= HHGear^.dY + cGravity;
+
+if (Gear^.Message and gm_Attack) <> 0 then
+ begin
+ Gear^.X:= HHGear^.X;
+ Gear^.Y:= HHGear^.Y;
+ Gear^.dX:= SignAs(AngleSin(HHGear^.Angle), HHGear^.dX);
+ Gear^.dY:= -AngleCos(HHGear^.Angle);
+ Gear^.Friction:= _450;
+ Gear^.Elasticity:= _0;
+ Gear^.State:= Gear^.State and not gsttmpflag;
+ Gear^.doStep:= @doStepRope
+ end
+end;
+
procedure doStepRopeWork(Gear: PGear);
var HHGear: PGear;
len, tx, ty, nx, ny, ropeDx, ropeDy, mdX, mdY: hwFloat;
@@ -655,6 +688,18 @@
DeleteGear(Gear)
end;
+ procedure WaitCollision;
+ begin
+ with HHGear^ do
+ begin
+ Message:= Message and not gm_Attack;
+ State:= State or gstMoving;
+ end;
+ RopePoints.Count:= 0;
+ Gear^.Elasticity:= _0;
+ Gear^.doStep:= @doStepRopeAfterAttack
+ end;
+
begin
HHGear:= PHedgehog(Gear^.Hedgehog)^.Gear;
@@ -782,17 +827,27 @@
if (Gear^.Message and gm_Attack) <> 0 then
if (Gear^.State and gsttmpFlag) <> 0 then
- DeleteMe
+ WaitCollision
else
else
if (Gear^.State and gsttmpFlag) = 0 then
Gear^.State:= Gear^.State or gsttmpFlag;
end;
-
procedure doStepRopeAttach(Gear: PGear);
var HHGear: PGear;
- tx, ty, tt: hwFloat;
+ tx, ty, tt: hwFloat;
+
+ procedure RemoveFromAmmo;
+ begin
+ if (Gear^.State and gstAttacked) = 0 then
+ begin
+ OnUsedAmmo(PHedgehog(HHGear^.Hedgehog)^);
+ ApplyAmmoChanges(PHedgehog(HHGear^.Hedgehog)^);
+ Gear^.State:= Gear^.State or gstAttacked
+ end
+ end;
+
begin
Gear^.X:= Gear^.X - Gear^.dX;
Gear^.Y:= Gear^.Y - Gear^.dY;
@@ -826,6 +881,9 @@
Gear^.Elasticity:= tt;
Gear^.doStep:= @doStepRopeWork;
with HHGear^ do State:= State and not (gstAttacking or gstMoving or gstHHHJump);
+
+ RemoveFromAmmo;
+
tt:= _0;
exit
end;
@@ -842,8 +900,7 @@
Gear^.doStep:= @doStepRopeWork;
with HHGear^ do State:= State and not (gstAttacking or gstHHHJump);
- OnUsedAmmo(PHedgehog(HHGear^.Hedgehog)^);
- ApplyAmmoChanges(PHedgehog(HHGear^.Hedgehog)^);
+ RemoveFromAmmo;
if Gear^.Elasticity < _10 then
Gear^.Elasticity:= _10000;
--- a/hedgewars/uGears.pas Fri Jan 30 19:26:32 2009 +0000
+++ b/hedgewars/uGears.pas Sat Jan 31 11:58:09 2009 +0000
@@ -1107,6 +1107,7 @@
hwRound(PHedgehog(Gear^.Hedgehog)^.Gear^.X) + WorldDx, hwRound(PHedgehog(Gear^.Hedgehog)^.Gear^.Y) + WorldDy);
DrawRotated(sprRopeHook, hwRound(RopePoints.ar[0].X) + WorldDx, hwRound(RopePoints.ar[0].Y) + WorldDy, 1, RopePoints.HookAngle)
end else
+ if Gear^.Elasticity.QWordValue > 0 then
begin
DrawRopeLine(hwRound(Gear^.X) + WorldDx, hwRound(Gear^.Y) + WorldDy,
hwRound(PHedgehog(Gear^.Hedgehog)^.Gear^.X) + WorldDx, hwRound(PHedgehog(Gear^.Hedgehog)^.Gear^.Y) + WorldDy);