Example #1
0
        public bool SpawnNpc(DungeonArrayRoom room)
        {
            List <Loc2D> possiblePoints = new List <Loc2D>();

            for (int y = room.StartY; y <= room.EndY; y++)
            {
                for (int x = room.StartX; x <= room.EndX; x++)
                {
                    if (MapArray[x, y].Data.Type == PMDToolkit.Enums.TileType.Walkable && StartPoint != new Loc2D(x, y))
                    {
                        bool placeHere = true;
                        for (int n = 0; n < BasicMap.MAX_NPC_SLOTS; n++)
                        {
                            if (!Npcs[n].dead && Npcs[n].CharLoc == new Loc2D(x, y))
                            {
                                placeHere = false;
                                break;
                            }
                        }
                        if (placeHere)
                        {
                            possiblePoints.Add(new Loc2D(x, y));
                        }
                    }
                }
            }

            if (possiblePoints.Count > 0)
            {
                SpawnNpc(possiblePoints[rand.Next(possiblePoints.Count)]);
                return(true);
            }
            return(false);
        }
Example #2
0
        public bool SpawnNpc(DungeonArrayRoom room)
        {
            List <Loc2D> possiblePoints = new List <Loc2D>();

            for (int y = room.StartY; y <= room.EndY; y++)
            {
                for (int x = room.StartX; x <= room.EndX; x++)
                {
                    if (MapArray[x, y].Data.Type == Enums.TileType.Walkable && StartPoint != new Loc2D(x, y))
                    {
                        bool placeHere = true;
                        for (int n = 0; n < MAX_NPC_SLOTS; n++)
                        {
                            if (!Npcs[n].dead && Npcs[n].CharLoc == new Loc2D(x, y))
                            {
                                placeHere = false;
                                break;
                            }
                        }
                        if (placeHere)
                        {
                            possiblePoints.Add(new Loc2D(x, y));
                        }
                    }
                }
            }

            if (possiblePoints.Count > 0)
            {
                int npcIndex = rand.Next(1, 3);
                Npc npc      = new Npc(possiblePoints[rand.Next(possiblePoints.Count)], (Direction8)rand.Next(8), npcIndex);
                AddNpc(npc);
                return(true);
            }
            return(false);
        }
