Beispiel #1
0
 public bool ConnectedTo(IEnumerable <LayoutObject> roomsToConnect, out LayoutObject failObj)
 {
     #region DEBUG
     if (BigBoss.Debug.logging(Logs.LevelGen) && BigBoss.Debug.Flag(DebugManager.DebugFlag.FineSteps))
     {
         BigBoss.Debug.printHeader(Logs.LevelGen, "Connected To");
     }
     #endregion
     failObj = null;
     var connected = ConnectedToAll();
     foreach (var obj in roomsToConnect)
     {
         if (!connected.Contains(obj))
         {
             failObj = obj;
             break;
         }
     }
     #region DEBUG
     if (BigBoss.Debug.logging(Logs.LevelGen) && BigBoss.Debug.Flag(DebugManager.DebugFlag.FineSteps))
     {
         BigBoss.Debug.printFooter(Logs.LevelGen, "Connected To");
     }
     #endregion
     return(failObj == null);
 }
Beispiel #2
0
 private void ConfirmEdges()
 {
     #region DEBUG
     if (BigBoss.Debug.logging(Logs.LevelGen))
     {
         BigBoss.Debug.printHeader(Logs.LevelGen, "Confirm Edges");
         Container.ToLog(Logs.LevelGen, "Pre Confirm Edges");
     }
     #endregion
     LayoutObject edgeObject = new LayoutObject("Edges");
     var          grids      = Container.GetGrid();
     grids.DrawAll(Draw.Not(Draw.IsType <GenSpace>(GridType.NULL).Or(Draw.IsType <GenSpace>(GridType.Wall))).IfThen((arr, x, y) =>
     {
         grids.DrawAround(x, y, true, Draw.IsType <GenSpace>(GridType.NULL).IfThen(Draw.SetTo(edgeObject.Grids, GridType.Wall, Theme)));
         return(true);
     }));
     Container.Objects.Add(edgeObject);
     #region DEBUG
     if (BigBoss.Debug.logging(Logs.LevelGen))
     {
         edgeObject.ToLog(Logs.LevelGen, "Edge Object");
         Container.ToLog(Logs.LevelGen, "Post Confirm Edges");
         BigBoss.Debug.printFooter(Logs.LevelGen, "Confirm Edges");
     }
     #endregion
 }
Beispiel #3
0
 protected void GenerateRoomShells()
 {
     #region DEBUG
     if (BigBoss.Debug.logging(Logs.LevelGen))
     {
         BigBoss.Debug.printHeader(Logs.LevelGen, "Generate Rooms");
     }
     #endregion
     List <ILayoutObject> rooms = new List <ILayoutObject>();
     int numRooms = Rand.Next(minRooms, maxRooms);
     #region DEBUG
     if (BigBoss.Debug.logging(Logs.LevelGen))
     {
         BigBoss.Debug.w(Logs.LevelGen, "Generating " + numRooms + " rooms.");
     }
     #endregion
     for (int i = 1; i <= numRooms; i++)
     {
         LayoutObject room = new LayoutObject("Room");
         rooms.Add(room);
         Layout.Rooms.Add(room);
     }
     #region DEBUG
     if (BigBoss.Debug.logging(Logs.LevelGen))
     {
         BigBoss.Debug.printFooter(Logs.LevelGen, "Generate Rooms");
     }
     #endregion
     Objects = rooms;
 }
Beispiel #4
0
 public RoomSpec(LayoutObject room, int depth, Theme theme, System.Random random)
 {
     Room          = room;
     Depth         = depth;
     Theme         = theme;
     Random        = random;
     RoomModifiers = theme.GetRoomMods();
 }
Beispiel #5
0
    public bool GetPathTo(LayoutObject target, out List <LayoutObject> list)
    {
        var visited = new HashSet <LayoutObject> {
            this
        };

        return(GetPathToRecursive(this, target, visited, out list));
    }
