King Mode: Fix king placement phase not working correctly with multiple teams in a clan
authorWuzzy <Wuzzy2@mail.ru>
Mon, 08 Jul 2019 21:44:26 +0200
changeset 15225 ceb289e8a582
parent 15224 b71bae455926
child 15226 bf11546c1920
King Mode: Fix king placement phase not working correctly with multiple teams in a clan New king placement phase rules: * Before the game begins, each team can walk with their king and teleport for free, everything else is disabled * This special round does not count towards the round counter, like in gfPlaceHog * TotalRounds is set to -1 during this round, like in gfPlaceHog Under the old rules, this was much more hacky. The delay of all delay-less weapons was just set to 1 The problem with the old rules was that if any clan had more than 1 team, eventually the weapon delay will time out before all kings have been placed.
ChangeLog.txt
hedgewars/uAmmos.pas
hedgewars/uGears.pas
hedgewars/uGearsUtils.pas
hedgewars/uStats.pas
hedgewars/uTeams.pas
hedgewars/uTypes.pas
hedgewars/uVariables.pas
--- a/ChangeLog.txt	Mon Jul 08 15:16:05 2019 +0300
+++ b/ChangeLog.txt	Mon Jul 08 21:44:26 2019 +0200
@@ -56,6 +56,8 @@
  * Battalion: Sudden Death effects are now like in the base game
  * King Mode: Fix team sometimes not being killed properly if king drowned
  * King Mode: Kill resurrected minions if king is not alive
+ * King Mode: Fix whole clan being killed if a king died
+ * King Mode: Fix king placement phase not working correctly with multiple teams in a clan
  * HedgeEditor: Fix major FPS drop when there are a lot of objects
  * Control: Fix score failure after using extra time
  * Frenzy: Fix incorrect ammo slot numbers in ammo menu
--- a/hedgewars/uAmmos.pas	Mon Jul 08 15:16:05 2019 +0300
+++ b/hedgewars/uAmmos.pas	Mon Jul 08 21:44:26 2019 +0200
@@ -126,21 +126,23 @@
             end;
         ammos[a]:= cnt;
 
-        if ((GameFlags and gfKing) <> 0) and ((GameFlags and gfPlaceHog) = 0)
-        and (Ammoz[a].SkipTurns = 0) and (a <> amTeleport) and (a <> amSkip) then
-            Ammoz[a].SkipTurns:= 1;
-
-        if ((GameFlags and gfPlaceHog) <> 0)
+        if (((GameFlags and gfPlaceHog) <> 0)
+        or (((GameFlags and gfKing) <> 0) and ((GameFlags and gfPlaceHog) = 0)))
         and (a <> amTeleport) and (a <> amSkip)
         and (Ammoz[a].SkipTurns < 10000) then
             inc(Ammoz[a].SkipTurns,10000);
-    if ((GameFlags and gfPlaceHog) <> 0) and (a = amTeleport) then
+    if (((GameFlags and gfPlaceHog) <> 0)
+    or (((GameFlags and gfKing) <> 0) and ((GameFlags and gfPlaceHog) = 0)))
+    and (a = amTeleport) then
         ammos[a]:= AMMO_INFINITE
         end
 
     else
         ammos[a]:= AMMO_INFINITE;
-    if ((GameFlags and gfPlaceHog) <> 0) and (a = amTeleport) then
+
+    if (((GameFlags and gfPlaceHog) <> 0)
+    or (((GameFlags and gfKing) <> 0) and ((GameFlags and gfPlaceHog) = 0)))
+    and (a = amTeleport) then
         begin
         InitialCountsLocal[Pred(StoreCnt)][a]:= cnt;
         InitialAmmoCounts[a]:= cnt;
@@ -496,7 +498,7 @@
     ammoReinforcement:= s;
 end;
 
-// Restore indefinitely disabled weapons and initial weapon counts.  Only used for hog placement right now
+// Restore indefinitely disabled weapons and initial weapon counts.
 procedure ResetWeapons;
 var i, t: Longword;
     a: TAmmoType;
