hedgewars/uAIAmmoTests.pas
changeset 7154 56e329edf4b8
parent 7134 beb16926ae5c
child 7161 21a9c70b2070
equal deleted inserted replaced
7151:ec15d9e1a7e3 7154:56e329edf4b8
   657     inc(valueResult);
   657     inc(valueResult);
   658 TestBaseballBat:= valueResult;
   658 TestBaseballBat:= valueResult;
   659 end;
   659 end;
   660 
   660 
   661 function TestFirePunch(Me: PGear; Targ: TPoint; Level: LongInt; var ap: TAttackParams): LongInt;
   661 function TestFirePunch(Me: PGear; Targ: TPoint; Level: LongInt; var ap: TAttackParams): LongInt;
   662 var val1: LongInt;
   662 var val1, val2, i, t: LongInt;
   663     x, y: real;
   663     x, y: real;
   664 begin
   664 begin
   665 Level:= Level; // avoid compiler hint
   665 Level:= Level; // avoid compiler hint
   666 TestFirePunch:= BadTurn;
   666 TestFirePunch:= BadTurn;
   667 ap.ExplR:= 0;
   667 ap.ExplR:= 0;
   668 ap.Time:= 0;
   668 ap.Time:= 0;
   669 ap.Power:= 1;
   669 ap.Power:= 1;
   670 ap.Angle:= hwSign(Me^.dX);
   670 ap.Angle:= hwSign(Me^.dX);
   671 x:= hwFloat2Float(Me^.X);
   671 x:= hwFloat2Float(Me^.X);
   672 y:= hwFloat2Float(Me^.Y);
   672 y:= hwFloat2Float(Me^.Y);
   673 if (Abs(trunc(x) - Targ.X) < 25)
   673 {
   674     and (Abs(trunc(y) - 50 - Targ.Y) < 50) then
   674 // this block is for digging with firepunch when blocked close to walls (notice TestColl check)
   675     begin
   675 if (Abs(trunc(x) - Targ.X) > 25)
   676 // TODO - find out WTH this works.
   676     or (Abs(trunc(y) + 50 - Targ.Y) > 50) then
       
   677     begin
   677     if TestColl(trunc(x), trunc(y) - 16, 6) and 
   678     if TestColl(trunc(x), trunc(y) - 16, 6) and 
   678        (RateShove(Me, trunc(x) + LongWord(10 * hwSign(Me^.dX)), 
   679        (RateShove(Me, trunc(x) + LongWord(10 * hwSign(Me^.dX)), 
   679                       trunc(y) - 40, 30, 30, 40, hwSign(Me^.dX)*0.45, -0.9,  1) = 0) then
   680                       trunc(y) - 40, 30, 30, 40, hwSign(Me^.dX)*0.45, -0.9,  1) >= 0) then
   680         val1:= Succ(BadTurn)
   681         val1:= Succ(BadTurn)
   681     else
   682     else
   682         val1:= BadTurn;
   683         val1:= BadTurn;
   683     exit(val1);
   684     exit(val1);
   684     end;
   685     end;
   685 (*
   686     }
   686 For some silly reason, having this enabled w/ the AI 
   687 // and this is actual try to attack
   687 val1:= 0;
   688 val1:= 0;
   688 for i:= 0 to 4 do
   689 for i:= 0 to 4 do
   689     begin
   690     begin
   690     t:= RateShove(Me, trunc(x) + 10 * hwSign(Targ.X - x), trunc(y) - 20 * i - 5, 10, 30, 40, hwSign(Me^.dX)*0.45, -0.9, 1);
   691     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, 1);
   691     if (val1 < 0) or (t < 0) then val1:= BadTurn
   692     if (val1 < 0) or (t < 0) then val1:= BadTurn
   692     else if t > 0 then val1:= t;
   693     else if t > 0 then val1:= t;
   693     end;
   694     end;
   694 
   695 
   695 val2:= 0;
   696 val2:= 0;
   696 for i:= 0 to 4 do
   697 for i:= 0 to 4 do
   697     begin
   698     begin
   698     t:= RateShove(Me, trunc(x) + 10 * hwSign(Targ.X - x), trunc(y) - 20 * i - 5, 10, 30, 40, -hwSign(Me^.dX)*0.45, -0.9, 1);
   699     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, 1);
   699     if (val2 < 0) or (t < 0) then val2:= BadTurn
   700     if (val2 < 0) or (t < 0) then val2:= BadTurn
   700     else if t > 0 then val2:= t;
   701     else if t > 0 then val2:= t;
   701     end;
   702     end;
   702 if (val1 > val2) and (val1 > 0) then 
   703 if (val1 > val2) and (val1 > 0) then 
   703     TestFirePunch:= val1
   704     TestFirePunch:= val1
   704 else if (val2 > val1) and (val2 > 0) then
   705 else if (val2 > val1) and (val2 > 0) then
   705     begin
   706     begin
   706     ap.Angle:= -hwSign(Me^.dX);
   707     ap.Angle:= -hwSign(Me^.dX);
   707     TestFirePunch:= val2
   708     TestFirePunch:= val2
   708     end
   709     end
   709 else TestFirePunch:= BadTurn;*)
   710 else TestFirePunch:= BadTurn;
   710 end;
   711 end;
   711 
   712 
       
   713 // TODO: TestWhip, TestFirepunch and TestBaseballBat could be called only once at each position 
       
   714 // (now they're called for each possible target in each position)
   712 function TestWhip(Me: PGear; Targ: TPoint; Level: LongInt; var ap: TAttackParams): LongInt;
   715 function TestWhip(Me: PGear; Targ: TPoint; Level: LongInt; var ap: TAttackParams): LongInt;
   713 var i, valueResult: LongInt;
   716 var valueResult, v1, v2: LongInt;
   714     x, y: real;
   717     x, y: real;
   715 begin
   718 begin
   716 Level:= Level; // avoid compiler hint
   719 Level:= Level; // avoid compiler hint
   717 ap.ExplR:= 0;
   720 ap.ExplR:= 0;
   718 ap.Time:= 0;
   721 ap.Time:= 0;
   719 ap.Power:= 1;
   722 ap.Power:= 1;
   720 ap.Angle:= 0;
       
   721 x:= hwFloat2Float(Me^.X);
   723 x:= hwFloat2Float(Me^.X);
   722 y:= hwFloat2Float(Me^.Y);
   724 y:= hwFloat2Float(Me^.Y);
   723 if (Abs(trunc(x) - Targ.X) > 25)
   725 
   724 or (Abs(trunc(y) - 50 - Targ.Y) > 50) then
   726 if(abs(Targ.X - x) > 50) or (abs(Targ.Y - y) > 30) then // we're way too far from our target
   725     begin
   727     exit(BadTurn);
   726     if TestColl(trunc(x), trunc(y) - 16, 6)
   728     
   727     and (RateShove(Me, trunc(x) + LongWord(10 * hwSign(Me^.dX)), trunc(y) - 40, 30, 30, 40, hwSign(Me^.dX), -0.8,  1) = 0) then
   729 // check left direction
   728         valueResult:= Succ(BadTurn)
   730 {first RateShove checks fartherest of two whip's AmmoShove attacks 
   729     else
   731 to encourage distant attacks (damaged hog is excluded from view of second 
   730         valueResult:= BadTurn;
   732 RateShove call)}
   731     exit(valueResult);
   733 v1:= RateShove(Me, trunc(x) - 15, trunc(y)
       
   734         , 30, 30, 40
       
   735         , -1, -0.8, 1 or fSetSkip);
       
   736 v1:= v1 +
       
   737     RateShove(Me, trunc(x), trunc(y)
       
   738         , 30, 30, 40
       
   739         , -1, -0.8, 1);
       
   740 // now try opposite direction
       
   741 v2:= RateShove(Me, trunc(x) + 15, trunc(y)
       
   742         , 30, 30, 40
       
   743         , 1, -0.8, 1 or fSetSkip);
       
   744 v2:= v2 +
       
   745     RateShove(Me, trunc(x), trunc(y)
       
   746         , 30, 30, 40
       
   747         , 1, -0.8, 1);
       
   748 
       
   749 if (v2 > v1) 
       
   750     or {don't encourage turning for no gain}((v2 = v1) and (not Me^.dX.isNegative)) then
       
   751     begin
       
   752     ap.Angle:= 1;
       
   753     valueResult:= v2
       
   754     end
       
   755 else 
       
   756     begin
       
   757     ap.Angle:= -1;
       
   758     valueResult:= v1
   732     end;
   759     end;
   733 
   760    
   734 valueResult:= 0;
       
   735 for i:= 0 to 4 do
       
   736     valueResult:= valueResult + RateShove(Me, trunc(x) + LongWord(10 * hwSignf(Targ.X - x)),
       
   737                                     trunc(y) - LongWord(20 * i) - 5, 10, 30, 40, hwSign(Me^.dX), -0.8, 1);
       
   738 if valueResult <= 0 then
   761 if valueResult <= 0 then
   739     valueResult:= BadTurn
   762     valueResult:= BadTurn
   740 else
   763 else
   741     inc(valueResult);
   764     inc(valueResult);
   742 
   765