# HG changeset patch
# User unc0rr
# Date 1294664029 -10800
# Node ID c5ddc3e6c8a4d4d97a95ae7134f3d289ac8f4ae4
# Parent  1d555e738a3ab7820a13475e81b9275970b35f15
Don't waste CPU cycles trying to find a piece of land when there's no free land left

diff -r 1d555e738a3a -r c5ddc3e6c8a4 hedgewars/uGears.pas
--- a/hedgewars/uGears.pas	Mon Jan 10 15:35:22 2011 +0300
+++ b/hedgewars/uGears.pas	Mon Jan 10 15:53:49 2011 +0300
@@ -1094,15 +1094,22 @@
 begin
 AddGear(0, 0, gtATStartGame, 0, _0, _0, 2000);
 
-for i:= 0 to Pred(cLandMines) do
+i:= 0;
+Gear:= PGear(1);
+while (i < cLandMines) and (Gear <> nil) do
     begin
     Gear:= AddGear(0, 0, gtMine, 0, _0, _0, 0);
     FindPlace(Gear, false, 0, LAND_WIDTH);
+    inc(i)
     end;
-for i:= 0 to Pred(cExplosives) do
+
+i:= 0;
+Gear:= PGear(1);
+while (i < cExplosives) and (Gear <> nil) do
     begin
     Gear:= AddGear(0, 0, gtExplosives, 0, _0, _0, 0);
     FindPlace(Gear, false, 0, LAND_WIDTH);
+    inc(i)
     end;
 
 if (GameFlags and gfLowGravity) <> 0 then
@@ -1426,12 +1433,13 @@
 var
     t: PGear;
 begin
+    r:= r*r;
     GearsNear := nil;
     t := GearsList;
     while t <> nil do begin
         if (t^.Kind = Kind) then begin
             if (X - t^.X)*(X - t^.X) + (Y - t^.Y)*(Y-t^.Y) <
-                int2hwFloat(r)*int2hwFloat(r) then
+                int2hwFloat(r) then
             begin
                 SetLength(GearsNear, Length(GearsNear)+1);
                 GearsNear[High(GearsNear)] := t;