Beispiel #6
0
    public LayoutObject Bake(Theme theme)
    {
        LayoutObject obj = new LayoutObject("Path");

        foreach (var v in PathPrint(List.Cast <Point>()))
        {
            obj.SetTo(v, v.val, theme);
        }
        return(obj);
    }
Beispiel #7
0
 protected void ConstructBFS(LayoutObject obj,
                             out Queue <Value2D <GenSpace> > queue,
                             out Container2D <bool> visited)
 {
     visited = new MultiMap <bool>();
     queue   = new Queue <Value2D <GenSpace> >();
     obj.GetConnectedGrid().DrawPerimeter(Draw.Not(Draw.IsType <GenSpace>(GridType.NULL)), new StrokedAction <GenSpace>()
     {
         UnitAction   = Draw.SetTo <GenSpace, bool>(visited, true),
         StrokeAction = Draw.AddTo(queue).And(Draw.SetTo <GenSpace, bool>(visited, true))
     }, false);
 }
Beispiel #8
0
 public void Connect(LayoutObject obj)
 {
     if (obj != null)
     {
         if (BigBoss.Debug.logging(Logs.LevelGen))
         {
             BigBoss.Debug.w(Logs.LevelGen, "Connecting " + ToString() + " to " + obj.ToString());
         }
         _connectedTo.Add(obj);
         obj._connectedTo.Add(this);
     }
 }
        public PageTemplate(Document document, String key, String width, String height, String colorType,
                            String bleeding, String layoutTop, string layoutLeft, string layoutWidth, string layoutHeight)
            : base(document, key, width, height, colorType, bleeding)
        {
            LayoutObject layout = new LayoutObject();

            layout.Width   = new Unit(layoutWidth);
            layout.Height  = new Unit(layoutHeight);
            layout.Top     = Height - new Unit(layoutTop);
            layout.Left    = new Unit(layoutLeft);
            _staticContent = new Content(this);

            SetLayout(layout);
        }
Beispiel #10
0
 // Use this for initialization
 void Start()
 {
     System.Random rand = new System.Random();
     for (int i = 0; i < 100; i++)
     {
         try
         {
             LayoutObject obj   = new LayoutObject("Room Test " + i);
             RoomSpec     spec  = new RoomSpec(obj, 1, null, rand);
             TRoomMod     troom = new TRoomMod();
             troom.Modify(spec);
             spec.Grids.ToLog(Logs.LevelGenMain, "Test TRoom " + i);
         }
         catch (Exception ex)
         {
             BigBoss.Debug.w(Logs.LevelGenMain, "Exception " + ex);
         }
     }
 }
Beispiel #11
0
    protected bool FindNextPathPoints(Container2D <GenSpace> map,
                                      Container2D <GenSpace> runningConnected,
                                      out LayoutObject hit,
                                      DrawAction <GenSpace> pass,
                                      Queue <Value2D <GenSpace> > curQueue,
                                      Container2D <bool> curVisited,
                                      out Value2D <GenSpace> startPoint,
                                      out Value2D <GenSpace> endPoint)
    {
        if (!map.DrawBreadthFirstSearch(
                curQueue, curVisited, false,
                Draw.IsType <GenSpace>(GridType.NULL),
                pass,
                out endPoint))
        {
            hit        = null;
            startPoint = null;
            return(false);
        }
        if (!Container.GetObjAt(endPoint, out hit))
        {
            startPoint = null;
            return(false);
        }
        Container2D <bool>          hitVisited;
        Queue <Value2D <GenSpace> > hitQueue;

        ConstructBFS(hit, out hitQueue, out hitVisited);
        curQueue.Enqueue(hitQueue);
        curVisited.PutAll(hitVisited);
        return(map.DrawBreadthFirstSearch(
                   hitQueue, hitVisited, false,
                   Draw.IsType <GenSpace>(GridType.NULL),
                   pass.And(Draw.ContainedIn(runningConnected)),
                   out startPoint));
    }
