private void GameEntityRepositoryService_GameEntityRepositoryChange(object sender, GameEntityRepositoryChangeEventArgs e)
 {
     if (e.Action == GameEntityRepositoryChangeAction.Add)
     {
         IGameEntity gameEntity;
         if (this.gameEntityRepositoryService.TryGetValue(e.GameEntityGuid, out gameEntity))
         {
             if (gameEntity is IGameEntityWithLineOfSight)
             {
                 Diagnostics.Assert(this.gameEntities != null);
                 IGameEntityWithLineOfSight gameEntityWithLineOfSight = gameEntity as IGameEntityWithLineOfSight;
                 gameEntityWithLineOfSight.LineOfSightData = new LineOfSightData();
                 this.gameEntities.Add(gameEntityWithLineOfSight);
                 MajorEmpire majorEmpire = gameEntityWithLineOfSight.Empire as MajorEmpire;
                 if (majorEmpire != null)
                 {
                     this.NeedRefreshBits |= majorEmpire.Bits;
                     this.NeedRefreshBits |= gameEntityWithLineOfSight.EmpireInfiltrationBits;
                 }
             }
             if (gameEntity is IGameEntityWithSharedSight)
             {
                 this.sharedSightGameEntities.Add(gameEntity as IGameEntityWithSharedSight);
                 this.forceRefreshSharedVibility = true;
             }
             if (gameEntity is IVisibilityProvider)
             {
                 Diagnostics.Assert(this.visibilityProviders != null);
                 IVisibilityProvider visibilityProvider = gameEntity as IVisibilityProvider;
                 if (visibilityProvider.LineOfSightEntities != null)
                 {
                     foreach (ILineOfSightEntity lineOfSightEntity in visibilityProvider.LineOfSightEntities)
                     {
                         lineOfSightEntity.LineOfSightData  = new LineOfSightData();
                         lineOfSightEntity.LineOfSightDirty = true;
                     }
                 }
                 visibilityProvider.VisibilityDirty = true;
                 this.visibilityProviders.Add(visibilityProvider);
                 return;
             }
         }
     }
     else if (e.Action == GameEntityRepositoryChangeAction.Remove)
     {
         IGameEntityWithLineOfSight gameEntityWithLineOfSight2 = this.gameEntities.Find((IGameEntityWithLineOfSight entity) => entity.GUID == e.GameEntityGuid);
         if (gameEntityWithLineOfSight2 != null)
         {
             Diagnostics.Assert(this.gameEntities.Count((IGameEntityWithLineOfSight entity) => entity.GUID == e.GameEntityGuid) <= 1, "There must be 1 instance max for a guid in the gameEntities list.");
             this.gameEntities.Remove(gameEntityWithLineOfSight2);
             MajorEmpire majorEmpire2 = gameEntityWithLineOfSight2.Empire as MajorEmpire;
             if (majorEmpire2 != null)
             {
                 this.NeedRefreshBits |= majorEmpire2.Bits;
                 this.NeedRefreshBits |= gameEntityWithLineOfSight2.EmpireInfiltrationBits;
             }
         }
         IGameEntityWithSharedSight item = this.sharedSightGameEntities.Find((IGameEntityWithSharedSight entity) => entity.GUID == e.GameEntityGuid);
         if (gameEntityWithLineOfSight2 != null)
         {
             this.sharedSightGameEntities.Remove(item);
             this.forceRefreshSharedVibility = true;
         }
         if (this.visibilityProviders != null)
         {
             IVisibilityProvider visibilityProvider2 = this.visibilityProviders.Find((IVisibilityProvider entity) => entity.GUID == e.GameEntityGuid);
             if (visibilityProvider2 != null)
             {
                 this.visibilityProviders.Remove(visibilityProvider2);
                 if (visibilityProvider2.VisibilityEmpires != null)
                 {
                     foreach (Empire empire in visibilityProvider2.VisibilityEmpires)
                     {
                         if (empire is MajorEmpire)
                         {
                             this.NeedRefreshBits |= empire.Bits;
                         }
                     }
                 }
                 if (ELCPUtilities.SpectatorMode)
                 {
                     foreach (int num in ELCPUtilities.EliminatedEmpireIndices)
                     {
                         this.NeedRefreshBits |= base.Game.Empires[num].Bits;
                     }
                 }
             }
         }
     }
 }
    private bool EvaluateVisibilityRefresh()
    {
        if (this.NeedRefreshBits == 0)
        {
            for (int i = 0; i < this.gameEntities.Count; i++)
            {
                IGameEntityWithLineOfSight gameEntityWithLineOfSight = this.gameEntities[i];
                if (gameEntityWithLineOfSight.LineOfSightActive && gameEntityWithLineOfSight.LineOfSightDirty)
                {
                    MajorEmpire majorEmpire = gameEntityWithLineOfSight.Empire as MajorEmpire;
                    if (majorEmpire != null)
                    {
                        this.NeedRefreshBits |= majorEmpire.Bits;
                        this.NeedRefreshBits |= gameEntityWithLineOfSight.EmpireInfiltrationBits;
                    }
                }
            }
            int j = 0;
            while (j < this.visibilityProviders.Count)
            {
                if (!this.visibilityProviders[j].VisibilityDirty)
                {
                    foreach (ILineOfSightEntity lineOfSightEntity in this.visibilityProviders[j].LineOfSightEntities)
                    {
                        if (lineOfSightEntity.LineOfSightActive && lineOfSightEntity.LineOfSightDirty)
                        {
                            MajorEmpire majorEmpire2 = lineOfSightEntity.Empire as MajorEmpire;
                            if (majorEmpire2 != null)
                            {
                                this.NeedRefreshBits |= majorEmpire2.Bits;
                                this.NeedRefreshBits |= lineOfSightEntity.EmpireInfiltrationBits;
                            }
                        }
                    }
                    using (IEnumerator <IVisibilityArea> enumerator2 = this.visibilityProviders[j].VisibleAreas.GetEnumerator())
                    {
                        while (enumerator2.MoveNext())
                        {
                            IVisibilityArea visibilityArea = enumerator2.Current;
                            if (visibilityArea.VisibilityDirty)
                            {
                                MajorEmpire majorEmpire3 = visibilityArea.Empire as MajorEmpire;
                                if (majorEmpire3 != null)
                                {
                                    this.NeedRefreshBits |= majorEmpire3.Bits;
                                }
                                if (ELCPUtilities.SpectatorMode)
                                {
                                    foreach (int num in ELCPUtilities.EliminatedEmpireIndices)
                                    {
                                        this.NeedRefreshBits |= base.Game.Empires[num].Bits;
                                    }
                                }
                            }
                        }
                        goto IL_295;
                    }
                    goto IL_1E3;
                }
                goto IL_1E3;
IL_295:
                j++;
                continue;
IL_1E3:
                foreach (Empire empire in this.visibilityProviders[j].VisibilityEmpires)
                {
                    if (empire is MajorEmpire)
                    {
                        this.NeedRefreshBits |= empire.Bits;
                    }
                    if (ELCPUtilities.SpectatorMode)
                    {
                        foreach (int num2 in ELCPUtilities.EliminatedEmpireIndices)
                        {
                            this.NeedRefreshBits |= base.Game.Empires[num2].Bits;
                        }
                    }
                }
                goto IL_295;
            }
        }
        int num3 = (this.majorEmpires == null) ? 0 : ((int)Mathf.Pow(2f, (float)this.majorEmpires.Length) - 1);

        this.NeedRefreshBits &= num3;
        return(this.NeedRefreshBits != 0);
    }