# HG changeset patch # User nemo # Date 1257976468 0 # Node ID 6e2b341dc4081f58e29e1f371e43ed3971d20a28 # Parent b86abe0687083b0a90a4fc7d4bc01aa0660b5db4 AI fire w/o moving for artillery. Needs testing, but seems to work quickly and w/o AI screwups. diff -r b86abe068708 -r 6e2b341dc408 hedgewars/uAIAmmoTests.pas --- a/hedgewars/uAIAmmoTests.pas Wed Nov 11 19:48:16 2009 +0000 +++ b/hedgewars/uAIAmmoTests.pas Wed Nov 11 21:54:28 2009 +0000 @@ -120,7 +120,7 @@ dX:= dX + cWindSpeed; dY:= dY + cGravity; dec(t) - until TestColl(hwRound(x), hwRound(y), 5) or (t <= 0); + until TestCollExcludingMe(Me, hwRound(x), hwRound(y), 5) or (t <= 0); EX:= hwRound(x); EY:= hwRound(y); Result:= RateExplosion(Me, EX, EY, 101); @@ -174,7 +174,7 @@ y:= y + dY; dY:= dY + cGravity; dec(t) - until TestColl(hwRound(x), hwRound(y), 5) or (t = 0); + until TestCollExcludingMe(Me, hwRound(x), hwRound(y), 5) or (t = 0); EX:= hwRound(x); EY:= hwRound(y); if t < 50 then CheckTrace:= RateExplosion(Me, EX, EY, 101) @@ -228,7 +228,7 @@ dY:= dY + cGravity; EX:= hwRound(x); EY:= hwRound(y); - until TestColl(EX, EY, 5) or (EY > 1000); + until TestCollExcludingMe(Me, EX, EY, 5) or (EY > 1000); if (EY < 1000) and not dY.isNegative then begin @@ -315,7 +315,7 @@ y:= y + vY; rx:= hwRound(x); ry:= hwRound(y); - if TestColl(rx, ry, 2) then + if TestCollExcludingMe(Me, rx, ry, 2) then begin x:= x + vX * 8; y:= y + vY * 8; diff -r b86abe068708 -r 6e2b341dc408 hedgewars/uAIMisc.pas --- a/hedgewars/uAIMisc.pas Wed Nov 11 19:48:16 2009 +0000 +++ b/hedgewars/uAIMisc.pas Wed Nov 11 21:54:28 2009 +0000 @@ -41,6 +41,7 @@ procedure FillBonuses(isAfterAttack: boolean); procedure AwareOfExplosion(x, y, r: LongInt); function RatePlace(Gear: PGear): LongInt; +function TestCollExcludingMe(Me: PGear; x, y, r: LongInt): boolean; function TestColl(x, y, r: LongInt): boolean; function RateExplosion(Me: PGear; x, y, r: LongInt): LongInt; function RateShove(Me: PGear; x, y, r, power: LongInt): LongInt; @@ -174,6 +175,22 @@ RatePlace:= Result end; +// Wrapper to test various approaches. If it works reasonably, will just replace. +// Right now, converting to hwFloat is a tad inefficient since the x/y were hwFloat to begin with... +function TestCollExcludingMe(Me: PGear; x, y, r: LongInt): boolean; +var MeX, MeY: LongInt; +begin + if ((x and LAND_WIDTH_MASK) = 0) and ((y and LAND_HEIGHT_MASK) = 0) then + begin + MeX:= hwRound(Me^.X); + MeY:= hwRound(Me^.Y); + // We are still inside the hog. Skip radius test + if ((((x-MeX)*(x-MeX)) + ((y-MeY)*(y-MeY))) < 256) and + ((Land[y, x] and $FF00) = 0) then exit(false); + end; + exit(TestColl(x, y, r)) +end; + function TestColl(x, y, r: LongInt): boolean; var b: boolean; begin