disallow placing girders over airmines and moving hogs
authoralfadur
Tue, 06 Aug 2019 23:47:02 +0300
changeset 15307 9299f43ba0ec
parent 15306 361e79c6c428
child 15308 b761efebe3c4
disallow placing girders over airmines and moving hogs
hedgewars/uCollisions.pas
hedgewars/uGearsHandlersMess.pas
--- a/hedgewars/uCollisions.pas	Tue Aug 06 23:28:14 2019 +0300
+++ b/hedgewars/uCollisions.pas	Tue Aug 06 23:47:02 2019 +0300
@@ -1056,18 +1056,18 @@
 
     while Gear <> nil do
         begin
-        if (Gear^.Kind = gtAirMine) or ((Gear^.Kind = gtHedgehog) and (Gear^.CollisionIndex <> 0)) then
+        if (Gear^.Kind = gtAirMine) or ((Gear^.Kind = gtHedgehog) and (Gear^.CollisionIndex = 0)) then
             begin
             gx:= hwRound(Gear^.X);
             gy:= hwRound(Gear^.Y);
-            r:= Gear^.Radius;
+            r:= Gear^.Radius + 1;
             if (gx + r >= sprX) and (gx - r < sprX + w) and (gy + r >= sprY) and (gy - r < sprY + h) then
                 for y := gy - r to gy + r do
                     for x := gx - r to gx + r do
                         begin
                         if (x >= sprX) and (x < sprX + w) and (y >= sprY) and (y < sprY + h)
-                        and (Sqr(x - gx) + Sqr(y - gy) < Sqr(r))
-                        and (((PLongword(@(p^[Image^.pitch * y + x * 4]))^) and AMask) <> 0) then
+                        and (Sqr(x - gx) + Sqr(y - gy) <= Sqr(r))
+                        and (((PLongword(@(p^[Image^.pitch * (y - sprY) + (x - sprX) * 4]))^) and AMask) <> 0) then
                             begin
                             CheckGearsUnderSprite := true;
                             if SDL_MustLock(Image) then
--- a/hedgewars/uGearsHandlersMess.pas	Tue Aug 06 23:28:14 2019 +0300
+++ b/hedgewars/uGearsHandlersMess.pas	Tue Aug 06 23:47:02 2019 +0300
@@ -3317,6 +3317,7 @@
             (hwRound(Distance(tx - int2hwFloat(leftX-(rightX-rx)), ty - y)) > cBuildMaxDist)
             )));
     if distFail
+    or CheckGearsUnderSprite(Ammoz[Gear^.AmmoType].PosSprite, Gear^.Target.X - SpritesData[Ammoz[Gear^.AmmoType].PosSprite].Width div 2, Gear^.Target.Y - SpritesData[Ammoz[Gear^.AmmoType].PosSprite].Height div 2, Gear^.State)
     or (not TryPlaceOnLand(Gear^.Target.X - SpritesData[Ammoz[Gear^.AmmoType].PosSprite].Width div 2, Gear^.Target.Y - SpritesData[Ammoz[Gear^.AmmoType].PosSprite].Height div 2, Ammoz[Gear^.AmmoType].PosSprite, Gear^.State, true, LandFlags)) then
         begin
         PlaySound(sndDenied);