Esempio n. 1
0
        // CONSTRUCTORS //

        public PatrolMaps(int width, int height, List <Point> roomCenters, DungeonFloor dungeonFloor)
        {
            this.width  = width;
            this.height = height;
            patrolGoals = new List <short[]>();
            CreatePatrolMaps(roomCenters, dungeonFloor);
        }
Esempio n. 2
0
        public static void PlaceCreatures(DungeonFloor dungeonFloor, Point upStairPos, List <string> monsterTypes)
        {
            List <Point> creatureSpots = new List <Point>();

            for (int i = 1; i < dungeonFloor.Width - 1; i++)
            {
                for (int j = 1; j < dungeonFloor.Height - 1; j++)
                {
                    Point spot = new Point(i, j);
                    if (GetNumOfAdjacentWalls(spot, dungeonFloor) <= 4 && dungeonFloor[i, j].Type == BlockType.Empty && spot.DistFrom(upStairPos) > 12)
                    {
                        creatureSpots.Add(spot);
                    }
                }
            }

            int creaturesSpawned     = 0;
            int desiredcreatureCount = creatureSpots.Count / 150;

            while (creaturesSpawned < desiredcreatureCount)
            {
                int     index   = Program.RNG.Next(0, creatureSpots.Count);
                Point   next    = creatureSpots[index];
                Monster monster = DataReader.GetMonster(monsterTypes[Program.RNG.Next(0, monsterTypes.Count)], dungeonFloor.Blocks, next);
                while (monster == null)
                {
                    monster = DataReader.GetMonster(monsterTypes[Program.RNG.Next(0, monsterTypes.Count)], dungeonFloor.Blocks, next);
                }
                dungeonFloor[next.X, next.Y] = monster;
                creaturesSpawned++;
                creatureSpots.RemoveAt(index);
            }
        }
Esempio n. 3
0
        // Generation Funcs //

        // fill the map with dirt
        public static void InitializeMap(DungeonFloor dungeonFloor)
        {
            // fill the map with dirt
            for (int i = 0; i < dungeonFloor.Width; i++)
            {
                for (int j = 0; j < dungeonFloor.Height; j++)
                {
                    dungeonFloor[i, j] = new Wall(Material.Stone);
                    dungeonFloor.Floor[i * Program.WorldMap.LocalTile.Width + j] = new DirtFloor();
                }
            }
        }
Esempio n. 4
0
        // FUNCTIONS //

        public void Init()
        {
            Point firstRoomPos = Program.Player.Position;

            for (int i = 0; i < floors.GetLength(0); i++)
            {
                floors[i] = new DungeonFloor(new Point(Program.WorldMap.LocalTile.Width, Program.WorldMap.LocalTile.Height));
                floors[i].Init(dungeonType, monsterTypes, i);
            }

            OnFinishedGenerating(this, EventArgs.Empty);
        }
Esempio n. 5
0
        // FUNCTIONS //

        public void CreatePatrolMaps(List <Point> roomCenters, DungeonFloor dungeonMap)
        {
            DungeonFloor map = dungeonMap;
            int          currentPatrolMap = 0;

            void DijkstraNeighbors(HashSet <Point> spots, short dist)
            {
                HashSet <Point> neighbors = new HashSet <Point>();

                foreach (Point spot in spots)
                {
                    for (int i = Math.Max(0, spot.X - 1); i <= Math.Min(spot.X + 1, width - 1); i++)
                    {
                        for (int j = Math.Max(0, spot.Y - 1); j <= Math.Min(spot.Y + 1, height - 1); j++)
                        {
                            Point point           = new Point(i, j);
                            bool  blockIsPassable = !(map.Blocks[i * Program.WorldMap.LocalTile.Width + j].Solid && map.Blocks[i * Program.WorldMap.LocalTile.Width + j].Type != BlockType.Door);
                            if ((patrolGoals[currentPatrolMap][point.X * width + point.Y] > dist) && blockIsPassable)
                            {
                                neighbors.Add(point);
                                patrolGoals[currentPatrolMap][point.X * width + point.Y] = dist;
                            }
                        }
                    }
                }
                if (neighbors.Count > 0)
                {
                    DijkstraNeighbors(neighbors, (short)(dist + 1));
                }
            }

            foreach (Point point in roomCenters)
            {
                patrolGoals.Add(new short[width * height]);

                for (int i = 0; i < width; i++)
                {
                    for (int j = 0; j < height; j++)
                    {
                        patrolGoals[currentPatrolMap][i * width + j] = dijkstraDefaultVal;
                    }
                }

                patrolGoals[currentPatrolMap][roomCenters[currentPatrolMap].X * width + roomCenters[currentPatrolMap].Y] = 0;

                DijkstraNeighbors(new HashSet <Point>(new Point[] { roomCenters[currentPatrolMap] }), 1);

                currentPatrolMap++;
            }
        }
