Hide team bar if all hedgehogs in it are hidden or dead
authorWuzzy <Wuzzy2@mail.ru>
Fri, 09 Mar 2018 12:43:36 +0100
changeset 13140 e330feceb662
parent 13139 674b76f2d64a
child 13141 8f2260eeb726
Hide team bar if all hedgehogs in it are hidden or dead This fixes some minor spoilers in the campaigns, especially A Classic Fairytale. This only affects hogs hidden with HideHog. Invisible hogs (gstInvisible) don't affect the team bars.
hedgewars/uGearsHandlersMess.pas
hedgewars/uTeams.pas
hedgewars/uVisualGearsHandlers.pas
hedgewars/uWorld.pas
--- a/hedgewars/uGearsHandlersMess.pas	Fri Mar 09 11:32:36 2018 +0100
+++ b/hedgewars/uGearsHandlersMess.pas	Fri Mar 09 12:43:36 2018 +0100
@@ -257,7 +257,8 @@
         Message := Message and (not gmAttack);
     end;
     HH^.GearHidden:= HH^.Gear;
-    HH^.Gear:= nil
+    HH^.Gear:= nil;
+    AddVisualGear(0, 0, vgtTeamHealthSorter);
 end;
 
 
--- a/hedgewars/uTeams.pas	Fri Mar 09 11:32:36 2018 +0100
+++ b/hedgewars/uTeams.pas	Fri Mar 09 12:43:36 2018 +0100
@@ -539,7 +539,8 @@
     HH^.Gear^.State:= (HH^.Gear^.State and (not (gstHHDriven or gstInvisible or gstAttacking))) or gstAttacked;
     AddCI(HH^.Gear);
     HH^.Gear^.Active:= true;
-    ScriptCall('onHogRestore', HH^.Gear^.Uid)
+    ScriptCall('onHogRestore', HH^.Gear^.Uid);
+    AddVisualGear(0, 0, vgtTeamHealthSorter);
 end;
 
 procedure RestoreTeamsFromSave;
--- a/hedgewars/uVisualGearsHandlers.pas	Fri Mar 09 11:32:36 2018 +0100
+++ b/hedgewars/uVisualGearsHandlers.pas	Fri Mar 09 12:43:36 2018 +0100
@@ -561,7 +561,7 @@
 
 procedure doStepTeamHealthSorter(Gear: PVisualGear; Steps: Longword);
 var i: Longword;
-    b: boolean;
+    b, noHogs: boolean;
     t, h: LongInt;
 begin
 {$IFNDEF PAS2C}
@@ -606,12 +606,20 @@
 t:= - 4;
 for i:= 0 to Pred(TeamsCount) do
         with thexchar[i] do
-          if team^.TeamHealth > 0 then
+          begin
+          noHogs:= true;
+          for h:= 0 to cMaxHHIndex do
+              // Check if all hogs are hidden
+              if team^.Hedgehogs[h].Gear <> nil then
+                  noHogs:= false;
+          // Skip team bar if all hogs are dead or hidden
+          if (team^.TeamHealth > 0) and (noHogs = false) then
             begin
             dec(t, team^.Clan^.HealthTex^.h + 2);
             ny:= t;
             dy:= dy - ny
             end;
+          end;
 
 Gear^.Timer:= cSorterWorkTime;
 Gear^.doStep:= @doStepTeamHealthSorterWork;
--- a/hedgewars/uWorld.pas	Fri Mar 09 11:32:36 2018 +0100
+++ b/hedgewars/uWorld.pas	Fri Mar 09 12:43:36 2018 +0100
@@ -1030,6 +1030,7 @@
 var t, i,  h, smallScreenOffset, TeamHealthBarWidth : LongInt;
     r: TSDL_Rect;
     highlight: boolean;
+    hasVisibleHog: boolean;
     htex: PTexture;
 begin
 if TeamsCount * 20 > Longword(cScreenHeight) div 7 then  // take up less screen on small displays
@@ -1042,7 +1043,12 @@
 else smallScreenOffset:= 0;
 for t:= 0 to Pred(TeamsCount) do
     with TeamsArray[t]^ do
-      if TeamHealth > 0 then
+      begin
+      hasVisibleHog:= false;
+      for i:= 0 to cMaxHHIndex do
+          if (Hedgehogs[i].Gear <> nil) then
+              hasVisibleHog:= true;
+      if (TeamHealth > 0) and hasVisibleHog then
         begin
         highlight:= bShowFinger and (CurrentTeam = TeamsArray[t]) and ((RealTicks mod 1000) < 500);
 
@@ -1143,6 +1149,7 @@
             DrawSpriteRotatedF(sprFinger, h, cScreenHeight + DrawHealthY + smallScreenOffset + 2 + SpritesData[sprFinger].Width div 4, 0, 1, -90);
             end;
         end;
+      end;
 if smallScreenOffset <> 0 then
     begin
     SetScale(cDefaultZoomLevel);