Esempio n. 1
0
 ///<summary>Gets or sets the probability that a cell is occupied, between 0 and 1.</summary>
 public double this[Location location] {
     get {
         MapCell cell = cells.Get(location);
         return(cell == null ? 0 : cell.Probability);
     }
     set {
         if (value == 0)
         {
             cells.Remove(location);
         }
         else
         {
             MapCell cell = cells.Get(location);
             if (cell == null)
             {
                 cells.Add(new MapCell(location)
                 {
                     Probability = value
                 });
             }
             else
             {
                 cell.Probability = value;
             }
         }
     }
 }
Esempio n. 2
0
        public void Build(Grid grid)
        {
            if (grid == null)
            {
                return;
            }

            var unvisited = new CellCollection();

            foreach (Cell cell in grid.GetCells())
            {
                if (cell != null)
                {
                    unvisited.Add(cell);
                }
            }

            unvisited.Remove(unvisited.Sample());

            while (!unvisited.IsEmpty())
            {
                Cell cell = unvisited.Sample();
                var  path = new CellCollection();
                path.Add(cell);

                while (unvisited.Contains(cell))
                {
                    cell = cell.Neighbors.Sample();

                    int position = path.IndexOf(cell);
                    if (position >= 0)
                    {
                        path.RemoveRange(position + 1, path.Count - position - 1);
                    }
                    else
                    {
                        path.Add(cell);
                    }
                }

                for (int i = 0; i < path.Count - 1; i++)
                {
                    path[i].Link(path[i + 1]);
                    unvisited.Remove(path[i]);
                }
            }
        }
Esempio n. 3
0
 public static void DecayCells(ref Region region)
 {
     foreach (var cell in region.GetCells().Where(x => x.type == CellType.Cell).ToArray())
     {
         var decayHit = Random.Range(0.0f, 1.0f);
         if (region.cellDecayAmount >= decayHit)
         {
             cell.children = new List <Cell>();
             CellCollection.Remove(cell);
         }
     }
 }
Esempio n. 4
0
        public static void CleanIsolatedCells()
        {
            //These should be the only type of cells that can be potentially isolated
            var cellsToCheck = CellCollection.cells.Select(s => s.Value).Where(x => x.type == CellType.Cell).ToList();

            foreach (var cell in cellsToCheck)
            {
                if (cell.FindClosestPathway() == null)
                {
                    CellCollection.Remove(cell);
                }
            }
        }