private static Point?GetClosestUnexploredLocation(TerrainMap terrainMap, VisibilityMap visibilityMap, IMovementProfile movementProfile, Point location)
        {
            int   closestDistance = int.MaxValue;
            Point?closestLocation = null;

            // We want to explore rooms before we explore corridors
            DungeonPrefab currentRoom = terrainMap.GetPrefabAtLocation(location);

            // If we are in a room then get the closest unseen location in the room
            foreach (
                Point unseenLocation in
                currentRoom == null
                        ? GetWalkableUnseenLocations(terrainMap, visibilityMap, movementProfile)
                        : GetWalkableUnseenLocationsWithinPrefab(currentRoom, terrainMap, visibilityMap, movementProfile))
            {
                int currentDistance = location.DistanceTo(unseenLocation);
                if (currentDistance >= closestDistance)
                {
                    continue;
                }

                closestDistance = currentDistance;
                closestLocation = unseenLocation;
            }

            return(closestLocation);
        }
示例#2
0
        public static void Fill(TerrainMap terrainMap, VisibilityMap visibilityMap, IMovementProfile movementProfile, Point location)
        {
            if (!terrainMap.Bounds.Contains(location))
            {
                return;
            }
            if (!visibilityMap.Bounds.Contains(location))
            {
                return;
            }
            if (visibilityMap[location].WasSeen)
            {
                return;
            }
            if (!movementProfile.TerrainIsTraversable(terrainMap[location]))
            {
                return;
            }

            visibilityMap[location].WasSeen = true;

            Fill(terrainMap, visibilityMap, movementProfile, Direction.North.ApplyTransform(location));
            Fill(terrainMap, visibilityMap, movementProfile, Direction.Northeast.ApplyTransform(location));
            Fill(terrainMap, visibilityMap, movementProfile, Direction.East.ApplyTransform(location));
            Fill(terrainMap, visibilityMap, movementProfile, Direction.Southeast.ApplyTransform(location));
            Fill(terrainMap, visibilityMap, movementProfile, Direction.South.ApplyTransform(location));
            Fill(terrainMap, visibilityMap, movementProfile, Direction.Southwest.ApplyTransform(location));
            Fill(terrainMap, visibilityMap, movementProfile, Direction.West.ApplyTransform(location));
            Fill(terrainMap, visibilityMap, movementProfile, Direction.Northwest.ApplyTransform(location));
        }
        private static void WalkTheDungeon(Game gameInstance)
        {
            Logger.Info("Walking the dungeon...");

            var pathFinder      = new AStarPathFinding();
            var movementProfile = new HumanoidMovement();
            var visibilityMap   = new VisibilityMap(gameInstance.Terrain.Width, gameInstance.Terrain.Height, null, null);

            var walkableLocations = gameInstance.Terrain.WalkableLocations(movementProfile).ToList();

            FloodFill.Fill(gameInstance.Terrain, visibilityMap, movementProfile, walkableLocations[Rng.Next(walkableLocations.Count - 1)]);

            var walkableUnseenLocations = GetWalkableUnseenLocations(gameInstance.Terrain, visibilityMap, movementProfile).ToList();

            while (walkableUnseenLocations.Count > 0)
            {
                var closestExploredLocation   = GetClosestExploredLocation(gameInstance.Terrain, visibilityMap, movementProfile, walkableUnseenLocations[Rng.Next(walkableUnseenLocations.Count - 1)]);
                var closestUnexploredLocation = GetClosestUnexploredLocation(gameInstance.Terrain, visibilityMap, movementProfile, closestExploredLocation.Value);

                var movementPath = pathFinder.FindPath(gameInstance.Terrain, new List <IActor>(), new DiggerMovement(), closestExploredLocation.Value, closestUnexploredLocation.Value);
                foreach (var node in movementPath)
                {
                    gameInstance.Terrain[node.Location]  = new Floor();
                    visibilityMap[node.Location].WasSeen = true;
                }

                visibilityMap[closestUnexploredLocation.Value].WasSeen = false;
                FloodFill.Fill(gameInstance.Terrain, visibilityMap, movementProfile, closestUnexploredLocation.Value);

                walkableUnseenLocations = GetWalkableUnseenLocations(gameInstance.Terrain, visibilityMap, movementProfile).ToList();
            }


            //digger.VisibilityMap.UpdateVisibilityMap(gameInstance.Terrain, gameInstance.LightMap, digger.Location.Coordinate);
            //var command = digger.Intellect.GetNextAction();
            //while (command is MoveCommand)
            //{
            //    var result = command.Execute();
            //    if ((!result.Success) && (command is MoveCommand))
            //    {
            //        // The move action failed
            //        // Ask the actor for a default action on bump
            //        var defaultBumpAction = digger.Intellect.GetDefaultBumpAction((MoveCommand)command);
            //        if (defaultBumpAction != null)
            //           defaultBumpAction.Execute();
            //    }

            //    digger.VisibilityMap.UpdateVisibilityMap(gameInstance.Terrain, gameInstance.LightMap, digger.Location.Coordinate);
            //    command = digger.Intellect.GetNextAction();
            //}

            //gameInstance.RemoveActor(digger);
            Logger.Info("Dungeon walk complete.");
        }
        private static Point?GetClosestExploredLocation(TerrainMap terrainMap, VisibilityMap visibilityMap, IMovementProfile movementProfile, Point location)
        {
            int   distance        = int.MaxValue;
            Point?closestLocation = null;

            foreach (var visibleLocation in GetWalkableSeenLocations(terrainMap, visibilityMap, movementProfile))
            {
                int currentDistance = location.DistanceTo(visibleLocation);
                if (currentDistance >= distance)
                {
                    continue;
                }

                distance        = currentDistance;
                closestLocation = visibleLocation;
            }

            return(closestLocation);
        }
