# HG changeset patch # User mbait # Date 1272404992 0 # Node ID da73f471798fafc9cd48a12e6bf28e2fa75602f7 # Parent 37f4f83fedb190df3289348ae11085af66a23c46 Teleport AI: * collision test while choosing teleport target diff -r 37f4f83fedb1 -r da73f471798f hedgewars/uAIAmmoTests.pas --- a/hedgewars/uAIAmmoTests.pas Tue Apr 27 12:51:29 2010 +0000 +++ b/hedgewars/uAIAmmoTests.pas Tue Apr 27 21:49:52 2010 +0000 @@ -639,16 +639,24 @@ function TestTeleport(Me: PGear; Targ: TPoint; Level: LongInt; var ap: TAttackParams): LongInt; var - i: longword; + i, failNum: longword; begin FillBonuses(true, [gtCase]); if bonuses.Count = 0 then TestTeleport := BadTurn else begin - i := random(bonuses.Count); - ap.AttackPutX := bonuses.ar[i].X; - ap.AttackPutY := bonuses.ar[i].Y - 50; - TestTeleport := 0; + failNum := 0; + repeat + i := random(bonuses.Count); + inc(failNum); + until(not TestColl(bonuses.ar[i].X, bonuses.ar[i].Y - cHHRadius - bonuses.ar[i].Radius, cHHRadius) or (failNum = bonuses.Count*2)); + if failNum < bonuses.Count*2 then begin + ap.AttackPutX := bonuses.ar[i].X; + ap.AttackPutY := bonuses.ar[i].Y - cHHRadius - bonuses.ar[i].Radius; + TestTeleport := 0; + end + else + TestTeleport := BadTurn; end; end;