# HG changeset patch
# User Wuzzy <Wuzzy2@mail.ru>
# Date 1558872995 -7200
# Node ID 1a754860b0e5d0ef1e889b9089351a7013ca2826
# Parent  a9873c81b5e633501693156046e8d92ed732aedf
Refactor definition of "local" clans

diff -r a9873c81b5e6 -r 1a754860b0e5 hedgewars/uGearsUtils.pas
--- a/hedgewars/uGearsUtils.pas	Sat May 25 18:18:42 2019 +0300
+++ b/hedgewars/uGearsUtils.pas	Sun May 26 14:16:35 2019 +0200
@@ -1869,7 +1869,7 @@
 
 function IsHogLocal(HH: PHedgehog): boolean;
 begin
-    IsHogLocal:= (not (HH^.Team^.ExtDriven or (HH^.BotLevel > 0))) or (HH^.Team^.Clan^.ClanIndex = LocalClan) or (GameType = gmtDemo);
+    IsHogLocal:= (not (HH^.Team^.ExtDriven or (HH^.BotLevel > 0))) or (HH^.Team^.Clan^.LocalOrAlly) or (GameType = gmtDemo);
 end;
 
 end.
diff -r a9873c81b5e6 -r 1a754860b0e5 hedgewars/uTeams.pas
--- a/hedgewars/uTeams.pas	Sat May 25 18:18:42 2019 +0300
+++ b/hedgewars/uTeams.pas	Sun May 26 14:16:35 2019 +0200
@@ -522,6 +522,7 @@
         Color:= TeamColor;
         TagTeamIndex:= 0;
         Flawless:= true;
+        LocalOrAlly:= false;
         DeathLogged:= false;
         StatsHandled:= false;
         end
@@ -562,7 +563,7 @@
         begin
         if (not ExtDriven) and (Hedgehogs[0].BotLevel = 0) then
             begin
-            LocalClan:= Clan^.ClanIndex;
+            Clan^.LocalOrAlly:= true;
             LocalTeam:= t;
             LocalAmmo:= Hedgehogs[0].AmmoStore
             end;
@@ -1082,7 +1083,6 @@
 CurrentHedgehog:= nil;
 TeamsCount:= 0;
 ClansCount:= 0;
-LocalClan:= -1;
 LocalTeam:= -1;
 LocalAmmo:= -1;
 TeamsGameOver:= false;
diff -r a9873c81b5e6 -r 1a754860b0e5 hedgewars/uTypes.pas
--- a/hedgewars/uTypes.pas	Sat May 25 18:18:42 2019 +0300
+++ b/hedgewars/uTypes.pas	Sun May 26 14:16:35 2019 +0200
@@ -476,6 +476,7 @@
             StatsHandled : boolean; // true if clan's rank has been handled for stats screen
             Flawless: boolean;
             Passive: boolean; // informational. Must be set to true if all of the teams are passive
+            LocalOrAlly: boolean; // true if at least 1 team in the clan is a local team. A local team is a non-extdriven team controlled by a human
             end;
 
      cdeclPtr = procedure; cdecl;
diff -r a9873c81b5e6 -r 1a754860b0e5 hedgewars/uVariables.pas
--- a/hedgewars/uVariables.pas	Sat May 25 18:18:42 2019 +0300
+++ b/hedgewars/uVariables.pas	Sun May 26 14:16:35 2019 +0200
@@ -2557,7 +2557,6 @@
     VisibleTeamsCount: Longword; // number of teams visible in team bar
     ClansArray, SpawnClansArray: TClansArray;
     ClansCount: Longword;
-    LocalClan: LongInt;  // last non-bot, non-extdriven clan
     LocalTeam: LongInt;  // last non-bot, non-extdriven clan first team
     LocalAmmo: LongInt;  // last non-bot, non-extdriven clan's first team's ammo index, updated to next upcoming hog for per-hog-ammo
     CurMinAngle, CurMaxAngle: Longword;
diff -r a9873c81b5e6 -r 1a754860b0e5 hedgewars/uWorld.pas
--- a/hedgewars/uWorld.pas	Sat May 25 18:18:42 2019 +0300
+++ b/hedgewars/uWorld.pas	Sun May 26 14:16:35 2019 +0200
@@ -173,10 +173,6 @@
             ClansArray[t]:= cp;
             ClansArray[t]^.ClanIndex:= t;
             ClansArray[0]^.ClanIndex:= 0;
-            if (LocalClan = t) then
-                LocalClan:= 0
-            else if (LocalClan = 0) then
-                LocalClan:= t
             end;
         end;
     CurrentTeam:= ClansArray[0]^.Teams[0];