bool EvalMeshElement(MapElement mapElement) { return(evalTags.Matches(mapElement.tags)); }
void AddRecursiveRooms(ArrayGrid <MapElement> map, MapElement roomElement, Vector2Int minRoomSize, Rect room, bool withDoors = true) { int sizeX = (int)room.size.x; if (sizeX % 2 != 0) { sizeX -= GameRNG.CoinToss() ? 1 : 0; } int sizeY = (int)room.size.y; if (sizeY % 2 != 0) { sizeY -= GameRNG.CoinToss() ? 1 : 0; } bool splitHorizontal = false; if (sizeY * 4 > sizeX) { splitHorizontal = true; } if (sizeX * 4 > sizeY) { splitHorizontal = false; } else { splitHorizontal = GameRNG.CoinToss(); } if (splitHorizontal) { if (sizeY / 2 < minRoomSize.y) { return; } int split = sizeY / 2 + GameRNG.Rand(sizeY / 2 - (int)minRoomSize.y); for (int x = (int)room.min.x; x < (int)room.max.x; ++x) { map[x, (int)room.min.y + split] = roomElement; } if (withDoors) { map[(int)room.min.x + GameRNG.Rand(sizeX - 1) + 1, (int)room.min.y + split] = defaultDoorElement; } Rect newRoom = room; Vector2Int newMax = newRoom.max.ToInt(); newMax.y = room.min.ToInt().y + split; newRoom.max = newMax; AddRecursiveRooms(map, roomElement, minRoomSize, newRoom, withDoors); newRoom = room; Vector2Int newMin = newRoom.min.ToInt(); newMin.y = room.min.ToInt().y + split; newRoom.min = newMin; AddRecursiveRooms(map, roomElement, minRoomSize, newRoom, withDoors); } else { if (sizeX / 2 < minRoomSize.x) { return; } int split = sizeX / 2 + GameRNG.Rand(sizeX / 2 - (int)minRoomSize.x); for (int y = (int)room.min.y; y < (int)room.max.y; ++y) { map[(int)room.min.x + split, y] = roomElement; } if (withDoors) { map[(int)room.min.x + split, (int)room.min.y + GameRNG.Rand(sizeY - 1) + 1] = defaultDoorElement; } Rect newRoom = room; Vector2Int newMax = newRoom.max.ToInt(); newMax.x = room.min.ToInt().x + split; newRoom.max = newMax; AddRecursiveRooms(map, roomElement, minRoomSize, newRoom, withDoors); newRoom = room; Vector2Int newMin = newRoom.min.ToInt(); newMin.x = room.min.ToInt().x + split; newRoom.min = newMin; AddRecursiveRooms(map, roomElement, minRoomSize, newRoom, withDoors); } }