merge
authormikade
Wed, 14 Sep 2011 17:52:46 +0200
changeset 5899 0c3db82e9f4d
parent 5897 0e0fc7e08a3d (current diff)
parent 5896 9ce1cf4e5a32 (diff)
child 5900 37516a3bdb0e
merge
hedgewars/uScript.pas
--- a/hedgewars/GSHandlers.inc	Wed Sep 14 15:23:40 2011 +0200
+++ b/hedgewars/GSHandlers.inc	Wed Sep 14 17:52:46 2011 +0200
@@ -4209,7 +4209,7 @@
     begin
         Gear^.State := Gear^.State or gstCollision;
         Gear^.State := Gear^.State and not gstMoving;
-        if not calcSlopeTangent(Gear, x, y, tx, ty, 255)
+        if not CalcSlopeTangent(Gear, x, y, tx, ty, 255)
            or (DistanceI(tx,ty) < _12) then // reject shots at too irregular terrain
         begin
             loadNewPortalBall(Gear, true);
--- a/hedgewars/uCollisions.pas	Wed Sep 14 15:23:40 2011 +0200
+++ b/hedgewars/uCollisions.pas	Wed Sep 14 17:52:46 2011 +0200
@@ -50,7 +50,8 @@
 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;
@@ -349,8 +350,39 @@
 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;
--- a/hedgewars/uScript.pas	Wed Sep 14 15:23:40 2011 +0200
+++ b/hedgewars/uScript.pas	Wed Sep 14 17:52:46 2011 +0200
@@ -1503,6 +1503,29 @@
         lua_pushinteger(L, ord(CurrentHedgehog^.CurAmmoType));
     lc_getcurammotype := 1;
 end;
+
+// boolean TestRectForObstacle(x1, y1, x2, y2, landOnly)
+function lc_testrectforobstacle(L : Plua_State) : LongInt; Cdecl;
+var rtn: Boolean;
+begin
+    if lua_gettop(L) <> 5 then
+        begin
+        LuaError('Lua: Wrong number of parameters passed to TestRectForObstacle!');
+        lua_pushnil(L); // return value on stack (nil)
+        end
+    else
+        begin
+        rtn:= TestRectancleForObstacle(
+                    lua_tointeger(L, 1),
+                    lua_tointeger(L, 2),
+                    lua_tointeger(L, 3),
+                    lua_tointeger(L, 4),
+                    lua_toboolean(L, 5)
+                    );
+        lua_pushboolean(L, rtn);
+        end;
+    lc_testrectforobstacle:= 1
+end;
 ///////////////////
 
 procedure ScriptPrintStack;
@@ -1986,6 +2009,7 @@
 lua_register(luaState, 'SetHogHat', @lc_sethoghat);
 lua_register(luaState, 'PlaceGirder', @lc_placegirder);
 lua_register(luaState, 'GetCurAmmoType', @lc_getcurammotype);
+lua_register(luaState, 'TestRectForObstacle', @lc_testrectforobstacle);
 
 
 ScriptClearStack; // just to be sure stack is empty