--- a/hedgewars/uGears.pas	Mon Jul 08 15:16:05 2019 +0300
+++ b/hedgewars/uGears.pas	Mon Jul 08 21:44:26 2019 +0200
@@ -680,7 +680,7 @@
         t:= t^.NextGear
         end;
 
-    if ((GameFlags and gfResetWeps) <> 0) and (not PlacingHogs) then
+    if ((GameFlags and gfResetWeps) <> 0) and (not PlacingHogs) and (not PlacingKings) then
         ResetWeapons;
 
     if (GameFlags and gfResetHealth) <> 0 then
@@ -968,7 +968,9 @@
     divide, sectionDivide: boolean;
 begin
 if (GameFlags and gfPlaceHog) <> 0 then
-    PlacingHogs:= true;
+    PlacingHogs:= true
+else if (GameFlags and gfKing) <> 0 then
+    PlacingKings:= true;
 
 divide:= ((GameFlags and gfDivideTeams) <> 0);
 
@@ -1005,6 +1007,8 @@
                                     Unplaced:= true
                                 else
                                     FindPlace(Gear, false, t, t + playWidth div ClansCount, true);// could make Gear == nil;
+                                if PlacingKings and King then
+                                    UnplacedKing:= true;
                                 if Gear <> nil then
                                     begin
                                     Gear^.Pos:= GetRandom(49);
@@ -1039,6 +1043,8 @@
             ar[i]^.Unplaced:= true
         else
             FindPlace(ar[i]^.Gear, false, leftX, rightX, true);
+        if PlacingKings and ar[i]^.King then
+            ar[i]^.UnplacedKing:= true;
         if ar[i]^.Gear <> nil then
             begin
             ar[i]^.Gear^.dX.isNegative:= hwRound(ar[i]^.Gear^.X) > leftX + playWidth div 2;
--- a/hedgewars/uGearsUtils.pas	Mon Jul 08 15:16:05 2019 +0300
+++ b/hedgewars/uGearsUtils.pas	Mon Jul 08 21:44:26 2019 +0200
@@ -1603,7 +1603,7 @@
     i: TAmmoType;
 begin
 SpawnBoxOfSmth:= nil;
-if (PlacingHogs) or
+if (PlacingHogs) or (PlacingKings) or
     (cCaseFactor = 0)
     or (CountGears(gtCase) >= cMaxCaseDrops)
     or (GetRandom(cCaseFactor) <> 0) then
--- a/hedgewars/uStats.pas	Mon Jul 08 15:16:05 2019 +0300
+++ b/hedgewars/uStats.pas	Mon Jul 08 21:44:26 2019 +0200
@@ -389,7 +389,7 @@
         begin end// nothing ?
 
     // Turn skipped
-    else if isTurnSkipped and (not PlacingHogs) then
+    else if isTurnSkipped and (not PlacingHogs) and (not PlacingKings) then
         begin
         AddVoice(sndCoward, PreviousTeam^.voicepack);
         AddCaption(FormatA(GetEventString(eidTurnSkipped), s), capcolDefault, capgrpMessage);
--- a/hedgewars/uTeams.pas	Mon Jul 08 15:16:05 2019 +0300
+++ b/hedgewars/uTeams.pas	Mon Jul 08 21:44:26 2019 +0200
@@ -201,7 +201,9 @@
            if Gear <> nil then
                AddCI(Gear)
            end
-        end;
+        end
+    else if (PreviousTeam <> nil) and PlacingKings and UnplacedKing then
+        UnplacedKing:= false;
 
 PreviousTeam:= CurrentTeam;
 
@@ -252,7 +254,7 @@
 
         with ClansArray[c]^ do
             begin
-            if (not PlacingHogs) and ((Succ(CurrTeam) mod TeamsNumber) = TagTeamIndex) then
+            if (not PlacingHogs) and (not PlacingKings) and ((Succ(CurrTeam) mod TeamsNumber) = TagTeamIndex) then
                 begin
                 if c = SwapClanPre then
                     inc(TotalRoundsPre);
