Esempio n. 1
0
    public void DrawSubTree(RoomNode v, float p, float a1, float a2)
    {
        float s, a;
        //POLARKOORDINATEN
        Vector3 cartesian = Vector3.zero;
        Vector2 polar     = new Vector2(p, (a1 + a2) / 2f);

        cartesian.x = polar.x * Mathf.Cos(polar.y);
        cartesian.z = polar.x * Mathf.Sin(polar.y);
        v.Position  = cartesian;

        if (r(p) < (a2 - a1))
        {
            s = r(p) / w(v);
            a = (a1 + a2 - r(p)) / 2f;
        }
        else
        {
            s = (a2 - a1) / w(v);
            a = a1;
        }

        foreach (RoomNode u in v.Connections)
        {
            DrawSubTree(u, p + d, a, a + s * w(u));
            a = a + s * w(u);
        }
    }
Esempio n. 2
0
    public int w(RoomNode v)
    {
        int leafCount = FindActualLeaves(v);
        int leafID    = v.ID;

        return(leafCount);
    }
Esempio n. 3
0
 public FreeTreeVisualization(float d, int nodeAmount, RoomNode rootnode)
 {
     this.d             = d;
     this.nodeAmount    = nodeAmount;
     this.rootnode      = rootnode;
     this.modifiedNodes = new List <RoomNode> ();
 }
Esempio n. 4
0
    public void ApplyNewCenter(RoomNode center)
    {
        Queue <RoomNode> nodeQueue = new Queue <RoomNode> ();

        if (center.Parent != null)
        {
            center.AddConnection(center.Parent, false);
            center.Parent = null;
            nodeQueue.Enqueue(center);
        }

        while (nodeQueue.Count > 0)
        {
            RoomNode parent = nodeQueue.Dequeue();
            foreach (RoomNode child in parent.Connections)
            {
                if (child.Parent != parent)
                {
                    if (child.Parent != null)
                    {
                        child.AddConnection(child.Parent, false);
                        nodeQueue.Enqueue(child);
                    }
                    child.RemoveConnection(parent, false);
                    child.Parent = parent;
                }
            }
        }
    }
Esempio n. 5
0
 // Loads room and returns true if loading for first time
 private bool loadRoom(RoomNode roomNode)
 {
     if (!roomNode.hasBeenLoaded)
     {
         GameObject room = Instantiate(Resources.Load(roomNode.name), Vector3.zero, Quaternion.Euler(0.0f, 180.0f, 0.0f)) as GameObject;
         roomNode.obj = room;
         map.roomsActive.Add(roomNode);
         // Gather all of the room's respawn points
         GameObject[] respawns = GameObject.FindGameObjectsWithTag("Respawn");
         foreach (GameObject r in respawns)
         {
             if (r.transform.root == roomNode.obj.transform)
             {
                 roomNode.playerRespawns.Add(r);
             }
         }
         EnemySpawner[] es = room.GetComponentsInChildren <EnemySpawner>();
         for (int i = 0; i < es.Length; i++)
         {
             roomNode.enemySpawners.Add(es[i]);
         }
         roomNode.hasBeenLoaded = true;
         return(true);
     }
     else
     {
         roomNode.obj.SetActive(true);
         return(false);
     }
 }
Esempio n. 6
0
    // Creates a neighboring connection in the graph structure between the two given rooms
    public void connectRooms(RoomNode roomOne, RoomNode roomTwo, Direction roomOneExit)
    {
        switch (roomOneExit)
        {
        case Direction.NORTH:
            roomOne.north = roomTwo;
            roomTwo.south = roomOne;
            break;

        case Direction.SOUTH:
            roomOne.south = roomTwo;
            roomTwo.north = roomOne;
            break;

        case Direction.EAST:
            roomOne.east = roomTwo;
            roomTwo.west = roomOne;
            break;

        case Direction.WEST:
            roomOne.west = roomTwo;
            roomTwo.east = roomOne;
            break;

        default:
            Debug.Log("Error connecting rooms " + roomOne.name + " and " + roomTwo.name + ": no direction");
            break;
        }
    }
Esempio n. 7
0
    static RoomNode GetNearestInstantiatedRoom(RoomNode start)
    {
        LinkedList <RoomNode> roomsToCheck     = new LinkedList <RoomNode> ();
        LinkedList <RoomNode> nextRoomsToCheck = new LinkedList <RoomNode> ();

        roomsToCheck.AddFirst(start);
        int visitMarker = Random.Range(int.MinValue, int.MaxValue);

        while (roomsToCheck.Count > 0)
        {
            foreach (RoomNode room in roomsToCheck)
            {
                if (room.roomObject != null)
                {
                    return(room);
                }

                room.visited = visitMarker;
                foreach (RoomNode n in room.neighbors)
                {
                    if (n.visited != visitMarker)
                    {
                        nextRoomsToCheck.AddFirst(n);
                    }
                }
            }
            roomsToCheck     = nextRoomsToCheck;
            nextRoomsToCheck = new LinkedList <RoomNode> ();
        }
        return(null);
    }
Esempio n. 8
0
    public Stack <Vector3> GetVectorPath(Vector3 i_strt, Vector3 i_end)
    {
        if (IsGrathConacted() == false)
        {
            Debug.LogError("grath is not conacted");
        }
        Stack <Vector3> moveQ  = null;
        RoomNode        startR = convertV3toRoomNode(i_strt);
        RoomNode        endR   = convertV3toRoomNode(i_end);


        if (startR != null && endR != null && isRoomReachbol(endR) == true)
        {
            if (startR != endR)
            {
                BfsNode bfsNode = findSortPath(startR, endR);
                moveQ = getV3PathFromBfsNode(i_end, bfsNode);
            }
            else
            {
                moveQ = new Stack <Vector3>();
                moveQ.Push(i_end);
            }
        }
        else
        {
            moveQ = new Stack <Vector3>();
        }

        return(moveQ);
    }
Esempio n. 9
0
    public void GenerateEnemySpawnPointsForRoom(RoomNode room)
    {
        //room is the corner coords, roomObj is the actual room script

        Vector3 randCoords;
        float   distanceBetween = Vector2Int.Distance(room.BottomLeftCorner, room.TopRightCorner);
        int     enemiesToSpawn;

        //distance is used because we cant easily get the area with the corners, but the distance between
        //two points gives us a bit of information on how far apart these are
        //for now we're gonna spawn 1 enemy for every 10 units of distance, starting at 2
        if (distanceBetween <= 5)
        {
            enemiesToSpawn = 1;
        }
        else
        {
            int tens = (int)(distanceBetween / 10);
            enemiesToSpawn = tens + 1;
        }

        for (int i = 0; i < enemiesToSpawn; i++)
        {
            randCoords = new Vector3(
                Random.Range(room.BottomLeftCorner.x + roomPadding, room.BottomRightCorner.x - roomPadding),
                1,
                Random.Range(room.BottomLeftCorner.y + roomPadding, room.TopLeftCorner.y - roomPadding)
                );

            room.roomObjReference.enemySpawnPoints.Add(randCoords);
        }
    }
Esempio n. 10
0
    public LinkedList <RoomNode> ConnectTwoRooms(RoomNode roomA, RoomNode roomB, LinkedList <RoomNode> existing)
    {
        LinkedList <RoomNode> existingCopy = new LinkedList <RoomNode> ();

        Util.LLAppend <RoomNode> (existingCopy, existing);
        return(BuildCorridors(roomA, roomB, Vector3.zero, existingCopy));
    }
Esempio n. 11
0
    public void Initialize(RoomNode roomNode)
    {
        this.roomNode = roomNode;
        var collider = GetComponent <Collider2D>();

        if (!collider)
        {
            Debug.LogWarning($"Wall {name} doesn\'t have a collider!", this);
            attachPoint = orientation.ToOffset() * .5f;
        }
        else
        {
            RaycastHit2D hit;
            var          myPos  = (Vector2)transform.position;
            var          rayDir = -orientation.ToOffset();
            var          from   = myPos - (rayDir * 5f);
            if (collider.Raycast(from, rayDir, out hit, 10f))
            {
                attachPoint = transform.InverseTransformPoint(hit.point);
            }
            else
            {
                Debug.LogError($"{name} can't hit self with a raycast! Casting from {from}, in direction {rayDir}",
                               this);
                attachPoint = orientation.ToOffset() * .5f;
            }
        }
    }
Esempio n. 12
0
    //public static List<RoomNode> SortRoomByArea( List<RoomNode> rooms)
    //{
    //    return rooms.OrderBy();
    //}

    public void SetRoomContent(RoomType roomType, RoomNode room, Map map, System.Random seed, MapSetting mapSetting)
    {
        //SetDoors(doors, map);
        room.FindPath();
        switch (roomType)
        {
        case RoomType.Boss:
            SetBossRoom(room, map, seed);
            break;

        case RoomType.Loot:
            SetLootRoom(room, map, seed, mapsetting);
            break;

        case RoomType.Trap:
            SetTrapRoom(room, map, seed);
            break;

        case RoomType.Normal:
            SetNormalRoom(room, map, seed);
            break;

        //case RoomType.Cave:
        //    SetCaveRoom(room,map, mapsetting, seed);
        //    break;
        default:
            break;
        }
        SetRoomCorridors(room, map);
        foreach (Vector2Int door in room.DoorWays)
        {
            //Debug.Log(door);
        }
        //SetRoomBorder(room, map);
    }
Esempio n. 13
0
    /// <summary>
    /// 随机确定分割的边界位置
    /// </summary>
    /// <param name="bottomLeft"></param>
    /// <param name="topRight"></param>
    /// <param name="minRoomWidth"></param>
    /// <param name="minRoomHeight"></param>
    /// <returns></returns>
    private PartitionLine GetPartitionLine(RoomNode room, int minRoomWidth, int minRoomHeight, int lineWidth)
    {
        Direction direction;
        bool      ifDivideByWidth  = room.Width > (2 * minRoomWidth) + lineWidth * 2 - 1;
        bool      ifDivideByHeight = room.Height > (2 * minRoomHeight) + lineWidth * 2 - 1;

        if (ifDivideByHeight && ifDivideByWidth)
        {
            direction = (Direction)seed.Next(0, 2);
        }
        else if (ifDivideByWidth)
        {
            direction = Direction.Vertical;
        }
        else if (ifDivideByHeight)
        {
            direction = Direction.Horizontal;
        }
        else
        {
            return(null);
        }

        return(new PartitionLine(direction, GetPartitionCoordinates(direction, room.bottomLeft, room.topRight, minRoomWidth, minRoomHeight, lineWidth)));
    }
