public Stack <List <Value2D <T> > > Find() { #region DEBUG if (BigBoss.Debug.Flag(DebugManager.DebugFlag.FineSteps) && BigBoss.Debug.logging(Logs.LevelGen) && typeof(T) == typeof(GridType)) { BigBoss.Debug.printHeader(Logs.LevelGen, "Jump Towards Search"); BigBoss.Debug.w(Logs.LevelGen, "Starting from " + curPoint + " Going towards " + gravityPt); MultiMap <GridType> tmpArr = new MultiMap <GridType>(); foreach (Value2D <T> val in container) { tmpArr[val] = (GridType)(object)container[val]; } tmpArr[curPoint.x, curPoint.y] = GridType.INTERNAL_RESERVED_CUR; tmpArr.ToLog(Logs.LevelGen, "Starting Map:"); } #endregion // Push start point onto path lastJump = new List <Value2D <T> >(new Value2D <T>[] { new Value2D <T>(curPoint.x, curPoint.y, container[curPoint]) }); pathTaken.Push(lastJump); jumps[curPoint] = new JumpSetup(this, curPoint, curPoint); try { while (pathTaken.Count > 0) { curPoint = lastJump[lastJump.Count - 1]; // Didn't find target, go towards target JumpSetup jumpSetup = jumps[curPoint]; if (GetJumpTowards(jumpSetup, out lastJump)) { // Found target pathTaken.Push(lastJump); break; } if (lastJump.Count > 0) { // Jumped // Chose a dir pathTaken.Push(lastJump); #region DEBUG if (BigBoss.Debug.Flag(DebugManager.DebugFlag.SearchSteps) && BigBoss.Debug.logging(Logs.LevelGen)) { PrintSetup(); } #endregion } else { // None found. Pop if (lastJump.Count <= 1) { pathTaken.Pop(); } else { lastJump.RemoveAt(lastJump.Count - 1); } #region DEBUG if (BigBoss.Debug.Flag(DebugManager.DebugFlag.SearchSteps) && BigBoss.Debug.logging(Logs.LevelGen)) { BigBoss.Debug.w(Logs.LevelGen, "Backing up from " + curPoint.x + " " + curPoint.y); PrintSetup(); } #endregion if (pathTaken.Count > 0) { lastJump = pathTaken.Peek(); } } } } catch (Exception ex) { BigBoss.Debug.w(Logs.LevelGen, ex.ToString()); #region DEBUG if (BigBoss.Debug.Flag(DebugManager.DebugFlag.FineSteps) && BigBoss.Debug.logging(Logs.LevelGen)) { BigBoss.Debug.printFooter(Logs.LevelGen, "Jump Towards Search"); } #endregion throw; } #region DEBUG if (BigBoss.Debug.Flag(DebugManager.DebugFlag.FineSteps) && BigBoss.Debug.logging(Logs.LevelGen)) { BigBoss.Debug.printFooter(Logs.LevelGen, "Jump Towards Search"); } #endregion return(pathTaken); }
bool GetJumpTowards(JumpSetup setup, out List <Value2D <T> > ret) { ret = new List <Value2D <T> >(setup.Amount); Point last; while (!setup.Done) { Point dir = setup.Dirs[setup.DirPtr++]; Point endPoint = curPoint + dir; if (edgeSafe && !jumps.InRange(endPoint)) { // Out of range #region DEBUG if (BigBoss.Debug.Flag(DebugManager.DebugFlag.SearchSteps) && BigBoss.Debug.logging(Logs.LevelGen)) { BigBoss.Debug.w(Logs.LevelGen, "end point out of array range " + endPoint); } #endregion ret = new List <Value2D <T> >(0); return(false); } // Can test this route Point cur = new Point(curPoint); for (int i = 1; i <= setup.Amount; i++) { last = cur; cur += dir; JumpSetup space = jumps[cur]; if (space == null) { space = new JumpSetup(this, cur, last); jumps[cur] = space; if (space.Allowed) { ret.Add(new Value2D <T>(cur.x, cur.y, container[cur])); // If found target, return path we took Value2D <T> found; if (container.GetPointAround(cur.x, cur.y, false, foundTarget, out found)) { #region DEBUG if (BigBoss.Debug.Flag(DebugManager.DebugFlag.FineSteps) && BigBoss.Debug.logging(Logs.LevelGen)) { BigBoss.Debug.w(Logs.LevelGen, "===== FOUND TARGET: " + found); } #endregion ret.Add(new Value2D <T>(found.x, found.y, container[found])); return(true); } continue; } } // Blocked #region DEBUG if (BigBoss.Debug.Flag(DebugManager.DebugFlag.SearchSteps) && BigBoss.Debug.logging(Logs.LevelGen)) { BigBoss.Debug.w(Logs.LevelGen, "failed to step past " + cur + " from " + setup.Point + " in dir " + dir + " jumping " + setup.Amount); } #endregion if (hugCorners) { if (ret.Count == 0) { setup.Amount = 1; } else { jumps[cur - dir].Amount = 1; } } break; } #region DEBUG if (ret.Count > 0) { if (BigBoss.Debug.Flag(DebugManager.DebugFlag.SearchSteps) && BigBoss.Debug.logging(Logs.LevelGen)) { BigBoss.Debug.w(Logs.LevelGen, "Chose Direction: " + dir + " from " + setup.Point + " jumping " + (cur - curPoint)); } return(false); } #endregion } ret.Clear(); return(false); }