Animate hedgehogs healths inside team health bar. Proper animation for the case when max team health grows is lost though.
authorunc0rr
Thu, 28 Nov 2013 00:41:35 +0400
changeset 9720 453a1c29b7e4
parent 9719 cbdef918d087
child 9721 1833dadcebf0
Animate hedgehogs healths inside team health bar. Proper animation for the case when max team health grows is lost though.
hedgewars/uTeams.pas
hedgewars/uTypes.pas
hedgewars/uVisualGearsHandlers.pas
hedgewars/uWorld.pas
--- a/hedgewars/uTeams.pas	Wed Nov 27 19:10:53 2013 +0100
+++ b/hedgewars/uTeams.pas	Thu Nov 28 00:41:35 2013 +0400
@@ -41,13 +41,14 @@
 procedure TeamGoneEffect(var Team: TTeam);
 procedure SwitchCurrentHedgehog(newHog: PHedgehog);
 
+var MaxTeamHealth: LongInt;
+
 implementation
 uses uLocale, uAmmos, uChat, uVariables, uUtils, uIO, uCaptions, uCommands, uDebug,
     uGearsUtils, uGearsList, uVisualGearsList, uTextures
     {$IFDEF USE_TOUCH_INTERFACE}, uTouch{$ENDIF};
 
-var MaxTeamHealth: LongInt;
-    GameOver: boolean;
+var GameOver: boolean;
     NextClan: boolean;
 
 function CheckForWin: boolean;
@@ -480,17 +481,11 @@
         else if Hedgehogs[i].GearHidden <> nil then
             inc(TeamHealth, Hedgehogs[i].GearHidden^.Health);
 
-    if not hasGone then
-        NewTeamHealthBarWidth:= TeamHealth
-        else
-        NewTeamHealthBarWidth:= 0;
-
-    if NewTeamHealthBarWidth > MaxTeamHealth then
+    if TeamHealth > MaxTeamHealth then
         begin
-        MaxTeamHealth:= NewTeamHealthBarWidth;
+        MaxTeamHealth:= TeamHealth;
         RecountAllTeamsHealth;
-        end else if NewTeamHealthBarWidth > 0 then
-            NewTeamHealthBarWidth:= (NewTeamHealthBarWidth * cTeamHealthWidth) div MaxTeamHealth
+        end
     end;
 
 RecountClanHealth(team^.Clan);
--- a/hedgewars/uTypes.pas	Wed Nov 27 19:10:53 2013 +0100
+++ b/hedgewars/uTypes.pas	Thu Nov 28 00:41:35 2013 +0400
@@ -369,6 +369,7 @@
             King: boolean;  // Flag for a bunch of hedgehog attributes
             Unplaced: boolean;  // Flag for hog placing mode
             Timer: Longword;
+            HealthBarHealth: LongInt;
             Effects: array[THogEffect] of LongInt;
             end;
 
@@ -387,8 +388,7 @@
             GraveName: shortstring;
             FortName: shortstring;
             TeamHealth: LongInt;
-            TeamHealthBarWidth,
-            NewTeamHealthBarWidth: LongInt;
+            TeamHealthBarHealth: LongInt;
             DrawHealthY: LongInt;
             AttackBar: LongWord;
             HedgehogsNumber: Longword;
--- a/hedgewars/uVisualGearsHandlers.pas	Wed Nov 27 19:10:53 2013 +0100
+++ b/hedgewars/uVisualGearsHandlers.pas	Thu Nov 28 00:41:35 2013 +0400
@@ -71,6 +71,7 @@
 procedure doStepSmoothWindBar(Gear: PVisualGear; Steps: Longword);
 procedure doStepStraightShot(Gear: PVisualGear; Steps: Longword);
 
+function isSorterActive: boolean; inline;
 procedure initModule;
 
 implementation
@@ -481,11 +482,17 @@
             dy, ny, dw: LongInt;
             team: PTeam;
             SortFactor: QWord;
+            hdw: array[0..cMaxHHIndex] of LongInt;
             end;
     currsorter: PVisualGear = nil;
 
+function isSorterActive: boolean; inline;
+begin
+    isSorterActive:= currsorter <> nil
+end;
+
 procedure doStepTeamHealthSorterWork(Gear: PVisualGear; Steps: Longword);
-var i, t: LongInt;
+var i, t, h: LongInt;
 begin
 for t:= 1 to min(Steps, Gear^.Timer) do
     begin
@@ -496,7 +503,13 @@
                 begin
                 {$WARNINGS OFF}
                 team^.DrawHealthY:= ny + dy * LongInt(Gear^.Timer) div cSorterWorkTime;