Esempio n. 14
0
    public void SliceRoom(int curIterationTimes, RoomNode curRoomToSlice, List <RoomNode> roomsToReturn, Queue <RoomNode> queue, int minRoomWidth, int minRoomHeight, int lineWidth, int corridorWidth)
    {
        PartitionLine line = GetPartitionLine(curRoomToSlice, minRoomWidth, minRoomHeight, lineWidth);
        RoomNode      left, right;

        borders.Add(line);
        if (line != null)
        {
            if (line.direction == Direction.Horizontal)
            {
                left  = new RoomNode(curRoomToSlice, new Vector2Int(curRoomToSlice.bottomLeft.x, line.coordinates.y + lineWidth), curRoomToSlice.topRight);
                right = new RoomNode(curRoomToSlice, curRoomToSlice.bottomLeft, new Vector2Int(curRoomToSlice.topRight.x, line.coordinates.y - lineWidth));
            }
            else /*if (line.direction == Direciton.Vertical)*/
            {
                left  = new RoomNode(curRoomToSlice, curRoomToSlice.bottomLeft, new Vector2Int(line.coordinates.x - lineWidth, curRoomToSlice.topRight.y) /*,curRoomToSlice.nodeIndex + 1*/);
                right = new RoomNode(curRoomToSlice, new Vector2Int(line.coordinates.x + lineWidth, curRoomToSlice.bottomLeft.y), curRoomToSlice.topRight /*, curRoomToSlice.nodeIndex + 2*/);
            }
            curRoomToSlice.leftChild  = left;
            curRoomToSlice.rightChild = right;
            AddRoomToCollections(left, queue, roomsToReturn);
            AddRoomToCollections(right, queue, roomsToReturn);
            ConnectNeighborRooms(left, right, line, corridorWidth, minRoomWidth, minRoomHeight, lineWidth);
        }
        else
        {
            leafNodes.Add(curRoomToSlice);
        }
        if (curIterationTimes == iterationTimes - 1)
        {
            leafNodes.AddRange(roomsToSlice);
        }
    }
    private void SplitTheSpace(RoomNode currentNode, List <RoomNode> listToReturn, int roomMinLength, int roomMinWidth, Queue <RoomNode> graph)
    {
        Line line = GetLineDividingSpace(currentNode.BottomLeftCorner, currentNode.TopRightCorner, roomMinWidth, roomMinLength);

        RoomNode node1, node2;

        if (line.Orientation == Orientation.Horizontal)
        {
            node1 = new RoomNode(currentNode.BottomLeftCorner,
                                 new Vector2Int(currentNode.TopRightCorner.x, line.Coordinates.y),
                                 currentNode, currentNode.TreeLayerIndex + 1);

            node2 = new RoomNode(new Vector2Int(currentNode.BottomLeftCorner.x, line.Coordinates.y),
                                 currentNode.TopRightCorner,
                                 currentNode, currentNode.TreeLayerIndex + 1);
        }
        else
        {
            node1 = new RoomNode(currentNode.BottomLeftCorner,
                                 new Vector2Int(line.Coordinates.x, currentNode.TopRightCorner.y),
                                 currentNode, currentNode.TreeLayerIndex + 1);

            node2 = new RoomNode(new Vector2Int(line.Coordinates.x, currentNode.BottomLeftCorner.y),
                                 currentNode.TopRightCorner,
                                 currentNode, currentNode.TreeLayerIndex + 1);
        }

        AddNewNodeToCollection(listToReturn, graph, node1);
        AddNewNodeToCollection(listToReturn, graph, node2);
    }
Esempio n. 16
0
    private void SetTraps(RoomNode room, Map map, System.Random seed, int tileType, MapSetting mapSetting, int floor)
    {
        List <Vector2Int> blockPoses = new List <Vector2Int>();

        for (int y = room.bottomLeft.y + 1; y < room.topRight.y; y++)
        {
            for (int x = room.bottomLeft.x + 1; x < room.topRight.x; x++)
            {
                if (map.mapMatrix[x, y] == floor)
                {
                    map.mapMatrix[x, y] = (seed.Next(0, 100) < mapsetting.trapPercentage) ? tileType : map.mapMatrix[x, y];
                }
                if (map.mapMatrix[x, y] == tileType)
                {
                    blockPoses.Add(new Vector2Int(x, y));
                }
            }
        }
        foreach (Vector2Int pos in blockPoses)
        {
            if (GetSurroundingTypeIn4(pos.x, pos.y, map, tileType) < 1)
            {
                map.mapMatrix[pos.x, pos.y] = floor;
            }
        }
    }
