Another try at keeping blowtorch/firepunch/jackhammer from going through indestructible stuff. Shame these routines don't use hedgehog movement
authornemo
Tue, 25 Aug 2009 20:54:11 +0000
changeset 2331 e4941a7986d6
parent 2330 ba46dcda3676
child 2332 351abbbb12f3
Another try at keeping blowtorch/firepunch/jackhammer from going through indestructible stuff. Shame these routines don't use hedgehog movement
hedgewars/GSHandlers.inc
hedgewars/uLandGraphics.pas
--- a/hedgewars/GSHandlers.inc	Mon Aug 24 22:57:59 2009 +0000
+++ b/hedgewars/GSHandlers.inc	Tue Aug 25 20:54:11 2009 +0000
@@ -573,7 +573,8 @@
 		DrawExplosion(i, hwRound(Gear^.Y) + 3, 3);
 		inc(i, 1)
 		end;
-    if Land[hwRound(Gear^.Y + _1_9) , hwRound(Gear^.X + Gear^.dX + SignAs(_16,Gear^.dX))] <> COLOR_INDESTRUCTIBLE then
+
+    if CheckLandValue(hwRound(Gear^.X + Gear^.dX + SignAs(_6,Gear^.dX)), hwRound(Gear^.Y + _1_9), COLOR_INDESTRUCTIBLE) then
         begin
         Gear^.X:= Gear^.X + Gear^.dX;
         Gear^.Y:= Gear^.Y + _1_9;
@@ -674,9 +675,11 @@
 		prevX:= hwRound(HHGear^.X);
 	
 // why the call to HedgehogStep then a further increment of X?	
-		if (prevX = hwRound(HHGear^.X)) and (Land[hwRound(HHGear^.Y) , hwRound(HHGear^.X + SignAs(_16, HHGear^.dX))] <> COLOR_INDESTRUCTIBLE) then HedgehogStep(HHGear);
+        if (prevX = hwRound(HHGear^.X)) and 
+           CheckLandValue(hwRound(HHGear^.X + SignAs(_6, HHGear^.dX)), hwRound(HHGear^.Y), COLOR_INDESTRUCTIBLE) then HedgehogStep(HHGear);
 		
-		if (prevX = hwRound(HHGear^.X)) and (Land[hwRound(HHGear^.Y) , hwRound(HHGear^.X + SignAs(_16, HHGear^.dX))] <> COLOR_INDESTRUCTIBLE) then HHGear^.X:= HHGear^.X + SignAs(_1, HHGear^.dX);
+        if (prevX = hwRound(HHGear^.X)) and 
+           CheckLandValue(hwRound(HHGear^.X + SignAs(_6, HHGear^.dX)), hwRound(HHGear^.Y), COLOR_INDESTRUCTIBLE) then HHGear^.X:= HHGear^.X + SignAs(_1, HHGear^.dX);
 		HHGear^.State:= HHGear^.State or gstAttacking
 		end;
 
@@ -684,11 +687,10 @@
 	if BTSteps = 7 then
 		begin
 		BTSteps:= 0;
-        if Land[hwRound(HHGear^.Y + Gear^.dY * (cHHRadius + cBlowTorchC)) , hwRound(HHGear^.X + Gear^.dX * (cHHRadius + cBlowTorchC) + SignAs(_16,Gear^.dX)
-)] <> COLOR_INDESTRUCTIBLE then
+        if CheckLandValue(hwRound(HHGear^.X + Gear^.dX * (cHHRadius + cBlowTorchC) + SignAs(_6,Gear^.dX)), hwRound(HHGear^.Y + Gear^.dY * (cHHRadius + cBlowTorchC)), COLOR_INDESTRUCTIBLE) then
             begin
-		Gear^.X:= HHGear^.X + Gear^.dX * (cHHRadius + cBlowTorchC);
-		Gear^.Y:= HHGear^.Y + Gear^.dY * (cHHRadius + cBlowTorchC);
+		    Gear^.X:= HHGear^.X + Gear^.dX * (cHHRadius + cBlowTorchC);
+		    Gear^.Y:= HHGear^.Y + Gear^.dY * (cHHRadius + cBlowTorchC);
             end;
 		HHGear^.State:= HHGear^.State or gstNoDamage;
 		AmmoShove(Gear, 2, 15);
@@ -1293,8 +1295,8 @@
 	exit
 	end;
 
-if Land[hwRound(HHGear^.Y + HHGear^.dY + SignAs(_16,Gear^.dX)
-), hwRound(HHGear^.X)] <> COLOR_INDESTRUCTIBLE then HHGear^.Y:= HHGear^.Y + HHGear^.dY
+if CheckLandValue(hwRound(HHGear^.X), hwRound(HHGear^.Y + HHGear^.dY + SignAs(_6,Gear^.dY)), COLOR_INDESTRUCTIBLE) then 
+   HHGear^.Y:= HHGear^.Y + HHGear^.dY
 end;
 
 procedure doStepFirePunch(Gear: PGear);
--- a/hedgewars/uLandGraphics.pas	Mon Aug 24 22:57:59 2009 +0000
+++ b/hedgewars/uLandGraphics.pas	Tue Aug 25 20:54:11 2009 +0000
@@ -28,6 +28,7 @@
 
 function SweepDirty: boolean;
 function Despeckle(X, Y: LongInt): boolean;
+function CheckLandValue(X, Y: LongInt; Color: Word): boolean;
 procedure DrawExplosion(X, Y, Radius: LongInt);
 procedure DrawHLinesExplosions(ar: PRangeArray; Radius: LongInt; y, dY: LongInt; Count: Byte);
 procedure DrawTunnel(X, Y, dX, dY: hwFloat; ticks, HalfWidth: LongInt);
@@ -477,4 +478,9 @@
 SweepDirty:= Result
 end;
 
+// Return true if outside of land or not the value tested, used right now for some X/Y movement that does not use normal hedgehog movement in GSHandlers.inc
+function CheckLandValue(X, Y: LongInt; Color: Word): boolean;
+begin
+     CheckLandValue:= ((X and LAND_WIDTH_MASK <> 0) or (Y and LAND_HEIGHT_MASK <> 0)) or (Land[Y, X] <> Color)
+end;
 end.