public PolityProminenceCluster Split(PolityProminence startProminence) { #if DEBUG int oldSize = Size; #endif //#if DEBUG // if ((Manager.RegisterDebugEvent != null) && (Manager.TracingData.Priority <= 0)) // { // if (Manager.TracingData.ClusterId == Id) // { // SaveLoadTest.DebugMessage debugMessage = new SaveLoadTest.DebugMessage("PolityProminenceCluster.Split - Cluster:" + Id, // "CurrentDate: " + Polity.World.CurrentDate + // ", Size: " + Size + // ", LastProminenceChangeDate: " + LastProminenceChangeDate + // " [offset: " + (LastProminenceChangeDate - Manager.TracingData.LastSaveDate) + "]" + // "", Polity.World.CurrentDate); // Manager.RegisterDebugEvent("DebugMessage", debugMessage); // } // } // LastProminenceChangeDate = Polity.World.CurrentDate; //#endif RemoveProminence(startProminence); PolityProminenceCluster splitCluster = new PolityProminenceCluster(startProminence); HashSet <CellGroup> groupsAlreadyTested = new HashSet <CellGroup> { startProminence.Group }; Queue <PolityProminence> prominencesToExplore = new Queue <PolityProminence>(_prominences.Count + 1); prominencesToExplore.Enqueue(startProminence); bool continueExploring = true; while (continueExploring && (prominencesToExplore.Count > 0)) { PolityProminence prominenceToExplore = prominencesToExplore.Dequeue(); foreach (CellGroup nGroup in prominenceToExplore.Group.NeighborGroups) { if (groupsAlreadyTested.Contains(nGroup)) { continue; } if (HasPolityProminence(nGroup)) { PolityProminence prominenceToAdd = _prominences[nGroup.Id]; RemoveProminence(prominenceToAdd); splitCluster.AddProminence(prominenceToAdd); Manager.AddUpdatedCell(prominenceToAdd.Group.Cell, CellUpdateType.Cluster, CellUpdateSubType.Membership); if (splitCluster.Size >= MinSplitSize) { continueExploring = false; break; } prominencesToExplore.Enqueue(prominenceToAdd); } groupsAlreadyTested.Add(nGroup); } } //#if DEBUG // Debug.Log("Splitted cluster (Id: " + Id + ") of size " + oldSize + " and created new cluster (Id: " + splitCluster.Id + ") of size " + splitCluster.Size); //#endif return(splitCluster); }
private void AddCellDataToInfoPanel_PolityClusters(TerrainCell cell) { InfoText.text += "\n"; InfoText.text += "\n -- Group Polity Clusters Data -- "; InfoText.text += "\n"; if (cell.Group == null) { InfoText.text += "\n\tNo population at location"; return; } int population = cell.Group.Population; if (population <= 0) { InfoText.text += "\n\tNo population at location"; return; } bool firstPolity = true; List <PolityProminence> polityProminences = new List <PolityProminence>(cell.Group.GetPolityProminences()); polityProminences.Sort((a, b) => { if (a.Value > b.Value) { return(-1); } if (a.Value < b.Value) { return(1); } return(0); }); foreach (PolityProminence polityProminence in polityProminences) { Polity polity = polityProminence.Polity; float prominenceValue = polityProminence.Value; PolityProminenceCluster prominenceCluster = polityProminence.Cluster; if (prominenceValue >= 0.001) { if (firstPolity) { InfoText.text += "\nPolities:"; firstPolity = false; } InfoText.text += "\n\tPolity: " + polity.Name.Text + "\n\t\tProminence: " + prominenceValue.ToString("P"); if (prominenceCluster != null) { InfoText.text += "\n\t\tCluster: " + prominenceCluster.Id.ToString(); } else { InfoText.text += "\n\t\tCluster: null"; } } } }