hedgewars/uGearsUtils.pas
changeset 6990 40e5af28d026
parent 6986 409dd3851309
child 7010 10a0a31804f3
equal deleted inserted replaced
6989:4c35e9cf6057 6990:40e5af28d026
   471 
   471 
   472 function CountNonZeroz(x, y, r, c: LongInt): LongInt;
   472 function CountNonZeroz(x, y, r, c: LongInt): LongInt;
   473 var i: LongInt;
   473 var i: LongInt;
   474     count: LongInt = 0;
   474     count: LongInt = 0;
   475 begin
   475 begin
   476 if (y and LAND_HEIGHT_MASK) = 0 then
   476     if (y and LAND_HEIGHT_MASK) = 0 then
   477     for i:= max(x - r, 0) to min(x + r, LAND_WIDTH - 4) do
   477         for i:= max(x - r, 0) to min(x + r, LAND_WIDTH - 4) do
   478         if Land[y, i] <> 0 then
   478             if Land[y, i] <> 0 then
   479             begin
   479             begin
   480             inc(count);
   480                 inc(count);
   481             if count = c then
   481                 if count = c then
   482                 exit(count)
   482                 begin
       
   483                     CountNonZeroz:= count;
       
   484                     exit
       
   485                 end;
   483             end;
   486             end;
   484 CountNonZeroz:= count;
   487     CountNonZeroz:= count;
   485 end;
   488 end;
   486 
   489 
   487 
   490 
   488 function NoGearsToAvoid(mX, mY: LongInt; rX, rY: LongInt): boolean;
   491 function NoGearsToAvoid(mX, mY: LongInt; rX, rY: LongInt): boolean;
   489 var t: PGear;
   492 var t: PGear;
   490 begin
   493 begin
       
   494 NoGearsToAvoid:= false;
   491 t:= GearsList;
   495 t:= GearsList;
   492 rX:= sqr(rX);
   496 rX:= sqr(rX);
   493 rY:= sqr(rY);
   497 rY:= sqr(rY);
   494 while t <> nil do
   498 while t <> nil do
   495     begin
   499     begin
   496     if t^.Kind <= gtExplosives then
   500     if t^.Kind <= gtExplosives then
   497         if not (hwSqr(int2hwFloat(mX) - t^.X) / rX + hwSqr(int2hwFloat(mY) - t^.Y) / rY > _1) then
   501         if not (hwSqr(int2hwFloat(mX) - t^.X) / rX + hwSqr(int2hwFloat(mY) - t^.Y) / rY > _1) then
   498             exit(false);
   502             exit;
   499     t:= t^.NextGear
   503     t:= t^.NextGear
   500     end;
   504     end;
   501 NoGearsToAvoid:= true
   505 NoGearsToAvoid:= true
   502 end;
   506 end;
   503 
   507 
   604 
   608 
   605 while t <> nil do
   609 while t <> nil do
   606     begin
   610     begin
   607     if (t <> Gear) and (t^.Kind = Kind) then
   611     if (t <> Gear) and (t^.Kind = Kind) then
   608         if not((hwSqr(Gear^.X - t^.X) / rX + hwSqr(Gear^.Y - t^.Y) / rY) > _1) then
   612         if not((hwSqr(Gear^.X - t^.X) / rX + hwSqr(Gear^.Y - t^.Y) / rY) > _1) then
   609         exit(t);
   613         begin
       
   614             CheckGearNear:= t;
       
   615             exit;
       
   616         end;
   610     t:= t^.NextGear
   617     t:= t^.NextGear
   611     end;
   618     end;
   612 
   619 
   613 CheckGearNear:= nil
   620 CheckGearNear:= nil
   614 end;
   621 end;