Show Sudden Death warning messages only once per round
authorWuzzy <Wuzzy2@mail.ru>
Mon, 10 Dec 2018 09:39:34 +0100
changeset 14411 b48c270328a5
parent 14410 dce60c706f01
child 14412 7dbc3e5f8129
Show Sudden Death warning messages only once per round
hedgewars/uGears.pas
hedgewars/uVariables.pas
--- a/hedgewars/uGears.pas	Mon Dec 10 09:01:27 2018 +0100
+++ b/hedgewars/uGears.pas	Mon Dec 10 09:39:34 2018 +0100
@@ -402,29 +402,36 @@
         end;
     stSuddenDeath:
         begin
-        if (cWaterRise <> 0) or (cHealthDecrease <> 0) then
+        if ((cWaterRise <> 0) or (cHealthDecrease <> 0)) and (not (isInMultiShoot or bBetweenTurns)) then
             begin
-            if (TotalRoundsPre = cSuddenDTurns) and (not SuddenDeath) and (not isInMultiShoot) then
+            // Start Sudden Death
+            if (TotalRoundsPre = cSuddenDTurns) and (not SuddenDeath) then
                 begin
                 StartSuddenDeath();
                 delay:= delaySDStart;
+                inc(step);
                 end
-            else if (TotalRoundsPre < cSuddenDTurns) and (not isInMultiShoot) then
+            // Show Sudden Death warning message
+            else if (TotalRoundsPre < cSuddenDTurns) and ((LastSuddenDWarn = -2) or (LastSuddenDWarn <> TotalRoundsPre)) then
                 begin
                 i:= cSuddenDTurns - TotalRoundsPre;
                 s:= ansistring(inttostr(i));
-                if i = 1 then
+                // X rounds before SD. X = 1, 2, 5, 10, 15, 20, 25, 50, 100, ...
+                if (i > 0) and ((i <= 2) or ((i mod 50 = 0) or ((i <= 25) and (i mod 5 = 0)))) then
                     begin
-                    AddCaption(trmsg[sidRoundSD], capcolDefault, capgrpGameState);
+                    if i = 1 then
+                        AddCaption(trmsg[sidRoundSD], capcolDefault, capgrpGameState)
+                    else
+                        AddCaption(FormatA(trmsg[sidRoundsSD], s), capcolDefault, capgrpGameState);
                     delay:= delaySDWarning;
+                    inc(step);
+                    LastSuddenDWarn:= TotalRoundsPre;
                     end
-                else if (i = 2) or ((i > 0) and ((i mod 50 = 0) or ((i <= 25) and (i mod 5 = 0)))) then
-                    begin
-                    AddCaption(FormatA(trmsg[sidRoundsSD], s), capcolDefault, capgrpGameState);
-                    delay:= delaySDWarning;
-                    end
-                end;
-            inc(step);
+                else
+                    inc(step, 2);
+                end
+            else
+                inc(step, 2);
             end
         else
             inc(step, 2);
--- a/hedgewars/uVariables.pas	Mon Dec 10 09:01:27 2018 +0100
+++ b/hedgewars/uVariables.pas	Mon Dec 10 09:39:34 2018 +0100
@@ -104,6 +104,7 @@
     IsGetAwayTime   : boolean;
     GameOver        : boolean;
     cSuddenDTurns   : LongInt;
+    LastSuddenDWarn : LongInt; // last round in which the last SD warning appeared. -2 = no warning so far
     cDamagePercent  : LongInt;
     cMineDudPercent : LongWord;
     cTemplateFilter : LongInt;
@@ -2801,6 +2802,7 @@
     TurnClockActive     := true;
     TagTurnTimeLeft     := 0;
     cSuddenDTurns       := 15;
+    LastSuddenDWarn     := -2;
     cDamagePercent      := 100;
     cRopePercent        := 100;
     cGetAwayTime        := 100;