hedgewars/uAIAmmoTests.pas
changeset 7200 744c8a5546c6
parent 7197 5a9775b97c7e
child 7204 522f165cd2e7
equal deleted inserted replaced
7199:f329fbf1ffb4 7200:744c8a5546c6
   710     inc(valueResult);
   710     inc(valueResult);
   711 TestBaseballBat:= valueResult;
   711 TestBaseballBat:= valueResult;
   712 end;
   712 end;
   713 
   713 
   714 function TestFirePunch(Me: PGear; Targ: TPoint; Level: LongInt; var ap: TAttackParams): LongInt;
   714 function TestFirePunch(Me: PGear; Targ: TPoint; Level: LongInt; var ap: TAttackParams): LongInt;
   715 var val1, val2, i, t: LongInt;
   715 var valueResult, v1, v2, i: LongInt;
   716     x, y: real;
   716     x, y: LongInt;
   717 begin
   717 begin
   718 Level:= Level; // avoid compiler hint
   718     Level:= Level; // avoid compiler hint
   719 TestFirePunch:= BadTurn;
   719     ap.ExplR:= 0;
   720 ap.ExplR:= 0;
   720     ap.Time:= 0;
   721 ap.Time:= 0;
   721     ap.Power:= 1;
   722 ap.Power:= 1;
   722     x:= hwRound(Me^.X);
   723 ap.Angle:= hwSign(Me^.dX);
   723     y:= hwRound(Me^.Y);
   724 x:= hwFloat2Float(Me^.X);
   724 
   725 y:= hwFloat2Float(Me^.Y);
   725     v1:= 0;
   726 {
   726     for i:= 0 to 8 do
   727 // this block is for digging with firepunch when blocked close to walls (notice TestColl check)
   727         begin
   728 if (Abs(trunc(x) - Targ.X) > 25)
   728         v1:= v1 + RateShove(Me, x - 10, y - 10 * i
   729     or (Abs(trunc(y) + 50 - Targ.Y) > 50) then
   729                 , 15, 30, 40
   730     begin
   730                 , -0.45, -0.9, afTrackFall or afSetSkip);
   731     if TestColl(trunc(x), trunc(y) - 16, 6) and 
   731         end;
   732        (RateShove(Me, trunc(x) + LongWord(10 * hwSign(Me^.dX)), 
   732     v1:= v1 + RateShove(Me, x - 10, y - 90
   733                       trunc(y) - 40, 30, 30, 40, hwSign(Me^.dX)*0.45, -0.9,  1) >= 0) then
   733             , 15, 30, 40
   734         val1:= Succ(BadTurn)
   734             , -0.45, -0.9, afTrackFall);
   735     else
   735 
   736         val1:= BadTurn;
   736 
   737     exit(val1);
   737     // now try opposite direction
   738     end;
   738     v2:= 0;
   739     }
   739     for i:= 0 to 8 do
   740 // and this is actual try to attack
   740         begin
   741 val1:= 0;
   741         v2:= v2 + RateShove(Me, x + 10, y - 10 * i
   742 for i:= 0 to 4 do
   742                 , 15, 30, 40
   743     begin
   743                 , 0.45, -0.9, afTrackFall or afSetSkip);
   744     t:= RateShove(Me, trunc(x) + 10 * hwSignf(Targ.X - x), trunc(y) - 20 * i - 5, 10, 30, 40, hwSign(Me^.dX)*0.45, -0.9, afTrackFall);
   744         end;
   745     if (val1 < 0) or (t < 0) then val1:= BadTurn
   745     v2:= v2 + RateShove(Me, x + 10, y - 90
   746     else if t > 0 then val1:= t;
   746             , 15, 30, 40
   747     end;
   747             , 0.45, -0.9, afTrackFall);
   748 
   748 
   749 val2:= 0;
   749     if (v2 > v1) 
   750 for i:= 0 to 4 do
   750         or {don't encourage turning for no gain}((v2 = v1) and (not Me^.dX.isNegative)) then
   751     begin
   751         begin
   752     t:= RateShove(Me, trunc(x) + 10 * hwSignf(Targ.X - x), trunc(y) - 20 * i - 5, 10, 30, 40, -hwSign(Me^.dX)*0.45, -0.9, afTrackFall);
   752         ap.Angle:= 1;
   753     if (val2 < 0) or (t < 0) then val2:= BadTurn
   753         valueResult:= v2
   754     else if t > 0 then val2:= t;
   754         end
   755     end;
   755     else 
   756 if (val1 > val2) and (val1 > 0) then 
   756         begin
   757     TestFirePunch:= val1
   757         ap.Angle:= -1;
   758 else if (val2 > val1) and (val2 > 0) then
   758         valueResult:= v1
   759     begin
   759         end;
   760     ap.Angle:= -hwSign(Me^.dX);
   760     
   761     TestFirePunch:= val2
   761     if valueResult <= 0 then
   762     end
   762         valueResult:= BadTurn;
   763 else TestFirePunch:= BadTurn;
   763 
       
   764     TestFirePunch:= valueResult;
   764 end;
   765 end;
   765 
   766 
   766 
   767 
   767 function TestWhip(Me: PGear; Targ: TPoint; Level: LongInt; var ap: TAttackParams): LongInt;
   768 function TestWhip(Me: PGear; Targ: TPoint; Level: LongInt; var ap: TAttackParams): LongInt;
   768 var valueResult, v1, v2: LongInt;
   769 var valueResult, v1, v2: LongInt;
   769     x, y: real;
   770     x, y: LongInt;
   770 begin
   771 begin
   771 Level:= Level; // avoid compiler hint
   772     Level:= Level; // avoid compiler hint
   772 ap.ExplR:= 0;
   773     ap.ExplR:= 0;
   773 ap.Time:= 0;
   774     ap.Time:= 0;
   774 ap.Power:= 1;
   775     ap.Power:= 1;
   775 x:= hwFloat2Float(Me^.X);
   776     x:= hwRound(Me^.X);
   776 y:= hwFloat2Float(Me^.Y);
   777     y:= hwRound(Me^.Y);
   777 
   778 
   778 // check left direction
   779     // check left direction
   779 {first RateShove checks fartherest of two whip's AmmoShove attacks 
   780     {first RateShove checks farthermost of two whip's AmmoShove attacks 
   780 to encourage distant attacks (damaged hog is excluded from view of second 
   781     to encourage distant attacks (damaged hog is excluded from view of second 
   781 RateShove call)}
   782     RateShove call)}
   782 v1:= RateShove(Me, trunc(x) - 15, trunc(y)
   783     v1:= RateShove(Me, x - 15, y
   783         , 30, 30, 40
   784             , 30, 30, 40
   784         , -1, -0.8, afTrackFall or afSetSkip);
   785             , -1, -0.8, afTrackFall or afSetSkip);
   785 v1:= v1 +
   786     v1:= v1 +
   786     RateShove(Me, trunc(x), trunc(y)
   787         RateShove(Me, x, y
   787         , 30, 30, 40
   788             , 30, 30, 40
   788         , -1, -0.8, afTrackFall);
   789             , -1, -0.8, afTrackFall);
   789 // now try opposite direction
   790     // now try opposite direction
   790 v2:= RateShove(Me, trunc(x) + 15, trunc(y)
   791     v2:= RateShove(Me, x + 15, y
   791         , 30, 30, 40
   792             , 30, 30, 40
   792         , 1, -0.8, afTrackFall or afSetSkip);
   793             , 1, -0.8, afTrackFall or afSetSkip);
   793 v2:= v2 +
   794     v2:= v2 +
   794     RateShove(Me, trunc(x), trunc(y)
   795         RateShove(Me, x, y
   795         , 30, 30, 40
   796             , 30, 30, 40
   796         , 1, -0.8, afTrackFall);
   797             , 1, -0.8, afTrackFall);
   797 
   798 
   798 if (v2 > v1) 
   799     if (v2 > v1) 
   799     or {don't encourage turning for no gain}((v2 = v1) and (not Me^.dX.isNegative)) then
   800         or {don't encourage turning for no gain}((v2 = v1) and (not Me^.dX.isNegative)) then
   800     begin
   801         begin
   801     ap.Angle:= 1;
   802         ap.Angle:= 1;
   802     valueResult:= v2
   803         valueResult:= v2
   803     end
   804         end
   804 else 
   805     else 
   805     begin
   806         begin
   806     ap.Angle:= -1;
   807         ap.Angle:= -1;
   807     valueResult:= v1
   808         valueResult:= v1
   808     end;
   809         end;
   809    
   810     
   810 if valueResult <= 0 then
   811     if valueResult <= 0 then
   811     valueResult:= BadTurn
   812         valueResult:= BadTurn
   812 else
   813     else
   813     inc(valueResult);
   814         inc(valueResult);
   814 
   815 
   815 TestWhip:= valueResult;
   816     TestWhip:= valueResult;
   816 end;
   817 end;
   817 
   818 
   818 function TestHammer(Me: PGear; Targ: TPoint; Level: LongInt; var ap: TAttackParams): LongInt;
   819 function TestHammer(Me: PGear; Targ: TPoint; Level: LongInt; var ap: TAttackParams): LongInt;
   819 var rate: LongInt;
   820 var rate: LongInt;
   820 begin
   821 begin