TestKamikaze, needs polishing
authorunc0rr
Fri, 03 Aug 2012 16:58:49 +0400
changeset 7471 ce5d3e39361e
parent 7468 1333ca7554dc
child 7474 bbecb1b4f59b
TestKamikaze, needs polishing
hedgewars/uAIAmmoTests.pas
hedgewars/uAIMisc.pas
--- a/hedgewars/uAIAmmoTests.pas	Wed Aug 01 18:35:09 2012 -0400
+++ b/hedgewars/uAIAmmoTests.pas	Fri Aug 03 16:58:49 2012 +0400
@@ -47,6 +47,7 @@
 function TestBaseballBat(Me: PGear; Targ: TPoint; Level: LongInt; var ap: TAttackParams): LongInt;
 function TestFirePunch(Me: PGear; Targ: TPoint; Level: LongInt; var ap: TAttackParams): LongInt;
 function TestWhip(Me: PGear; Targ: TPoint; Level: LongInt; var ap: TAttackParams): LongInt;
+function TestKamikaze(Me: PGear; Targ: TPoint; Level: LongInt; var ap: TAttackParams): LongInt;
 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;
@@ -84,7 +85,7 @@
             //(proc: @TestTeleport;    flags: amtest_OnTurn), // amTeleport
             (proc: nil;              flags: 0), // amSwitch
             (proc: @TestMortar;      flags: 0), // amMortar
-            (proc: nil;              flags: 0), // amKamikaze
+            (proc: @TestKamikaze;    flags: 0), // amKamikaze
             (proc: @TestCake;        flags: amtest_OnTurn or amtest_NoTarget), // amCake
             (proc: nil;              flags: 0), // amSeduction
             (proc: @TestWatermelon;  flags: 0), // amWatermelon
@@ -167,7 +168,7 @@
         
         EX:= trunc(x);
         EY:= trunc(y);
-        if Me^.Hedgehog^.BotLevel = 1 then
+        if Level = 1 then
             value:= RateExplosion(Me, EX, EY, 101, afTrackFall or afErasesLand)
         else value:= RateExplosion(Me, EX, EY, 101);
         if value = 0 then
@@ -330,7 +331,7 @@
     EX:= trunc(x);
     EY:= trunc(y);
     if t < 50 then 
-        if Me^.Hedgehog^.BotLevel = 1 then
+        if Level = 1 then
             Score:= RateExplosion(Me, EX, EY, 101, afTrackFall or afErasesLand)
         else Score:= RateExplosion(Me, EX, EY, 101)
     else 
@@ -600,19 +601,22 @@
     d: Longword;
     fallDmg, valueResult: LongInt;
 begin
-if Me^.Hedgehog^.BotLevel > 3 then exit(BadTurn);
+if Level > 3 then exit(BadTurn);
 dmgMod:= 0.01 * hwFloat2Float(cDamageModifier) * cDamagePercent;
 Level:= Level; // avoid compiler hint
 ap.ExplR:= 0;
 ap.Time:= 0;
 ap.Power:= 1;
+
 x:= hwFloat2Float(Me^.X);
 y:= hwFloat2Float(Me^.Y);
+
 if Abs(trunc(x) - Targ.X) + Abs(trunc(y) - Targ.Y) < 40 then
     begin
     TestDesertEagle:= BadTurn;
     exit(BadTurn);
     end;
+
 t:= 2 / sqrt(sqr(Targ.X - x)+sqr(Targ.Y-y));
 Vx:= (Targ.X - x) * t;
 Vy:= (Targ.Y - y) * t;
@@ -650,7 +654,7 @@
     d: Longword;
     fallDmg, valueResult: LongInt;
 begin
-if Me^.Hedgehog^.BotLevel > 3 then exit(BadTurn);
+if Level > 3 then exit(BadTurn);
 dmgMod:= 0.01 * hwFloat2Float(cDamageModifier) * cDamagePercent;
 Level:= Level; // avoid compiler hint
 ap.ExplR:= 0;
@@ -700,9 +704,9 @@
     x, y, trackFall: LongInt;
     dx, dy: real;
 begin
