public void Init(GlobalNodeInfo info) { Vector2Int minCoord = new Vector2Int(int.MaxValue, int.MaxValue); Vector2Int maxCoord = new Vector2Int(int.MinValue, int.MinValue); for (int i = 0; i < info.localNetwork.Count; i++) { for (int j = 0; j < info.localNetwork[i].list.Count; j++) { minCoord = Vector2Int.Min(minCoord, info.localNetwork[i].list[j].localAddress); maxCoord = Vector2Int.Max(maxCoord, info.localNetwork[i].list[j].localAddress); } } Debug.Log("Found " + minCoord + " " + maxCoord); difficulty = info.info.nodeDifficulty; globalAddress = info.info.globalAddress; int x = globalAddress.x; int y = globalAddress.y; width = maxCoord.x + 1; height = maxCoord.y + 1; net = new int[width, height]; roles = new int[width, height]; nodes = new NetworkNodeInfo[width, height]; for (int i = 0; i < width; i++) { for (int j = 0; j < height; j++) { int nodeType = 0; net[i, j] = nodeType; roles[i, j] = -1; } } for (int i = 0; i < info.localNetwork.Count; i++) { for (int j = 0; j < info.localNetwork[i].list.Count; j++) { var node = info.localNetwork[i].list[j]; net[node.localAddress.x, node.localAddress.y] = node.nodeType; roles[node.localAddress.x, node.localAddress.y] = node.nodeRole; nodes[node.localAddress.x, node.localAddress.y] = node; } } entryPoint = info.entryPoint; }
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); }
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(); }