예제 #1
0
        public DungeonArrayFloor(GeneratorOptions options, RDungeonChamberReq req)
        {
            Rooms = new DungeonArrayRoom[4, 4]; //array of all rooms
            VHalls = new DungeonArrayHall[4, 3]; //vertical halls
            HHalls = new DungeonArrayHall[3, 4]; //horizontal halls
            Start = new DungeonPoint(-1, -1);     //marks spawn point
            End = new DungeonPoint(-1, -1);       //marks stairs
            Chamber = new DungeonPoint(-1, -1);       //marks chamber
            int i, j, a = -1, b; //counter variables
            MapArray = new int[50, 50]; // stores map grid
            int x, y;      // used for navigating map array
            bool isDone;   // bool used for various purposes

            // Part of Options class now
            //int trapFreq = 66; // adjust to number between 0 and 100 to see changes
            //int trapMin = 5;  // adjust to number between 0 and 255 to see changes
            //int trapMax = 30; // adjust to number between 0 and 255 to see changes

            //initialize map array to empty
            for (y = 0; y < 50; y++) {
                for (x = 0; x < 50; x++) {
                    MapArray[x, y] = UBLOCK;
                }
            }

            //initialize all rooms+halls to closed by default
            for (x = 0; x <= Rooms.GetUpperBound(0); x++) {
                for (y = 0; y <= Rooms.GetUpperBound(1); y++) {
                    Rooms[x, y] = new DungeonArrayRoom();
                }
            }

            for (x = 0; x <= VHalls.GetUpperBound(0); x++) {
                for (y = 0; y <= VHalls.GetUpperBound(1); y++) {
                    VHalls[x, y] = new DungeonArrayHall();
                }
            }

            for (x = 0; x <= HHalls.GetUpperBound(0); x++) {
                for (y = 0; y <= HHalls.GetUpperBound(1); y++) {
                    HHalls[x, y] = new DungeonArrayHall();
                }
            }

            // path generation algorithm
            Start = new DungeonPoint(random.Next(0, Rooms.GetUpperBound(0) + 1), random.Next(0, Rooms.GetUpperBound(1) + 1)); // randomly determine start room
            DungeonPoint wanderer = Start;

            //start = random.Next(0, 16); // randomly determine start room
            //x = start;
            i = 0;
            j = random.Next(0, 6) + 5; // magic numbers, determine what the dungeon looks like (in general, paths)
            b = -1; // direction of movement
            do {
                if (random.Next(0, (2 + i)) == 0) {//will end the current path and start a new one from the start
                    if (random.Next(0, 2) == 0) {//determine if the room should be open or a hall
                        Rooms[wanderer.X, wanderer.Y].Opened = OPEN;
                    } else {
                        Rooms[wanderer.X, wanderer.Y].Opened = HALL;
                    }
                    i++;
                    wanderer = Start;
                    b = -1;
                } else {
                    bool working = true;
                    do {
                        DungeonPoint sample = wanderer;
                        y = random.Next(0, 4);
                        if (y != b) {//makes sure there is no backtracking
                            switch (y) {
                                case 0:

                                    sample.Y--;
                                    b = 1;
                                    break;
                                case 1:

                                    sample.Y++;
                                    b = 0;
                                    break;
                                case 2:

                                    sample.X--;
                                    b = 3;
                                    break;
                                case 3:

                                    sample.X++;
                                    b = 2;
                                    break;
                            }
                            if (sample.X >= 0 && sample.X <= Rooms.GetUpperBound(0) && sample.Y >= 0 && sample.Y <= Rooms.GetUpperBound(1)) {// a is the room to be checked after making a move between rooms
                                openHallBetween(wanderer, sample);
                                wanderer = sample;
                                working = false;
                            }
                        } else {
                            b = -1;
                        }
                    } while (working);

                    if (random.Next(0, 2) == 0) {//determine if the room should be open or a hall
                        Rooms[wanderer.X, wanderer.Y].Opened = OPEN;
                    } else {
                        Rooms[wanderer.X, wanderer.Y].Opened = HALL;
                    }
                }
            } while (i < j);

            Rooms[Start.X, Start.Y].Opened = OPEN;

            //Determine key rooms
            if (req == null || req.End != Enums.Acceptance.Always) {
                isDone = false;
                do { //determine ending room randomly
                    x = random.Next(0, Rooms.GetUpperBound(0) + 1);
                    y = random.Next(0, Rooms.GetUpperBound(1) + 1);
                    if (Rooms[x, y].Opened == OPEN) {
                        End = new DungeonPoint(x, y);
                        //Console.WriteLine(x);
                        isDone = true;
                    }
                } while (!isDone);
            }
            Start = new DungeonPoint(-1, -1);
            if (req == null || req.Start != Enums.Acceptance.Always) {
                isDone = false;
                do { //determine starting room randomly
                    x = random.Next(0, Rooms.GetUpperBound(0) + 1);
                    y = random.Next(0, Rooms.GetUpperBound(1) + 1);
                    if (Rooms[x, y].Opened == OPEN) {
                        Start = new DungeonPoint(x, y);
                        //Console.WriteLine(x);
                        isDone = true;
                    }
                } while (!isDone);
            }

            if (req != null) {
                isDone = false;
                for (int n = 0; n < 100; n++) { //determine chamber room randomly
                    x = random.Next(0, Rooms.GetUpperBound(0) + 1);
                    y = random.Next(0, Rooms.GetUpperBound(1) + 1);
                    bool approved = true;
                    //if the chamber cannot be on a start, and it picked the start
                    if (req.Start == Enums.Acceptance.Never && Start.X == x && Start.Y == y) {
                        approved = false;
                    }
                    //if the chamber cannot be on an end, and it picked the end
                    if (req.End == Enums.Acceptance.Never && End.X == x && End.Y == y) {
                        approved = false;
                    }
                    //if the chamber demands a certain setup, and it doesn't meet the setup
                    if (req.TopAcceptance == Enums.Acceptance.Always) {
                        if (y == 0 || !VHalls[x, y - 1].Open) approved = false;
                    } else if (req.TopAcceptance == Enums.Acceptance.Never) {
                        if (y > 0 && VHalls[x, y - 1].Open) approved = false;
                    }
                    if (req.BottomAcceptance == Enums.Acceptance.Always) {
                        if (y == Rooms.GetUpperBound(1) || !VHalls[x, y].Open) approved = false;
                    } else if (req.BottomAcceptance == Enums.Acceptance.Never) {
                        if (y < Rooms.GetUpperBound(1) && VHalls[x, y].Open) approved = false;
                    }
                    if (req.LeftAcceptance == Enums.Acceptance.Always) {
                        if (x == 0 || !HHalls[x - 1, y].Open) approved = false;
                    } else if (req.LeftAcceptance == Enums.Acceptance.Never) {
                        if (x > 0 && HHalls[x - 1, y].Open) approved = false;
                    }
                    if (req.RightAcceptance == Enums.Acceptance.Always) {
                        if (x == Rooms.GetUpperBound(0) || !HHalls[x, y].Open) approved = false;
                    } else if (req.RightAcceptance == Enums.Acceptance.Never) {
                        if (x < Rooms.GetUpperBound(0) && HHalls[x, y].Open) approved = false;
                    }
                    if (Rooms[x, y].Opened == OPEN && approved) {
                        //set chamber to the point
                        Chamber = new DungeonPoint(x, y);

                        //if start or end is on this point, set to this location
                        if (End.X == -1 && End.Y == -1) {
                            End = new DungeonPoint(x, y);
                        }
                        if (Start.X == -1 && Start.Y == -1) {
                            Start = new DungeonPoint(x, y);
                        }

                        //Console.WriteLine(x);
                        isDone = true;
                        break;
                    }
                }

                if (!isDone) {
                    //chamber could not be placed; reroll start and end if they were set to -1 assuming that chamber was going to take care of it
                    if (End.X == -1 && End.Y == -1) {
                        isDone = false;
                        do { //determine ending room randomly
                            x = random.Next(0, Rooms.GetUpperBound(0) + 1);
                            y = random.Next(0, Rooms.GetUpperBound(1) + 1);
                            if (Rooms[x, y].Opened == OPEN) {
                                End = new DungeonPoint(x, y);
                                //Console.WriteLine(x);
                                isDone = true;
                            }
                        } while (!isDone);
                    }

                    if (Start.X == -1 && Start.Y == -1) {
                        isDone = false;
                        do { //determine starting room randomly
                            x = random.Next(0, Rooms.GetUpperBound(0) + 1);
                            y = random.Next(0, Rooms.GetUpperBound(1) + 1);
                            if (Rooms[x, y].Opened == OPEN) {
                                Start = new DungeonPoint(x, y);
                                //Console.WriteLine(x);
                                isDone = true;
                            }
                        } while (!isDone);
                    }
                }
            }

            // begin part 2, creating ASCII map
            //create rooms
            //Console.WriteLine("ROOMS:");
            //Console.WriteLine(Chamber.X + "," + Chamber.Y);
            for (i = 0; i <= Rooms.GetUpperBound(0); i++) {
                for (j = 0; j <= Rooms.GetUpperBound(1); j++) {
                    if (Rooms[i, j].Opened != CLOSED && (Chamber.X != i || Chamber.Y != j)) {
                        createRoom(i, j, options, req);
                    }
                }
            }
            //Console.WriteLine(Chamber.X + "," + Chamber.Y);
            //create chamber
            if (Chamber.X > -1 && Chamber.Y > -1) {
                createChamber(options, req);
            }

            //Console.WriteLine("DRAW:");
            for (i = 0; i <= Rooms.GetUpperBound(0); i++) {
                for (j = 0; j <= Rooms.GetUpperBound(1); j++) {
                    if (Rooms[i, j].Opened != CLOSED) {
                        drawRoom(i, j);
                    }
                }
            }

            for (i = 0; i <= Rooms.GetUpperBound(0); i++) {
                for (j = 0; j <= Rooms.GetUpperBound(1); j++) {
                    if (Rooms[i, j].Opened != CLOSED) {
                        padSingleRoom(i, j);
                    }
                }
            }
            //Console.WriteLine("HALLS:");

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

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

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

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

            // create halls
            //for (i = 0; i < 12; i++) {
            //    if (VHalls[i] == OPEN) {
            //        createVHall(i, options);
            //    }
            //    if (HHalls[i] == OPEN) {
            //        createHHall(i, options);
            //    }
            //}
            //Console.WriteLine("SE:");
            if (Start.X != Chamber.X || Start.Y != Chamber.Y) {
                addSEpos(Start, START, req);
            }
            if (End.X != Chamber.X || End.Y != Chamber.Y) {
                addSEpos(End, END, req);
            }

            //Console.WriteLine("WATER:");
            //add water
            DrawWater(options);

            DrawCraters(options);

            //Console.WriteLine("TRAPS:");
            // add traps
            int finalTraps = random.Next(options.TrapMin, options.TrapMax + 1);
            if (finalTraps > 0) {
                for (i = 0; i < finalTraps; i++) { // add traps
                    for (j = 0; j < 200; j++) {
                        a = random.Next(0, Rooms.GetUpperBound(0) + 1);
                        b = random.Next(0, Rooms.GetUpperBound(1) + 1);
                        x = random.Next(Rooms[a, b].StartX, Rooms[a, b].EndX + 1);
                        y = random.Next(Rooms[a, b].StartY, Rooms[a, b].EndY + 1);
                        if (Rooms[a, b].Opened == OPEN && MapArray[x, y] == GROUND) {
                            MapArray[x, y] = TRAPTILE;
                            break;
                        }
                    }
                }
            }
            //if (options.TrapFrequency > 0 && options.TrapMax > 0) {
            //    for (i = options.TrapMin; i < options.TrapMax; i++) {
            //        if (random.Next(0, 100) + 1 >= options.TrapFrequency) { // then generate a trap
            //            a = random.Next(0, 16);
            //            convertRoomToXY(a, ref x, ref  y);
            //            x = x + 1 + (random.Next(0, 6));
            //            y = y + 1 + (random.Next(0, 5));
            //            if (mapArray[y, x] == '.') {
            //                mapArray[y, x] = 'Q';
            //            }
            //        }
            //    }
            //}
            //Console.WriteLine("ITEMS:");
            // generate items (up to 16) ~moved to its own method
            //for (i = 0; i < 16; i++) {
            //bool success = false;
            //    for (int k = 0; k < 200; k++) { // do until you succeed
            //        a = random.Next(0, 16);
            //convertRoomToXY(a, ref x, ref y);
            //        x = random.Next(room[a,1], room[a,3]+1);
            //        y = random.Next(room[a,2], room[a,4]+1);
            //        if (mapArray[y, x] == '.' /* mapArray[y, x] != 'S' && mapArray[y, x] != 'E' &&
            //                                     mapArray[y, x] != ' '*/) {
            //            mapArray[y, x] = (char)(96 + i); //ascii for lowercase letters
            //            break;
            //        }
            //    }
            //}

            //return MapArray;
        }