-    if Me^.Hedgehog^.BotLevel < 3 then trackFall:= afTrackFall
+    if Level < 3 then trackFall:= afTrackFall
     else trackFall:= 0;
-    Level:= Level; // avoid compiler hint
+
     ap.ExplR:= 0;
     ap.Time:= 0;
     ap.Power:= 1;
@@ -749,9 +753,9 @@
 var valueResult, v1, v2, i: LongInt;
     x, y, trackFall: LongInt;
 begin
-    if Me^.Hedgehog^.BotLevel = 1 then trackFall:= afTrackFall
+    if Level = 1 then trackFall:= afTrackFall
     else trackFall:= 0;
-    Level:= Level; // avoid compiler hint
+
     ap.ExplR:= 0;
     ap.Time:= 0;
     ap.Power:= 1;
@@ -805,9 +809,9 @@
 var valueResult, v1, v2: LongInt;
     x, y, trackFall: LongInt;
 begin
-    if Me^.Hedgehog^.BotLevel = 1 then trackFall:= afTrackFall
+    if Level = 1 then trackFall:= afTrackFall
     else trackFall:= 0;
-    Level:= Level; // avoid compiler hint
+
     ap.ExplR:= 0;
     ap.Time:= 0;
     ap.Power:= 1;
@@ -854,6 +858,59 @@
     TestWhip:= valueResult;
 end;
 
+function TestKamikaze(Me: PGear; Targ: TPoint; Level: LongInt; var ap: TAttackParams): LongInt;
+const step = 8;
+var valueResult, i, v: LongInt;
+    trackFall: LongInt;
+    t, d, x, y, dx, dy, cx: real;
+begin
+    ap.ExplR:= 0;
+    ap.Time:= 0;
+    ap.Power:= 1;
+
+    if Level = 1 then 
+        trackFall:= afTrackFall
+    else if Level = 2 then
+        trackFall:= 0
+    else
+        exit(BadTurn);
+        
+    valueResult:= 0;
+
+    x:= hwFloat2Float(Me^.X);
+    y:= hwFloat2Float(Me^.Y);
+    
+    d:= sqrt(sqr(Targ.X - x) + sqr(Targ.Y - y));
+    t:= step / d;
+    dx:= (Targ.X - x) * t;
+    dy:= (Targ.Y - y) * t;
+
+    ap.Angle:= DxDy2AttackAnglef(dx, -dy);
+    
+    if dx >= 0 then cx:= 0.45 else cx:= -0.45;
+
+    for i:= 0 to 512 div step - 2 do
+        begin
+        valueResult:= valueResult + 
+            RateShove(Me, trunc(x), trunc(y)
+                , 30, 30, 25
+                , cx, -0.9, trackFall or afSetSkip);
+                
+        x:= x + dx;
+        y:= y + dy;
+        end;
+        
+    v:= RateShove(Me, trunc(x), trunc(y)
+            , 30, 30, 25
+            , cx, -0.9, trackFall);
+    valueResult:= valueResult + v - KillScore * friendlyfactor div 100 * 1024;
+    
+    if v < 65536 then
+        inc(valueResult, RateExplosion(Me, trunc(x), trunc(y), 30));
+
+    TestKamikaze:= valueResult;
+end;
+
 function TestHammer(Me: PGear; Targ: TPoint; Level: LongInt; var ap: TAttackParams): LongInt;
 var rate: LongInt;
 begin
--- a/hedgewars/uAIMisc.pas	Wed Aug 01 18:35:09 2012 -0400
+++ b/hedgewars/uAIMisc.pas	Fri Aug 03 16:58:49 2012 +0400
@@ -86,12 +86,13 @@
         ar: array[0..Pred(MAXBONUS div 8)] of TBonus;  // don't use too many
         end;
 
+const KillScore = 200;
+var friendlyfactor: LongInt = 300;
+       
 implementation
 uses uCollisions, uVariables, uUtils, uDebug, uLandTexture;
 
-const KillScore = 200;
-
-var friendlyfactor: LongInt = 300;
+var 
     KnownExplosion: record
         X, Y, Radius: LongInt
         end = (X: 0; Y: 0; Radius: 0);