コード例 #1
0
    protected CandidatesConnection CreateCandidatesConnection(ConnPointCandidate lastConnPointCandidate, ConnPointCandidate newConnPointCandidate)
    {
        CandidatesConnection candidatesConnection = new CandidatesConnection
        {
            LastConnPointCandidate = lastConnPointCandidate,
            NewConnPointCandidate  = newConnPointCandidate
        };

        return(candidatesConnection);
    }
コード例 #2
0
    protected Candidate CreateNewCandidate(ConnPointCandidate lastConnPointCandidate, DungeonSet candidatesSet)
    {
        VoxelStep newCandidateStepVoxel = new VoxelStep();

        // GENERATE ROOM WITH ONE CONNECTION POINT (only after all target rooms have been exhausted)
        if (acceptedCandidates.Count >= factoryOwner.TargetElementsCount)
        {
            potentialCandidates = lastConnPointCandidate.OwnerSet.GetAllClosingElementsShuffled(random);
        }

        // GET RANDOM NEW CANDIDATE
        Candidate newCandidate = GetNewCandidate(potentialCandidates, candidatesSet);

        potentialCandidates = potentialCandidates.RemoveFromArray(newCandidate.Element);

        // CHECK IF NEW ELEMENT ALLOWED NEIGHBOUR TO LAST ELEMENT
        bool notAllowedNeighbours = CheckIfCandidatesCanBeNeighbours(GetFirstOpenCandidate(), newCandidate);

        if (notAllowedNeighbours)
        {
            potentialCandidates = candidatesSet.GetAllHallwayElementsShuffled(random);
            return(null);
        }

        // COONECT THE CANDIDATES
        ConnPointCandidate newConnPointCandidate = AlignNewCandidateWithConnPoint(lastConnPointCandidate, newCandidate);

        CandidatesConnection candidatesConnection = CreateCandidatesConnection(lastConnPointCandidate, newConnPointCandidate);

        candidatesConnection.LastCandidateWorldPos = GetFirstOpenCandidate().WorldPos;

        newCandidate.CandidatesConnection = candidatesConnection;

        //STEP VOXELS
        newCandidateStepVoxel.oldStepVoxelsPos = GetOldStepVoxels(lastConnPointCandidate);
        newCandidateStepVoxel.newStepVoxelsPos = GetNewStepVoxels(newCandidate);
        //

        //candidatesConnection.NewCandidateStepVoxel = newCandidateStepVoxel;

        //CHECK OVERLAP
        bool overlap = CheckIfNewElementOverlaps(newCandidateStepVoxel, newCandidate);

        if (overlap)
        {
            if (potentialCandidates.Length == 0)
            {
                potentialCandidates = candidatesSet.GetAllClosingElementsShuffled(random);
            }

            return(null);
        }

        return(newCandidate);
    }
コード例 #3
0
    /// <summary>
    /// Creates a dungeon room <b>GameObject</b> from a accepted <b>Candidate</b> object.
    /// If it is possible the object will be pooled, else it is fully initialized.
    /// </summary>
    /// <param name="acceptedCandidate">Object that defines the new element. Objects are usually provided by <b>Elements Factory</b>.</param>
    protected void BuildElement(Candidate acceptedCandidate)
    {
        ConnPoint newConnPoint = elementsFactory.GetNewElement(acceptedCandidate, this.transform);

        CandidatesConnection candidatesConnection = acceptedCandidate.CandidatesConnection;
        Element previousElement = elementsFactory.initilizedElements[candidatesConnection.LastCandidateWorldPos];

        ConnPoint lastConnPoint = GetConnPointAtPosition(previousElement.connPoints, acceptedCandidate.LastConnPointCandidate.LocalPosition);

        newConnPoint.sharedConnPoint = lastConnPoint ?? throw new System.Exception("DungeonGenerator:: No PREVIOUS ELEMENT connection point found.");

        lastConnPoint.sharedConnPoint = newConnPoint;
    }