Adds basic camp generation and placement
Adds basic camp generation and placement logic to the map generation process. It attempts to place the camp in a valid location, avoiding paths and water bodies. It also sets the player's spawn point to the center of the generated camp, including some basic camp props like a tent, campfire, and bed. Additionally, vegetation spawning is now dependent on the `should_spawn_*` methods of the `CellDataResource`, allowing more control over what spawns where.
This commit is contained in:
parent
3959333534
commit
a1efaf6294
8 changed files with 402 additions and 125 deletions
|
|
@ -14,41 +14,15 @@ var map_data: Array = Global.map_data
|
|||
## Density 0.1 to 0.6 - add bushes, varying quantity TBD
|
||||
## Density 0.1 to 0.4 - add flowers, varying quantity TBD
|
||||
|
||||
# Weighted random selection based on tree chances
|
||||
static func select_weighted_tree(tree_preferences: Dictionary):
|
||||
if tree_preferences.is_empty():
|
||||
return null
|
||||
|
||||
# Calculate total weight
|
||||
var total_weight = 0.0
|
||||
for tree_name in tree_preferences.keys():
|
||||
total_weight += tree_preferences[tree_name]["chance"]
|
||||
|
||||
if total_weight <= 0.0:
|
||||
return null
|
||||
|
||||
# Generate random number between 0 and total_weight
|
||||
var random_value = randf() * total_weight
|
||||
|
||||
# Find which tree this random value corresponds to
|
||||
var cumulative_weight = 0.0
|
||||
for tree_name in tree_preferences.keys():
|
||||
cumulative_weight += tree_preferences[tree_name]["chance"]
|
||||
if random_value <= cumulative_weight:
|
||||
return tree_preferences[tree_name]["resource"]
|
||||
|
||||
# Fallback (shouldn't happen, but just in case)
|
||||
var first_key = tree_preferences.keys()[0]
|
||||
return tree_preferences[first_key]["resource"]
|
||||
|
||||
# Pre-calculate tree distribution for the cell
|
||||
static func generate_cell_with_distribution(x: int, z: int, density: float, path: bool = false, water: bool = false):
|
||||
static func generate_cell_with_distribution(x: int, z: int, density: float, path: bool = false, water: bool = false, camp: bool = false):
|
||||
var cell_data = CellDataResource.new()
|
||||
cell_data.x = x
|
||||
cell_data.z = z
|
||||
cell_data.vegetation_density = density
|
||||
cell_data.camp = camp
|
||||
|
||||
if not (path or water):
|
||||
if not (path or water or camp):
|
||||
if density >= 0.6:
|
||||
var tree_preferences = BiomeData.calculate_tree_probabilities(x, z)
|
||||
var tree_distribution = calculate_tree_distribution(tree_preferences, density)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue