//////////////////////////////////////////////////////////////////////////// // Create Map Nodes //////////////////////////////////////////////////////// public static Dictionary <WorldNode, List <MapNode> > CreateMapNodes(List <WorldNode> worldNodes) { // Wrap map Nodes around around Initial Dictionary <WorldNode, List <MapNode> > worldNodeAndWrapperNodes = new Dictionary <WorldNode, List <MapNode> >(); foreach (WorldNode worldNode in worldNodes) { List <Vector3> mapVects = GetMapVects(worldNode); List <MapNode> mapNodes = new List <MapNode>(); int mapCount = 1; int layerCount = 0; int nodeLayerCount = -1; foreach (Vector3 vect in mapVects) { int rotation = 0; int mapType = -1; if (worldNode.entrance) { mapType = MapSettings.MAPTYPE_SHIPPORT_FLOOR; } else { mapType = MapSettings.MAPTYPE_MAP_FLOOR; } int mapPiece = Random.Range(0, 4); // 3 is the number of availble map pieces MapNode mapNode = WorldBuilder._nodeBuilder.CreateNode <MapNode>(worldNode.gameObject.transform, vect, rotation, mapType, mapPiece, NodeTypes.MapNode); mapNode.NodeSize = 1; mapNode.neighbours = new int[6]; for (int i = 0; i < mapNode.neighbours.Length; i++) { mapNode.neighbours[i] = 1; } mapNode.worldNodeParent = worldNode; if (worldNode.NodeSize == 1) { nodeLayerCount = worldNode.NodeLayerCount + 4; // 4 total layers in 1 map and vent piece } else if (worldNode.NodeSize == 3) { nodeLayerCount = worldNode.NodeLayerCount + layerCount; if (mapCount % 9 == 0) { layerCount = layerCount + 4; // 4 total layers in 1 map and vent piece } } else { Debug.LogError("something weird here"); } mapNode.NodeLayerCount = nodeLayerCount; mapNodes.Add(mapNode); if (!worldNode.entrance) { WorldBuilder._nodeBuilder.AttachCoverToNode(mapNode, mapNode.gameObject, CoverTypes.NormalCover, new Vector3(0, 0, 0)); } LayerManager.AddNodeToLayer(mapNode); // for camera layers mapCount++; } worldNode.mapNodes = mapNodes; worldNodeAndWrapperNodes.Add(worldNode, mapNodes); //////////////// //// Map Neighbours int[] worldNodeNeighbours = worldNode.neighbours; if (worldNode.NodeSize == 1) { MapNode mapNode = worldNode.mapNodes[0]; int[] mapNeighbours = mapNode.neighbours; for (int i = 0; i < worldNodeNeighbours.Length; i++) { if (worldNodeNeighbours[i] != -1) { mapNeighbours[i] = 1; } else { mapNeighbours[i] = -1; //mapNode.entranceSides.Add(i); } } } //////// if (worldNode.NodeSize == 3) { // bottom SetMapNeighboursWithMultipleLinks(worldNode, 0, 4, new int[] { 0, 1, 2, 3, 4, 5, 6, 7, 8 }, worldNode.entrance); // Front SetMapNeighboursWithMultipleLinks(worldNode, 1, 10, new int[] { 0, 1, 2, 9, 10, 11, 18, 19, 20 }, worldNode.entrance); // Left SetMapNeighboursWithMultipleLinks(worldNode, 2, 12, new int[] { 0, 3, 6, 9, 12, 15, 18, 21, 24 }, worldNode.entrance); // Right SetMapNeighboursWithMultipleLinks(worldNode, 3, 14, new int[] { 2, 5, 8, 11, 14, 17, 20, 23, 26 }, worldNode.entrance); // Back SetMapNeighboursWithMultipleLinks(worldNode, 4, 16, new int[] { 6, 7, 8, 15, 16, 17, 24, 25, 26 }, worldNode.entrance); // Top SetMapNeighboursWithMultipleLinks(worldNode, 5, 22, new int[] { 18, 19, 20, 21, 22, 23, 24, 25, 26 }, worldNode.entrance); } } return(worldNodeAndWrapperNodes); }
//////////////////////////////////////////////////////////////////////////// // Create World Nodes /////////////////////////////////////////////////// public static void CreateWorldNodes(List <Vector3> nodeVects) { // build inital map Node _WorldNodes = new List <WorldNode>(); int rowMultipler = MapSettings.worldSizeX; int colMultiplier = MapSettings.worldSizeZ; int totalMultiplier = MapSettings.worldSizeX * MapSettings.worldSizeZ; WorldNodeData_01 worldFloor = ScriptableObject.CreateInstance <WorldNodeData_01>(); List <int[, ]> floors = worldFloor.floors; int countFloorX = 0; // complicated to explain to future me int countFloorZ = 0; int countFloorY = 1; int count = 1; foreach (Vector3 vect in nodeVects) { int rotation = 0; int mapType = -1; int mapPiece = -1; WorldNode nodeScript = WorldBuilder._nodeBuilder.CreateNode <WorldNode>(WorldManager._WorldContainer.transform, vect, rotation, mapType, mapPiece, NodeTypes.WorldNode); nodeScript.worldNodeCount = (count - 1); nodeScript.NodeLayerCount = countFloorY * 12; // 12 is the number of (mapieces + vents layers) in the y axis of a worldnode // for the specified map structures if (MapSettings.LOADPREBUILT_STRUCTURE) { int[,] floor = floors[countFloorY - 1]; if (floor[countFloorX, countFloorZ] == 01) { int randSize = MapSettings.getRandomMapSize; nodeScript.NodeSize = randSize; } else { nodeScript.NodeSize = 0; } } else { int randSize = MapSettings.getRandomMapSize; nodeScript.NodeSize = randSize; } int shipEntranceProbablity = 20; if (nodeScript.NodeSize == 3 && Random.Range(0, shipEntranceProbablity) == 0) { WorldBuilder._nodeBuilder.AttachCoverToNode(nodeScript, nodeScript.gameObject, CoverTypes.LargeGarageCover, new Vector3(0, 0, 0)); nodeScript.entrance = true; } _WorldNodes.Add(nodeScript); // for counting, best not to change, even tho its ugly countFloorX++; if (count % totalMultiplier == 0) { countFloorY++; } if (countFloorX % rowMultipler == 0) { countFloorX = 0; countFloorZ++; } if (countFloorZ % colMultiplier == 0) { countFloorZ = 0; } // think need to add world nodes to layer sytem LayerManager.AddNodeToLayer(nodeScript); // for camera layers // for the dynamic grid experiment LocationManager.SetNodeScriptToLocation_CLIENT(vect, nodeScript); //LocationManager.SetNodeScriptToLocation_SERVER(vect, nodeScript); // this needs to do this in the server count++; } }
//////////////////////////////////////////////////////////////////////////// // Create Connector Nodes //////////////////////////////////////////////// public static Dictionary <WorldNode, List <ConnectorNode> > CreateConnectorNodes(Dictionary <WorldNode, List <KeyValuePair <Vector3, int> > > connectorVects) { // Wrap map Nodes around around Initial Dictionary <WorldNode, List <ConnectorNode> > worldNodeAndConnectorNodes = new Dictionary <WorldNode, List <ConnectorNode> >(); foreach (WorldNode worldNode in connectorVects.Keys) { List <ConnectorNode> connectorNodes = new List <ConnectorNode>(); List <KeyValuePair <Vector3, int> > vectsAndRot = connectorVects[worldNode]; foreach (KeyValuePair <Vector3, int> pair in vectsAndRot) { Vector3 vector = pair.Key; int rotation = pair.Value; int mapType = MapSettings.MAPTYPE_CONNECT_FLOOR; int mapPiece = 0; // only 1 connector map piece atm for both vertical and horizontal pieces int nodeLayerCount = -1; ConnectorNode connectorNode = WorldBuilder._nodeBuilder.CreateNode <ConnectorNode>(worldNode.gameObject.transform, vector, rotation, mapType, mapPiece, NodeTypes.ConnectorNode); WorldBuilder._nodeBuilder.AttachCoverToNode(connectorNode, connectorNode.gameObject, CoverTypes.ConnectorCover, new Vector3(0, rotation * 90, 0)); connectorNode.NodeSize = 1; connectorNode.neighbours = new int[6]; for (int i = 0; i < connectorNode.neighbours.Length; i++) { connectorNode.neighbours[i] = 1; } connectorNode.worldNodeParent = worldNode; connectorNodes.Add(connectorNode); // Up connector if (rotation == 4) { connectorNode.connectorUp = true; connectorNode.NodeMapType = MapSettings.MAPTYPE_CONNECT_UP_FLOOR; connectorNode.transform.localEulerAngles = new Vector3(0, rotation * 90, 0); Transform nodeCover = connectorNode.transform.Find("ConnectorCoverPrefab(Clone)"); nodeCover.localPosition = new Vector3(0, 0, 0); // to fix annoying vertical connector nodeCover.localScale = new Vector3(8, 8, 8); nodeCover.Find("Select").transform.localScale = new Vector3(0.1f, 0.1f, 0.1f); } if (worldNode.NodeSize == 1) { nodeLayerCount = worldNode.NodeLayerCount + 4; // 4 total layers in 1 map and vent piece } else { Debug.LogError("something weird here"); } connectorNode.NodeLayerCount = nodeLayerCount; LayerManager.AddNodeToLayer(connectorNode); // for camera layers } worldNode.connectorNodes = connectorNodes; worldNodeAndConnectorNodes.Add(worldNode, connectorNodes); ///// Connector Neighbours << This is a bit annoying is only using worldnode neighbours atm, might be cool to just use map neighbours instead... something to do int[] worldNodeNeighbours = worldNode.neighbours; if (worldNode.NodeSize == 1) { foreach (ConnectorNode connectorNode in worldNode.connectorNodes) { int[] connectorNeighbours = connectorNode.neighbours; for (int i = 0; i < worldNodeNeighbours.Length; i++) { if (worldNodeNeighbours[i] != -1) { connectorNeighbours[i] = 1; } else { connectorNeighbours[i] = -1; //connectorNode.entranceSides.Add(i); } } } } //////// } return(worldNodeAndConnectorNodes); }