@@ -264,7 +266,7 @@
         inc(c);
         if c = ClansCount then
             c:= 0;
-        if (not PlacingHogs) then
+        if (not PlacingHogs) and (not PlacingKings) then
             begin
             if c = SwapClanPre then
                 inc(TotalRoundsPre);
@@ -334,15 +336,18 @@
     g: PGear;
     s: ansistring;
 begin
-if PlacingHogs then
+if PlacingHogs or PlacingKings then
     begin
     PlacingHogs:= false;
+    PlacingKings:= false;
     for t:= 0 to Pred(TeamsCount) do
         for i:= 0 to cMaxHHIndex do
-            if (TeamsArray[t]^.Hedgehogs[i].Gear <> nil) and (TeamsArray[t]^.Hedgehogs[i].Unplaced) then
-                PlacingHogs:= true;
+            if ((GameFlags and gfPlaceHog) <> 0) and (TeamsArray[t]^.Hedgehogs[i].Gear <> nil) and (TeamsArray[t]^.Hedgehogs[i].Unplaced) then
+                PlacingHogs:= true
+            else if ((GameFlags and gfPlaceHog) = 0) and ((GameFlags and gfKing) <> 0) and (TeamsArray[t]^.Hedgehogs[i].Gear <> nil) and (TeamsArray[t]^.Hedgehogs[i].UnplacedKing) then
+                PlacingKings:= true;
 
-    if not PlacingHogs then // Reset  various things I mucked with
+    if (not PlacingHogs) and (not PlacingKings) then // Reset various things I mucked with
         begin
         for i:= 0 to ClansCount do
             if ClansArray[i] <> nil then
@@ -354,7 +359,7 @@
 
     end;
 
-if not PlacingHogs then
+if (not PlacingHogs) and (not PlacingKings) then
     begin
     if (TotalRoundsReal = -1) then
         TotalRoundsReal:= 0;
@@ -363,7 +368,7 @@
     end;
 
 // Determine clan ID to check to determine whether to increase TotalRoundsPre/TotalRoundsReal
-if (not PlacingHogs) then
+if (not PlacingHogs) and (not PlacingKings) then
     begin
     if SwapClanPre = -1 then
         begin
@@ -424,6 +429,11 @@
         TurnTimeLeft:= 15000
     else TurnTimeLeft:= 0
     end
+else if PlacingKings then
+    if CurrentHedgehog^.King and CurrentHedgehog^.UnplacedKing then
+        TurnTimeLeft:= cHedgehogTurnTime
+    else
+        TurnTimeLeft:= 0
 else
     begin
     if ((GameFlags and gfTagTeam) <> 0) and (not NextClan) then
--- a/hedgewars/uTypes.pas	Mon Jul 08 15:16:05 2019 +0300
+++ b/hedgewars/uTypes.pas	Mon Jul 08 21:44:26 2019 +0200
@@ -420,6 +420,7 @@
             InitialHealth: LongInt; // used for gfResetHealth
             King: boolean;  // Flag for a bunch of hedgehog attributes
             Unplaced: boolean;  // Flag for hog placing mode
+            UnplacedKing: boolean;  // Flag for king placing phase in King Mode
             Timer: Longword;
             HealthBarHealth: LongInt;
             Effects: array[THogEffect] of LongInt;
--- a/hedgewars/uVariables.pas	Mon Jul 08 15:16:05 2019 +0300
+++ b/hedgewars/uVariables.pas	Mon Jul 08 21:44:26 2019 +0200
@@ -2551,6 +2551,7 @@
     SpeechType: Longword;
     SpeechText: shortstring;
     PlacingHogs: boolean; // a convenience flag to indicate placement of hogs is still in progress
+    PlacingKings: boolean; // a convenience flag to indicate placement of kings in King Mode is still in progress
     StepSoundTimer: LongInt;
     StepSoundChannel: LongInt;