Much stuff wow
This commit is contained in:
parent
7255cbdf64
commit
734730beee
45 changed files with 697 additions and 119 deletions
47
Utilities/BiomeGeneration/BiomeData.gd
Normal file
47
Utilities/BiomeGeneration/BiomeData.gd
Normal file
|
|
@ -0,0 +1,47 @@
|
|||
class_name BiomeDataClass
|
||||
extends Node
|
||||
|
||||
var tree_collection = preload("res://Entities/Tree/Resources/TreeData.tres") as TreeDataCollection
|
||||
|
||||
# Calculate spawn probability for each tree type
|
||||
func calculate_tree_probabilities(x: int, z: int) -> Dictionary:
|
||||
if Global.biome_data == null:
|
||||
Log.pr("Biome data not initialized. Call generate_environment_maps first.")
|
||||
return {}
|
||||
|
||||
if x > Global.map_data.size() and x <= 0:
|
||||
if z > Global.map_data[x].size() and z <= 0:
|
||||
Log.pr("Coordinates out of bounds: (%d, %d)" % [x, z])
|
||||
return {}
|
||||
|
||||
var moisture = Global.biome_data.moisture.get_pixel(x, z).r
|
||||
var temperature = Global.biome_data.temperature.get_pixel(x, z).r
|
||||
var elevation = Global.biome_data.elevation.get_pixel(x, z).r
|
||||
|
||||
var probabilities = {}
|
||||
|
||||
for tree in tree_collection.trees:
|
||||
# Calculate suitability for each environmental factor
|
||||
var moisture_suit = calculate_suitability(moisture, tree.moisture_range[0], tree.moisture_range[1])
|
||||
var temp_suit = calculate_suitability(temperature, tree.temperature_range[0], tree.temperature_range[1])
|
||||
var elev_suit = calculate_suitability(elevation, tree.elevation_range[0], tree.elevation_range[1])
|
||||
|
||||
# Combined probability
|
||||
probabilities[tree.tree_name] = {}
|
||||
probabilities[tree.tree_name]['chance'] = moisture_suit * temp_suit * elev_suit
|
||||
probabilities[tree.tree_name]['resource'] = tree
|
||||
|
||||
return probabilities
|
||||
|
||||
func calculate_suitability(value: float, min_pref: float, max_pref: float) -> float:
|
||||
if value >= min_pref and value <= max_pref:
|
||||
return 1.0
|
||||
else:
|
||||
var distance_outside = 0.0
|
||||
if value < min_pref:
|
||||
distance_outside = min_pref - value
|
||||
else:
|
||||
distance_outside = value - max_pref
|
||||
|
||||
# Exponential decay - drops very quickly
|
||||
return max(0.01, exp(-distance_outside * 10.0))
|
||||
1
Utilities/BiomeGeneration/BiomeData.gd.uid
Normal file
1
Utilities/BiomeGeneration/BiomeData.gd.uid
Normal file
|
|
@ -0,0 +1 @@
|
|||
uid://by8rwvoabdrgn
|
||||
35
Utilities/BiomeGeneration/BiomeGeneration.gd
Normal file
35
Utilities/BiomeGeneration/BiomeGeneration.gd
Normal file
|
|
@ -0,0 +1,35 @@
|
|||
class_name BiomeGenerationClass
|
||||
extends Node
|
||||
|
||||
# Generate environmental maps
|
||||
static func generate_environment_maps(width: int, height: int) -> Dictionary:
|
||||
var moisture_noise = FastNoiseLite.new()
|
||||
moisture_noise.seed = 12345
|
||||
moisture_noise.frequency = 0.02
|
||||
|
||||
var temperature_noise = FastNoiseLite.new()
|
||||
temperature_noise.seed = 54321
|
||||
temperature_noise.frequency = 0.015
|
||||
|
||||
var elevation_noise = FastNoiseLite.new()
|
||||
elevation_noise.seed = 98765
|
||||
elevation_noise.frequency = 0.01
|
||||
|
||||
var maps = {}
|
||||
maps.moisture = Image.create(width, height, false, Image.FORMAT_RF)
|
||||
maps.temperature = Image.create(width, height, false, Image.FORMAT_RF)
|
||||
maps.elevation = Image.create(width, height, false, Image.FORMAT_RF)
|
||||
|
||||
for x in range(width):
|
||||
for y in range(height):
|
||||
var moisture = (moisture_noise.get_noise_2d(x, y) + 1.0) * 0.5
|
||||
var temperature = (temperature_noise.get_noise_2d(x, y) + 1.0) * 0.5
|
||||
var elevation = (elevation_noise.get_noise_2d(x, y) + 1.0) * 0.5
|
||||
|
||||
maps.moisture.set_pixel(x, y, Color(moisture, 0, 0, 1))
|
||||
maps.temperature.set_pixel(x, y, Color(temperature, 0, 0, 1))
|
||||
maps.elevation.set_pixel(x, y, Color(elevation, 0, 0, 1))
|
||||
|
||||
Global.biome_data = maps
|
||||
|
||||
return maps
|
||||
1
Utilities/BiomeGeneration/BiomeGeneration.gd.uid
Normal file
1
Utilities/BiomeGeneration/BiomeGeneration.gd.uid
Normal file
|
|
@ -0,0 +1 @@
|
|||
uid://ddle3veoss0ny
|
||||
Loading…
Add table
Add a link
Reference in a new issue