- Introduce clans (teams with same color)
authorunc0rr
Tue, 03 Jul 2007 16:09:04 +0000
changeset 549 4278a80140a8
parent 548 ac1e32b538fd
child 550 f6a18d2bab00
- Introduce clans (teams with same color)
hedgewars/CCHandlers.inc
hedgewars/GSHandlers.inc
hedgewars/HHHandlers.inc
hedgewars/uAIMisc.pas
hedgewars/uStore.pas
hedgewars/uTeams.pas
--- a/hedgewars/CCHandlers.inc	Tue Jul 03 14:47:33 2007 +0000
+++ b/hedgewars/CCHandlers.inc	Tue Jul 03 16:09:04 2007 +0000
@@ -47,18 +47,17 @@
 end;
 
 procedure chAddTeam(var s: shortstring);
+var Color: Longword;
 begin
 if isDeveloperMode then
    begin
    ParseCommand('ammstore 93919294221912103323', true);
-   AddTeam;
-
+   val(s, Color);
+   TryDo(Color <> 0, 'Error: black team color', true);
 
-   if GameType in [gmtDemo, gmtSave] then CurrentTeam^.ExtDriven:= true;
-   val(s, CurrentTeam^.Color);
-   TryDo(CurrentTeam^.Color <> 0, 'Error: black team color', true);
-   CurrentTeam^.AdjColor:= CurrentTeam^.Color;
-   AdjustColor(CurrentTeam^.AdjColor)
+   AddTeam(Color);
+
+   if GameType in [gmtDemo, gmtSave] then CurrentTeam^.ExtDriven:= true
    end
 end;
 
--- a/hedgewars/GSHandlers.inc	Tue Jul 03 14:47:33 2007 +0000
+++ b/hedgewars/GSHandlers.inc	Tue Jul 03 16:09:04 2007 +0000
@@ -212,7 +212,7 @@
    end;
 
 str(Gear^.State, s);
-Gear^.Surf:= RenderString(s, PHedgehog(Gear^.Hedgehog)^.Team^.Color, font);
+Gear^.Surf:= RenderString(s, PHedgehog(Gear^.Hedgehog)^.Team^.Clan^.Color, font);
 if hwRound(Gear^.Y) < cWaterLine then Gear^.doStep:= @doStepHealthTagWork
                                  else Gear^.doStep:= @doStepHealthTagWorkUnderWater;
 Gear^.Y:= Gear^.Y - int2hwFloat(Gear^.Surf^.h)
--- a/hedgewars/HHHandlers.inc	Tue Jul 03 14:47:33 2007 +0000
+++ b/hedgewars/HHHandlers.inc	Tue Jul 03 16:09:04 2007 +0000
@@ -115,13 +115,13 @@
                     a:= TAmmoType(Gear^.State);
                     AddAmmo(PHedgehog(HH^.Hedgehog), a);
                     s:= trammo[Ammoz[a].NameId] + '(+' + IntToStr(Ammoz[a].NumberInCase) + ')';
-                    AddCaption(s, PHedgehog(HH^.Hedgehog)^.Team^.Color, capgrpAmmoinfo);
+                    AddCaption(s, PHedgehog(HH^.Hedgehog)^.Team^.Clan^.Color, capgrpAmmoinfo);
                     end;
      posCaseHealth: begin
                     inc(HH^.Health, Gear^.Health);
                     str(Gear^.Health, s);
                     s:= '+' + s;
-                    AddCaption(s, PHedgehog(HH^.Hedgehog)^.Team^.Color, capgrpAmmoinfo);
+                    AddCaption(s, PHedgehog(HH^.Hedgehog)^.Team^.Clan^.Color, capgrpAmmoinfo);
                     RenderHealth(PHedgehog(HH^.Hedgehog)^);
                     RecountTeamHealth(PHedgehog(HH^.Hedgehog)^.Team)
                     end;