예제 #2
0
        public static RDungeonChamberReq GetChamberReq(int chamberNum, string string1, string string2, string string3)
        {
            RDungeonChamberReq req = new RDungeonChamberReq();
            try {
                switch (chamberNum) {
                    case 1: {//pre-mapped, does not allow start or end
                        string[] start = string2.Split(':');
                        string[] end = string3.Split(':');
                        int sourceX = start[0].ToInt();
                        int sourceY = start[1].ToInt();
                        req.MinX = end[0].ToInt() - sourceX + 1;
                        req.MinY = end[1].ToInt() - sourceY + 1;
                        req.MaxX = req.MinX;
                        req.MaxY = req.MinY;
                        req.Start = Enums.Acceptance.Never;
                        req.End = Enums.Acceptance.Never;

                        IMap sourceMap = MapManager.RetrieveMap(string1.ToInt());
                        List<int> entrances = new List<int>();
                        for (int x = 0; x < req.MinX; x++) {
                            if (sourceMap.Tile[sourceX + x, sourceY].RDungeonMapValue == DungeonArrayFloor.GROUND ||
                                sourceMap.Tile[sourceX + x, sourceY].RDungeonMapValue == DungeonArrayFloor.HALLTILE ||
                                sourceMap.Tile[sourceX + x, sourceY].RDungeonMapValue == DungeonArrayFloor.DOORTILE) {
                                entrances.Add(x);
                            }
                        }
                        if (entrances.Count == 0) {
                            req.TopAcceptance = Enums.Acceptance.Never;
                        } else {
                            req.TopPassage = entrances[Server.Math.Rand(0, entrances.Count)];
                        }

                        entrances = new List<int>();
                        for (int x = 0; x < req.MinX; x++) {
                            if (sourceMap.Tile[sourceX + x, sourceY+req.MinY-1].RDungeonMapValue == DungeonArrayFloor.GROUND ||
                                sourceMap.Tile[sourceX + x, sourceY+req.MinY-1].RDungeonMapValue == DungeonArrayFloor.HALLTILE ||
                                sourceMap.Tile[sourceX + x, sourceY+req.MinY-1].RDungeonMapValue == DungeonArrayFloor.DOORTILE) {
                                entrances.Add(x);
                            }
                        }
                        if (entrances.Count == 0) {
                            req.BottomAcceptance = Enums.Acceptance.Never;
                        } else {
                            req.BottomPassage = entrances[Server.Math.Rand(0, entrances.Count)];
                        }

                        entrances = new List<int>();
                        for (int y = 0; y < req.MinY; y++) {
                            if (sourceMap.Tile[sourceX, sourceY+y].RDungeonMapValue == DungeonArrayFloor.GROUND ||
                                sourceMap.Tile[sourceX, sourceY+y].RDungeonMapValue == DungeonArrayFloor.HALLTILE ||
                                sourceMap.Tile[sourceX, sourceY+y].RDungeonMapValue == DungeonArrayFloor.DOORTILE) {
                                entrances.Add(y);
                            }
                        }
                        if (entrances.Count == 0) {
                            req.LeftAcceptance = Enums.Acceptance.Never;
                        } else {
                            req.LeftPassage = entrances[Server.Math.Rand(0, entrances.Count)];
                        }

                        entrances = new List<int>();
                        for (int y = 0; y < req.MinY; y++) {
                            if (sourceMap.Tile[sourceX+req.MinX-1, sourceY+y].RDungeonMapValue == DungeonArrayFloor.GROUND ||
                                sourceMap.Tile[sourceX+req.MinX-1, sourceY+y].RDungeonMapValue == DungeonArrayFloor.HALLTILE ||
                                sourceMap.Tile[sourceX+req.MinX-1, sourceY+y].RDungeonMapValue == DungeonArrayFloor.DOORTILE) {
                                entrances.Add(y);
                            }
                        }

                        if (entrances.Count == 0) {
                            req.RightAcceptance = Enums.Acceptance.Never;
                        } else {
                            req.RightPassage = entrances[Server.Math.Rand(0, entrances.Count)];
                        }
                        }
                        break;
                    case 2: {//no chamber
                            req.TopPassage = -1;
                            req.TopAcceptance = Enums.Acceptance.Never;
                            req.BottomPassage = -1;
                            req.BottomAcceptance = Enums.Acceptance.Never;
                            req.LeftPassage = -1;
                            req.LeftAcceptance = Enums.Acceptance.Never;
                            req.RightPassage = -1;
                            req.RightAcceptance = Enums.Acceptance.Never;
                        }
                        break;
                    case 3: {//chamber that accepts start and end

                        }
                        break;
                    case 4: {//Ice Puzzle
                            req.Start = Enums.Acceptance.Never;
                            req.End = Enums.Acceptance.Never;
                            string[] parse = string1.Split(':');
                            if (parse[0] == "1") {
                                req.Start = Enums.Acceptance.Always;
                            }
                            if (parse[1] == "1") {
                                req.End = Enums.Acceptance.Always;
                            }
                            parse = string3.Split(':');
                            req.MinX = parse[0].ToInt()+2;
                            req.MinY = parse[1].ToInt()+2;

                            if (req.MinX > 50) req.MinX = 50;
                            if (req.MinY > 50) req.MinY = 50;
                            if (req.MinX < 4) req.MinX = 4;
                            if (req.MinY < 4) req.MinY = 4;

                            req.MaxX = req.MinX;
                            req.MaxY = req.MinY;

                            req.TopPassage = 0;
                            req.BottomPassage = req.MinX-1;
                            req.LeftPassage = 0;
                            req.RightPassage = req.MinY-1;
                        }
                        break;
                    case 10: {//single-item chamber, does not allow start or end
                        req.MinX = 5;
                        req.MinY = 5;
                        req.MaxX = req.MinX;
                        req.MaxY = req.MinY;
                        req.Start = Enums.Acceptance.Never;
                        req.End = Enums.Acceptance.Never;

                        }
                        break;
                    case 11: {//3x3 kecleon shop, does not allow start or end
                        req.MinX = 7;
                        req.MinY = 7;
                        req.MaxX = req.MinX;
                        req.MaxY = req.MinY;
                        req.Start = Enums.Acceptance.Never;
                        req.End = Enums.Acceptance.Never;

                        }
                        break;
                    default: {
                            req.MinX = 2;
                            req.MaxX = 2;
                            req.MinY = 2;
                            req.MaxY = 2;
                            req.TopPassage = -1;
                            req.TopAcceptance = Enums.Acceptance.Maybe;
                            req.BottomPassage = -1;
                            req.BottomAcceptance = Enums.Acceptance.Maybe;
                            req.LeftPassage = -1;
                            req.LeftAcceptance = Enums.Acceptance.Maybe;
                            req.RightPassage = -1;
                            req.RightAcceptance = Enums.Acceptance.Maybe;
                            req.Start = Enums.Acceptance.Always;
                            req.End = Enums.Acceptance.Always;
                        }
                        break;
                }
            } catch (Exception e) {
                Messenger.AdminMsg("Error: GetChamberReq", Text.Black);
                Messenger.AdminMsg(e.ToString(), Text.Black);
            }

            return req;
        }
