Change AI behavior for drill rocket
authorUrbertar
Tue, 26 Mar 2013 22:39:22 +0200 (2013-03-26)
changeset 8793 43e106417a05
parent 8789 caba5291face
child 8795 b5b79a8f9354
Change AI behavior for drill rocket
hedgewars/GSHandlers.inc
hedgewars/uAIAmmoTests.pas
hedgewars/uAIMisc.pas
--- a/hedgewars/GSHandlers.inc	Tue Mar 26 17:34:29 2013 +0100
+++ b/hedgewars/GSHandlers.inc	Tue Mar 26 22:39:22 2013 +0200
@@ -2886,18 +2886,16 @@
 procedure doStepDrillDrilling(Gear: PGear);
 var 
     t: PGearArray;
-    ox, oy: hwFloat;
     tempColl: Word; 
 begin
     AllInactive := false;
 
+
     if (Gear^.Timer > 0) and ((Gear^.Timer mod 10) = 0) then
     begin
-        ox := Gear^.X;
-        oy := Gear^.Y;
+        DrawTunnel(Gear^.X, Gear^.Y, Gear^.dX, Gear^.dY, 2, 6);
         Gear^.X := Gear^.X + Gear^.dX;
         Gear^.Y := Gear^.Y + Gear^.dY;
-        DrawTunnel(oX, oY, Gear^.dX, Gear^.dY, 2, 6);
         if (Gear^.Timer mod 30) = 0 then
             AddVisualGear(hwRound(Gear^.X + _20 * Gear^.dX), hwRound(Gear^.Y + _20 * Gear^.dY), vgtDust);
         if (CheckGearDrowning(Gear)) then
--- a/hedgewars/uAIAmmoTests.pas	Tue Mar 26 17:34:29 2013 +0100
+++ b/hedgewars/uAIAmmoTests.pas	Tue Mar 26 22:39:22 2013 +0200
@@ -197,6 +197,8 @@
     x, y, dX, dY: real;
     t: LongInt;
     value: LongInt;
+    t2: real;
+    timer: Longint;
 begin
     mX:= hwFloat2Float(Me^.X);
     mY:= hwFloat2Float(Me^.Y);
@@ -224,7 +226,25 @@
                 dec(t)
             until (((Me = CurrentHedgehog^.Gear) and TestColl(trunc(x), trunc(y), 5)) or 
                    ((Me <> CurrentHedgehog^.Gear) and TestCollExcludingMe(Me, trunc(x), trunc(y), 5))) or (y > cWaterLine);
-            
+
+            if TestCollWithLand(trunc(x), trunc(y), 5) then
+                begin
+                timer := 500;
+                t2 := 0.5 / sqrt(sqr(dX) + sqr(dY));
+                dX := dX * t2;
+                dY := dY * t2;
+                repeat
+                    x:= x + dX;
+                    y:= y + dY;
+                    dec(timer);
+                until (Abs(Targ.X - trunc(x)) + Abs(Targ.Y - trunc(y)) < 5)
+                    or (x < 0)
+                    or (y < 0)
+                    or (trunc(x) > LAND_WIDTH)
+                    or (trunc(y) > LAND_HEIGHT)
+                    or not TestCollWithLand(trunc(x), trunc(y), 5)
+                    or (timer = 0)
+                end;
             EX:= trunc(x);
             EY:= trunc(y);
             if Level = 1 then
--- a/hedgewars/uAIMisc.pas	Tue Mar 26 17:34:29 2013 +0100
+++ b/hedgewars/uAIMisc.pas	Tue Mar 26 22:39:22 2013 +0200
@@ -64,6 +64,7 @@
 function  TestCollExcludingObjects(x, y, r: LongInt): boolean; inline;
 function  TestCollExcludingMe(Me: PGear; x, y, r: LongInt): boolean; inline;
 function  TraceShoveFall(x, y, dX, dY: Real): LongInt;
+function TestCollWithLand(x, y, r: LongInt): boolean; inline;
 
 function  RateExplosion(Me: PGear; x, y, r: LongInt): LongInt; inline;
 function  RateExplosion(Me: PGear; x, y, r: LongInt; Flags: LongWord): LongInt;