Tweak the hole carving to become less agressive about spacing if random points keep failing.
authornemo
Thu, 31 Dec 2015 15:11:44 -0500
changeset 11478 8c95d5a4366c
parent 11477 e425a6eb9da3
child 11479 846a3b3a3d1c
Tweak the hole carving to become less agressive about spacing if random points keep failing.
hedgewars/uGears.pas
hedgewars/uGearsUtils.pas
--- a/hedgewars/uGears.pas	Thu Dec 31 12:47:33 2015 -0500
+++ b/hedgewars/uGears.pas	Thu Dec 31 15:11:44 2015 -0500
@@ -808,6 +808,15 @@
                 if (Gear <> nil) and (Gear^.State and gsttmpFlag <> 0) then
                     begin
                     DrawExplosion(hwRound(Gear^.X), hwRound(Gear^.Y), 50);
+                    AddFileLog('Carved a hole for hog at coordinates (' + inttostr(hwRound(Gear^.X)) + ',' + inttostr(hwRound(Gear^.Y)) + ')')
+                    end;
+// place flowers after in case holes overlap (we shrink search distance if we are failing to place)
+for p:= 0 to Pred(TeamsCount) do
+    with TeamsArray[p]^ do
+        for i:= 0 to cMaxHHIndex do
+            with Hedgehogs[i] do
+                if (Gear <> nil) and (Gear^.State and gsttmpFlag <> 0) then
+                    begin
                     ForcePlaceOnLand(hwRound(Gear^.X) - SpritesData[sprTargetBee].Width div 2, 
                                      hwRound(Gear^.Y) - SpritesData[sprTargetBee].Height div 2, 
                                      sprTargetBee, 0, lfBasic, $FFFFFFFF, false, false, false);
--- a/hedgewars/uGearsUtils.pas	Thu Dec 31 12:47:33 2015 -0500
+++ b/hedgewars/uGearsUtils.pas	Thu Dec 31 15:11:44 2015 -0500
@@ -939,9 +939,9 @@
             while (cnt < 1000) do
                 begin
                 inc(cnt);
-                x:= leftX+GetRandom(rightX-leftX-16)+8;
-                y:= topY+GetRandom(LAND_HEIGHT-topY-16)+8;
-                if NoGearsToAvoid(x, y, 100, 100) then
+                x:= leftX+GetRandom(rightX-leftX-32)+16;
+                y:= topY+GetRandom(LAND_HEIGHT-topY-32)+16;
+                if NoGearsToAvoid(x, y, 100 div max(1,cnt div 100), 100 div max(1,cnt div 100)) then
                     begin
                     Gear^.State:= Gear^.State or gsttmpFlag;
                     Gear^.X:= int2hwFloat(x);