--- a/hedgewars/uAIMisc.pas	Tue Jul 03 14:47:33 2007 +0000
+++ b/hedgewars/uAIMisc.pas	Tue Jul 03 16:09:04 2007 +0000
@@ -83,8 +83,8 @@
                   begin
                   Point.X:= hwRound(Gear^.X);
                   Point.Y:= hwRound(Gear^.Y);
-                  if Color <> CurrentTeam^.Color then Score:=  Gear^.Health
-                                                 else Score:= -Gear^.Health
+                  if Clan <> CurrentTeam^.Clan then Score:=  Gear^.Health
+                                               else Score:= -Gear^.Health
                   end;
              inc(Targets.Count)
              end;
@@ -93,7 +93,7 @@
 
 procedure FillBonuses(isAfterAttack: boolean);
 var Gear: PGear;
-    MyColor: Longword;
+    MyClan: PClan;
 
     procedure AddBonus(x, y: LongInt; r: Longword; s: LongInt);
     begin
@@ -107,7 +107,7 @@
 
 begin
 bonuses.Count:= 0;
-MyColor:= PHedgehog(ThinkingHH^.Hedgehog)^.Team^.Color;
+MyClan:= PHedgehog(ThinkingHH^.Hedgehog)^.Team^.Clan;
 Gear:= GearsList;
 while Gear <> nil do
       begin
@@ -119,8 +119,8 @@
            gtHedgehog: begin
                        if Gear^.Damage >= Gear^.Health then AddBonus(hwRound(Gear^.X), hwRound(Gear^.Y), 60, -25) else
                           if isAfterAttack and (ThinkingHH^.Hedgehog <> Gear^.Hedgehog) then
-                             if (MyColor = PHedgehog(Gear^.Hedgehog)^.Team^.Color) then AddBonus(hwRound(Gear^.X), hwRound(Gear^.Y), 150, -3) // hedgehog-friend
-                                                                                   else AddBonus(hwRound(Gear^.X), hwRound(Gear^.Y), 100, 3)
+                             if (MyClan = PHedgehog(Gear^.Hedgehog)^.Team^.Clan) then AddBonus(hwRound(Gear^.X), hwRound(Gear^.Y), 150, -3) // hedgehog-friend
+                                                                                 else AddBonus(hwRound(Gear^.X), hwRound(Gear^.Y), 100, 3)
                        end;
            end;
       Gear:= Gear^.NextGear
--- a/hedgewars/uStore.pas	Tue Jul 03 14:47:33 2007 +0000
+++ b/hedgewars/uStore.pas	Tue Jul 03 16:09:04 2007 +0000
@@ -144,21 +144,21 @@
      with TeamsArray[t]^ do
       begin
       r.w:= 104;
-      NameTag:= RenderString(TeamName, Color, Font);
+      NameTag:= RenderString(TeamName, Clan^.Color, Font);
       r.w:= cTeamHealthWidth + 5;
       r.h:= NameTag^.h;
       DrawRoundRect(@r, cWhiteColor, cColorNearBlack, StoreSurface, true);
       HealthRect:= r;
       rr:= r;
       inc(rr.x, 2); dec(rr.w, 4); inc(rr.y, 2); dec(rr.h, 4);
-      DrawRoundRect(@rr, AdjColor, AdjColor, StoreSurface, false);
+      DrawRoundRect(@rr, Clan^.AdjColor, Clan^.AdjColor, StoreSurface, false);
       inc(r.y, r.h);
       dec(drY, r.h + 2);
       DrawHealthY:= drY;
       for i:= 0 to 7 do
           with Hedgehogs[i] do
                if Gear <> nil then
-                  NameTag:= RenderString(Name, Color, fnt16);
+                  NameTag:= RenderString(Name, Clan^.Color, fnt16);
       end;
     end;
 
