//get rooms with a certain number of 'openings' public List <Vector2Int> GetRoomsWithCertainOpeningNumber(int minNumber, int maxNumber) { List <Vector2Int> m_PossibleRooms = new List <Vector2Int>(); foreach (KeyValuePair <Vector2Int, RoomOpeningTypes> pair in m_Taken) { Vector2Int gridPos = pair.Key; RoomOpeningTypes roomOpeningsType = pair.Value; //if grid pos already taken dont return, this is a hack, im so tired if (gridPos == m_SpawnRoomGridPos || gridPos == m_TradeRoomGridPos) { continue; } RoomOpeningInfo roomInfo = null; if (m_RoomOpeningsData.ContainsKey(roomOpeningsType)) { roomInfo = m_RoomOpeningsData[roomOpeningsType]; } if (roomInfo == null) { continue; } if (roomInfo.m_NumberOfOpenings >= minNumber && roomInfo.m_NumberOfOpenings <= maxNumber) { m_PossibleRooms.Add(gridPos); } } return(m_PossibleRooms); }
public void CheckNeighboursAndOpenings(Vector2Int pos, ref int numberOfNeighbours, ref bool rightNeighbour, ref bool leftNeighbour, ref bool upNeighbour, ref bool downNeighbour) { //check if there are any neighbors and neighbors have possible path to them RoomOpeningInfo neightbourRoomOpenings = null; Vector2Int offset = pos + new Vector2Int(0, 1); if (m_Taken.ContainsKey(offset)) { neightbourRoomOpenings = m_RoomOpeningsData[m_Taken[offset]]; //get the neighbour opening room data if (neightbourRoomOpenings.m_DownOpening) //if neighbour can connect too { upNeighbour = true; ++numberOfNeighbours; } } //check down offset = pos + new Vector2Int(0, -1); if (m_Taken.ContainsKey(offset)) { neightbourRoomOpenings = m_RoomOpeningsData[m_Taken[offset]]; //get the neighbour opening room data if (neightbourRoomOpenings.m_UpOpening) //if neighbour can connect too { downNeighbour = true; ++numberOfNeighbours; } } //check right offset = pos + new Vector2Int(1, 0); if (m_Taken.ContainsKey(offset)) { neightbourRoomOpenings = m_RoomOpeningsData[m_Taken[offset]]; //get the neighbour opening room data if (neightbourRoomOpenings.m_LeftOpening) //if neighbour can connect too { rightNeighbour = true; ++numberOfNeighbours; } } //check left offset = pos + new Vector2Int(-1, 0); if (m_Taken.ContainsKey(offset)) { neightbourRoomOpenings = m_RoomOpeningsData[m_Taken[offset]]; //get the neighbour opening room data if (neightbourRoomOpenings.m_RightOpening) //if neighbour can connect too { leftNeighbour = true; ++numberOfNeighbours; } } }
public RoomOpeningTypes GetExactRoomType(int minNumberOfOpenings, bool rightNeighbour, bool leftNeighbour, bool upNeighbour, bool downNeighbour) { foreach (KeyValuePair <RoomOpeningTypes, RoomOpeningInfo> roomPair in m_RoomOpeningsData) { RoomOpeningInfo room = roomPair.Value; if (room.m_NumberOfOpenings != minNumberOfOpenings) { continue; } //everything must be exact if (rightNeighbour == room.m_RightOpening && leftNeighbour == room.m_LeftOpening && upNeighbour == room.m_UpOpening && downNeighbour == room.m_DownOpening) { return(room.m_RoomOpeningType); } } return(RoomOpeningTypes.NO_OPENING); }
public void GenerateLevel() { m_Taken.Clear(); m_RoomsBehaviour.Clear(); foreach (Transform child in m_RoomParent.transform) { Destroy(child.gameObject); } Vector2Int start = Vector2Int.zero; m_SpawnRoomGridPos = m_BossRoomGridPos = m_TradeRoomGridPos = start; Queue <Vector2Int> m_RoomLocations = new Queue <Vector2Int>(); m_Taken.Add(start, RoomOpeningTypes.L_R_U_D_OPENING); m_RoomLocations.Enqueue(start); while (m_RoomLocations.Count > 0) { Vector2Int roomLocation = m_RoomLocations.Dequeue(); RoomOpeningTypes roomType = m_Taken[roomLocation]; if (m_Taken.Count >= m_MinMaxRoomNumber.y) { //dont add anymore, edit current ones left in the queue instead if (m_Taken.ContainsKey(roomLocation)) { m_Taken[roomLocation] = ChangeCurrentRoomToExact(roomLocation); } } else { RoomOpeningInfo openingInfo = null; if (m_RoomOpeningsData.ContainsKey(roomType)) { openingInfo = m_RoomOpeningsData[roomType]; } if (openingInfo == null) { continue; } //make sure to check the door direction and have no rooms that is already taking that space Vector2Int newPos = roomLocation + new Vector2Int(0, 1); if (!m_Taken.ContainsKey(newPos) && openingInfo.m_UpOpening) { if (AddToTaken(newPos, AddNextRoom(newPos))) { m_RoomLocations.Enqueue(newPos); } } newPos = roomLocation + new Vector2Int(0, -1); if (!m_Taken.ContainsKey(newPos) && openingInfo.m_DownOpening) { if (AddToTaken(newPos, AddNextRoom(newPos))) { m_RoomLocations.Enqueue(newPos); } } newPos = roomLocation + new Vector2Int(1, 0); if (!m_Taken.ContainsKey(newPos) && openingInfo.m_RightOpening) { if (AddToTaken(newPos, AddNextRoom(newPos))) { m_RoomLocations.Enqueue(newPos); } } newPos = roomLocation + new Vector2Int(-1, 0); if (!m_Taken.ContainsKey(newPos) && openingInfo.m_LeftOpening) { if (AddToTaken(newPos, AddNextRoom(newPos))) { m_RoomLocations.Enqueue(newPos); } } } } FixAllRooms(); //make sure theres no weird rooms with broken paths DecideRoomType(); //set the room types InstantiateRooms(); //spawn and instantiate rooms InitRoomType(); BuildNavMesh(); SetAllRoomsInactive(); InitUI(); //init the minimap stuff //setup initial start room if (m_RoomsBehaviour.ContainsKey(m_SpawnRoomGridPos)) { m_RoomsBehaviour[m_SpawnRoomGridPos].gameObject.SetActive(true); m_RoomsBehaviour[m_SpawnRoomGridPos].SetupRoom(); m_CurrRoom = m_PrevRoom = m_SpawnRoomGridPos; } }
public List <RoomOpeningTypes> GetPossibleRoomTypes(Vector2Int pos, int minNumberOfOpenings, bool rightNeighbour, bool leftNeighbour, bool upNeighbour, bool downNeighbour) { List <RoomOpeningTypes> possibleRooms = new List <RoomOpeningTypes>(); RoomOpeningInfo neightbourRoomOpenings = null; bool downNeighbourAvail, upNeighbourAvail, rightNeightbourAvail, leftneighbourAvail; downNeighbourAvail = upNeighbourAvail = rightNeightbourAvail = leftneighbourAvail = true; //check if the up neighbour is available to link Vector2Int offset = pos + new Vector2Int(0, 1); if (upNeighbour) { neightbourRoomOpenings = m_RoomOpeningsData[m_Taken[offset]]; //get the neighbour opening room data upNeighbourAvail = neightbourRoomOpenings.m_DownOpening; } offset = pos + new Vector2Int(0, -1); if (downNeighbour) { neightbourRoomOpenings = m_RoomOpeningsData[m_Taken[offset]]; //get the neighbour opening room data downNeighbourAvail = neightbourRoomOpenings.m_UpOpening; } //check if right neighbour is available to link offset = pos + new Vector2Int(1, 0); if (rightNeighbour) { neightbourRoomOpenings = m_RoomOpeningsData[m_Taken[offset]]; //get the neighbour opening room data rightNeightbourAvail = neightbourRoomOpenings.m_LeftOpening; } offset = pos + new Vector2Int(-1, 0); if (leftNeighbour) { neightbourRoomOpenings = m_RoomOpeningsData[m_Taken[offset]]; //get the neighbour opening room data leftneighbourAvail = neightbourRoomOpenings.m_RightOpening; } foreach (KeyValuePair <RoomOpeningTypes, RoomOpeningInfo> roomPair in m_RoomOpeningsData) { RoomOpeningInfo room = roomPair.Value; if (room.m_NumberOfOpenings < minNumberOfOpenings) { continue; } if (rightNeighbour) //if theres a right neighbour { if (!rightNeightbourAvail && room.m_RightOpening) //if theres an opening abv, but up neighbour cant link { continue; } else if (rightNeightbourAvail && !room.m_RightOpening) //if neighbour can take but room no opening { continue; } } if (leftNeighbour) { if (!leftneighbourAvail && room.m_LeftOpening) //if theres an opening abv, but up neighbour cant link { continue; } else if (leftneighbourAvail && !room.m_LeftOpening) //if neighbour can take but room no opening { continue; } } if (upNeighbour) { if (!upNeighbourAvail && room.m_UpOpening) //if theres an opening abv, but up neighbour cant link { continue; } else if (upNeighbourAvail && !room.m_UpOpening) //if neighbour can take but room no opening { continue; } } if (downNeighbour) { if (!downNeighbourAvail && room.m_DownOpening) //if theres an opening abv, but up neighbour cant link { continue; } else if (downNeighbourAvail && !room.m_DownOpening) //if neighbour can take but room no opening { continue; } } possibleRooms.Add(room.m_RoomOpeningType); } return(possibleRooms); }