public int GetGenerationChances(Tree_ tree, float temperature, float moisture) { int generationChances = 0; TreeStats_ treeStats = (TreeStats_)tree.mechanics_.stats_; if (treeStats.biome.IsSupported(temperature, moisture)) { generationChances = treeStats.biome.GetGenerationChances(temperature, moisture); } return(generationChances); }
public static void Main(string[] args) { int n = int.Parse(Console.ReadLine()); Tree_ tree = new Tree_(); for (int i = 0; i < n; i++) { char[] ch = Array.ConvertAll(Console.ReadLine().Split(' '), s => char.Parse(s)); tree.Add(ch[0], ch[1], ch[2]); } tree.Preorder(tree.root); Console.WriteLine(); tree.Inorder(tree.root); Console.WriteLine(); tree.Postorder(tree.root); }
public void Build() { world.mechanics.stats.mapSize = mapSize; world.mechanics.stats.limitTemperatures = limitTemperatures; Tilemap baseGroundTilemap = world.graphics.grid.worldBaseGround_.baseGroundTilemap; Tilemap grassTilemap = world.graphics.grid.grassTilemap; Tilemap sandTilemap = world.graphics.grid.sandTilemap; for (int yPosition = 0; yPosition < mapSize.y; yPosition++) { float calculatedTemperature = (((limitTemperatures.y - limitTemperatures.x) * yPosition) / mapSize.y) + limitTemperatures.x; float maxMoisture = -(50 * (calculatedTemperature - possibleLimitTemperatures.y) / (possibleLimitTemperatures.x - possibleLimitTemperatures.y)) + 100; float minMoisture = 100 - maxMoisture; Vector2 moistureLimits = new Vector2(maxMoisture, minMoisture); for (int xPosition = 0; xPosition < mapSize.x; xPosition++) { float calculatedMoisture = (((moistureLimits.x - moistureLimits.y) * (xPosition - 0)) / (mapSize.x - 1 - 0)) + moistureLimits.y; Vector3Int position = new Vector3Int(xPosition, yPosition, 0); //Generate ground components Tile ground = groundGenerator.GenerateGround(calculatedTemperature, calculatedMoisture); baseGroundTilemap.SetTile(position, ground); //Generate trees Tree_ tree = treeGenerator.GenerateTree(calculatedTemperature, calculatedMoisture); if (tree != null) { if (Random.Range(1, 4) == 1) { if (Random.Range(1, 100) <= ((TreeStats_)tree.mechanics_.stats_).biome.treeDensity) { Tree_ newTree = Instantiate(tree, baseGroundTilemap.CellToWorld(position), Quaternion.identity); newTree.transform.SetParent(trees.transform); } } } } } }
public Tree_ GenerateTree(float temperature, float moisture) { List <Tree_> treesToRandomGeneration = new List <Tree_>(); foreach (Tree_ tree in trees) { tree.Build(); int generationChances = GetGenerationChances(tree, temperature, moisture); for (int i = 1; i < generationChances; i++) { treesToRandomGeneration.Add(tree); } } if (treesToRandomGeneration.Count > 0) { Tree_ tree = treesToRandomGeneration[Random.Range(0, treesToRandomGeneration.Count)]; return(tree); } else { return(null); } }