make sentries reload after being hit
authoralfadur
Thu, 09 Jul 2020 00:45:27 +0300
changeset 15734 b496233ac26d
parent 15733 4a8a1dd9528a
child 15735 73c4e7d47575
make sentries reload after being hit
hedgewars/uGearsHandlersMess.pas
--- a/hedgewars/uGearsHandlersMess.pas	Thu Jul 09 00:32:53 2020 +0300
+++ b/hedgewars/uGearsHandlersMess.pas	Thu Jul 09 00:45:27 2020 +0300
@@ -7272,6 +7272,19 @@
         and (TraceAttackPath(Sentry^.X, Sentry^.Y, targetX, targetY, _4, lfLandMask) <= 18);
 end;
 
+procedure ResetSentryState(Gear: PGear; state, timer: LongInt);
+begin
+    Gear^.Timer := timer;
+    Gear^.Tag := state;
+    Gear^.Target.X := 0;
+    Gear^.Target.Y := 0;
+    if Gear^.Karma <> 0 then
+    begin
+        ClearGlobalHitOrderLeq(Gear^.Karma);
+        Gear^.Karma := 0;
+    end;
+end;
+
 procedure doStepSentry(Gear: PGear);
 var HHGear, bullet: PGear;
     distX, distY, invDistance: HwFloat;
@@ -7286,13 +7299,18 @@
     if CheckGearDrowning(Gear) then
         exit;
 
-    dec(Gear^.Health, Gear^.Damage);
-    Gear^.Damage := 0;
-    if Gear^.Health <= 0 then
+    if Gear^.Damage > 0 then
     begin
-        doMakeExplosion(hwRound(Gear^.X), hwRound(Gear^.Y), Gear^.Boom, Gear^.Hedgehog, EXPLAutoSound);
-        DeleteGear(Gear);
-        exit;
+        dec(Gear^.Health, Gear^.Damage);
+        Gear^.Damage := 0;
+        if Gear^.Health <= 0 then
+        begin
+            doMakeExplosion(hwRound(Gear^.X), hwRound(Gear^.Y), Gear^.Boom, Gear^.Hedgehog, EXPLAutoSound);
+            DeleteGear(Gear);
+            exit;
+        end;
+
+        ResetSentryState(Gear, sentry_Reloading, 10000)
     end;
 
     if ((Gear^.Health * 100) < random(cSentryHealth * 90)) and ((GameTicks and $FF) = 0) then
@@ -7304,18 +7322,8 @@
     if Gear^.dY.isNegative or (TestCollisionYwithGear(Gear, 1) = 0) then
     begin
         doStepFallingGear(Gear);
-        if Gear^.Tag <> sentry_Idle then
-        begin
-            Gear^.Timer := 0;
-            Gear^.Tag := sentry_Idle;
-            Gear^.Target.X := 0;
-            Gear^.Target.Y := 0;
-            if Gear^.Karma <> 0 then
-            begin
-                ClearGlobalHitOrderLeq(Gear^.Karma);
-                Gear^.Karma := 0;
-            end;
-        end;
+        if not (Gear^.Tag in [sentry_Idle, sentry_Reloading]) then
+            ResetSentryState(Gear, sentry_Idle, 1000);
         exit;
     end;