hedgewars/uGears.pas
changeset 14398 87562a68c41f
parent 14394 d670e4efe1ed
child 14400 9c7d5f595881
--- a/hedgewars/uGears.pas	Sun Dec 09 22:28:46 2018 +0100
+++ b/hedgewars/uGears.pas	Mon Dec 10 02:30:14 2018 +0100
@@ -64,7 +64,7 @@
     delay2: LongWord;
     step: (stInit, stDelay, stChDmg, stSweep, stTurnStats, stChWin1,
     stTurnReact, stAfterDelay, stChWin2, stWater, stChWin3,
-    stHealth, stSpawn, stNTurn);
+    stChKing, stHealth, stSpawn, stNTurn);
     NewTurnTick: LongWord;
     //SDMusic: shortstring;
 
@@ -86,7 +86,7 @@
             CheckNoDamage:= false;
 
             dmg:= Gear^.Damage;
-            if Gear^.Health < dmg then
+            if (Gear^.Health < dmg) then
                 begin
                 Gear^.Active:= true;
                 Gear^.Health:= 0
@@ -105,7 +105,15 @@
             RenderHealth(Gear^.Hedgehog^);
             RecountTeamHealth(Gear^.Hedgehog^.Team);
 
+            end
+        else if ((GameFlags and gfKing) <> 0) and (not Gear^.Hedgehog^.Team^.hasKing) then
+            begin
+            Gear^.Active:= true;
+            Gear^.Health:= 0;
+            RenderHealth(Gear^.Hedgehog^);
+            RecountTeamHealth(Gear^.Hedgehog^.Team);
             end;
+
         if (not isInMultiShoot) then
             Gear^.Karma:= 0;
         Gear^.Damage:= 0
@@ -114,6 +122,25 @@
     end;
 end;
 
+function CheckMinionsDie: boolean;
+var Gear: PGear;
+begin
+    CheckMinionsDie:= false;
+    if (GameFlags and gfKing) = 0 then
+        exit;
+
+    Gear:= GearsList;
+    while Gear <> nil do
+        begin
+        if (Gear^.Kind = gtHedgehog) and (not Gear^.Hedgehog^.King) and (not Gear^.Hedgehog^.Team^.hasKing) then
+            begin
+            CheckMinionsDie:= true;
+            exit;
+            end;
+        Gear:= Gear^.NextGear;
+        end;
+end;
+
 procedure HealthMachine;
 var Gear: PGear;
     team: PTeam;
@@ -357,10 +384,17 @@
         inc(step)
         end;
 
+    stChKing:
+        begin
+        if (not isInMultiShoot) and (CheckMinionsDie) then
+            step:= stChDmg
+        else
+            inc(step);
+        end;
     stHealth:
         begin
         if (cWaterRise <> 0) or (cHealthDecrease <> 0) then
-             begin
+            begin
             if (TotalRoundsPre = cSuddenDTurns) and (not SuddenDeath) and (not isInMultiShoot) then
                 StartSuddenDeath()
             else if (TotalRoundsPre < cSuddenDTurns) and (not isInMultiShoot) then