Esempio n. 17
0
    private void RemovePort(RoomNode _roomNode, Port _portToRemove, string _portDirection)
    {
        List <Edge> edgesToList;

        //identificamos los puertos que provengan de este room node & nos aseguramos de que este port proviene de este room node
        if (_portDirection == "out")
        {
            _roomNode.outputContainer.Remove(_portToRemove);
            edgesToList = edges.ToList().Where(x => x.output.portName == _portToRemove.portName && x.output.node == _portToRemove.node).ToList();

            if (edgesToList.Any())
            {
                Edge targetEdge = edgesToList.First();
                targetEdge.input.Disconnect(targetEdge);
                RemoveElement(edgesToList.First());
            }
        }
        else
        {
            _roomNode.inputContainer.Remove(_portToRemove);
            edgesToList = edges.ToList().Where(x => x.input.portName == _portToRemove.portName && x.input.node == _portToRemove.node).ToList();

            if (edgesToList.Any())
            {
                Edge targetEdge = edgesToList.First();
                targetEdge.output.Disconnect(targetEdge);
                RemoveElement(edgesToList.First());
            }
        }


        _roomNode.RefreshPorts();
        _roomNode.RefreshExpandedState();
    }
        protected void OnEndConnection(RoomNode roomNode, Event e)
        {
            if (connectionFrom == null)
            {
                return;
            }

            var from = connectionFrom;
            var to   = roomNode;

            // TODO: how to handle this properly?
            var connection = (Connection)CreateInstance(Data.ConnectionType);

            connection.From = connectionFrom.Data;
            connection.To   = roomNode.Data;

            if (from != to && !connectionNodes.Any(x => (x.From == @from && x.To == to) || (x.To == @from && x.From == to)))
            {
                Data.Connections.Add(connection);
                AssetDatabase.AddObjectToAsset(connection, Data);

                CreateConnection(connection, @from, to);
            }

            connectionFrom     = null;
            connectionProgress = null;
            GUI.changed        = true;
        }
    private void GenerateStairsOnNodes()
    {
        List <RoomNode> l_allNodesOnGraphWithOutputs = m_graphView.nodes.ToList().Where(x => x.outputContainer.Q <Port>() != null).Cast <RoomNode>().ToList();
        List <RoomNode> nodesAlreadyUsed             = new List <RoomNode>();
        int             numberOfNodes = l_allNodesOnGraphWithOutputs.Count();

        for (int i = 0; i < m_numberOfFloorsToGenerate; i++)
        {
            int      randomSelectionNode = Random.Range(0, numberOfNodes);
            RoomNode selectedNode        = l_allNodesOnGraphWithOutputs.ElementAt(randomSelectionNode);

            while (nodesAlreadyUsed.Contains(selectedNode))
            {
                randomSelectionNode = Random.Range(0, numberOfNodes);
                selectedNode        = l_allNodesOnGraphWithOutputs.ElementAt(randomSelectionNode);
            }

            nodesAlreadyUsed.Add(selectedNode);

            List <Port> l_portsConnectedToSelectedNode = m_graphView.ports.ToList().Where(x => x.node == selectedNode && x.direction == Direction.Output).ToList();


            int  randomSelectionPort = Random.Range(0, l_portsConnectedToSelectedNode.Count());
            Port selectedPort        = l_portsConnectedToSelectedNode.ElementAt(randomSelectionPort);

            Edge conectorEdge = m_edgesList.Find(x => x.output == selectedPort);
            conectorEdge.output.portName += " stairs";
        }
    }
    int GetManhattenDistance(RoomNode _nodeA, RoomNode _nodeB)
    {
        int x = Mathf.Abs(_nodeA.gridX - _nodeB.gridX);
        int y = Mathf.Abs(_nodeA.gridY - _nodeB.gridY);

        return(x + y);
    }
Esempio n. 21
0
    private void PositionNode(RoomNode pNode, int pDepth)
    {
        // Position each node in the graph...
        for (int i = 0; i < pNode.Children.Count; i++)
        {
            // r = whether this child is on the right of the parent
            PositionNode(pNode.Children[i], pDepth + 1);
        }

        layoutCounter++;

        float x = layoutCounter * displayOffset.x;
        float y = pDepth * displayOffset.y;

        pNode.Object.transform.localPosition = new Vector2(x, y);

        foreach (EdgeNode e in pNode.Edges)
        {
            // Ignore connections with no specified edge node.
            if (e != null)
            {
                e.Object.transform.position = (e.Parent.Object.transform.position + e.Child.Object.transform.position) / 2;
                e.Object.transform.parent   = e.Parent.Object.transform;
            }
        }

        avgPos += (Vector2)pNode.Object.transform.position;
    }
        /// <summary>
        /// Creates a connection between the two given room nodes.
        /// </summary>
        /// <param name="from"></param>
        /// <param name="to"></param>
        /// <returns></returns>
        public ConnectionBase CreateConnection(RoomNode from, RoomNode to)
        {
            // Do not create the connection if the from room is same as the to room
            if (from.Room == to.Room)
            {
                return(null);
            }

            // Do not create the connection if it already exists
            if (connectionNodes.Any(x => (x.From == from && x.To == to) || (x.To == from && x.From == to)))
            {
                return(null);
            }

            var type           = FindType(LevelGraph.RoomType);
            var connectionType = type != null ? LevelGraph.ConnectionType : typeof(Connection).FullName;
            var connection     = (ConnectionBase)CreateInstance(connectionType);

            connection.From = from.Room;
            connection.To   = to.Room;

            LevelGraph.Connections.Add(connection);
            AssetDatabase.AddObjectToAsset(connection, LevelGraph);

            CreateConnectionNode(connection);

            EditorUtility.SetDirty(LevelGraph);

            return(connection);
        }
