public void Launch(LevelConditions conditions, Dictionary <int, CellController> cells, Dictionary <int, WallController> walls) { rooms.Clear(); processed.Clear(); Doors.Clear(); LCache.Clear(); LogicCells.Clear(); Conditions = conditions; // Filling logic walls foreach (WallController w in walls.Values) { LogicWalls[w.Position.toInt()] = new LogicWall(w.Position, w.wallSprite.Top, w.wallSprite.Bottom, w.wallSprite.Left, w.wallSprite.Right); } // Filling logic cells foreach (CellController cell in cells.Values) { if (LogicCells.ContainsKey(cell.Position.toInt())) { continue; } LogicCells.Add(cell.Position.toInt(), new LogicCell(cell.Position)); if (cell.SizeX > 1 || cell.SizeY > 1) { MapRect rect = cell.GetCurCellIndexes(); rect.Foreach((MapPoint p) => { if (!LogicCells.ContainsKey(p.toInt())) { LogicCells.Add(p.toInt(), new LogicCell(p)); } }); } } // Calculating reaches foreach (LogicCell cell in LogicCells.Values) { WallController w = null; LogicCell c = null; //left c = GetLogicCell(cell.Position.X - 1, cell.Position.Y); w = GetWall(cell.Position.X, cell.Position.Y); if (c != null && (w == null || w.wallSprite.Top == false)) { cell.ReachableCells.Add(c); } //right c = GetLogicCell(cell.Position.X + 1, cell.Position.Y); w = GetWall(cell.Position.X + 1, cell.Position.Y + 1); if (c != null && (w == null || w.wallSprite.Bottom == false)) { cell.ReachableCells.Add(c); } //top c = GetLogicCell(cell.Position.X, cell.Position.Y + 1); w = GetWall(cell.Position.X + 1, cell.Position.Y + 1); if (c != null && (w == null || w.wallSprite.Left == false)) { cell.ReachableCells.Add(c); } //bottom c = GetLogicCell(cell.Position.X, cell.Position.Y - 1); w = GetWall(cell.Position.X, cell.Position.Y); if (c != null && (w == null || w.wallSprite.Right == false)) { cell.ReachableCells.Add(c); } cell.AdjacentWalls += GetWall(cell.Position.X, cell.Position.Y) == null?0:1; cell.AdjacentWalls += GetWall(cell.Position.X + 1, cell.Position.Y) == null?0:1; cell.AdjacentWalls += GetWall(cell.Position.X, cell.Position.Y + 1) == null?0:1; cell.AdjacentWalls += GetWall(cell.Position.X + 1, cell.Position.Y + 1) == null?0:1; } // Finding Rooms curRoom = new Room(this); foreach (LogicCell cell in LogicCells.Values) { if (processed.Contains(cell)) { continue; } Next(cell); if (curRoom.Size > 0) { rooms.Add(curRoom); Debug.Log(string.Format("Found room #{1} with {0} cells", curRoom.Size, curRoom.Number)); curRoom = new Room(this); curRoom.Number = rooms.Count; } } // STEP 2 - Recognize rooms Recognize(); // STEP 3 - Calculate connections Connections(); foreach (Room r in rooms) { M.Overlay.DrawRoom(r); Debug.Log(string.Format("Room #{0} is {1}, {2} objects", r.Number, Enum.GetName(typeof(RoomType), r.TypeOfRoom), r.LogicObjects.Count)); foreach (Door d in r.Doors) { if (d.Rooms.Count == 1) { Debug.Log(string.Format(" Room #{0} contains door that leads to nothing", r.Number)); } else if (d.Rooms.Count == 2) { Debug.Log(string.Format(" Room #{0} contains door that leads to room #{1}", r.Number, d.GetAnotherRoom(r).Number)); } else { Debug.Log(string.Format(" Buggy room #{0}", r.Number)); } } } evaluator.Launch(); }