Example #1
0
        /*********
        ** Public methods
        *********/
        /// <summary>Get all machine groups in a location.</summary>
        /// <param name="location">The location to search.</param>
        /// <param name="reflection">Simplifies access to private game code.</param>
        public IEnumerable <MachineGroup> GetMachineGroups(GameLocation location, IReflectionHelper reflection)
        {
            MachineGroupBuilder builder = new MachineGroupBuilder(location);
            ISet <Vector2>      visited = new HashSet <Vector2>();

            foreach (Vector2 tile in location.GetTiles())
            {
                this.FloodFillGroup(builder, location, tile, visited, reflection);
                if (builder.HasTiles())
                {
                    yield return(builder.Build());

                    builder.Reset();
                }
            }
        }
Example #2
0
        internal static IEnumerable <TubeNetwork> GetAllNetworksIn(GameLocation location)
        {
            var visited = new HashSet <Vector2>();

            foreach (Vector2 tile in location.GetTiles())
            {
                if (visited.Contains(tile))
                {
                    continue;
                }
                if (TubeNetwork.GetNetworkAtTile(location, tile, visited) is TubeNetwork network)
                {
                    yield return(network);
                }
            }
        }
        /// <summary>Get all machine groups in a location.</summary>
        /// <param name="location">The location to search.</param>
        public IEnumerable <IMachineGroup> GetMachineGroups(GameLocation location)
        {
            MachineGroupBuilder    builder       = new(this.GetLocationKey(location), this.SortMachines, this.BuildStorage);
            LocationFloodFillIndex locationIndex = new(location);
            ISet <Vector2>         visited       = new HashSet <Vector2>();

            foreach (Vector2 tile in location.GetTiles())
            {
                this.FloodFillGroup(builder, location, tile, locationIndex, visited);
                if (builder.HasTiles())
                {
                    yield return(builder.Build());

                    builder.Reset();
                }
            }
        }
Example #4
0
        // Called by Automate mod to check if there's a container at the given tile.
        public IContainer getContainerHook(GameLocation location, Vector2 tile, out Vector2 size)
        {
            foreach (var warp in location.warps)
            {
                // Manhattan distance.
                if (Math.Abs(tile.X - warp.X) + Math.Abs(tile.Y - warp.Y) <= 1 && location.GetTiles().Contains(tile))
                {
                    size = Vector2.One;
                    ContainerBridge bridge = new ContainerBridge(warp);
                    this.Monitor.Log($"Adding container from {location.Name} at {tile} to {warp.TargetName} at {warp.TargetX}, {warp.TargetY}");
                    if (!this.bridges.ContainsKey(location))
                    {
                        this.bridges.Add(location, new HashSet <ContainerBridge>());
                    }
                    this.bridges[location].Add(bridge);
                    return(bridge);
                }
            }

            size = Vector2.Zero;
            return(null);
        }