public override bool Place(Container2D <GenSpace> grid, LayoutObject obj, Theme theme, System.Random rand, out Boxing placed) { List <Bounding> options = obj.FindRectangles(GridWidth, GridLength, true, UnitTest); options = new List <Bounding>(options.Filter((bounds) => { Counter counter = new Counter(); grid.DrawRect(new Bounding(bounds, 1), FrontTest.IfThen(Draw.Count <GenSpace>(counter))); return(counter > 0); })); if (options.Count == 0) { placed = null; return(false); } #region DEBUG if (BigBoss.Debug.logging(Logs.LevelGen) && BigBoss.Debug.Flag(DebugManager.DebugFlag.FineSteps)) { BigBoss.Debug.w(Logs.LevelGen, "Options:"); if (GridWidth == 1 && GridLength == 1) { MultiMap <GenSpace> tmp = new MultiMap <GenSpace>(); tmp.PutAll(obj); foreach (Bounding bounds in options) { tmp.DrawRect(bounds, Draw.SetTo(GridType.INTERNAL_RESERVED_CUR, theme)); } tmp.ToLog(Logs.LevelGen); } else { foreach (Bounding bounds in options) { MultiMap <GenSpace> tmp = new MultiMap <GenSpace>(); tmp.PutAll(obj); tmp.DrawRect(bounds, Draw.SetTo(GridType.INTERNAL_RESERVED_CUR, theme)); tmp.ToLog(Logs.LevelGen); } } } #endregion // Place startpoints placed = null; return(false); //placed = options.Random(rand); placed.Expand(1); GridLocation side = GridLocation.BOTTOMRIGHT; foreach (GridLocation loc in GridLocationExt.Dirs().Randomize(rand)) { if (obj.DrawEdge(placed, loc, UnitTest, false)) { side = loc; break; } } obj.DrawEdge(placed, side, Draw.SetTo(GridType.StairPlace, theme), false); return(true); }
public List <Bounding> Find() { List <Bounding> ret = new List <Bounding>(); if (_width >= _arr.Width || _height >= _arr.Height) { return(ret); } if (_width == 1 && _height == 1) { return(SingleFind()); } // Initialize _x = _scope.XMin; _y = _scope.YMin; _lastPassedX = int.MaxValue; _lastTestedX = _scope.XMin; _lastTestedY = _scope.YMin; xShift = _arr.Bounding.XMin; _lastPassedXArr = new bool[_arr.Width]; if (_tester.StrokeAction == null && _width > 3 && _height > 3) { // Just unit FindSkip(ret); } else if (_tester.StrokeAction != null && _tester.UnitAction != null && _width > 5 && _height > 5) { // Unit and stroke with optimization // Find non-stroke options, then test stroke DrawAction <T> stroke = _tester.StrokeAction; _tester.StrokeAction = null; _width -= 2; _height -= 2; FindSkip(ret); _width += 2; _height += 2; _tester.StrokeAction = stroke; List <Bounding> retTmp = new List <Bounding>(ret); ret.Clear(); StrokedAction <T> strokeTest = new StrokedAction <T>() { StrokeAction = _tester.StrokeAction }; foreach (Bounding b in retTmp) { b.Expand(1); if (_arr.DrawRect(b.XMin, b.XMax, b.YMin, b.YMax, strokeTest)) { ret.Add(b); } } } else { FindNormal(ret); } if (_tryFlipped && ret.Count == 0) { // Flip and try again _tryFlipped = false; int tmp = _width; _width = _height; _height = tmp; return(Find()); } return(ret); }