Fix mapgen flowers being placed into indestructible map border
authorWuzzy <Wuzzy2@mail.ru>
Sat, 15 Jun 2019 19:49:02 +0200
changeset 15159 fcd697bce2a8
parent 15158 4744d7b78c75
child 15160 4c13bc464c61
Fix mapgen flowers being placed into indestructible map border
hedgewars/uGears.pas
--- a/hedgewars/uGears.pas	Sat Jun 15 19:44:52 2019 +0200
+++ b/hedgewars/uGears.pas	Sat Jun 15 19:49:02 2019 +0200
@@ -1059,14 +1059,24 @@
             with Hedgehogs[i] do
                 if (Gear <> nil) and (Gear^.State and gsttmpFlag <> 0) then
                     begin
+                    // Get flower position
                     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);
+                    // Calculate offset from map boundaries and border
+                    if hasBorder then
+                        x:= max(min(x, RightX - SpritesData[sprTargetBee].Width) - cBorderWidth, LeftX + cBorderWidth)
+                    else
+                        x:= max(min(x, RightX - SpritesData[sprTargetBee].Width), LeftX);
                     y:= max(y, TopY);
+
+                    // Place flower
                     ForcePlaceOnLand(x, y, sprTargetBee, 0, lfBasic, $FFFFFFFF, false, false, false);
+
+                    // Place hog
                     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(x) + ',' + inttostr(y) + ')')
                     end;