Example #3
0
        //an initial create-map method
        public override void Generate(int seed, RDungeonFloor entry, List<FloorBorder> floorBorders, Dictionary<int, List<int>> borderLinks)
        {
            //TODO: make sure that this algorithm follows floorBorders and borderLinks constraints

            this.seed = seed;
            this.entry = entry;
            FloorBorders = floorBorders;
            BorderLinks = borderLinks;

            BorderPoints = new Loc2D[floorBorders.Count];

            rand = new Random(seed);

            MapArray = new Tile[entry.FloorSettings["CellX"] * entry.FloorSettings["CellWidth"] + 2, entry.FloorSettings["CellY"] * entry.FloorSettings["CellHeight"] + 2];
            GridArray = new GridType[entry.FloorSettings["CellX"] * entry.FloorSettings["CellWidth"] + 2, entry.FloorSettings["CellY"] * entry.FloorSettings["CellHeight"] + 2];

            Rooms = new DungeonArrayRoom[entry.FloorSettings["CellX"], entry.FloorSettings["CellY"]]; //array of all rooms
            VHalls = new DungeonArrayHall[entry.FloorSettings["CellX"], entry.FloorSettings["CellY"] - 1]; //vertical halls
            HHalls = new DungeonArrayHall[entry.FloorSettings["CellX"] - 1, entry.FloorSettings["CellY"]]; //horizontal halls
            StartRoom = new Loc2D(-1, -1);     //marks spawn point

            bool isDone;   // bool used for various purposes

            //initialize map array to empty
            for (int y = 0; y < Height; y++) {
                for (int x = 0; x < Width; x++) {
                    GridArray[x, y] = GridType.Blocked;
                }
            }

            //initialize all rooms+halls to closed by default
            for (int x = 0; x < entry.FloorSettings["CellX"]; x++) {
                for (int y = 0; y < entry.FloorSettings["CellY"]; y++) {
                    Rooms[x, y] = new DungeonArrayRoom();
                }
            }

            for (int x = 0; x < entry.FloorSettings["CellX"]; x++) {
                for (int y = 0; y < entry.FloorSettings["CellY"] - 1; y++) {
                    VHalls[x, y] = new DungeonArrayHall();
                }
            }

            for (int x = 0; x < entry.FloorSettings["CellX"] - 1; x++) {
                for (int y = 0; y < entry.FloorSettings["CellY"]; y++) {
                    HHalls[x, y] = new DungeonArrayHall();
                }
            }

            // path generation algorithm
            StartRoom = new Loc2D(rand.Next(0, entry.FloorSettings["CellX"]), rand.Next(0, entry.FloorSettings["CellY"])); // randomly determine start room
            Loc2D wanderer = StartRoom;

            int pathsMade = 0;
            int pathsNeeded = rand.Next(0, 6) + 5; // magic numbers, determine what the dungeon looks like (in general, paths)
            Direction4 prevDir = Direction4.None; // direction of movement
            do {
                if (rand.Next(0, (2 + pathsMade)) == 0) {//will end the current path and start a new one from the start
                    if (rand.Next(0, 2) == 0) {//determine if the room should be open or a hall
                        Rooms[wanderer.X, wanderer.Y].Opened = DungeonArrayRoom.RoomState.Open;
                    } else {
                        Rooms[wanderer.X, wanderer.Y].Opened = DungeonArrayRoom.RoomState.Hall;
                    }
                    pathsMade++;
                    wanderer = StartRoom;
                    prevDir = Direction4.None;
                } else {
                    bool working = true;
                    do {
                        Loc2D sample = wanderer;
                        Direction4 nextDir = (Direction4)rand.Next(0, 4);
                        if (nextDir != prevDir) {//makes sure there is no backtracking
                            Operations.MoveInDirection4(ref sample, nextDir, 1);
                            prevDir = Operations.ReverseDir(nextDir);
                            if (sample.X >= 0 && sample.X < entry.FloorSettings["CellX"] && sample.Y >= 0 && sample.Y < entry.FloorSettings["CellY"]) {// a is the room to be checked after making a move between rooms
                                openHallBetween(wanderer, sample);
                                wanderer = sample;
                                working = false;
                            }
                        } else {
                            prevDir = Direction4.None;
                        }
                    } while (working);

                    if (rand.Next(0, 2) == 0) {//determine if the room should be open or a hall
                        Rooms[wanderer.X, wanderer.Y].Opened = DungeonArrayRoom.RoomState.Open;
                    } else {
                        Rooms[wanderer.X, wanderer.Y].Opened = DungeonArrayRoom.RoomState.Hall;
                    }
                }
            } while (pathsMade < pathsNeeded);

            Rooms[StartRoom.X, StartRoom.Y].Opened = DungeonArrayRoom.RoomState.Open;

            //Determine key rooms
            isDone = false;
            do { //determine ending room randomly
                int x = rand.Next(0, Rooms.GetLength(0));
                int y = rand.Next(0, Rooms.GetLength(1));
                if (Rooms[x, y].Opened == DungeonArrayRoom.RoomState.Open) {
                    EndRoom = new Loc2D(x, y);
                    isDone = true;
                }
            } while (!isDone);

            StartRoom = new Loc2D(-1, -1);

            isDone = false;
            do { //determine starting room randomly
                int x = rand.Next(0, Rooms.GetLength(0));
                int y = rand.Next(0, Rooms.GetLength(1));
                if (Rooms[x, y].Opened == DungeonArrayRoom.RoomState.Open) {
                    StartRoom = new Loc2D(x, y);
                    isDone = true;
                }
            } while (!isDone);

            // begin part 2, creating ASCII map
            //create rooms

            for (int i = 0; i < Rooms.GetLength(0); i++) {
                for (int j = 0; j < Rooms.GetLength(1); j++) {
                    if (Rooms[i, j].Opened != DungeonArrayRoom.RoomState.Closed) {
                        createRoom(i, j);
                    }
                }
            }

            for (int i = 0; i < Rooms.GetLength(0); i++) {
                for (int j = 0; j < Rooms.GetLength(1); j++) {
                    if (Rooms[i, j].Opened != DungeonArrayRoom.RoomState.Closed) {
                        drawRoom(i, j);
                    }
                }
            }

            for (int i = 0; i < Rooms.GetLength(0); i++) {
                for (int j = 0; j < Rooms.GetLength(1); j++) {
                    if (Rooms[i, j].Opened != DungeonArrayRoom.RoomState.Closed) {
                        padSingleRoom(i, j);
                    }
                }
            }

            for (int i = 0; i < VHalls.GetLength(0); i++) {
                for (int j = 0; j < VHalls.GetLength(1); j++) {
                    if (VHalls[i, j].Open) {
                        createVHall(i, j);
                    }
                }
            }

            for (int i = 0; i < HHalls.GetLength(0); i++) {
                for (int j = 0; j < HHalls.GetLength(1); j++) {
                    if (HHalls[i, j].Open) {
                        createHHall(i, j);
                    }
                }
            }

            for (int i = 0; i < VHalls.GetLength(0); i++) {
                for (int j = 0; j < VHalls.GetLength(1); j++) {
                    if (VHalls[i, j].Open) {
                        DrawHalls(VHalls[i, j]);
                    }
                }
            }

            for (int i = 0; i < HHalls.GetLength(0); i++) {
                for (int j = 0; j < HHalls.GetLength(1); j++) {
                    if (HHalls[i, j].Open) {
                        DrawHalls(HHalls[i, j]);
                    }
                }
            }

            addSEpos(StartRoom, true);
            addSEpos(EndRoom, false);

            //texturing
            MapLayer ground = new MapLayer(Width, Height);
            GroundLayers.Add(ground);
            for (int y = 0; y < Height; y++) {
                for (int x = 0; x < Width; x++) {
                    if (GridArray[x, y] == GridType.End) {
                        MapArray[x, y] = new Tile(PMDToolkit.Enums.TileType.ChangeFloor, 1, 0, 0);
                        GroundLayers[0].Tiles[x, y] = new TileAnim(new Loc2D(47, 0), 0);
                    } else if (GridArray[x, y] == GridType.Blocked) {
                        MapArray[x, y] = new Tile(PMDToolkit.Enums.TileType.Blocked, 0, 0, 0);

                        bool[] blockedDirs = new bool[8];
                        for (int n = 0; n < 8; n++) {
                            blockedDirs[n] = IsBlocked(x, y, (Direction8)n);
                        }
                        if (blockedDirs[(int)Direction8.Down] && blockedDirs[(int)Direction8.Left] && blockedDirs[(int)Direction8.Up] && blockedDirs[(int)Direction8.Right]) {
                            int layer = 0;
                            if (!blockedDirs[(int)Direction8.DownLeft])
                                layer += 8 * 2;

                            if (!blockedDirs[(int)Direction8.UpLeft])
                                layer += 1;

                            if (!blockedDirs[(int)Direction8.UpRight])
                                layer += 8;

                            if (!blockedDirs[(int)Direction8.DownRight])
                                layer += 2;

                            GroundLayers[0].Tiles[x, y] = new TileAnim(new Loc2D(), 0);
                        } else if (!blockedDirs[(int)Direction8.Down] && blockedDirs[(int)Direction8.Left] && blockedDirs[(int)Direction8.Up] && blockedDirs[(int)Direction8.Right]) {
                            int layer = 6;
                            if (blockedDirs[(int)Direction8.UpRight])
                                layer += 1 * 8;

                            if (blockedDirs[(int)Direction8.UpLeft])
                                layer += 2 * 8;

                            GroundLayers[0].Tiles[x, y] = new TileAnim(new Loc2D(), 0);
                        } else if (blockedDirs[(int)Direction8.Down] && !blockedDirs[(int)Direction8.Left] && blockedDirs[(int)Direction8.Up] && blockedDirs[(int)Direction8.Right]) {
                            int layer = 7;
                            if (blockedDirs[(int)Direction8.DownRight])
                                layer += 1 * 8;

                            if (blockedDirs[(int)Direction8.UpRight])
                                layer += 2 * 8;

                            GroundLayers[0].Tiles[x, y] = new TileAnim(new Loc2D(), 0);
                        } else if (blockedDirs[(int)Direction8.Down] && blockedDirs[(int)Direction8.Left] && !blockedDirs[(int)Direction8.Up] && blockedDirs[(int)Direction8.Right]) {
                            int layer = 4;
                            if (blockedDirs[(int)Direction8.DownLeft])
                                layer += 1 * 8;

                            if (blockedDirs[(int)Direction8.DownRight])
                                layer += 2 * 8;

                            GroundLayers[0].Tiles[x, y] = new TileAnim(new Loc2D(), 0);
                        } else if (blockedDirs[(int)Direction8.Down] && blockedDirs[(int)Direction8.Left] && blockedDirs[(int)Direction8.Up] && !blockedDirs[(int)Direction8.Right]) {
                            int layer = 5;
                            if (blockedDirs[(int)Direction8.UpLeft])
                                layer += 1 * 8;

                            if (blockedDirs[(int)Direction8.DownLeft])
                                layer += 2 * 8;

                            GroundLayers[0].Tiles[x, y] = new TileAnim(new Loc2D(), 0);
                        } else if (!blockedDirs[(int)Direction8.Down] && !blockedDirs[(int)Direction8.Left] && blockedDirs[(int)Direction8.Up] && blockedDirs[(int)Direction8.Right]) {
                            int layer = 34;
                            if (blockedDirs[(int)Direction8.UpRight])
                                layer += 8;

                            GroundLayers[0].Tiles[x, y] = new TileAnim(new Loc2D(), 0);
                        } else if (blockedDirs[(int)Direction8.Down] && !blockedDirs[(int)Direction8.Left] && !blockedDirs[(int)Direction8.Up] && blockedDirs[(int)Direction8.Right]) {
                            int layer = 35;
                            if (blockedDirs[(int)Direction8.DownRight])
                                layer += 8;

                            GroundLayers[0].Tiles[x, y] = new TileAnim(new Loc2D(), 0);
                        } else if (blockedDirs[(int)Direction8.Down] && blockedDirs[(int)Direction8.Left] && !blockedDirs[(int)Direction8.Up] && !blockedDirs[(int)Direction8.Right]) {
                            int layer = 32;
                            if (blockedDirs[(int)Direction8.DownLeft])
                                layer += 8;

                            GroundLayers[0].Tiles[x, y] = new TileAnim(new Loc2D(), 0);
                        } else if (!blockedDirs[(int)Direction8.Down] && blockedDirs[(int)Direction8.Left] && blockedDirs[(int)Direction8.Up] && !blockedDirs[(int)Direction8.Right]) {
                            int layer = 33;
                            if (blockedDirs[(int)Direction8.UpLeft])
                                layer += 8;

                            GroundLayers[0].Tiles[x, y] = new TileAnim(new Loc2D(), 0);
                        } else if (blockedDirs[(int)Direction8.Down] && !blockedDirs[(int)Direction8.Left] && !blockedDirs[(int)Direction8.Up] && !blockedDirs[(int)Direction8.Right])
                            GroundLayers[0].Tiles[x, y] = new TileAnim(new Loc2D(36, 0), 0);
                        else if (!blockedDirs[(int)Direction8.Down] && blockedDirs[(int)Direction8.Left] && !blockedDirs[(int)Direction8.Up] && !blockedDirs[(int)Direction8.Right])
                            GroundLayers[0].Tiles[x, y] = new TileAnim(new Loc2D(37, 0), 0);
                        else if (!blockedDirs[(int)Direction8.Down] && !blockedDirs[(int)Direction8.Left] && blockedDirs[(int)Direction8.Up] && !blockedDirs[(int)Direction8.Right])
                            GroundLayers[0].Tiles[x, y] = new TileAnim(new Loc2D(38, 0), 0);
                        else if (!blockedDirs[(int)Direction8.Down] && !blockedDirs[(int)Direction8.Left] && !blockedDirs[(int)Direction8.Up] && blockedDirs[(int)Direction8.Right])
                            GroundLayers[0].Tiles[x, y] = new TileAnim(new Loc2D(39, 0), 0);
                        else if (!blockedDirs[(int)Direction8.Down] && blockedDirs[(int)Direction8.Left] && !blockedDirs[(int)Direction8.Up] && blockedDirs[(int)Direction8.Right])
                            GroundLayers[0].Tiles[x, y] = new TileAnim(new Loc2D(44, 0), 0);
                        else if (blockedDirs[(int)Direction8.Down] && !blockedDirs[(int)Direction8.Left] && blockedDirs[(int)Direction8.Up] && !blockedDirs[(int)Direction8.Right])
                            GroundLayers[0].Tiles[x, y] = new TileAnim(new Loc2D(45, 0), 0);
                        else if (!blockedDirs[(int)Direction8.Down] && !blockedDirs[(int)Direction8.Left] && !blockedDirs[(int)Direction8.Up] && !blockedDirs[(int)Direction8.Right])
                            GroundLayers[0].Tiles[x, y] = new TileAnim(new Loc2D(46, 0), 0);

                    } else {
                        MapArray[x, y] = new Tile(PMDToolkit.Enums.TileType.Walkable, 0, 0, 0);
                        GroundLayers[0].Tiles[x, y] = new TileAnim(new Loc2D(47, 0), 0);
                    }
                }
            }

            GenItems();
            SpawnNpcs();
        }
