public Outlet(RoomGenerator prev, RoomGenerator next, MapGenerator.Direction dir) { m_prev = prev; m_next = next; m_prev.SetRoom(this, dir); m_next.SetRoom(this, MapGenerationHelpers.Opposite(dir)); }
public bool CheckAvailability(MapGenerator.Direction dir) { if ((dir == MapGenerator.Direction.Up && m_top != null) || (dir == MapGenerator.Direction.Right && m_right != null) || (dir == MapGenerator.Direction.Left && m_left != null) || (dir == MapGenerator.Direction.Down && m_bottom != null)) { return(false); } return(true); }
//------------------------------------------------------------------- // This links 2 rooms together. // mapIndex: the index of the room's location in the map // dir: the direction of the room we want to link to // TODO: this return value seems off, need to think about refactoring this // return: whether we created a new room while linking //------------------------------------------------------------------- bool Link(int mapIndex, MapGenerator.Direction dir) { // the offset from the mapIndex to reach the other room int offset = GetOffsetDifference(mapIndex, dir); bool createdNewRoom = false; if (offset != 0) { // The index to the room we are linking to int linkRoomIndex = mapIndex + offset; Debug.Assert(linkRoomIndex >= 0 && linkRoomIndex < m_mapSize); // The room hasn't been created yet if (!m_roomGenMap.ContainsKey(linkRoomIndex)) { // If we've reached the maximum number of rooms allowed // we do NOT create any additional rooms if (maxRoomCount <= m_roomCount) { return(false); } // Create the room m_roomGenMap.Add(linkRoomIndex, new RoomGenerator(linkRoomIndex)); createdNewRoom = true; ++m_roomCount; } // Link the rooms Debug.Assert(m_roomGenMap.ContainsKey(mapIndex)); Debug.Assert(m_roomGenMap.ContainsKey(linkRoomIndex)); m_outlets.Add(new Outlet(m_roomGenMap[mapIndex], m_roomGenMap[linkRoomIndex], dir)); if (createdNewRoom) { // Outward Expand if (outwardExpand) { toExpand.Enqueue(m_roomGenMap[linkRoomIndex]); } // Linear Expand else { Expand(linkRoomIndex); } } } return(createdNewRoom); }
public void SetRoom(Outlet outlet, MapGenerator.Direction dir) { switch (dir) { case MapGenerator.Direction.Up: m_top = outlet; return; case MapGenerator.Direction.Down: m_bottom = outlet; return; case MapGenerator.Direction.Left: m_left = outlet; return; case MapGenerator.Direction.Right: m_right = outlet; return; } }
public static MapGenerator.Direction Opposite(MapGenerator.Direction dir) { switch (dir) { case MapGenerator.Direction.Up: return(MapGenerator.Direction.Down); case MapGenerator.Direction.Down: return(MapGenerator.Direction.Up); case MapGenerator.Direction.Left: return(MapGenerator.Direction.Right); case MapGenerator.Direction.Right: return(MapGenerator.Direction.Left); default: Debug.Assert(false); break; } // if we get the same direction we've reached an error return(dir); }