public IEnumerator Create(Message message, bool infected) { creating = true; creatingMessage = message; yield return(StartCoroutine(Parse())); // Check if vandal tags detected. if (creating == false) { SpawnBoss(message); yield break; } if (scrMaster.Instance.Transitioning) { if (infected) { infectedBufferQueue.Enqueue(message); } else { scrGUI.Instance.AddToFeed(message.page_title, new Color(0.1f, 0.1f, 0.1f)); } creating = false; yield break; } if (freePositionsCount == 0) { // Debug.Log("There are no free positions left to create a node for \"" + message.page_title + "\"."); creating = false; if (!infected) { yield break; } } // Don't create a node if there are no nodes available. if (inactiveNodeCount == 0) { // Debug.Log("There are no inactive nodes left to create a node for \"" + message.page_title + "\"."); creating = false; if (!infected) { yield break; } } // Don't create a node if there are no cubes available. if (inactiveCubeCount == 0) { // Debug.Log("There are no inactive cubes left to create a node for \"" + message.page_title + "\"."); creating = false; if (!infected) { yield break; } } // Set the size of the core based on the change_size of the message. int coreSize = Mathf.Clamp(Mathf.CeilToInt(Mathf.Log10(Mathf.Abs(message.change_size) + 1)), scrNode.CORE_SIZE_MIN, scrNode.CORE_SIZE_MAX); // Get the number of cubes there would be around this core. int numCubes = scrNode.CubePositions[coreSize - 1].Length; // Don't create a node if there aren't enough cubes available. if (inactiveCubeCount < numCubes) { Debug.Log("There are not enough inactive cubes (" + inactiveCubeCount + "/" + numCubes + ") in the pool to create a node for \"" + message.page_title + "\"."); creating = false; if (!infected) { yield break; } } // If not creating but got this far, node is infected and must replace an existing one, if (creating == false) { creating = true; // Loop through the active nodes until one is found that is completely out of the player's view. LinkedListNode <GameObject> n = nodePool.Last; for (int i = 0; i < TOTAL_NODES - inactiveNodeCount; ++i) { scrNode nScript = n.Value.GetComponent <scrNode>(); // Don't replace nodes in view, fully infected nodes, the node being uploaded, or nodes that arent being infected. if (!(nScript.VisibleToPlayer || nScript.FullyInfected || !nScript.Infected || NodeBeingUploaded != null && n.Value == NodeBeingUploaded.gameObject)) { // Convert the node. nScript.ConvertToInfected(message); break; } // Move back one node. n = n.Previous; yield return(new WaitForEndOfFrame()); } scrGUI.Instance.AddToFeed(message.page_title, ColCoreInfected); yield return(new WaitForSeconds(3.0f)); // 3 Second delay between node creation. creating = false; yield break; } // All checks have passed - a node can be made. Get the first inactive node in the node pool. LinkedListNode <GameObject> node = nodePool.First; // Activate, position and initialise the node. ActivateNode(node); node.Value.transform.position = PopRandomFreePosition(); scrNode nodeScript = node.Value.GetComponent <scrNode>(); nodeScript.Init(node, message, coreSize, infected, creatingWords); // Set the cell's state to either infected or, if contribution is positive, clean else blocked. CellStates[ToCellSpace(nodeScript.transform.position.x), ToCellSpace(nodeScript.transform.position.y)] = infected ? CellState.INFECTED : nodeScript.Data.change_size > 0 ? CellState.CLEAN : CellState.BLOCKED; // Assign cubes to the node. LinkedListNode <GameObject> cube = cubePool.First; for (int i = 0, numLoops = 0; i < numCubes; ++i) { // Get the next cube before the cube is activated. LinkedListNode <GameObject> next = cube.Next; // Activate the cube and add it to the node. ActivateCube(cube); nodeScript.AddCube(cube); // Move to the next cube in the pool. cube = next; if (++numLoops == LOOPS_PER_FRAME) { numLoops = 0; yield return(new WaitForEndOfFrame()); } } // Query surrounding nodes for links. CreateLinks(node); // Release the node! Go! Go free!! nodeScript.MakeReady(); scrGUI.Instance.AddToFeed(message.page_title, infected ? ColCoreInfected : (message.change_size > 0 ? Color.cyan : Color.grey)); creating = false; }