hedgewars/uGearsUtils.pas
changeset 12448 8b89fe2115ad
parent 12446 48ee3777e42e
child 12449 8c5475bb4db7
equal deleted inserted replaced
12447:ac710bb12fbb 12448:8b89fe2115ad
   784         gear^.State := gstWait;
   784         gear^.State := gstWait;
   785         end;
   785         end;
   786     RecountTeamHealth(tempTeam);
   786     RecountTeamHealth(tempTeam);
   787 end;
   787 end;
   788 
   788 
   789 function CountNonZeroz(x, y, r, c: LongInt; mask: LongWord): LongInt;
   789 function CountLand(x, y, r, c: LongInt; mask, antimask: LongWord): LongInt;
   790 var i: LongInt;
   790 var i: LongInt;
   791     count: LongInt = 0;
   791     count: LongInt = 0;
   792 begin
   792 begin
   793     if (y and LAND_HEIGHT_MASK) = 0 then
   793     if (y and LAND_HEIGHT_MASK) = 0 then
   794         for i:= max(x - r, 0) to min(x + r, LAND_WIDTH - 1) do
   794         for i:= max(x - r, 0) to min(x + r, LAND_WIDTH - 1) do
   795             if Land[y, i] and mask <> 0 then
   795             if (Land[y, i] and mask <> 0) and (Land[y, i] and antimask = 0) then
   796             begin
   796                 begin
   797                 inc(count);
   797                 inc(count);
   798                 if count = c then
   798                 if count = c then
   799                 begin
   799                     begin
   800                     CountNonZeroz:= count;
   800                     CountLand:= count;
   801                     exit
   801                     exit
       
   802                     end;
   802                 end;
   803                 end;
   803             end;
   804     CountLand:= count;
   804     CountNonZeroz:= count;
       
   805 end;
   805 end;
   806 
   806 
   807 function isSteadyPosition(x, y, r, c: LongInt; mask: Longword): boolean;
   807 function isSteadyPosition(x, y, r, c: LongInt; mask: Longword): boolean;
   808 var cnt, i: LongInt;
   808 var cnt, i: LongInt;
   809 begin
   809 begin
   881             while y < cWaterLine do
   881             while y < cWaterLine do
   882                 begin
   882                 begin
   883                 repeat
   883                 repeat
   884                     inc(y, 2);
   884                     inc(y, 2);
   885                 until (y >= cWaterLine) or
   885                 until (y >= cWaterLine) or
   886                         ((not ignoreOverlap) and (CountNonZeroz(x, y, Gear^.Radius - 1, 1, $FFFF) = 0)) or
   886                     (ignoreOverLap and (CountLand(x, y, Gear^.Radius - 1, 1, $FF00, 0) = 0)) or
   887                         (ignoreOverlap and (CountNonZeroz(x, y, Gear^.Radius - 1, 1, lfLandMask and (not lfIce)) = 0));
   887                     (not ignoreOverLap and (CountLand(x, y, Gear^.Radius - 1, 1, $FFFF, 0) = 0));
       
   888 
   888 
   889 
   889                 sy:= y;
   890                 sy:= y;
   890 
   891 
   891                 repeat
   892                 repeat
   892                     inc(y);
   893                     inc(y);
   893                 until (y >= cWaterLine) or
   894                 until (y >= cWaterLine) or
   894                         ((not ignoreOverlap) and (CountNonZeroz(x, y, Gear^.Radius - 1, 1, $FFFF) <> 0)) or
   895                         (ignoreOverlap and 
   895                         (ignoreOverlap and (CountNonZeroz(x, y, Gear^.Radius - 1, 1, lfLandMask and (not lfIce)) <> 0));
   896                                 ((CountLand(x, y, Gear^.Radius - 1, 1, $FFFF, lfIce) <> 0) or
       
   897                                  (CountLand(x, y+1, Gear^.Radius - 1, Gear^.Radius + 1, lfIce, 0) > Gear^.Radius))) or
       
   898                         (not ignoreOverlap and 
       
   899                             ((CountLand(x, y, Gear^.Radius - 1, 1, lfLandMask, lfIce) <> 0) or
       
   900                              (CountLand(x, y+1, Gear^.Radius - 1, Gear^.Radius + 1, lfIce, 0) > Gear^.Radius)));
   896 
   901 
   897                 if (y - sy > Gear^.Radius * 2) and (y < cWaterLine)
   902                 if (y - sy > Gear^.Radius * 2) and (y < cWaterLine)
   898                     and (((Gear^.Kind = gtExplosives)
   903                     and (((Gear^.Kind = gtExplosives)
   899                         and (ignoreNearObjects or NoGearsToAvoid(x, y - Gear^.Radius, 60, 60))
   904                         and (ignoreNearObjects or NoGearsToAvoid(x, y - Gear^.Radius, 60, 60))
   900                         and (isSteadyPosition(x, y+1, Gear^.Radius - 1, 3, $FFFF)
   905                         and (isSteadyPosition(x, y+1, Gear^.Radius - 1, 3, $FFFF)
   901                          or (CountNonZeroz(x, y+1, Gear^.Radius - 1, Gear^.Radius+1, $FFFF) > Gear^.Radius)
   906                          or (CountLand(x, y+1, Gear^.Radius - 1, Gear^.Radius+1, $FFFF, 0) > Gear^.Radius)
   902                             ))
   907                             ))
   903                     or
   908                     or
   904                         ((Gear^.Kind <> gtExplosives)
   909                         ((Gear^.Kind <> gtExplosives)
   905                         and (ignoreNearObjects or NoGearsToAvoid(x, y - Gear^.Radius, 110, 110))
   910                         and (ignoreNearObjects or NoGearsToAvoid(x, y - Gear^.Radius, 110, 110))
   906                         )) then
   911                         )) then