//Sets up for the relivant scene void OnLevelWasLoaded(int level) { if (level == 1) { MapSetup(); userOptions = FindObjectOfType <SimOptionsUi>(); if (userOptions.reportOutput != null) { userOptions.reportOutput.Seed = currentSeed.ToString(); } } else if (level == 0) { GUIEnabled = false; } }
//map genoration procedure public void GenerateMap() { Time.timeScale = 0; DataUI = FindObjectOfType<SimOptionsUi>(); //Setting up generated map object currentTireHight = new Vector3(0, 0, 0); tileTable = new Dictionary<Coord, Terrain>(); string nameHolder = "Generated Map"; if (transform.FindChild(nameHolder)) { DestroyImmediate(transform.FindChild(nameHolder).gameObject); } Transform mapHolder = new GameObject(nameHolder).transform; mapHolder.parent = transform; //Adding time base directional light if (transform.FindChild("Sol(Clone)")) { DestroyImmediate(transform.FindChild("Sol(Clone)").gameObject); } Transform solHolder = Instantiate(sol, transform.position + Vector3.up * 5, Quaternion.Euler(Vector3.right * 20)) as Transform; solHolder.parent = transform; solHolder.GetComponent<SunControls>().NightFall += OnDayEnd; if (transform.FindChild("StrandHolder(Clone)")) { DestroyImmediate(transform.FindChild("StrandHolder(Clone)").gameObject); } Transform holderStrand = Instantiate(dnaStrand, Vector3.zero, Quaternion.Euler(Vector3.zero)) as Transform; holderStrand.parent = transform; //Building and positioning navmesh mask apiture for custom navigation size if (transform.FindChild("NavMeshApiture(Clone)")) { DestroyImmediate(transform.FindChild("NavMeshApiture(Clone)").gameObject); } Transform apitureHolder = Instantiate(maskApiture, new Vector3(0f,1.4f,-1f) , Quaternion.Euler(0f,0f,0f)) as Transform; apitureHolder.parent = transform; SetApiture(apitureHolder); //Adding camara world limit if (transform.FindChild("WorldLimit(Clone)")) { DestroyImmediate(transform.FindChild("WorldLimit(Clone)").gameObject); } Transform worldLimitHolder = Instantiate(worldLimit, Vector3.zero, Quaternion.Euler(Vector3.zero)) as Transform; worldLimitHolder.parent = transform; //Setting variables for requested map settings //currentMap = map; int Diameter = (map.mapRadius + (map.mapRadius - 1)); int targetHeight = map.mapRadius; int StartingX = 1; //Populating terain map and intanciating tiles //Generates A hexagon of hexagons with a given Diameter allTileCoords = new List<Coord>(); for (int y = 1; y <= Diameter; y++) { for (int x = StartingX; x <= targetHeight + StartingX - 1; x++) { allTileCoords.Add(new Coord(x, y)); placeTile(mapHolder, tilePrefab, x, y); if (currentTerrain != null) { tileTable.Add(new Coord(x, y), currentTerrain); } } if (y < map.mapRadius) { targetHeight++; } else { targetHeight--; } if (y % 2 == 0 && y < map.mapRadius) { StartingX--; } else if (y % 2 != 0 && y > map.mapRadius) { StartingX++; } if (y == map.mapRadius && y % 2 != 0) { StartingX++; } } //1st order shuffle of coords based on seed shuffleTileCoords = new Queue<Coord>(Utility.ShuffleArray(allTileCoords.ToArray(), map.seed)); //Undulating terratin height Coord randomTileID; Terrain currentTile; if (map.isFlat != true) { for (int i = 0; i < allTileCoords.Count / 2; i++) { randomTileID = GetRandomCoord(); currentTile = tileTable[randomTileID]; if (i % 2 == 0) { if (HeightConnected(randomTileID, 'l') == true && currentTile.heightCheck() == 'm') { currentTile.SetTerrainHeight(0.5f); } else { i--; } } else { if (HeightConnected(randomTileID, 'h') == true && currentTile.heightCheck() == 'm') { currentTile.SetTerrainHeight(-0.5f); } else { i--; } } } } //2nd order shuffle of coords based on seed shuffleTileCoords = new Queue<Coord>(Utility.ShuffleArray(shuffleTileCoords.ToArray(), map.seed)); int producerCount = (int)((tileTable.Count * map.producerPercent) / 4); int currentPropCount = 0; // Randomly placing producers at requested desity for (int i = 0; i < producerCount; i++) { randomTileID = GetRandomCoord(); currentPropCount++; if (randomTileID != map.mapCenter) { currentTile = tileTable[randomTileID]; currentTile.hasSeed = true; if (i % 3 == 0) { currentTile.ProducerType = 1; } else if (i % 4 == 0) { currentTile.ProducerType = 2; } else { currentTile.ProducerType = 0; } } else { currentPropCount--; } } // Randomly placing Spawners base on map spawner density pSpawnerList = new List<Spawner>(); sSpawnerList = new List<Spawner>(); hSpawnerList = new List<Spawner>(); int spawnerCount = map.spawnerDensity * 4; for (int i = 0; i < spawnerCount; i++) { randomTileID = GetRandomCoord(); currentTile = tileTable[randomTileID]; if (i % 4 == 0) { currentTile.AddNest(2, Utility.GenerateGeneString(map.seed, 8 , 'p')); pSpawnerList.Add(currentTile.GetComponentInChildren<Spawner>()); } else if (i % 3 == 0) { currentTile.AddNest(1, Utility.GenerateGeneString(map.seed, 13, 'o')); sSpawnerList.Add(currentTile.GetComponentInChildren<Spawner>()); } else { currentTile.AddNest(0, Utility.GenerateGeneString(map.seed, 11, 'h')); hSpawnerList.Add(currentTile.GetComponentInChildren<Spawner>()); } } // Randomly placing water at requested desity int waterCount = (int)((tileTable.Count * map.waterPercent) / 4); int currentWaterCount = 0; for (int i = 0; i < waterCount; i++) { randomTileID = GetRandomCoord(); currentWaterCount++; if (tileTable[randomTileID].heightCheck() != 'h') { currentTile = tileTable[randomTileID]; currentTile.isWater = true; } else { currentWaterCount--; } } //Adding bedrock graphics if (map.mapRadius > 5) { for (int i = 1; i <= 3; i++){ currentTireHight = new Vector3(i, -i, i); targetHeight = map.mapRadius - i; StartingX = 1; Diameter = (map.mapRadius - i + (map.mapRadius - i - 1)); for (int y = 1; y <= Diameter; y++) { for (int x = StartingX; x <= targetHeight + StartingX - 1; x++) { placeTile(mapHolder, BedRockPrefab, x, y); } if (y < map.mapRadius) { targetHeight++; } else { targetHeight--; } if (y % 2 == 0 && y < map.mapRadius) { StartingX--; } else if (y % 2 != 0 && y > map.mapRadius) { StartingX++; } if (y == map.mapRadius && y % 2 != 0) { StartingX++; } } } } Time.timeScale = 1; StartCoroutine(AnimatCount()); }
//map genoration procedure public void GenerateMap() { Time.timeScale = 0; DataUI = FindObjectOfType <SimOptionsUi>(); //Setting up generated map object currentTireHight = new Vector3(0, 0, 0); tileTable = new Dictionary <Coord, Terrain>(); string nameHolder = "Generated Map"; if (transform.FindChild(nameHolder)) { DestroyImmediate(transform.FindChild(nameHolder).gameObject); } Transform mapHolder = new GameObject(nameHolder).transform; mapHolder.parent = transform; //Adding time base directional light if (transform.FindChild("Sol(Clone)")) { DestroyImmediate(transform.FindChild("Sol(Clone)").gameObject); } Transform solHolder = Instantiate(sol, transform.position + Vector3.up * 5, Quaternion.Euler(Vector3.right * 20)) as Transform; solHolder.parent = transform; solHolder.GetComponent <SunControls>().NightFall += OnDayEnd; if (transform.FindChild("StrandHolder(Clone)")) { DestroyImmediate(transform.FindChild("StrandHolder(Clone)").gameObject); } Transform holderStrand = Instantiate(dnaStrand, Vector3.zero, Quaternion.Euler(Vector3.zero)) as Transform; holderStrand.parent = transform; //Building and positioning navmesh mask apiture for custom navigation size if (transform.FindChild("NavMeshApiture(Clone)")) { DestroyImmediate(transform.FindChild("NavMeshApiture(Clone)").gameObject); } Transform apitureHolder = Instantiate(maskApiture, new Vector3(0f, 1.4f, -1f), Quaternion.Euler(0f, 0f, 0f)) as Transform; apitureHolder.parent = transform; SetApiture(apitureHolder); //Adding camara world limit if (transform.FindChild("WorldLimit(Clone)")) { DestroyImmediate(transform.FindChild("WorldLimit(Clone)").gameObject); } Transform worldLimitHolder = Instantiate(worldLimit, Vector3.zero, Quaternion.Euler(Vector3.zero)) as Transform; worldLimitHolder.parent = transform; //Setting variables for requested map settings //currentMap = map; int Diameter = (map.mapRadius + (map.mapRadius - 1)); int targetHeight = map.mapRadius; int StartingX = 1; //Populating terain map and intanciating tiles //Generates A hexagon of hexagons with a given Diameter allTileCoords = new List <Coord>(); for (int y = 1; y <= Diameter; y++) { for (int x = StartingX; x <= targetHeight + StartingX - 1; x++) { allTileCoords.Add(new Coord(x, y)); placeTile(mapHolder, tilePrefab, x, y); if (currentTerrain != null) { tileTable.Add(new Coord(x, y), currentTerrain); } } if (y < map.mapRadius) { targetHeight++; } else { targetHeight--; } if (y % 2 == 0 && y < map.mapRadius) { StartingX--; } else if (y % 2 != 0 && y > map.mapRadius) { StartingX++; } if (y == map.mapRadius && y % 2 != 0) { StartingX++; } } //1st order shuffle of coords based on seed shuffleTileCoords = new Queue <Coord>(Utility.ShuffleArray(allTileCoords.ToArray(), map.seed)); //Undulating terratin height Coord randomTileID; Terrain currentTile; if (map.isFlat != true) { for (int i = 0; i < allTileCoords.Count / 2; i++) { randomTileID = GetRandomCoord(); currentTile = tileTable[randomTileID]; if (i % 2 == 0) { if (HeightConnected(randomTileID, 'l') == true && currentTile.heightCheck() == 'm') { currentTile.SetTerrainHeight(0.5f); } else { i--; } } else { if (HeightConnected(randomTileID, 'h') == true && currentTile.heightCheck() == 'm') { currentTile.SetTerrainHeight(-0.5f); } else { i--; } } } } //2nd order shuffle of coords based on seed shuffleTileCoords = new Queue <Coord>(Utility.ShuffleArray(shuffleTileCoords.ToArray(), map.seed)); int producerCount = (int)((tileTable.Count * map.producerPercent) / 4); int currentPropCount = 0; // Randomly placing producers at requested desity for (int i = 0; i < producerCount; i++) { randomTileID = GetRandomCoord(); currentPropCount++; if (randomTileID != map.mapCenter) { currentTile = tileTable[randomTileID]; currentTile.hasSeed = true; if (i % 3 == 0) { currentTile.ProducerType = 1; } else if (i % 4 == 0) { currentTile.ProducerType = 2; } else { currentTile.ProducerType = 0; } } else { currentPropCount--; } } // Randomly placing Spawners base on map spawner density pSpawnerList = new List <Spawner>(); sSpawnerList = new List <Spawner>(); hSpawnerList = new List <Spawner>(); int spawnerCount = map.spawnerDensity * 4; for (int i = 0; i < spawnerCount; i++) { randomTileID = GetRandomCoord(); currentTile = tileTable[randomTileID]; if (i % 4 == 0) { currentTile.AddNest(2, Utility.GenerateGeneString(map.seed, 8, 'p')); pSpawnerList.Add(currentTile.GetComponentInChildren <Spawner>()); } else if (i % 3 == 0) { currentTile.AddNest(1, Utility.GenerateGeneString(map.seed, 13, 'o')); sSpawnerList.Add(currentTile.GetComponentInChildren <Spawner>()); } else { currentTile.AddNest(0, Utility.GenerateGeneString(map.seed, 11, 'h')); hSpawnerList.Add(currentTile.GetComponentInChildren <Spawner>()); } } // Randomly placing water at requested desity int waterCount = (int)((tileTable.Count * map.waterPercent) / 4); int currentWaterCount = 0; for (int i = 0; i < waterCount; i++) { randomTileID = GetRandomCoord(); currentWaterCount++; if (tileTable[randomTileID].heightCheck() != 'h') { currentTile = tileTable[randomTileID]; currentTile.isWater = true; } else { currentWaterCount--; } } //Adding bedrock graphics if (map.mapRadius > 5) { for (int i = 1; i <= 3; i++) { currentTireHight = new Vector3(i, -i, i); targetHeight = map.mapRadius - i; StartingX = 1; Diameter = (map.mapRadius - i + (map.mapRadius - i - 1)); for (int y = 1; y <= Diameter; y++) { for (int x = StartingX; x <= targetHeight + StartingX - 1; x++) { placeTile(mapHolder, BedRockPrefab, x, y); } if (y < map.mapRadius) { targetHeight++; } else { targetHeight--; } if (y % 2 == 0 && y < map.mapRadius) { StartingX--; } else if (y % 2 != 0 && y > map.mapRadius) { StartingX++; } if (y == map.mapRadius && y % 2 != 0) { StartingX++; } } } } Time.timeScale = 1; StartCoroutine(AnimatCount()); }
//Sets up for the relivant scene void OnLevelWasLoaded(int level) { if (level == 1) { MapSetup(); userOptions = FindObjectOfType<SimOptionsUi>(); if (userOptions.reportOutput != null) { userOptions.reportOutput.Seed = currentSeed.ToString(); } } else if(level == 0) { GUIEnabled = false; } }