public void IsParentOf(PlannedSegment child)
 {
     if (Children == null)
     {
         Children = new List <PlannedSegment>();
     }
     Children.Add(child);
 }
Example #2
0
    public int PathWeight;                 //^ but in cells generated instead of number of segments


    public SegmentStump(PlannedSegment parent, SegmentCellOriented zeroposrot, int role, int pathdepth, int pathweight)
    {
        Parent     = parent;
        ZeroPosRot = zeroposrot;
        StumpRole  = role;
        PathDepth  = pathdepth;
        PathWeight = pathweight;
    }
 public void AddSegment(PlannedSegment seg)
 {
     AllSegments.Add(seg);
     if (seg.SegmentRole == DungeonSegmentRole.MainPath)
     {
         MainPath.Add(seg);
     }
     else
     {
         SideWays.Add(seg);
     }
     if (StartingSegment == null)
     {
         StartingSegment = seg;
     }
     DungeonWeight += seg.Scheme.Weight;
 }
Example #4
0
    public static List <SegmentStump> MakeStumpsForOpenings(PlannedSegment segment)
    {
        List <SegmentStump> result = new List <SegmentStump>();
        SegmentStump        stump;

        foreach (SegmentCellOriented opening in segment.Scheme.Openings[segment.ZeroPosRot.Facing])
        {
            stump = new SegmentStump(segment,
                                     new SegmentCellOriented(segment.ZeroPosRot.U + opening.U,
                                                             segment.ZeroPosRot.R + opening.R,
                                                             opening.Facing,
                                                             opening.Type,
                                                             segment.ZeroPosRot.Altitude + opening.Altitude),
                                     segment.SegmentRole,
                                     segment.PathDepth,
                                     segment.PathWeight);
            result.Add(stump);
        }
        return(result);
    }
    //private int SideBranchingEntropy = 0;   //influences chances of sideways branching; rises as branches fail to branch when they should (dungeon topology wont allow it)
    //WIP
    public override bool GeneratePlan(out DungeonPlan dungeonPlan)
    {
        dungeonPlan = new DungeonPlan();
        SegmentStump        MainPathStump;
        List <SegmentStump> SidewayStumps = new List <SegmentStump>();

        if (PlanningGrid == null)
        {
            PlanningGrid = new byte[Settings.PlanGridDimensions + 1, Settings.PlanGridDimensions + 1];
        }
        else
        {
            Array.Clear(PlanningGrid, 0, PlanningGrid.Length);
        }


        //ENTRANCE
        PlannedSegment EntrancePlan  = new PlannedSegment();
        SegmentStump   EntranceStump = new SegmentStump(null,
                                                        new SegmentCellOriented((int)(Settings.PlanGridDimensions * EntranceMargin.x),
                                                                                (int)(Settings.PlanGridDimensions * EntranceMargin.y),
                                                                                SegmentRotation.Up,
                                                                                DoorType.NonExistant, //no door into first segment
                                                                                0),                   //starting altitude is considered zero
                                                        DungeonSegmentRole.MainPath,                  //Entrance is a start of main path
                                                        0,                                            //dungeon starting segment has 0 depth and weight before it
                                                        0);
        ArchivedSegment schemeChoice = TryFindFittingSegment(SegmentCategory.Entrance, EntranceStump);

        if (schemeChoice == null)
        {
            Debug.Log("Could not plan entrance");
            return(false);
        }
        else
        {
            RegisterInGrid(schemeChoice, EntranceStump);
        }
        EntrancePlan.PlanFromScheme(schemeChoice, EntranceStump);
        dungeonPlan.AddSegment(EntrancePlan);
        List <SegmentStump> OpeningsStumps = SegmentStump.MakeStumpsForOpenings(EntrancePlan);

        ShuffleList <SegmentStump>(OpeningsStumps);

        MainPathStump           = OpeningsStumps[0]; //first one after shuffle is main, the rest are sideways
        MainPathStump.StumpRole = DungeonSegmentRole.MainPath;
        OpeningsStumps.RemoveAt(0);
        foreach (SegmentStump stump in OpeningsStumps)
        {
            stump.StumpRole  = DungeonSegmentRole.Sideway;
            stump.PathDepth  = 0;   //depth and weight are related to sideway now
            stump.PathWeight = 0;
            SidewayStumps.Add(stump);
        }


        //MAIN PATH
        PlannedSegment MainPathPlan;
        int            ChosenCategory;

        while ((ChosenCategory = ChooseCategoryForStump(MainPathStump)) != SegmentCategory.Exit)
        {
            MainPathPlan = new PlannedSegment();
            schemeChoice = TryFindFittingSegment(ChosenCategory, MainPathStump);
            if (schemeChoice == null)
            {
                //Debug.Log("Could not plan part of main path at Depth / Weight: " + MainPathStump.PathDepth + " / " + MainPathStump.PathWeight);
                return(false);
            }
            else
            {
                RegisterInGrid(schemeChoice, MainPathStump);
            }
            MainPathPlan.PlanFromScheme(schemeChoice, MainPathStump);
            dungeonPlan.AddSegment(MainPathPlan);
            OpeningsStumps = SegmentStump.MakeStumpsForOpenings(MainPathPlan);
            ShuffleList <SegmentStump>(OpeningsStumps);

            MainPathStump           = OpeningsStumps[0]; //first one after shuffle is main, the rest are sideways
            MainPathStump.StumpRole = DungeonSegmentRole.MainPath;
            OpeningsStumps.RemoveAt(0);
            foreach (SegmentStump stump in OpeningsStumps)
            {
                stump.StumpRole  = DungeonSegmentRole.Sideway;
                stump.PathDepth  = 0;
                stump.PathWeight = 0;
                SidewayStumps.Add(stump);
            }
        }


        //EXIT
        PlannedSegment MainPathExitPlan = new PlannedSegment();

        schemeChoice = TryFindFittingSegment(SegmentCategory.Exit, MainPathStump);
        if (schemeChoice == null)
        {
            //Debug.Log("Could not plan exit part of main path");
            return(false);
        }
        else
        {
            RegisterInGrid(schemeChoice, MainPathStump);
        }
        MainPathExitPlan.PlanFromScheme(schemeChoice, MainPathStump);
        dungeonPlan.AddSegment(MainPathExitPlan);


        //SIDEWAYS
        PlannedSegment SidewayPlan;

        while (SidewayStumps.Count != 0)
        {
            ChosenCategory = ChooseCategoryForStump(SidewayStumps[0]);
            SidewayPlan    = new PlannedSegment();
            schemeChoice   = TryFindFittingSegment(ChosenCategory, SidewayStumps[0]);
            if (schemeChoice == null)
            {
                //Debug.Log("Could not plan a sideway");
                return(false);
            }
            else
            {
                RegisterInGrid(schemeChoice, SidewayStumps[0]);
            }
            SidewayPlan.PlanFromScheme(schemeChoice, SidewayStumps[0]);
            dungeonPlan.AddSegment(SidewayPlan);

            OpeningsStumps = SegmentStump.MakeStumpsForOpenings(SidewayPlan); //if sideway continues - add its exit stumps to the end of SidewayStumps
            foreach (SegmentStump stump in OpeningsStumps)
            {
                stump.StumpRole = DungeonSegmentRole.Sideway;
                SidewayStumps.Add(stump);
            }
            SidewayStumps.RemoveAt(0); //stump is built upon and should be removed
        }

        return(true); //generated successfully
    }
 public void HasParent(PlannedSegment parent)
 {
     Parent = parent;
 }