Densité de partie de plantes en fonction du niveau de mutation

This commit is contained in:
Altaezio
2026-04-12 20:10:40 +02:00
parent a432d30c8b
commit e5dea5bb50
7 changed files with 121 additions and 30 deletions

View File

@@ -36,6 +36,7 @@ enum OriginType {BRANCH_ORIGIN, MUTATION_ORIGIN, BASE_LEAF_ORIGIN}
@export var mutation_weight_base := 10
@export var mutation_weight_loss := 3
@export var mutation_weight_gain := 1
@export var seed_texture_sets: Array[SeedTextureSet]
@export var base_y_offset := -50.0
@@ -75,6 +76,9 @@ func shuffle_weighted(array: Array, weights: Array[int]):
array[i] = originalArray[indices[i]]
weights[i] = originalWeights[indices[i]]
func get_mutation_weight(level: int) -> int:
return 3 * level
func build_seed_texture(random_seed: int) -> Texture:
rng.seed = random_seed
@@ -129,7 +133,9 @@ func build_plant_texture(plant_data: PlantData) -> Texture:
for mutation in plant_data.mutations:
if mutation.id in parts_mutation_associations:
parts_to_place[OriginType.MUTATION_ORIGIN].append(parts_mutation_associations[mutation.id].parts)
mutation_weights.append(mutation_weight_base)
var mutation_weight := get_mutation_weight(mutation.level)
mutation_weights.append(mutation_weight)
weight_per_origin_type[OriginType.MUTATION_ORIGIN] += mutation_weight
var flipped: bool = rng.randi() % 2 == 0
@@ -195,6 +201,9 @@ func get_part(all_parts: Dictionary[OriginType, Array], weight_per_origin_type:
weight_per_origin_type[((origin + 2) % 3) as OriginType] += origin_weight_gain
return all_parts[origin][ind]
else: # find a mutation part to place
if weight_copy[originIndInd] < 0:
break
var parts_per_mutations: Array = all_parts[origin]
shuffle_weighted(parts_per_mutations, mutation_weights)
for mutation_parts_ind in range(parts_per_mutations.size()):