add river bioma gen + label weather random

This commit is contained in:
2026-04-30 23:23:49 +02:00
parent 8c7f1c3c82
commit abae8434fc
9 changed files with 784 additions and 7 deletions

View File

@@ -367,6 +367,7 @@ func _register_cell_with_ray(grid_pos: Vector2i) -> bool:
right_info_node = info_list[0]
var exit_found = {"north": false, "est": false, "south": false, "west": false}
var river_exit_found = {"north": false, "est": false, "south": false, "west": false}
var height_found = {"north": 0, "est": 0, "south": 0, "west": 0}
var have_lamppost = false
@@ -376,6 +377,7 @@ func _register_cell_with_ray(grid_pos: Vector2i) -> bool:
var rotation_steps = roundi(rad_to_deg(right_info_node.global_rotation.y) / -90.0)
var data = right_info_node.get_rotated_data(rotation_steps)
exit_found = data["connections"]
river_exit_found = data["river_connections"]
height_found = data["heights"]
if "have_lamppost" in right_info_node:
@@ -385,6 +387,7 @@ func _register_cell_with_ray(grid_pos: Vector2i) -> bool:
board[grid_pos] = {
"type": "obstacle",
"exit": exit_found,
"river_exit": river_exit_found,
"heights": height_found,
"node": root_chunk,
"info": right_info_node,
@@ -402,6 +405,10 @@ func _add_compatible_biome(grid_pos: Vector2i) -> void:
var req_conn_est = _needed_connection(grid_pos + Vector2i(1, 0), "west")
var req_conn_south = _needed_connection(grid_pos + Vector2i(0, 1), "north")
var req_conn_west = _needed_connection(grid_pos + Vector2i(-1, 0), "est")
var req_river_north = _needed_river_connection(grid_pos + Vector2i(0, -1), "south")
var req_river_est = _needed_river_connection(grid_pos + Vector2i(1, 0), "west")
var req_river_south = _needed_river_connection(grid_pos + Vector2i(0, 1), "north")
var req_river_west = _needed_river_connection(grid_pos + Vector2i(-1, 0), "est")
var req_height_north = _needed_heights(grid_pos + Vector2i(0, -1), "south")
var req_height_est = _needed_heights(grid_pos + Vector2i(1, 0), "west")
@@ -423,12 +430,17 @@ func _add_compatible_biome(grid_pos: Vector2i) -> void:
var rot = candidate["rotation"]
var data = candidate["data"]
var u_conn = data["connections"]
var u_river_conn = data["river_connections"]
var u_height = data["heights"]
var match_conn_n = (req_conn_north == -1) or ((req_conn_north == 1) == u_conn["north"])
var match_conn_e = (req_conn_est == -1) or ((req_conn_est == 1) == u_conn["est"])
var match_conn_s = (req_conn_south == -1) or ((req_conn_south == 1) == u_conn["south"])
var match_conn_o = (req_conn_west == -1) or ((req_conn_west == 1) == u_conn["west"])
var match_river_n = (req_river_north == -1) or ((req_river_north == 1) == u_river_conn["north"])
var match_river_e = (req_river_est == -1) or ((req_river_est == 1) == u_river_conn["est"])
var match_river_s = (req_river_south == -1) or ((req_river_south == 1) == u_river_conn["south"])
var match_river_o = (req_river_west == -1) or ((req_river_west == 1) == u_river_conn["west"])
var match_alt_n = (req_height_north == -1) or (req_height_north == u_height["north"])
var match_alt_e = (req_height_est == -1) or (req_height_est == u_height["est"])
@@ -441,7 +453,7 @@ func _add_compatible_biome(grid_pos: Vector2i) -> void:
var diff_o = abs(u_height["west"] - height_target) if req_height_west == -1 else 0
var excessive_jumps = diff_n > 1 or diff_e > 1 or diff_s > 1 or diff_o > 1
if match_conn_n and match_conn_e and match_conn_s and match_conn_o and match_alt_n and match_alt_e and match_alt_s and match_alt_o and not excessive_jumps:
if match_conn_n and match_conn_e and match_conn_s and match_conn_o and match_river_n and match_river_e and match_river_s and match_river_o and match_alt_n and match_alt_e and match_alt_s and match_alt_o and not excessive_jumps:
var score = 0
if req_height_north == -1 and u_height["north"] == height_target: score += 1
if req_height_est == -1 and u_height["est"] == height_target: score += 1
@@ -474,6 +486,7 @@ func _add_compatible_biome(grid_pos: Vector2i) -> void:
board[grid_pos] = {
"type": "bioma",
"exit": choise.data["connections"],
"river_exit": choise.data["river_connections"],
"heights": choise.data["heights"],
"node": new_chunk,
"info": info_new,
@@ -499,6 +512,7 @@ func _add_compatible_biome(grid_pos: Vector2i) -> void:
board[grid_pos] = {
"type": "biome",
"exit": {"north":false, "est":false, "south":false, "west":false},
"river_exit": {"north":false, "est":false, "south":false, "west":false},
"heights": safe_heights,
"node": backup,
"info": info_backup,
@@ -512,6 +526,13 @@ func _needed_connection(near_pos: Vector2i, side_needed: String) -> int:
return 1 if board[near_pos]["exit"][side_needed] else 0
return -1
func _needed_river_connection(near_pos: Vector2i, side_needed: String) -> int:
if not board.has(near_pos):
_register_cell_with_ray(near_pos)
if board.has(near_pos) and board[near_pos].has("river_exit"):
return 1 if board[near_pos]["river_exit"][side_needed] else 0
return -1
func _needed_heights(near_pos: Vector2i, side_needed: String) -> int:
if board.has(near_pos) and board[near_pos].has("heights"):
return board[near_pos]["heights"][side_needed]

View File

@@ -12,6 +12,12 @@ class_name ChunkInfo
@export var south: bool = false
@export var west: bool = false
@export_group("River exit")
@export var river_north: bool = false
@export var river_est: bool = false
@export var river_south: bool = false
@export var river_west: bool = false
@export_group("Margin heights (level 0, 1, 2)")
@export_range(0, 2, 1) var height_north: int = 0
@export_range(0, 2, 1) var height_est: int = 0
@@ -29,14 +35,17 @@ func _ready() -> void:
func get_rotated_data(steps_90: int) -> Dictionary:
var original_exit = [north, est, south, west]
var original_river_exit = [river_north, river_est, river_south, river_west]
var original_height = [height_north, height_est, height_south, height_west]
var calculated_exit = []
var calculated_river_exit = []
var calculated_height = []
for i in range(4):
var index = (i - steps_90 + 4) % 4
calculated_exit.append(original_exit[index])
calculated_river_exit.append(original_river_exit[index])
calculated_height.append(original_height[index])
return {
@@ -44,6 +53,10 @@ func get_rotated_data(steps_90: int) -> Dictionary:
"north": calculated_exit[0], "est": calculated_exit[1],
"south": calculated_exit[2], "west": calculated_exit[3]
},
"river_connections": {
"north": calculated_river_exit[0], "est": calculated_river_exit[1],
"south": calculated_river_exit[2], "west": calculated_river_exit[3]
},
"heights": {
"north": calculated_height[0], "est": calculated_height[1],
"south": calculated_height[2], "west": calculated_height[3]