/// <summary> /// Changes the biome. /// </summary> /// <returns><c>true</c>, if biome was changed, <c>false</c> otherwise.</returns> bool checkChangeBiome() { playerCC = vxe.getChunkCoords (playerTrans.position); mybiome = biome.biomeMap [playerCC.x, playerCC.z]; return (mybiome != prevBiome); }
/* * Randomly choose which biome a * city will spawn in, current chances are the ff: * Snow - 5% - 0~4 * Tundra - 10% - 5~14 * Grassland - 40% - 15~54 * Woods - 30% - 55~84 * Forest - 10% - 85~94 * Desert - 5% - 95~99 * */ BIOMES RollForCityBiome() { //Get total percentage int total = 0; foreach (int value in elligibleBiomes.Values) { total += value; } int roll = UnityEngine.Random.Range(0, total); int lowerBound = 0; int upperBound = 0; foreach (KeyValuePair <BIOMES, int> keyValue in elligibleBiomes) { BIOMES biome = keyValue.Key; int biomeChance = keyValue.Value; upperBound += biomeChance; if (roll >= lowerBound && roll < upperBound) { return(biome); } else { lowerBound += biomeChance; } } return(BIOMES.GRASSLAND); }
/// <summary> /// Changes the biome. /// </summary> /// <returns><c>true</c>, if biome was changed, <c>false</c> otherwise.</returns> bool checkChangeBiome() { playerCC = vxe.getChunkCoords(playerTrans.position); mybiome = biome.biomeMap [playerCC.x, playerCC.z]; return(mybiome != prevBiome); }
// Update is called once per frame void Update() { framecount++; if (framecount % spawnInterval != 0 || count >= spawnLimit) { return; } Random.seed = (int)(Time.deltaTime * 1000); Vector3 pos = new Vector3(), normal = new Vector3(); if (vxe.RayCast(camera.transform.position, camera.transform.forward, 64, ref pos, ref normal)) { Vec3Int chunkcoord = vxe.ToGrid(pos) / vxe.chunk_size; BIOMES mybiome = biome.biomeMap[chunkcoord.x, chunkcoord.z]; int animal = Random.Range(0, spawns[(int)mybiome].obj.Length); GameObject spawnObject = spawns[(int)mybiome].obj[animal]; if (spawns[(int)mybiome].sticksToWalls[animal] || Vector3.Dot(normal, Vector3.up) > 0.999f) { GameObject newsphere = (GameObject)Instantiate(spawnObject, pos + normal * VoxelExtractionPointCloud.Instance.voxel_size * 0.5f, Quaternion.identity); newsphere.SetActive(true); //newsphere.GetComponent<GrowScript>().init(pos, normal, (Vector3.Dot (normal,Vector3.up) > 0.999f) ); count++; } } }
/// <summary> /// Waits to initialize. /// </summary> /// <returns>The to initialize.</returns> IEnumerator waitToInitialize() { while (biome.biomeMap == null) { yield return(new WaitForEndOfFrame()); } playerCC = vxe.getChunkCoords(playerTrans.position); mybiome = biome.biomeMap [playerCC.x, playerCC.z]; }
/// <summary> /// Sets the environment list based on biome. /// </summary> /// <returns>The environment list based on biome.</returns> /// <param name="Pos">Position.</param> GameObject[] SetEnvironmentListBasedOnBiome(Vector3 Pos) { playerCC = vxe.getChunkCoords(Pos); chunkx = playerCC.x; chunkz = playerCC.z; mybiome = biome.biomeMap [chunkx, chunkz]; return(getAssetListBasedOnBiome(mybiome)); }
IEnumerator waitToInitialize() { while (biome.biomeMap == null) { yield return new WaitForEndOfFrame (); } playerCC = vxe.getChunkCoords (playerTrans.position); mybiome=biome.getBiomeFromCoords (playerCC); prevBiome = mybiome; switchBiomeAudio (mybiome); }
IEnumerator waitToInitialize() { while (biome.biomeMap == null) { yield return(new WaitForEndOfFrame()); } playerCC = vxe.getChunkCoords(playerTrans.position); mybiome = biome.getBiomeFromCoords(playerCC); prevBiome = mybiome; switchBiomeAudio(mybiome); }
/// <summary> /// Gets the next environment game objectList /// </summary> /// <returns>The next environment game object.</returns> /// <param name="newBiome">New biome.</param> GameObject[] getAssetListBasedOnBiome(BIOMES newBiome) { switch (newBiome) { case BIOMES.grass: return(grassAssets); case BIOMES.sand: return(desertAssets); default: //marsh return(marshAssets); } }
public City(HexTile hexTile, BIOMES biomeType) { this.hexTile = hexTile; this.biomeType = biomeType; this.cityType = CITY_TYPE.NORMAL; this.cityLevel = 1; this.richnessLevel = GenerateRichness(); this.population = 0; this.numOfRoads = 0; this.garrison = 0; this.gold = 0; this.connectedCities = new List <CityTile>(); this.kingdomTile = null; this.faction = new Faction(); }
void switchBiomeAudio(BIOMES newBiome) { switch (newBiome) { case BIOMES.grass: au_source.clip = grassAudio; break; case BIOMES.sand: au_source.clip = sandAudio; break; case BIOMES.jungle: au_source.clip = marshAudio; break; } au_source.Play (); }
// Use this for initialization void Start() { //Initialize VBariables biome = BiomeScript.Instance; vxe = VoxelExtractionPointCloud.Instance; mybiome = biome.biomeArea [0].biome; au_source = GetComponent<AudioSource> (); if (playerTrans == null) playerTrans = GameObject.FindWithTag ("Player").GetComponent<Transform> (); /*playerCC = vxe.getChunkCoords (playerTrans.position); mybiome = biome.biomeMap [playerCC.x, playerCC.z]; prevBiome = mybiome; switchBiomeAudio (mybiome); */ StartCoroutine (waitToInitialize ()); }
// Use this for initialization void Start() { vxe = VoxelExtractionPointCloud.Instance; biome = BiomeScript.Instance; mybiome = biome.biomeArea [0].biome; occupiedNearMe = new List <Chunks> (); assetChunkTable = new Dictionary <Vec3Int, GameObject> (); if (playerTrans == null) { playerTrans = GameObject.FindWithTag("Player").GetComponent <Transform> (); } spawns = new IndexStack <SpawnObject> (new SpawnObject[max_spawns + 20]); StartCoroutine(FullPullSpawn()); StartCoroutine(MaintainSpawns()); }
void switchBiomeAudio(BIOMES newBiome) { switch (newBiome) { case BIOMES.grass: au_source.clip = grassAudio; break; case BIOMES.sand: au_source.clip = sandAudio; break; case BIOMES.jungle: au_source.clip = marshAudio; break; } au_source.Play(); }
// Use this for initialization void Start() { //Initialize VBariables biome = BiomeScript.Instance; vxe = VoxelExtractionPointCloud.Instance; mybiome = biome.biomeArea [0].biome; au_source = GetComponent <AudioSource> (); if (playerTrans == null) { playerTrans = GameObject.FindWithTag("Player").GetComponent <Transform> (); } /*playerCC = vxe.getChunkCoords (playerTrans.position); * mybiome = biome.biomeMap [playerCC.x, playerCC.z]; * prevBiome = mybiome; * switchBiomeAudio (mybiome); */ StartCoroutine(waitToInitialize()); }
/* * Place each hexagon tile in their respective * biome lists for easy access to each specific biomes * tiles. * */ void AssignHexTileToList(HexTile tile) { BIOMES biomeType = tile.biomeType; switch (biomeType) { case BIOMES.SNOW: snowHexTiles.Add(tile); CityGenerator.Instance.tilesElligibleForCities.Add(tile); break; case BIOMES.TUNDRA: tundraHexTiles.Add(tile); CityGenerator.Instance.tilesElligibleForCities.Add(tile); break; case BIOMES.GRASSLAND: grasslandHexTiles.Add(tile); CityGenerator.Instance.tilesElligibleForCities.Add(tile); break; case BIOMES.WOODLAND: woodsHexTiles.Add(tile); CityGenerator.Instance.tilesElligibleForCities.Add(tile); break; case BIOMES.FOREST: forestHexTiles.Add(tile); CityGenerator.Instance.tilesElligibleForCities.Add(tile); break; case BIOMES.DESERT: desertHexTiles.Add(tile); CityGenerator.Instance.tilesElligibleForCities.Add(tile); break; } }
/* * Generate Cities then generate * each cities' connections * */ public void GenerateCities() { cities = new List <HexTile>(); CheckForUnelligibleBiomes(); for (int i = 0; i < cityCount; i++) { BIOMES chosenBiome = RollForCityBiome(); if (chosenBiome == BIOMES.SNOW) { PlaceCityOnBiomeTile(Biomes.Instance.snowHexTiles); } else if (chosenBiome == BIOMES.TUNDRA) { PlaceCityOnBiomeTile(Biomes.Instance.tundraHexTiles); } else if (chosenBiome == BIOMES.GRASSLAND) { PlaceCityOnBiomeTile(Biomes.Instance.grasslandHexTiles); } else if (chosenBiome == BIOMES.WOODLAND) { PlaceCityOnBiomeTile(Biomes.Instance.woodsHexTiles); } else if (chosenBiome == BIOMES.FOREST) { PlaceCityOnBiomeTile(Biomes.Instance.forestHexTiles); } else if (chosenBiome == BIOMES.DESERT) { PlaceCityOnBiomeTile(Biomes.Instance.desertHexTiles); } } SetCapitalCities(); // pendingCityTiles.Add(capitalCities[0]); // GenerateCityConnections(); PathManager.Instance.GenerateConnections(cities); }
public void SetTileBiomeType(BIOMES biomeType) { this.biomeType = biomeType; }
void GenerateBiomes() { for (int i = 0; i < this.cities.Count; i++) { HexTile currentHexTile = this.cities [i].GetComponent <HexTile> (); HexTile[] neighbours = currentHexTile.GetTilesInRange(5); BIOMES targetBiomeType = BIOMES.BARE; Sprite biomeSprite = null; if (i == 0) { targetBiomeType = BIOMES.GRASSLAND; biomeSprite = grasslandSprite; } else if (i == 1) { targetBiomeType = BIOMES.DESERT; biomeSprite = desertSprite; } else if (i == 2) { targetBiomeType = BIOMES.WOODLAND; biomeSprite = woodlandSprite; } else if (i == 3) { targetBiomeType = BIOMES.GRASSLAND; biomeSprite = grasslandSprite; } else if (i == 4) { targetBiomeType = BIOMES.FOREST; biomeSprite = forestSprite; } else if (i == 5) { targetBiomeType = BIOMES.WOODLAND; biomeSprite = woodlandSprite; } else if (i == 6) { targetBiomeType = BIOMES.SNOW; biomeSprite = snowSprite; } else if (i == 7) { targetBiomeType = BIOMES.TUNDRA; biomeSprite = tundraSprite; } for (int j = 0; j < neighbours.Length; j++) { neighbours[j].SetTileBiomeType(targetBiomeType); neighbours[j].GenerateResourceValues(); neighbours[j].GetComponent <SpriteRenderer> ().sprite = biomeSprite; neighbours [j].elevationType = ELEVATION.PLAIN; switch (targetBiomeType) { case BIOMES.GRASSLAND: neighbours[j].primaryResourceToPurchaseTile = RESOURCE.STONE; neighbours[j].secondaryResourceToPurchaseTile = RESOURCE.MANA; break; case BIOMES.WOODLAND: neighbours[j].primaryResourceToPurchaseTile = RESOURCE.LUMBER; neighbours[j].secondaryResourceToPurchaseTile = RESOURCE.METAL; break; case BIOMES.FOREST: neighbours[j].primaryResourceToPurchaseTile = RESOURCE.LUMBER; neighbours[j].secondaryResourceToPurchaseTile = RESOURCE.MANA; break; case BIOMES.DESERT: neighbours[j].primaryResourceToPurchaseTile = RESOURCE.STONE; neighbours[j].secondaryResourceToPurchaseTile = RESOURCE.METAL; break; case BIOMES.TUNDRA: neighbours[j].primaryResourceToPurchaseTile = RESOURCE.LUMBER; neighbours[j].secondaryResourceToPurchaseTile = RESOURCE.MANA; break; case BIOMES.SNOW: neighbours[j].primaryResourceToPurchaseTile = RESOURCE.STONE; neighbours[j].secondaryResourceToPurchaseTile = RESOURCE.METAL; break; } } } }
// Update is called once per frame void Update() { framecount++; // if ((framecount % 10 != 0 || (thingsSpawned.Count > maxToSpawnInBiome * 4)) && portal.activeInHierarchy) { return; } Random.seed = (int)(Time.deltaTime * 1000); //A Random Point in your Camera View Port Vector3 ranPt = new Vector3(Random.Range(0.0f, 1.0f), Random.Range(0.0f, 1.0f), backCam.nearClipPlane); //The World Point you see thru camera Vector3 startpt = backCam.ViewportToWorldPoint(ranPt); //The Direction vector from Camera to start point Vector3 dir = startpt - backCam.transform.position; Vector3 pos = new Vector3(), normal = new Vector3(); if (vxe.RayCast(startpt, dir, 64, ref pos, ref normal)) { //SPAWN PORTAL:********************************************************************* //If the portal is not active, try spawning one if (!portal.activeInHierarchy) { spawnPortal(pos, 0.6f, chunkFloorPos.y); } ///SPAWNING FOR ANIMALS********************************************************************* //Convert the voxel position into a Chunk World Position Vec3Int chunkcoord = vxe.ToGrid(pos) / vxe.chunk_size; //Loads up the BiomeMap through the grid size BIOMES mybiome = biome.biomeMap [chunkcoord.x, chunkcoord.z]; //If there are too many spawns in this Biome, do not spawn more if (spawnCountInBoime [(int)mybiome] > maxToSpawnInBiome) { return; } //randomly chooses an animal to spawn int animalIndex = Random.Range(0, spawnTable [mybiome].SpawnList.Length); GameObject spawnObject = spawnTable [mybiome].SpawnList [animalIndex].gameObject; Chunks chunk = vxe.getChunkFromPt(pos); bool isSurface = vxe.isChunkASurface(DIR.DIR_UP, chunk, .65f); if (spawnTable [mybiome].SpawnList [animalIndex].sticksToWalls || isSurface) // Vector3.Dot (normal, Vector3.up) > 0.999f) { { GameObject newsphere = (GameObject)Instantiate(spawnObject, pos + normal * VoxelExtractionPointCloud.Instance.voxel_size * 0.5f, Quaternion.identity); newsphere.SetActive(true); //SimpleAI ai = newsphere.GetComponent<SimpleAI> (); thingsSpawned.Add(newsphere); //newsphere.GetComponent<GrowScript>().init(pos, normal, (Vector3.Dot (normal,Vector3.up) > 0.999f) ); spawnCountInBoime [(int)mybiome]++; } } }
/// <summary> /// Gets the next environment game objectList /// </summary> /// <returns>The next environment game object.</returns> /// <param name="newBiome">New biome.</param> List<GameObject> getNextEnvironmentGameObject(BIOMES newBiome) { switch (newBiome) { case BIOMES.grass: return grassAssets; case BIOMES.sand: return desertAssets; case BIOMES.ice: return iceAssets; default: //marsh return marshAssets; } }
/// <summary> /// Sets the environment list based on biome. /// </summary> /// <returns>The environment list based on biome.</returns> /// <param name="Pos">Position.</param> List<GameObject> SetEnvironmentListBasedOnBiome(Vector3 Pos) { playerCC = vxe.getChunkCoords (Pos); chunkx = playerCC.x; chunkz = playerCC.z; mybiome = biome.biomeMap [chunkx, chunkz]; return getNextEnvironmentGameObject (mybiome); }
// Use this for initialization void Start() { vxe = VoxelExtractionPointCloud.Instance; biome = BiomeScript.Instance; mybiome = biome.biomeArea [0].biome; occupiedNearMe = new List<Chunks> (); assetChunkTable = new Dictionary<Vec3Int, GameObject> (); if (playerTrans == null) playerTrans = GameObject.FindWithTag ("Player").GetComponent<Transform> (); InitializeEnvironmentBiome (ref desertGameObjects, "DesertAssets", ref desertAssets); InitializeEnvironmentBiome (ref grassGameObjects, "GrassAssets", ref grassAssets); InitializeEnvironmentBiome (ref IceGameObjects, "IceAssets", ref iceAssets); InitializeEnvironmentBiome (ref marshGameObjects, "MarshAssets", ref marshAssets); spawns = new IndexStack<SpawnObject> (new SpawnObject[max_spawns]); StartCoroutine (FullPullSpawn ()); StartCoroutine (MaintainSpawns ()); }
/// <summary> /// Waits to initialize. /// </summary> /// <returns>The to initialize.</returns> IEnumerator waitToInitialize() { while (biome.biomeMap == null) { yield return new WaitForEndOfFrame (); } playerCC = vxe.getChunkCoords (playerTrans.position); mybiome = biome.biomeMap [playerCC.x, playerCC.z]; }