protected override bool Build() { InitRooms(); int distance; var retry = 0; var minDistance = (int)Math.Sqrt(Rooms.Count); do { var innerRetry = 0; do { if (innerRetry++ > 10) { return(false); } RoomEntrance = pdsharp.utils.Random.Element(Rooms); }while (RoomEntrance.Width() < 4 || RoomEntrance.Height() < 4); innerRetry = 0; do { if (innerRetry++ > 10) { return(false); } RoomExit = pdsharp.utils.Random.Element(Rooms); }while (RoomExit == RoomEntrance || RoomExit.Width() < 6 || RoomExit.Height() < 6 || RoomExit.Top == 0); Graph.BuildDistanceMap(Rooms, RoomExit); distance = RoomEntrance.Distance(); if (retry++ > 10) { return(false); } }while (distance < minDistance); RoomEntrance.type = RoomType.ENTRANCE; RoomExit.type = RoomType.BOSS_EXIT; Graph.BuildDistanceMap(Rooms, RoomExit); var path = Graph.BuildPath(Rooms, RoomEntrance, RoomExit); Graph.SetPrice(path, RoomEntrance.distance); Graph.BuildDistanceMap(Rooms, RoomExit); path = Graph.BuildPath(Rooms, RoomEntrance, RoomExit); var room = RoomEntrance; foreach (var next in path) { room.Connect(next); room = next; } room = RoomExit.Connected.Keys.First(); if (RoomExit.Top == room.Bottom) { return(false); } foreach (var r in Rooms.Where(r => r.type == RoomType.NULL && r.Connected.Count > 0)) { r.type = RoomType.TUNNEL; } var candidates = new List <Room>(); foreach (var r in RoomExit.Neigbours) { if (!RoomExit.Connected.ContainsKey(r) && (RoomExit.Left == r.Right || RoomExit.Right == r.Left || RoomExit.Bottom == r.Top)) { candidates.Add(r); } } if (candidates.Count > 0) { var kingsRoom = pdsharp.utils.Random.Element(candidates); kingsRoom.Connect(RoomExit); kingsRoom.type = RoomType.RAT_KING; } Paint(); PaintWater(); PaintGrass(); PlaceTraps(); return(true); }
protected override bool Build() { InitRooms(); int distance; var retry = 0; do { if (retry++ > 10) { return(false); } var innerRetry = 0; do { if (innerRetry++ > 10) { return(false); } RoomEntrance = Random.Element(Rooms); } while (RoomEntrance.Width() < 4 || RoomEntrance.Height() < 4); innerRetry = 0; do { if (innerRetry++ > 10) { return(false); } RoomExit = Random.Element(Rooms); }while (RoomExit == RoomEntrance || RoomExit.Width() < 7 || RoomExit.Height() < 7 || RoomExit.Top == 0); Graph.BuildDistanceMap(Rooms, RoomExit); distance = Graph.BuildPath(Rooms, RoomEntrance, RoomExit).Count; } while (distance < 3); RoomEntrance.type = RoomType.ENTRANCE; RoomExit.type = RoomType.BOSS_EXIT; var path = Graph.BuildPath(Rooms, RoomEntrance, RoomExit); Graph.SetPrice(path, RoomEntrance.distance); Graph.BuildDistanceMap(Rooms, RoomExit); path = Graph.BuildPath(Rooms, RoomEntrance, RoomExit); _anteroom = path[path.Count - 2]; _anteroom.type = RoomType.STANDARD; var room = RoomEntrance; foreach (var next in path) { room.Connect(next); room = next; } foreach (var room1 in Rooms.Where(room1 => room1.type == RoomType.NULL && room1.Connected.Count > 0)) { room1.type = RoomType.PASSAGE; } Paint(); var r = RoomExit.Connected.Keys.ToArray()[0]; if (RoomExit.Connected[r].Y == RoomExit.Top) { return(false); } PaintWater(); PaintGrass(); PlaceTraps(); return(true); }
protected override bool Build() { InitRooms(); int distance; var retry = 0; var minDistance = (int)Math.Sqrt(Rooms.Count); do { var innerRetry = 0; do { if (innerRetry++ > 10) { return(false); } RoomEntrance = pdsharp.utils.Random.Element(Rooms); }while (RoomEntrance.Width() < 4 || RoomEntrance.Height() < 4); innerRetry = 0; do { if (innerRetry++ > 10) { return(false); } RoomExit = pdsharp.utils.Random.Element(Rooms); }while (RoomExit == RoomEntrance || RoomExit.Width() < 6 || RoomExit.Height() < 6 || RoomExit.Top == 0); Graph.BuildDistanceMap(Rooms, RoomExit); distance = Graph.BuildPath(Rooms, RoomEntrance, RoomExit).Count; if (retry++ > 10) { return(false); } }while (distance < minDistance); RoomEntrance.type = RoomType.ENTRANCE; RoomExit.type = RoomType.EXIT; Graph.BuildDistanceMap(Rooms, RoomExit); var path = Graph.BuildPath(Rooms, RoomEntrance, RoomExit); Graph.SetPrice(path, RoomEntrance.distance); Graph.BuildDistanceMap(Rooms, RoomExit); path = Graph.BuildPath(Rooms, RoomEntrance, RoomExit); var room = RoomEntrance; foreach (var next in path) { room.Connect(next); room = next; } Room roomShop = null; var shopSquare = 0; foreach (var r in Rooms) { if (r.type != RoomType.NULL || r.Connected.Count <= 0) { continue; } r.type = RoomType.PASSAGE; if (r.Square() <= shopSquare) { continue; } roomShop = r; shopSquare = r.Square(); } if (roomShop == null || shopSquare < 30) { return(false); } roomShop.type = Imp.Quest.IsCompleted ? RoomType.SHOP : RoomType.STANDARD; Paint(); PaintWater(); PaintGrass(); return(true); }