Esempio n. 6
0
        // this one uses a dungeon floor as input
        public static int GetNumOfAdjacentWalls(Point point, DungeonFloor dungeonFloor)
        {
            int adjacentWalls = 0;

            for (int x = point.X - 1; x <= point.X + 1; x++)
            {
                for (int y = point.Y - 1; y <= point.Y + 1; y++)
                {
                    if (dungeonFloor[x, y].Solid && !point.Equals(new Point(x, y)))
                    {
                        adjacentWalls += 1;
                    }
                }
            }
            return(adjacentWalls);
        }
Esempio n. 7
0
        // the rest are self explanatory
        public static void PlaceStairs(DungeonFloor dungeonFloor, Point upStairPos)
        {
            dungeonFloor[upStairPos.X, upStairPos.Y] = new UpStair(Material.Stone);

            List <Point> potentialSpots = new List <Point>(); // for the down stair

            for (int i = 1; i < dungeonFloor.Width - 1; i++)
            {
                for (int j = 1; j < dungeonFloor.Height - 1; j++)
                {
                    if (GetNumOfAdjacentWalls(new Point(i, j), dungeonFloor) < 2 && new Point(i, j).DistFrom(upStairPos) > 20)
                    {
                        potentialSpots.Add(new Point(i, j));
                    }
                }
            }
            Point spot = potentialSpots[Program.RNG.Next(0, potentialSpots.Count)];

            dungeonFloor[spot.X, spot.Y] = new DownStair(Material.Stone);
        }
Esempio n. 8
0
        public static void PlaceItemsAndChests(DungeonFloor dungeonFloor, Point upStairPos)
        {
            // Figure out where items can be placed
            List <Point> itemSpots = new List <Point>();

            for (int i = 1; i < dungeonFloor.Width - 1; i++)
            {
                for (int j = 1; j < dungeonFloor.Height - 1; j++)
                {
                    if (GetNumOfAdjacentWalls(new Point(i, j), dungeonFloor) < 2 && dungeonFloor[i, j].Type == BlockType.Empty)
                    {
                        itemSpots.Add(new Point(i, j));
                    }
                }
            }

            // Generate a dijkstra map starting from the player's pos
            int[] placementMap = new int[dungeonFloor.Width * dungeonFloor.Height];
            for (int i = 0; i < dungeonFloor.Width; i++)
            {
                for (int j = 0; j < dungeonFloor.Height; j++)
                {
                    placementMap[i * dungeonFloor.Width + j] = new Point(i, j).Equals(upStairPos) ? 0 : 100000;
                }
            }
            DijkstraMaps.DijkstraNeighbors(new HashSet <Point>(new Point[] { upStairPos }), 1, ref placementMap, dungeonFloor.Blocks, new Point(dungeonFloor.Width, dungeonFloor.Height));

            // Find out the value of the spot farthest from the player
            int maxValue = 0;

            for (int i = 0; i < dungeonFloor.Width; i++)
            {
                for (int j = 0; j < dungeonFloor.Height; j++)
                {
                    maxValue = (placementMap[i * dungeonFloor.Width + j] > maxValue && placementMap[i * dungeonFloor.Width + j] != 100000) ? placementMap[i * dungeonFloor.Width + j] : maxValue;
                }
            }


            const int chanceToSpawnCloserThanMinDist = 20;
            int       desiredItemCount = itemSpots.Count / 50;
            int       itemsPlaced      = 0;

            while (itemsPlaced < desiredItemCount)
            {
                int   roll = Program.RNG.Next(1, 101);
                Point next;
                int   index;

                // repeatedly pick spots until it matches the spot that our roll corellates with
                do
                {
                    index = Program.RNG.Next(0, itemSpots.Count);
                    next  = itemSpots[index];
                } while ((placementMap[next.X * dungeonFloor.Width + next.Y] > (maxValue / 3) * 2 && roll <= chanceToSpawnCloserThanMinDist) || (placementMap[next.X * dungeonFloor.Width + next.Y] < (maxValue / 3) * 2 && roll > chanceToSpawnCloserThanMinDist));

                Block itemOrChest = GetItemOrChest();
                if (itemOrChest != null)
                {
                    dungeonFloor[next.X, next.Y] = itemOrChest;
                }

                itemsPlaced++;
                itemSpots.RemoveAt(index);
            }
        }
Esempio n. 9
0
        // CONSTRUCTOR

        public RoomPlacementAlgorithm(DungeonFloor dungeonFloor, List <string> monsterTypes)
        {
            this.dungeonFloor = dungeonFloor;
            this.monsterTypes = monsterTypes;
            rng = new Random();
        }
        // CONSTRUCTOR

        public RoomPlacementAlgorithm(DungeonFloor dungeonFloor, List <string> monsterTypes) : base(dungeonFloor, monsterTypes)
        {
        }
 protected DungeonGenerationAlgorithm(DungeonFloor dungeonFloor, List <string> monsterTypes)
 {
     this.dungeonFloor = dungeonFloor;
     this.monsterTypes = monsterTypes;
     rng = new Random();
 }
Esempio n. 12
0
 public CaveGenerationAlgorithm(DungeonFloor dungeonFloor, List <string> monsterTypes) : base(dungeonFloor, monsterTypes)
 {
 }