Esempio n. 23
0
    private void CreateSideRooms(RoomNode node, int roomSupply)
    {
        int availableDoors = Mathf.Max(0, maxDoors - node.DoorCount);

        //There's nothing to do if no doors can be created
        //This will prevent endless loops since the roomSupply eventually drains
        //Prevent, that more doors are created than roomsCounts defines
        if (availableDoors == 0 || roomSupply <= 0 || nodesCreated >= roomsCount)
        {
            return;
        }
        //At least one door should be placed, else return
        int min = 1;
        //Only create as much doors as there are available
        //Don't create more doors than the supply offers
        int max = Mathf.Min(roomSupply, availableDoors);
        //The amount of rooms to be created
        //Since Range's max is exclusive I have to add 1 in order to make it inclusive
        int roomsCreated    = Random.Range(min, max + 1);
        int remainingSupply = roomSupply - roomsCreated;
        //Prevent possible division by zero.
        int supplyPerNode = (remainingSupply > 0) ? (int)Mathf.Ceil(remainingSupply / (float)roomsCreated) : 0;

        //Create new graph nodes, recursively call this function again with the remainingSupply
        for (int i = 0; i < roomsCreated; i++)
        {
            RoomNode newNode = new RoomNode(false, NodeType.SIDE);
            node.AddConnection(newNode);
            int newNodeSupply = (supplyPerNode > remainingSupply) ? Mathf.Max(0, remainingSupply) : supplyPerNode;
            CreateSideRooms(newNode, newNodeSupply);
            nodesCreated++;
        }
    }
        /// <summary>
        /// Shows the room context menu.
        /// </summary>
        /// <param name="roomNode"></param>
        private void ShowRoomContextMenu(RoomNode roomNode)
        {
            var genericMenu = new GenericMenu();

            genericMenu.AddItem(new GUIContent("Delete room"), false, () => DeleteRoomNode(roomNode));
            genericMenu.ShowAsContext();
        }
Esempio n. 25
0
    void ConnectRooms()
    {
        LinkedList <RoomNode> newCorridors  = new LinkedList <RoomNode> ();
        LinkedList <RoomNode> existingRooms = new LinkedList <RoomNode> ();

        Util.LLAppend <RoomNode> (existingRooms, roomNodeList);
        foreach (RoomNode roomA in roomNodeList)
        {
            foreach (RoomNode roomB in roomNodeList)
            {
                if (roomA != roomB && !roomA.connections.Contains(roomB))
                {
                    Vector3 touchDir = RoomNode.CheckRoomTouch(roomA.octTreeNode.boundary, roomB.octTreeNode.boundary);
                    if (touchDir != Vector3.zero && ((Random.Range(0, 100) < 50) || !roomA.ConnectsTo(roomB)))
                    {
                        RoomNode.MakeConnections(roomA, roomB);
                        foreach (RoomNode c in ConnectTwoRooms(roomA, roomB, existingRooms))
                        {
                            newCorridors.AddFirst(c);
                            existingRooms.AddFirst(c);
                        }
                    }
                }
            }
        }

        foreach (RoomNode c in newCorridors)
        {
            roomNodeList.AddFirst(c);
        }
    }
Esempio n. 26
0
 public void Reset()
 {
     gCost           = 0f;
     hCost           = 0f;
     parentLinkIndex = 0;
     parentNode      = null;
 }
Esempio n. 27
0
 public ConfigurationGrid2D(RoomTemplateInstanceGrid2D shape, Vector2Int position, TEnergyData energyData, RoomNode <TNode> node)
 {
     RoomShape  = shape;
     Position   = position;
     EnergyData = energyData;
     Room       = node;
 }
Esempio n. 28
0
    public Port GenerateInputPortsOnNode(RoomNode _roomNode, string _overridedName = "")
    {
        Port l_generatedPort = GeneratePort(_roomNode, Direction.Input, Port.Capacity.Single);

        string portName;

        portName = string.IsNullOrEmpty(_overridedName) ? "Input" : _overridedName;//si no ponemos nombre, que se muestre el por defecto

        //generamos el campo de texto donde pondremos el nombre de la conexion
        TextField portText = new TextField();

        portText.value = portName;                                                             //asignamos el valor del puerto a la nueva string
        portText.RegisterValueChangedCallback(evt => l_generatedPort.portName = evt.newValue); //capturamos el evento de cambiar el nombre en el textField y le asignamos ese nombre al puertoGenerado
        l_generatedPort.contentContainer.Add(portText);
        l_generatedPort.portName = portName;

        //boton para borrar el puerto
        Button deleteInputPortButton = new Button();

        deleteInputPortButton.text = "-";
        deleteInputPortButton.clickable.clicked += () => RemovePort(_roomNode, l_generatedPort, "input");
        l_generatedPort.contentContainer.Add(deleteInputPortButton);

        _roomNode.inputContainer.Add(l_generatedPort);
        _roomNode.RefreshPorts();
        _roomNode.RefreshExpandedState();

        return(l_generatedPort);
    }
Esempio n. 29
0
    void PopulateRooms(RoomNode startNode)
    {
        RoomNode bossRoom = startNode;

        foreach (var room in roomTree)
        {
            if (room.numChildren == 0)
            {
                if (room.distanceFromStart > bossRoom.distanceFromStart)
                {
                    bossRoom = room;
                }
            }
        }
        roomLayout bossroomLayout = Instantiate(bossLayout, bossRoom.position, Quaternion.identity);

        bossRoom.roomManager.enemies = bossroomLayout.enemies;
        foreach (var room in roomTree)
        {
            if (room != startNode && room != bossRoom)
            {
                roomLayout layout = Instantiate(layouts[Random.Range(0, layouts.Count)], room.roomManager.transform);
                room.roomManager.enemies = layout.enemies;
                room.roomManager.turrets = layout.turrets;
            }
        }
    }
