public void GetSpawnHexes() { if (gridSide != GridSide.none) { spawnHexes = TerrainGen.GetGridSide(gridSide); } }
public static TerrainGen Create(World world, string layerFolder) { TerrainGen provider = new TerrainGen(); provider.Init(world, layerFolder); return(provider); }
public void CreateChunk(int x, int y, int z) { WorldPos worldPos = new WorldPos(x, y, z); //Instantiate the chunk at the coordinates using the chunk prefab GameObject newChunkObject = Instantiate( chunkPrefab, new Vector3(x, y, z), Quaternion.Euler(Vector3.zero) ) as GameObject; Chunk newChunk = newChunkObject.GetComponent<Chunk>(); newChunk.pos = worldPos; newChunk.world = this; //Add it to the chunks dictionary with the position as the key chunks.Add(worldPos, newChunk); var terrainGen = new TerrainGen(); newChunk = terrainGen.ChunkGen(newChunk); newChunk.SetBlocksUnmodified(); Serialization.Load(newChunk); }
public void CreateSimpleChunk(int x, int y, int z) { WorldPos worldPos = new WorldPos(x, y, z); //Instantiate the chunk at the coordinates using the chunk prefab GameObject newSimpleChunkObject = Instantiate( simpleChunkPrefab, new Vector3(x, y, z), Quaternion.Euler(Vector3.zero) ) as GameObject; SimpleChunk newSimpleChunk = newSimpleChunkObject.GetComponent <SimpleChunk>(); newSimpleChunk.pos = worldPos; newSimpleChunk.simpleWorld = this; //Add it to the chunks dictionary with the position as the key simpleChunks.Add(worldPos, newSimpleChunk); var terrainGen = new TerrainGen(); newSimpleChunk = terrainGen.SimpleChunkGen(newSimpleChunk); if (newSimpleChunk.simpleChunkType == SimpleChunkType.Air) { newSimpleChunk.gameObject.SetActive(false); return; } newSimpleChunkObject.GetComponent <Renderer>().material.mainTexture = textureDict.textDict[newSimpleChunk.simpleChunkType]; }
private void StartWorld() { Configure(); networking.StartConnections(this); terrainGen = TerrainGen.Create(this, config.layerFolder); }
public void CreateChunk(int x, int y, int z) { //the coordinates of this chunk in the world WorldPos worldPos = new WorldPos(x, y, z); //Instantiate the chunk at the coordinates using the chunk prefab GameObject newChunkObject = Instantiate( chunkPrefab, new Vector3(worldPos.x, worldPos.y, worldPos.z), Quaternion.Euler(Vector3.zero) ) as GameObject; //Get the object's chunk component Chunk newChunk = newChunkObject.GetComponent<Chunk>(); //Assign its values newChunk.pos = worldPos; newChunk.world = this; //Add it to the chunks dictionary with the position as the key chunks.Add(worldPos, newChunk); //now spawn me some test chunks! var terrainGen = new TerrainGen(); newChunk = terrainGen.ChunkGen(newChunk); // newChunk.SetBlocksUnmodified(); //bool loaded = Serialization.Load(newChunk); }
public override IEnumerator Generate() { yield return(0); TerrainGen.GenerateTerrain(this.parentChunk); //Architect.BuildSubChunk(this,this.design); //StartCoroutine(ReDraw()); waitingChunks.Remove(this); renderChunks.Add(this); while (waitingChunks.Count > 0 && waitingChunks[0] == null) { waitingChunks.RemoveAt(0); } if (waitingChunks.Count > 0) { StartCoroutine(waitingChunks[0].Generate()); } else { if (state == 0) { StartCoroutine(renderChunks[0].ReDraw()); } state = 1; } }
public void CreateChunk(int x, int y, int z) { WorldPos worldPos = new WorldPos(x,y,z); GameObject newChunkObject = Instantiate( chunkPrefab, new Vector3(worldPos.x,worldPos.y,worldPos.z), Quaternion.Euler(Vector3.zero) ) as GameObject; Chunk newChunk = newChunkObject.GetComponent<Chunk>(); newChunk.pos = worldPos; newChunk.world = this; chunks.Add(worldPos, newChunk); //bool loaded = Serialization.Load(newChunk); //if(loaded) //return; var terrainGen = new TerrainGen(); newChunk = terrainGen.ChunkGen(newChunk); newChunk.SetBlocksUnmodified(); bool loaded = Serialization.Load(newChunk); }
public void CreateChunk(int x, int y, int z) { //The coordinates of this chunk in the world WorldPos worldPos = new WorldPos(x, y, z); //Instantiate the chunk at the coordinates using the chunk prefab GameObject newChunkObject = Instantiate(chunkPrefab, new Vector3(worldPos.x, worldPos.y, worldPos.z), Quaternion.Euler(Vector3.zero)) as GameObject; //Get the object's chunk component Chunk newChunk = newChunkObject.GetComponent <Chunk>(); //Assign its values newChunk.pos = worldPos; newChunk.world = this; //Add it to the chunks dictionary with the position as the key chunks.Add(worldPos, newChunk); var terrainGen = new TerrainGen(); newChunk = terrainGen.ChunkGen(newChunk); newChunk.SetBlocksUnmodified(); //Loads saved chunk when creating one Serialization.Load(newChunk); }
public void CreateChunk(int x, int y, int z) { WorldPos worldPos = new WorldPos(x, y, z); GameObject newChunkObject = Instantiate( chunkPrefab, new Vector3(worldPos.x, worldPos.y, worldPos.z), Quaternion.Euler(Vector3.zero) ) as GameObject; Chunk newChunk = newChunkObject.GetComponent <Chunk>(); newChunk.pos = worldPos; newChunk.world = this; chunks.Add(worldPos, newChunk); //bool loaded = Serialization.Load(newChunk); //if(loaded) //return; var terrainGen = new TerrainGen(); newChunk = terrainGen.ChunkGen(newChunk); newChunk.SetBlocksUnmodified(); bool loaded = Serialization.Load(newChunk); }
// Start is called before the first frame update void Awake() { pathKeeper = this.GetComponent <PathKeeper>(); // if (TerrainGen.instance == null) { instance = this; } mapGenState = MapGen.none; hexGrid = new HexGrid(gridX, gridZ); edgeHexes = new List <Vector2Int>(); noiseMaps = new NoiseMap[2]; noiseMaps[0] = new NoiseMap() { scale = 2, weight = 30, offSet = new Vector2Int(Random.Range(0, 1000), Random.Range(0, 1000)) }; CalcNoise(noiseMaps[0]); noiseMaps[1] = new NoiseMap() { scale = 15, weight = 20, offSet = new Vector2Int(Random.Range(0, 1000), Random.Range(0, 1000)) }; CalcNoise(noiseMaps[1]); navMesh.buildHeightMesh = true; }
public static void CreateGrid(int gridX, int gridZ, GameObject hexHighlighter, GameObject highlightParent) { changed = new List <HexHighlighter>(); highlighterGrid = new HexHighlighter[gridX, gridZ]; for (int x = 0; x < gridX; x++) { for (int z = 0; z < gridZ; z++) { GameObject newHighlighter; newHighlighter = Instantiate(hexHighlighter); Vector3 hexPos = TerrainGen.GetHexPosition(x, z); hexPos.y += TerrainGen.hexSize / 2; newHighlighter.transform.position = hexPos; HexHighlighter hexHighlighterScr = newHighlighter.GetComponent <HexHighlighter>(); if (hexPos.y > 0) { hexHighlighterScr.Set(HexHighlight.grid); } else { hexHighlighterScr.Set(HexHighlight.none); newHighlighter.SetActive(false); } highlighterGrid[x, z] = hexHighlighterScr; newHighlighter.transform.parent = highlightParent.transform; } } }
static void Main(string[] largs) { args = largs; Stopwatch sw = new Stopwatch(); World world = new World("test"); foreach (Dimension d in world.Dimensions.Values) { sw.Restart(); Console.Write($"Generating dimension {d.Name} @ 2..."); TerrainGen.GenerateAround(d, 0, 0, 2); Console.WriteLine($"\rGenerated dimension {d.Name} @ 2 in {sw.Elapsed}"); } /*foreach (Dimension d in world.Dimensions.Values) * { * sw.Restart(); * Console.Write($"Generating dimension {d.Name} @ 16..."); * TerrainGen.GenerateAround(d, 0, 0, 16); * Console.WriteLine($"\rGenerated dimension {d.Name} @ 16 in {sw.Elapsed}"); * } * foreach (Dimension d in world.Dimensions.Values) * { * sw.Restart(); * Console.Write($"Generating dimension {d.Name} @ 32..."); * TerrainGen.GenerateAround(d, 0, 0, 32); * Console.WriteLine($"\rGenerated dimension {d.Name} @ 32 in {sw.Elapsed}"); * }*/ sw.Restart(); Console.Write($"Saving world!"); world.Save(); Console.WriteLine("\rSaved world in " + sw.Elapsed); Console.ReadLine(); }
//public bool CanChunk = true; //// Use this for initialization //void Start () { // for(int x = -2; x < 20; x++) // { // for(int y = 0; y < 1; y++) // { // for(int z = -1; z < 20; z++) // { // CreateChunk(x * AVVoxel.Chunk.chunkSizeX, y * AVVoxel.Chunk.chunkSizeY, z * AVVoxel.Chunk.chunkSizeZ); // } // } // } //} //// Update is called once per frame //void Update () { // if(genChunk) // { // genChunk = false; // WorldPos chunkPos = new WorldPos(newChunkX, newChunkY, newChunkZ); // AVVoxel.Chunk chunk = null; // if(chunks.TryGetValue(chunkPos, out chunk)) // { // DestroyChunk(chunkPos.x, chunkPos.y, chunkPos.z); // } // else // { // CreateChunk(chunkPos.x, chunkPos.y, chunkPos.z); // } // } //} public void CreateChunk(int x, int y, int z) { WorldPos worldPos = new WorldPos(x, y, z); GameObject newChunkObject = Instantiate(chunkPrefab, new Vector3(worldPos.x, worldPos.y, worldPos.z), Quaternion.Euler(Vector3.zero)) as GameObject; AVVoxel.Chunk newChunk = newChunkObject.GetComponent <AVVoxel.Chunk>(); newChunk.worldPos = worldPos; newChunk.world = this; chunks.Add(worldPos, newChunk); TerrainGen terrainGen = new TerrainGen(); terrainGen.Trees = Trees; terrainGen.PineTrees = PineTrees; terrainGen.Grass = Grass; terrainGen.Seaweed = Seaweed; newChunk = terrainGen.ChunkGen(newChunk); //CanChunk = false; // StartCoroutine(terrainGen.ChunkGenRoutine(newChunk,this)); newChunk.SetBlocksUnmodified(); Serialization.Load(newChunk); // CreateCloud(x, y, z); }
// Start is called before the first frame update void Start() { TerrainGenerator = GameObject.Find("TerrainGenerator"); TerrainGeneratorScript = TerrainGenerator.GetComponent <TerrainGen>(); food = new GameObject("Food"); foodList = new List <GameObject>(); }
public Chunk CreateChunk(int x, int y, int z) { //if (y == 0) // Debug.Log("create " + x + ", 0, " + z); // assign a new world position with the values passed WorldPos worldPos = new WorldPos(x, y, z); // Instantiate the chunk at the coordinates using the chunk prefab GameObject newChunkObject = Instantiate(chunkPrefab, new Vector3(x, y, z), Quaternion.Euler(Vector3.zero)) as GameObject; // assigns the instantiated chunk to newChunk Chunk newChunk = newChunkObject.GetComponent <Chunk>(); newChunk.pos = worldPos; newChunk.world = this; // Add it to the chunks dictionary with the position as the key chunks.Add(worldPos, newChunk); var terrainGen = new TerrainGen(); newChunk = terrainGen.ChunkGen(newChunk); //newChunk.SetBlocksUnmodified(); return(newChunk); }
public void CreateChunk(int x, int y, int z) { WorldPos worldPos = new WorldPos(x, y, z); //Instantiate the chunk at the coordinates using the chunk prefab GameObject newChunkObject = Instantiate( chunkPrefab, new Vector3(x, y, z), Quaternion.Euler(Vector3.zero) ) as GameObject; Chunk newChunk = newChunkObject.GetComponent <Chunk>(); newChunk.pos = worldPos; newChunk.world = this; //Add it to the chunks dictionary with the position as the key chunks.Add(worldPos, newChunk); var terrainGen = new TerrainGen(); newChunk = terrainGen.ChunkGen(newChunk); newChunk.SetBlocksUnmodified(); Serialization.Load(newChunk); }
public void CreateChunk(int x, int y, int z) { //Debug.Log(string.Format("World - CreateChunk: Pos - {0} {1} {2}", x, y, z)); var worldPos = new WorldPos(x, y, z); var newChunkObject = Instantiate(ChunkPreFab, new Vector3(x, y, z), Quaternion.Euler(Vector3.zero)) as GameObject; if (newChunkObject == null) { return; } var newChunk = newChunkObject.GetComponent <Chunk>(); newChunk.WorldPos = worldPos; newChunk.World = this; Chunks.Add(worldPos, newChunk); var terrainGen = new TerrainGen(); newChunk = terrainGen.ChunkGen(newChunk); newChunk.SetBlocksUnModified(); var loaded = Serialization.LoadChunk(newChunk); }
//instantiate the chunk at the coords //set chunks pos and world variables //add it to the chunk dictionary public void CreateChunk(int x, int y, int z) { //the coords of chunk in world WorldPos worldPos = new WorldPos(x, y, z); //instantiate chunk at coords using chunk prefab GameObject newChunkObject = Instantiate(chunkPrefab, new Vector3(x, y, z), Quaternion.Euler(Vector3.zero)) as GameObject; //get the chunk component Chunk newChunk = newChunkObject.GetComponent <Chunk>(); //assign values newChunk.pos = worldPos; newChunk.world = this; //add the chunks to the dictionary with position as the key chunks.Add(worldPos, newChunk); //if not generate a new chunk var terrainGen = new TerrainGen(); newChunk = terrainGen.ChunkGen(newChunk); newChunk.SetBlocksUnmodified(); bool loaded = Serialization.Load(newChunk); //set all chunks generated as unmodifies newChunk.SetBlocksUnmodified(); //then set all the player changes on top of said chunk Serialization.Load(newChunk); }
//Creates a new chunk at given position public Chunk CreateChunk(int x, int y, int z) { WorldPos worldPos = new WorldPos(x, y, z); //Instantiate the chunk at the cordinates using chunk prefab GameObject newChunkObject = Instantiate(chunkPrefab, new Vector3(x, y, z), Quaternion.Euler(Vector3.zero)) as GameObject; Chunk newChunk = newChunkObject.GetComponent <Chunk>(); newChunk.pos = worldPos; newChunk.world = this; //Adds it to chunk dictonary chunks.Add(worldPos, newChunk); //Terrain Generation TerrainGen terrainGen = new TerrainGen(); newChunk = terrainGen.ChunkGen(newChunk); //Sets the generated blocks to unmodified and tries to load any modified blocks from the save file if (isClient) { NetworkBlocksClient.RequestChuckData(newChunk.pos); } else { newChunk.SetBlocksUnmodified(); Serialization.Load(newChunk); } //newChunk.SetBlocksUnmodified(); //Serialization.Load(newChunk); return(newChunk); }
public void CalcDensity() { float sum = 0; int count = 0; for (int x = (int)bounds.xMin; x < bounds.xMax + 1; x++) { for (int z = (int)bounds.zMin; z < bounds.zMax + 1; z++) { Vector2Int globalPoint = new Vector2Int(x, z); Vector2Int localPoint = GetLocalCoord(globalPoint); //float density = CalculateDensityAt(x, z); float density = TerrainGen.CalculateDensityAt(globalPoint); if (terrainHeightMap[localPoint.x, localPoint.y] > 0) { sum += density; count++; } densityMap[localPoint.x, localPoint.y] = density; } } avgDensity = sum / count; }
public void CreateChunk(int x, int y, int z) { WorldPos worldPos = new WorldPos(x, y, z); //Instantiate the at the coordiantes using the prefab GameObject newChunkObject = Instantiate(chunkPrefab, new Vector3(x, y, z), Quaternion.Euler(Vector3.zero)) as GameObject; Chunk newChunk = newChunkObject.GetComponent <Chunk>(); newChunk.pos = worldPos; newChunk.world = this; //Add it to the chunks dictioanry with the position as key chunks.Add(worldPos, newChunk); TerrainGen terrainGen = new TerrainGen(); terrainGen.SetOrigin(origin); terrainGen.SetWorld(this); //List<string> companies = new List<string>(); ////TODO Give company names to terrain gen //companies.Add("Apple"); //companies.Add("Alphabet"); //companies.Add("Amazon"); //companies.Add("Yahoo"); //companies.Add("Twitter"); terrainGen.SetCompanies(companies); newChunk = terrainGen.ChunkGen(newChunk); newChunk.SetBlocksUnmodified(); Serialization.Load(newChunk); }
public void FindTarget(MotionType fallBack = MotionType.move) { RaycastHit hit; Vector3 castPos = TerrainGen.GetAsGridPosition(this.transform.position); castPos.y += 1; if (Physics.Raycast(castPos, Vector3.down, out hit, 3, buildingMask)) { if (!hit.collider.transform.parent.name.Contains("Copse")) { BuildingBase hitTarget; hitTarget = hit.collider.transform.GetComponentInParent <BuildingBase>(); if (hitTarget != null) { motionType = MotionType.attack; attackTarget = hitTarget; } } else { motionType = fallBack; } } else { motionType = fallBack; } }
int CalcCost(PathType type, Vector2Int pos, Vector2Int destination) { int cost = 0; float heightDif; Hex posHex = TerrainGen.GetHex(pos.x, pos.y); Hex destHex = TerrainGen.GetHex(destination.x, destination.y); if (type != PathType.flight) { if (posHex != null && destHex != null) { heightDif = posHex.height - destHex.height; heightDif /= TerrainGen.hexSize / 2; if (heightDif > 0) { cost += Mathf.RoundToInt(heightDif); } cost += destHex.cost; } else { cost += 10000; } } return(cost); }
private void Awake() { TerrainInstance = this; _terrainMesh = GetComponent <MeshFilter>().mesh; _vertices = _terrainMesh.vertices; for (int i = 18; i < _vertices.Length; i += 11) { _vertices[i] = new Vector3(_vertices[i].x, _vertices[i].y + Random.Range(0.5f, 1.5f), _vertices[i].z); } for (int i = 0; i <= 5; i++) { for (int j = i, k = 0; k < 11; j += 11) { _vertices[j] = new Vector3(_vertices[j].x, _vertices[j].y - Random.Range(0.1f, 0.7f), _vertices[j].z); k++; } } _terrainMesh.vertices = _vertices; GetComponent <MeshCollider>().sharedMesh = null; GetComponent <MeshCollider>().sharedMesh = _terrainMesh; }
private bool AoE() { if (areaEffect > 0) { List <Vector2Int> hexes; hexes = TerrainGen.GetHexInRange(TerrainGen.GetGridPosition2D(transform.position), Mathf.RoundToInt(1 + areaEffect)); List <mobBase> mobs = new List <mobBase>(); foreach (Vector2Int hex in hexes) { List <mobBase> mobHex = MobLister.GetMobList(hex); if (mobHex != null) { foreach (mobBase mob in mobHex) { float distance = MyMath.calcDistance(transform.position, mob.transform.position); if (distance < areaEffect * TerrainGen.hexSize && mob != target) { mobs.Add(mob); } } } } foreach (mobBase mob in mobs) { float distance = MyMath.calcDistance(transform.position, mob.transform.position); float dmgMult = distance / (TerrainGen.hexSize * areaEffect); mob.DamageMob(damage); } return(true); } return(false); }
void Start() { weaponName = "knife"; transform.position = TerrainGen.GetSpawnPoint(); controller = GetComponent <CharacterController>(); raftSpeed = speed * 2; originalSpeed = speed; }
void PlaceHexHook(Vector3 position) { Vector3 newPos; newPos = position; newPos.y += 0.001f; hexHook.transform.position = TerrainGen.GetAsGridPosition(newPos); }
private void loaderLoop() { while (!stopThread) { Queue <ChunkRequest> queueCopy = new Queue <ChunkRequest>(); lock (chunkRequests) { // Wait for chunk requests while (chunkRequests.Count == 0 && !stopThread) { Monitor.Wait(chunkRequests); } // Copy for (int i = 0; i < 3 && chunkRequests.Count > 0; i++) { queueCopy.Enqueue(chunkRequests[0]); chunkRequests.RemoveAt(0); } } Queue <TerrainGen.ChunkCreateMsg> done = new Queue <TerrainGen.ChunkCreateMsg>(); while (queueCopy.Count > 0 && !stopThread) { ChunkRequest r = (ChunkRequest)queueCopy.Dequeue(); // Heightmap HeightMap h = World.getOrCreateHeightMap(r.cx, r.cz); h.generate(Constants.WORLD_SEED); // Chunk block data ChunkData c = new ChunkData(r.cx, r.cy, r.cz); c.generate(h); // Mesh Vector2Int meshI = new Vector2Int(-1, -1); if (!c.isAir()) { meshI = c.generateMesh(); while ((meshI.x == -1 && meshI.y == -1) && !stopThread) { // Wait for the main thread to finish with one of the mesh data objects if (done.Count > 0) { TerrainGen.chunksLoaded(done); done.Clear(); } Thread.Sleep(32); meshI = c.generateMesh(); } } TerrainGen.ChunkCreateMsg m = new TerrainGen.ChunkCreateMsg(r.cx, r.cy, r.cz, c, meshI); done.Enqueue(m); } TerrainGen.chunksLoaded(done); } }
public void CreateChunk(int x, int y, int z) { WorldPos worldPos = new WorldPos(x, y, z); //Instantiate the chunk at the coordinates using the chunk prefab GameObject newChunkObject = Instantiate( chunkPrefab, new Vector3(x, y, z), Quaternion.Euler(Vector3.zero) ) as GameObject; Chunk newChunk = newChunkObject.GetComponent <Chunk>(); newChunk.pos = worldPos; newChunk.world = this; //Add it to the chunks dictionary with the position as the key chunks.Add(worldPos, newChunk); var terrainGen = new TerrainGen(); newChunk = terrainGen.ChunkGen(newChunk); if (newChunk.airCount == 6144) { newChunk.gameObject.SetActive(false); } newChunk.SetBlocksUnmodified(); for (int i = 0; i < newChunk.treeList.Count; i++) { GameObject newTree = Instantiate(treePrefab); newTree.transform.position = newChunk.treeList[i]; } for (int i = 0; i < newChunk.bushList.Count; i++) { GameObject newBush = Instantiate(huckPrefab); newBush.transform.position = newChunk.bushList[i]; } if (newChunk.boneSpawn) { print("boneSpawn"); GameObject newBone = Instantiate(bonePrefab); newBone.transform.position = newChunk.boneList[0]; } if (newChunk.horseSpawn) { print("boneSpawn"); GameObject newHorse = Instantiate(horsePrefab); newHorse.transform.position = newChunk.horseList[0]; } Serialization.Load(newChunk); if (newChunk.hasWater) { GameObject newWater = Instantiate(waterPrefab); newWater.transform.position = newChunk.transform.position; newChunk.water = newWater; newChunk.chunkWater = newWater.GetComponent <ChunkWater>(); } }
void Start() { terrain = world.getTerrain(); if (terrain == null) { Debug.LogError("ERR!! Terrain not found."); } addLivingObjectsToWorld(); }
public static Vector3 GetNextHex(int x, int z, PathType type = PathType.normal) { Vector3 nextPos; nextPos = TerrainGen.GetHexPosition(pathGrids[type][x, z].targetVec); return(nextPos); }
public PathNode(int x, int y) //Grid<PathNode> grid, //this.grid = grid; { this.x = x; this.y = y; height = TerrainGen.GenerateTerrainAt(x, y); isWalkable = height > 0; isWater = height <= 0; }
void Start() { //Makes the block index fetch all the BlockDefinition components //on this gameobject and add them to the index Block.index.GetMissingDefinitions(); noiseGen = new Noise(worldName); terrainGen = gameObject.GetComponent<TerrainGen>(); terrainGen.noiseGen = noiseGen; terrainGen.world = this; random = new System.Random(); }
public RoadGenerator(TerrainGen terrainGen){ cityCenters = terrainGen.cityCenters; centers = terrainGen.centers; visited = new bool[centers.Count]; centerDistances = new int[centers.Count]; lastCenter = new int[centers.Count]; ratio = (float)terrainGen.m_terrainSize / terrainGen.m_heightMapSize; waterLevel = terrainGen.waterLimit; this.terrainGen = terrainGen; }
public static void Build(Chunk chunk, BlockPos pos, TerrainGen terrainGen) { int leaves = terrainGen.GetNoise(pos.x + chunk.pos.x, 0, pos.z + chunk.pos.z, 1f, 2, 1) +1; for (int x = -leaves; x <= leaves; x++) { for (int y = 3; y <= 6; y++) { for (int z = -leaves; z <= leaves; z++) { TerrainGen.SetBlock(chunk, "leaves", pos.Add(x,y,z), true); } } } for (int y = 0; y <= 5; y++) { TerrainGen.SetBlock(chunk, "log", pos.Add(0, y, 0), true); } }
public void CreateChunk(int x, int y, int z) { WorldPos worldPos = new WorldPos (x, 0, z); GameObject newChunkObject = Instantiate (chunkPrefab, new Vector3 (x, 0, z), Quaternion.identity) as GameObject; Chunk newChunk = newChunkObject.GetComponent<Chunk> (); newChunk.name = "Chunk@" + new Vector3(x, y, z); newChunk.pos = worldPos; newChunk.world = this; //Add it to the chunks dictionary with the position as the key chunks.Add (worldPos, newChunk); var terrainGen = new TerrainGen (); newChunk = terrainGen.ChunkGen (newChunk); newChunk.SetBlocksUnmodified (); Serialization.Load (newChunk); }
public void createChunk(int x, int y, int z) { WorldPos worldPos = new WorldPos (x, y, z); //Instantiate a new Chunk at the coordinates GameObject newChunkObject = Instantiate (chunkPrefab, new Vector3 (x, y, z), Quaternion.Euler (Vector3.zero)) as GameObject; Chunk newChunk = newChunkObject.GetComponent<Chunk> (); newChunk.pos = worldPos; newChunk.world = this; //Add the new Chunk to the dictionary at this world position chunks.Add (worldPos, newChunk); TerrainGen terrainGen = new TerrainGen (); newChunk = terrainGen.ChunkGen (newChunk); newChunk.setBlocksUnmodified (); Serialization.loadChunk (newChunk); }
public virtual void GenerateStructures(BlockPos chunkPos, TerrainGen terrainGen) { if (layerType != LayerType.Structure) return; if (customTerrainLayer) { customLayer.GenerateStructures(chunkPos, terrainGen); return; } int minX, maxX, minZ, maxZ; minX = chunkPos.x - structure.negX; maxX = chunkPos.x + Config.Env.ChunkSize + structure.posX; minZ = chunkPos.z - structure.negZ; maxZ = chunkPos.z + Config.Env.ChunkSize + structure.posZ; for (int x = minX; x < maxX; x++) { for (int z = minZ; z < maxZ; z++) { int percentChance = GetNoise(x, 0, z, 10, 100, 1); if (percentChance < chanceToSpawnBlock) { if (percentChance < GetNoise(x + 1, 0, z, 10, 100, 1) && percentChance < GetNoise(x - 1, 0, z, 10, 100, 1) && percentChance < GetNoise(x, 0, z + 1, 10, 100, 1) && percentChance < GetNoise(x, 0, z - 1, 10, 100, 1)) { int height = terrainGen.GenerateTerrainForBlockColumn(x, z, true); structure.Build(world, chunkPos, new BlockPos(x, height, z), this); } } } } }
void BiomeCheck(Chunk chunk, TerrainGen gen) { if (!biomeSelected) { gen.Randomize(seed); biomeRange(Random.Range (1,4)); AddBiome (); } /*count ++; if (count > 10) { biomeSelected = false; minRange = biomeRange (-14, 1); maxRange = biomeRange (1, 16); AddBiome (); GenBiome (gen); } minRange.x += count; minRange.z += count; maxRange.z -= count; maxRange.x -= count; */ if (chunk.pos.x >= minRange.x && chunk.pos.x <= minRange.x) { if (chunk.pos.z >= minRange.z && chunk.pos.z <= maxRange.z) { GenBiome (gen); } else { biomeSelected = false; biomeRange(Random.Range (1,4)); //minRange = biomeRange (-14, 1); //maxRange = biomeRange (1, 16); AddBiome (); GenBiome (gen); } } else { biomeSelected = false; biomeRange(Random.Range (1,4)); //minRange = biomeRange (-14, 1); //maxRange = biomeRange (1, 16); AddBiome (); GenBiome (gen); } }
void GenBiome(TerrainGen gen) { if (biomeType == 0) gen.Caves (); else if (biomeType == 1) gen.Forest (); else if (biomeType == 2) gen.Mountains (); else if (biomeType == 3) gen.MountainCaves (); else if (biomeType == 4) gen.Desert (); else if (biomeType == 5) gen.MountainsDesert (); else if (biomeType == 6) gen.Plain (); }
void GetTerrainLayers() { gen = World.instance.gameObject.GetComponent<TerrainGen>(); List<TerrainLayer> layers = new List<TerrainLayer>(); layers.AddRange(gen.layerOrder); if (layers.Remove(null)) { EditorUtility.SetDirty(gen); } gen.layerOrder = layers.ToArray(); }
public virtual void GenerateStructures(BlockPos chunkPos, TerrainGen terrainGen) { }
private float[,] createTerrain() { Generatable terrain = new TerrainGen(ChunckSize,Zoom); return terrain.Generate(); }
// public int newChunkX; // public int newChunkY; // public int newChunkZ; // // public bool genChunk; // void Start() // { // for (int x = -4; x < 4; x++) // { // for (int y = -1; y < 3; y++) // { // for (int z = -4; z < 4; z++) // { // CreateChunk(x * 16, y * 16, z * 16); // } // } // } // } // // void Update() // { // if (genChunk) // { // genChunk = false; // WorldPos chunkPos = new WorldPos(newChunkX, newChunkY, newChunkZ); // Chunk chunk = null; // // if (chunks.TryGetValue(chunkPos, out chunk)) // { // DestroyChunk(chunkPos.x, chunkPos.y, chunkPos.z); // } // else // { // CreateChunk(chunkPos.x, chunkPos.y, chunkPos.z); // } // } // } public void CreateChunk(int x, int y, int z) { WorldPos worldPos = new WorldPos(x, y, z); GameObject newChunkObject = Instantiate(chunkPrefab, new Vector3(x, y, z), Quaternion.Euler(Vector3.zero)) as GameObject; Chunk newChunk = newChunkObject.GetComponent<Chunk>(); newChunk.pos = worldPos; newChunk.world = this; chunks.Add(worldPos, newChunk); // bool loaded = Serialization.Load(newChunk); // if (loaded) // { // return; // } // for (int xi = 0; xi < 16; xi++) // { // for (int yi = 0; yi < 16; yi++) // { // for (int zi = 0; zi < 16; zi++) // { // if (yi <= 7) // { // SetBlock(x + xi, y + yi, z + zi, new BlockGrass()); // } // else // { // SetBlock(x + xi, y + yi, z + zi, new BlockAir()); // } // } // } // } var terrainGen = new TerrainGen(); newChunk = terrainGen.ChunkGen(newChunk); newChunk.SetBlockUnmodified(); Serialization.Load(newChunk); }
public void CreateChunk(int x, int y, int z) { WorldPos worldPos = new WorldPos(x, y, z); //Instantiate the chunk at the coordinates using the chunk prefab GameObject newChunkObject = Instantiate( chunkPrefab, new Vector3(x, y, z), Quaternion.Euler(Vector3.zero) ) as GameObject; Chunk newChunk = newChunkObject.GetComponent<Chunk>(); //gets the script component newChunk.pos = worldPos; //rounds position to an int newChunk.world = this; //tells the chunk how to get back to mommy newChunk.tag = "breakable"; //Add it to the chunks dictionary with the position as the key chunks.Add(worldPos, newChunk); TerrainGen terrainGen = new TerrainGen(); //this has some preset values for generating newChunk = terrainGen.ChunkGen(newChunk); //this runs the generation code newChunk.SetBlocksUnmodified(); //this tells Serialization not to save as there was no changes Serialization.Load(newChunk); }
/// <summary> /// This is the code that generates the chunk. /// If using a different TerrainGen, override this class and call it here. /// </summary> /// <param name="chunk"></param> protected virtual void GenerateChunk(Chunk chunk) { if (isFlat == "false") { var terrainGen = new TerrainGen(noiseGen); terrainGen.ChunkGen(chunk); }else{ var terrainGenFlat = new TerrainGenFlat(noiseGen); terrainGenFlat.ChunkGen(chunk); } }
/* void Start () { cityList.AddRange(detectRegions(GetComponent<TerrainGen> ().getPopMap ())); } */ /* void OnDrawGizmos() { if (Application.isPlaying && cityDebug.Count > 0) { foreach(City c in cityList) { Gizmos.color = new Color(Random.Range(0f,1f),Random.Range(0f,1f),Random.Range(0f,1f)); foreach(Index x in c.cityCells) { Gizmos.DrawCube(new Vector3(x.x - size/2 ,0,x.y - size/2 ),Vector3.one); } } } } */ public static City[] getCityCells(TerrainGen terrain) { return detectRegions(terrain.getPopMap()); }
void GenAndLoadChunk(Chunk chunk) { var terrainGen = new TerrainGen(); terrainGen.ChunkGen(chunk); Serialization.Load(chunk); if (Config.Toggle.LightSceneOnStart) { if (chunk.pos.y == Config.Env.WorldMaxY) { BlockLight.ResetLightChunkColumn(this, chunk); } } chunk.terrainGenerated = true; }
/// <summary> /// This is the code that generates the chunk. /// If using a different TerrainGen, override this class and call it here. /// </summary> /// <param name="chunk"></param> protected virtual void GenerateChunk(Chunk chunk) { var terrainGen = new TerrainGen(); terrainGen.ChunkGen(chunk); }