示例#5
0
        public Point?GetClosestExploredLocation(Point origin)
        {
            int   distance        = int.MaxValue;
            Point?closestLocation = null;

            foreach (
                Point visibleLocation in
                VisibilityMap.GetSeenLocations().Where(
                    x => Race.MovementProfile.TerrainIsTraversable(GameInstance.Terrain[x])))
            {
                int currentDistance = origin.DistanceTo(visibleLocation);
                if (currentDistance >= distance)
                {
                    continue;
                }

                distance        = currentDistance;
                closestLocation = visibleLocation;
            }

            return(closestLocation);
        }
示例#6
0
 public static void Push()
 {
     if (!IsHistoryEnabled)
     {
         return;
     }
     for (int i = HISTORY_LENGTH - 1; i > 0; i--)
     {
         Components[i] = Components[i - 1];
         LightEmittingComponents[i] = LightEmittingComponents[i - 1];
         MagnetComponents[i]        = MagnetComponents[i - 1];
         Layers[i]        = Layers[i - 1];
         MapVisibility[i] = MapVisibility[i - 1];
         ComponentSelectorComponents[i] = ComponentSelectorComponents[i - 1];
         Colliders[i] = Colliders[i - 1];
     }
     Components[0] = new List <Component>(ComponentsManager.Components);
     LightEmittingComponents[0] = new List <ILightEmitting>(ComponentsManager.LightEmittingComponents);
     MagnetComponents[0]        = new List <IMagnetic>(ComponentsManager.MagnetComponents);
     Layers[0]        = new List <int>(ComponentsManager.Layers);
     MapVisibility[0] = new VisibilityMap(ComponentsManager.VisibilityMap);
     ComponentSelectorComponents[0] = MicroWorld.Graphics.GUI.GUIEngine.s_componentSelector.CloneTiles();
     Colliders[0] = MicroWorld.Components.ComponentsManager.collidersManager.PushColliders();
 }
 private static IEnumerable <Point> GetWalkableSeenLocations(TerrainMap terrainMap, VisibilityMap visibilityMap, IMovementProfile movementProfile)
 {
     return(from location in visibilityMap.GetSeenLocations()
            where movementProfile.TerrainIsTraversable(terrainMap[location])
            select location);
 }
        private static IEnumerable <Point> GetWalkableUnseenLocationsWithinPrefab(Map <ITerrain> prefab, TerrainMap terrainMap, VisibilityMap visibilityMap, IMovementProfile movementProfile)
        {
            IEnumerable <Point> unseenLocationsInPrefab = from location in prefab.Locations
                                                          where
                                                          movementProfile.TerrainIsTraversable(
                terrainMap[location]) &&
                                                          !visibilityMap[location].WasSeen
                                                          select location;

            // Return any unseen locations within the prefab else return the closest unseen location on the map
            return(unseenLocationsInPrefab.Count() > 0 ? unseenLocationsInPrefab : GetWalkableUnseenLocations(terrainMap, visibilityMap, movementProfile));
        }
示例#9
0
 /// <summary>
 /// Enumerates all the unseen locations within the dungeon and returns the location closest to the actor.
 /// </summary>
 /// <param name="actor">The actor to evaluate the locations against</param>
 /// <returns>Returns the closest unseen location within the map</returns>
 private IEnumerable <Point> GetWalkableUnseenLocations()
 {
     return(from location in VisibilityMap.GetUnseenLocations()
            where Race.MovementProfile.TerrainIsTraversable(GameInstance.Terrain[location])
            select location);
 }