# HG changeset patch # User alfadur # Date 1593541548 -10800 # Node ID 5ce76c658c22b6ffade9871e5e42c0bf49ecc5bc # Parent a3f492e601dd02db3d0e307abf5e32b2708dcee6 don't shoot if the target moves out of range while aiming diff -r a3f492e601dd -r 5ce76c658c22 hedgewars/uGearsHandlersMess.pas --- a/hedgewars/uGearsHandlersMess.pas Tue Jun 30 20:02:04 2020 +0300 +++ b/hedgewars/uGearsHandlersMess.pas Tue Jun 30 21:25:48 2020 +0300 @@ -7228,6 +7228,19 @@ end end; +function CheckSentryAttackRange(Sentry: PGear; targetX, targetY: HwFloat): Boolean; +var distX, distY: hwFloat; +begin + distX := targetX - Sentry^.X; + distY := targetY - Sentry^.Y; + CheckSentryAttackRange := + (distX.isNegative = Sentry^.dX.isNegative) + and (distX.Round > 24) + and (distX.Round < 500) + and (hwAbs(distY) < hwAbs(distX)) + and (TraceAttackPath(Sentry^.X, Sentry^.Y, targetX, targetY, _4, lfLandMask) <= 18); +end; + procedure doStepSentry(Gear: PGear); var HHGear, bullet: PGear; distX, distY, invDistance: HwFloat; @@ -7286,9 +7299,19 @@ end else if Gear^.Tag = sentry_Aiming then begin - Gear^.WDTimer := 5 + GetRandom(3); - Gear^.Tag := sentry_Attacking; - Gear^.Timer := 100; + if CheckSentryAttackRange(Gear, int2hwFloat(Gear^.Target.X), int2hwFloat(Gear^.Target.Y)) then + begin + Gear^.WDTimer := 5 + GetRandom(3); + Gear^.Tag := sentry_Attacking; + Gear^.Timer := 100; + end + else + begin + Gear^.Target.X := 0; + Gear^.Target.Y := 0; + Gear^.Tag := sentry_Idle; + Gear^.Timer := 5000; + end end else if Gear^.Tag = sentry_Attacking then begin @@ -7356,13 +7379,7 @@ and ((CurrentHedgehog^.Gear^.State and (gstMoving or gstHHDriven)) = (gstMoving or gstHHDriven)) then begin HHGear := CurrentHedgehog^.Gear; - distX := HHGear^.X - Gear^.X; - distY := HHGear^.Y - Gear^.Y; - if (distX.isNegative = Gear^.dX.isNegative) - and (distX.Round > 24) - and (distX.Round < 500) - and (hwAbs(distY) < hwAbs(distX)) - and (TraceAttackPath(Gear^.X, Gear^.Y, HHGear^.X, HHGear^.Y, _4, lfLandMask) <= 18 ) then + if CheckSentryAttackRange(Gear, HHGear^.X, HHGear^.Y) then begin Gear^.Target.X := hwRound(HHGear^.X); Gear^.Target.Y := hwRound(HHGear^.Y);