Beispiel #12
0
 bool GetPathToRecursive(LayoutObject cur, LayoutObject target, HashSet <LayoutObject> visited, out List <LayoutObject> list)
 {
     list = new List <LayoutObject>();
     if (_connectedTo.Contains(target))
     {
         list.Add(target);
         return(true);
     }
     // Recursively search
     foreach (var connected in _connectedTo)
     {
         if (!visited.Contains(connected))
         {
             List <LayoutObject> targetPath;
             visited.Add(connected);
             if (GetPathToRecursive(connected, target, visited, out targetPath))
             {
                 list.AddRange(targetPath);
                 return(true);
             }
         }
     }
     return(false);
 }
Beispiel #13
0
 public abstract bool Place(Container2D <GenSpace> grid, LayoutObject obj, Theme theme, System.Random rand, out Boxing placed);
Beispiel #14
0
    protected void ConfirmConnection()
    {
        #region DEBUG
        if (BigBoss.Debug.logging(Logs.LevelGen))
        {
            BigBoss.Debug.printHeader(Logs.LevelGen, "Confirm Connections");
        }
        #endregion
        DrawAction <GenSpace> passTest = Draw.ContainedIn <GenSpace>(Path.PathTypes).Or(Draw.CanDrawDoor());
        var layoutCopy            = Container.GetGrid().Array;
        List <LayoutObject> rooms = new List <LayoutObject>(Layout.Rooms.Cast <LayoutObject>());
        var runningConnected      = Container2D <GenSpace> .CreateArrayFromBounds(layoutCopy);

        // Create initial queue and visited
        var startingRoom = rooms.Take();
        startingRoom.GetConnectedGrid().DrawAll(Draw.AddTo(runningConnected));
        Container2D <bool>          visited;
        Queue <Value2D <GenSpace> > queue;
        ConstructBFS(startingRoom, out queue, out visited);
        visited = visited.Array;
        LayoutObject fail;
        while (!startingRoom.ConnectedTo(rooms, out fail))
        {
            // Find start points
            #region DEBUG
            if (BigBoss.Debug.logging(Logs.LevelGen))
            {
                runningConnected.ToLog(Logs.LevelGen, "Source Setup");
                fail.ToLog(Logs.LevelGen, "Failed to connect to this");
            }
            #endregion
            Value2D <GenSpace> startPoint;
            Value2D <GenSpace> endPoint;
            LayoutObject       hit;
            if (!FindNextPathPoints(layoutCopy, runningConnected, out hit, passTest, queue, visited, out startPoint, out endPoint))
            {
                throw new ArgumentException("Cannot find path to fail room");
            }
            // Connect
            #region DEBUG
            if (BigBoss.Debug.logging(Logs.LevelGen))
            {
                layoutCopy.SetTo(startPoint, GridType.INTERNAL_RESERVED_CUR, Theme);
                layoutCopy.ToLog(Logs.LevelGen, "Largest after putting blocked");
                BigBoss.Debug.w(Logs.LevelGen, "Start Point:" + startPoint);
            }
            #endregion
            var hitConnected = hit.GetConnectedGrid();
            var stack        = layoutCopy.DrawJumpTowardsSearch(
                startPoint.x,
                startPoint.y,
                3,
                5,
                Draw.IsType <GenSpace>(GridType.NULL).And(Draw.Inside <GenSpace>(layoutCopy.Bounding.Expand(5))),
                passTest.And(Draw.ContainedIn(hitConnected)),
                Rand,
                endPoint,
                true);
            var path = new Path(stack);
            if (path.Valid)
            {
                #region DEBUG
                if (BigBoss.Debug.logging(Logs.LevelGen))
                {
                    path.Bake(null).ToLog(Logs.LevelGen, "Connecting Path");
                }
                #endregion
                path.Simplify();
                Point        first = path.FirstEnd;
                Point        second = path.SecondEnd;
                LayoutObject leaf1, leaf2;
                LayoutObject pathObj = path.Bake(Theme);
                Container.ConnectTo(first, pathObj, first, out leaf1, out pathObj);
                Container.ConnectTo(second, pathObj, second, out leaf2, out pathObj);
                if (leaf1[first].Type == GridType.Wall)
                {
                    leaf1.SetTo(first, GridType.Door, Theme);
                }
                if (leaf2[second].Type == GridType.Wall)
                {
                    leaf2.SetTo(second, GridType.Door, Theme);
                }
                foreach (var v in pathObj)
                {
                    layoutCopy[v] = v.val;
                    runningConnected.Put(v);
                    if (!visited[v])
                    {
                        queue.Enqueue(v);
                    }
                    visited[v] = true;
                }
                foreach (var p in path)
                {
                    layoutCopy.DrawAround(p.x, p.y, false, Draw.IsType <GenSpace>(GridType.NULL).IfThen(Draw.SetTo(pathObj, GridType.Floor, Theme).And(Draw.SetTo(GridType.Floor, Theme))));
                    layoutCopy.DrawCorners(p.x, p.y, new DrawAction <GenSpace>((arr, x, y) =>
                    {
                        if (!arr.IsType(x, y, GridType.NULL))
                        {
                            return(false);
                        }
                        return(arr.Cornered(x, y, Draw.IsType <GenSpace>(GridType.Floor)));
                    }).IfThen(Draw.SetTo(pathObj, GridType.Floor, Theme)));
                }
                Container.Objects.Add(pathObj);
                hitConnected.DrawAll(Draw.AddTo(runningConnected));
                #region DEBUG
                if (BigBoss.Debug.logging(Logs.LevelGen))
                {
                    Container.ToLog(Logs.LevelGen, "Final Connection");
                }
                #endregion
            }
            else
            {
                throw new ArgumentException("Cannot create path to hit room");
            }
        }
        #region DEBUG
        if (BigBoss.Debug.logging(Logs.LevelGen))
        {
            BigBoss.Debug.printFooter(Logs.LevelGen, "Confirm Connections");
        }
        #endregion
    }