@@ -175,7 +175,7 @@
       begin
       CrosshairSurf:= SDL_CreateRGBSurface(SDL_HWSURFACE, tmpsurf^.w, tmpsurf^.h, cBits, PixelFormat^.RMask, PixelFormat^.GMask, PixelFormat^.BMask, PixelFormat^.AMask);
       TryDo(CrosshairSurf <> nil, errmsgCreateSurface, true);
-      SDL_FillRect(CrosshairSurf, nil, AdjColor);
+      SDL_FillRect(CrosshairSurf, nil, Clan^.AdjColor);
       SDL_UpperBlit(tmpsurf, nil, CrosshairSurf, nil);
       TryDo(SDL_SetColorKey(CrosshairSurf, SDL_SRCCOLORKEY or SDL_RLEACCEL, 0) = 0, errmsgTransparentSet, true);
       end;
@@ -453,7 +453,7 @@
 begin
 str(Hedgehog.Gear^.Health, s);
 if Hedgehog.HealthTag <> nil then SDL_FreeSurface(Hedgehog.HealthTag);
-Hedgehog.HealthTag:= RenderString(s, Hedgehog.Team^.Color, fnt16)
+Hedgehog.HealthTag:= RenderString(s, Hedgehog.Team^.Clan^.Color, fnt16)
 end;
 
 function  LoadImage(const filename: string; hasAlpha: boolean; critical, setTransparent: boolean): PSDL_Surface;
--- a/hedgewars/uTeams.pas	Tue Jul 03 14:47:33 2007 +0000
+++ b/hedgewars/uTeams.pas	Tue Jul 03 16:09:04 2007 +0000
@@ -26,6 +26,7 @@
 
 type PHedgehog = ^THedgehog;
      PTeam     = ^TTeam;
+     PClan     = ^TClan;
      THedgehog = record
                  Name: string[MAXNAMELEN];
                  Gear: PGear;
@@ -42,7 +43,7 @@
                  MaxStepDamage: Longword;
                  end;
      TTeam = record
-             Color, AdjColor: Longword;
+             Clan: PClan;
              TeamName: string[MAXNAMELEN];
              ExtDriven: boolean;
              Binds: TBinds;
@@ -59,13 +60,21 @@
              AttackBar: LongWord;
              HedgehogsNumber: byte;
              end;
+     TClan = record
+             Color, AdjColor: Longword;
+             Teams: array[0..Pred(cMaxTeams)] of PTeam;
+             TeamsNumber: Longword;
+             ClanHealth: LongInt;
+             end;
 
 var CurrentTeam: PTeam = nil;
     TeamsArray: array[0..Pred(cMaxTeams)] of PTeam;
     TeamsCount: Longword = 0;
+    ClansArray: array[0..Pred(cMaxTeams)] of PClan;
+    ClansCount: Longword = 0;
     CurMinAngle, CurMaxAngle: Longword;
 
-function AddTeam: PTeam;
+function AddTeam(TeamColor: Longword): PTeam;
 procedure ApplyAmmoChanges(var Hedgehog: THedgehog);
 procedure SwitchHedgehog;
 procedure InitTeams;
@@ -83,16 +92,17 @@
 procedure FreeTeamsList; forward;
 
 function CheckForWin: boolean;
-var team, AliveTeam: PTeam;
+var team: PTeam;
+    AliveClan: PClan;
     s: shortstring;
     t, AliveCount: LongInt;
 begin
 AliveCount:= 0;
-for t:= 0 to Pred(TeamsCount) do
-    if TeamsArray[t]^.TeamHealth > 0 then
+for t:= 0 to Pred(ClansCount) do
+    if ClansArray[t]^.ClanHealth > 0 then
        begin
        inc(AliveCount);
-       AliveTeam:= TeamsArray[t]
+       AliveClan:= ClansArray[t]
        end;
 
 if AliveCount >= 2 then exit(false);