Esempio n. 30
0
    private void GenerateLevel(RoomNode node, RoomTransformation prevChunk)
    {
        //Place the Chunk somewhere, where it won't collide with another chunk
        GameObject chunk = InstantiateChunk(node, new Vector3(tmpChunkPos, 0f, tmpChunkStep));

        if (isConstraintError)
        {
            return;
        }

        tmpChunkPos += tmpChunkStep;
        //Obtain the actual position, the chunk will have later on
        Vector3            chunkSize     = ChunkSize(chunk);
        RoomTransformation roomTransform = new RoomTransformation(chunk, node.Position, chunkSize, spacing);

        roomTransform.AddConnection(prevChunk);
        positionMeta.Add(roomTransform);
        debugData.AddRoomMeta(chunk, node);

        if (prevChunk != null)
        {
            HallwayMeta hallway = prevChunk.FindMatchingDoors(roomTransform);
            hallwayMeta.Add(hallway);
        }

        //Recursively generate subrooms
        foreach (RoomNode subNode in node.Connections)
        {
            GenerateLevel(subNode, roomTransform);
        }
    }
Esempio n. 31
0
 private Graph()
 {
     for(int y = 0 ;y < c_y ;++y)
     {
         for(int x = 0;x < c_x;++x)
         {
             m_rooms[y, x] = new RoomNode(x ,y);
         }
     }
 }
Esempio n. 32
0
    public static GameObject BuildRoom(RoomNode room, RoomStyle roomStyle)
    {
        GameObject boxObj = new GameObject(room.name);

        for(int i = 0; i < 6; i ++)
        {
            Vector3 dir = Util.VecDenum(i);

            Bounds wallBounds = new Bounds(room.roomBounds.center + Vector3.Scale(room.roomBounds.extents, dir),
                Vector3.Scale(room.roomBounds.size, Util.LNot(dir)));

            int holeCount = 0;
            Bounds[] tempDoorSet = new Bounds[room.neighbors.Count];
            foreach(RoomNode neighbor in room.neighbors)
            {
                //if(wallBounds.Intersects(neighbor.roomBounds))
                if(RoomNode.CheckOverlap(wallBounds, neighbor.roomBounds, -1))
                {
                    Bounds b = RoomNode.OverlapBounds(room.roomBounds, neighbor.roomBounds);
                    b.extents += Util.VecAbs(dir);
                    tempDoorSet[holeCount] = b;
                    holeCount ++;
                }
            }

            Bounds[] doorSet = new Bounds[holeCount];
            for(int k = 0; k < holeCount; k++)
            {
                doorSet[k] = tempDoorSet[k];
            }

            Mesh wallMesh = BuildWall(wallBounds, doorSet, dir * -1);
            if(wallMesh != null)
            {
                TangentSolver.Solve(wallMesh);
                GameObject wallObj = new GameObject("Wall", typeof(MeshRenderer), typeof(MeshFilter), typeof(MeshCollider));
                wallObj.GetComponent<MeshFilter>().mesh = wallMesh;
                wallObj.transform.parent = boxObj.transform;
                wallObj.transform.localPosition = Vector3.Scale(room.roomBounds.extents, dir);
                wallObj.renderer.material = roomStyle.materials[i];
                wallObj.GetComponent<MeshCollider>().sharedMesh = wallMesh;
            }
        }

        return boxObj;
    }
Esempio n. 33
0
    public void GenerateRooms(OctTree tree)
    {
        if (tree.GetChildCount () != 0) {
                        foreach (OctTree subTree in tree.children) {
                                if (subTree != null) {
                                        GenerateRooms (subTree);
                                }
                        }
                } else {
                        RoomNode newRoom = new RoomNode (tree.boundary);
                        newRoom.roomBounds.extents -= Vector3.one * minSeparation;
                        newRoom.RandomizeBounds (Vector3.one, minRoomSize, maxRoomSize);
                        newRoom.QuantizeBounds (corridorSize);
                        /*Vector3 center, extents;

                        extents.x = Mathf.Floor (Random.Range (minRoomSize / 2, tree.boundary.extents.x));
                        extents.y = Mathf.Floor (Random.Range (minRoomSize / 2, tree.boundary.extents.y));
                        extents.z = Mathf.Floor (Random.Range (minRoomSize / 2, tree.boundary.extents.z));

                        center = tree.boundary.center;
                        center.x = Mathf.Round (center.x + Random.Range (extents.x - tree.boundary.extents.x, tree.boundary.extents.x - extents.x));
                        center.y = Mathf.Round (center.y + Random.Range (extents.y - tree.boundary.extents.y, tree.boundary.extents.y - extents.y));
                        center.z = Mathf.Round (center.z + Random.Range (extents.z - tree.boundary.extents.z, tree.boundary.extents.z - extents.z));

                        newRoom.roomBounds.center = center;
                        newRoom.roomBounds.extents = extents;*/

                        newRoom.octTreeNode = tree;
                        roomNodeList.AddFirst (newRoom);
                        tree.roomNode = newRoom;
                }
    }
Esempio n. 34
0
 public static void MakeConnections(RoomNode a, RoomNode b)
 {
     a.connections.AddFirst(b);
     b.connections.AddFirst(a);
 }
Esempio n. 35
0
 public bool ConnectsTo(RoomNode dest, int visitKey)
 {
     if(dest == this) return true;
     visited = visitKey;
     foreach(RoomNode neighbor in neighbors)
     {
         if(neighbor.visited != visitKey)
         {
             if(neighbor.ConnectsTo(dest, visitKey)) return true;
         }
     }
     return false;
 }
