Ejemplo n.º 1
0
    public override void Init(int x, int y, int difficulty)
    {
        globalAddress = new Vector2Int(x, y);

        GlobalNodeInfo info = null;

        if (GameController.instance._globalNodesOverrides.ContainsKey(globalAddress))
        {
            info = GameController.instance._globalNodesOverrides[globalAddress];
        }

        if (info != null)
        {
            Init(info);
            return;
        }
        else
        {
            nodes = null;
        }

        width  = 2 + GMARandom.Range3D(difficulty, (1 + difficulty) * 2, x, y, 1);
        height = 2 + GMARandom.Range3D(difficulty, (1 + difficulty) * 2, x, y, 2);

        this.difficulty = difficulty;

        //width = 2;
        //height = 1;

        Debug.Log("Init " + x + " " + y + " " + difficulty + " " + width + " " + height);

        net   = new int[width, height];
        links = new Link[width, height];
        roles = new int[width, height];

        haveEntryPoint = false;
        shiftx         = GMARandom.Range2D(-1000000, 100000, x + y, (x + 1) * (y + 1));
        shifty         = GMARandom.Range2D(-1000000, 100000, x - y, x + y);
        //shiftx = -863620;
        //shifty = 52045;

        Debug.Log(x + " " + y + " " + shiftx + "  " + shifty);

        for (int i = 0; i < width; i++)
        {
            for (int j = 0; j < height; j++)
            {
                int nodeType = Node.GetType(i + shiftx, j + shifty);
                net[i, j] = nodeType;

                links[i, j]          = GetLink(nodeType, new Vector2(i, j));
                links[i, j].nodeType = nodeType;

                roles[i, j] = -1;
            }
        }

        for (int i = 0; i < width; i++)
        {
            net[i, 0] = Node.RemoveLink(net[i, 0], 2);
            links[i, 0].RemoveLink(2);

            //if ((net[i, 0] == 1 || net[i, 0] == 8 || net[i, 0] == 2) && !haveEntryPoint) //TODO entryPoint
            //{
            //    entryPoint.x = i;
            //    entryPoint.y = 0;
            //    haveEntryPoint = true;
            //}

            net[i, height - 1] = Node.RemoveLink(net[i, height - 1], 0);
            links[i, height - 1].RemoveLink(0);
        }

        for (int j = 0; j < height; j++)
        {
            net[0, j] = Node.RemoveLink(net[0, j], 3);
            links[0, j].RemoveLink(3);

            //if ((net[0, j] == 1 || net[0, j] == 2) && !haveEntryPoint)
            //{
            //    entryPoint.x = 0;
            //    entryPoint.y = j;
            //    haveEntryPoint = true;
            //}

            net[width - 1, j] = Node.RemoveLink(net[width - 1, j], 1);
            links[width - 1, j].RemoveLink(1);
        }

        FormNodesGroups();
        ConnectNearestPoints();
        NodesRedefinition();

        GetEndPoints();
        root = MakeTree();
        FormEndPointsGroups2();
    }
