Exemplo n.º 1
0
    public bool LoadNodeIntoSlots(GraphNode graphNode)
    {
        int nodeIndex       = -1;
        int nodeID          = GraphNode.NODE_ID_INVALID;
        int firstSlotRow    = -1;
        int firstSlotColumn = -1;
        int slotsWidth      = 0;
        int slotsHeight     = 0;
        int lastSlotRow     = -1;
        int lastSlotColumn  = -1;

        bool[] passages         = null;
        int    otherFirstRow    = -1;
        int    otherFirstColumn = -1;
        int    otherLastRow     = -1;
        int    otherLastColumn  = -1;

        int[] IDRow = null;

        if (graphNode == null)
        {
            return(false);
        }
        nodeID          = graphNode.ID;
        firstSlotRow    = graphNode.GetFirstSlotRow();
        firstSlotColumn = graphNode.GetFirstSlotColumn();
        slotsWidth      = graphNode.GetWidthInSlots();
        slotsHeight     = graphNode.GetHeightInSlots();
        if ((nodeID == GraphNode.NODE_ID_INVALID) || (slotsWidth < 1) || (slotsHeight < 1))
        {
            return(false);
        }
        lastSlotRow    = firstSlotRow + slotsHeight - 1;
        lastSlotColumn = firstSlotColumn + slotsWidth - 1;
        if ((firstSlotRow < 0) || (firstSlotColumn < 0) || (lastSlotRow >= mapSize) || (lastSlotColumn >= mapSize))
        {
            return(false);
        }

        /*halmeida - if the node has already been loaded into the map before, with different data, we remove it before adding it
         * again.*/
        nodeIndex = GetLoadedNodeIndex(nodeID);
        if (nodeIndex > -1)
        {
            if ((nodeFirstRows[nodeIndex] != firstSlotRow) || (nodeFirstColumns[nodeIndex] != firstSlotColumn) ||
                (nodeLastRows[nodeIndex] != lastSlotRow) || (nodeLastColumns[nodeIndex] != lastSlotColumn))
            {
                ClearLoadedNodeWithIndex(nodeIndex);
            }
            else
            {
                return(true);
            }
        }
        /*halmeida - check if the new node collides with the area of another.*/

        /*halmeida - following the same logic as the tiles within a structure, the row index of the slots grows as the
         * position gets lower. For that reason, the bottom of the area of a node is its last and lowest row, with the biggest
         * slot row index within the node.*/
        if (loadedNodeIDs != null)
        {
            for (int i = 0; i < loadedNodeIDs.Length; i++)
            {
                otherFirstRow    = nodeFirstRows[i];
                otherFirstColumn = nodeFirstColumns[i];
                otherLastRow     = nodeLastRows[i];
                otherLastColumn  = nodeLastColumns[i];
                if (UsefulFunctions.AreasCollideLimits(firstSlotColumn, lastSlotRow, lastSlotColumn, firstSlotRow, otherFirstColumn,
                                                       otherLastRow, otherLastColumn, otherFirstRow))
                {
                    Debug.Log("Debug : MenuMap : impossible to add node " + nodeID + ", collision detected with " + loadedNodeIDs[i] + ".");
                    return(false);
                }
            }
        }
        /*halmeida - get the passage presence data from the node.*/
        passages    = new bool[4];
        passages[0] = (graphNode.GetNodesUp() != null);
        passages[1] = (graphNode.GetNodesLeft() != null);
        passages[2] = (graphNode.GetNodesDown() != null);
        passages[3] = (graphNode.GetNodesRight() != null);
        /*halmeida - add the node into the designated slots.*/
        if (slotNodeIDs != null)
        {
            for (int i = firstSlotRow; i <= lastSlotRow; i++)
            {
                IDRow = slotNodeIDs[i];
                for (int j = firstSlotColumn; j <= lastSlotColumn; j++)
                {
                    IDRow[j] = nodeID;
                }
            }
        }
        UsefulFunctions.IncreaseArray <int>(ref loadedNodeIDs, nodeID);
        UsefulFunctions.IncreaseArray <int>(ref nodeFirstRows, firstSlotRow);
        UsefulFunctions.IncreaseArray <int>(ref nodeFirstColumns, firstSlotColumn);
        UsefulFunctions.IncreaseArray <int>(ref nodeLastRows, lastSlotRow);
        UsefulFunctions.IncreaseArray <int>(ref nodeLastColumns, lastSlotColumn);
        UsefulFunctions.IncreaseArray <bool[]>(ref nodePassages, passages);
        UsefulFunctions.IncreaseArray <GameObject>(ref nodeSlotObjects, null);
        UsefulFunctions.IncreaseArray <Image>(ref nodeSlotImages, null);
        UsefulFunctions.IncreaseArray <GameObject[]>(ref nodeWallObjects, null);
        UsefulFunctions.IncreaseArray <Image[]>(ref nodeWallImages, null);
        if (mapVisible)
        {
            CreateNodeVisual(loadedNodeIDs.Length - 1);
        }
        return(true);
    }
