Start TestCake
authorunc0rr
Wed, 18 Jul 2012 23:02:14 +0400
changeset 7398 2b7b939014b5
parent 7397 833fc211ca2d
child 7399 e7ce559d8c94
Start TestCake
hedgewars/uAIAmmoTests.pas
hedgewars/uGearsHandlers.pas
--- a/hedgewars/uAIAmmoTests.pas	Wed Jul 18 15:05:56 2012 +0100
+++ b/hedgewars/uAIAmmoTests.pas	Wed Jul 18 23:02:14 2012 +0400
@@ -50,6 +50,7 @@
 function TestAirAttack(Me: PGear; Targ: TPoint; Level: LongInt; var ap: TAttackParams): LongInt;
 function TestTeleport(Me: PGear; Targ: TPoint; Level: LongInt; var ap: TAttackParams): LongInt;
 function TestHammer(Me: PGear; Targ: TPoint; Level: LongInt; var ap: TAttackParams): LongInt;
+function TestCake(Me: PGear; Targ: TPoint; Level: LongInt; var ap: TAttackParams): LongInt;
 
 type TAmmoTestProc = function (Me: PGear; Targ: TPoint; Level: LongInt; var ap: TAttackParams): LongInt;
     TAmmoTest = record
@@ -84,7 +85,7 @@
             (proc: nil;              flags: 0), // amSwitch
             (proc: @TestMortar;      flags: 0), // amMortar
             (proc: nil;              flags: 0), // amKamikaze
-            (proc: nil;              flags: 0), // amCake
+            (proc: @TestCake;        flags: 0), // amCake
             (proc: nil;              flags: 0), // amSeduction
             (proc: @TestWatermelon;  flags: 0), // amWatermelon
             (proc: nil;              flags: 0), // amHellishBomb
@@ -981,4 +982,53 @@
         end;
 end;
 
+
+function checkCakeWalk(Gear: PGear): LongInt;
+begin
+checkCakeWalk:= BadTurn
+end;
+
+function TestCake(Me: PGear; Targ: TPoint; Level: LongInt; var ap: TAttackParams): LongInt;
+var valueResult, v1, v2: LongInt;
+    x, y, trackFall: LongInt;
+    cake: TGear;
+begin
+    Level:= Level; // avoid compiler hint
+    ap.ExplR:= 0;
+    ap.Time:= 0;
+    ap.Power:= 1;
+
+    cake.Radius:= 7;
+
+    // check left direction
+    cake.Angle:= 3;
+    cake.dX.isNegative:= true;
+    cake.X:= Me^.X - _3;
+    cake.Y:= Me^.Y;
+    v1:= checkCakeWalk(@cake);
+
+    // now try opposite direction
+    cake.Angle:= 1;
+    cake.dX.isNegative:= false;
+    cake.X:= Me^.X + _3;
+    cake.Y:= Me^.Y;
+    v2:= checkCakeWalk(@cake);
+
+    if (v2 > v1) then
+        begin
+        ap.Angle:= 1;
+        valueResult:= v2
+        end
+    else
+        begin
+        ap.Angle:= -1;
+        valueResult:= v1
+        end;
+
+    if valueResult <= 0 then
+        valueResult:= BadTurn;
+
+    TestCake:= valueResult;
+end;
+
 end.
--- a/hedgewars/uGearsHandlers.pas	Wed Jul 18 15:05:56 2012 +0100
+++ b/hedgewars/uGearsHandlers.pas	Wed Jul 18 23:02:14 2012 +0400
@@ -29,6 +29,8 @@
 
 uses SDLh, uFloat, uCollisions;
 
+
+
 const dirs: array[0..3] of TPoint =   ((X: 0; Y: -1), (X: 1; Y: 0),(X: 0; Y: 1),(X: -1; Y: 0));
 
 procedure PrevAngle(Gear: PGear; dA: LongInt); inline;
@@ -38,7 +40,7 @@
 
 procedure NextAngle(Gear: PGear; dA: LongInt); inline;
 begin
-    Gear^.Angle := (LongInt(Gear^.Angle) + 4 + dA) mod 4
+    Gear^.Angle := (LongInt(Gear^.Angle)     + dA) mod 4
 end;
 
 procedure cakeStep(Gear: PGear);