public static Point16 FindStorageCenter(Point16 startSearch)
        {
            HashSet <Point16> explored = new HashSet <Point16>();

            explored.Add(startSearch);
            Queue <Point16> toExplore = new Queue <Point16>();

            foreach (Point16 point in AdjacentComponents(startSearch))
            {
                toExplore.Enqueue(point);
            }

            while (toExplore.Count > 0)
            {
                Point16 explore = toExplore.Dequeue();
                if (!explored.Contains(explore) && explore != StorageComponent.killTile)
                {
                    explored.Add(explore);
                    if (TEStorageCenter.IsStorageCenter(explore))
                    {
                        return(explore);
                    }
                    foreach (Point16 point in AdjacentComponents(explore))
                    {
                        toExplore.Enqueue(point);
                    }
                }
            }
            return(new Point16(-1, -1));
        }
        public static void SearchAndRefreshNetwork(Point16 position)
        {
            Point16 center = FindStorageCenter(position);

            if (center.X >= 0 && center.Y >= 0)
            {
                TEStorageCenter centerEnt = (TEStorageCenter)ByPosition[center];
                centerEnt.ResetAndSearch();
            }
        }
Ejemplo n.º 3
0
        public int CanPlace(int i, int j, int type, int style, int direction)
        {
            int count = 0;

            if (GetTileEntity() != null && GetTileEntity() is TEStorageCenter)
            {
                count++;
            }

            Point16           startSearch = new Point16(i - 1, j - 1);
            HashSet <Point16> explored    = new HashSet <Point16>();

            explored.Add(startSearch);
            Queue <Point16> toExplore = new Queue <Point16>();

            foreach (Point16 point in TEStorageComponent.AdjacentComponents(startSearch))
            {
                toExplore.Enqueue(point);
            }

            while (toExplore.Count > 0)
            {
                Point16 explore = toExplore.Dequeue();
                if (!explored.Contains(explore) && explore != killTile)
                {
                    explored.Add(explore);
                    if (TEStorageCenter.IsStorageCenter(explore))
                    {
                        count++;
                        if (count >= 2)
                        {
                            return(-1);
                        }
                    }
                    foreach (Point16 point in TEStorageComponent.AdjacentComponents(explore))
                    {
                        toExplore.Enqueue(point);
                    }
                }
            }
            return(count);
        }
Ejemplo n.º 4
0
        public void ResetAndSearch()
        {
            Point16 oldCenter = center;

            center = new Point16(-1, -1);

            HashSet <Point16> explored = new HashSet <Point16>();

            explored.Add(Position);
            Queue <Point16> toExplore = new Queue <Point16>();

            foreach (Point16 point in AdjacentComponents())
            {
                toExplore.Enqueue(point);
            }

            while (toExplore.Count > 0)
            {
                Point16 explore = toExplore.Dequeue();
                if (!explored.Contains(explore) && explore != StorageComponent.killTile)
                {
                    explored.Add(explore);
                    if (TEStorageCenter.IsStorageCenter(explore))
                    {
                        center = explore;
                        break;
                    }
                    foreach (Point16 point in AdjacentComponents(explore))
                    {
                        toExplore.Enqueue(point);
                    }
                }
            }

            if (center != oldCenter)
            {
                NetHelper.SendTEUpdate(ID, Position);
            }
        }