Show team health bars, without sorting yet
authorunc0rr
Thu, 12 Jan 2006 16:33:26 +0000
changeset 47 8daf1ee0b9a3
parent 46 c99140d2355a
child 48 0f396d0c429d
Show team health bars, without sorting yet
hedgewars/HHHandlers.inc
hedgewars/uGears.pas
hedgewars/uMisc.pas
hedgewars/uStore.pas
hedgewars/uTeams.pas
hedgewars/uWorld.pas
--- a/hedgewars/HHHandlers.inc	Wed Jan 11 20:01:36 2006 +0000
+++ b/hedgewars/HHHandlers.inc	Thu Jan 12 16:33:26 2006 +0000
@@ -1,6 +1,6 @@
 (*
  * Hedgewars, a worms-like game
- * Copyright (c) 2004, 2005 Andrey Korotaev <unC0Rr@gmail.com>
+ * Copyright (c) 2004, 2005, 2006 Andrey Korotaev <unC0Rr@gmail.com>
  *
  * Distributed under the terms of the BSD-modified licence:
  *
@@ -176,7 +176,8 @@
 case Gear.Pos of
      posCaseHealth: begin
                     inc(HH.Health, Gear.Health);
-                    RenderHealth(PHedgehog(HH.Hedgehog)^)
+                    RenderHealth(PHedgehog(HH.Hedgehog)^);
+                    RecountTeamHealth(PHedgehog(HH.Hedgehog)^.Team)
                     end;
      end;
 end;
--- a/hedgewars/uGears.pas	Wed Jan 11 20:01:36 2006 +0000
+++ b/hedgewars/uGears.pas	Thu Jan 12 16:33:26 2006 +0000
@@ -1,6 +1,6 @@
 (*
  * Hedgewars, a worms-like game
- * Copyright (c) 2004, 2005 Andrey Korotaev <unC0Rr@gmail.com>
+ * Copyright (c) 2004, 2005, 2006 Andrey Korotaev <unC0Rr@gmail.com>
  *
  * Distributed under the terms of the BSD-modified licence:
  *
@@ -237,7 +237,11 @@
       Gear.Message:= gm_Destroy;
       CurAmmoGear.Message:= gm_Destroy;
       exit
-      end else PHedgehog(Gear.Hedgehog).Gear:= nil;
+      end else
+      begin
+      RecountTeamHealth(PHedgehog(Gear.Hedgehog).Team);
+      PHedgehog(Gear.Hedgehog).Gear:= nil;
+      end;
 if CurAmmoGear = Gear then
    CurAmmoGear:= nil;
 if FollowGear = Gear then FollowGear:= nil;
@@ -266,6 +270,7 @@
                                          else dec(Gear.Health, Gear.Damage);
             AddGear(Round(Gear.X), Round(Gear.Y) - 32, gtHealthTag, Gear.Damage).Hedgehog:= Gear.Hedgehog;
             RenderHealth(PHedgehog(Gear.Hedgehog)^);
+            RecountTeamHealth(PHedgehog(Gear.Hedgehog)^.Team);
             
             Gear.Damage:= 0
             end;
--- a/hedgewars/uMisc.pas	Wed Jan 11 20:01:36 2006 +0000
+++ b/hedgewars/uMisc.pas	Thu Jan 12 16:33:26 2006 +0000
@@ -1,6 +1,6 @@
 (*
  * Hedgewars, a worms-like game
- * Copyright (c) 2004, 2005 Andrey Korotaev <unC0Rr@gmail.com>
+ * Copyright (c) 2004, 2005, 2006 Andrey Korotaev <unC0Rr@gmail.com>
  *
  * Distributed under the terms of the BSD-modified licence:
  *
@@ -58,6 +58,7 @@
     cWaterLine       : integer = 1024;
     cVisibleWater    : integer = 64;
     cScreenEdgesDist : integer = 240;
+    cTeamHealthWidth : integer = 128;
 
     GameTicks     : LongWord = 0;
 
--- a/hedgewars/uStore.pas	Wed Jan 11 20:01:36 2006 +0000
+++ b/hedgewars/uStore.pas	Thu Jan 12 16:33:26 2006 +0000
@@ -1,6 +1,6 @@
 (*
  * Hedgewars, a worms-like game
- * Copyright (c) 2004, 2005 Andrey Korotaev <unC0Rr@gmail.com>
+ * Copyright (c) 2004, 2005, 2006 Andrey Korotaev <unC0Rr@gmail.com>
  *
  * Distributed under the terms of the BSD-modified licence:
  *
@@ -51,6 +51,7 @@
 procedure DrawLand (X, Y: integer; Surface: PSDL_Surface);
 procedure DXOutText(X, Y: Integer; Font: THWFont; s: string; Surface: PSDL_Surface);
 procedure DrawCaption(X, Y: integer; Rect: TSDL_Rect; Surface: PSDL_Surface; const fromTempSurf: boolean = false);
+procedure DrawFromStoreRect(X, Y: integer; Rect: PSDL_Rect; Surface: PSDL_Surface);
 procedure DrawHedgehog(X, Y: integer; Dir: integer; Pos, Step: LongWord; Surface: PSDL_Surface);
 procedure DrawExplosion(X, Y, Radius: integer);
 procedure DrawHLinesExplosions(ar: PRangeArray; Radius: Longword; y, dY: integer; Count: Byte);
@@ -283,6 +284,31 @@
   SDL_FreeSurface(tmpsurf);
 end;
 
+procedure DrawRoundRect(rect: PSDL_Rect; BorderColor, FillColor: Longword; Surface: PSDL_Surface);
+var r: TSDL_Rect;
+begin
+r:= rect^;
+SDL_FillRect(Surface, @r, 0);
+r.y:= rect.y + 1;
+r.h:= rect.h - 2;
+SDL_FillRect(Surface, @r, BorderColor);
+r.x:= rect.x + 1;
+r.w:= rect.w - 2;
+r.y:= rect.y;
+r.h:= rect.h;
+SDL_FillRect(Surface, @r, BorderColor);
+r.x:= rect.x + 2;
+r.y:= rect.y + 1;
+r.w:= rect.w - 4;
+r.h:= rect.h - 2;
+SDL_FillRect(Surface, @r, FillColor);
+r.x:= rect.x + 1;
+r.y:= rect.y + 2;
+r.w:= rect.w - 2;
+r.h:= rect.h - 4;
+SDL_FillRect(Surface, @r, FillColor)
+end;
+
 function WriteInRoundRect(Surface: PSDL_Surface; X, Y: integer; Color: LongWord; Font: THWFont; s: string): TSDL_Rect;
 var w, h: integer;
     tmpsurf: PSDL_Surface;
@@ -293,24 +319,7 @@
 Result.y:= Y;
 Result.w:= w + 6;
 Result.h:= h + 6;
-SDL_FillRect(Surface, @Result, 0);
-Result.w:= 1;
-Result.y:= Y + 1;
-Result.h:= h + 4;
-SDL_FillRect(Surface, @Result, cWhiteColor);
-Result.x:= X + w + 5;
-SDL_FillRect(Surface, @Result, cWhiteColor);
-Result.x:= X + 1;
-Result.w:= w + 4;
-Result.y:= Y;
-Result.h:= 1;
-SDL_FillRect(Surface, @Result, cWhiteColor);
-Result.y:= Y + h + 5;
-SDL_FillRect(Surface, @Result, cWhiteColor);
-Result.x:= X + 1;
-Result.y:= Y + 1;
-Result.h:= h + 4;
-SDL_FillRect(Surface, @Result, cColorNearBlack);
+DrawRoundRect(@Result, cWhiteColor, cColorNearBlack, Surface);
 SDL_GetRGB(Color, Surface.format, @clr.r, @clr.g, @clr.b);
 tmpsurf:= TTF_RenderText_Blended(Fontz[Font].Handle, PChar(s), clr);
 Result.x:= X + 3;
@@ -333,17 +342,24 @@
     procedure WriteNames(Font: THWFont);
     var Team: PTeam;
         i: integer;
-        r: TSDL_Rect;
+        r, rr: TSDL_Rect;
     begin
     r.x:= 0;
     r.y:= 272;
     Team:= TeamsList;
     while Team<>nil do
       begin
-      r.w:= 1968;
+      r.w:= 104;
       r:= WriteInRoundRect(StoreSurface, r.x, r.y, Team.Color, Font, Team.TeamName);
       Team.NameRect:= r;
       inc(r.y, r.h);
+      r.w:= cTeamHealthWidth + 5;
+      DrawRoundRect(@r, cWhiteColor, cColorNearBlack, StoreSurface);
+      Team.HealthRect:= r;
+      rr:= r;
+      inc(rr.x, 2); dec(rr.w, 4); inc(rr.y, 2); dec(rr.h, 4);
+      DrawRoundRect(@rr, Team.Color, Team.Color, StoreSurface);
+      inc(r.y, r.h);
       for i:= 0 to 7 do
           if Team.Hedgehogs[i].Gear<>nil then
              begin
@@ -588,6 +604,11 @@
 DrawFromRect(X, Y, @r, LandSurface, Surface)
 end;
 
+procedure DrawFromStoreRect(X, Y: integer; Rect: PSDL_Rect; Surface: PSDL_Surface);
+begin
+DrawFromRect(X, Y, Rect, StoreSurface, Surface)
+end;
+
 procedure DrawCaption(X, Y: integer; Rect: TSDL_Rect; Surface: PSDL_Surface; const fromTempSurf: boolean = false);
 begin
 if fromTempSurf then DrawFromRect(X - (Rect.w) div 2, Y, @Rect, TempSurface,  Surface)
--- a/hedgewars/uTeams.pas	Wed Jan 11 20:01:36 2006 +0000
+++ b/hedgewars/uTeams.pas	Thu Jan 12 16:33:26 2006 +0000
@@ -1,6 +1,6 @@
 (*
  * Hedgewars, a worms-like game
- * Copyright (c) 2004, 2005 Andrey Korotaev <unC0Rr@gmail.com>
+ * Copyright (c) 2004, 2005, 2006 Andrey Korotaev <unC0Rr@gmail.com>
  *
  * Distributed under the terms of the BSD-modified licence:
  *
@@ -60,9 +60,11 @@
              Hedgehogs: array[0..cMaxHHIndex] of THedgehog;
              Ammos: array[0..cMaxHHIndex] of THHAmmo;
              CurrHedgehog: integer;
-             NameRect, CrossHairRect, GraveRect: TSDL_Rect;
+             NameRect, CrossHairRect,
+             GraveRect, HealthRect: TSDL_Rect;
              GraveName: string;
              FortName: string;
+             TeamHealth: integer;
              AttackBar: LongWord;
              end;
 
@@ -75,9 +77,11 @@
 procedure InitTeams;
 procedure OnUsedAmmo(Ammo: PHHAmmo);
 function  TeamSize(p: PTeam): Longword;
+procedure RecountTeamHealth(team: PTeam);
 
 implementation
 uses uMisc, uStore, uWorld, uIO, uAIActions;
+const MaxTeamHealth: integer = 0;
 
 procedure FreeTeamsList; forward;
 
@@ -178,31 +182,47 @@
     end;
 end;
 
-procedure InitTeams;
+procedure RecountAllTeamsHealth;
 var p: PTeam;
-    i: integer;
 begin
 p:= TeamsList;
 while p <> nil do
       begin
+      RecountTeamHealth(p);
+      p:= p.Next
+      end
+end;
+
+procedure InitTeams;
+var p: PTeam;
+    i: integer;
+    th: integer;
+begin
+p:= TeamsList;
+while p <> nil do
+      begin
+      th:= 0;
       FillAmmoGroup(@p.Ammos[0]);
       for i:= 0 to cMaxHHIndex do
           if p.Hedgehogs[i].Gear <> nil then
              begin
              p.Hedgehogs[i].Gear.Health:= 100;
+             inc(th, 100);
              p.Hedgehogs[i].Ammo:= @p.Ammos[0] // 0 means all hedgehogs
              // will have common set of ammo
              end;
+      if th > MaxTeamHealth then MaxTeamHealth:= th;
       p:= p.Next
       end;
 SetFirstTurnHedgehog;
+RecountAllTeamsHealth
 end;
 
 procedure ApplyAmmoChanges(Hedgehog: PHedgehog);
 var s: shortstring;
 begin
 with Hedgehog^ do
-     begin     
+     begin
      if Ammo[CurSlot, CurAmmo].Count = 0 then
         begin
         CurAmmo:= 0;
@@ -273,6 +293,23 @@
     if p.Hedgehogs[i].Gear <> nil then inc(Result)
 end;
 
+procedure RecountTeamHealth(team: PTeam);
+var i: integer;
+begin
+with team^ do
+     begin
+     TeamHealth:= 0;
+     for i:= 0 to cMaxHHIndex do
+         if Hedgehogs[i].Gear <> nil then
+            inc(TeamHealth, Hedgehogs[i].Gear.Health);
+     if TeamHealth > MaxTeamHealth then
+        begin
+        MaxTeamHealth:= TeamHealth;
+        RecountAllTeamsHealth;
+        end else TeamHealth:= (TeamHealth * cTeamHealthWidth) div MaxTeamHealth
+     end
+end;
+
 initialization
 
 finalization
--- a/hedgewars/uWorld.pas	Wed Jan 11 20:01:36 2006 +0000
+++ b/hedgewars/uWorld.pas	Thu Jan 12 16:33:26 2006 +0000
@@ -1,6 +1,6 @@
 (*
  * Hedgewars, a worms-like game
- * Copyright (c) 2004, 2005 Andrey Korotaev <unC0Rr@gmail.com>
+ * Copyright (c) 2004, 2005, 2006 Andrey Korotaev <unC0Rr@gmail.com>
  *
  * Distributed under the terms of the BSD-modified licence:
  *
@@ -199,6 +199,25 @@
     Captions[Pred(cMaxCaptions)].EndTime:= 0
     end;
 
+// Teams Healths
+team:= TeamsList;
+i:= cSCreenHeight - 32;
+while team <> nil do
+      begin
+      DrawFromStoreRect(cScreenWidth div 2 - team.NameRect.w - 3, i,
+                        @team.NameRect, Surface);
+      r:= team.HealthRect;
+      r.w:= 3 + team.TeamHealth;
+      DrawFromStoreRect(cScreenWidth div 2, i,
+                        @r, Surface);
+      inc(r.x, cTeamHealthWidth + 3);
+      r.w:= 2;
+      DrawFromStoreRect(cScreenWidth div 2 + team.TeamHealth + 3, i,
+                        @r, Surface);
+      dec(i, team.HealthRect.h + 2);
+      team:= team.Next
+      end;
+
 // Lag alert
 if isInLag then DrawSprite(sprLag, 32, 32  + cConsoleYAdd, (RealTicks shr 7) mod 7, Surface);