Example #4
0
        public bool SpawnNpc(DungeonArrayRoom room)
        {
            List<Loc2D> possiblePoints = new List<Loc2D>();
            for (int y = room.StartY; y <= room.EndY; y++) {
                for (int x = room.StartX; x <= room.EndX; x++) {
                    if (MapArray[x, y].Data.Type == PMDToolkit.Enums.TileType.Walkable && StartPoint != new Loc2D(x, y)) {
                        bool placeHere = true;
                        for (int n = 0; n < BasicMap.MAX_NPC_SLOTS; n++) {
                            if (!Npcs[n].dead && Npcs[n].CharLoc == new Loc2D(x, y)) {
                                placeHere = false;
                                break;
                            }
                        }
                        if (placeHere) {
                            possiblePoints.Add(new Loc2D(x, y));
                        }
                    }
                }
            }

            if (possiblePoints.Count > 0) {
                int npcIndex = rand.Next(1, 3);
                Npc npc = new Npc(possiblePoints[rand.Next(possiblePoints.Count)], (Direction8)rand.Next(8), npcIndex);
                AddNpc(npc);
                return true;
            }
            return false;
        }
Example #5
0
        void createVHall(int hallX, int hallY)
        {
            DungeonArrayRoom startRoom = Rooms[hallX, hallY];
            DungeonArrayRoom endRoom   = Rooms[hallX, hallY + 1];

            int n = endRoom.StartY - startRoom.EndY; //distance between rooms

            if (n < 1)
            {
                if (startRoom.StartX > endRoom.EndX || startRoom.EndX < endRoom.StartX)
                {
                    n++;
                }
                else
                {
                    return;
                }
            }
            n--;

            int x, y, m, /* n,*/ h, r = 0, var;

            y = startRoom.EndY;

            m = rand.Next(entry.FloorSettings["HallTurnMin"], entry.FloorSettings["HallTurnMax"] + 1); // the number of horizontal pieces in the hall


            if (m > ((n - 1) / 2))
            {
                m = (n - 1) / 2;                                 //reduces the number of hall turns to something the length of the hall can accept
            }
            x = rand.Next(startRoom.StartX, startRoom.EndX + 1); //picks a X coordinate to start at


            VHalls[hallX, hallY].TurnPoints.Add(new Loc2D(x, y));


            if (m <= 0 && (x > endRoom.EndX || x < endRoom.StartX))  //checks if at least one turn is needed to make rooms meet
            {
                m = 1;
            }


            for (int i = 0; i <= m; i++)
            {
                if (i == m)
                {
                    var = rand.Next(endRoom.StartX, endRoom.EndX + 1) - x;
                }
                else
                {
                    var = rand.Next(entry.FloorSettings["HallVarMin"], entry.FloorSettings["HallVarMax"] + 1);
                    if (rand.Next(0, 2) == 0)
                    {
                        var = -var;
                    }
                }

                if (i != 0)
                {
                    if ((x + var) < 1)
                    {
                        var = 1 - x;
                    }
                    if ((x + var) > Width - 2)
                    {
                        var = Width - 2 - x;
                    }
                    //addHorizHall(x, y, var, mapArray);

                    x += var;
                    VHalls[hallX, hallY].TurnPoints.Add(new Loc2D(x, y));
                }// else {
                 //mapArray[y,x] = ',';
                 //}



                if (n >= 0)
                {
                    h = (r + n) / (m + 1);
                    r = (r + n) % (m + 1);
                }
                else
                {
                    h = -(r - n) / (m + 1);
                    r = (r - n) % (m + 1);
                }
                //addVertHall(x, y, h, mapArray);

                y += h;
                VHalls[hallX, hallY].TurnPoints.Add(new Loc2D(x, y));
            }

            VHalls[hallX, hallY].TurnPoints[VHalls[hallX, hallY].TurnPoints.Count - 1] = new Loc2D(x, y + 1);
            //mapArray[y + 1, x] = ',';


            //int x, y, h, j; // variables for position
            //h = hall % 4;
            //j = hall / 4;

            //x = 3 + Convert.ToInt32(13.5 * h);
            //y = 7 + 12 * j;

            //addVertHall(x, y, mapArray);
        }
