AI uses cake! Known issues: AI could damage itself for no reason, could let cake go looping in a hole with exit closed by AI hog.
authorunc0rr
Sun, 22 Jul 2012 00:48:48 +0400
changeset 7416 2f2f78fc65a3
parent 7414 a9f18c66ce34
child 7418 f611ee4760c0
AI uses cake! Known issues: AI could damage itself for no reason, could let cake go looping in a hole with exit closed by AI hog.
hedgewars/GSHandlers.inc
hedgewars/uAI.pas
hedgewars/uAIActions.pas
hedgewars/uAIAmmoTests.pas
hedgewars/uConsts.pas
hedgewars/uGearsHandlers.pas
hedgewars/uVariables.pas
--- a/hedgewars/GSHandlers.inc	Fri Jul 20 21:30:53 2012 -0400
+++ b/hedgewars/GSHandlers.inc	Sun Jul 22 00:48:48 2012 +0400
@@ -3007,7 +3007,6 @@
 ////////////////////////////////////////////////////////////////////////////////
 
 const cakeh =   27;
-    cakeDmg =   75;
 var 
     CakePoints: array[0..Pred(cakeh)] of record
         x, y: hwFloat;
@@ -3091,6 +3090,19 @@
     if Gear^.Tag < 7 then
         exit;
 
+    dec(Gear^.Health);
+    Gear^.Timer := Gear^.Health*10;
+    if Gear^.Health mod 100 = 0 then
+        Gear^.PortalCounter:= 0;
+    // This is not seconds, but at least it is *some* feedback
+    if (Gear^.Health = 0) or ((Gear^.Message and gmAttack) <> 0) then
+        begin
+        FollowGear := Gear;
+        Gear^.RenderTimer := false;
+        Gear^.doStep := @doStepCakeDown;
+        exit
+        end;
+
     cakeStep(Gear);
 
     if Gear^.Tag = 0 then
@@ -3102,18 +3114,6 @@
         CakePoints[CakeI].y := Gear^.Y;
         Gear^.DirAngle := DxDy2Angle(tdx, tdy);
         end;
-
-    dec(Gear^.Health);
-    Gear^.Timer := Gear^.Health*10;
-    if Gear^.Health mod 100 = 0 then
-        Gear^.PortalCounter:= 0;
-    // This is not seconds, but at least it is *some* feedback
-    if (Gear^.Health = 0) or ((Gear^.Message and gmAttack) <> 0) then
-        begin
-        FollowGear := Gear;
-        Gear^.RenderTimer := false;
-        Gear^.doStep := @doStepCakeDown
-        end
 end;
 
 procedure doStepCakeUp(Gear: PGear);
--- a/hedgewars/uAI.pas	Fri Jul 20 21:30:53 2012 -0400
+++ b/hedgewars/uAI.pas	Sun Jul 22 00:48:48 2012 +0400
@@ -191,7 +191,14 @@
                             AddAction(BestActions, aia_attack, aim_push, 650 + random(300), 0, 0);
                             AddAction(BestActions, aia_attack, aim_release, ap.Power, 0, 0);
                             end;
-                            
+
+                    if (Ammoz[a].Ammo.Propz and ammoprop_Track) <> 0 then
+                        begin
+                        AddAction(BestActions, aia_waitAmmoXY, 0, 12, ap.ExplX, ap.ExplY);
+                        AddAction(BestActions, aia_attack, aim_push, 1, 0, 0);
+                        AddAction(BestActions, aia_attack, aim_release, 7, 0, 0);
+                        end;
+
                     if ap.ExplR > 0 then
                         AddAction(BestActions, aia_AwareExpl, ap.ExplR, 10, ap.ExplX, ap.ExplY);
                     end
@@ -476,12 +483,11 @@
                 
             end else
                 begin
-                (*
-                if not scoreShown then
+                {if not scoreShown then
                     begin
                     if BestActions.Score > 0 then ParseCommand('/say Expected score = ' + inttostr(BestActions.Score div 1024), true);
                     scoreShown:= true
-                    end;*)
+                    end;}
                 ProcessAction(BestActions, Gear)
                 end
         else if ((GameTicks - StartTicks) > cMaxAIThinkTime)
--- a/hedgewars/uAIActions.pas	Fri Jul 20 21:30:53 2012 -0400
+++ b/hedgewars/uAIActions.pas	Sun Jul 22 00:48:48 2012 +0400
@@ -44,6 +44,7 @@
     aia_Wait       = $8009;
     aia_Put        = $800A;
     aia_waitAngle  = $800B;
+    aia_waitAmmoXY = $800C;
     
     aim_push       = $8000;
     aim_release    = $8001;
@@ -234,6 +235,10 @@
                 
             aia_waitAngle:
                 if Me^.Angle <> Abs(Param) then exit;
+
+            aia_waitAmmoXY:
+                if (CurAmmoGear <> nil) and ((hwRound(CurAmmoGear^.X) <> X) or (hwRound(CurAmmoGear^.Y) <> Y)) then exit;
+
             end
         else
             begin
--- a/hedgewars/uAIAmmoTests.pas	Fri Jul 20 21:30:53 2012 -0400
+++ b/hedgewars/uAIAmmoTests.pas	Sun Jul 22 00:48:48 2012 +0400
@@ -85,7 +85,7 @@
             (proc: nil;              flags: 0), // amSwitch
             (proc: @TestMortar;      flags: 0), // amMortar
             (proc: nil;              flags: 0), // amKamikaze
