// 나뭇가지 방향조절 public void SetBranchDirection(BranchDir brDir) { var nDir = (int)brDir; if (nDir == m_nDirection) { return; } var rV3 = new Vector3(0, 180 * nDir, 0); gameObject.transform.rotation = Quaternion.Euler(rV3); m_nDirection = nDir; }
public void Close(BranchDir dir) { switch (dir) { case BranchDir.North: if (north != State.Open) { Debug.WriteLine("Something wrong tried to close not open branch in room: " + Id); } else { north = State.Closed; } break; case BranchDir.East: if (east != State.Open) { Debug.WriteLine("Something wrong tried to close not open branch in room: " + Id); } else { east = State.Closed; } break; case BranchDir.South: if (south != State.Open) { Debug.WriteLine("Something wrong tried to close not open branch in room: " + Id); } else { south = State.Closed; } break; case BranchDir.West: if (west != State.Open) { Debug.WriteLine("Something wrong tried to close not open branch in room: " + Id); } else { west = State.Closed; } break; } }
public bool IsOpen(BranchDir dir) { switch (dir) { case BranchDir.North: if (north == State.Open) { return(true); } else { return(false); } case BranchDir.East: if (east == State.Open) { return(true); } else { return(false); } case BranchDir.South: if (south == State.Open) { return(true); } else { return(false); } case BranchDir.West: if (west == State.Open) { return(true); } else { return(false); } default: return(false); } }
public bool Allocate(BranchDir dir, Hallway hallway) { switch (dir) { case BranchDir.North: if (north == State.Allocated) { return(false); } north = State.Allocated; northHallway = hallway; return(true); case BranchDir.East: if (east == State.Allocated) { return(false); } east = State.Allocated; eastHallway = hallway; return(true); case BranchDir.South: if (south == State.Allocated) { return(false); } south = State.Allocated; southHallway = hallway; return(true); case BranchDir.West: if (west == State.Allocated) { return(false); } west = State.Allocated; westHallway = hallway; return(true); default: return(false); } }
public bool OpenBranch(int i) { BranchDir dir = (BranchDir)i; switch (dir) { case BranchDir.North: if (north != State.None) { return(false); } north = State.Open; return(true); case BranchDir.East: if (east != State.None) { return(false); } east = State.Open; return(true); case BranchDir.South: if (south != State.None) { return(false); } south = State.Open; return(true); case BranchDir.West: if (west != State.None) { return(false); } west = State.Open; return(true); default: return(false); } }
public bool IsAllocated(BranchDir dir) { switch (dir) { case BranchDir.North: if (north == State.Allocated) { return(true); } return(false); case BranchDir.East: if (east == State.Allocated) { return(true); } return(false); case BranchDir.South: if (south == State.Allocated) { return(true); } return(false); case BranchDir.West: if (west == State.Allocated) { return(true); } return(false); default: return(false); } }
public Hallway GetHallway(BranchDir dir) { switch (dir) { case BranchDir.North: if (north == State.Allocated) { return(northHallway); } return(null); case BranchDir.East: if (east == State.Allocated) { return(eastHallway); } return(null); case BranchDir.South: if (south == State.Allocated) { return(southHallway); } return(null); case BranchDir.West: if (west == State.Allocated) { return(westHallway); } return(null); default: return(null); } }
void Generate(int size, bool gen_npc) { List <Room> rooms = new List <Room>(); List <Hallway> hallways = new List <Hallway>(); //Start position /*int s = random.Next(4); * * int sx = s % 2 * (size - 16); * int sy = (s >> 1) * (size - 16);*/ Room start = new Room(0, 0, 16, 16); //Open up starting branches start.OpenBranch(1); start.OpenBranch(2); rooms.Add(start); Room room = start; int rn = 0; int hn = 0; int depth = 100; //First branch extra long int again = 10; while (room != null) { //Branch depth achieved go back to previous room for new branching if (depth == 0) { while (!room.HasOpenBranch()) { room = room.Parent; if (room == null) { break; } } if (room != null) { depth = random.Next(5, 10); Debug.WriteLine("Starting new branch"); } else { break; } } //If we closed of all branches without adding a new room we reached the potential end point of this branch if (!room.HasOpenBranch()) { depth = 0; Debug.WriteLine("Closed off all branches"); continue; } int width; int height; int x; int y; int w = NextGaussian(20, 10); int h = NextGaussian(20, 10); if (w < 10 || h < 10) { continue; } if (again == 3) { w = 20; h = 10; } if (again == 2) { w = 10; h = 20; } if (again == 1) { w = 10; h = 10; } BranchDir dir = (BranchDir)random.Next(4); while (!room.IsOpen(dir)) { dir = (BranchDir)random.Next(4); } switch (dir) { case BranchDir.North: { width = random.Next(2, 4); height = random.Next(4, 6); if ((room.Y - height - h) > 0) { x = random.Next(room.CenterX - w / 2, room.CenterX - width / 2); if (x < 0) { x = room.X; } y = room.Y - height - h; if ((x + w) < size && (y + h) < size) { Hallway hallway = new Hallway(room.CenterX - width / 2, room.Y - height, width, height, HallWayOrientation.Vertical); Room new_room = new Room(x, y, w, h, room); bool good = true; rooms.ForEach(r => { if (r.IsInside(new_room)) { good = false; } }); if (good) { rooms.Add(new_room); hallways.Add(hallway); new_room.Allocate(BranchDir.South, hallway); room.Allocate(BranchDir.North, hallway); int b; if (depth >= 3) { b = random.Next(2, 3); } else { b = random.Next(1, 3); } if (depth == 1) { b = 0; } if (depth >= 5) { b = 3; } while (b != 0) { int open_b = random.Next(4); if (new_room.OpenBranch(open_b)) { b--; } } room = new_room; depth--; rn++; hn++; } else { if (again == 0) { room.Close(BranchDir.North); Debug.WriteLine("10 retry was not enough on north"); again = 10; } again--; } } else { room.Close(BranchDir.North); } } else { room.Close(BranchDir.North); } break; } case BranchDir.East: { width = random.Next(4, 6); height = random.Next(2, 4); if ((room.X + room.Width + width + w) < size) { x = room.X + room.Width + width; y = random.Next(room.CenterY - h / 2, room.CenterY - width / 2); if (y < 0) { y = room.Y; } if ((x + w) < size && (y + h) < size) { Hallway hallway = new Hallway(room.X + room.Width, room.CenterY - height / 2, width, height, HallWayOrientation.Horizontal); Room new_room = new Room(x, y, w, h, room); bool good = true; rooms.ForEach(r => { if (r.IsInside(new_room)) { good = false; } }); if (good) { rooms.Add(new_room); hallways.Add(hallway); new_room.Allocate(BranchDir.West, hallway); room.Allocate(BranchDir.East, hallway); int b; if (depth >= 3) { b = random.Next(2, 3); } else { b = random.Next(1, 3); } if (depth == 1) { b = 0; } if (depth >= 5) { b = 3; } while (b != 0) { int open_b = random.Next(4); if (new_room.OpenBranch(open_b)) { b--; } } room = new_room; depth--; rn++; hn++; } else { if (again == 0) { room.Close(BranchDir.East); Debug.WriteLine("10 retry was not enough east"); again = 10; } again--; } } else { room.Close(BranchDir.East); } } else { room.Close(BranchDir.East); } break; } case BranchDir.South: { width = random.Next(2, 4); height = random.Next(4, 6); if ((room.Y + room.Height + height + h) < size) { x = random.Next(room.CenterX - w / 2, room.CenterX - width / 2); if (x < 0) { x = room.X; } y = room.Y + room.Height + height; if ((x + w) < size && (y + h) < size) { Hallway hallway = new Hallway(room.CenterX - width / 2, room.Y + room.Height, width, height, HallWayOrientation.Vertical); Room new_room = new Room(x, y, w, h, room); bool good = true; rooms.ForEach(r => { if (r.IsInside(new_room)) { good = false; } }); if (good) { rooms.Add(new_room); hallways.Add(hallway); new_room.Allocate(BranchDir.North, hallway); room.Allocate(BranchDir.South, hallway); int b; if (depth >= 3) { b = random.Next(2, 3); } else { b = random.Next(1, 3); } if (depth == 1) { b = 0; } if (depth >= 5) { b = 3; } while (b != 0) { int open_b = random.Next(4); if (new_room.OpenBranch(open_b)) { b--; } } room = new_room; depth--; rn++; hn++; } else { if (again == 0) { room.Close(BranchDir.South); Debug.WriteLine("10 retry was not enough on south"); again = 10; } again--; } } else { room.Close(BranchDir.South); } } else { room.Close(BranchDir.South); } break; } case BranchDir.West: { width = random.Next(4, 6); height = random.Next(2, 4); if ((room.X - width - w) > 0) { x = room.X - width - w; y = random.Next(room.CenterY - h / 2, room.CenterY - width / 2); if (y < 0) { y = room.Y; } if ((x + w) < size && (y + h) < size) { Hallway hallway = new Hallway(room.X - width, room.CenterY - height / 2, width, height, HallWayOrientation.Horizontal); Room new_room = new Room(x, y, w, h, room); bool good = true; rooms.ForEach(r => { if (r.IsInside(new_room)) { good = false; } }); if (good) { rooms.Add(new_room); hallways.Add(hallway); new_room.Allocate(BranchDir.East, hallway); room.Allocate(BranchDir.West, hallway); int b; if (depth >= 3) { b = random.Next(2, 3); } else { b = random.Next(1, 3); } if (depth == 1) { b = 0; } if (depth >= 5) { b = 3; } while (b != 0) { int open_b = random.Next(4); if (new_room.OpenBranch(open_b)) { b--; } } room = new_room; depth--; rn++; hn++; } else { if (again == 0) { room.Close(BranchDir.West); Debug.WriteLine("10 retry was not enough on west"); again = 10; } again--; } } else { room.Close(BranchDir.West); } } else { room.Close(BranchDir.West); } break; } } } Debug.WriteLine("Generated: " + rn + " rooms and " + hn + " hallways"); //Create map CreateMap(rooms, hallways, size); Debug.WriteLine("Map created"); //Generate sectors //Sector sector = new Sector(0, 0, size, size); //Temp //sector.Finalise(); //map.AddSector(sector); CreateSectors(rooms); CreateHallwaySectors(hallways); Debug.WriteLine("Sectors created"); map.Finalise(); //Make minimap CreateMinimapData(rooms, hallways, size + 2); Debug.Write("Minimap data created"); //Generate NPCs if (gen_npc) { int s = GenerateEntities(rooms); Debug.WriteLine("Generated: " + s + " NPCs & Objects"); } }