/// <summary>
    /// Вращение всех shape так, чтобы не пропали соединения с коннекторами. Также генерирует shape-ы, если у повернутого shape есть свободные выходы в соседние пустые ноды.
    /// </summary>
    private static void RandomSafeRotateWithGenerationAllShapes()
    {
        //количество подключенных коннекторов в начале этой функции
        int connectedConnectorsMaxCount = ConnectorsManager.GetConnectedCount();

        foreach (var node in NodesGrid.Grid)
        {
            if (node.Shape != null)
            {
                Direction currentDir = node.Shape.CurrentDirection;
                RandomRotateShape(node.Shape);

                int connectedCount = ConnectorsManager.GetConnectedCount();

                //возврат к состоянию до рэндомного вращения
                if (connectedCount < connectedConnectorsMaxCount)
                {
                    node.Shape.FastRotateToDirection(currentDir);
                }

                connectedConnectorsMaxCount = Mathf.Max(connectedConnectorsMaxCount, connectedCount);
            }

            //генерация ноды, если свободная клетка
            List <KeyValuePair <Node, Direction> > nodes = NodesGrid.FindAvailableNeighborNodesForShapeSides(node);
            foreach (var nodeDirPair in nodes)
            {
                GenerateRecursively(nodeDirPair.Key, nodeDirPair.Value.GetOpposite());
            }
        }
    }
    public static void Generate()
    {
        Instance.FillNodes();

        Direction sofaDir;
        int       xIndex, yIndex;
        Vector3   sofa_pos;

        Instance.CreateSofa(out sofa_pos, out sofaDir, out xIndex, out yIndex);
        Instance.CreateWindows(sofaDir);

        Vector3 plasmaPos;

        Instance.CreatePlasma(sofa_pos, sofaDir, out plasmaPos);
        Instance.CreatePlasmaConnector(plasmaPos, sofaDir);

        Instance.CreateStartConnector(sofaDir);

        Instance.CreateComp();
        Instance.CreatePhone();


        int chairCount  = Random.Range(1, 3);
        int coverCount  = Random.Range(2, 4);
        var chairPrefab = RandomUtils.GetRandomItem(Instance._chairPrefabs);
        var coverPrefab = RandomUtils.GetRandomItem(Instance._coversPrefabs);

        Instance.CreateCovers(chairCount, chairPrefab);
        Instance.CreateCovers(coverCount, coverPrefab);

        AstarPath.active.Scan();
        NodesGrid.UpdateNodesData();
        Instance.DebugEmptyNodes();
    }
Ejemplo n.º 3
0
    private static bool TraverseRecursively(Shape shape, List <ChainItem> chain)
    {
        _traversedShapes.Add(shape);
        bool chainItemHasConnector = false;

        ChainItem chainItem = new ChainItem();

        chainItem.Shape           = shape;
        chainItem.TargetDirection = shape.CurrentDirection;
        chain.Add(chainItem);

        var connector = FindConnectorWithConnection(shape);

        if (connector != null && shape.HasConnection(connector.CurrentDirection))
        {
            //Debug.LogWarning(connector.name);
            chainItemHasConnector = true;
            _unTraversedConnectors.Remove(connector);
        }

        var neighbors = NodesGrid.FindConnectedNeighborShapes(shape);

        bool hasFirstChain = false;

        foreach (var neighbor in neighbors)
        {
            if (!_traversedShapes.Contains(neighbor))
            {
                List <ChainItem> targetChain = chain;
                if (hasFirstChain)
                {
                    targetChain = chainItem.childChain;
                }

                bool nextChainItemHasConnector = TraverseRecursively(neighbor, targetChain);
                chainItemHasConnector |= nextChainItemHasConnector;
                hasFirstChain          = true;
            }
        }

        //если текущая нода не соединена с коннектором и дочерние ответвления тоже не соединены с коннектором, то удалить данный узел.
        if (!chainItemHasConnector)
        {
            //chainItem.Shape.name += "_RemovedChainItem";
            chain.Remove(chainItem);
        }

        return(chainItemHasConnector);
    }
Ejemplo n.º 4
0
        protected void DetailsGrid_CustomCallback(object sender, DevExpress.Web.ASPxGridViewCustomCallbackEventArgs e)
        {
            if (NodesGrid.FocusedRowIndex == null || NodesGrid.FocusedRowIndex == -1)
            {
                return;
            }

            string NodeName = NodesGrid.GetRowValues(NodesGrid.FocusedRowIndex, "Name").ToString();

            Div2.InnerHtml = NodeName + " - Services Status";
            DataTable dt = VSWebBL.SecurityBL.NodesBL.Ins.GetNodeServices(NodeName);

            Session["Servicesgrid"] = dt;
            servicesGrid.DataSource = dt;
            servicesGrid.DataBind();
        }
