/// <summary> /// Places assets, such as houses and trees, in the world. /// It does not let objects collide with eachother during the build /// </summary> /// <param name="map"></param> public void ApplyAssets(TDMapII map) { int[] base_map = map.getBasePosition(); BasePos = new Vector3(150 - base_map[1], 0, 150 - base_map[0]); PlaceBase(); int[] Village = map.getVillages(); int[][] Forrests = map.getForrests(); int x_pos = Village[0]; int y_pos = Village[1]; for (int i = 0; i < 8; i++) { if (HousePos.Count == 60) break; for (int j = 0; j < 8; j++) { if (HousePos.Count == 60) break; int x = y_pos - 35 + 10 * i; int z = x_pos - 35 + 10 * j; Vector3 Pos = new Vector3(150 - x + offset, 5f, 150 - z + offset); if (HousePossible(z, x, map, 3) && ObjPossible(HousePos, Pos, 5)) { Vector3 Rot = new Vector3(-90, Random.Range(0, 2) * -90, 0); GameObject huisje = (GameObject)Instantiate(C_Building, Pos, Quaternion.identity); huisje.transform.Rotate(Rot); HousePos.Add(Pos); HouseInfo.Add(new Vector3[2] { Pos, Rot }); } } } nrHotels = HousePos.Count; float misses = 30; while (HousePos.Count <= nrHouses) { if (misses <= 0) break; int x = Random.Range(30, 270); int z = Random.Range(30, 270); Vector3 Pos = new Vector3(150 - x + offset, 0.8f, 150 - z + offset); if (HousePossible(z, x, map, 7) && ObjPossible(HousePos, Pos, 30)) { Vector3 Rot = new Vector3(90, Random.Range(0, 360), 0); GameObject huisje = (GameObject)Instantiate(House, Pos, Quaternion.identity); huisje.transform.Rotate(Rot); HousePos.Add(Pos); HouseInfo.Add(new Vector3[2] { Pos, Rot }); } else { misses--; } } //Debug.Log("misses left(house): " + misses + "\n nr houses: " + HousePos.Count); foreach (int[] forrest in Forrests) { int x_posF = forrest[0]; int y_posF = forrest[1]; int minF = forrest[2]; int maxF = forrest[3]; misses = 10; for (int i = 0; i < maxF*2; i++) { if (misses <= 0) break; int x = Random.Range(minF, maxF) + y_posF; int z = Random.Range(minF, maxF) + x_posF; Vector3 Pos = new Vector3(150 - x + offset, 0, 150 - z + offset); if (CheckIfPlacableTile(z, x, map) && ObjPossible(TreePos, Pos, 2) && ObjPossible(HousePos, Pos, 6)) { float nr = Random.Range(0f, 1f); if(nr >= .4) { Instantiate(Tree, Pos, Quaternion.identity); } else if (nr < .4) { Pos.y = 0.8f; Instantiate(PineTree, Pos, new Quaternion(-0.7071f, 0, 0, 0.7071f)); //PineTree } TreePos.Add(Pos); } else { misses--; } } } misses = 25; while (TreePos.Count <= nrTrees) { if (misses <= 0) break; int x = Random.Range(30, 270); int z = Random.Range(30, 270); Vector3 Pos = new Vector3(150 - x + offset, 0, 150 - z + offset); if (CheckIfPlacableTile(z, x, map) && ObjPossible(TreePos, Pos, 2) && ObjPossible(HousePos, Pos, 6)) { float nr = Random.Range(0f, 1f); if (nr >= .4) { Instantiate(Tree, Pos, Quaternion.identity); } else if (nr < .4) { Pos.y = 0.8f; Instantiate(PineTree, Pos, new Quaternion(-0.7071f, 0, 0, 0.7071f)); //PineTree } TreePos.Add(Pos); } else { misses--; } } for (int i = nrHotels; i < HousePos.Count; i++) { Vector3 Pos = HousePos[i]; int x = (int)(150 - Pos.z - offset); int z = (int)(150 - Pos.x - offset); if (HousePossible(z, x, map, 15) && ObjPossible(TreePos, Pos, 10)) { Pos.y = 0; placeWalls(Pos); WallsPos.Add(Pos); } } }