/// <summary>
        /// Finds the path to furniture.
        /// </summary>
        /// <returns>The path to furniture.</returns>
        /// <param name="start">Start tile.</param>
        /// <param name="objectType">Object type of the furniture.</param>
        public static List <Tile> FindPathToFurniture(Tile start, string type)
        {
            if (start == null || type == null)
            {
                return(null);
            }

            RoomPath_AStar roomResolver = new RoomPath_AStar(World.Current, start.Room, RoomGoalFurnitureEvaluator(type), RoomHeuristic());
            List <Room>    roomPath     = roomResolver.GetList();

            Tile nearestExit;

            if (roomPath.Count == 1)
            {
                nearestExit = start;
            }
            else
            {
                nearestExit = GetNearestExit(roomPath);
            }

            Tile  targetTile = null;
            float distance   = 0f;

            foreach (Furniture furniture in World.Current.FurnitureManager.Where(furniture => furniture.Type == type))
            {
                if (targetTile == null || Vector3.Distance(nearestExit.Vector3, furniture.Tile.Vector3) < distance)
                {
                    distance   = Vector3.Distance(nearestExit.Vector3, furniture.Tile.Vector3);
                    targetTile = furniture.Tile;
                }
            }

            return(FindPathToTile(start, targetTile));
        }
Exemple #2
0
        public static bool IsRoomReachable(Room start, Room goal)
        {
            if (start == null || goal == null)
            {
                return(false);
            }

            RoomPath_AStar roomResolver = new RoomPath_AStar(World.Current, start, RoomEvaluator(goal), RoomHeuristic());

            return(roomResolver.Length() > 1);
        }
        public static List <Room> FindPathToRoom(Room start, Room goal)
        {
            if (start == null || goal == null)
            {
                return(null);
            }

            RoomPath_AStar roomResolver = new RoomPath_AStar(World.Current, start, RoomEvaluator(goal), RoomHeuristic());
            List <Room>    path         = roomResolver.GetList();

            return(path);
        }
        /// <summary>
        /// Finds the path to any inventory with type in <paramref name="types"/>
        /// </summary>
        public static List <Tile> FindPathToInventory(Tile start, string[] types, bool canTakeFromStockpile = true)
        {
            if (start == null || types == null || types.Length == 0)
            {
                return(null);
            }

            RoomPath_AStar roomResolver = new RoomPath_AStar(World.Current, start.GetNearestRoom(), RoomGoalInventoryEvaluator(types, canTakeFromStockpile), RoomHeuristic());
            List <Room>    roomPath     = roomResolver.GetList();

            if (roomPath.Count >= 1)
            {
                Tile nearestExit;
                if (roomPath.Count == 1)
                {
                    nearestExit = start;
                }
                else
                {
                    nearestExit = GetNearestExit(roomPath);
                }

                Tile  targetTile = null;
                float distance   = 0f;

                foreach (Inventory inventory in World.Current.InventoryManager.Inventories.Where(dictEntry => types.Contains(dictEntry.Key)).SelectMany(dictEntry => dictEntry.Value))
                {
                    if (inventory.Tile == null || !inventory.CanBePickedUp(canTakeFromStockpile))
                    {
                        continue;
                    }

                    if (targetTile == null || Vector3.Distance(nearestExit.Vector3, inventory.Tile.Vector3) < distance)
                    {
                        distance   = Vector3.Distance(nearestExit.Vector3, inventory.Tile.Vector3);
                        targetTile = inventory.Tile;
                    }
                }

                return(FindPathToTile(start, targetTile));
            }
            else
            {
                // Since we don't have a roomPath, someone's done something weird, like a room of doors, so just use Dijkstra to find our way
                Path_AStar  resolver = new Path_AStar(World.Current, start, GoalInventoryEvaluator(types, canTakeFromStockpile), DijkstraDistance());
                List <Tile> path     = resolver.GetList();
                return(path);
            }
        }
        /// <summary>
        /// Finds the path to furniture.
        /// </summary>
        /// <returns>The path to furniture.</returns>
        /// <param name="start">Start tile.</param>
        /// <param name="objectType">Object type of the furniture.</param>
        public static List <Tile> FindPathToFurniture(Tile start, string type)
        {
            if (start == null || type == null)
            {
                return(null);
            }

            RoomPath_AStar roomResolver = new RoomPath_AStar(World.Current, start.GetNearestRoom(), RoomGoalFurnitureEvaluator(type), RoomHeuristic());
            List <Room>    roomPath     = roomResolver.GetList();

            if (roomPath.Count >= 1)
            {
                Tile nearestExit;
                if (roomPath.Count == 1)
                {
                    nearestExit = start;
                }
                else
                {
                    nearestExit = GetNearestExit(roomPath);
                }

                Tile  targetTile = null;
                float distance   = float.MaxValue;
                foreach (Furniture furniture in World.Current.FurnitureManager.Where(furniture => furniture.Type == type))
                {
                    if (Vector3.Distance(nearestExit.Vector3, furniture.Tile.Vector3) < distance)
                    {
                        distance   = Vector3.Distance(nearestExit.Vector3, furniture.Tile.Vector3);
                        targetTile = furniture.Tile;
                    }
                }

                return(FindPathToTile(start, targetTile));
            }
            else
            {
                // Since we don't have a roomPath, someone's done something weird, like a room of doors, so just use Dijkstra to find our way
                Path_AStar  resolver = new Path_AStar(World.Current, start, GoalFurnitureEvaluator(type), DijkstraDistance());
                List <Tile> path     = resolver.GetList();
                return(path);
            }
        }
        /// <summary>
        /// Finds the path to any inventory with type in <paramref name="types"/>
        /// </summary>
        public static List <Tile> FindPathToInventory(Tile start, string[] types, bool canTakeFromStockpile = true)
        {
            if (start == null || types == null || types.Length == 0)
            {
                return(null);
            }

            RoomPath_AStar roomResolver = new RoomPath_AStar(World.Current, start.Room, RoomGoalInventoryEvaluator(types, canTakeFromStockpile), RoomHeuristic());
            List <Room>    roomPath     = roomResolver.GetList();

            Tile nearestExit;

            if (roomPath.Count == 1)
            {
                nearestExit = start;
            }
            else
            {
                nearestExit = GetNearestExit(roomPath);
            }

            Tile  targetTile = null;
            float distance   = 0f;

            foreach (Inventory inventory in World.Current.InventoryManager.Inventories.Where(dictEntry => types.Contains(dictEntry.Key)).SelectMany(dictEntry => dictEntry.Value))
            {
                if (inventory.Tile == null)
                {
                    continue;
                }

                if (targetTile == null || Vector3.Distance(nearestExit.Vector3, inventory.Tile.Vector3) < distance)
                {
                    distance   = Vector3.Distance(nearestExit.Vector3, inventory.Tile.Vector3);
                    targetTile = inventory.Tile;
                }
            }

            return(FindPathToTile(start, targetTile));
        }