place some generated sentries in water
authoralfadur
Sat, 11 Jul 2020 23:06:29 +0300
changeset 15742 b743adf298d8
parent 15741 08e556cad305
child 15743 1244c64b8e28
place some generated sentries in water
hedgewars/uGears.pas
--- a/hedgewars/uGears.pas	Sat Jul 11 20:33:23 2020 +0300
+++ b/hedgewars/uGears.pas	Sat Jul 11 23:06:29 2020 +0300
@@ -761,7 +761,7 @@
     end;
 end;
 
-procedure AddSentries(count: LongWord);
+procedure AddLandSentries(count: LongWord);
 var i, x, y, swapIndex: LongInt;
     positions: array[0..1023] of TPoint;
     positionsCount, tries: LongInt;
@@ -817,6 +817,36 @@
         AddGear(positions[i].X, positions[i].Y - cHHRadius, gtSentry, 0, _0, _0, 0);
 end;
 
+function AddWaterSentries(count: Longword): Longword;
+var i, x, y: LongInt;
+    positions: array[0..255] of TPoint;
+    positionsCount, tries: LongInt;
+begin
+    AddWaterSentries := 0;
+    positionsCount := 0;
+    tries := 512;
+
+    while (positionsCount < 256) and (tries > 0) do
+    begin
+        x := leftX + cHHRadius + GetRandom(rightX - leftX - 2 * cHHRadius);
+        y := cWaterLine - 3 * cHHRadius;
+        if (CountLand(x, y, cHHRadius - 1, 1, lfAll, 0) = 0) then
+        begin
+            positions[positionsCount].X := x;
+            positions[positionsCount].Y := y;
+            inc(positionsCount);
+            if positionsCount >= 256 then
+                break;
+        end;
+    end;
+
+    for i := 0 to min(count, positionsCount) - 1 do
+    begin
+        AddGear(positions[i].X, positions[i].Y - cHHRadius, gtSentry, 0, _0, _0, 0);
+        inc(AddWaterSentries);
+    end;
+end;
+
 procedure AddMiscGears;
 var p,i,j,t,h,unplaced: Longword;
     rx, ry: LongInt;
@@ -919,7 +949,10 @@
         end;
 if p <> 0 then DeleteGear(Gear);
 
-AddSentries(cSentries);
+if cSentries > 10 then
+    AddLandSentries(cSentries - AddWaterSentries(cSentries div 10))
+else
+    AddLandSentries(cSentries);
 
 if (GameFlags and gfLowGravity) <> 0 then
     begin