Example #6
0
        void createHHall(int hallX, int hallY)
        {
            DungeonArrayRoom startRoom = Rooms[hallX, hallY];
            DungeonArrayRoom endRoom   = Rooms[hallX + 1, hallY];

            int distance = endRoom.StartX - startRoom.EndX;

            if (distance < 1)
            {
                if (startRoom.StartY > endRoom.EndY || startRoom.EndY < endRoom.StartY)
                {
                    distance++;
                }
                else
                {
                    return;
                }
            }
            distance--;

            int x, y, m, h, r = 0, var;

            x = startRoom.EndX;

            m = rand.Next(entry.FloorSettings["HallTurnMin"], entry.FloorSettings["HallTurnMax"] + 1); // the number of vertical pieces in the hall


            if (m > ((distance - 1) / 2))
            {
                m = (distance - 1) / 2;                          //reduces the number of hall turns to something the length of the hall can accept
            }
            y = rand.Next(startRoom.StartY, startRoom.EndY + 1); //picks a Y coordinate to start at


            HHalls[hallX, hallY].TurnPoints.Add(new Loc2D(x, y));

            if (m <= 0 && (y > endRoom.EndY || y < endRoom.StartY))  //checks if at least one turn is needed to make rooms meet
            {
                m = 1;
            }


            for (int i = 0; i <= m; i++)
            {
                if (i == m)
                {
                    var = rand.Next(endRoom.StartY, endRoom.EndY + 1) - y;
                }
                else
                {
                    var = rand.Next(entry.FloorSettings["HallVarMin"], entry.FloorSettings["HallVarMax"] + 1);
                    if (rand.Next(0, 2) == 0)
                    {
                        var = -var;
                    }
                }
                if (i != 0)
                {
                    if ((y + var) < 1)
                    {
                        var = 1 - y;
                    }
                    if ((y + var) > Height - 2)
                    {
                        var = Height - 2 - y;
                    }

                    y += var;
                    HHalls[hallX, hallY].TurnPoints.Add(new Loc2D(x, y));
                }

                if (distance >= 0)
                {
                    h = (r + distance) / (m + 1);
                    r = (r + distance) % (m + 1);
                }
                else
                {
                    h = -(r - distance) / (m + 1);
                    r = (r - distance) % (m + 1);
                }
                //addHorizHall(x, y, h, mapArray);

                x += h;
                HHalls[hallX, hallY].TurnPoints.Add(new Loc2D(x, y));
            }

            HHalls[hallX, hallY].TurnPoints[HHalls[hallX, hallY].TurnPoints.Count - 1] = new Loc2D(x + 1, y);
            //mapArray[y, x + 1] = ',';


            //int x, y, h, j;
            //h = hall % 3;
            //j = hall / 3;

            //x = 8 + 13 * h;
            //y = 3 + 12 * j;

            //addHorizHall(x, y, 6, mapArray);
        }