예제 #3
0
        void createVHall(int hallX, int hallY, GeneratorOptions options, RDungeonChamberReq req)
        {
            //Console.Write("V"+hall+":");
            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 {
                    //Console.WriteLine(";");
                    return;
                }
            }
            n--;

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

            y = startRoom.EndY;

            m = random.Next(options.HallTurnMin, options.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 = random.Next(startRoom.StartX, startRoom.EndX + 1); //picks a X coordinate to start at

            if (Chamber.X == hallX && Chamber.Y == hallY && req != null && req.BottomPassage > -1) {
                x = startRoom.StartX + req.BottomPassage;
            }

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

            if (m <= 0 && (x > endRoom.EndX || x < endRoom.StartX ||
                (Chamber.X == hallX && Chamber.Y == hallY + 1 && req != null && req.TopPassage > -1 && x != endRoom.StartX + req.TopPassage))) {//checks if at least one turn is needed to make rooms meet
                m = 1;
            }

            //Console.Write("("+room[startRoom,1]+"."+room[startRoom,3]+")");
            for (int i = 0; i <= m; i++) {
                if (i == m) {
                    var = random.Next(endRoom.StartX, endRoom.EndX + 1) - x;
                    if (Chamber.X == hallX && Chamber.Y == hallY + 1 && req != null && req.TopPassage > -1) {
                        var = endRoom.StartX + req.TopPassage - x;
                    }
                } else {
                    var = random.Next(options.HallVarMin, options.HallVarMax + 1);
                    if (random.Next(0, 2) == 0) {
                        var = -var;
                    }
                }

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

                    x += var;
                    VHalls[hallX, hallY].TurnPoints.Add(new DungeonPoint(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);
                }
                //Console.Write("("+n+","+r+")");
                //addVertHall(x, y, h, mapArray);

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

            VHalls[hallX, hallY].TurnPoints[VHalls[hallX, hallY].TurnPoints.Count - 1] = new DungeonPoint(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);
            //Console.WriteLine(";");
        }
예제 #4
0
        void createRoom(int roomX, int roomY, GeneratorOptions options, RDungeonChamberReq req)
        {
            if (Rooms[roomX, roomY].StartX > -1) {
                return;
            }

            int x = 0, y = 0, u, v, w, l; // variables used for position
            convertRoomToXY(roomX, roomY, ref x, ref y);

            //Determine room length/width
            if (Rooms[roomX, roomY].Opened == HALL) {
                w = 0;
                l = 0;
            } else {

                w = random.Next(options.RoomWidthMin, options.RoomWidthMax + 1) - 1;
                l = random.Next(options.RoomLengthMin, options.RoomLengthMax + 1) - 1;
                if (w < 1) w = 1;
                if (l < 1) l = 1;
                if (w > 47) w = 47;
                if (l > 47) l = 47;
            }

            //move X and Y to a random starting point that still would include the original x/y; exceptional case for l/w under or equal to 6
            if (w <= 6) {
                x -= (random.Next(0, (13 - w)) + w - 7);
            } else {
                x -= random.Next(0, w + 1);
            }
            if (l <= 6) {
                y -= (random.Next(0, (13 - l)) + l - 7);
            } else {
                y -= random.Next(0, l + 1);
            }

            if (x < 1) x = 1;
            if ((x + w) > 48) x = (48 - w);

            if (y < 1) y = 1;
            if ((y + l) > 48) y = (48 - l);

            // once we have our room coords, render it on the map
            u = x + w;
            v = y + l;

            for (int i = 0; i <= Rooms.GetUpperBound(0); i++) {
                for (int j = 0; j <= Rooms.GetUpperBound(1); j++) {
                    if ((roomX == i && roomY == j) ||//if the room is this room
                        ((6 + i * 12) >= x && (6 + i * 12) <= u && (6 + j * 12) >= y && (6 + j * 12) <= v)) {//if the room's anchor point was eclipsed in this room
                        Rooms[i, j].StartX = x;
                        Rooms[i, j].StartY = y;
                        Rooms[i, j].EndX = u;
                        Rooms[i, j].EndY = v;
                    }
                }
            }

            // done
        }
예제 #5
0
        void createHHall(int hallX, int hallY, GeneratorOptions options, RDungeonChamberReq req)
        {
            //Console.Write("H"+hall+":");
            DungeonArrayRoom startRoom = Rooms[hallX, hallY];
            DungeonArrayRoom endRoom = Rooms[hallX + 1, hallY];

            int n = endRoom.StartX - startRoom.EndX; //distance between rooms

            if (n < 1) {
                if (startRoom.StartY > endRoom.EndY || startRoom.EndY < endRoom.StartY) {
                    n++;
                } else {
                    //Console.WriteLine(";");
                    return;
                }
            }
            n--;

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

            x = startRoom.EndX;

            m = random.Next(options.HallTurnMin, options.HallTurnMax + 1); // the number of vertical 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

            y = random.Next(startRoom.StartY, startRoom.EndY + 1); //picks a Y coordinate to start at

            if (Chamber.X == hallX && Chamber.Y == hallY && req != null && req.RightPassage > -1) {
                y = startRoom.StartY + req.RightPassage;
            }

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

            if (m <= 0 && (y > endRoom.EndY || y < endRoom.StartY ||
                (Chamber.X == hallX + 1 && Chamber.Y == hallY && req != null && req.LeftPassage > -1 && y != endRoom.StartY + req.LeftPassage))) {//checks if at least one turn is needed to make rooms meet
                m = 1;
            }

            //Console.Write("("+room[startRoom,2]+"."+room[startRoom,4]+")");
            for (int i = 0; i <= m; i++) {
                if (i == m) {
                    var = random.Next(endRoom.StartY, endRoom.EndY + 1) - y;
                    if (Chamber.X == hallX + 1 && Chamber.Y == hallY && req != null && req.LeftPassage > -1) {
                        var = endRoom.StartY + req.LeftPassage - y;
                    }
                } else {
                    var = random.Next(options.HallVarMin, options.HallVarMax + 1);
                    if (random.Next(0, 2) == 0) {
                        var = -var;
                    }
                }
                if (i != 0) {
                    if ((y + var) < 1) var = 1 - y;
                    if ((y + var) > 48) var = 48 - y;
                    //addVertHall(x, y, var, mapArray);

                    y += var;
                    HHalls[hallX, hallY].TurnPoints.Add(new DungeonPoint(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);
                }
                //Console.Write("("+n+","+r+")");
                //addHorizHall(x, y, h, mapArray);

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

            HHalls[hallX, hallY].TurnPoints[HHalls[hallX, hallY].TurnPoints.Count - 1] = new DungeonPoint(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);
            //Console.WriteLine(";");
        }
예제 #6
0
        void createChamber(GeneratorOptions options, RDungeonChamberReq req)
        {
            int x = 0, y = 0, u = 0, v = 0, w, l; // variables used for position
            convertRoomToXY(Chamber.X, Chamber.Y, ref x, ref y);
            int roomX = Chamber.X;
            int roomY = Chamber.Y;
            bool eclipse = true;

            int iterations = 100;
            if (req.MinX == req.MaxX && req.MinY == req.MaxY) {
                iterations = 1;
            }

            for (int k = 0; k < iterations && eclipse == true; k++) {
                //Determine room length/width

                //chamber cannot be a hall
                w = random.Next(req.MinX, req.MaxX + 1) - 1;
                l = random.Next(req.MinY, req.MaxY + 1) - 1;
                if (w < 1) w = 1;
                if (l < 1) l = 1;
                if (w > 47) w = 47;
                if (l > 47) l = 47;

                //move X and Y to a random starting point that still would include the original x/y; exceptional case for l/w under or equal to 6
                if (w <= 6) {
                    x -= (random.Next(0, (13 - w)) + w - 7);
                } else {
                    x -= random.Next(0, w + 1);
                }
                if (l <= 6) {
                    y -= (random.Next(0, (13 - l)) + l - 7);
                } else {
                    y -= random.Next(0, l + 1);
                }

                if (x < 1) x = 1;
                if ((x + w) > 48) x = (48 - w);

                if (y < 1) y = 1;
                if ((y + l) > 48) y = (48 - l);

                // once we have our room coords, render it on the map
                u = x + w;
                v = y + l;

                eclipse = false;
                if (req.Start == Enums.Acceptance.Never || req.End == Enums.Acceptance.Never) {//if we're dealing with a chamber with no tolerance to entrances/exits

                    for (int i = 0; i <= Rooms.GetUpperBound(0); i++) {
                        for (int j = 0; j <= Rooms.GetUpperBound(1); j++) {
                            if (Chamber.X != i || Chamber.Y != j) {//if the room not is this room
                                if (doesBigRoomEclipseSmallRoom(x, y, u, v, Rooms[i, j].StartX, Rooms[i, j].StartY, Rooms[i, j].EndX, Rooms[i, j].EndY)) {
                                    if (req.Start == Enums.Acceptance.Never && Start.X == i && Start.Y == j) {
                                        eclipse = true;
                                    }
                                    if (req.End == Enums.Acceptance.Never && End.X == i && End.Y == j) {
                                        eclipse = true;
                                    }
                                }
                            }
                        }
                    }
                }
            }

            if (eclipse) {
                //the chamber has eclipsed a start/end room; it can't stay
                Chamber = new DungeonPoint(-1, -1);

                //reroll everything

                w = random.Next(options.RoomWidthMin, options.RoomWidthMax + 1) - 1;
                l = random.Next(options.RoomLengthMin, options.RoomLengthMax + 1) - 1;

                if (w < 1) w = 1;
                if (l < 1) l = 1;
                if (w > 47) w = 47;
                if (l > 47) l = 47;

                //move X and Y to a random starting point that still would include the original x/y; exceptional case for l/w under or equal to 6
                if (w <= 6) {
                    x -= (random.Next(0, (13 - w)) + w - 7);
                } else {
                    x -= random.Next(0, w + 1);
                }
                if (l <= 6) {
                    y -= (random.Next(0, (13 - l)) + l - 7);
                } else {
                    y -= random.Next(0, l + 1);
                }

                if (x < 1) x = 1;
                if ((x + w) > 48) x = (48 - w);

                if (y < 1) y = 1;
                if ((y + l) > 48) y = (48 - l);

                // once we have our room coords, render it on the map
                u = x + w;
                v = y + l;
            }

            for (int i = 0; i <= Rooms.GetUpperBound(0); i++) {
                for (int j = 0; j <= Rooms.GetUpperBound(1); j++) {
                    if ((roomX == i && roomY == j) ||//if the room is this room
                        doesBigRoomEclipseSmallRoom(x, y, u, v, Rooms[i, j].StartX, Rooms[i, j].StartY, Rooms[i, j].EndX, Rooms[i, j].EndY)) {
                        Rooms[i, j].StartX = x;
                        Rooms[i, j].StartY = y;
                        Rooms[i, j].EndX = u;
                        Rooms[i, j].EndY = v;
                    }
                }
            }

            // done
        }
예제 #7
0
        void addSEpos(DungeonPoint point, int type, RDungeonChamberReq req)
        {
            //Console.WriteLine("SE Added: " + type);
            int x = 0, y = 0, u = 0, v = 0;
            int c;
            if (type == START) c = STARTTILE;
            else c = ENDTILE;

            //convertRoomToXY(roomNum, ref x, ref y);
            x = Rooms[point.X, point.Y].StartX;
            y = Rooms[point.X, point.Y].StartY;
            u = Rooms[point.X, point.Y].EndX;
            v = Rooms[point.X, point.Y].EndY;

            //Console.WriteLine(roomNum + " " + type);
            //bool done = false;
            int randx = 0, randy = 0;
            for (int i = 0; i < 200; i++) {
                bool approved = true;
                randx = random.Next(x, u + 1);
                randy = random.Next(y, v + 1);
                //Console.WriteLine(x + "," + y + "," + u + "," + v);
                if (MapArray[randx, randy] != GROUND) {
                    approved = false;
                }
                if (Chamber.X > -1 && Chamber.Y > -1) {
                    if (randx >= Rooms[Chamber.X, Chamber.Y].StartX && randx <= Rooms[Chamber.X, Chamber.Y].EndX &&
                        randy >= Rooms[Chamber.X, Chamber.Y].StartY && randy <= Rooms[Chamber.X, Chamber.Y].EndY) {
                        //if the start or end was picked to be inside a chamber
                        if (type == START) {
                            if (req.Start == Enums.Acceptance.Never) {
                                approved = false;
                            } else {
                                //the chamber is okay with having a START inside it
                                Start = new DungeonPoint(Chamber.X, Chamber.Y);
                                return;
                            }
                        } else {
                            if (req.End == Enums.Acceptance.Never) {
                                approved = false;
                            } else {
                                //the chamber is okay with having a End inside it
                                End = new DungeonPoint(Chamber.X, Chamber.Y);
                                return;
                            }
                        }
                    }
                }

                if (approved) {
                    MapArray[randx, randy] = c;
                    return;
                }
            }
            while (true) {//backup plan in case rooms are so small that all there's left is halls and doors
                bool approved = true;
                randx = random.Next(x, u + 1);
                randy = random.Next(y, v + 1);
                //Console.WriteLine(x + "," + y + "," + u + "," + v);
                if (MapArray[randx, randy] != HALLTILE && MapArray[randx, randy] != DOORTILE && MapArray[randx, randy] != GROUND) {
                    approved = false;
                }

                if (Chamber.X > -1 && Chamber.Y > -1) {
                    if (randx >= Rooms[Chamber.X, Chamber.Y].StartX && randx <= Rooms[Chamber.X, Chamber.Y].EndX &&
                        randy >= Rooms[Chamber.X, Chamber.Y].StartY && randy <= Rooms[Chamber.X, Chamber.Y].EndY) {
                        //if the start or end was picked to be inside a chamber
                        if (type == START) {
                            if (req.Start == Enums.Acceptance.Never) {
                                approved = false;
                            } else {
                                //the chamber is okay with having a START inside it
                                Start = new DungeonPoint(Chamber.X, Chamber.Y);
                                return;
                            }
                        } else {
                            if (req.End == Enums.Acceptance.Never) {
                                approved = false;
                            } else {
                                //the chamber is okay with having a End inside it
                                End = new DungeonPoint(Chamber.X, Chamber.Y);
                                return;
                            }
                        }
                    }
                }

                if (approved) {
                    MapArray[randx, randy] = c;
                    return;
                }
            }
        }