Esempio n. 36
0
 private void ConactNaibers(RoomNode i_badRoom)
 {
     foreach(RoomNode room in i_badRoom.m_niebringRooms)
     {
         if(room.m_eColor == eColor.White)
         {
             ConactMe(room.myPosition, i_badRoom.myPosition);
             break;
         }
     }
 }
Esempio n. 37
0
 public static void MakeNeighbors(RoomNode a, RoomNode b)
 {
     a.neighbors.AddFirst(b);
     b.neighbors.AddFirst(a);
 }
Esempio n. 38
0
    private bool isRoomReachbol(RoomNode i_room)
    {
        bool res = false;

        foreach( RoomNode room in i_room.m_niebringRooms)
        {
            if(isRoomVisabol(room) == true )
            {
                res = true;
                break;
            }
        }
        return res;
    }
Esempio n. 39
0
    private BfsNode findSortPath(RoomNode i_start , RoomNode i_end)
    {
        Queue<BfsNode> queue = new Queue<BfsNode>();
        List<Vector2> arcivs = new List<Vector2>();
        queue.Enqueue(new BfsNode(i_start.myPosition, null, 0));
        BfsNode solver = null;

        while (solver == null && queue.Count != 0)
        {
            BfsNode node = queue.Dequeue();
            if (m_rooms[(int)node.mySpot.y, (int)node.mySpot.x].m_niebringRooms == null) continue;
            foreach (RoomNode room in m_rooms[(int)node.mySpot.y, (int)node.mySpot.x].m_niebringRooms)
            {
                if (isRoomVisabol(room) != true) continue;
                BfsNode bfsNode = new BfsNode(room.myPosition, node, node.depth + 1);
                if (room == i_end)
                {
                    solver = bfsNode;
                    break;
                }
                if (arcivs.Contains(bfsNode.mySpot) == false)
                {
                    arcivs.Add(bfsNode.mySpot);
                    queue.Enqueue(bfsNode);
                }
            }
        }
        return solver;
    }
Esempio n. 40
0
 private bool isRoomVisabol(RoomNode i_room)
 {
     return i_room.refRoom.GetComponent<Renderer>().enabled;
 }
Esempio n. 41
0
 private void Visit(RoomNode i_room)
 {
     i_room.m_eColor = eColor.Grey;
     if (i_room.m_niebringRooms != null)
     {
         foreach (RoomNode room in i_room.m_niebringRooms)
         {
             if (room.m_eColor == eColor.White)
             {
                 Visit(room);
             }
         }
     }
     i_room.m_eColor = eColor.Black;
 }
Esempio n. 42
0
 public LinkedList<RoomNode> ConnectTwoRooms(RoomNode roomA, RoomNode roomB, LinkedList<RoomNode> existing)
 {
     LinkedList<RoomNode> existingCopy = new LinkedList<RoomNode> ();
             Util.LLAppend<RoomNode> (existingCopy, existing);
             return BuildCorridors (roomA, roomB, Vector3.zero, existingCopy);
 }
Esempio n. 43
0
 public bool ConnectsTo(RoomNode dest)
 {
     return ConnectsTo(dest, Random.Range(int.MinValue, int.MaxValue));
 }
