Second part of the change. Make collision check use the new mask bit.
--- a/hedgewars/GSHandlers.inc Sat Jun 23 21:37:47 2012 -0400
+++ b/hedgewars/GSHandlers.inc Sat Jun 23 22:39:00 2012 -0400
@@ -3165,8 +3165,7 @@
HHGear := Gear^.Hedgehog^.Gear;
HHGear^.Message := HHGear^.Message and (not gmAttack);
- DeleteCI(HHGear);
- Gear^.IntersectGear:= nil;
+ Gear^.CollisionMask:= $FF7F;
FollowGear := Gear;
@@ -4026,12 +4025,12 @@
gear^.RenderTimer := true;
// abort if there is no other portal connected to this one
- if (Gear^.IntersectGear = nil) then
+ if (Gear^.LinkedGear = nil) then
exit;
- if ((Gear^.IntersectGear^.Tag and 1) = 0) then // or if it's still moving;
+ if ((Gear^.LinkedGear^.Tag and 1) = 0) then // or if it's still moving;
exit;
- conPortal := Gear^.IntersectGear;
+ conPortal := Gear^.LinkedGear;
// check all gears for stuff to port through
iterator := nil;
@@ -4414,8 +4413,8 @@
if not Gear^.dX.isNegative then
Gear^.DirAngle := 180-Gear^.DirAngle;
- if ((Gear^.IntersectGear = nil)
- or (hwRound(Distance(Gear^.X - Gear^.IntersectGear^.X,Gear^.Y-Gear^.IntersectGear^.Y)) >=Gear^.Radius*2)) then
+ if ((Gear^.LinkedGear = nil)
+ or (hwRound(Distance(Gear^.X - Gear^.LinkedGear^.X,Gear^.Y-Gear^.LinkedGear^.Y)) >=Gear^.Radius*2)) then
begin
loadNewPortalBall(Gear, false);
inc(Gear^.Tag);
@@ -4457,7 +4456,7 @@
newPortal^.dX := newPortal^.dX * s;
newPortal^.dY := newPortal^.dY * s;
- newPortal^.IntersectGear := nil;
+ newPortal^.LinkedGear := nil;
if CurrentHedgehog <> nil then
with CurrentHedgehog^ do
@@ -4486,8 +4485,8 @@
else
begin
// link portals with each other
- newPortal^.IntersectGear := iterator;
- iterator^.IntersectGear := newPortal;
+ newPortal^.LinkedGear := iterator;
+ iterator^.LinkedGear := newPortal;
iterator^.Health := newPortal^.Health;
end;
end;
@@ -4940,7 +4939,7 @@
ApplyDamage(tmp, CurrentHedgehog, tmp^.Health div 3, dsUnknown);
//DrawTunnel(tmp^.X, tmp^.Y - _1, _0, _0_5, cHHRadius * 6, cHHRadius * 3);
tmp2:= AddGear(hwRound(tmp^.X), hwRound(tmp^.Y), gtHammerHit, 0, _0, _0, 0);
- tmp2^.IntersectGear:= tmp;
+ tmp2^.LinkedGear:= tmp;
SetAllToActive
end
else
@@ -4959,7 +4958,7 @@
HitGear: PGear;
begin
AllInactive := false;
- HitGear := Gear^.IntersectGear;
+ HitGear := Gear^.LinkedGear;
dec(Gear^.Timer);
if (HitGear = nil) or (Gear^.Timer = 0) or ((Gear^.Message and gmDestroy) <> 0) then
begin
--- a/hedgewars/uCollisions.pas Sat Jun 23 21:37:47 2012 -0400
+++ b/hedgewars/uCollisions.pas Sat Jun 23 22:39:00 2012 -0400
@@ -138,18 +138,11 @@
var x, y, i: LongInt;
TestWord: LongWord;
begin
-if Gear^.IntersectGear <> nil then
- with Gear^ do
- if (hwRound(IntersectGear^.X) + IntersectGear^.Radius < hwRound(X) - Radius)
- or (hwRound(IntersectGear^.X) - IntersectGear^.Radius > hwRound(X) + Radius) then
- begin
- IntersectGear:= nil;
- TestWord:= 0
- end
- else
- TestWord:= 255
-else
- TestWord:= 0;
+// Special case to emulate the old intersect gear clearing, but with a bit of slop for pixel overlap
+if (Gear^.CollisionMask = $FF7F) and (Gear^.Hedgehog <> nil) and (Gear^.Hedgehog^.Gear <> nil) and
+ ((hwRound(Gear^.Hedgehog^.Gear^.X) + Gear^.Hedgehog^.Gear^.Radius + 4 < hwRound(Gear^.X) - Gear^.Radius) or
+ (hwRound(Gear^.Hedgehog^.Gear^.X) - Gear^.Hedgehog^.Gear^.Radius - 4 > hwRound(Gear^.X) + Gear^.Radius)) then
+ Gear^.CollisionMask:= $FFFF;
x:= hwRound(Gear^.X);
if Dir < 0 then
@@ -164,7 +157,7 @@
i:= y + Gear^.Radius * 2 - 2;
repeat
if (y and LAND_HEIGHT_MASK) = 0 then
- if Land[y, x] > TestWord then
+ if Land[y, x] and Gear^.CollisionMask <> 0 then
exit;
inc(y)
until (y > i);
@@ -176,18 +169,11 @@
var x, y, i: LongInt;
TestWord: LongWord;
begin
-if Gear^.IntersectGear <> nil then
- with Gear^ do
- if (hwRound(IntersectGear^.Y) + IntersectGear^.Radius < hwRound(Y) - Radius) or
- (hwRound(IntersectGear^.Y) - IntersectGear^.Radius > hwRound(Y) + Radius) then
- begin
- IntersectGear:= nil;
- TestWord:= 0
- end
- else
- TestWord:= 255
-else
- TestWord:= 0;
+// Special case to emulate the old intersect gear clearing, but with a bit of slop for pixel overlap
+if (Gear^.CollisionMask = $FF7F) and (Gear^.Hedgehog <> nil) and (Gear^.Hedgehog^.Gear <> nil) and
+ ((hwRound(Gear^.Hedgehog^.Gear^.Y) + Gear^.Hedgehog^.Gear^.Radius + 4 < hwRound(Gear^.Y) - Gear^.Radius) or
+ (hwRound(Gear^.Hedgehog^.Gear^.Y) - Gear^.Hedgehog^.Gear^.Radius - 4 > hwRound(Gear^.Y) + Gear^.Radius)) then
+ Gear^.CollisionMask:= $FFFF;
y:= hwRound(Gear^.Y);
if Dir < 0 then
@@ -201,12 +187,12 @@
i:= x + Gear^.Radius * 2 - 2;
repeat
if (x and LAND_WIDTH_MASK) = 0 then
- if Land[y, x] > TestWord then
- begin
+ if Land[y, x] and Gear^.CollisionMask <> 0 then
+ begin
TestCollisionYwithGear:= Land[y, x];
exit;
- end;
- inc(x)
+ end;
+ inc(x)
until (x > i);
end;
TestCollisionYwithGear:= 0
--- a/hedgewars/uGearsHedgehog.pas Sat Jun 23 21:37:47 2012 -0400
+++ b/hedgewars/uGearsHedgehog.pas Sat Jun 23 22:39:00 2012 -0400
@@ -395,6 +395,7 @@
newGear^.Target.X:= TargetPoint.X;
newGear^.Target.Y:= TargetPoint.Y
end;
+ if newGear <> nil then newGear^.CollisionMask:= $FF7F;
// Clear FollowGear if using on a rope/parachute/saucer etc so focus stays with the hog's movement
if altUse then
--- a/hedgewars/uGearsList.pas Sat Jun 23 21:37:47 2012 -0400
+++ b/hedgewars/uGearsList.pas Sat Jun 23 22:39:00 2012 -0400
@@ -100,15 +100,14 @@
gear^.Density:= _1;
// Define ammo association, if any.
gear^.AmmoType:= GearKindAmmoTypeMap[Kind];
+gear^.CollisionMask:= $FFFF;
+
+if CurrentHedgehog <> nil then gear^.Hedgehog:= CurrentHedgehog;
+
if Ammoz[Gear^.AmmoType].Ammo.Propz and ammoprop_NeedTarget <> 0 then
gear^.Z:= cHHZ+1
else gear^.Z:= cUsualZ;
-if CurrentHedgehog <> nil then
- begin
- gear^.Hedgehog:= CurrentHedgehog;
- gear^.IntersectGear:= CurrentHedgehog^.Gear
- end;
case Kind of
gtGrenade,
@@ -483,9 +482,9 @@
// make sure that portals have their link removed before deletion
if (Gear^.Kind = gtPortal) then
begin
- if (Gear^.IntersectGear <> nil) then
- if (Gear^.IntersectGear^.IntersectGear = Gear) then
- Gear^.IntersectGear^.IntersectGear:= nil;
+ if (Gear^.LinkedGear <> nil) then
+ if (Gear^.LinkedGear^.LinkedGear = Gear) then
+ Gear^.LinkedGear^.LinkedGear:= nil;
end
else if Gear^.Kind = gtHedgehog then
(*
--- a/hedgewars/uGearsRender.pas Sat Jun 23 21:37:47 2012 -0400
+++ b/hedgewars/uGearsRender.pas Sat Jun 23 22:39:00 2012 -0400
@@ -948,8 +948,8 @@
gtBall: DrawSpriteRotatedF(sprBalls, x, y, Gear^.Tag,0, Gear^.DirAngle);
gtPortal: if ((Gear^.Tag and 1) = 0) // still moving?
- or (Gear^.IntersectGear = nil) or (Gear^.IntersectGear^.IntersectGear <> Gear) // not linked&backlinked?
- or ((Gear^.IntersectGear^.Tag and 1) = 0) then // linked portal still moving?
+ or (Gear^.LinkedGear = nil) or (Gear^.LinkedGear^.LinkedGear <> Gear) // not linked&backlinked?
+ or ((Gear^.LinkedGear^.Tag and 1) = 0) then // linked portal still moving?
DrawSpriteRotatedF(sprPortal, x, y, Gear^.Tag, hwSign(Gear^.dX), Gear^.DirAngle)
else DrawSpriteRotatedF(sprPortal, x, y, 4 + Gear^.Tag div 2, hwSign(Gear^.dX), Gear^.DirAngle);
--- a/hedgewars/uGearsUtils.pas Sat Jun 23 21:37:47 2012 -0400
+++ b/hedgewars/uGearsUtils.pas Sat Jun 23 22:39:00 2012 -0400
@@ -107,7 +107,7 @@
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);
+ dmg:= dmgBase - hwRound(Distance(tdX, tdY));
if dmg > 1 then
begin
dmg:= ModifyDamage(min(dmg div 2, Radius), Gear);
--- a/hedgewars/uTypes.pas Sat Jun 23 21:37:47 2012 -0400
+++ b/hedgewars/uTypes.pas Sat Jun 23 22:39:00 2012 -0400
@@ -249,7 +249,8 @@
Tag: LongInt;
Tex: PTexture;
Z: Longword;
- IntersectGear: PGear;
+ CollisionMask: Word;
+ LinkedGear: PGear;
FlightTime: Longword;
uid: Longword;
ImpactSound: TSound; // first sound, others have to be after it in the sounds def.