hedgewars/uAIAmmoTests.pas
changeset 7416 2f2f78fc65a3
parent 7398 2b7b939014b5
child 7424 fe0f07667f24
equal deleted inserted replaced
7414:a9f18c66ce34 7416:2f2f78fc65a3
    83             (proc: nil;              flags: 0), // amTeleport
    83             (proc: nil;              flags: 0), // amTeleport
    84             //(proc: @TestTeleport;    flags: amtest_OnTurn), // amTeleport
    84             //(proc: @TestTeleport;    flags: amtest_OnTurn), // amTeleport
    85             (proc: nil;              flags: 0), // amSwitch
    85             (proc: nil;              flags: 0), // amSwitch
    86             (proc: @TestMortar;      flags: 0), // amMortar
    86             (proc: @TestMortar;      flags: 0), // amMortar
    87             (proc: nil;              flags: 0), // amKamikaze
    87             (proc: nil;              flags: 0), // amKamikaze
    88             (proc: @TestCake;        flags: 0), // amCake
    88             (proc: @TestCake;        flags: amtest_OnTurn or amtest_NoTarget), // amCake
    89             (proc: nil;              flags: 0), // amSeduction
    89             (proc: nil;              flags: 0), // amSeduction
    90             (proc: @TestWatermelon;  flags: 0), // amWatermelon
    90             (proc: @TestWatermelon;  flags: 0), // amWatermelon
    91             (proc: nil;              flags: 0), // amHellishBomb
    91             (proc: nil;              flags: 0), // amHellishBomb
    92             (proc: nil;              flags: 0), // amNapalm
    92             (proc: nil;              flags: 0), // amNapalm
    93             (proc: nil;              flags: 0), // amDrill
    93             (proc: nil;              flags: 0), // amDrill
   120             );
   120             );
   121 
   121 
   122 const BadTurn = Low(LongInt) div 4;
   122 const BadTurn = Low(LongInt) div 4;
   123 
   123 
   124 implementation
   124 implementation
   125 uses uAIMisc, uVariables, uUtils;
   125 uses uAIMisc, uVariables, uUtils, uGearsHandlers, uCollisions;
   126 
   126 
   127 function Metric(x1, y1, x2, y2: LongInt): LongInt; inline;
   127 function Metric(x1, y1, x2, y2: LongInt): LongInt; inline;
   128 begin
   128 begin
   129 Metric:= abs(x1 - x2) + abs(y1 - y2)
   129 Metric:= abs(x1 - x2) + abs(y1 - y2)
   130 end;
   130 end;
   981             end;
   981             end;
   982         end;
   982         end;
   983 end;
   983 end;
   984 
   984 
   985 
   985 
   986 function checkCakeWalk(Gear: PGear): LongInt;
   986 procedure checkCakeWalk(Me, Gear: PGear; var ap: TAttackParams);
   987 begin
   987 var i: Longword;
   988 checkCakeWalk:= BadTurn
   988     v: LongInt;
       
   989 begin
       
   990 while (not TestColl(hwRound(Gear^.X), hwRound(Gear^.Y), 6)) and (Gear^.Y.Round < LAND_HEIGHT) do
       
   991     Gear^.Y:= Gear^.Y + _1;
       
   992 
       
   993 for i:= 0 to 2040 do
       
   994     begin
       
   995     cakeStep(Gear);
       
   996     v:= RateExplosion(Me, hwRound(Gear^.X), hwRound(Gear^.Y), cakeDmg * 2, afTrackFall);
       
   997     if v > ap.Power then 
       
   998         begin
       
   999         ap.ExplX:= hwRound(Gear^.X);
       
  1000         ap.ExplY:= hwRound(Gear^.Y);
       
  1001         ap.Power:= v
       
  1002         end
       
  1003     end;
   989 end;
  1004 end;
   990 
  1005 
   991 function TestCake(Me: PGear; Targ: TPoint; Level: LongInt; var ap: TAttackParams): LongInt;
  1006 function TestCake(Me: PGear; Targ: TPoint; Level: LongInt; var ap: TAttackParams): LongInt;
   992 var valueResult, v1, v2: LongInt;
  1007 var valueResult, v1, v2: LongInt;
   993     x, y, trackFall: LongInt;
  1008     x, y, trackFall: LongInt;
   994     cake: TGear;
  1009     cake: TGear;
   995 begin
  1010 begin
   996     Level:= Level; // avoid compiler hint
  1011     Level:= Level; // avoid compiler hint
   997     ap.ExplR:= 0;
  1012     ap.ExplR:= 0;
   998     ap.Time:= 0;
  1013     ap.Time:= 0;
   999     ap.Power:= 1;
  1014     ap.Power:= BadTurn; // use it as max score value in checkCakeWalk
  1000 
  1015 
       
  1016     FillChar(cake, sizeof(cake), 0);
  1001     cake.Radius:= 7;
  1017     cake.Radius:= 7;
       
  1018     cake.CollisionMask:= $FF7F;
  1002 
  1019 
  1003     // check left direction
  1020     // check left direction
  1004     cake.Angle:= 3;
  1021     cake.Angle:= 3;
  1005     cake.dX.isNegative:= true;
  1022     cake.dX.isNegative:= true;
  1006     cake.X:= Me^.X - _3;
  1023     cake.X:= Me^.X - _3;
  1007     cake.Y:= Me^.Y;
  1024     cake.Y:= Me^.Y;
  1008     v1:= checkCakeWalk(@cake);
  1025     checkCakeWalk(Me, @cake, ap);
       
  1026     v1:= ap.Power;
  1009 
  1027 
  1010     // now try opposite direction
  1028     // now try opposite direction
  1011     cake.Angle:= 1;
  1029     cake.Angle:= 1;
  1012     cake.dX.isNegative:= false;
  1030     cake.dX.isNegative:= false;
  1013     cake.X:= Me^.X + _3;
  1031     cake.X:= Me^.X + _3;
  1014     cake.Y:= Me^.Y;
  1032     cake.Y:= Me^.Y;
  1015     v2:= checkCakeWalk(@cake);
  1033     checkCakeWalk(Me, @cake, ap);
       
  1034     v2:= ap.Power;
       
  1035 
       
  1036     ap.Power:= 1;
  1016 
  1037 
  1017     if (v2 > v1) then
  1038     if (v2 > v1) then
  1018         begin
  1039         begin
  1019         ap.Angle:= 1;
  1040         ap.Angle:= 1;
  1020         valueResult:= v2
  1041         valueResult:= v2