public JumpTowardsSearcher(Container2D <T> cont, int x, int y, int minJump, int maxJump,
                               DrawAction <T> allowedSpace,
                               DrawAction <T> target,
                               System.Random rand,
                               Point gravityPt,
                               bool hugCorners = true,
                               bool edgeSafe   = false)
    {
        jumps = Container2D <JumpSetup> .CreateArrayFromBounds <T>(cont);

        this.container            = cont;
        curPoint                  = new Point(x, y);
        this.allowedSpace         = allowedSpace;
        this.rand                 = rand;
        this.gravityPt            = gravityPt;
        this.foundTarget          = target;
        this.edgeSafe             = edgeSafe;
        this.minJump              = minJump;
        this.maxJump              = maxJump;
        this.hugCorners           = hugCorners;
        jumpAmountOptionPrototype = new List <int>(maxJump - minJump);
        for (int i = minJump; i <= maxJump; i++)
        {
            jumpAmountOptionPrototype.Add(i);
        }
        jumpSmallerOptionPrototype = new List <int>(minJump);
        for (int i = 1; i < minJump; i++)
        {
            jumpSmallerOptionPrototype.Add(i);
        }
    }
Beispiel #2
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
    }