@@ -105,12 +115,17 @@
    SendStat(siGameResult, trmsg[sidDraw]);
    AddGear(0, 0, gtATFinishGame, 0, _0, _0, 2000)
    end else // win
-   begin
-   s:= Format(trmsg[sidWinner], TeamsArray[0]^.TeamName);
-   AddCaption(s, $FFFFFF, capgrpGameState);
-   SendStat(siGameResult, s);
-   AddGear(0, 0, gtATFinishGame, 0, _0, _0, 2000)
-   end;
+   with AliveClan^ do
+     begin
+     if TeamsNumber = 1 then
+        s:= Format(trmsg[sidWinner], Teams[0]^.TeamName)  // team wins
+     else
+        s:= Format(trmsg[sidWinner], Teams[0]^.TeamName); // clan wins
+
+     AddCaption(s, $FFFFFF, capgrpGameState);
+     SendStat(siGameResult, s);
+     AddGear(0, 0, gtATFinishGame, 0, _0, _0, 2000)
+     end;
 SendStats
 end;
 
@@ -167,8 +182,9 @@
 TurnTimeLeft:= cHedgehogTurnTime
 end;
 
-function AddTeam: PTeam;
+function AddTeam(TeamColor: Longword): PTeam;
 var Result: PTeam;
+    c: LongInt;
 begin
 TryDo(TeamsCount <= cMaxTeams, 'Too many teams', true);
 New(Result);
@@ -180,6 +196,31 @@
 TeamsArray[TeamsCount]:= Result;
 inc(TeamsCount);
 
+c:= Pred(ClansCount);
+while (c >= 0) and (ClansArray[c]^.Color <> TeamColor) do dec(c);
+if c < 0 then
+   begin
+   new(Result^.Clan);
+   FillChar(Result^.Clan^, sizeof(TClan), 0);
+   ClansArray[ClansCount]:= Result^.Clan;
+   inc(ClansCount);
+   with Result^.Clan^ do
+        begin
+        Color:= TeamColor;
+        AdjColor:= Color;
+        AdjustColor(AdjColor);
+        end
+   end else
+   begin
+   Result^.Clan:= ClansArray[c];
+   end;
+
+with Result^.Clan^ do
+    begin
+    Teams[TeamsNumber]:= Result;
+    inc(TeamsNumber)
+    end;
+
 CurrentTeam:= Result;
 AddTeam:= Result
 end;
@@ -244,7 +285,7 @@
         s:= s + ' (' + IntToStr(Count) + ')';
      if (Propz and ammoprop_Timerable) <> 0 then
         s:= s + ', ' + inttostr(Timer div 1000) + ' ' + trammo[sidSeconds];
-     AddCaption(s, Team^.Color, capgrpAmmoinfo);
+     AddCaption(s, Team^.Clan^.Color, capgrpAmmoinfo);
      if (Propz and ammoprop_NeedTarget) <> 0
         then begin
         Gear^.State:= Gear^.State or      gstHHChooseTarget;
@@ -267,6 +308,17 @@
 TeamSize:= Result
 end;
 
+procedure RecountClanHealth(clan: PClan);
+var i: LongInt;
+begin
+with clan^ do
+    begin
+    ClanHealth:= 0;
+    for i:= 0 to Pred(TeamsNumber) do
+        inc(ClanHealth, Teams[i]^.TeamHealth)
+    end
+end;
+
 procedure RecountTeamHealth(team: PTeam);
 var i: LongInt;
 begin
@@ -283,6 +335,9 @@
         RecountAllTeamsHealth;
         end else TeamHealthBarWidth:= (TeamHealthBarWidth * cTeamHealthWidth) div MaxTeamHealth
      end;
+
+RecountClanHealth(team^.Clan);
+
 // FIXME: at the game init, gtTeamHealthSorters are created for each team, and they work simultaneously
 AddGear(0, 0, gtTeamHealthSorter, 0, _0, _0, 0)
 end;