Пример #1
0
    private Region CreateRegionAtRandomConnection(Wall w, bool createCorridor, PremadeRegion regionLayout = null)
    {
        CustomRegion         customRegion;
        List <VariantRegion> possibleRegionLayouts;
        List <BoundsInt>     possibleConnections = new List <BoundsInt>(w.possibleConnections);

        if (regionLayout == null)
        {
            if (createCorridor)
            {
                customRegion = corridorLayouts;
            }
            else
            {
                customRegion = roomLayouts;
            }
            //Debug.Log("Create Region At Random Connection - " + "useSeperateVerticalRegions: " + customRegion.useSeperateVerticalRegions + " | Wall is Vertical: " + w.isVertical);
            if (customRegion.useSeperateVerticalRegions && !w.isVertical)
            {
                possibleRegionLayouts = customRegion.verticalRegionVariations;
            }
            else
            {
                possibleRegionLayouts = customRegion.regionVariations;
            }
        }
        else
        {
            //Debug.Log("Creating a premade region.");
            customRegion = new CustomRegion();

            VariantRegion vr;
            if (regionLayout.GetType() == typeof(VariantRegion))
            {
                vr = (VariantRegion)regionLayout;
            }
            else
            {
                vr = new VariantRegion(regionLayout);
            }
            possibleRegionLayouts = new List <VariantRegion>()
            {
                vr
            };
            customRegion.regionVariations = possibleRegionLayouts;
            customRegion.type             = regionLayout.type;
        }
        while (possibleConnections.Count > 0)
        {
            // Get and remove a connection from the list
            BoundsInt con = possibleConnections[Random.Range(0, possibleConnections.Count)];
            possibleConnections.Remove(con);

            List <VariantRegion> regionLayouts = new List <VariantRegion>(possibleRegionLayouts);

            while (regionLayouts.Count > 0)
            {
                // Get and remove a layout from the list to avoid duplicate checking
                VariantRegion layout = regionLayouts[Random.Range(0, regionLayouts.Count)];
                regionLayouts.Remove(layout);

                // Test layout connections against possbile connections
                RegionConnections vrcs = layout.connections.Find(x => x.direction == Region.GetOppositeDirection(w.dir));
                if (vrcs == null)
                {
                    continue;
                }

                List <BoundsInt> variantConnections = new List <BoundsInt>(vrcs.boundsList);
                while (variantConnections.Count > 0)
                {
                    // Get and remove a connection from the list
                    BoundsInt varcon = variantConnections[Random.Range(0, variantConnections.Count)];
                    variantConnections.Remove(varcon);

                    Vector3Int alignmentOffset = AlignConnections(con, varcon, w.dir);

                    Vector3Int size     = new Vector3Int(layout.innerRegionWidth, layout.innerRegionLength, 1);
                    Vector3Int position = Vector3Int.RoundToInt(alignmentOffset - new Vector3(size.x / 2f, size.y / 2f));

                    testBounds = Region.GetOuterBounds(position, size);


                    bool isOverlapping = false;
                    for (int i = 0; i < regions.Count; i++)
                    {
                        if (Region.BoundsOverlap(regions[i].outerBounds, testBounds, 1))
                        {
                            isOverlapping = true;
                            break;
                        }
                    }

                    // Place region
                    if (!isOverlapping)
                    {
                        Region newRegion = new Region(layout, position);

                        if (newRegion.type == RegionType.None)
                        {
                            newRegion.type = customRegion.type;
                        }

                        if (newRegion.floorTiles == null)
                        {
                            newRegion.floorTiles = customRegion.tilesets[Random.Range(0, customRegion.tilesets.Count)];
                        }
                        return(newRegion);
                    }
                }
            }
        }

        // No new Region could be created
        return(null);
    }
Пример #2
0
    private BoundsInt GetRandomConnection(VariantRegion varRegion, Direction dir)
    {
        RegionConnections conns = varRegion.connections.Find(x => x.direction == dir);

        return(GetRandomConnection(conns.boundsList));
    }
Пример #3
0
 public Region(VariantRegion variantRegion, Vector3Int position)
     : this((PremadeRegion)variantRegion, position)
 {
     this.variableFurnitures = new List <VariableRegionFurnitures>(variantRegion.variableFurnitures);
 }