hedgewars/uAIAmmoTests.pas
changeset 7471 ce5d3e39361e
parent 7441 5d64f59f2ca5
child 7474 bbecb1b4f59b
equal deleted inserted replaced
7468:1333ca7554dc 7471:ce5d3e39361e
    45 function TestDesertEagle(Me: PGear; Targ: TPoint; Level: LongInt; var ap: TAttackParams): LongInt;
    45 function TestDesertEagle(Me: PGear; Targ: TPoint; Level: LongInt; var ap: TAttackParams): LongInt;
    46 function TestSniperRifle(Me: PGear; Targ: TPoint; Level: LongInt; var ap: TAttackParams): LongInt;
    46 function TestSniperRifle(Me: PGear; Targ: TPoint; Level: LongInt; var ap: TAttackParams): LongInt;
    47 function TestBaseballBat(Me: PGear; Targ: TPoint; Level: LongInt; var ap: TAttackParams): LongInt;
    47 function TestBaseballBat(Me: PGear; Targ: TPoint; Level: LongInt; var ap: TAttackParams): LongInt;
    48 function TestFirePunch(Me: PGear; Targ: TPoint; Level: LongInt; var ap: TAttackParams): LongInt;
    48 function TestFirePunch(Me: PGear; Targ: TPoint; Level: LongInt; var ap: TAttackParams): LongInt;
    49 function TestWhip(Me: PGear; Targ: TPoint; Level: LongInt; var ap: TAttackParams): LongInt;
    49 function TestWhip(Me: PGear; Targ: TPoint; Level: LongInt; var ap: TAttackParams): LongInt;
       
    50 function TestKamikaze(Me: PGear; Targ: TPoint; Level: LongInt; var ap: TAttackParams): LongInt;
    50 function TestAirAttack(Me: PGear; Targ: TPoint; Level: LongInt; var ap: TAttackParams): LongInt;
    51 function TestAirAttack(Me: PGear; Targ: TPoint; Level: LongInt; var ap: TAttackParams): LongInt;
    51 function TestTeleport(Me: PGear; Targ: TPoint; Level: LongInt; var ap: TAttackParams): LongInt;
    52 function TestTeleport(Me: PGear; Targ: TPoint; Level: LongInt; var ap: TAttackParams): LongInt;
    52 function TestHammer(Me: PGear; Targ: TPoint; Level: LongInt; var ap: TAttackParams): LongInt;
    53 function TestHammer(Me: PGear; Targ: TPoint; Level: LongInt; var ap: TAttackParams): LongInt;
    53 function TestCake(Me: PGear; Targ: TPoint; Level: LongInt; var ap: TAttackParams): LongInt;
    54 function TestCake(Me: PGear; Targ: TPoint; Level: LongInt; var ap: TAttackParams): LongInt;
    54 
    55 
    82             (proc: nil;              flags: 0), // amGirder
    83             (proc: nil;              flags: 0), // amGirder
    83             (proc: nil;              flags: 0), // amTeleport
    84             (proc: nil;              flags: 0), // amTeleport
    84             //(proc: @TestTeleport;    flags: amtest_OnTurn), // amTeleport
    85             //(proc: @TestTeleport;    flags: amtest_OnTurn), // amTeleport
    85             (proc: nil;              flags: 0), // amSwitch
    86             (proc: nil;              flags: 0), // amSwitch
    86             (proc: @TestMortar;      flags: 0), // amMortar
    87             (proc: @TestMortar;      flags: 0), // amMortar
    87             (proc: nil;              flags: 0), // amKamikaze
    88             (proc: @TestKamikaze;    flags: 0), // amKamikaze
    88             (proc: @TestCake;        flags: amtest_OnTurn or amtest_NoTarget), // amCake
    89             (proc: @TestCake;        flags: amtest_OnTurn or amtest_NoTarget), // amCake
    89             (proc: nil;              flags: 0), // amSeduction
    90             (proc: nil;              flags: 0), // amSeduction
    90             (proc: @TestWatermelon;  flags: 0), // amWatermelon
    91             (proc: @TestWatermelon;  flags: 0), // amWatermelon
    91             (proc: nil;              flags: 0), // amHellishBomb
    92             (proc: nil;              flags: 0), // amHellishBomb
    92             (proc: nil;              flags: 0), // amNapalm
    93             (proc: nil;              flags: 0), // amNapalm
   165         until (((Me = CurrentHedgehog^.Gear) and TestColl(trunc(x), trunc(y), 5)) or 
   166         until (((Me = CurrentHedgehog^.Gear) and TestColl(trunc(x), trunc(y), 5)) or 
   166                ((Me <> CurrentHedgehog^.Gear) and TestCollExcludingMe(Me, trunc(x), trunc(y), 5))) or (t <= 0);
   167                ((Me <> CurrentHedgehog^.Gear) and TestCollExcludingMe(Me, trunc(x), trunc(y), 5))) or (t <= 0);
   167         
   168         
   168         EX:= trunc(x);
   169         EX:= trunc(x);
   169         EY:= trunc(y);
   170         EY:= trunc(y);
   170         if Me^.Hedgehog^.BotLevel = 1 then
   171         if Level = 1 then
   171             value:= RateExplosion(Me, EX, EY, 101, afTrackFall or afErasesLand)
   172             value:= RateExplosion(Me, EX, EY, 101, afTrackFall or afErasesLand)
   172         else value:= RateExplosion(Me, EX, EY, 101);
   173         else value:= RateExplosion(Me, EX, EY, 101);
   173         if value = 0 then
   174         if value = 0 then
   174             value:= - Metric(Targ.X, Targ.Y, EX, EY) div 64;
   175             value:= - Metric(Targ.X, Targ.Y, EX, EY) div 64;
   175         if valueResult <= value then
   176         if valueResult <= value then
   328         until (((Me = CurrentHedgehog^.Gear) and TestColl(trunc(x), trunc(y), 5)) or 
   329         until (((Me = CurrentHedgehog^.Gear) and TestColl(trunc(x), trunc(y), 5)) or 
   329                ((Me <> CurrentHedgehog^.Gear) and TestCollExcludingMe(Me, trunc(x), trunc(y), 5))) or (t = 0);
   330                ((Me <> CurrentHedgehog^.Gear) and TestCollExcludingMe(Me, trunc(x), trunc(y), 5))) or (t = 0);
   330     EX:= trunc(x);
   331     EX:= trunc(x);
   331     EY:= trunc(y);
   332     EY:= trunc(y);
   332     if t < 50 then 
   333     if t < 50 then 
   333         if Me^.Hedgehog^.BotLevel = 1 then
   334         if Level = 1 then
   334             Score:= RateExplosion(Me, EX, EY, 101, afTrackFall or afErasesLand)
   335             Score:= RateExplosion(Me, EX, EY, 101, afTrackFall or afErasesLand)
   335         else Score:= RateExplosion(Me, EX, EY, 101)
   336         else Score:= RateExplosion(Me, EX, EY, 101)
   336     else 
   337     else 
   337         Score:= BadTurn;
   338         Score:= BadTurn;
   338 
   339 
   598 function TestDesertEagle(Me: PGear; Targ: TPoint; Level: LongInt; var ap: TAttackParams): LongInt;
   599 function TestDesertEagle(Me: PGear; Targ: TPoint; Level: LongInt; var ap: TAttackParams): LongInt;
   599 var Vx, Vy, x, y, t, dmgMod: real;
   600 var Vx, Vy, x, y, t, dmgMod: real;
   600     d: Longword;
   601     d: Longword;
   601     fallDmg, valueResult: LongInt;
   602     fallDmg, valueResult: LongInt;
   602 begin
   603 begin
   603 if Me^.Hedgehog^.BotLevel > 3 then exit(BadTurn);
   604 if Level > 3 then exit(BadTurn);
   604 dmgMod:= 0.01 * hwFloat2Float(cDamageModifier) * cDamagePercent;
   605 dmgMod:= 0.01 * hwFloat2Float(cDamageModifier) * cDamagePercent;
   605 Level:= Level; // avoid compiler hint
   606 Level:= Level; // avoid compiler hint
   606 ap.ExplR:= 0;
   607 ap.ExplR:= 0;
   607 ap.Time:= 0;
   608 ap.Time:= 0;
   608 ap.Power:= 1;
   609 ap.Power:= 1;
       
   610 
   609 x:= hwFloat2Float(Me^.X);
   611 x:= hwFloat2Float(Me^.X);
   610 y:= hwFloat2Float(Me^.Y);
   612 y:= hwFloat2Float(Me^.Y);
       
   613 
   611 if Abs(trunc(x) - Targ.X) + Abs(trunc(y) - Targ.Y) < 40 then
   614 if Abs(trunc(x) - Targ.X) + Abs(trunc(y) - Targ.Y) < 40 then
   612     begin
   615     begin
   613     TestDesertEagle:= BadTurn;
   616     TestDesertEagle:= BadTurn;
   614     exit(BadTurn);
   617     exit(BadTurn);
   615     end;
   618     end;
       
   619 
   616 t:= 2 / sqrt(sqr(Targ.X - x)+sqr(Targ.Y-y));
   620 t:= 2 / sqrt(sqr(Targ.X - x)+sqr(Targ.Y-y));
   617 Vx:= (Targ.X - x) * t;
   621 Vx:= (Targ.X - x) * t;
   618 Vy:= (Targ.Y - y) * t;
   622 Vy:= (Targ.Y - y) * t;
   619 ap.Angle:= DxDy2AttackAnglef(Vx, -Vy);
   623 ap.Angle:= DxDy2AttackAnglef(Vx, -Vy);
   620 d:= 0;
   624 d:= 0;
   648 function TestSniperRifle(Me: PGear; Targ: TPoint; Level: LongInt; var ap: TAttackParams): LongInt;
   652 function TestSniperRifle(Me: PGear; Targ: TPoint; Level: LongInt; var ap: TAttackParams): LongInt;
   649 var Vx, Vy, x, y, t, dmg, dmgMod: real;
   653 var Vx, Vy, x, y, t, dmg, dmgMod: real;
   650     d: Longword;
   654     d: Longword;
   651     fallDmg, valueResult: LongInt;
   655     fallDmg, valueResult: LongInt;
   652 begin
   656 begin
   653 if Me^.Hedgehog^.BotLevel > 3 then exit(BadTurn);
   657 if Level > 3 then exit(BadTurn);
   654 dmgMod:= 0.01 * hwFloat2Float(cDamageModifier) * cDamagePercent;
   658 dmgMod:= 0.01 * hwFloat2Float(cDamageModifier) * cDamagePercent;
   655 Level:= Level; // avoid compiler hint
   659 Level:= Level; // avoid compiler hint
   656 ap.ExplR:= 0;
   660 ap.ExplR:= 0;
   657 ap.Time:= 0;
   661 ap.Time:= 0;
   658 ap.Power:= 1;
   662 ap.Power:= 1;
   698 function TestBaseballBat(Me: PGear; Targ: TPoint; Level: LongInt; var ap: TAttackParams): LongInt;
   702 function TestBaseballBat(Me: PGear; Targ: TPoint; Level: LongInt; var ap: TAttackParams): LongInt;
   699 var valueResult, a, v1, v2: LongInt;
   703 var valueResult, a, v1, v2: LongInt;
   700     x, y, trackFall: LongInt;
   704     x, y, trackFall: LongInt;
   701     dx, dy: real;
   705     dx, dy: real;
   702 begin
   706 begin
   703     if Me^.Hedgehog^.BotLevel < 3 then trackFall:= afTrackFall
   707     if Level < 3 then trackFall:= afTrackFall
   704     else trackFall:= 0;
   708     else trackFall:= 0;
   705     Level:= Level; // avoid compiler hint
   709 
   706     ap.ExplR:= 0;
   710     ap.ExplR:= 0;
   707     ap.Time:= 0;
   711     ap.Time:= 0;
   708     ap.Power:= 1;
   712     ap.Power:= 1;
   709     x:= hwRound(Me^.X);
   713     x:= hwRound(Me^.X);
   710     y:= hwRound(Me^.Y);
   714     y:= hwRound(Me^.Y);
   747 
   751 
   748 function TestFirePunch(Me: PGear; Targ: TPoint; Level: LongInt; var ap: TAttackParams): LongInt;
   752 function TestFirePunch(Me: PGear; Targ: TPoint; Level: LongInt; var ap: TAttackParams): LongInt;
   749 var valueResult, v1, v2, i: LongInt;
   753 var valueResult, v1, v2, i: LongInt;
   750     x, y, trackFall: LongInt;
   754     x, y, trackFall: LongInt;
   751 begin
   755 begin
   752     if Me^.Hedgehog^.BotLevel = 1 then trackFall:= afTrackFall
   756     if Level = 1 then trackFall:= afTrackFall
   753     else trackFall:= 0;
   757     else trackFall:= 0;
   754     Level:= Level; // avoid compiler hint
   758 
   755     ap.ExplR:= 0;
   759     ap.ExplR:= 0;
   756     ap.Time:= 0;
   760     ap.Time:= 0;
   757     ap.Power:= 1;
   761     ap.Power:= 1;
   758     x:= hwRound(Me^.X);
   762     x:= hwRound(Me^.X);
   759     y:= hwRound(Me^.Y) + 4;
   763     y:= hwRound(Me^.Y) + 4;
   803 
   807 
   804 function TestWhip(Me: PGear; Targ: TPoint; Level: LongInt; var ap: TAttackParams): LongInt;
   808 function TestWhip(Me: PGear; Targ: TPoint; Level: LongInt; var ap: TAttackParams): LongInt;
   805 var valueResult, v1, v2: LongInt;
   809 var valueResult, v1, v2: LongInt;
   806     x, y, trackFall: LongInt;
   810     x, y, trackFall: LongInt;
   807 begin
   811 begin
   808     if Me^.Hedgehog^.BotLevel = 1 then trackFall:= afTrackFall
   812     if Level = 1 then trackFall:= afTrackFall
   809     else trackFall:= 0;
   813     else trackFall:= 0;
   810     Level:= Level; // avoid compiler hint
   814 
   811     ap.ExplR:= 0;
   815     ap.ExplR:= 0;
   812     ap.Time:= 0;
   816     ap.Time:= 0;
   813     ap.Power:= 1;
   817     ap.Power:= 1;
   814     x:= hwRound(Me^.X);
   818     x:= hwRound(Me^.X);
   815     y:= hwRound(Me^.Y);
   819     y:= hwRound(Me^.Y);
   852         inc(valueResult);
   856         inc(valueResult);
   853 
   857 
   854     TestWhip:= valueResult;
   858     TestWhip:= valueResult;
   855 end;
   859 end;
   856 
   860 
       
   861 function TestKamikaze(Me: PGear; Targ: TPoint; Level: LongInt; var ap: TAttackParams): LongInt;
       
   862 const step = 8;
       
   863 var valueResult, i, v: LongInt;
       
   864     trackFall: LongInt;
       
   865     t, d, x, y, dx, dy, cx: real;
       
   866 begin
       
   867     ap.ExplR:= 0;
       
   868     ap.Time:= 0;
       
   869     ap.Power:= 1;
       
   870 
       
   871     if Level = 1 then 
       
   872         trackFall:= afTrackFall
       
   873     else if Level = 2 then
       
   874         trackFall:= 0
       
   875     else
       
   876         exit(BadTurn);
       
   877         
       
   878     valueResult:= 0;
       
   879 
       
   880     x:= hwFloat2Float(Me^.X);
       
   881     y:= hwFloat2Float(Me^.Y);
       
   882     
       
   883     d:= sqrt(sqr(Targ.X - x) + sqr(Targ.Y - y));
       
   884     t:= step / d;
       
   885     dx:= (Targ.X - x) * t;
       
   886     dy:= (Targ.Y - y) * t;
       
   887 
       
   888     ap.Angle:= DxDy2AttackAnglef(dx, -dy);
       
   889     
       
   890     if dx >= 0 then cx:= 0.45 else cx:= -0.45;
       
   891 
       
   892     for i:= 0 to 512 div step - 2 do
       
   893         begin
       
   894         valueResult:= valueResult + 
       
   895             RateShove(Me, trunc(x), trunc(y)
       
   896                 , 30, 30, 25
       
   897                 , cx, -0.9, trackFall or afSetSkip);
       
   898                 
       
   899         x:= x + dx;
       
   900         y:= y + dy;
       
   901         end;
       
   902         
       
   903     v:= RateShove(Me, trunc(x), trunc(y)
       
   904             , 30, 30, 25
       
   905             , cx, -0.9, trackFall);
       
   906     valueResult:= valueResult + v - KillScore * friendlyfactor div 100 * 1024;
       
   907     
       
   908     if v < 65536 then
       
   909         inc(valueResult, RateExplosion(Me, trunc(x), trunc(y), 30));
       
   910 
       
   911     TestKamikaze:= valueResult;
       
   912 end;
       
   913 
   857 function TestHammer(Me: PGear; Targ: TPoint; Level: LongInt; var ap: TAttackParams): LongInt;
   914 function TestHammer(Me: PGear; Targ: TPoint; Level: LongInt; var ap: TAttackParams): LongInt;
   858 var rate: LongInt;
   915 var rate: LongInt;
   859 begin
   916 begin
   860 Level:= Level; // avoid compiler hint
   917 Level:= Level; // avoid compiler hint
   861 ap.ExplR:= 0;
   918 ap.ExplR:= 0;