Ejemplo n.º 5
0
    // Update is called once per frame
    private void Update()
    {
        if (_path == null)
        {
            return;
        }

        if (PathIsTraversed())
        {
            _path = null;
            _currentWaypointIndex = 0;

            if (!_isClonedInCurrentShape)
            {
                _prevOutDirection = _currentShape.GetOutDirection(_prevOutDirection);//получение направления выхода из текущей shape
            }
            var prevShape = _currentShape;
            _currentShape = NodesGrid.GetNextShape(_currentShape, _prevOutDirection);
            if (prevShape != _currentShape)
            {
                TryAddShapeToList(_currentShape);
            }

            if (_currentShape == null || _currentShape.IsInRotateProcess || !_currentShape.HasConnection(_prevOutDirection))
            {
                DestroySelf();
                return;
            }

            _path = _currentShape.GetPath(_prevOutDirection);
            _isClonedInCurrentShape = false;
            _parentSignal           = null;
        }

        bool    isUpdated     = UpdateCurrentWaypoint();
        Vector3 moveDirection = GetMoveDirection(_currentWaypoint);

        if (isUpdated)
        {
            TryClone();
            CorrectMovement(moveDirection);
        }

        Rotate(_currentWaypoint);
        Move(_currentWaypoint, moveDirection);
    }
    private static void GenerateRecursively(Node node, Direction prevOutDirection)
    {
        if (!node.IsAvailable)
        {
            return;
        }

        CreateShape(node, typeof(TeeShape));
        FastRotateToConnection((TeeShape)node.Shape, prevOutDirection);

        //генерация ноды, если свободная клетка
        List <KeyValuePair <Node, Direction> > nodes = NodesGrid.FindAvailableNeighborNodesForShapeSides(node);

        foreach (var nodeDirPair in nodes)
        {
            GenerateRecursively(nodeDirPair.Key, nodeDirPair.Value.GetOpposite());
        }
    }
Ejemplo n.º 7
0
        protected void NodesGrid_SelectionChanged(object sender, EventArgs e)
        {
            if (NodesGrid.Selection.Count > 0)
            {
                int index = NodesGrid.FocusedRowIndex;

                if (index >= 0)
                {
                    string NodeName = NodesGrid.GetRowValues(index, "Name").ToString();
                    Div2.InnerHtml = NodeName + " - Services Status";

                    DataTable dt = VSWebBL.SecurityBL.NodesBL.Ins.GetNodeServices(NodeName);

                    servicesGrid.DataSource = dt;
                    servicesGrid.DataBind();
                }
            }
        }
    private static void FillEmptyNodes()
    {
        int needShapesCount = NodesGrid.GetNodesCountWithNotShapeObject();

        if (_shapesCount == needShapesCount)
        {
            return;
        }

        //if (shapesCount!=0)
        //    Debug.LogWarning("<color=green>FillEmptyNodes()</color> count=" + shapesCount);

        foreach (var node in NodesGrid.Grid)
        {
            if (node.IsAvailable)
            {
                CreateRandomShape(node);
            }
        }
    }
    private void CheckConnectRecursively(Shape shape)
    {
        _traversedShapes.Add(shape);

        var connector = FindConnectorWithConnection(shape);

        if (connector != null && shape.HasConnection(connector.CurrentDirection))
        {
            _unConnectedConnectors.Remove(connector);
        }

        var neighbors = NodesGrid.FindConnectedNeighborShapes(shape);

        foreach (var neighbor in neighbors)
        {
            if (!_traversedShapes.Contains(neighbor))
            {
                CheckConnectRecursively(neighbor);
            }
        }
    }
Ejemplo n.º 10
0
        public SpawnNode(NodesGrid.Node gridNode, int index)
        {
            Index = index;
            GridNode = gridNode;

            if (gridNode.Y == 0)
                MainDirection = Direction.Up;
            else if (gridNode.Y == 6)
                MainDirection = Direction.Down;
            else if (gridNode.X == 0)
                MainDirection = Direction.Right;
            else
                MainDirection = Direction.Left;

            if (gridNode.Y == 0 || gridNode.Y == 6)
            {
                if (gridNode.X == 0)
                    DirectionInCover = Direction.Right;
                else if (gridNode.X == 6)
                    DirectionInCover = Direction.Left;
            }
        }
Ejemplo n.º 11
0
        //protected void btn_Clickdelete(object sender, EventArgs e)
        //{
        //    ImageButton bttnDel = (ImageButton)sender;
        //    Nodes AssignnodesObject = new Nodes();
        //    AssignnodesObject.ID = Convert.ToInt32(bttnDel.CommandArgument);
        //    //ID = Convert.ToInt32(bttnDel.CommandArgument);
        //    string NodeName = bttnDel.AlternateText;
        //    pnlAreaDtls.Style.Add("visibility", "visible");
        //    //divmsg.InnerHtml = "Are you sure you want to delete the server " + NodeName + "?";

        //}


        //protected void GridView_CustomJSProperties(object sender, ASPxGridViewClientJSPropertiesEventArgs e)
        //{
        //    e.Properties["cpVisibleRowCount"] = AssignNodesGridView.VisibleRowCount;
        //}
        //protected void lnkSelectAllRows_Load(object sender, EventArgs e)
        //{
        //    ((ASPxHyperLink)sender).Visible = ComandColumn.SelectAllCheckboxMode != GridViewSelectAllCheckBoxMode.AllPages;
        //}
        //protected void lnkClearSelection_Load(object sender, EventArgs e)
        //{
        //    ((ASPxHyperLink)sender).Visible = ComandColumn.SelectAllCheckboxMode != GridViewSelectAllCheckBoxMode.AllPages;
        //}



        private void FillNodesGrid()
        {
            try
            {
                int row = NodesGrid.FocusedRowIndex;

                DataTable NodesGridData = VSWebBL.SecurityBL.NodesBL.Ins.GetAllNodeServicesDetails();

                NodesGrid.DataSource = NodesGridData;
                NodesGrid.DataBind();

                if (row < 0 && NodesGridData.Rows.Count > 0)
                {
                    row = 0;
                }
                NodesGrid.FocusedRowIndex = row;
            }
            catch (Exception ex)
            {
                Log.Entry.Ins.WriteHistoryEntry(DateTime.Now.ToString() + " Exception - " + ex);
                throw ex;
            }
            finally { }
        }