hedgewars/uCollisions.pas
changeset 5906 ed9676dc8cb4
parent 5896 9ce1cf4e5a32
child 5919 f737843dd331
--- a/hedgewars/uCollisions.pas	Wed Sep 14 22:27:22 2011 +0200
+++ b/hedgewars/uCollisions.pas	Wed Sep 14 22:39:39 2011 +0200
@@ -47,10 +47,11 @@
 function  TestCollisionX(Gear: PGear; Dir: LongInt): boolean;
 function  TestCollisionY(Gear: PGear; Dir: LongInt): boolean;
 
-function  TestCollisionXwithXYShift(Gear: PGear; ShiftX: hwFloat; ShiftY: LongInt; Dir: LongInt): boolean;
-function  TestCollisionYwithXYShift(Gear: PGear; ShiftX, ShiftY: LongInt; Dir: LongInt): boolean;
+function  TestCollisionXwithXYShift(Gear: PGear; ShiftX: hwFloat; ShiftY: LongInt; Dir: LongInt; withGear: boolean = true): boolean;
+function  TestCollisionYwithXYShift(Gear: PGear; ShiftX, ShiftY: LongInt; Dir: LongInt; withGear: boolean = true): boolean;
 
-function  calcSlopeTangent(Gear: PGear; collisionX, collisionY: LongInt; var outDeltaX, outDeltaY: LongInt; TestWord: LongWord): Boolean;
+function  TestRectancleForObstacle(x1, y1, x2, y2: LongInt; landOnly: boolean): boolean;
+function  CalcSlopeTangent(Gear: PGear; collisionX, collisionY: LongInt; var outDeltaX, outDeltaY: LongInt; TestWord: LongWord): Boolean;
 
 implementation
 uses uConsts, uLandGraphics, uVariables, uDebug, uGears;
@@ -291,11 +292,13 @@
    end
 end;
 
-function TestCollisionXwithXYShift(Gear: PGear; ShiftX: hwFloat; ShiftY: LongInt; Dir: LongInt): boolean;
+function TestCollisionXwithXYShift(Gear: PGear; ShiftX: hwFloat; ShiftY: LongInt; Dir: LongInt; withGear: boolean = true): boolean;
 begin
 Gear^.X:= Gear^.X + ShiftX;
 Gear^.Y:= Gear^.Y + int2hwFloat(ShiftY);
-TestCollisionXwithXYShift:= TestCollisionXwithGear(Gear, Dir);
+if withGear then 
+    TestCollisionXwithXYShift:= TestCollisionXwithGear(Gear, Dir)
+else TestCollisionXwithXYShift:= TestCollisionX(Gear, Dir);
 Gear^.X:= Gear^.X - ShiftX;
 Gear^.Y:= Gear^.Y - int2hwFloat(ShiftY)
 end;
@@ -337,17 +340,49 @@
 TestCollisionY:= false
 end;
 
-function TestCollisionYwithXYShift(Gear: PGear; ShiftX, ShiftY: LongInt; Dir: LongInt): boolean;
+function TestCollisionYwithXYShift(Gear: PGear; ShiftX, ShiftY: LongInt; Dir: LongInt; withGear: boolean = true): boolean;
 begin
 Gear^.X:= Gear^.X + int2hwFloat(ShiftX);
 Gear^.Y:= Gear^.Y + int2hwFloat(ShiftY);
-TestCollisionYwithXYShift:= TestCollisionYwithGear(Gear, Dir);
+if withGear then TestCollisionYwithXYShift:= TestCollisionYwithGear(Gear, Dir)
+else TestCollisionYwithXYShift:= TestCollisionY(Gear, Dir);
 Gear^.X:= Gear^.X - int2hwFloat(ShiftX);
 Gear^.Y:= Gear^.Y - int2hwFloat(ShiftY)
 end;
 
+function TestRectancleForObstacle(x1, y1, x2, y2: LongInt; landOnly: boolean): boolean;
+var x, y: LongInt;
+    TestWord: LongWord;
+begin
+if landOnly then
+    TestWord:= 255
+else
+    TestWord:= 0;
 
-function calcSlopeTangent(Gear: PGear; collisionX, collisionY: LongInt; var outDeltaX, outDeltaY: LongInt; TestWord: LongWord): boolean;
+if x1 > x2 then
+begin
+    x  := x1;
+    x1 := x2;
+    x2 := x;
+end;
+
+if y1 > y2 then
+begin
+    y  := y1;
+    y1 := y2;
+    y2 := y;
+end;
+
+for y := y1 to y2 do
+    for x := x1 to x2 do
+        if ((y and LAND_HEIGHT_MASK) = 0) and ((x and LAND_WIDTH_MASK) = 0)
+          and (Land[y, x] > TestWord) then
+            exit(true);
+
+TestRectancleForObstacle:= false
+end;
+
+function CalcSlopeTangent(Gear: PGear; collisionX, collisionY: LongInt; var outDeltaX, outDeltaY: LongInt; TestWord: LongWord): boolean;
 var ldx, ldy, rdx, rdy: LongInt;
     i, j, mx, my, li, ri, jfr, jto, tmpo : ShortInt;
     tmpx, tmpy: LongWord;