Minor optimisation for AI to cut down on hwSqrt calls
authornemo
Sun, 11 Mar 2012 12:19:04 -0400
changeset 6766 31ba56a8ec43
parent 6765 8fcd2508c49f
child 6767 ccbf07b38a43
Minor optimisation for AI to cut down on hwSqrt calls
hedgewars/uAIMisc.pas
--- a/hedgewars/uAIMisc.pas	Sun Mar 11 11:39:45 2012 -0400
+++ b/hedgewars/uAIMisc.pas	Sun Mar 11 12:19:04 2012 -0400
@@ -235,7 +235,7 @@
 end;
 
 function RateExplosion(Me: PGear; x, y, r: LongInt): LongInt;
-var i, dmg, rate: LongInt;
+var i, dmg, dmgBase, rate: LongInt;
 begin
 rate:= 0;
 // add our virtual position
@@ -246,10 +246,13 @@
     Score:= - ThinkingHH^.Health
     end;
 // rate explosion
+dmgBase:= r + cHHRadius div 2;
 for i:= 0 to Targets.Count do
     with Targets.ar[i] do
         begin
-        dmg:= hwRound(_0_01 * cDamageModifier * min((r + cHHRadius div 2 - LongInt(DistanceI(Point.x - x, Point.y - y).Round)) div 2, r) * cDamagePercent);
+        dmg:= 0;
+        if abs(Point.x - x) + abs(Point.y - y) < dmgBase then
+            dmg:= hwRound(_0_01 * cDamageModifier * min((dmgBase - LongInt(DistanceI(Point.x - x, Point.y - y).Round)) div 2, r) * cDamagePercent);
 
         if dmg > 0 then
             begin