# HG changeset patch
# User Wuzzy <Wuzzy2@mail.ru>
# Date 1559573382 -7200
# Node ID b4a0dc4e85e8515aa59d0f72c884f211d4b5da05
# Parent  f9d57bade2a5677b24d680aa7ae01726a6b14933
Ensure the flowers get placed within map bounds

diff -r f9d57bade2a5 -r b4a0dc4e85e8 hedgewars/uGears.pas
--- a/hedgewars/uGears.pas	Mon Jun 03 15:37:32 2019 +0200
+++ b/hedgewars/uGears.pas	Mon Jun 03 16:49:42 2019 +0200
@@ -958,7 +958,7 @@
 end;
 
 procedure AssignHHCoords;
-var i, t, p, j: LongInt;
+var i, t, p, j, x, y: LongInt;
     ar: array[0..Pred(cMaxHHs)] of PHedgehog;
     Count: Longword;
     divide, sectionDivide: boolean;
@@ -1059,13 +1059,15 @@
             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);
-                    Gear^.Y:= int2hwFloat(hwRound(Gear^.Y) - 16 - Gear^.Radius);
+                    x:= hwRound(Gear^.X) - SpritesData[sprTargetBee].Width div 2;
+                    y:= hwRound(Gear^.Y) - SpritesData[sprTargetBee].Height div 2;
+                    x:= max(min(x, RightX - SpritesData[sprTargetBee].Width), LeftX);
+                    y:= max(y, TopY);
+                    ForcePlaceOnLand(x, y, sprTargetBee, 0, lfBasic, $FFFFFFFF, false, false, false);
+                    Gear^.Y:= int2hwFloat(hwRound(Gear^.Y) - (SpritesData[sprTargetBee].Height div 2) - Gear^.Radius);
                     AddCI(Gear);
                     Gear^.State:= Gear^.State and (not gsttmpFlag);
-                    AddFileLog('Placed flower for hog at coordinates (' + inttostr(hwRound(Gear^.X)) + ',' + inttostr(hwRound(Gear^.Y)) + ')')
+                    AddFileLog('Placed flower for hog at coordinates (' + inttostr(x) + ',' + inttostr(y) + ')')
                     end;