hedgewars/uAIAmmoTests.pas
changeset 7041 76a9274f280f
parent 7007 0ccdff4ae8e9
child 7078 a3408d9ba5ad
equal deleted inserted replaced
7040:4aff2da0d0b3 7041:76a9274f280f
   477 var Vx, Vy: real;
   477 var Vx, Vy: real;
   478     Score, EX, EY: LongInt;
   478     Score, EX, EY: LongInt;
   479     TestTime: Longword;
   479     TestTime: Longword;
   480     x, y, dY, meX, meY: real;
   480     x, y, dY, meX, meY: real;
   481 begin
   481 begin
   482 TestMortar:= BadTurn;
   482     TestMortar:= BadTurn;
   483 ap.ExplR:= 0;
   483     ap.ExplR:= 0;
   484 meX:= hwFloat2Float(Me^.X);
   484     meX:= hwFloat2Float(Me^.X);
   485 meY:= hwFloat2Float(Me^.Y);
   485     meY:= hwFloat2Float(Me^.Y);
   486 
   486 
   487 if (Level > 2) then
   487     if (Level > 2) then
   488     exit;
   488         exit(BadTurn);
   489 
   489 
   490 TestTime:= Solve(Targ.X, Targ.Y, trunc(meX), trunc(meY));
   490     TestTime:= Solve(Targ.X, Targ.Y, trunc(meX), trunc(meY));
   491 
   491 
   492 if TestTime = 0 then
   492     if TestTime = 0 then
   493     exit;
   493         exit(BadTurn);
   494 
   494 
   495     Vx:= (Targ.X - meX) / TestTime;
   495     Vx:= (Targ.X - meX) / TestTime;
   496     Vy:= cGravityf * (TestTime div 2) - (Targ.Y - meY) / TestTime;
   496     Vy:= cGravityf * (TestTime div 2) - (Targ.Y - meY) / TestTime;
   497 
   497 
   498     x:= meX;
   498     x:= meX;
   546 ap.Power:= 1;
   546 ap.Power:= 1;
   547 x:= hwFloat2Float(Me^.X);
   547 x:= hwFloat2Float(Me^.X);
   548 y:= hwFloat2Float(Me^.Y);
   548 y:= hwFloat2Float(Me^.Y);
   549 range:= Metric(trunc(x), trunc(y), Targ.X, Targ.Y);
   549 range:= Metric(trunc(x), trunc(y), Targ.X, Targ.Y);
   550 if ( range < MIN_RANGE ) or ( range > MAX_RANGE ) then
   550 if ( range < MIN_RANGE ) or ( range > MAX_RANGE ) then
   551     exit;
   551     exit(BadTurn);
       
   552 
   552 Vx:= (Targ.X - x) * 1 / 1024;
   553 Vx:= (Targ.X - x) * 1 / 1024;
   553 Vy:= (Targ.Y - y) * 1 / 1024;
   554 Vy:= (Targ.Y - y) * 1 / 1024;
   554 ap.Angle:= DxDy2AttackAnglef(Vx, -Vy);
   555 ap.Angle:= DxDy2AttackAnglef(Vx, -Vy);
   555 repeat
   556 repeat
   556     x:= x + vX;
   557     x:= x + vX;
   566         if valueResult = 0 then 
   567         if valueResult = 0 then 
   567             valueResult:= - Metric(Targ.X, Targ.Y, rx, ry) div 64
   568             valueResult:= - Metric(Targ.X, Targ.Y, rx, ry) div 64
   568         else 
   569         else 
   569             dec(valueResult, Level * 4000);
   570             dec(valueResult, Level * 4000);
   570         // 27/20 is reuse bonus
   571         // 27/20 is reuse bonus
   571         TestShotgun:= valueResult * 27 div 20;
   572         exit(valueResult * 27 div 20)
   572         exit 
       
   573     end
   573     end
   574 until (Abs(Targ.X - trunc(x)) + Abs(Targ.Y - trunc(y)) < 4)
   574 until (Abs(Targ.X - trunc(x)) + Abs(Targ.Y - trunc(y)) < 4)
   575     or (x < 0)
   575     or (x < 0)
   576     or (y < 0)
   576     or (y < 0)
   577     or (trunc(x) > LAND_WIDTH)
   577     or (trunc(x) > LAND_WIDTH)
   591 ap.Time:= 0;
   591 ap.Time:= 0;
   592 ap.Power:= 1;
   592 ap.Power:= 1;
   593 x:= hwFloat2Float(Me^.X);
   593 x:= hwFloat2Float(Me^.X);
   594 y:= hwFloat2Float(Me^.Y);
   594 y:= hwFloat2Float(Me^.Y);
   595 if Abs(trunc(x) - Targ.X) + Abs(trunc(y) - Targ.Y) < 40 then
   595 if Abs(trunc(x) - Targ.X) + Abs(trunc(y) - Targ.Y) < 40 then
   596 begin
   596     begin
   597     TestDesertEagle:= BadTurn;
   597     TestDesertEagle:= BadTurn;
   598     exit;
   598     exit(BadTurn);
   599 end;
   599     end;
   600 t:= 0.5 / sqrt(sqr(Targ.X - x)+sqr(Targ.Y-y));
   600 t:= 0.5 / sqrt(sqr(Targ.X - x)+sqr(Targ.Y-y));
   601 Vx:= (Targ.X - x) * t;
   601 Vx:= (Targ.X - x) * t;
   602 Vy:= (Targ.Y - y) * t;
   602 Vy:= (Targ.Y - y) * t;
   603 ap.Angle:= DxDy2AttackAnglef(Vx, -Vy);
   603 ap.Angle:= DxDy2AttackAnglef(Vx, -Vy);
   604 d:= 0;
   604 d:= 0;
   636 TestBaseballBat:= BadTurn;
   636 TestBaseballBat:= BadTurn;
   637 ap.ExplR:= 0;
   637 ap.ExplR:= 0;
   638 x:= hwFloat2Float(Me^.X);
   638 x:= hwFloat2Float(Me^.X);
   639 y:= hwFloat2Float(Me^.Y);
   639 y:= hwFloat2Float(Me^.Y);
   640 if (Level > 2) or (Abs(trunc(x) - Targ.X) + Abs(trunc(y) - Targ.Y) > 25) then
   640 if (Level > 2) or (Abs(trunc(x) - Targ.X) + Abs(trunc(y) - Targ.Y) > 25) then
   641     exit;
   641     exit(BadTurn);
   642 
   642 
   643 ap.Time:= 0;
   643 ap.Time:= 0;
   644 ap.Power:= 1;
   644 ap.Power:= 1;
   645 if (Targ.X) - trunc(x) >= 0 then
   645 if (Targ.X) - trunc(x) >= 0 then
   646     ap.Angle:=   cMaxAngle div 4
   646     ap.Angle:=   cMaxAngle div 4
   674        (RateShove(Me, trunc(x) + LongWord(10 * hwSign(Me^.dX)), 
   674        (RateShove(Me, trunc(x) + LongWord(10 * hwSign(Me^.dX)), 
   675                       trunc(y) - 40, 30, 30, 40, hwSign(Me^.dX)*0.45, -0.9,  1) = 0) then
   675                       trunc(y) - 40, 30, 30, 40, hwSign(Me^.dX)*0.45, -0.9,  1) = 0) then
   676         val1:= Succ(BadTurn)
   676         val1:= Succ(BadTurn)
   677     else
   677     else
   678         val1:= BadTurn;
   678         val1:= BadTurn;
   679     TestFirePunch:= val1;
   679     exit(val1);
   680     exit;
       
   681     end;
   680     end;
   682 (*
   681 (*
   683 For some silly reason, having this enabled w/ the AI 
   682 For some silly reason, having this enabled w/ the AI 
   684 val1:= 0;
   683 val1:= 0;
   685 for i:= 0 to 4 do
   684 for i:= 0 to 4 do
   723     if TestColl(trunc(x), trunc(y) - 16, 6)
   722     if TestColl(trunc(x), trunc(y) - 16, 6)
   724     and (RateShove(Me, trunc(x) + LongWord(10 * hwSign(Me^.dX)), trunc(y) - 40, 30, 30, 40, hwSign(Me^.dX), -0.8,  1) = 0) then
   723     and (RateShove(Me, trunc(x) + LongWord(10 * hwSign(Me^.dX)), trunc(y) - 40, 30, 30, 40, hwSign(Me^.dX), -0.8,  1) = 0) then
   725         valueResult:= Succ(BadTurn)
   724         valueResult:= Succ(BadTurn)
   726     else
   725     else
   727         valueResult:= BadTurn;
   726         valueResult:= BadTurn;
   728     TestWhip:= valueResult;
   727     exit(valueResult);
   729     exit;
       
   730     end;
   728     end;
   731 
   729 
   732 valueResult:= 0;
   730 valueResult:= 0;
   733 for i:= 0 to 4 do
   731 for i:= 0 to 4 do
   734     valueResult:= valueResult + RateShove(Me, trunc(x) + LongWord(10 * hwSignf(Targ.X - x)),
   732     valueResult:= valueResult + RateShove(Me, trunc(x) + LongWord(10 * hwSignf(Targ.X - x)),
   768     i, t, valueResult: LongInt;
   766     i, t, valueResult: LongInt;
   769 begin
   767 begin
   770 ap.ExplR:= 0;
   768 ap.ExplR:= 0;
   771 ap.Time:= 0;
   769 ap.Time:= 0;
   772 if (Level > 3) then
   770 if (Level > 3) then
   773 begin
   771     exit(BadTurn);
   774     TestAirAttack:= BadTurn;
       
   775     exit;
       
   776 end;
       
   777 
   772 
   778 ap.AttackPutX:= Targ.X;
   773 ap.AttackPutX:= Targ.X;
   779 ap.AttackPutY:= Targ.Y;
   774 ap.AttackPutY:= Targ.Y;
   780 
   775 
   781 bombsSpeed:= hwFloat2Float(cBombsSpeed);
   776 bombsSpeed:= hwFloat2Float(cBombsSpeed);
   835 var
   830 var
   836     i, failNum: longword;
   831     i, failNum: longword;
   837     maxTop: longword;
   832     maxTop: longword;
   838 begin
   833 begin
   839     TestTeleport := BadTurn;
   834     TestTeleport := BadTurn;
   840     exit;
   835     exit(BadTurn);
   841     Level:= Level; // avoid compiler hint
   836     Level:= Level; // avoid compiler hint
   842     //FillBonuses(true, [gtCase]);
   837     //FillBonuses(true, [gtCase]);
   843     if bonuses.Count = 0 then
   838     if bonuses.Count = 0 then
   844         begin
   839         begin
   845         if Me^.Health <= 100  then
   840         if Me^.Health <= 100  then