hedgewars/uAIAmmoTests.pas
changeset 7197 5a9775b97c7e
parent 7178 c61cfc9eb29d
child 7200 744c8a5546c6
equal deleted inserted replaced
7195:9e6e8e5a4c2e 7197:5a9775b97c7e
    41 function TestClusterBomb(Me: PGear; Targ: TPoint; Level: LongInt; var ap: TAttackParams): LongInt;
    41 function TestClusterBomb(Me: PGear; Targ: TPoint; Level: LongInt; var ap: TAttackParams): LongInt;
    42 function TestWatermelon(Me: PGear; Targ: TPoint; Level: LongInt; var ap: TAttackParams): LongInt;
    42 function TestWatermelon(Me: PGear; Targ: TPoint; Level: LongInt; var ap: TAttackParams): LongInt;
    43 function TestMortar(Me: PGear; Targ: TPoint; Level: LongInt; var ap: TAttackParams): LongInt;
    43 function TestMortar(Me: PGear; Targ: TPoint; Level: LongInt; var ap: TAttackParams): LongInt;
    44 function TestShotgun(Me: PGear; Targ: TPoint; Level: LongInt; var ap: TAttackParams): LongInt;
    44 function TestShotgun(Me: PGear; Targ: TPoint; Level: LongInt; var ap: TAttackParams): LongInt;
    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 TestBaseballBat(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 TestFirePunch(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 TestWhip(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 TestAirAttack(Me: PGear; Targ: TPoint; Level: LongInt; var ap: TAttackParams): LongInt;
    50 function TestAirAttack(Me: PGear; Targ: TPoint; Level: LongInt; var ap: TAttackParams): LongInt;
    50 function TestTeleport(Me: PGear; Targ: TPoint; Level: LongInt; var ap: TAttackParams): LongInt;
    51 function TestTeleport(Me: PGear; Targ: TPoint; Level: LongInt; var ap: TAttackParams): LongInt;
    95             (proc: nil;              flags: 0), // amExtraDamage
    96             (proc: nil;              flags: 0), // amExtraDamage
    96             (proc: nil;              flags: 0), // amInvulnerable
    97             (proc: nil;              flags: 0), // amInvulnerable
    97             (proc: nil;              flags: 0), // amExtraTime
    98             (proc: nil;              flags: 0), // amExtraTime
    98             (proc: nil;              flags: 0), // amLaserSight
    99             (proc: nil;              flags: 0), // amLaserSight
    99             (proc: nil;              flags: 0), // amVampiric
   100             (proc: nil;              flags: 0), // amVampiric
   100             (proc: nil;              flags: 0), // amSniperRifle
   101             (proc: @TestSniperRifle; flags: 0), // amSniperRifle
   101             (proc: nil;              flags: 0), // amJetpack
   102             (proc: nil;              flags: 0), // amJetpack
   102             (proc: @TestMolotov;     flags: 0), // amMolotov
   103             (proc: @TestMolotov;     flags: 0), // amMolotov
   103             (proc: nil;              flags: 0), // amBirdy
   104             (proc: nil;              flags: 0), // amBirdy
   104             (proc: nil;              flags: 0), // amPortalGun
   105             (proc: nil;              flags: 0), // amPortalGun
   105             (proc: nil;              flags: 0), // amPiano
   106             (proc: nil;              flags: 0), // amPiano
   600 if Abs(trunc(x) - Targ.X) + Abs(trunc(y) - Targ.Y) < 40 then
   601 if Abs(trunc(x) - Targ.X) + Abs(trunc(y) - Targ.Y) < 40 then
   601     begin
   602     begin
   602     TestDesertEagle:= BadTurn;
   603     TestDesertEagle:= BadTurn;
   603     exit(BadTurn);
   604     exit(BadTurn);
   604     end;
   605     end;
   605 t:= 0.5 / sqrt(sqr(Targ.X - x)+sqr(Targ.Y-y));
   606 t:= 2 / sqrt(sqr(Targ.X - x)+sqr(Targ.Y-y));
       
   607 Vx:= (Targ.X - x) * t;
       
   608 Vy:= (Targ.Y - y) * t;
       
   609 ap.Angle:= DxDy2AttackAnglef(Vx, -Vy);
       
   610 d:= 0;
       
   611 
       
   612 repeat
       
   613     x:= x + vX;
       
   614     y:= y + vY;
       
   615     if ((trunc(x) and LAND_WIDTH_MASK) = 0)and((trunc(y) and LAND_HEIGHT_MASK) = 0)
       
   616     and (Land[trunc(y), trunc(x)] <> 0) then
       
   617         inc(d);
       
   618 until (Abs(Targ.X - trunc(x)) + Abs(Targ.Y - trunc(y)) < 5)
       
   619     or (x < 0)
       
   620     or (y < 0)
       
   621     or (trunc(x) > LAND_WIDTH)
       
   622     or (trunc(y) > LAND_HEIGHT)
       
   623     or (d > 50);
       
   624 
       
   625 if Abs(Targ.X - trunc(x)) + Abs(Targ.Y - trunc(y)) < 5 then
       
   626     begin
       
   627     fallDmg:= TraceShoveFall(Me, Targ.X, Targ.Y, vX * 0.00125 * 20, vY * 0.00125 * 20);
       
   628     if fallDmg < 0 then
       
   629         valueResult:= 204800
       
   630     else valueResult:= Max(0, (4 - d div 50) * trunc((7+fallDmg)*dmgMod) * 1024)
       
   631     end
       
   632 else
       
   633     valueResult:= BadTurn;
       
   634 TestDesertEagle:= valueResult
       
   635 end;
       
   636 
       
   637 
       
   638 function TestSniperRifle(Me: PGear; Targ: TPoint; Level: LongInt; var ap: TAttackParams): LongInt;
       
   639 var Vx, Vy, x, y, t, dmg, dmgMod: real;
       
   640     d: Longword;
       
   641     fallDmg, valueResult: LongInt;
       
   642 begin
       
   643 dmgMod:= 0.01 * hwFloat2Float(cDamageModifier) * cDamagePercent;
       
   644 Level:= Level; // avoid compiler hint
       
   645 ap.ExplR:= 0;
       
   646 ap.Time:= 0;
       
   647 ap.Power:= 1;
       
   648 x:= hwFloat2Float(Me^.X);
       
   649 y:= hwFloat2Float(Me^.Y);
       
   650 if Abs(trunc(x) - Targ.X) + Abs(trunc(y) - Targ.Y) < 40 then
       
   651     exit(BadTurn);
       
   652 
       
   653 dmg:= sqrt(sqr(Targ.X - x)+sqr(Targ.Y-y));
       
   654 t:= 1.5 / dmg;
       
   655 dmg:= dmg * 0.33333333;
   606 Vx:= (Targ.X - x) * t;
   656 Vx:= (Targ.X - x) * t;
   607 Vy:= (Targ.Y - y) * t;
   657 Vy:= (Targ.Y - y) * t;
   608 ap.Angle:= DxDy2AttackAnglef(Vx, -Vy);
   658 ap.Angle:= DxDy2AttackAnglef(Vx, -Vy);
   609 d:= 0;
   659 d:= 0;
   610 
   660 
   617 until (Abs(Targ.X - trunc(x)) + Abs(Targ.Y - trunc(y)) < 4)
   667 until (Abs(Targ.X - trunc(x)) + Abs(Targ.Y - trunc(y)) < 4)
   618     or (x < 0)
   668     or (x < 0)
   619     or (y < 0)
   669     or (y < 0)
   620     or (trunc(x) > LAND_WIDTH)
   670     or (trunc(x) > LAND_WIDTH)
   621     or (trunc(y) > LAND_HEIGHT)
   671     or (trunc(y) > LAND_HEIGHT)
   622     or (d > 200);
   672     or (d > 23);
   623 
   673 
   624 if Abs(Targ.X - trunc(x)) + Abs(Targ.Y - trunc(y)) < 3 then
   674 if Abs(Targ.X - trunc(x)) + Abs(Targ.Y - trunc(y)) < 4 then
   625     begin
   675     begin
   626     fallDmg:= TraceShoveFall(Me, Targ.X, Targ.Y, vX * 0.005 * 20, vY * 0.005 * 20);
   676     fallDmg:= TraceShoveFall(Me, Targ.X, Targ.Y, vX * 0.00166 * dmg, vY * 0.00166 * dmg);
   627     if fallDmg < 0 then
   677     if fallDmg < 0 then
   628         valueResult:= 204800
   678         TestSniperRifle:= BadTurn
   629     else valueResult:= Max(0, (4 - d div 50) * trunc((7+fallDmg)*dmgMod) * 1024)
   679     else 
       
   680         TestSniperRifle:= Max(0, trunc((dmg + fallDmg) * dmgMod) * 1024)
   630     end
   681     end
   631 else
   682 else
   632     valueResult:= BadTurn;
   683     TestSniperRifle:= BadTurn
   633 TestDesertEagle:= valueResult
   684 end;
   634 end;
   685 
   635 
   686 
   636 function TestBaseballBat(Me: PGear; Targ: TPoint; Level: LongInt; var ap: TAttackParams): LongInt;
   687 function TestBaseballBat(Me: PGear; Targ: TPoint; Level: LongInt; var ap: TAttackParams): LongInt;
   637 var valueResult: LongInt;
   688 var valueResult: LongInt;
   638     x, y: real;
   689     x, y: real;
   639 begin
   690 begin