hedgewars/uAIAmmoTests.pas
changeset 3433 566788d32e52
parent 3407 dcc129c4352e
child 3438 670324167e42
equal deleted inserted replaced
3432:83cef0f08a86 3433:566788d32e52
   643 
   643 
   644 
   644 
   645 function TestTeleport(Me: PGear; Targ: TPoint; Level: LongInt; var ap: TAttackParams): LongInt;
   645 function TestTeleport(Me: PGear; Targ: TPoint; Level: LongInt; var ap: TAttackParams): LongInt;
   646 var
   646 var
   647   i, failNum: longword;
   647   i, failNum: longword;
   648 begin
   648   maxTop: longword;
       
   649 begin
       
   650   TestTeleport := BadTurn;
   649   Level:= Level; // avoid compiler hint
   651   Level:= Level; // avoid compiler hint
   650   FillBonuses(true, [gtCase]);
   652   FillBonuses(true, [gtCase]);
   651   if bonuses.Count = 0 then begin
   653   if bonuses.Count = 0 then begin
   652     if Me^.Health <= 100  then begin
   654     if Me^.Health <= 100  then begin
   653       ap.AttackPutX := Targ.X;
   655 	  maxTop := Targ.Y - cHHRadius * 2; 
   654       ap.AttackPutY := topY + cHHRadius*2;
   656 	  while(not TestColl(Targ.X, maxTop, cHHRadius) and (maxTop > topY)) do
   655       TestTeleport := Targ.Y - topY;
   657 	  	dec(maxTop, cHHRadius*2);
       
   658 	  if(not TestColl(Targ.X, maxTop + cHHRadius, cHHRadius)) then begin
       
   659         ap.AttackPutX := Targ.X;
       
   660         ap.AttackPutY := maxTop + cHHRadius;
       
   661         TestTeleport := Targ.Y - maxTop;
       
   662 	  end;
   656     end
   663     end
   657     else
       
   658       TestTeleport := BadTurn;
       
   659   end
   664   end
   660   else begin
   665   else begin
   661 	failNum := 0;
   666 	failNum := 0;
   662     repeat 
   667     repeat 
   663 		i := random(bonuses.Count);
   668 		i := random(bonuses.Count);
   666 	if failNum < bonuses.Count*2 then begin
   671 	if failNum < bonuses.Count*2 then begin
   667 	  ap.AttackPutX := bonuses.ar[i].X;
   672 	  ap.AttackPutX := bonuses.ar[i].X;
   668 	  ap.AttackPutY := bonuses.ar[i].Y - cHHRadius - bonuses.ar[i].Radius;
   673 	  ap.AttackPutY := bonuses.ar[i].Y - cHHRadius - bonuses.ar[i].Radius;
   669 	  TestTeleport := 0;
   674 	  TestTeleport := 0;
   670 	end
   675 	end
   671     else
       
   672 	  TestTeleport := BadTurn;
       
   673   end;
   676   end;
   674 end;
   677 end;
   675 
   678 
   676 end.
   679 end.