-            (proc: @TestCake;        flags: 0), // amCake
+            (proc: @TestCake;        flags: amtest_OnTurn or amtest_NoTarget), // amCake
             (proc: nil;              flags: 0), // amSeduction
             (proc: @TestWatermelon;  flags: 0), // amWatermelon
             (proc: nil;              flags: 0), // amHellishBomb
@@ -122,7 +122,7 @@
 const BadTurn = Low(LongInt) div 4;
 
 implementation
-uses uAIMisc, uVariables, uUtils;
+uses uAIMisc, uVariables, uUtils, uGearsHandlers, uCollisions;
 
 function Metric(x1, y1, x2, y2: LongInt): LongInt; inline;
 begin
@@ -983,9 +983,24 @@
 end;
 
 
-function checkCakeWalk(Gear: PGear): LongInt;
+procedure checkCakeWalk(Me, Gear: PGear; var ap: TAttackParams);
+var i: Longword;
+    v: LongInt;
 begin
-checkCakeWalk:= BadTurn
+while (not TestColl(hwRound(Gear^.X), hwRound(Gear^.Y), 6)) and (Gear^.Y.Round < LAND_HEIGHT) do
+    Gear^.Y:= Gear^.Y + _1;
+
+for i:= 0 to 2040 do
+    begin
+    cakeStep(Gear);
+    v:= RateExplosion(Me, hwRound(Gear^.X), hwRound(Gear^.Y), cakeDmg * 2, afTrackFall);
+    if v > ap.Power then 
+        begin
+        ap.ExplX:= hwRound(Gear^.X);
+        ap.ExplY:= hwRound(Gear^.Y);
+        ap.Power:= v
+        end
+    end;
 end;
 
 function TestCake(Me: PGear; Targ: TPoint; Level: LongInt; var ap: TAttackParams): LongInt;
@@ -996,23 +1011,29 @@
     Level:= Level; // avoid compiler hint
     ap.ExplR:= 0;
     ap.Time:= 0;
-    ap.Power:= 1;
+    ap.Power:= BadTurn; // use it as max score value in checkCakeWalk
 
+    FillChar(cake, sizeof(cake), 0);
     cake.Radius:= 7;
+    cake.CollisionMask:= $FF7F;
 
     // check left direction
     cake.Angle:= 3;
     cake.dX.isNegative:= true;
     cake.X:= Me^.X - _3;
     cake.Y:= Me^.Y;
-    v1:= checkCakeWalk(@cake);
+    checkCakeWalk(Me, @cake, ap);
+    v1:= ap.Power;
 
     // now try opposite direction
     cake.Angle:= 1;
     cake.dX.isNegative:= false;
     cake.X:= Me^.X + _3;
     cake.Y:= Me^.Y;
-    v2:= checkCakeWalk(@cake);
+    checkCakeWalk(Me, @cake, ap);
+    v2:= ap.Power;
+
+    ap.Power:= 1;
 
     if (v2 > v1) then
         begin
--- a/hedgewars/uConsts.pas	Fri Jul 20 21:30:53 2012 -0400
+++ b/hedgewars/uConsts.pas	Sun Jul 22 00:48:48 2012 +0400
@@ -146,6 +146,7 @@
     cBarrelHealth = 60;
     cShotgunRadius = 22;
     cBlowTorchC    = 6;
+    cakeDmg =   75;
 
     cKeyMaxIndex = 1023;
     cKbdMaxIndex = 65536;//need more room for the modifier keys
@@ -266,6 +267,7 @@
     ammoprop_NeedUpDown   = $00008000;//Used by TouchInterface to show or hide up/down widgets 
     ammoprop_OscAim       = $00010000;
     ammoprop_NoMoveAfter  = $00020000;
+    ammoprop_Track        = $00040000;
     ammoprop_NoRoundEnd   = $10000000;
 
     AMMO_INFINITE = 100;
--- a/hedgewars/uGearsHandlers.pas	Fri Jul 20 21:30:53 2012 -0400
+++ b/hedgewars/uGearsHandlers.pas	Sun Jul 22 00:48:48 2012 +0400
@@ -52,8 +52,8 @@
     dA := hwSign(Gear^.dX);
     xx := dirs[Gear^.Angle].x;
     yy := dirs[Gear^.Angle].y;
-    xxn := dirs[(LongInt(Gear^.Angle) + 4 + dA) mod 4].x;
-    yyn := dirs[(LongInt(Gear^.Angle) + 4 + dA) mod 4].y;
+    xxn := dirs[(Gear^.Angle + dA) and 3].x;
+    yyn := dirs[(Gear^.Angle + dA) and 3].y;
 
     if (xx = 0) then
         if TestCollisionYwithGear(Gear, yy) <> 0 then
--- a/hedgewars/uVariables.pas	Fri Jul 20 21:30:53 2012 -0400
+++ b/hedgewars/uVariables.pas	Sun Jul 22 00:48:48 2012 +0400
@@ -1446,7 +1446,8 @@
             NumberInCase: 1;
             Ammo: (Propz: ammoprop_ForwMsgs or 
                           ammoprop_NoCrosshair or 
-                          ammoprop_DontHold;
+                          ammoprop_DontHold or
+                          ammoprop_Track;
                 Count: 1;
                 NumPerTurn: 0;
                 Timer: 0;