hedgewars/uAIAmmoTests.pas
changeset 7212 ab60dbe8fd0c
parent 7210 2ff30b79d2b0
child 7274 a07777b818f1
equal deleted inserted replaced
7210:2ff30b79d2b0 7212:ab60dbe8fd0c
   683     TestSniperRifle:= BadTurn
   683     TestSniperRifle:= BadTurn
   684 end;
   684 end;
   685 
   685 
   686 
   686 
   687 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;
   688 var valueResult: LongInt;
   688 var valueResult, a, v1, v2: LongInt;
   689     x, y: real;
   689     x, y: LongInt;
   690 begin
   690     dx, dy: real;
   691 Level:= Level; // avoid compiler hint
   691 begin
   692 TestBaseballBat:= BadTurn;
   692     Level:= Level; // avoid compiler hint
   693 ap.ExplR:= 0;
   693     ap.ExplR:= 0;
   694 x:= hwFloat2Float(Me^.X);
   694     ap.Time:= 0;
   695 y:= hwFloat2Float(Me^.Y);
   695     ap.Power:= 1;
   696 if (Level > 2) then
   696     x:= hwRound(Me^.X);
   697     exit(BadTurn);
   697     y:= hwRound(Me^.Y);
   698 
   698 
   699 ap.Time:= 0;
   699     a:= 0;
   700 ap.Power:= 1;
   700     valueResult:= 0;
   701 if (Targ.X) - trunc(x) >= 0 then
   701 
   702     ap.Angle:=   cMaxAngle div 4
   702     while a <= cMaxAngle div 2 do
   703 else
   703         begin
   704     ap.Angle:= - cMaxAngle div 4;
   704         dx:= sin(a / cMaxAngle * pi) * 0.5;
   705 
   705         dy:= cos(a / cMaxAngle * pi) * 0.5;
   706 valueResult:= RateShove(Me, trunc(x) + LongWord(10*hwSignf(Targ.X - x)), trunc(y), 15, 30, 115, hwSign(Me^.dX)*0.353, -0.353, afTrackFall);
   706 
   707 if valueResult <= 0 then
   707         v1:= RateShove(Me, x - 10, y
   708     valueResult:= BadTurn
   708                 , 33, 30, 115
   709 else
   709                 , -dx, -dy, afTrackFall);
   710     inc(valueResult);
   710         v2:= RateShove(Me, x + 10, y
   711 TestBaseballBat:= valueResult;
   711                 , 33, 30, 115
       
   712                 , dx, -dy, afTrackFall);
       
   713         if (v1 > valueResult) or (v2 > valueResult) then
       
   714             if (v2 > v1) 
       
   715                 or {don't encourage turning for no gain}((v2 = v1) and (not Me^.dX.isNegative)) then
       
   716                 begin
       
   717                 ap.Angle:= a;
       
   718                 valueResult:= v2
       
   719                 end
       
   720             else 
       
   721                 begin
       
   722                 ap.Angle:= -a;
       
   723                 valueResult:= v1
       
   724                 end;
       
   725 
       
   726         a:= a + 15 + random(cMaxAngle div 16)
       
   727         end;
       
   728    
       
   729     if valueResult <= 0 then
       
   730         valueResult:= BadTurn;
       
   731 
       
   732     TestBaseballBat:= valueResult;
   712 end;
   733 end;
   713 
   734 
   714 function TestFirePunch(Me: PGear; Targ: TPoint; Level: LongInt; var ap: TAttackParams): LongInt;
   735 function TestFirePunch(Me: PGear; Targ: TPoint; Level: LongInt; var ap: TAttackParams): LongInt;
   715 var valueResult, v1, v2, i: LongInt;
   736 var valueResult, v1, v2, i: LongInt;
   716     x, y: LongInt;
   737     x, y: LongInt;