Esempio n. 44
0
    //Returns a list of newly created rooms
    public LinkedList<RoomNode> BuildCorridors(RoomNode roomA, RoomNode roomB, Vector3 lastDir, LinkedList<RoomNode> existingRooms)
    {
        if (lastDir == Vector3.zero)
                        Debug.Log ("Attempting to build new corridor");
                if (roomA == roomB)
                        return new LinkedList<RoomNode> ();
                int attempts = 8;
                while (attempts > 0) {
                        Vector3 overlapAxes = RoomNode.OverlapAxes (roomA.roomBounds, roomB.roomBounds);
                        int numOverlaps = Util.VecNonZeroes (overlapAxes);
                        int selectedAxis = Random.Range (0, 3);
                        if (overlapAxes == Vector3.one)
                                return new LinkedList<RoomNode> ();
                        while (overlapAxes[selectedAxis] != 0)
                                selectedAxis = Random.Range (0, 3);
                        Vector3 corridorDir = Vector3.zero;
                        corridorDir [selectedAxis] = Mathf.Sign (roomB.roomBounds.center [selectedAxis] - roomA.roomBounds.center [selectedAxis]);
                        //Debug.Log ("Connect " + numOverlaps);
                        if (numOverlaps == 2) {
                                LinkedList<RoomNode> result = new LinkedList<RoomNode> ();
                                Bounds b = RoomNode.OverlapBounds (roomA.roomBounds, roomB.roomBounds);
                                RoomNode r = new RoomNode (b);
                                Vector3 randomAxes = Vector3.one;
                                randomAxes [selectedAxis] = 0;
                                if (lastDir != Vector3.zero) {
                                        r.ShoveToEdge (lastDir, Vector3.one * 0.5f * corridorSize);
                                } else
                                        r.RandomizeBounds (randomAxes, corridorSize * Vector3.one, corridorSize * Vector3.one);
                                int limit = 12;
                                while (GetOverlapped(r.roomBounds, existingRooms,corridorDir) != null && limit > 0) {
                                        r.roomBounds = b;
                                        r.RandomizeBounds (randomAxes, corridorSize * Vector3.one, corridorSize * Vector3.one);
                                        limit --;
                                }
                                if (limit == 0) {
                                        //Debug.Log ("OH GOD DAMMIT " + r.roomBounds.ToString ());
                                        //Instantiate (indicatorPrefab, r.roomBounds.center, Quaternion.identity);
                                } else {
                                        r.isCorridor = true;
                                        RoomNode.MakeNeighbors (roomA, r);
                                        RoomNode.MakeNeighbors (r, roomB);
                                        r.name = numOverlaps.ToString ();
                                        result.AddFirst (r);

                                        return result;
                                }
                        } else if (numOverlaps < 2) {
                                Bounds b = RoomNode.OverlapBounds (roomA.roomBounds, roomB.roomBounds);
                                int selectedOther = Random.Range (0, 3);
                                while (selectedOther == selectedAxis || overlapAxes[selectedOther] != 0) {
                                        selectedOther = Random.Range (0, 3);
                                }
                                Vector3 newCenter;
                                Vector3 newExtents;
                                newCenter = b.center;
                                newExtents = b.extents;
                                if (numOverlaps == 1) {
                                        newCenter [selectedOther] = roomA.roomBounds.center [selectedOther];
                                        newExtents [selectedOther] = roomA.roomBounds.extents [selectedOther];
                                } else if (numOverlaps == 0) {
                                        Debug.Log ("Connecting Zero");
                                        newCenter = roomA.roomBounds.center;
                                        newExtents = roomA.roomBounds.extents;
                                        newCenter [selectedAxis] = b.center [selectedAxis];
                                        newExtents [selectedAxis] = b.extents [selectedAxis];
                                }
                                float sign = Mathf.Sign (newCenter [selectedAxis] - roomA.roomBounds.center [selectedAxis]);
                                float extension = Random.Range (corridorSize, roomB.roomBounds.extents [selectedAxis]);
                                newCenter [selectedAxis] += extension * sign;
                                newExtents [selectedAxis] += extension;
                                b.center = newCenter;
                                b.extents = newExtents;
                                RoomNode r = new RoomNode (b);
                                Vector3 randomAxes = Vector3.one;
                                randomAxes [selectedAxis] = 0;
                                if (lastDir != Vector3.zero) {
                                        r.ShoveToEdge (lastDir, Vector3.one * 0.5f * corridorSize);
                                } else
                                        r.RandomizeBounds (randomAxes, corridorSize * Vector3.one, corridorSize * Vector3.one);
                                int limit = 12;
                                while (GetOverlapped(r.roomBounds, existingRooms,corridorDir) != null && limit > 0) {
                                        b = RoomNode.OverlapBounds (roomA.roomBounds, roomB.roomBounds);
                                        newCenter = b.center;
                                        newExtents = b.extents;
                                        if (numOverlaps == 1) {
                                                newCenter [selectedOther] = roomA.roomBounds.center [selectedOther];
                                                newExtents [selectedOther] = roomA.roomBounds.extents [selectedOther];
                                        } else if (numOverlaps == 0) {
                                                newCenter = roomA.roomBounds.center;
                                                newExtents = roomA.roomBounds.extents;
                                                newCenter [selectedAxis] = b.center [selectedAxis];
                                                newExtents [selectedAxis] = b.extents [selectedAxis];
                                        }

                                        extension = Random.Range (corridorSize, roomB.roomBounds.extents [selectedAxis]);
                                        newCenter [selectedAxis] += extension * sign;
                                        newExtents [selectedAxis] += extension;
                                        b.center = newCenter;
                                        b.extents = newExtents;
                                        r.roomBounds = b;
                                        r.RandomizeBounds (randomAxes, corridorSize * Vector3.one, corridorSize * Vector3.one);
                                        limit --;
                                }
                                if (limit == 0) {
                                        //Debug.Log ("Aw f**k");

                                } else {
                                        LinkedList<RoomNode> result = BuildCorridors (r, roomB, corridorDir, existingRooms);
                                        if (result.Count != 0) {
                                                r.isCorridor = true;
                                                RoomNode.MakeNeighbors (roomA, r);
                                                r.name = numOverlaps.ToString ();
                                                result.AddFirst (r);
                                                return result;
                                        }
                                }
                        }
                        attempts--;
                }

                if (lastDir == Vector3.zero)
                        Debug.Log ("Couldn't Connect");
                return new LinkedList<RoomNode> ();
    }
Esempio n. 45
0
    static RoomNode GetNearestInstantiatedRoom(RoomNode start)
    {
        LinkedList<RoomNode> roomsToCheck = new LinkedList<RoomNode> ();
                LinkedList<RoomNode> nextRoomsToCheck = new LinkedList<RoomNode> ();
                roomsToCheck.AddFirst (start);
                int visitMarker = Random.Range (int.MinValue, int.MaxValue);
                while (roomsToCheck.Count > 0) {
                        foreach (RoomNode room in roomsToCheck) {
                                if (room.roomObject != null)
                                        return room;

                                room.visited = visitMarker;
                                foreach (RoomNode n in room.neighbors)
                                        if (n.visited != visitMarker)
                                                nextRoomsToCheck.AddFirst (n);
                        }
                        roomsToCheck = nextRoomsToCheck;
                        nextRoomsToCheck = new LinkedList<RoomNode> ();
                }
                return null;
    }
Esempio n. 46
0
 public void removNiber(RoomNode i_badNiber)
 {
     m_niebringRooms.Remove(i_badNiber);
 }