# HG changeset patch # User mbait # Date 1273145605 0 # Node ID 566788d32e52df7d76513db8fca212fc8eb8e826 # Parent 83cef0f08a869ce1e89ebf990507d9521a969476 Teleport AI: * calculate max height from target and check collision diff -r 83cef0f08a86 -r 566788d32e52 hedgewars/uAIAmmoTests.pas --- a/hedgewars/uAIAmmoTests.pas Thu May 06 09:25:13 2010 +0000 +++ b/hedgewars/uAIAmmoTests.pas Thu May 06 11:33:25 2010 +0000 @@ -645,17 +645,22 @@ function TestTeleport(Me: PGear; Targ: TPoint; Level: LongInt; var ap: TAttackParams): LongInt; var i, failNum: longword; + maxTop: longword; begin + TestTeleport := BadTurn; Level:= Level; // avoid compiler hint FillBonuses(true, [gtCase]); if bonuses.Count = 0 then begin if Me^.Health <= 100 then begin - ap.AttackPutX := Targ.X; - ap.AttackPutY := topY + cHHRadius*2; - TestTeleport := Targ.Y - topY; + maxTop := Targ.Y - cHHRadius * 2; + while(not TestColl(Targ.X, maxTop, cHHRadius) and (maxTop > topY)) do + dec(maxTop, cHHRadius*2); + if(not TestColl(Targ.X, maxTop + cHHRadius, cHHRadius)) then begin + ap.AttackPutX := Targ.X; + ap.AttackPutY := maxTop + cHHRadius; + TestTeleport := Targ.Y - maxTop; + end; end - else - TestTeleport := BadTurn; end else begin failNum := 0; @@ -668,8 +673,6 @@ ap.AttackPutY := bonuses.ar[i].Y - cHHRadius - bonuses.ar[i].Radius; TestTeleport := 0; end - else - TestTeleport := BadTurn; end; end;