-                team^.TeamHealthBarWidth:= team^.NewTeamHealthBarWidth + dw * LongInt(Gear^.Timer) div cSorterWorkTime;
+                team^.TeamHealthBarHealth:= team^.TeamHealth + dw * LongInt(Gear^.Timer) div cSorterWorkTime;
+
+                for h:= 0 to cMaxHHIndex do
+                    if (team^.Hedgehogs[h].Gear <> nil) then
+                        team^.Hedgehogs[h].HealthBarHealth:= team^.Hedgehogs[h].Gear^.Health + hdw[h] * LongInt(Gear^.Timer) div cSorterWorkTime
+                    else
+                        team^.Hedgehogs[h].HealthBarHealth:= hdw[h] * LongInt(Gear^.Timer) div cSorterWorkTime;
                 {$WARNINGS ON}
                 end;
     end;
@@ -513,7 +526,7 @@
 procedure doStepTeamHealthSorter(Gear: PVisualGear; Steps: Longword);
 var i: Longword;
     b: boolean;
-    t: LongInt;
+    t, h: LongInt;
 begin
 Steps:= Steps; // avoid compiler hint
 
@@ -522,7 +535,7 @@
         begin
         team:= TeamsArray[t];
         dy:= team^.DrawHealthY;
-        dw:= team^.TeamHealthBarWidth - team^.NewTeamHealthBarWidth;
+        dw:= team^.TeamHealthBarHealth - team^.TeamHealth;
         if team^.TeamHealth > 0 then
             begin
             SortFactor:= team^.Clan^.ClanHealth;
@@ -531,6 +544,12 @@
             end
         else
             SortFactor:= 0;
+
+        for h:= 0 to cMaxHHIndex do
+            if (team^.Hedgehogs[h].Gear <> nil) then
+                hdw[h]:= team^.Hedgehogs[h].HealthBarHealth - team^.Hedgehogs[h].Gear^.Health
+            else
+                hdw[h]:= team^.Hedgehogs[h].HealthBarHealth;
         end;
 
 if TeamsCount > 1 then
--- a/hedgewars/uWorld.pas	Wed Nov 27 19:10:53 2013 +0100
+++ b/hedgewars/uWorld.pas	Thu Nov 28 00:41:35 2013 +0400
@@ -60,9 +60,10 @@
     , uCaptions
     , uCursor
     , uCommands
-{$IFDEF USE_VIDEO_RECORDING}    
+    , uTeams
+{$IFDEF USE_VIDEO_RECORDING}
     , uVideoRec
-{$ENDIF}    
+{$ENDIF}
     ;
 
 var cWaveWidth, cWaveHeight: LongInt;
@@ -1231,7 +1232,7 @@
 
 
 procedure RenderTeamsHealth;
-var t, i, h, smallScreenOffset : LongInt;
+var t, i, h, smallScreenOffset, TeamHealthBarWidth : LongInt;
     r: TSDL_Rect;
     highlight: boolean;
     htex: PTexture;
@@ -1248,7 +1249,6 @@
     with TeamsArray[t]^ do
       if TeamHealth > 0 then
         begin
-        h:= 0;
         highlight:= bShowFinger and (CurrentTeam = TeamsArray[t]) and ((RealTicks mod 1000) < 500);
 
         if highlight then
@@ -1265,6 +1265,8 @@
         // draw flag
         DrawTexture(-14, cScreenHeight + DrawHealthY + smallScreenOffset, FlagTex);
 
+        TeamHealthBarWidth:= cTeamHealthWidth * TeamHealthBarHealth div MaxTeamHealth;
+
         // draw health bar
         r.x:= 0;
         r.y:= 0;
@@ -1277,13 +1279,14 @@
         r.w:= 3;
         DrawTextureFromRect(TeamHealthBarWidth + 15, cScreenHeight + DrawHealthY + smallScreenOffset, @r, htex);
 
+        h:= 0;
         if not hasGone then
             for i:= 0 to cMaxHHIndex do
-                if Hedgehogs[i].Gear <> nil then
-                    begin
-                    inc(h,Hedgehogs[i].Gear^.Health);
-                    if h < TeamHealth then DrawTexture(15 + h*TeamHealthBarWidth div TeamHealth, cScreenHeight + DrawHealthY + smallScreenOffset + 1, SpritesData[sprSlider].Texture);
-                    end;
+                begin
+                inc(h, Hedgehogs[i].HealthBarHealth);
+                if (h < TeamHealthBarHealth) and (Hedgehogs[i].HealthBarHealth > 0) then 
+                    DrawTexture(15 + h * TeamHealthBarWidth div TeamHealthBarHealth, cScreenHeight + DrawHealthY + smallScreenOffset + 1, SpritesData[sprSlider].Texture);
+                end;
 
         // draw ai kill counter for gfAISurvival
         if (GameFlags and gfAISurvival) <> 0 then