Quick and simple dynamite AI without precalculated retreat and without accurate dynamite physics model (no bounce). Still does pretty well, using it mostly off cliffs.
authorunc0rr
Fri, 29 Nov 2013 15:53:46 +0400
changeset 9722 22dba2d8de93
parent 9721 1833dadcebf0
child 9723 31d10d684e90
Quick and simple dynamite AI without precalculated retreat and without accurate dynamite physics model (no bounce). Still does pretty well, using it mostly off cliffs.
hedgewars/uAIAmmoTests.pas
--- a/hedgewars/uAIAmmoTests.pas	Thu Nov 28 21:13:49 2013 -0500
+++ b/hedgewars/uAIAmmoTests.pas	Fri Nov 29 15:53:46 2013 +0400
@@ -54,6 +54,7 @@
 function TestTeleport(Me: PGear; Targ: TTarget; Level: LongInt; var ap: TAttackParams): LongInt;
 function TestHammer(Me: PGear; Targ: TTarget; Level: LongInt; var ap: TAttackParams): LongInt;
 function TestCake(Me: PGear; Targ: TTarget; Level: LongInt; var ap: TAttackParams): LongInt;
+function TestDynamite(Me: PGear; Targ: TTarget; Level: LongInt; var ap: TAttackParams): LongInt;
 
 type TAmmoTestProc = function (Me: PGear; Targ: TTarget; Level: LongInt; var ap: TAttackParams): LongInt;
     TAmmoTest = record
@@ -74,7 +75,7 @@
             (proc: nil;              flags: 0), // amRope
             (proc: nil;              flags: 0), // amMine
             (proc: @TestDesertEagle; flags: amtest_MultipleAttacks), // amDEagle
-            (proc: nil;              flags: 0), // amDynamite
+            (proc: @TestDynamite;    flags: amtest_NoTarget), // amDynamite
             (proc: @TestFirePunch;   flags: amtest_NoTarget), // amFirePunch
             (proc: @TestWhip;        flags: amtest_NoTarget), // amWhip
             (proc: @TestBaseballBat; flags: amtest_NoTarget), // amBaseballBat
@@ -1222,4 +1223,46 @@
     TestCake:= valueResult;
 end;
 
+function TestDynamite(Me: PGear; Targ: TTarget; Level: LongInt; var ap: TAttackParams): LongInt;
+var valueResult: LongInt;
+    x, y, dx, dy: real;
+    EX, EY, t: LongInt;
+begin
+x:= hwFloat2Float(Me^.X) + hwSign(Me^.dX) * 7;
+y:= hwFloat2Float(Me^.Y);
+dx:= hwSign(Me^.dX) * 0.03;
+dy:= 0;
+t:= 5000;
+repeat
+    dec(t);
+    x:= x + dx;
+    dy:= dy + cGravityf;
+    y:= y + dy;
+    
+    if TestColl(trunc(x), trunc(y), 3) then
+        t:= 0;
+until t = 0;
+
+EX:= trunc(x);
+EY:= trunc(y);
+
+if Level = 1 then
+    valueResult:= RateExplosion(Me, EX, EY, 76, afTrackFall or afErasesLand)
+else 
+    valueResult:= RateExplosion(Me, EX, EY, 76);
+
+if (valueResult > 0) then
+    begin
+    ap.Angle:= 0;
+    ap.Power:= 1;
+    ap.Time:= 0;
+    ap.ExplR:= 150;
+    ap.ExplX:= EX;
+    ap.ExplY:= EY
+    end else
+    valueResult:= BadTurn;
+
+TestDynamite:= valueResult
+end;
+
 end.