Beispiel #15
0
    protected void ClusterAround(LayoutObjectContainer cluster, LayoutObject obj)
    {
        #region Debug
        if (BigBoss.Debug.logging(Logs.LevelGen))
        {
            BigBoss.Debug.printHeader("Cluster Around");
        }
        #endregion
        obj.ShiftOutside(cluster, new Point(1, 0), null, false, false);
        obj.Shift(-1, 0); // Shift to overlapping slightly
        MultiMap <bool> visited = new MultiMap <bool>();
        visited[0, 0] = true;
        ProbabilityList <ClusterInfo> shiftOptions = new ProbabilityList <ClusterInfo>();
        Queue <Point> shiftQueue = new Queue <Point>();
        shiftQueue.Enqueue(new Point());
        Container2D <GenSpace> clusterGrid = cluster.GetGrid();
        Container2D <GenSpace> objGrid     = obj.GetGrid();
        #region Debug
        if (BigBoss.Debug.logging(Logs.LevelGen))
        {
            var tmp = new MultiMap <GenSpace>();
            tmp.PutAll(obj.GetGrid());
            tmp.PutAll(cluster.GetGrid());
            tmp.ToLog(Logs.LevelGen, "Starting placement");
        }
        #endregion
        while (shiftQueue.Count > 0)
        {
            Point curShift = shiftQueue.Dequeue();
            #region Debug
            if (BigBoss.Debug.Flag(DebugManager.DebugFlag.FineSteps) && BigBoss.Debug.logging(Logs.LevelGen))
            {
                var tmpMap = new MultiMap <GenSpace>();
                tmpMap.PutAll(clusterGrid);
                tmpMap.PutAll(objGrid, curShift);
                tmpMap.ToLog(Logs.LevelGen, "Analyzing at shift " + curShift);
            }
            #endregion
            // Test if pass
            List <Point> intersectPoints = new List <Point>();
            if (objGrid.DrawAll((arr, x, y) =>
            {
                if (GridTypeEnum.EdgeType(arr[x, y].GetGridType()))
                {
                    GridType clusterType = clusterGrid[x + curShift.x, y + curShift.y].GetGridType();
                    if (clusterType == GridType.NULL)
                    {
                        return(true);
                    }
                    intersectPoints.Add(new Point(x, y));
                    return(GridTypeEnum.EdgeType(clusterType));
                }
                else
                {
                    return(!clusterGrid.Contains(x + curShift.x, y + curShift.y));
                }
            }) &&
                intersectPoints.Count > 0)
            { // Passed test
                // queue surrounding points
                visited.DrawAround(curShift.x, curShift.y, true, Draw.Not(Draw.EqualTo(true)).IfThen(Draw.AddTo <bool>(shiftQueue).And(Draw.SetTo(true))));

                #region Debug
                if (BigBoss.Debug.Flag(DebugManager.DebugFlag.FineSteps) && BigBoss.Debug.logging(Logs.LevelGen))
                {
                    BigBoss.Debug.w(Logs.LevelGen, "passed with " + intersectPoints.Count);
                }
                #endregion
                shiftOptions.Add(new ClusterInfo()
                {
                    Shift = curShift, Intersects = intersectPoints
                }, Math.Pow(intersectPoints.Count, 3));
            }
        }
        #region Debug
        if (BigBoss.Debug.logging(Logs.LevelGen))
        {
            shiftOptions.ToLog(Logs.LevelGen, "Shift options");
        }
        #endregion
        List <Point> clusterDoorOptions = new List <Point>();
        ClusterInfo  info;
        var          placed = new List <Value2D <GenSpace> >(0);
        while (shiftOptions.Take(Rand, out info))
        {
            clusterGrid.DrawPoints(info.Intersects, Draw.CanDrawDoor().IfThen(Draw.AddTo <GenSpace>(clusterDoorOptions)).Shift(info.Shift));
            #region Debug
            if (BigBoss.Debug.logging(Logs.LevelGen))
            {
                BigBoss.Debug.w(Logs.LevelGen, "selected " + info.Shift);
                var tmpMap = new MultiMap <GenSpace>();
                clusterGrid.DrawAll(Draw.CopyTo(tmpMap));
                objGrid.DrawAll(Draw.CopyTo(tmpMap, info.Shift));
                tmpMap.DrawPoints(info.Intersects, Draw.SetTo(GridType.INTERNAL_RESERVED_CUR, Theme).Shift(info.Shift));
                tmpMap.ToLog(Logs.LevelGen, "Intersect Points");
                tmpMap = new MultiMap <GenSpace>();
                clusterGrid.DrawAll(Draw.CopyTo(tmpMap));
                objGrid.DrawAll(Draw.CopyTo(tmpMap, info.Shift));
                tmpMap.DrawPoints(clusterDoorOptions, Draw.SetTo(GridType.Door, Theme));
                tmpMap.ToLog(Logs.LevelGen, "Cluster door options");
            }
            #endregion
            if (clusterDoorOptions.Count > 0)
            { // Cluster side has door options
                obj.Shift(info.Shift.x, info.Shift.y);
                placed = obj.PlaceSomeDoors(clusterDoorOptions, Theme, Rand);
                if (placed.Count != 0)
                { // Placed a door
                    foreach (Point p in placed)
                    {
                        LayoutObject clusterObj;
                        cluster.GetObjAt(p, out clusterObj);
                        obj.Connect(clusterObj);
                    }
                    break;
                }
                else
                {
                    #region Debug
                    if (BigBoss.Debug.logging(Logs.LevelGen))
                    {
                        BigBoss.Debug.w(Logs.LevelGen, "selected point failed to match " + info.Shift + ". Backing up");
                    }
                    #endregion
                    obj.Shift(-info.Shift.x, -info.Shift.y);
                }
            }
        }
        if (placed.Count == 0)
        {
            throw new ArgumentException("Could not cluster rooms");
        }
        #region Debug
        if (BigBoss.Debug.logging(Logs.LevelGen))
        {
            var tmpMap = new MultiMap <GenSpace>();
            tmpMap.PutAll(clusterGrid);
            tmpMap.PutAll(obj.GetGrid());
            tmpMap.ToLog(Logs.LevelGen, "Final setup " + info.Shift);
            BigBoss.Debug.printFooter("Cluster Around");
        }
        #endregion
    }