Exemplo n.º 2
0
    public bool LoadNodeIntoSlots(int nodeID, int firstSlotRow, int firstSlotColumn, int slotsWidth, int slotsHeight)
    {
        int lastSlotRow      = -1;
        int lastSlotColumn   = -1;
        int otherFirstRow    = -1;
        int otherFirstColumn = -1;
        int otherLastRow     = -1;
        int otherLastColumn  = -1;

        int[]          IDRow            = null;
        int            blockFirstRow    = -1;
        int            blockFirstColumn = -1;
        int            blockLastRow     = -1;
        int            blockLastColumn  = -1;
        int            blockerIndex     = -1;
        SpriteRenderer blockerRenderer  = null;
        Color          blockerColor     = Color.black;

        if ((nodeID == GraphNode.NODE_ID_INVALID) || (slotsWidth < 1) || (slotsHeight < 1))
        {
            return(false);
        }
        lastSlotRow    = firstSlotRow + slotsHeight - 1;
        lastSlotColumn = firstSlotColumn + slotsWidth - 1;
        if ((firstSlotRow < 0) || (firstSlotColumn < 0) || (lastSlotRow >= mapMatrixSize) || (lastSlotColumn >= mapMatrixSize))
        {
            return(false);
        }
        /*halmeida - check if the new node collides with the area of another.*/

        /*halmeida - following the same logic as the tiles within a structure, the row index of the slots grows as the
         * position gets lower. For that reason, the top of the area of a node is its last and lowest row, with the biggest
         * slot row index within the node.*/
        if (loadedNodeIDs != null)
        {
            for (int i = 0; i < loadedNodeIDs.Length; i++)
            {
                otherFirstRow    = nodeFirstRows[i];
                otherFirstColumn = nodeFirstColumns[i];
                otherLastRow     = nodeLastRows[i];
                otherLastColumn  = nodeLastColumns[i];
                if (UsefulFunctions.AreasCollideLimits(firstSlotColumn, lastSlotRow, lastSlotColumn, firstSlotRow, otherFirstColumn,
                                                       otherLastRow, otherLastColumn, otherFirstRow))
                {
                    Debug.Log("Debug : RoomSightBlocker : impossible to add node " + nodeID + ", collision detected with " + loadedNodeIDs[i] + ".");
                    return(false);
                }
            }
        }
        /*halmeida - add the node into the designated slots.*/
        UsefulFunctions.IncreaseArray <int>(ref loadedNodeIDs, nodeID);
        UsefulFunctions.IncreaseArray <int>(ref nodeFirstRows, firstSlotRow);
        UsefulFunctions.IncreaseArray <int>(ref nodeFirstColumns, firstSlotColumn);
        UsefulFunctions.IncreaseArray <int>(ref nodeLastRows, lastSlotRow);
        UsefulFunctions.IncreaseArray <int>(ref nodeLastColumns, lastSlotColumn);
        if (slotNodeIDs != null)
        {
            for (int i = firstSlotRow; i <= lastSlotRow; i++)
            {
                IDRow = slotNodeIDs[i];
                for (int j = firstSlotColumn; j <= lastSlotColumn; j++)
                {
                    IDRow[j] = nodeID;
                    if (BlockerExists(i, j, ref blockerIndex))
                    {
                        blockerFadings[blockerIndex] = true;
                    }
                }
            }
        }

        /*halmeida - add sight blockers to the surrounding slots. If a blocker is created where another
         * node's slot is already loaded, that blocker is made immediately invisible.*/
        blockFirstRow = firstSlotRow - surroundStripeSize;
        if (blockFirstRow < 0)
        {
            blockFirstRow = 0;
        }
        blockFirstColumn = firstSlotColumn - surroundStripeSize;
        if (blockFirstColumn < 0)
        {
            blockFirstColumn = 0;
        }
        blockLastRow = lastSlotRow + surroundStripeSize;
        if (blockLastRow > (mapMatrixSize - 1))
        {
            blockLastRow = mapMatrixSize - 1;
        }
        blockLastColumn = lastSlotColumn + surroundStripeSize;
        if (blockLastColumn > (mapMatrixSize - 1))
        {
            blockLastColumn = mapMatrixSize - 1;
        }
        UsefulFunctions.IncreaseArray <int>(ref nodeBlockerFirstRows, blockFirstRow);
        UsefulFunctions.IncreaseArray <int>(ref nodeBlockerFirstColumns, blockFirstColumn);
        UsefulFunctions.IncreaseArray <int>(ref nodeBlockerLastRows, blockLastRow);
        UsefulFunctions.IncreaseArray <int>(ref nodeBlockerLastColumns, blockLastColumn);
        if (slotNodeIDs != null)
        {
            for (int i = blockFirstRow; i <= blockLastRow; i++)
            {
                IDRow = slotNodeIDs[i];
                for (int j = blockFirstColumn; j <= blockLastColumn; j++)
                {
                    if (IDRow[j] != nodeID)
                    {
                        if (!BlockerExists(i, j, ref blockerIndex))
                        {
                            CreateBlocker(i, j);
                            if (blockerObjects != null)
                            {
                                blockerIndex = blockerObjects.Length - 1;
                            }
                        }
                        if (IDRow[j] != GraphNode.NODE_ID_INVALID)
                        {
                            if (!blockerFadings[blockerIndex])
                            {
                                blockerFadings[blockerIndex] = true;
                                blockerRenderer       = blockerRenderers[blockerIndex];
                                blockerColor          = blockerRenderer.color;
                                blockerColor.a        = 0f;
                                blockerRenderer.color = blockerColor;
                            }
                        }
                    }
                }
            }
        }
        return(true);
    }