int SortByFitness(MapGenBase a, MapGenBase b) { if (a.map.fitness > b.map.fitness) { return(-1); } else if (a.map.fitness < b.map.fitness) { return(1); } else { return(0); } }
void Start() { int widthAndHeight = Mathf.CeilToInt(Mathf.Sqrt(generatorCount)); generators = new List <MapGenBase>(); for (int i = 0; i < generatorCount; i++) { GameObject mapObject = Instantiate(generatorTemplate); mapObject.transform.position = Vector3.right * (i % widthAndHeight) + Vector3.up * (i / widthAndHeight); mapObject.transform.localScale = .98f * Vector3.one / widthAndHeight; mapObject.transform.position *= 1f / widthAndHeight; mapObject.transform.position -= (Vector3)Vector2.one * (.5f - .5f / widthAndHeight); mapObject.SetActive(true); MapGenBase mapGen = mapObject.GetComponent <MapGenBase>(); mapGen.fastForward = fastForward; generators.Add(mapGen); } }
/** * Will return back a chunk, if it doesn't exist and its not a MP client it will generates all the blocks for the * specified chunk from the map seed and chunk seed */ public Chunk provideChunk(int x, int z) { ChunkPrimer chunkprimer = new ChunkPrimer(); for (int i = 0; i < this.cachedBlockIDs.Length; ++i) { IBlockState iblockstate = this.cachedBlockIDs[i]; if (iblockstate != null) { for (int j = 0; j < 16; ++j) { for (int k = 0; k < 16; ++k) { chunkprimer.setBlockState(j, i, k, iblockstate); } } } } for (int i = 0; i < this.structureGenerators.Count; ++i) { MapGenBase mapGenBase = this.structureGenerators [i]; mapGenBase.generate(this, this.worldObj, x, z, chunkprimer); } Chunk chunk = new Chunk(this.worldObj, chunkprimer, x, z); BiomeGenBase[] abiomegenbase = this.worldObj.getWorldChunkManager().loadBlockGeneratorData((BiomeGenBase[])null, x * 16, z * 16, 16, 16); // byte[] abyte = chunk.getBiomeArray(); // // for (int l = 0; l < abyte.length; ++l) // { // abyte[l] = (byte)abiomegenbase[l].biomeID; // } // // chunk.generateSkylightMap(); return(chunk); }
void Update() { if (Input.GetKeyDown(KeyCode.Space)) { for (int i = 0; i < generators.Count; i++) { generators[i].Reset(); } measuredFitnesses = false; } bool allFinished = true; for (int i = 0; i < generators.Count; i++) { generators[i].fastForward = fastForward; if (generators[i].finished == false) { allFinished = false; } } if (allFinished && measuredFitnesses == false) { measuredFitnesses = true; if (fitnessCheck) { bestMap = null; for (int i = 0; i < generators.Count; i++) { TileMap map = generators[i].map; float fitness = 0f; if (map.hasStartTile && map.hasFinishTile) { fitness = Pathing.GetShortestDistance(map, map.startTile, map.finishTile); if (fillInactiveTiles) { for (int x = 0; x < map.width; x++) { for (int y = 0; y < map.height; y++) { if (Pathing.deadTiles[x, y] == 0) { map.SetTile(x, y, TileType.Wall); } } } map.ApplyTex(); } } map.fitness = fitness; } generators.Sort(SortByFitness); } } if (measuredFitnesses && fitnessCheck) { bestMap = generators[(int)((generators.Count - 1) * (1f - fitnessPercentile))]; } }