Beispiel #16
0
 protected void ClusterRooms()
 {
     #region DEBUG
     if (BigBoss.Debug.logging(Logs.LevelGen))
     {
         BigBoss.Debug.printHeader(Logs.LevelGen, "Cluster Rooms");
     }
     #endregion
     List <LayoutObject> ret = new List <LayoutObject>();
     int numClusters         = Rand.Next(maxRoomClusters - minRoomClusters) + minRoomClusters;
     // Num clusters cannot be more than half num rooms
     if (numClusters > Objects.Count / 2)
     {
         numClusters = Objects.Count / 2;
     }
     List <LayoutObjectContainer> clusters = new List <LayoutObjectContainer>();
     for (int i = 0; i < numClusters; i++)
     {
         clusters.Add(new LayoutObjectContainer());
     }
     #region DEBUG
     if (BigBoss.Debug.logging(Logs.LevelGen))
     {
         BigBoss.Debug.w(Logs.LevelGen, "Number of clusters: " + numClusters);
     }
     #endregion
     // Add two rooms to each
     foreach (LayoutObjectContainer cluster in clusters)
     {
         LayoutObject obj1 = (LayoutObject)Objects.Take();
         LayoutObject obj2 = (LayoutObject)Objects.Take();
         cluster.Objects.Add(obj1);
         ClusterAround(cluster, obj2);
         cluster.Objects.Add(obj2);
         #region DEBUG
         if (BigBoss.Debug.logging(Logs.LevelGen))
         {
             cluster.ToLog(Logs.LevelGen);
         }
         #endregion
     }
     #region DEBUG
     if (BigBoss.Debug.logging(Logs.LevelGen))
     {
         BigBoss.Debug.w(Logs.LevelGen, "Rooms left: " + Objects.Count);
     }
     #endregion
     // For remaining rooms, put into random clusters
     foreach (LayoutObject r in new List <ILayoutObject>(Objects))
     {
         if (Rand.Percent(clusterProbability))
         {
             LayoutObjectContainer cluster = clusters.Random(Rand);
             ClusterAround(cluster, r);
             cluster.Objects.Add(r);
             Objects.Remove(r);
             #region DEBUG
             if (BigBoss.Debug.logging(Logs.LevelGen))
             {
                 cluster.ToLog(Logs.LevelGen);
             }
             #endregion
         }
     }
     // Add Clusters to rooms list
     foreach (ILayoutObject cluster in clusters)
     {
         Objects.Add(cluster);
     }
     #region DEBUG
     if (BigBoss.Debug.logging(Logs.LevelGen))
     {
         foreach (LayoutObjectContainer cluster in clusters)
         {
             cluster.ToLog(Logs.LevelGen);
         }
         BigBoss.Debug.printFooter(Logs.LevelGen, "Cluster Rooms");
     }
     #endregion
 }
Beispiel #17
0
 protected bool ValidateRoom(LayoutObject room)
 {
     return(room.Bounding.IsValid());
 }
Beispiel #18
0
    public static bool ConnectTo(this ILayoutObject obj1, Point pt1, ILayoutObject obj2, Point pt2, out LayoutObject retObj1, out LayoutObject retObj2)
    {
        if (obj1 is LayoutObjectContainer)
        {
            if (!((LayoutObjectContainer)obj1).GetObjAt(pt1, out retObj1))
            {
                retObj2 = null;
                return(false);
            }
        }
        else
        {
            retObj1 = (LayoutObject)obj1;
        }

        if (obj2 is LayoutObjectContainer)
        {
            if (!((LayoutObjectContainer)obj2).GetObjAt(pt2, out retObj2))
            {
                return(false);
            }
        }
        else
        {
            retObj2 = (LayoutObject)obj2;
        }
        retObj1.Connect(retObj2);
        retObj2.Connect(retObj1);
        return(true);
    }