/// <inheritdoc cref="IPipelineProcess{T}"/> public RoomData Translate(RoomData room) { var availableSections = RoomLayoutRepository.FilterForSizeAndType( room.Type, room.Width - 2, room.Height - 2 ) ?? new List <RoomLayoutData>(); var activeSections = new List <RoomsSection>(); var joinCount = R.RandomRange(1, MAX_JOIN_COUNT); PlaceDefaultValues(room, activeSections); // Joins sections if (availableSections.Count > 0) { for (var s = 0; s < joinCount; s++) { var currentLayout = availableSections[R.RandomRange(0, availableSections.Count)]; var currentTry = 0; do { var section = new RoomsSection { Height = currentLayout.Height, Width = currentLayout.Width, Left = R.RandomRange(1, room.Width - currentLayout.Width), Top = R.RandomRange(1, room.Width - currentLayout.Width), Layout = currentLayout }; if (!SectionCollides(section, activeSections)) { activeSections.Add(section); break; } currentTry++; } while (currentTry < TRY_FAIL_COUNT); } } // Places prefabs foreach (var section in activeSections) { foreach (var layoutItemInfo in section.Layout.RoomLayout) { var rx = layoutItemInfo.X + section.Left; var ry = layoutItemInfo.Y + section.Height; if (rx < 0 || ry < 0 || rx >= room.Width || ry >= room.Height) { continue; } room.Tiles[rx, ry].Child = layoutItemInfo.GerPrefab(); } } return(room); }
public bool CollidesWith(RoomsSection room) { if (Left > room.Right) { return(false); } if (Top > room.Bottom) { return(false); } if (Right < room.Left) { return(false); } if (Bottom < room.Top) { return(false); } return(true); }
/// <summary> /// Checks whether or not room section collides with other sections /// - Same logic as room collision <see cref="CreateRoomProcessor"/> /// </summary> /// <param name="section">Section to check</param> /// <param name="activeSections">Sections to check with</param> /// <returns>True - if section collides</returns> private static bool SectionCollides(RoomsSection section, IEnumerable <RoomsSection> activeSections) { return(activeSections.Any(section.CollidesWith)); }