public bool IsRoomInDirectionFree(Position pos, int direction) { var dirPos = pos.GetBiasedPosition(direction); if ((0 <= dirPos.X) && (dirPos.X < Width) && (0 <= dirPos.Y) && (dirPos.Y < Height)) { return(!Rooms[dirPos.X][dirPos.Y].Occupied); } return(false); }
private bool SetTraits(Position pos, int direction, int doorType) { var biased_pos = pos.GetBiasedPosition(direction); if ((biased_pos.X >= 0) && (biased_pos.Y >= 0)) { if ((biased_pos.X < this.Width) && (biased_pos.Y < this.Height)) { if (!this.MazeGenerator.IsFree(biased_pos)) { return(false); } this.MazeGenerator.MarkReservedPosition(biased_pos); } } var room = this.GetRoom(pos); if (room.IsLinked(direction)) { throw new Exception("Room in direction isn't linked"); } if (room.GetDoorType(direction) != 0) { throw new Exception(); } LinkType linkType; if (doorType == (int)DungeonBlockType.StairsDown) { linkType = LinkType.To; } else if (doorType == (int)DungeonBlockType.StairsUp) { linkType = LinkType.From; } else { throw new Exception("Invalid door_type"); } room.Link(direction, linkType); room.SetDoorType(direction, doorType); return(true); }
private int Sub(Position pos) { if (this.GetRoom(pos) != null) { var count = 1; for (int iDir = 0; iDir < 4; iDir++) { var room = this.GetRoom(pos.GetBiasedPosition(iDir)); if (room != null && !room.Occupied) { count += 1; } } return(count); } return(0); }
private bool CreateSubPathRecursive(Position pos) { var room = GetRoom(pos); var maze_room = this.MazeGenerator.GetRoom(pos); for (int direction = 0; direction < 4; direction++) { if (maze_room.GetPassageType(direction) == 2) { var biased_pos = pos.GetBiasedPosition(direction); if (room != null) { room.Link(direction, LinkType.To); } this.CreateSubPathRecursive(biased_pos); } } return(true); }
private bool GenerateCriticalPathRecursive(int critPathPos, int critPathMin, int critPathMax, int direction, MTRandom rnd) { var directions = new int[4]; _critPathMaxResult += 1; if (_critPathMaxResult <= 10 * critPathMax) { if (critPathMin <= critPathPos && critPathPos <= critPathMax && this.IsRoomInDirectionFree(_currentPos, StartDirection)) { this.StartPos = _currentPos; foreach (var move in this.CriticalPath) { int temp = move.PosFrom.X; move.PosFrom.X = move.PosTo.X; move.PosTo.X = temp; temp = move.PosFrom.Y; move.PosFrom.Y = move.PosTo.Y; move.PosTo.Y = temp; move.Direction = Direction.GetOppositeDirection(move.Direction); } this.CriticalPath.Reverse(); return(true); } else { critPathPos += 1; var count = 0; if (critPathPos <= critPathMax) { if (direction != -1) { direction = Direction.GetOppositeDirection(direction); } for (int i = 0; i < 4; i++) { if (i == direction) { directions[i] = 0; } else { var next_pos = _currentPos.GetBiasedPosition(i); directions[i] = Sub(next_pos); count += directions[i]; } } while (count > 0) { var rndNum = rnd.GetUInt32() % count + 1; int cnt2 = 0; var iDir = 0; while (iDir < 4) { cnt2 += directions[iDir]; if (cnt2 >= rndNum) { break; } iDir++; } count -= directions[iDir]; directions[iDir] = 0; if (this.MakeMove(iDir)) { if (this.GenerateCriticalPathRecursive(critPathPos, critPathMin, critPathMax, iDir, rnd)) { return(true); } this.UndoMove(); } } } } } return(false); }
private bool CreateSubPathRecursive(Position pos) { var room = GetRoom(pos); var maze_room = this.MazeGenerator.GetRoom(pos); for (int direction = 0; direction < 4; direction++) { if (maze_room.GetPassageType(direction) == 2) { var biased_pos = pos.GetBiasedPosition(direction); if (room != null) room.Link(direction, LinkType.To); this.CreateSubPathRecursive(biased_pos); } } return true; }
private bool SetTraits(Position pos, int direction, int doorType) { var biased_pos = pos.GetBiasedPosition(direction); if ((biased_pos.X >= 0) && (biased_pos.Y >= 0)) { if ((biased_pos.X < this.Width) && (biased_pos.Y < this.Height)) { if (!this.MazeGenerator.IsFree(biased_pos)) return false; this.MazeGenerator.MarkReservedPosition(biased_pos); } } var room = this.GetRoom(pos); if (room.IsLinked(direction)) throw new Exception("Room in direction isn't linked"); if (room.GetDoorType(direction) != 0) throw new Exception(); LinkType linkType; if (doorType == (int)DungeonBlockType.StairsDown) linkType = LinkType.To; else if (doorType == (int)DungeonBlockType.StairsUp) linkType = LinkType.From; else throw new Exception("Invalid door_type"); room.Link(direction, linkType); room.SetDoorType(direction, doorType); return true; }
public bool IsRoomInDirectionFree(Position pos, int direction) { var dirPos = pos.GetBiasedPosition(direction); if ((0 <= dirPos.X) && (dirPos.X < Width) && (0 <= dirPos.Y) && (dirPos.Y < Height)) return !Rooms[dirPos.X][dirPos.Y].Occupied; return false; }
private int Sub(Position pos) { if (this.GetRoom(pos) != null) { var count = 1; for (int iDir = 0; iDir < 4; iDir++) { var room = this.GetRoom(pos.GetBiasedPosition(iDir)); if (room != null && !room.Occupied) count += 1; } return count; } return 0; }