示例#1
0
 // CONSTRUCTORS
 public MapTile(Point size, Point worldIndex, float[,] heightMap, List <string> plantTypes, List <string> creatureTypes, bool containsDungeon)
 {
     width           = size.X;
     height          = size.Y;
     this.worldIndex = worldIndex;
     map             = new Block[width * height];
     floor           = new Tile[width * height];
     creatures       = new List <Creature>();
     projectiles     = new List <Projectile>();
     dijkstraMaps    = new DijkstraMaps(width, height);
     Init(new Random(), worldIndex, heightMap, plantTypes, creatureTypes, containsDungeon);
     owned = false;
 }
示例#2
0
        // CONSTRUCTOR //

        public MapTile(Point size, Point worldIndex, float[,] heightMap, bool containsDungeon)
        {
            width        = size.X;
            height       = size.Y;
            map          = new Block[width * height];
            memoryMap    = new Block[width * height];
            floor        = new Tile[width * height];
            creatures    = new List <Creature>();
            dijkstraMaps = new DijkstraMaps(width, height);
            Init(new Random(), worldIndex, heightMap, containsDungeon);
            owned        = false;
            inDungeon    = false;
            loading      = false;
            currentFloor = -1;
        }
示例#3
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);
            }
        }