Tiny optimization
authorunc0rr
Mon, 03 Feb 2014 13:32:09 +0400
changeset 10097 acef073e190f
parent 10096 51d6b80ba43c
child 10098 f00dee04b5d7
Tiny optimization
hedgewars/uAIAmmoTests.pas
--- a/hedgewars/uAIAmmoTests.pas	Sat Feb 01 22:03:22 2014 -0500
+++ b/hedgewars/uAIAmmoTests.pas	Mon Feb 03 13:32:09 2014 +0400
@@ -684,7 +684,7 @@
 function TestDesertEagle(Me: PGear; Targ: TTarget; Level: LongInt; var ap: TAttackParams): LongInt;
 var Vx, Vy, x, y, t: real;
     d: Longword;
-    {fallDmg, }valueResult: LongInt;
+    ix, iy, valueResult: LongInt;
 begin
 if (Level > 4) or (Targ.Score < 0) or (Targ.Kind <> gtHedgehog) then exit(BadTurn);
 Level:= Level; // avoid compiler hint
@@ -704,20 +704,25 @@
 ap.Angle:= DxDy2AttackAnglef(Vx, -Vy);
 d:= 0;
 
-repeat
-    x:= x + vX;
-    y:= y + vY;
-    if ((trunc(x) and LAND_WIDTH_MASK) = 0)and((trunc(y) and LAND_HEIGHT_MASK) = 0)
-    and (Land[trunc(y), trunc(x)] <> 0) then
-        inc(d);
-until (Abs(Targ.Point.X - trunc(x)) + Abs(Targ.Point.Y - trunc(y)) < 5)
-    or (x < 0)
-    or (y < 0)
-    or (trunc(x) > LAND_WIDTH)
-    or (trunc(y) > LAND_HEIGHT)
-    or (d > 48);
+ix:= trunc(x);
+iy:= trunc(y);
 
-if Abs(Targ.Point.X - trunc(x)) + Abs(Targ.Point.Y - trunc(y)) < 5 then
+if ((ix and LAND_WIDTH_MASK) = 0) and ((iy and LAND_HEIGHT_MASK) = 0) then
+    repeat
+        if Land[iy, ix] <> 0 then
+            inc(d);
+        x:= x + vX;
+        y:= y + vY;
+        ix:= trunc(x);
+        iy:= trunc(y);
+    until (Abs(Targ.Point.X - ix) + Abs(Targ.Point.Y - iy) < 5)
+        or (x < 0)
+        or (y < 0)
+        or (ix >= LAND_WIDTH)
+        or (iy >= LAND_HEIGHT)
+        or (d > 48);
+
+if Abs(Targ.Point.X - ix) + Abs(Targ.Point.Y - iy) < 5 then
     begin
     ap.AttacksNum:= 1 + (d + 8) div 12;
     valueResult:= RateShove(Me, Targ.Point.X, Targ.Point.Y, 1, 7, 20, vX*0.125, vY*0.125, afTrackFall) - ap.AttacksNum