Exemplo n.º 1
0
        private Point?GetExploreDestination()
        {
            //todo, clean up later
            var potentiallyReachable = FloodFill.ScanToArray(Player.Position, point => !point.IsMapEdge() && (!Map.Seen[point] || TileDefinition.IsPassable(TileTypeAt(point))));
            var dm2 = new DijkstraMap(p => (Map.Seen[p] || p.IsMapEdge())? -1 : 1)              //todo, seen==blocked?
            {
                IsSource = p => (Map.Seen[p] || p.IsMapEdge())
            };

            dm2.Scan();
            //CharacterScreens.PrintDijkstraTest(dm2);
            foreach (Point p in Map.GetAllPoints(false))
            {
                if (dm2[p] == DijkstraMap.Unexplored || dm2[p] == DijkstraMap.Blocked)
                {
                    continue;
                }
                dm2[p] = -(dm2[p] * dm2[p]);
            }
            dm2.RescanWithCurrentValues();
            //CharacterScreens.PrintDijkstraTest(dm2);
            var dm = new DijkstraMap(p => (!Map.Seen[p] || !TileDefinition.IsPassable(TileTypeAt(p)))? -1 : 1)
            {
                IsSource       = p => !Map.Seen[p] && potentiallyReachable[p],
                GetSourceValue = p => - (dm2[p])
            };

            dm.Scan();
            //CharacterScreens.PrintDijkstraTest(dm2);
            //CharacterScreens.PrintDijkstraTest(dm);
            List <Point> playerPath = dm.GetDownhillPath(Player.Position, true, earlyStopCondition: p => !Map.Seen[p]);

            if (playerPath.Count == 0)
            {
                return(null);
            }
            else
            {
                return(playerPath[playerPath.Count - 1]);
            }
        }
Exemplo n.º 2
0
        private void ChooseAutoexploreAction(PlayerTurnEvent e)
        {
            var potentiallyReachable = FloodFill.ScanToArray(Player.Position, point => !point.IsMapEdge() && (!Map.Seen[point] || TileDefinition.IsPassable(TileTypeAt(point))));
            var distanceToKnown      = new DijkstraMap(p => (Map.Seen[p] || p.IsMapEdge())? -1 : 1)
            {
                IsSource = p => (Map.Seen[p] || p.IsMapEdge())
            };

            distanceToKnown.Scan();
            foreach (Point p in Map.GetAllPoints(false))
            {
                if (distanceToKnown[p] == DijkstraMap.Unexplored || distanceToKnown[p] == DijkstraMap.Blocked)
                {
                    continue;
                }
                distanceToKnown[p] = -(distanceToKnown[p] * distanceToKnown[p]);
            }
            distanceToKnown.RescanWithCurrentValues();
            var exploreMap = new DijkstraMap(p => (!Map.Seen[p] || !TileDefinition.IsPassable(TileTypeAt(p)))? -1 : 1)              // todo, needs items, shrines, etc. eventually
            {
                IsSource       = p => !Map.Seen[p] && potentiallyReachable[p],
                GetSourceValue = p => - (distanceToKnown[p])
            };

            exploreMap.Scan();
            List <Point> playerPath = exploreMap.GetDownhillPath(Player.Position, true, earlyStopCondition: p => true);

            if (playerPath.Count == 0)
            {
                return;
            }
            else
            {
                e.ChosenAction = new WalkAction(Player, playerPath[0]);
            }
        }