public LogicGrid(CellInfo[,] infoGrid) { int width = infoGrid.GetLength(0); int height = infoGrid.GetLength(1); Grid = new LogicCell[width, height]; Dictionary <int, LogicCell> cells = new Dictionary <int, LogicCell>(); for (int x = 0; x < width; x++) { for (int y = 0; y < height; y++) { Grid[x, y] = infoGrid[x, y].CellFromBytes(); if (Grid[x, y] != null) { cells[Grid[x, y].GetCellID()] = Grid[x, y]; } } } for (int x = 0; x < width; x++) { for (int y = 0; y < height; y++) { if (Grid[x, y] is DoorButtonCell doorButton) { if (cells[doorButton.GetLinkedDoorID()] is DoorCell door) { doorButton.SetLinkedDoor(door); } } } } }
private LogicCell ConvertYosysCell(KeyValuePair <string, YosysCell> yosysCell) { var type = yosysCell.Value.type; LogicCell cell = null; switch (type) { case "$_NOT_": cell = new LogicCell("NOT"); break; case "$_AND_": cell = new LogicCell("AND"); break; case "$_ANDNOT_": cell = new LogicCell("ANDNOT"); break; case "$_NAND_": cell = new LogicCell("NAND"); break; case "$_OR_": cell = new LogicCell("OR"); break; case "$_XOR_": cell = new LogicCell("XOR"); break; case "$_XNOR_": cell = new LogicCell("XNOR"); break; case "$_NOR_": cell = new LogicCell("NOR"); break; case "$_ORNOT_": cell = new LogicCell("ORNOT"); break; case "$_DFF_P_": cell = new LogicCell("DFFP"); break; case "$_MUX_": cell = new LogicCell("MUX"); break; default: throw new Exception($"Invalid type token: {type}"); } return(cell); }
void Next(LogicCell curCell) { curRoom.AddCell(curCell, LCache, M.House.GetCell(curCell.Position)); processed.Add(curCell); M.House.ForEachWall(curCell.Position, (WallPoint wp, WallController wc, Corner corn) => { if (wc == null) { return; } if (wc.WallObject is DoorController) { Door door = null; if (!Doors.TryGetValue(wp.toInt(), out door)) { door = new Door(wp); Doors.Add(wp.toInt(), door); } door.AddRoom(curRoom); curRoom.AddDoor(door); } else if (wc.WallObject is EntranceController) { curRoom.Entrance = true; } else if (wc.WallObject is GarageGateController) { curRoom.GarageGate = true; } else if (wc.WallObject is WindowController) { WindowController window = wc.WallObject as WindowController; curRoom.NorthWindows |= window.North; curRoom.SouthWindows |= window.South; curRoom.EastWindows |= window.East; curRoom.WestWindows |= window.West; } }); foreach (LogicCell nc in curCell.ReachableCells) { if (!processed.Contains(nc)) { Next(nc); } } }
void Recursive(LogicCell cell) { processed.Add(cell); bool wasWithDoor = toProcess.Remove(cell); if(toProcess.Count==0) return; if( (cell.ReachableCells.Count>2 && cell.AdjacentWalls<3) || (cell.ReachableCells.Count==2 && wasWithDoor)) { foreach(LogicCell c in cell.ReachableCells ) { if(processed.Contains(c)) continue; Recursive(c); } } }
public bool IsRectFree(MapRect rect) { bool res = true; rect.Foreach((MapPoint p) => { LogicCell c = null; if (res && !LogicCells.TryGetValue(p.toInt(), out c)) { res = false; } if (res && p.X > rect.MinX && p.Y > rect.MinY) { LogicWall w = null; if (Seg.LogicWalls.TryGetValue(new WallPoint(p.X, p.Y).toInt(), out w)) { res = false; } } }); if (res) { for (int x = rect.MinX + 1; x <= rect.MaxX; x++) { LogicWall w = null; if (Seg.LogicWalls.TryGetValue(new WallPoint(x, rect.MinY).toInt(), out w) && w.Top) { res = false; } } for (int y = rect.MinY + 1; y <= rect.MaxY; y++) { LogicWall w = null; if (Seg.LogicWalls.TryGetValue(new WallPoint(rect.MinX, y).toInt(), out w) && w.Right) { res = false; } } } return(res); }
public bool Process(Segmentator s, Room r) { if (r.TypeOfRoom != RoomType.Dining || r.TypeOfRoom != RoomType.Kitchen) { return(false); } List <LogicHob> hobs = r.GetObjects <LogicHob>(); foreach (LogicHob h in hobs) { MapPoint pos = new MapPoint(h.ObjectRect.MinX, h.ObjectRect.MinY); LogicCell cell = r.LogicCells[pos.toInt()]; if (cell.ReachableCells.Count == 4) { return(true); } } return(false); }
void Recursive(LogicCell cell) { processed.Add(cell); bool wasWithDoor = toProcess.Remove(cell); if (toProcess.Count == 0) { return; } if ((cell.ReachableCells.Count > 2 && cell.AdjacentWalls < 3) || (cell.ReachableCells.Count == 2 && wasWithDoor)) { foreach (LogicCell c in cell.ReachableCells) { if (processed.Contains(c)) { continue; } Recursive(c); } } }
private IEnumerator BuildWorldFromCellInfoCoroutine(CellInfo[,] cellInfos) { // voir https://docs.unity3d.com/ScriptReference/Tilemaps.Tilemap.SetTiles.html // créer arrays de tile ensuite call setTiles ? Vector3Int pos = new Vector3Int(0, 0, 0); m_totalTiles = cellInfos.GetLength(0) * cellInfos.GetLength(1); List <Tile> wallCells = new List <Tile>(); List <Tile> floorCells = new List <Tile>(); List <Tile> doorCells = new List <Tile>(); List <Tile> doorButtonCells = new List <Tile>(); List <Tile> playerSpawnCells = new List <Tile>(); List <Vector3Int> wallPos = new List <Vector3Int>(); List <Vector3Int> floorPos = new List <Vector3Int>(); List <Vector3Int> doorPos = new List <Vector3Int>(); List <Vector3Int> doorButtonPos = new List <Vector3Int>(); List <Vector3Int> playerSpawnPos = new List <Vector3Int>(); for (int x = 0; x < cellInfos.GetLength(0); x++) { for (int y = 0; y < cellInfos.GetLength(1); y++) { LogicCell cell = cellInfos[x, y].CellFromBytes(); pos.x = x; pos.y = y; if (cell is WallCell) { wallCells.Add(m_defaultWallTile); wallPos.Add(pos); } else if (cell is FloorCell) { floorCells.Add(m_defaultFloorTile); floorPos.Add(pos); } else if (cell is DoorCell) { doorCells.Add(m_defaultDoorTile); doorPos.Add(pos); } else if (cell is DoorButtonCell) { doorButtonCells.Add(m_defaultInteractableTile); doorButtonPos.Add(pos); } else if (cell is PlayerSpawnCell) { playerSpawnCells.Add(m_defaultPlayerSpawnTile); playerSpawnPos.Add(pos); } m_loadedTiles++; } yield return(null); } m_walls.SetTiles(wallPos.ToArray(), wallCells.ToArray()); m_floor.SetTiles(floorPos.ToArray(), floorCells.ToArray()); m_doors.SetTiles(doorPos.ToArray(), doorCells.ToArray()); m_interactable.SetTiles(doorButtonPos.ToArray(), doorButtonCells.ToArray()); m_playerSpawn.SetTiles(playerSpawnPos.ToArray(), playerSpawnCells.ToArray()); IsRebuilt = true; m_onWorldBuilt.Invoke(); }
void Next(LogicCell curCell) { curRoom.AddCell(curCell,LCache,M.House.GetCell(curCell.Position)); processed.Add(curCell); M.House.ForEachWall(curCell.Position, (WallPoint wp, WallController wc,Corner corn) => { if(wc==null) return; if(wc.WallObject is DoorController) { Door door = null; if(!Doors.TryGetValue(wp.toInt(),out door)) { door = new Door(wp); Doors.Add(wp.toInt(),door); } door.AddRoom(curRoom); curRoom.AddDoor(door); } else if(wc.WallObject is EntranceController) { curRoom.Entrance = true; } else if(wc.WallObject is GarageGateController) { curRoom.GarageGate = true; } else if(wc.WallObject is WindowController) { WindowController window = wc.WallObject as WindowController; curRoom.NorthWindows |= window.North; curRoom.SouthWindows |= window.South; curRoom.EastWindows |= window.East; curRoom.WestWindows |= window.West; } }); foreach(LogicCell nc in curCell.ReachableCells) { if(!processed.Contains(nc)) Next (nc); } }
public void AddCell(LogicCell cell, LogicCache cache, CellController phCell) { LogicCells[cell.Position.toInt()] = cell; if (Cells.Contains(phCell)) { return; } Cells.Add(phCell); if (phCell.CellObject != null) { ILogicObject lo = phCell.CellObject.Fabricate(); if (lo.ObjectType != phCell.CellObject.GetCellObjectType()) { throw new UnityException("Wrong object type!"); } if (lo != null) { LogicObjects.Add(lo); cache.Objects.Add(lo); switch (lo.ObjectType) { case CellObjects.Shower: case CellObjects.Sink: cache.HotWaterConsumers.Add(lo as IHotWaterConsumer); break; case CellObjects.Bathtub: cache.HotWaterConsumers.Add(lo as IHotWaterConsumer); cache.Bathtubs.Add(lo as LogicBathtub); break; case CellObjects.Boiler: cache.Boilers.Add(lo as LogicBoiler); break; case CellObjects.Fireplace: cache.Fireplaces.Add(lo as LogicFireplace); break; case CellObjects.Heater: cache.Heaters.Add(lo as LogicHeater); break; case CellObjects.HeatingPipe: cache.HeatingPipes.Add(lo as LogicHeatingPipe); break; case CellObjects.Hob: break; case CellObjects.Riser: cache.Risers.Add(lo as LogicRiser); break; case CellObjects.Toilet: break; case CellObjects.Ventshaft: cache.Vents.Add(lo as LogicVentshaft); break; } } } }
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(); }
public bool Process(Segmentator s, Room r) { processed = new List <LogicCell>(); Dictionary <Door, LogicCell> doorCells = new Dictionary <Door, LogicCell>(); foreach (Door d in r.Doors) { if (doorCells.ContainsKey(d)) { continue; } LogicCell c = null; MapPoint p = null; p = new MapPoint(d.Position.X, d.Position.Y); if (r.LogicCells.TryGetValue(p.toInt(), out c) && !processed.Contains(c)) { processed.Add(c); doorCells.Add(d, c); continue; } p = new MapPoint(d.Position.X - 1, d.Position.Y); if (r.LogicCells.TryGetValue(p.toInt(), out c) && !processed.Contains(c)) { processed.Add(c); doorCells.Add(d, c); continue; } p = new MapPoint(d.Position.X, d.Position.Y - 1); if (r.LogicCells.TryGetValue(p.toInt(), out c) && !processed.Contains(c)) { processed.Add(c); doorCells.Add(d, c); continue; } p = new MapPoint(d.Position.X - 1, d.Position.Y - 1); if (r.LogicCells.TryGetValue(p.toInt(), out c) && !processed.Contains(c)) { processed.Add(c); doorCells.Add(d, c); continue; } } toProcess = new List <LogicCell>(doorCells.Values); if (toProcess.Count == 0) { return(false); } processed.Clear(); Recursive(toProcess[0]); if (toProcess.Count > 0) { return(true); } return(false); }