// checks if the "to be fit" tile fits on this tile public bool CanConnect(GenerationTile other) { string name = this.transform.name; string name1 = other.transform.name; ConnectionID idThis = this.connectionID.GetExit().id; ConnectionID idOther = other.GetConnectionId().GetEntry().id; List <ConnectionVariations> cVarThis = GetSignature(idThis.connectionID); List <ConnectionVariations> cVarOther = GetSignature(idOther.connectionID); bool idsMatch = (cVarThis.Count == cVarThis.Count); if (!idsMatch) { return(false); } for (int i = 0; i < cVarThis.Count; i++) { if (cVarThis[i] != cVarOther[i]) { return(false); } } return(true); }
public GenerationTile GetTileId() { if (tileId == null) { tileId = GetComponent <GenerationTile>(); } return(tileId); }
private GenerationTileController[] GetAllConnectableTiles(GenerationTileController input) { List <GenerationTileController> returnList = new List <GenerationTileController>(); for (int i = 0; i < inputControllers.Length; i++) { GenerationTile t = input.GetTileId(); if (t.CanConnect(inputControllers[i].GetTileId())) { returnList.Add(inputControllers[i]); } } return(returnList.ToArray()); }
public override Generated_World Generate_World(GameObject entity_parent, int width, int height) { // Generate height map int[] height_map = new int[width * height]; int index = 0; for (int j = 0; j < height; j++) { for (int i = 0; i < width; i++) { height_map[index] = Mathf.FloorToInt(Mathf.PerlinNoise(i * roughness, j * roughness) * scale + water_level - scale - water_level * 3 + Mathf.PerlinNoise( i * biome_delta + 100, j * biome_delta + 100) * water_level * 6); height_map[index] = height_map[index] <= 0 ? 1 : height_map[index]; index++; } } // Generate vertices World.Vertex[] vertices = new World.Vertex[width * height]; int len = width * height; for (index = 0; index < len; index++) { Stack <VertexType> vert_stack = new Stack <VertexType>(); while (vert_stack.Count <= height_map[index]) { if (vert_stack.Count < water_level) { vert_stack.Push(VertexType.Dirt); } else if (vert_stack.Count < water_level + 2) { vert_stack.Push(VertexType.Sand); } else { vert_stack.Push(VertexType.Grass); } } vertices[index] = new World.Vertex(vert_stack); } // Generate tiles World.TileData[] tiles = new World.TileData[(width - 1) * (height - 1)]; index = 0; int v_index = 0; for (int j = 0; j < height - 1; j++) { for (int i = 0; i < width - 1; i++) { GenerationTile[] available = generationMap[(int)vertices[v_index].Type.Peek()]; if (available != null) { for (int e = 0; e < available.Length; e++) { if (UnityEngine.Random.value < available[e].probability) { GenerationTile genT = available[e]; if (genT.tile.Requirements.ValidateTerrain(vertices, width, height, i, j).Valid) { Tiles.Tile t = genT.tile.CreateInstance( entity_parent, new Vector3(i, height_map[v_index] + 1, j)); tiles[index] = new World.TileData(t); break; } } } } v_index++; index++; } v_index++; } // Instantiate the world Generated_World world = new Generated_World(); world.Vertices = vertices; world.Tiles = tiles; world.Entities = new QuadTree(0, 0, width, height); return(world); }
public void OnValidate() { tileId = GetComponent <GenerationTile>(); }