Example #7
0
        //an initial create-map method
        public override void Generate(int seed, RDungeonFloor entry, List <FloorBorder> floorBorders, Dictionary <int, List <int> > borderLinks)
        {
            //TODO: make sure that this algorithm follows floorBorders and borderLinks constraints

            this.seed    = seed;
            this.entry   = entry;
            FloorBorders = floorBorders;
            BorderLinks  = borderLinks;

            BorderPoints = new Loc2D[floorBorders.Count];

            rand = new Random(seed);

            MapArray  = new Tile[entry.FloorSettings["CellX"] * entry.FloorSettings["CellWidth"] + 2, entry.FloorSettings["CellY"] * entry.FloorSettings["CellHeight"] + 2];
            GridArray = new GridType[entry.FloorSettings["CellX"] * entry.FloorSettings["CellWidth"] + 2, entry.FloorSettings["CellY"] * entry.FloorSettings["CellHeight"] + 2];

            Rooms     = new DungeonArrayRoom[entry.FloorSettings["CellX"], entry.FloorSettings["CellY"]];     //array of all rooms
            VHalls    = new DungeonArrayHall[entry.FloorSettings["CellX"], entry.FloorSettings["CellY"] - 1]; //vertical halls
            HHalls    = new DungeonArrayHall[entry.FloorSettings["CellX"] - 1, entry.FloorSettings["CellY"]]; //horizontal halls
            StartRoom = new Loc2D(-1, -1);                                                                    //marks spawn point

            bool isDone;                                                                                      // bool used for various purposes


            //initialize map array to empty
            for (int y = 0; y < Height; y++)
            {
                for (int x = 0; x < Width; x++)
                {
                    GridArray[x, y] = GridType.Blocked;
                }
            }

            //initialize all rooms+halls to closed by default
            for (int x = 0; x < entry.FloorSettings["CellX"]; x++)
            {
                for (int y = 0; y < entry.FloorSettings["CellY"]; y++)
                {
                    Rooms[x, y] = new DungeonArrayRoom();
                }
            }



            for (int x = 0; x < entry.FloorSettings["CellX"]; x++)
            {
                for (int y = 0; y < entry.FloorSettings["CellY"] - 1; y++)
                {
                    VHalls[x, y] = new DungeonArrayHall();
                }
            }

            for (int x = 0; x < entry.FloorSettings["CellX"] - 1; x++)
            {
                for (int y = 0; y < entry.FloorSettings["CellY"]; y++)
                {
                    HHalls[x, y] = new DungeonArrayHall();
                }
            }

            // path generation algorithm
            StartRoom = new Loc2D(rand.Next(0, entry.FloorSettings["CellX"]), rand.Next(0, entry.FloorSettings["CellY"])); // randomly determine start room
            Loc2D wanderer = StartRoom;

            int        pathsMade   = 0;
            int        pathsNeeded = rand.Next(0, 6) + 5; // magic numbers, determine what the dungeon looks like (in general, paths)
            Direction4 prevDir     = Direction4.None;     // direction of movement

            do
            {
                if (rand.Next(0, (2 + pathsMade)) == 0) //will end the current path and start a new one from the start
                {
                    if (rand.Next(0, 2) == 0)           //determine if the room should be open or a hall
                    {
                        Rooms[wanderer.X, wanderer.Y].Opened = DungeonArrayRoom.RoomState.Open;
                    }
                    else
                    {
                        Rooms[wanderer.X, wanderer.Y].Opened = DungeonArrayRoom.RoomState.Hall;
                    }
                    pathsMade++;
                    wanderer = StartRoom;
                    prevDir  = Direction4.None;
                }
                else
                {
                    bool working = true;
                    do
                    {
                        Loc2D      sample  = wanderer;
                        Direction4 nextDir = (Direction4)rand.Next(0, 4);
                        if (nextDir != prevDir)  //makes sure there is no backtracking
                        {
                            Operations.MoveInDirection4(ref sample, nextDir, 1);
                            prevDir = Operations.ReverseDir(nextDir);
                            if (sample.X >= 0 && sample.X < entry.FloorSettings["CellX"] && sample.Y >= 0 && sample.Y < entry.FloorSettings["CellY"])  // a is the room to be checked after making a move between rooms
                            {
                                openHallBetween(wanderer, sample);
                                wanderer = sample;
                                working  = false;
                            }
                        }
                        else
                        {
                            prevDir = Direction4.None;
                        }
                    } while (working);

                    if (rand.Next(0, 2) == 0)  //determine if the room should be open or a hall
                    {
                        Rooms[wanderer.X, wanderer.Y].Opened = DungeonArrayRoom.RoomState.Open;
                    }
                    else
                    {
                        Rooms[wanderer.X, wanderer.Y].Opened = DungeonArrayRoom.RoomState.Hall;
                    }
                }
            } while (pathsMade < pathsNeeded);

            Rooms[StartRoom.X, StartRoom.Y].Opened = DungeonArrayRoom.RoomState.Open;

            //Determine key rooms
            isDone = false;
            do   //determine ending room randomly
            {
                int x = rand.Next(0, Rooms.GetLength(0));
                int y = rand.Next(0, Rooms.GetLength(1));
                if (Rooms[x, y].Opened == DungeonArrayRoom.RoomState.Open)
                {
                    EndRoom = new Loc2D(x, y);
                    isDone  = true;
                }
            } while (!isDone);

            StartRoom = new Loc2D(-1, -1);

            isDone = false;
            do   //determine starting room randomly
            {
                int x = rand.Next(0, Rooms.GetLength(0));
                int y = rand.Next(0, Rooms.GetLength(1));
                if (Rooms[x, y].Opened == DungeonArrayRoom.RoomState.Open)
                {
                    StartRoom = new Loc2D(x, y);
                    isDone    = true;
                }
            } while (!isDone);



            // begin part 2, creating ASCII map
            //create rooms

            for (int i = 0; i < Rooms.GetLength(0); i++)
            {
                for (int j = 0; j < Rooms.GetLength(1); j++)
                {
                    if (Rooms[i, j].Opened != DungeonArrayRoom.RoomState.Closed)
                    {
                        createRoom(i, j);
                    }
                }
            }

            for (int i = 0; i < Rooms.GetLength(0); i++)
            {
                for (int j = 0; j < Rooms.GetLength(1); j++)
                {
                    if (Rooms[i, j].Opened != DungeonArrayRoom.RoomState.Closed)
                    {
                        drawRoom(i, j);
                    }
                }
            }

            for (int i = 0; i < Rooms.GetLength(0); i++)
            {
                for (int j = 0; j < Rooms.GetLength(1); j++)
                {
                    if (Rooms[i, j].Opened != DungeonArrayRoom.RoomState.Closed)
                    {
                        padSingleRoom(i, j);
                    }
                }
            }

            for (int i = 0; i < VHalls.GetLength(0); i++)
            {
                for (int j = 0; j < VHalls.GetLength(1); j++)
                {
                    if (VHalls[i, j].Open)
                    {
                        createVHall(i, j);
                    }
                }
            }

            for (int i = 0; i < HHalls.GetLength(0); i++)
            {
                for (int j = 0; j < HHalls.GetLength(1); j++)
                {
                    if (HHalls[i, j].Open)
                    {
                        createHHall(i, j);
                    }
                }
            }


            for (int i = 0; i < VHalls.GetLength(0); i++)
            {
                for (int j = 0; j < VHalls.GetLength(1); j++)
                {
                    if (VHalls[i, j].Open)
                    {
                        DrawHalls(VHalls[i, j]);
                    }
                }
            }

            for (int i = 0; i < HHalls.GetLength(0); i++)
            {
                for (int j = 0; j < HHalls.GetLength(1); j++)
                {
                    if (HHalls[i, j].Open)
                    {
                        DrawHalls(HHalls[i, j]);
                    }
                }
            }

            addSEpos(StartRoom, true);
            addSEpos(EndRoom, false);

            //texturing
            MapLayer ground = new MapLayer(Width, Height);

            GroundLayers.Add(ground);
            for (int y = 0; y < Height; y++)
            {
                for (int x = 0; x < Width; x++)
                {
                    if (GridArray[x, y] == GridType.End)
                    {
                        MapArray[x, y] = new Tile(PMDToolkit.Enums.TileType.ChangeFloor, 1, 0, 0);
                        GroundLayers[0].Tiles[x, y] = new TileAnim(new Loc2D(47, 0), 0);
                    }
                    else if (GridArray[x, y] == GridType.Blocked)
                    {
                        MapArray[x, y] = new Tile(PMDToolkit.Enums.TileType.Blocked, 0, 0, 0);

                        bool[] blockedDirs = new bool[8];
                        for (int n = 0; n < 8; n++)
                        {
                            blockedDirs[n] = IsBlocked(x, y, (Direction8)n);
                        }
                        if (blockedDirs[(int)Direction8.Down] && blockedDirs[(int)Direction8.Left] && blockedDirs[(int)Direction8.Up] && blockedDirs[(int)Direction8.Right])
                        {
                            int layer = 0;
                            if (!blockedDirs[(int)Direction8.DownLeft])
                            {
                                layer += 8 * 2;
                            }

                            if (!blockedDirs[(int)Direction8.UpLeft])
                            {
                                layer += 1;
                            }

                            if (!blockedDirs[(int)Direction8.UpRight])
                            {
                                layer += 8;
                            }

                            if (!blockedDirs[(int)Direction8.DownRight])
                            {
                                layer += 2;
                            }

                            GroundLayers[0].Tiles[x, y] = new TileAnim(new Loc2D(), 0);
                        }
                        else if (!blockedDirs[(int)Direction8.Down] && blockedDirs[(int)Direction8.Left] && blockedDirs[(int)Direction8.Up] && blockedDirs[(int)Direction8.Right])
                        {
                            int layer = 6;
                            if (blockedDirs[(int)Direction8.UpRight])
                            {
                                layer += 1 * 8;
                            }

                            if (blockedDirs[(int)Direction8.UpLeft])
                            {
                                layer += 2 * 8;
                            }

                            GroundLayers[0].Tiles[x, y] = new TileAnim(new Loc2D(), 0);
                        }
                        else if (blockedDirs[(int)Direction8.Down] && !blockedDirs[(int)Direction8.Left] && blockedDirs[(int)Direction8.Up] && blockedDirs[(int)Direction8.Right])
                        {
                            int layer = 7;
                            if (blockedDirs[(int)Direction8.DownRight])
                            {
                                layer += 1 * 8;
                            }

                            if (blockedDirs[(int)Direction8.UpRight])
                            {
                                layer += 2 * 8;
                            }

                            GroundLayers[0].Tiles[x, y] = new TileAnim(new Loc2D(), 0);
                        }
                        else if (blockedDirs[(int)Direction8.Down] && blockedDirs[(int)Direction8.Left] && !blockedDirs[(int)Direction8.Up] && blockedDirs[(int)Direction8.Right])
                        {
                            int layer = 4;
                            if (blockedDirs[(int)Direction8.DownLeft])
                            {
                                layer += 1 * 8;
                            }

                            if (blockedDirs[(int)Direction8.DownRight])
                            {
                                layer += 2 * 8;
                            }

                            GroundLayers[0].Tiles[x, y] = new TileAnim(new Loc2D(), 0);
                        }
                        else if (blockedDirs[(int)Direction8.Down] && blockedDirs[(int)Direction8.Left] && blockedDirs[(int)Direction8.Up] && !blockedDirs[(int)Direction8.Right])
                        {
                            int layer = 5;
                            if (blockedDirs[(int)Direction8.UpLeft])
                            {
                                layer += 1 * 8;
                            }

                            if (blockedDirs[(int)Direction8.DownLeft])
                            {
                                layer += 2 * 8;
                            }

                            GroundLayers[0].Tiles[x, y] = new TileAnim(new Loc2D(), 0);
                        }
                        else if (!blockedDirs[(int)Direction8.Down] && !blockedDirs[(int)Direction8.Left] && blockedDirs[(int)Direction8.Up] && blockedDirs[(int)Direction8.Right])
                        {
                            int layer = 34;
                            if (blockedDirs[(int)Direction8.UpRight])
                            {
                                layer += 8;
                            }

                            GroundLayers[0].Tiles[x, y] = new TileAnim(new Loc2D(), 0);
                        }
                        else if (blockedDirs[(int)Direction8.Down] && !blockedDirs[(int)Direction8.Left] && !blockedDirs[(int)Direction8.Up] && blockedDirs[(int)Direction8.Right])
                        {
                            int layer = 35;
                            if (blockedDirs[(int)Direction8.DownRight])
                            {
                                layer += 8;
                            }

                            GroundLayers[0].Tiles[x, y] = new TileAnim(new Loc2D(), 0);
                        }
                        else if (blockedDirs[(int)Direction8.Down] && blockedDirs[(int)Direction8.Left] && !blockedDirs[(int)Direction8.Up] && !blockedDirs[(int)Direction8.Right])
                        {
                            int layer = 32;
                            if (blockedDirs[(int)Direction8.DownLeft])
                            {
                                layer += 8;
                            }

                            GroundLayers[0].Tiles[x, y] = new TileAnim(new Loc2D(), 0);
                        }
                        else if (!blockedDirs[(int)Direction8.Down] && blockedDirs[(int)Direction8.Left] && blockedDirs[(int)Direction8.Up] && !blockedDirs[(int)Direction8.Right])
                        {
                            int layer = 33;
                            if (blockedDirs[(int)Direction8.UpLeft])
                            {
                                layer += 8;
                            }

                            GroundLayers[0].Tiles[x, y] = new TileAnim(new Loc2D(), 0);
                        }
                        else if (blockedDirs[(int)Direction8.Down] && !blockedDirs[(int)Direction8.Left] && !blockedDirs[(int)Direction8.Up] && !blockedDirs[(int)Direction8.Right])
                        {
                            GroundLayers[0].Tiles[x, y] = new TileAnim(new Loc2D(36, 0), 0);
                        }
                        else if (!blockedDirs[(int)Direction8.Down] && blockedDirs[(int)Direction8.Left] && !blockedDirs[(int)Direction8.Up] && !blockedDirs[(int)Direction8.Right])
                        {
                            GroundLayers[0].Tiles[x, y] = new TileAnim(new Loc2D(37, 0), 0);
                        }
                        else if (!blockedDirs[(int)Direction8.Down] && !blockedDirs[(int)Direction8.Left] && blockedDirs[(int)Direction8.Up] && !blockedDirs[(int)Direction8.Right])
                        {
                            GroundLayers[0].Tiles[x, y] = new TileAnim(new Loc2D(38, 0), 0);
                        }
                        else if (!blockedDirs[(int)Direction8.Down] && !blockedDirs[(int)Direction8.Left] && !blockedDirs[(int)Direction8.Up] && blockedDirs[(int)Direction8.Right])
                        {
                            GroundLayers[0].Tiles[x, y] = new TileAnim(new Loc2D(39, 0), 0);
                        }
                        else if (!blockedDirs[(int)Direction8.Down] && blockedDirs[(int)Direction8.Left] && !blockedDirs[(int)Direction8.Up] && blockedDirs[(int)Direction8.Right])
                        {
                            GroundLayers[0].Tiles[x, y] = new TileAnim(new Loc2D(44, 0), 0);
                        }
                        else if (blockedDirs[(int)Direction8.Down] && !blockedDirs[(int)Direction8.Left] && blockedDirs[(int)Direction8.Up] && !blockedDirs[(int)Direction8.Right])
                        {
                            GroundLayers[0].Tiles[x, y] = new TileAnim(new Loc2D(45, 0), 0);
                        }
                        else if (!blockedDirs[(int)Direction8.Down] && !blockedDirs[(int)Direction8.Left] && !blockedDirs[(int)Direction8.Up] && !blockedDirs[(int)Direction8.Right])
                        {
                            GroundLayers[0].Tiles[x, y] = new TileAnim(new Loc2D(46, 0), 0);
                        }
                    }
                    else
                    {
                        MapArray[x, y] = new Tile(PMDToolkit.Enums.TileType.Walkable, 0, 0, 0);
                        GroundLayers[0].Tiles[x, y] = new TileAnim(new Loc2D(47, 0), 0);
                    }
                }
            }

            GenItems();
            SpawnNpcs();
        }