예제 #1
0
    protected override bool ModifyInternal(RoomSpec spec)
    {
        List <Bounding> options = spec.Grids.FindRectangles(5, 5, false, new StrokedAction <GenSpace>()
        {
            UnitAction   = Draw.Walkable(),
            StrokeAction = Draw.Not(Draw.Blocking(Draw.Walkable())).And(Draw.IsType <GenSpace>(GridType.Floor).Or(Draw.WallType <GenSpace>()))
        }, spec.Grids.Bounding);

        while (options.Count > 0)
        {
            Bounding bounding = options.RandomTake(spec.Random);
            Point    center   = bounding.GetCenter();
            if (spec.Grids[center].Type != GridType.Floor)
            {
                return(false);
            }
            List <Point> doors = new List <Point>();
            HandleDoor(bounding.XMin, center.y, doors, spec);
            HandleDoor(bounding.XMin, center.y, doors, spec);
            HandleDoor(center.x, bounding.YMin, doors, spec);
            HandleDoor(center.x, bounding.YMax, doors, spec);
            if (doors.Count == 0)
            {
                return(false);
            }
            // Draw it
            spec.Grids.DrawRect(bounding.XMin, bounding.XMax, bounding.YMin, bounding.YMax, new StrokedAction <GenSpace>()
            {
                StrokeAction = Draw.SetTo(GridType.Wall, spec.Theme),
                UnitAction   = Draw.SetTo(GridType.Floor, spec.Theme)
            });
            foreach (var door in doors)
            {
                spec.Grids.SetTo(door, GridType.Door, spec.Theme);
            }
            spec.Grids.SetTo(center, GridType.Chest, spec.Theme);
            return(true);
        }
        return(true);
    }
예제 #2
0
    // Gets center point of intersecting bounds
    public Point GetIntersectCenter(Bounding rhs)
    {
        Bounding intersection = IntersectBounds(rhs);

        return(intersection.GetCenter());
    }
예제 #3
0
    protected bool PlaceMissingStair(bool up, Bounding otherStair, out Boxing placed)
    {
        Container2D <GenSpace> layout = Container.GetGrid();

        #region Debug
        if (BigBoss.Debug.logging(Logs.LevelGen))
        {
            BigBoss.Debug.printHeader(Logs.LevelGen, "Placing missing stair");
            BigBoss.Debug.w(Logs.LevelGen, "Up: " + up + ", other stair " + otherStair);
        }
        #endregion
        foreach (LayoutObject obj in Container.Flatten().Randomize(Rand))
        {
            #region DEBUG
            if (BigBoss.Debug.logging(Logs.LevelGen))
            {
                obj.ToLog("Trying in.");
            }
            #endregion
            if (otherStair != null)
            {
                if (otherStair.GetCenter().Distance(obj.Bounding.GetCenter()) < MinStairDist)
                {
                    #region DEBUG
                    if (BigBoss.Debug.logging(Logs.LevelGen))
                    {
                        BigBoss.Debug.w(Logs.LevelGen, "Skipping due to distance to other stair.");
                    }
                    #endregion
                    continue;
                }
            }
            StairElement stair = Theme.Stair.SmartElement.Get(Rand) as StairElement;

            if (!stair.Place(layout, obj, Theme, Rand, out placed))
            {
                #region DEBUG
                if (BigBoss.Debug.logging(Logs.LevelGen))
                {
                    BigBoss.Debug.w(Logs.LevelGen, "No options.");
                }
                #endregion
                continue;
            }
            obj.DrawRect(placed, Draw.SetTo(up ? GridType.StairUp : GridType.StairDown, Theme).And(Draw.MergeIn(stair, Theme)));
            #region Debug
            if (BigBoss.Debug.logging(Logs.LevelGen))
            {
                obj.ToLog(Logs.LevelGen, "Placed stairs");
                Container.ToLog(Logs.LevelGen, "Layout");
                BigBoss.Debug.printFooter("Placing Missing Stair");
            }
            #endregion
            return(true);
        }
        placed = null;
        #region Debug
        if (BigBoss.Debug.logging(Logs.LevelGen))
        {
            BigBoss.Debug.printFooter("Placing Missing Stair");
        }
        #endregion
        return(false);
    }