/// <summary> /// Creates Places list, walking critical path and adding subpaths recursively. /// Creates _lockedDoorCandidates list, places on the way to end room and to chest places. /// </summary> /// <param name="startRoom"></param> /// <param name="path"></param> private void InitLists(RoomTrait startRoom, List <MazeMove> path) { var room = startRoom; var depth = 0; foreach (var move in path) { this.Places.Add(new PlaceNode(room, depth, false)); room.RoomIndex = this.Places.Count - 1; room.isOnPath = true; var lockedDoorCandidate = new LockedDoorCandidateNode(room, move.Direction, this.Places.Count - 1); _lockedDoorCandidates.AddLast(lockedDoorCandidate); for (var direction = 0; direction < 4; direction++) { if (move.Direction != direction && room.Links[direction] == LinkType.To) { var nextRoom = room.Neighbor[direction]; if (nextRoom != null) { CreateEmptyPlacesRecursive(nextRoom, depth + 1); } } } room = room.Neighbor[move.Direction]; depth++; } }
/// <summary> /// Section of teh floor, contain Puzzles. /// </summary> /// <param name="startRoom">Start room of this section.</param> /// <param name="path">Critical path for this section.</param> /// <param name="haveBossRoom">Should we place a boss door in this section.</param> /// <param name="rng">Randrom generator for this dungeon.</param> public DungeonFloorSection(RoomTrait startRoom, List <MazeMove> path, bool haveBossRoom, MTRandom rng) { _lockColorProvider = new LockColorProvider(); _lockedDoorCandidates = new LinkedList <LockedDoorCandidateNode>(); this.Places = new List <PlaceNode>(); this.Puzzles = new List <Puzzle>(); _placeBossDoor = haveBossRoom; _rng = rng; this.InitLists(startRoom, path); }
/// <summary> /// CalculateWeights helper method. /// </summary> /// <param name="room"></param> /// <param name="count"></param> /// <returns></returns> private int CalculateSubPathWeightRecursive(RoomTrait room, int count) { for (var direction = 0; direction < 4; direction++) { if (room.Links[direction] != LinkType.To) { continue; } var nextRoom = room.Neighbor[direction]; if (nextRoom != null) { count = CalculateSubPathWeightRecursive(nextRoom, count + 1); } } return(count); }
/// <summary> /// Recursively add subpath rooms to Places list. /// </summary> /// <param name="room"></param> /// <param name="depth"></param> private void CreateEmptyPlacesRecursive(RoomTrait room, int depth) { this.Places.Add(new PlaceNode(room, depth, false)); room.RoomIndex = this.Places.Count - 1; for (var direction = 0; direction < 4; direction++) { if (room.Links[direction] != LinkType.To) { continue; } var nextRoom = room.Neighbor[direction]; if (nextRoom != null) { CreateEmptyPlacesRecursive(nextRoom, depth + 1); } } }
/// <summary> /// Makes it a locked place with a locked door. /// </summary> public void DeclareLock(bool lockSelf = false) { var doorElement = _section.GetLock(lockSelf); if (doorElement == null) return; this.PlaceIndex = doorElement.PlaceIndex; _room = doorElement.Room; this.UpdatePosition(); this.IsLock = true; this.LockColor = _section.GetLockColor(); this.DoorDirection = doorElement.Direction; _room.ReserveDoor(this.DoorDirection); _room.isLocked = true; if (_room.RoomType != RoomType.End || _room.RoomType != RoomType.Start) _room.RoomType = RoomType.Room; // Boss door - special case if ((DungeonBlockType)_room.DoorType[this.DoorDirection] == DungeonBlockType.BossDoor) { this.IsBossLock = true; this.AddDoor(this.DoorDirection, DungeonBlockType.BossDoor); } else this.AddDoor(this.DoorDirection, DungeonBlockType.DoorWithLock); if (lockSelf) this.GetLockDoor().IsLocked = true; }
public void SetNeighbor(int direction, RoomTrait room) { this.Neighbor[direction] = room; }
public PlaceNode(RoomTrait room, int depth, bool isUsed) { this.Room = room; this.Depth = depth; this.IsUsed = isUsed; }
public LockedDoorCandidateNode(RoomTrait room, int direction, int placeIndex) { this.Room = room; this.Direction = direction; this.PlaceIndex = placeIndex; }
/// <summary> /// Recursively add subpath rooms to Places list. /// </summary> /// <param name="room"></param> /// <param name="depth"></param> private void CreateEmptyPlacesRecursive(RoomTrait room, int depth) { this.Places.Add(new PlaceNode(room, depth, false)); room.RoomIndex = this.Places.Count - 1; for (var direction = 0; direction < 4; direction++) { if (room.Links[direction] != LinkType.To) continue; var nextRoom = room.Neighbor[direction]; if (nextRoom != null) CreateEmptyPlacesRecursive(nextRoom, depth + 1); } }
/// <summary> /// Creates Places list, walking critical path and adding subpaths recursively. /// Creates _lockedDoorCandidates list, places on the way to end room and to chest places. /// </summary> /// <param name="startRoom"></param> /// <param name="path"></param> private void InitLists(RoomTrait startRoom, List<MazeMove> path) { var room = startRoom; var depth = 0; foreach (var move in path) { this.Places.Add(new PlaceNode(room, depth, false)); room.RoomIndex = this.Places.Count - 1; room.isOnPath = true; var lockedDoorCandidate = new LockedDoorCandidateNode(room, move.Direction, this.Places.Count - 1); _lockedDoorCandidates.AddLast(lockedDoorCandidate); for (var direction = 0; direction < 4; direction++) { if (move.Direction != direction && room.Links[direction] == LinkType.To) { var nextRoom = room.Neighbor[direction]; if (nextRoom != null) CreateEmptyPlacesRecursive(nextRoom, depth + 1); } } room = room.Neighbor[move.Direction]; depth++; } }
/// <summary> /// CalculateWeights helper method. /// </summary> /// <param name="room"></param> /// <param name="count"></param> /// <returns></returns> private int CalculateSubPathWeightRecursive(RoomTrait room, int count) { for (var direction = 0; direction < 4; direction++) { if (room.Links[direction] != LinkType.To) continue; var nextRoom = room.Neighbor[direction]; if (nextRoom != null) count = CalculateSubPathWeightRecursive(nextRoom, count + 1); } return count; }
/// <summary> /// This place will precede locked place and contain some means to unlock it. /// </summary> /// <param name="lockPlace"></param> public void DeclareUnlock(PuzzlePlace lockPlace) { var place = lockPlace as PuzzlePlace; if (place == null || place.PlaceIndex == -1) throw new PuzzleException("We can't declare unlock"); this.PlaceIndex = _section.GetUnlock(place); _room = _section.Places[PlaceIndex].Room; this.IsUnlock = true; this.UpdatePosition(); }
/// <summary> /// Declares that this place is not to be used by any other puzzles. /// If we didn't declare this place to be something, reserve random place. /// </summary> public void ReservePlace() { if (this.IsUnlock || this.IsLock || this.IsBossLock) _section.ReservePlace(PlaceIndex); else { PlaceIndex = _section.ReservePlace(); _room = _section.Places[PlaceIndex].Room; this.UpdatePosition(); } }
/// <summary> /// Section of teh floor, contain Puzzles. /// </summary> /// <param name="startRoom">Start room of this section.</param> /// <param name="path">Critical path for this section.</param> /// <param name="haveBossRoom">Should we place a boss door in this section.</param> /// <param name="rng">Randrom generator for this dungeon.</param> public DungeonFloorSection(RoomTrait startRoom, List<MazeMove> path, bool haveBossRoom, MTRandom rng) { _lockColorProvider = new LockColorProvider(); _lockedDoorCandidates = new LinkedList<LockedDoorCandidateNode>(); this.Places = new List<PlaceNode>(); this.Puzzles = new List<Puzzle>(); _placeBossDoor = haveBossRoom; _rng = rng; this.InitLists(startRoom, path); }