AI is pretty good at using Bee weapon
authorunc0rr
Thu, 31 Dec 2015 16:26:21 +0300
changeset 11475 1d478892cf1c
parent 11474 67ae276ba229
child 11476 c4e1d39acc56
AI is pretty good at using Bee weapon
hedgewars/uAI.pas
hedgewars/uAIAmmoTests.pas
hedgewars/uGearsHandlersMess.pas
--- a/hedgewars/uAI.pas	Thu Dec 31 14:00:27 2015 +0300
+++ b/hedgewars/uAI.pas	Thu Dec 31 16:26:21 2015 +0300
@@ -166,6 +166,11 @@
 
                     AddAction(BestActions, aia_Weapon, Longword(a), 300 + random(400), 0, 0);
 
+                    if (Ammoz[a].Ammo.Propz and ammoprop_NeedTarget) <> 0 then
+                        begin
+                        AddAction(BestActions, aia_Put, 0, 8, ap.AttackPutX, ap.AttackPutY)
+                        end;
+
                     if (ap.Angle > 0) then
                         AddAction(BestActions, aia_LookRight, 0, 200, 0, 0)
                     else if (ap.Angle < 0) then
@@ -189,11 +194,6 @@
                             end
                         end;
 
-                    if (Ammoz[a].Ammo.Propz and ammoprop_NeedTarget) <> 0 then
-                        begin
-                        AddAction(BestActions, aia_Put, 0, 1, ap.AttackPutX, ap.AttackPutY)
-                        end;
-
                     if (Ammoz[a].Ammo.Propz and ammoprop_OscAim) <> 0 then
                         begin
                         AddAction(BestActions, aia_attack, aim_push, 350 + random(200), 0, 0);
--- a/hedgewars/uAIAmmoTests.pas	Thu Dec 31 14:00:27 2015 +0300
+++ b/hedgewars/uAIAmmoTests.pas	Thu Dec 31 16:26:21 2015 +0300
@@ -198,9 +198,6 @@
     f: boolean;
     speed, d: real;
 begin
-        addfilelog('002');
-
-    speed:= sqrt(sqr(dx) + sqr(dy));
     // parabola flight before activation
     t:= 500;
     repeat
@@ -218,19 +215,21 @@
         eY:= trunc(y);
         exit(RateExplosion(Me, eX, eY, 101, afTrackFall or afErasesLand));
     end;
-        
+
+
     // activated
     t:= 5000;
-    
+    speed:= sqrt(sqr(dx) + sqr(dy));
+
     repeat
         if (t and $F) = 0 then
         begin
-            dx:= 0.9 * (dx + 0.000064 * (tX - x));
-            dy:= 0.9 * (dy + 0.000064 * (tY - y));
+            dx:= dx + 0.000064 * (tX - x);
+            dy:= dy + 0.000064 * (tY - y);
             d := speed / sqrt(sqr(dx) + sqr(dy));
             dx:= dx * d;
             dy:= dy * d;
-            end;
+        end;
 
         x:= x + dx;
         y:= y + dy;
@@ -251,13 +250,13 @@
 
 function TestBee(Me: PGear; Targ: TTarget; Level: LongInt; var ap: TAttackParams): LongInt;
 var i, j: LongInt;
-    valueResult, v: LongInt;
+    valueResult, v, a, p: LongInt;
     mX, mY, dX: real;
     eX, eY: LongInt;
 begin
-    if Level > 1 then 
+    if Level > 1 then
         exit(BadTurn);
-    addfilelog('001');
+
     eX:= 0;
     eY:= 0;
     mX:= hwFloat2Float(Me^.X);
@@ -266,30 +265,29 @@
     for i:= 0 to 8 do
         for j:= 0 to 1 do
             begin
-            ap.Angle:= i * 120;
-            ap.Power:= random(1700) + 300;
-            dx:= sin(ap.Angle / 2048);
-            if j = 0 then 
-                begin
-                ap.Angle:= -ap.Angle;
-                dx:= -dx;
-                end;
-            
+            a:= i * 120;
+            p:= random(cMaxPower - 200) + 180;
+
+            if j = 0 then
+                a:= -a;
+
             v:= calcBeeFlight(Me
                     , mX
                     , mY
-                    , sin(ap.Angle / 2048) * ap.Power / cMaxPower
-                    , cos(ap.Angle / 2048) * ap.Power / cMaxPower
+                    , sin(a * pi / 2048) * p / cPowerDivisor
+                    , -cos(a * pi / 2048) * p / cPowerDivisor
                     , Targ.Point.X
                     , Targ.Point.Y
                     , eX
                     , eY);
-                    
+
             if v > valueResult then
                 begin
                 ap.ExplR:= 100;
                 ap.ExplX:= eX;
                 ap.ExplY:= eY;
+                ap.Angle:= a;
+                ap.Power:= p;
                 valueResult:= v
                 end
             end;
@@ -297,7 +295,10 @@
     ap.AttackPutX:= Targ.Point.X;
     ap.AttackPutY:= Targ.Point.Y;
 
-    TestBee:= valueResult
+    if valueResult > 0 then
+        TestBee:= valueResult - 5000
+    else
+        TestBee:= BadTurn // no digging
 end;
 
 function TestDrillRocket(Me: PGear; Targ: TTarget; Level: LongInt; var ap: TAttackParams): LongInt;
--- a/hedgewars/uGearsHandlersMess.pas	Thu Dec 31 14:00:27 2015 +0300
+++ b/hedgewars/uGearsHandlersMess.pas	Thu Dec 31 16:26:21 2015 +0300
@@ -1028,13 +1028,13 @@
         end
     else
         begin
-        if (GameTicks and $F) = 0 then
+        if (Gear^.Timer and $F) = 0 then
             begin
-            if (GameTicks and $30) = 0 then
+            if (Gear^.Timer and $3F) = 0 then
                 AddVisualGear(gX, gY, vgtBeeTrace);
 
-            Gear^.dX := Gear^.Elasticity * (Gear^.dX + _0_000064 * (Gear^.Target.X - gX));
-            Gear^.dY := Gear^.Elasticity * (Gear^.dY + _0_000064 * (Gear^.Target.Y - gY));
+            Gear^.dX := Gear^.dX + _0_000064 * (Gear^.Target.X - gX);
+            Gear^.dY := Gear^.dY + _0_000064 * (Gear^.Target.Y - gY);
             // make sure new speed isn't higher than original one (which we stored in Friction variable)
             t := Gear^.Friction / Distance(Gear^.dX, Gear^.dY);
             Gear^.dX := Gear^.dX * t;