public void GetAllRoomsAndCorridors() { Rooms.Clear(); Corridors.Clear(); ClearAllSpaces(TileMap, NumColumns, NumRows); DetermineSpaceTypes(); for (int column = 0; column < NumColumns; column++) { for (int row = 0; row < NumRows; row++) { Tile activeSpace = GetFloorSpace(column, row); if (activeSpace == null) { continue; } if (activeSpace.SpaceType == SpaceType.Room) { if (activeSpace.Parent == null) { Rooms.Add(CreateRoomFromSpace(activeSpace)); } } else if (activeSpace.SpaceType == SpaceType.Corridor) { if (activeSpace.Parent == null) { Corridors.Add(CreateCorridorFromSpace(activeSpace)); } } } } }
public async Task Genrate() { _startingpos = (StartingPosition)NumGen.Next(0, 5) /*StartingPosition.Center*/; LogToUiThread($"Starting position : {_startingpos}"); int roomcount = _dp.RoomNumber.Next(); LogToUiThread($"Generating {roomcount} rooms"); for (int i = 0; i < roomcount; i++) { bool isFirst = i == 0; Direction dir = Direction.North; if (isFirst) { dir = GetDirByStartupPos(); } else { dir = (Direction)NumGen.Next(0, 4); } var r = await GenerateRoom(dir, (Corridors.Count > 0)?Corridors[i - 1] : null, (isFirst)); Rooms.Add(r); //si dernière salle, pas couloir if (i < roomcount - 1) { var c = await GenerateCorridor(r); Corridors.Add(c); } } }
void GetTilesAndRoomsFromFlyweights() { foreach (Guid guid in flyweights.Keys) { JObject jObject = flyweights[guid] as JObject; JToken typeNameToken = jObject.GetValue("TypeName"); string typeName = typeNameToken.ToString(); switch (typeName) { case "MapCore.Tile": Tile tile = jObject.ToObject <Tile>(); Tiles.Add(tile); reconstitutedFlyweights[guid] = tile; break; case "MapCore.MapRegion": MapRegion mapRegion = jObject.ToObject <MapRegion>(); reconstitutedFlyweights[guid] = mapRegion; if (mapRegion.RegionType == RegionType.Room) { Rooms.Add(mapRegion); } else if (mapRegion.RegionType == RegionType.Corridor) { Corridors.Add(mapRegion); } break; } } }
/// <summary> /// Adds a Room to the Corridors list. /// </summary> /// <param name="room">Room to add.</param> /// <param name="fit">Indicates whether the new corridor should mutually fit to other Story features.</param> /// <param name="merge">Indicates whether the new corridor should merge with other corridors.</param> /// <returns> /// True if one or more rooms were added to the Story. /// </returns> public bool AddCorridor(Room room, bool fit = true, bool merge = true) { if (Perimeter == null || room.Perimeter == null || !Perimeter.Covers(perimeter)) { return(false); } var newRoom = new Room() { Color = room.Color, Elevation = Elevation, Height = room.Height, Name = room.Name, Perimeter = room.Perimeter }; var fitRooms = new List <Room> { newRoom }; if (fit) { var toRooms = new List <Room>(Exclusions); toRooms.AddRange(Services); fitRooms = FitRooms(fitRooms, toRooms, false); Rooms = FitRooms(Rooms, fitRooms); } if (fitRooms.Count == 0) { return(false); } Corridors.AddRange(fitRooms); var merged = Shaper.Merge(CorridorsAsPolygons); if (merge && merged.Count < Corridors.Count) { Corridors.Clear(); foreach (var corridor in merged) { Corridors.Add( new Room() { Color = room.Color, Elevation = Elevation, Height = room.Height, Name = room.Name, Perimeter = corridor }); } } return(true); }
public void AddCorridor(string firstName, string secondName) { var nodeFirst = FindNode(firstName); var nodeSecond = FindNode(secondName); if (nodeFirst == null || nodeSecond == null) { return; } nodeFirst.AddCorridor(nodeSecond); nodeSecond.AddCorridor(nodeFirst); Corridors.Add(new GraphCorridor(LastIdCorridor, nodeFirst, nodeSecond)); LastIdCorridor++; }
public void ConnectRooms() { var rooms = AllRooms; Corridors.Add(1, 2, rooms); Corridors.Add((1), (3), rooms); Corridors.Add((1), (4), rooms); Corridors.Add((2), (6), rooms); Corridors.Add((2), (999), rooms, 2, true); Corridors.Add((3), (7), rooms, 2); Corridors.Add((4), (8), rooms); Corridors.Add((4), (999), rooms, 2, true); Corridors.Add((5), (999), rooms, 2, true); Corridors.Add((5), (6), rooms); Corridors.Add((5), (10), rooms, 2); Corridors.Add((6), (7), rooms); Corridors.Add((6), (11), rooms); Corridors.Add((7), (8), rooms); Corridors.Add((8), (9), rooms); Corridors.Add((8), (11), rooms); Corridors.Add((9), (12), rooms, 2); Corridors.Add((9), (999), rooms, 1, true); Corridors.Add((10), (13), rooms, 2); Corridors.Add((11), (14), rooms); Corridors.Add((11), (15), rooms); Corridors.Add((12), (16), rooms, 2); ; Corridors.Add((13), (14), rooms); Corridors.Add((13), (19), rooms); ; Corridors.Add((14), (17), rooms); Corridors.Add((14), (999), rooms, 1, true); Corridors.Add((15), (18), rooms); Corridors.Add((15), (16), rooms); Corridors.Add((15), (999), rooms, 1, true); ; ; Corridors.Add((16), (21), rooms); Corridors.Add((17), (19), rooms); Corridors.Add((17), (20), rooms, 2); Corridors.Add((18), (20), rooms, 2); Corridors.Add((18), (21), rooms); ; Corridors.Add((19), (999), rooms, 2, true); Corridors.Add((21), (999), rooms, 2, true); }
/// <summary> /// Attempt to build a corridor at the end of a random corridor. /// </summary> /// <returns> /// True if a corridor was built. Otherwise, false. /// </returns> private bool BuildCorridorOnCorridorEnd() { for (int attempt = 0; attempt < MaximumAttempts; attempt++) { int directionAwayFromCorridor; Vector2 corridorEndpoint = GetEndOfCorridor(out directionAwayFromCorridor); Rect corridor = GetCorridor(corridorEndpoint, directionAwayFromCorridor); if (RectangleFits(corridor)) { Corridors.Add(corridor); BuildRectangle(corridor); return(true); } } return(false); }
/// <summary> /// Creates a rectangular corridor Room from a centerline axis, width, and height, at the Story elevation. /// Adds the new Room to the Corrdors list. /// Corridors conform to Service perimeters. /// Corridors change intersecting Room perimeters to conform to the corridor's perimeter. /// </summary> /// <param name="axis">Center Line of the corridor.</param> /// <param name="width">Width of the corridor.</param> /// <param name="height">Height of the corridor.</param> /// <param name="name">String identifier.</param> /// <param name="color">Rendering color of the Room as a Space.</param> /// <returns> /// None. /// </returns> public void AddCorridor(Line axis, double width = 2.0, double height = 3.0, string name = "", Color color = null) { var corridor = new Room() { Color = color, Elevation = Elevation, Height = height, Name = name }; corridor.MakePerimeter(axis, width); Corridors.Add(corridor); FitCorridorsToServices(); FitRoomsToCorridors(); }
/// <summary> /// Attempt to build a corridor on the side of a room. /// </summary> /// <returns> /// True if a corridor was built. Otherwise, false. /// </returns> private bool BuildCorridorOnRoomEdge() { for (int attempt = 0; attempt < MaximumAttempts; attempt++) { int direction; Vector2 door = GetRoomEdge(out direction); Rect corridor = GetCorridor(door, direction); if (RectangleFits(corridor)) { Corridors.Add(corridor); BuildRectangle(corridor); Map[(int)door.x, (int)door.y] = (int)MapElements.Door; Doors.Add(door); return(true); } } return(false); }
/// <summary> /// Adds a Room to the Corridors list. /// </summary> /// <param name="room">Room to add.</param> /// <returns> /// True if one or more Rooms were added. /// </returns> public bool AddCorridor(Room room, bool merge = true, double tolerance = 0.0, double minLength = 0.0) { var perimeters = Shaper.FitWithin(room.Perimeter, Perimeter); if (perimeters.Count == 0) { return(false); } var fitAmong = new List <Polygon>(OpeningsAsPolygons); fitAmong.AddRange(ExclusionsAsPolygons); fitAmong.AddRange(ServicesAsPolygons); var corridors = Shaper.Differences(perimeters, fitAmong).ToList(); if (corridors.Count() == 0) { return(false); } corridors.AddRange(CorridorsAsPolygons); if (merge) { corridors = Shaper.Merge(corridors); } Corridors.Clear(); foreach (var corridor in corridors) { Corridors.Add( new Room(room) { Elevation = Elevation, Height = room.Height, Perimeter = corridor }); } FitRooms(); return(true); }
/// <summary> /// Creates a corridor Room from a perimeter and height, at the Story elevation. /// Adds the new Room to the Corrdors list. /// Corridors conform to Service perimeters. /// Corridors change intersecting Room perimeters to conform to the corridor's perimeter. /// </summary> /// <param name="perimeter">Polygon perimeter of the corridor.</param> /// <param name="height">Height of the corridor.</param> /// <param name="name">String identifier.</param> /// <param name="color">Rendering color of the Room as a Space.</param> /// <returns> /// None. /// </returns> public void AddCorridor(Polygon perimeter, double height = 3.0, string name = "", Color color = null) { if (Perimeter == null) { throw new ArgumentNullException(Messages.PERIMETER_NULL_EXCEPTION); } var corridor = new Room() { Color = color, Elevation = elevation, Height = height, Name = name, Perimeter = perimeter }; Corridors.Add(corridor); FitCorridorsToServices(); FitRoomsToCorridors(); }
public void AddCorridors() { VectQuater aux; bool canCreate; int cardinal; foreach (Room room in rooms) { //Main Corridor cardinal = 0; canCreate = true; if (room is Triangle) { while (!room.PrevRoom[cardinal]) { cardinal++; } aux = room.CorridorCreator(cardinal); for (int j = 0; j < nCInitialized; j++) { if (aux.vector3 == posNoCorr[j]) { continue; } } posCorr[cInitialized] = aux.vector3; posNoCorr[nCInitialized] = aux.vector3; cInitialized++; nCInitialized++; if (aux.quaternion.eulerAngles.y == 90 || aux.quaternion.eulerAngles.y == 270) { Corridors.Add(new CorrH(aux.vector3, aux.quaternion, cInitialized)); } else { Corridors.Add(new CorrV(aux.vector3, aux.quaternion, cInitialized)); } continue; } if (!(room is Octagon)) { room.ActualizeCanCreate(ref posRooms, rInitialized); } while (!room.PrevRoom[cardinal]) { cardinal++; } aux = room.CorridorCreator(cardinal); for (int j = 0; j < nCInitialized; j++) { if (canCreate && aux.vector3 == posNoCorr[j]) { canCreate = false; } } if (canCreate) { room.Corridors[cardinal] = true; posCorr[cInitialized] = aux.vector3; posNoCorr[nCInitialized] = aux.vector3; cInitialized++; nCInitialized++; if (aux.quaternion.eulerAngles.y == 90 || aux.quaternion.eulerAngles.y == 270) { Corridors.Add(new CorrH(aux.vector3, aux.quaternion, cInitialized)); } else { Corridors.Add(new CorrV(aux.vector3, aux.quaternion, cInitialized)); } } if (room is Octagon) { continue; } //Other Corridors for (int i = 0; i < room.CanCreateSq.Length; i++) { if (!room.CanCreateSq[i] && i != cardinal && Random.Range(0, 10) < properties.ProbCorrid) { aux = room.CorridorCreator(i); for (int j = 0; j < nCInitialized; j++) { if (canCreate && aux.vector3 == posNoCorr[j]) { canCreate = false; } } if (canCreate) { room.Corridors[i] = true; posCorr[cInitialized] = aux.vector3; posNoCorr[nCInitialized] = aux.vector3; cInitialized++; nCInitialized++; if (aux.quaternion.eulerAngles.y == 90 || aux.quaternion.eulerAngles.y == 270) { Corridors.Add(new CorrH(aux.vector3, aux.quaternion, cInitialized)); } else { Corridors.Add(new CorrV(aux.vector3, aux.quaternion, cInitialized)); } } } } } //foreach ends }