|
|
|
|
@ -16,39 +16,32 @@ export(int) var river_proba = 200 |
|
|
|
|
var rng = RandomNumberGenerator.new() |
|
|
|
|
var noise = OpenSimplexNoise.new() |
|
|
|
|
|
|
|
|
|
var terrain |
|
|
|
|
|
|
|
|
|
func _ready(): |
|
|
|
|
rng.randomize() |
|
|
|
|
noise.seed = rng.randi() |
|
|
|
|
noise.octaves = octaves |
|
|
|
|
|
|
|
|
|
# var Global.terrain_name="bonjour90" |
|
|
|
|
terrain = Global.terrain |
|
|
|
|
|
|
|
|
|
print(terrain.list()) |
|
|
|
|
|
|
|
|
|
if terrain.exists(Global.terrain_name): |
|
|
|
|
terrain.load(Global.terrain_name) |
|
|
|
|
|
|
|
|
|
if Global.terrain.exists(Global.terrain_name): |
|
|
|
|
Global.terrain.load(Global.terrain_name) |
|
|
|
|
else: |
|
|
|
|
terrain.create(width,height,spacing,Global.terrain_name) |
|
|
|
|
Global.terrain.create(width,height,spacing,Global.terrain_name) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if terrain.is_created(): |
|
|
|
|
if Global.terrain.is_created(): |
|
|
|
|
init_data() |
|
|
|
|
terrain.save_data() |
|
|
|
|
Global.terrain.save_data() |
|
|
|
|
|
|
|
|
|
if terrain.is_created() or terrain.is_loaded(): |
|
|
|
|
|
|
|
|
|
if Global.terrain.is_created() or Global.terrain.is_loaded(): |
|
|
|
|
Global.terrain.load_data(Global.terrain_name) |
|
|
|
|
add_trees() |
|
|
|
|
emit_signal("world_loaded", terrain) |
|
|
|
|
emit_signal("world_loaded") |
|
|
|
|
else: |
|
|
|
|
Global.print_debug("Pas de terrain, pas de construction ...") |
|
|
|
|
Global.print_debug("Pas de Global.terrain, pas de construction ...") |
|
|
|
|
Global.print_debug("Pas de construction ..., pas de palais ...") |
|
|
|
|
Global.print_debug("Pas de palais ..., pas de palais.") |
|
|
|
|
|
|
|
|
|
func init_data(): |
|
|
|
|
# for point in terrain.get_points(): |
|
|
|
|
# for point in Global.terrain.get_points(): |
|
|
|
|
# point.set_elevation(point_find_elevation(point.point2d())) |
|
|
|
|
# point.set_data("water", point_is_water(point)) |
|
|
|
|
# point.set_data("mountain", point_is_mountain(point)) |
|
|
|
|
@ -56,14 +49,14 @@ func init_data(): |
|
|
|
|
|
|
|
|
|
# fill_oceans() |
|
|
|
|
|
|
|
|
|
# for point in terrain.get_points(): |
|
|
|
|
# for point in Global.terrain.get_points(): |
|
|
|
|
# if point.get_data("water") and not point.get_data("ocean"): |
|
|
|
|
# point.set_elevation(0.1) |
|
|
|
|
# point.set_data("water", false) |
|
|
|
|
# point.set_data("coast", point_is_coast(point)) |
|
|
|
|
# if point.get_data("river"): |
|
|
|
|
# set_river_path(point) |
|
|
|
|
for triangle in terrain.get_triangles(): |
|
|
|
|
for triangle in Global.terrain.get_triangles(): |
|
|
|
|
triangle.set_elevation(find_elevation(triangle.center2d())) |
|
|
|
|
# triangle.set_data("elevation", triangle_find_elevation(triangle)) |
|
|
|
|
triangle.set_data("water", triangle_is_water(triangle)) |
|
|
|
|
@ -76,19 +69,19 @@ func init_data(): |
|
|
|
|
# for point in triangle.points(): |
|
|
|
|
# if point.get_data("ocean"): |
|
|
|
|
# triangle.set_data("ocean", true) |
|
|
|
|
# for edge in terrain.get_edges(): |
|
|
|
|
# for edge in Global.terrain.get_edges(): |
|
|
|
|
# edge.set_data("coast", edge_is_coast(edge)) |
|
|
|
|
# edge.set_data("river", edge_is_river(edge)) |
|
|
|
|
|
|
|
|
|
func fill_oceans(): |
|
|
|
|
var stack = [] |
|
|
|
|
for point in terrain.get_points(): |
|
|
|
|
for point in Global.terrain.get_points(): |
|
|
|
|
if point.point2d().x < 10 and point.get_data("water") and not point.get_data("ocean"): |
|
|
|
|
stack.append(point.get_index()) |
|
|
|
|
while stack.size(): |
|
|
|
|
var current_point_id = stack.pop_back() |
|
|
|
|
terrain.get_point(current_point_id).set_data("ocean", true) |
|
|
|
|
for neighbour in terrain.get_point(current_point_id).points_around(): |
|
|
|
|
Global.terrain.get_point(current_point_id).set_data("ocean", true) |
|
|
|
|
for neighbour in Global.terrain.get_point(current_point_id).points_around(): |
|
|
|
|
if neighbour.get_data("water") and not neighbour.get_data("ocean"): |
|
|
|
|
stack.append(neighbour.get_index()) |
|
|
|
|
break |
|
|
|
|
@ -103,13 +96,13 @@ func set_river_path(point): |
|
|
|
|
|
|
|
|
|
while stack.size(): |
|
|
|
|
var current_point_id = stack.pop_front() |
|
|
|
|
if terrain.get_point(current_point_id).get_elevation() < start_elevation: |
|
|
|
|
if Global.terrain.get_point(current_point_id).get_elevation() < start_elevation: |
|
|
|
|
waypoints.append(current_point_id) |
|
|
|
|
start_elevation = terrain.get_point(current_point_id).get_elevation() |
|
|
|
|
start_elevation = Global.terrain.get_point(current_point_id).get_elevation() |
|
|
|
|
stack = [] |
|
|
|
|
if terrain.get_point(current_point_id).get_data("ocean"): |
|
|
|
|
if Global.terrain.get_point(current_point_id).get_data("ocean"): |
|
|
|
|
break |
|
|
|
|
for neighbour in terrain.get_point(current_point_id).points_around(): |
|
|
|
|
for neighbour in Global.terrain.get_point(current_point_id).points_around(): |
|
|
|
|
if not came_from.has(neighbour.get_index()): |
|
|
|
|
stack.append(neighbour.get_index()) |
|
|
|
|
came_from[neighbour.get_index()] = current_point_id |
|
|
|
|
@ -124,8 +117,8 @@ func set_river_path(point): |
|
|
|
|
|
|
|
|
|
path.append(point.get_index()) |
|
|
|
|
for index in path: |
|
|
|
|
terrain.get_point(index).set_data("river", true) |
|
|
|
|
# terrain.get_point(index).set_data("water", true) |
|
|
|
|
Global.terrain.get_point(index).set_data("river", true) |
|
|
|
|
# Global.terrain.get_point(index).set_data("water", true) |
|
|
|
|
|
|
|
|
|
# Point |
|
|
|
|
|
|
|
|
|
@ -207,7 +200,7 @@ func edge_is_river(edge): |
|
|
|
|
func add_trees(): |
|
|
|
|
rng.randomize() |
|
|
|
|
var treescene = load("res://entities/environment/birchtree/birchtree.tscn") |
|
|
|
|
for triangle in terrain.get_triangles(): |
|
|
|
|
for triangle in Global.terrain.get_triangles(): |
|
|
|
|
if not triangle.get_data("water"): |
|
|
|
|
var num = rng.randi_range(0, 5) |
|
|
|
|
if num == 1: |
|
|
|
|
|