Ejemplo n.º 2
0
    public GlobalNodeInfo GenerateGNI(int x, int y, int difficulty)
    {
        GlobalNodeInfo info = new GlobalNodeInfo();

        info.info = new NetworkNodeInfo();
        info.info.globalAddress  = new Vector2Int(x, y);
        info.info.localAddress   = new Vector2Int(x, y);
        info.info.nodeDifficulty = difficulty;
        info.info.nodeRole       = 7;
        info.info.nodeType       = Node.GetType(x, y);

        width  = 2 + GMARandom.Range3D(difficulty, (1 + difficulty) * 2, x, y, 1);
        height = 2 + GMARandom.Range3D(difficulty, (1 + difficulty) * 2, x, y, 2);

        this.difficulty = difficulty;

        Debug.Log("Init " + x + " " + y + " " + difficulty + " " + width + " " + height);

        net   = new int[width, height];
        links = new Link[width, height];
        roles = new int[width, height];

        haveEntryPoint = false;
        shiftx         = GMARandom.Range2D(-1000000, 100000, x + y, (x + 1) * (y + 1));
        shifty         = GMARandom.Range2D(-1000000, 100000, x - y, x + y);
        //shiftx = -863620;
        //shifty = 52045;

        Debug.Log(x + " " + y + " " + shiftx + "  " + shifty);

        for (int i = 0; i < width; i++)
        {
            for (int j = 0; j < height; j++)
            {
                int nodeType = Node.GetType(i + shiftx, j + shifty);
                net[i, j] = nodeType;

                links[i, j]          = GetLink(nodeType, new Vector2(i, j));
                links[i, j].nodeType = nodeType;

                roles[i, j] = -1;
            }
        }

        for (int i = 0; i < width; i++)
        {
            net[i, 0] = Node.RemoveLink(net[i, 0], 2);
            links[i, 0].RemoveLink(2);

            //if ((net[i, 0] == 1 || net[i, 0] == 8 || net[i, 0] == 2) && !haveEntryPoint) //TODO entryPoint
            //{
            //    entryPoint.x = i;
            //    entryPoint.y = 0;
            //    haveEntryPoint = true;
            //}

            net[i, height - 1] = Node.RemoveLink(net[i, height - 1], 0);
            links[i, height - 1].RemoveLink(0);
        }

        for (int j = 0; j < height; j++)
        {
            net[0, j] = Node.RemoveLink(net[0, j], 3);
            links[0, j].RemoveLink(3);

            //if ((net[0, j] == 1 || net[0, j] == 2) && !haveEntryPoint)
            //{
            //    entryPoint.x = 0;
            //    entryPoint.y = j;
            //    haveEntryPoint = true;
            //}

            net[width - 1, j] = Node.RemoveLink(net[width - 1, j], 1);
            links[width - 1, j].RemoveLink(1);
        }

        FormNodesGroups();
        ConnectNearestPoints();
        NodesRedefinition();

        GetEndPoints();
        root = MakeTree();
        FormEndPointsGroups2();



        return(info);
    }
Ejemplo n.º 3
0
    public override NetworkNodeInfo GetNodeInfo(int x, int y)
    {
        //Debug.Log("Get node info " + x + " " + y + " " + nodes.GetLength(0) + " " + nodes.GetLength(1));

        NetworkNodeInfo info = new NetworkNodeInfo();

        if (nodes != null && x >= 0 && x < width && y >= 0 && y < height && nodes[x, y] != null)
        {
            info = nodes[x, y];

            if (info.nodeRole >= 0 && info.nodeRole < Library.instance.rolesSpr.Count)
            {
                info.sprite = Library.instance.rolesSpr[info.nodeRole];
            }

            return(info);
        }

        info.nodeType       = GetNodeType(x, y);
        info.nodeRole       = GetNodeRole(x, y);
        info.localAddress   = new Vector2Int(x, y);
        info.globalAddress  = GetGlobalAddress(info.localAddress);
        info.nodeDifficulty = GetNodeDifficulty(x, y);

        int appLevel = GMARandom.Range2D(info.nodeDifficulty * 10, (info.nodeDifficulty + 1) * 10, info.globalAddress.x, info.globalAddress.y);

        if (appLevel < 1)
        {
            appLevel = 1;
        }

        NetworkNodeInfo.AppSettings app = new NetworkNodeInfo.AppSettings();
        app.appName  = "LocalNode";
        app.appLevel = appLevel;
        info.apps.Add(app);

        int xx = info.globalAddress.x + x;
        int yy = info.globalAddress.y + y;

        appLevel = GMARandom.Range2D(appLevel - 1, appLevel + 2, xx, yy);
        if (appLevel == 0)
        {
            appLevel = 1;
        }


        if (info.nodeRole == 1)
        {
            app          = new NetworkNodeInfo.AppSettings();
            app.appName  = "SecurityModule";
            app.appLevel = appLevel;
            info.apps.Add(app);
        }
        else if (info.nodeRole == 4)
        {
            app          = new NetworkNodeInfo.AppSettings();
            app.appName  = "DataStorage";
            app.appLevel = appLevel;
            info.apps.Add(app);
        }
        else if (info.nodeRole == 5)
        {
            app          = new NetworkNodeInfo.AppSettings();
            app.appName  = "PersonalComputer";
            app.appLevel = appLevel;
            info.apps.Add(app);
        }

        if (info.nodeRole >= 0 && info.nodeRole < Library.instance.rolesSpr.Count)
        {
            info.sprite = Library.instance.rolesSpr[info.nodeRole];
        }

        return(info);
    }