mirror of
https://github.com/Relintai/broken_seals.git
synced 2024-11-13 20:47:19 +01:00
Ported the current world generator to the new addon. Now the world in-game uses the new world generator's resource to generate the terrain.
This commit is contained in:
parent
3adfad40a2
commit
0c96328005
@ -27,6 +27,31 @@ func create_content(item_name : String = "") -> void:
|
|||||||
func remove_content_entry(entry : WorldGenBaseResource) -> void:
|
func remove_content_entry(entry : WorldGenBaseResource) -> void:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
func get_content_with_name(name : String) -> WorldGenBaseResource:
|
||||||
|
if resource_name == name:
|
||||||
|
return self
|
||||||
|
|
||||||
|
for c in get_content():
|
||||||
|
if c:
|
||||||
|
var cc = c.get_content_with_name(name)
|
||||||
|
if cc:
|
||||||
|
return cc
|
||||||
|
|
||||||
|
return null
|
||||||
|
|
||||||
|
func get_all_contents_with_name(name : String) -> Array:
|
||||||
|
var arr : Array = Array()
|
||||||
|
|
||||||
|
if resource_name == name:
|
||||||
|
arr.append(self)
|
||||||
|
|
||||||
|
for c in get_content():
|
||||||
|
if c:
|
||||||
|
var cc : Array = c.get_all_contents_with_name(name)
|
||||||
|
arr.append_array(cc)
|
||||||
|
|
||||||
|
return arr
|
||||||
|
|
||||||
func duplicate_content_entry(entry : WorldGenBaseResource) -> void:
|
func duplicate_content_entry(entry : WorldGenBaseResource) -> void:
|
||||||
var de : WorldGenBaseResource = entry.duplicate(true)
|
var de : WorldGenBaseResource = entry.duplicate(true)
|
||||||
de.resource_name += " (Duplicate)"
|
de.resource_name += " (Duplicate)"
|
||||||
@ -43,6 +68,25 @@ func _setup_terra_library(library : TerramanLibrary, pseed : int) -> void:
|
|||||||
pass
|
pass
|
||||||
|
|
||||||
func generate_terra_chunk(chunk: TerraChunk, pseed : int, spawn_mobs: bool) -> void:
|
func generate_terra_chunk(chunk: TerraChunk, pseed : int, spawn_mobs: bool) -> void:
|
||||||
|
generate_terra_chunk_internal(chunk, pseed, spawn_mobs, get_rect())
|
||||||
|
|
||||||
|
func generate_terra_chunk_internal(chunk: TerraChunk, pseed : int, spawn_mobs: bool, world_parent_rect : Rect2) -> void:
|
||||||
|
var wcr : Rect2 = get_rect()
|
||||||
|
wcr.position += world_parent_rect.position
|
||||||
|
|
||||||
|
var p : Vector2 = Vector2(chunk.get_position_x(), chunk.get_position_z())
|
||||||
|
|
||||||
|
#TODO
|
||||||
|
#if !wcr.has_point(p):
|
||||||
|
# return
|
||||||
|
|
||||||
|
_generate_terra_chunk(chunk, spawn_mobs, spawn_mobs)
|
||||||
|
|
||||||
|
for c in get_content():
|
||||||
|
if c:
|
||||||
|
c.generate_terra_chunk_internal(chunk, pseed, spawn_mobs, wcr)
|
||||||
|
|
||||||
|
func _generate_terra_chunk(chunk: TerraChunk, pseed : int, spawn_mobs: bool) -> void:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
func generate_map(pseed : int) -> Image:
|
func generate_map(pseed : int) -> Image:
|
||||||
|
39
game/modules/planets/test_planet/test_world.tres
Normal file
39
game/modules/planets/test_planet/test_world.tres
Normal file
@ -0,0 +1,39 @@
|
|||||||
|
[gd_resource type="Resource" load_steps=11 format=2]
|
||||||
|
|
||||||
|
[ext_resource path="res://addons/world_generator/resources/world_gen_world.gd" type="Script" id=1]
|
||||||
|
[ext_resource path="res://world_generator/continents/test_continent.gd" type="Script" id=2]
|
||||||
|
[ext_resource path="res://world_generator/zones/test_zone.gd" type="Script" id=3]
|
||||||
|
[ext_resource path="res://world_generator/subzones/spawner.gd" type="Script" id=4]
|
||||||
|
[ext_resource path="res://modules/planets/test_planet/dungeons/dung_teleporter.tscn" type="PackedScene" id=5]
|
||||||
|
[ext_resource path="res://modules/planets/test_planet/biomes/simple_biome/low_poly_rpg_item_collection_3/t1.tres" type="PropData" id=6]
|
||||||
|
[ext_resource path="res://modules/planets/test_planet/biomes/simple_biome/low_poly_rpg_item_collection_3/t2.tres" type="PropData" id=7]
|
||||||
|
|
||||||
|
[sub_resource type="Resource" id=2]
|
||||||
|
resource_name = "Spawner"
|
||||||
|
script = ExtResource( 4 )
|
||||||
|
rect = Rect2( 55, 78, 22, 25 )
|
||||||
|
locked = false
|
||||||
|
|
||||||
|
[sub_resource type="Resource" id=3]
|
||||||
|
resource_name = "TestForest"
|
||||||
|
script = ExtResource( 3 )
|
||||||
|
rect = Rect2( 39, 35, 142, 171 )
|
||||||
|
locked = false
|
||||||
|
subzones = [ SubResource( 2 ) ]
|
||||||
|
|
||||||
|
[sub_resource type="Resource" id=1]
|
||||||
|
resource_name = "Continent"
|
||||||
|
script = ExtResource( 2 )
|
||||||
|
rect = Rect2( 30, 15, 434, 459 )
|
||||||
|
locked = false
|
||||||
|
zones = [ SubResource( 3 ) ]
|
||||||
|
dungeon_teleporter = ExtResource( 5 )
|
||||||
|
prop_tree = ExtResource( 6 )
|
||||||
|
prop_tree2 = ExtResource( 7 )
|
||||||
|
|
||||||
|
[resource]
|
||||||
|
resource_name = "TestWorld"
|
||||||
|
script = ExtResource( 1 )
|
||||||
|
rect = Rect2( -250, -250, 500, 500 )
|
||||||
|
locked = false
|
||||||
|
continents = [ SubResource( 1 ) ]
|
@ -234,6 +234,11 @@ _global_script_classes=[ {
|
|||||||
"language": "GDScript",
|
"language": "GDScript",
|
||||||
"path": "res://addons/world_generator/resources/subzone.gd"
|
"path": "res://addons/world_generator/resources/subzone.gd"
|
||||||
}, {
|
}, {
|
||||||
|
"base": "TerramanLevelGenerator",
|
||||||
|
"class": "TerraWorldGenerator",
|
||||||
|
"language": "GDScript",
|
||||||
|
"path": "res://scripts/world_generators/TerraWorldGenerator.gd"
|
||||||
|
}, {
|
||||||
"base": "GameModule",
|
"base": "GameModule",
|
||||||
"class": "UIGuiChildModule",
|
"class": "UIGuiChildModule",
|
||||||
"language": "GDScript",
|
"language": "GDScript",
|
||||||
@ -310,6 +315,7 @@ _global_script_class_icons={
|
|||||||
"SpellEffectVisualBasic": "",
|
"SpellEffectVisualBasic": "",
|
||||||
"SpellGD": "",
|
"SpellGD": "",
|
||||||
"SubZone": "",
|
"SubZone": "",
|
||||||
|
"TerraWorldGenerator": "",
|
||||||
"UIGuiChildModule": "",
|
"UIGuiChildModule": "",
|
||||||
"UIWindowModule": "",
|
"UIWindowModule": "",
|
||||||
"WorldGenBaseResource": "",
|
"WorldGenBaseResource": "",
|
||||||
|
45
game/scripts/world_generators/TerraWorldGenerator.gd
Normal file
45
game/scripts/world_generators/TerraWorldGenerator.gd
Normal file
@ -0,0 +1,45 @@
|
|||||||
|
tool
|
||||||
|
extends TerramanLevelGenerator
|
||||||
|
class_name TerraWorldGenerator
|
||||||
|
|
||||||
|
# Copyright (c) 2019-2021 Péter Magyar
|
||||||
|
#
|
||||||
|
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
# of this software and associated documentation files (the "Software"), to deal
|
||||||
|
# in the Software without restriction, including without limitation the rights
|
||||||
|
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
# copies of the Software, and to permit persons to whom the Software is
|
||||||
|
# furnished to do so, subject to the following conditions:
|
||||||
|
#
|
||||||
|
# The above copyright notice and this permission notice shall be included in all
|
||||||
|
# copies or substantial portions of the Software.
|
||||||
|
#
|
||||||
|
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
|
# SOFTWARE.
|
||||||
|
|
||||||
|
export(int) var _level_seed : int
|
||||||
|
export(bool) var _spawn_mobs : bool
|
||||||
|
export(Resource) var world_gen_world : Resource = null
|
||||||
|
|
||||||
|
var _world : TerraWorld
|
||||||
|
var _library : TerramanLibrary
|
||||||
|
|
||||||
|
func setup(world : TerraWorld, level_seed : int, spawn_mobs : bool, library: TerramanLibrary) -> void:
|
||||||
|
_level_seed = level_seed
|
||||||
|
_spawn_mobs = spawn_mobs
|
||||||
|
_library = library
|
||||||
|
|
||||||
|
if world_gen_world != null:
|
||||||
|
world_gen_world.setup_terra_library(_library, _level_seed)
|
||||||
|
_library.refresh_rects()
|
||||||
|
|
||||||
|
func _generate_chunk(chunk : TerraChunk) -> void:
|
||||||
|
if world_gen_world == null:
|
||||||
|
return
|
||||||
|
|
||||||
|
world_gen_world.generate_terra_chunk(chunk, _level_seed, _spawn_mobs)
|
@ -1,18 +1,10 @@
|
|||||||
[gd_scene load_steps=10 format=2]
|
[gd_scene load_steps=8 format=2]
|
||||||
|
|
||||||
[ext_resource path="res://tw/new_terramanlibrarymergerpcm.tres" type="TerramanLibraryMergerPCM" id=1]
|
[ext_resource path="res://tw/new_terramanlibrarymergerpcm.tres" type="TerramanLibraryMergerPCM" id=1]
|
||||||
[ext_resource path="res://tw/TerraWorldBlocky.gd" type="Script" id=2]
|
[ext_resource path="res://tw/TerraWorldBlocky.gd" type="Script" id=2]
|
||||||
[ext_resource path="res://scripts/world_generators/MainTPlanetGenerator.gd" type="Script" id=3]
|
[ext_resource path="res://tw/world_generator.tres" type="TerramanLevelGenerator" id=3]
|
||||||
[ext_resource path="res://scripts/settings/DirectionalLightSettings.gd" type="Script" id=4]
|
[ext_resource path="res://scripts/settings/DirectionalLightSettings.gd" type="Script" id=4]
|
||||||
[ext_resource path="res://test_props/MeshDataInstance.tres" type="PropData" id=5]
|
[ext_resource path="res://test_props/MeshDataInstance.tres" type="PropData" id=5]
|
||||||
[ext_resource path="res://modules/planets/test_planet/DungeonPlanetData.tres" type="Planet" id=6]
|
|
||||||
|
|
||||||
[sub_resource type="TerramanLevelGenerator" id=1]
|
|
||||||
script = ExtResource( 3 )
|
|
||||||
_force_planet = -1
|
|
||||||
_level_seed = 0
|
|
||||||
_spawn_mobs = false
|
|
||||||
planet = ExtResource( 6 )
|
|
||||||
|
|
||||||
[sub_resource type="ProceduralSky" id=2]
|
[sub_resource type="ProceduralSky" id=2]
|
||||||
sky_top_color = Color( 0.34902, 0.643137, 0.705882, 1 )
|
sky_top_color = Color( 0.34902, 0.643137, 0.705882, 1 )
|
||||||
@ -58,7 +50,7 @@ glow_hdr_luminance_cap = 1.0
|
|||||||
[node name="World" type="TerraWorldBlocky"]
|
[node name="World" type="TerraWorldBlocky"]
|
||||||
world_height = 100.0
|
world_height = 100.0
|
||||||
library = ExtResource( 1 )
|
library = ExtResource( 1 )
|
||||||
level_generator = SubResource( 1 )
|
level_generator = ExtResource( 3 )
|
||||||
voxel_scale = 3.0
|
voxel_scale = 3.0
|
||||||
build_flags = 510
|
build_flags = 510
|
||||||
num_lods = 5
|
num_lods = 5
|
||||||
|
10
game/tw/world_generator.tres
Normal file
10
game/tw/world_generator.tres
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
[gd_resource type="TerramanLevelGenerator" load_steps=3 format=2]
|
||||||
|
|
||||||
|
[ext_resource path="res://scripts/world_generators/TerraWorldGenerator.gd" type="Script" id=1]
|
||||||
|
[ext_resource path="res://modules/planets/test_planet/test_world.tres" type="Resource" id=2]
|
||||||
|
|
||||||
|
[resource]
|
||||||
|
script = ExtResource( 1 )
|
||||||
|
_level_seed = 0
|
||||||
|
_spawn_mobs = true
|
||||||
|
world_gen_world = ExtResource( 2 )
|
@ -1,6 +1,13 @@
|
|||||||
tool
|
tool
|
||||||
extends Continent
|
extends Continent
|
||||||
|
|
||||||
|
export(PackedScene) var dungeon_teleporter : PackedScene
|
||||||
|
export(PropData) var prop_tree : PropData
|
||||||
|
export(PropData) var prop_tree2 : PropData
|
||||||
|
|
||||||
|
var voxel_scale : float = 1
|
||||||
|
var current_seed : int = 0
|
||||||
|
|
||||||
func get_editor_rect_border_color() -> Color:
|
func get_editor_rect_border_color() -> Color:
|
||||||
return Color(0.8, 0.8, 0.8, 1)
|
return Color(0.8, 0.8, 0.8, 1)
|
||||||
|
|
||||||
@ -19,3 +26,126 @@ func get_editor_class() -> String:
|
|||||||
func get_editor_additional_text() -> String:
|
func get_editor_additional_text() -> String:
|
||||||
return "TestContinent"
|
return "TestContinent"
|
||||||
|
|
||||||
|
func _setup_terra_library(library : TerramanLibrary, pseed : int) -> void:
|
||||||
|
pass
|
||||||
|
|
||||||
|
func _generate_terra_chunk(chunk: TerraChunk, pseed : int, spawn_mobs: bool) -> void:
|
||||||
|
voxel_scale = chunk.voxel_scale
|
||||||
|
current_seed = pseed
|
||||||
|
|
||||||
|
# #todo generate this properly
|
||||||
|
# var entrance_position : Vector3 = Vector3(7, 5, 7)
|
||||||
|
#
|
||||||
|
# for i in range(get_building_count()):
|
||||||
|
# var d : Building = get_building(i)
|
||||||
|
#
|
||||||
|
# if d.has_method("has_entrance_position"):
|
||||||
|
# d.entrance_position.origin = entrance_position
|
||||||
|
#
|
||||||
|
# entrance_position = d.next_level_teleporter_position_data_space
|
||||||
|
# entrance_position *= voxel_scale
|
||||||
|
|
||||||
|
var cx : int = chunk.get_position_x()
|
||||||
|
var cz : int = chunk.get_position_z()
|
||||||
|
|
||||||
|
var chunk_seed : int = 123 + (cx * 231) + (cz * 123)
|
||||||
|
|
||||||
|
var rng : RandomNumberGenerator = RandomNumberGenerator.new()
|
||||||
|
rng.seed = chunk_seed
|
||||||
|
|
||||||
|
#terrarin_gen.generate_simple_terrarin(chunk, spawn_mobs)
|
||||||
|
gen_terra_chunk(chunk, rng)
|
||||||
|
|
||||||
|
if chunk.position_x == 0 && chunk.position_z == 0:
|
||||||
|
#test
|
||||||
|
spawn_dungeon(chunk, chunk_seed, spawn_mobs)
|
||||||
|
else:
|
||||||
|
if rng.randi() % 10 == 0:
|
||||||
|
spawn_dungeon(chunk, chunk_seed, spawn_mobs)
|
||||||
|
|
||||||
|
# for i in range(get_building_count()):
|
||||||
|
# get_building(i).generate_terra_chunk(chunk, spawn_mobs)
|
||||||
|
|
||||||
|
if not Engine.editor_hint and spawn_mobs and rng.randi() % 4 == 0:
|
||||||
|
var level : int = 1
|
||||||
|
|
||||||
|
if chunk.get_voxel_world().has_method("get_mob_level"):
|
||||||
|
level = chunk.get_voxel_world().get_mob_level()
|
||||||
|
|
||||||
|
ESS.entity_spawner.spawn_mob(0, level, \
|
||||||
|
Vector3(chunk.position_x * chunk.size_x * chunk.voxel_scale + chunk.size_x / 2,\
|
||||||
|
100, \
|
||||||
|
chunk.position_z * chunk.size_z * chunk.voxel_scale + chunk.size_z / 2))
|
||||||
|
|
||||||
|
func gen_terra_chunk(chunk: TerraChunk, rng : RandomNumberGenerator) -> void:
|
||||||
|
chunk.channel_ensure_allocated(TerraChunkDefault.DEFAULT_CHANNEL_TYPE, 1)
|
||||||
|
chunk.channel_ensure_allocated(TerraChunkDefault.DEFAULT_CHANNEL_ISOLEVEL, 0)
|
||||||
|
|
||||||
|
var s : FastNoise = FastNoise.new()
|
||||||
|
s.set_noise_type(FastNoise.TYPE_SIMPLEX)
|
||||||
|
s.set_seed(current_seed)
|
||||||
|
|
||||||
|
var sdet : FastNoise = FastNoise.new()
|
||||||
|
sdet.set_noise_type(FastNoise.TYPE_SIMPLEX)
|
||||||
|
sdet.set_seed(current_seed)
|
||||||
|
|
||||||
|
for x in range(-chunk.margin_start, chunk.size_x + chunk.margin_end):
|
||||||
|
for z in range(-chunk.margin_start, chunk.size_x + chunk.margin_end):
|
||||||
|
var vx : int = x + (chunk.position_x * chunk.size_x)
|
||||||
|
var vz : int = z + (chunk.position_z * chunk.size_z)
|
||||||
|
|
||||||
|
var val : float = (s.get_noise_2d(vx * 0.05, vz * 0.05) + 2)
|
||||||
|
val *= val
|
||||||
|
val *= 20.0
|
||||||
|
val += abs(sdet.get_noise_2d(vx * 0.8, vz * 0.8)) * 20
|
||||||
|
|
||||||
|
chunk.set_voxel(val, x, z, TerraChunkDefault.DEFAULT_CHANNEL_ISOLEVEL)
|
||||||
|
|
||||||
|
if val < 50:
|
||||||
|
chunk.set_voxel(2, x, z, TerraChunkDefault.DEFAULT_CHANNEL_TYPE)
|
||||||
|
elif val > 90:
|
||||||
|
chunk.set_voxel(4, x, z, TerraChunkDefault.DEFAULT_CHANNEL_TYPE)
|
||||||
|
else:
|
||||||
|
if chunk.position_x == 0 && chunk.position_z == 0:
|
||||||
|
continue
|
||||||
|
|
||||||
|
if rng.randf() > 0.992:
|
||||||
|
var tr : Transform = Transform()
|
||||||
|
|
||||||
|
tr = tr.rotated(Vector3(0, 1, 0), rng.randf() * PI)
|
||||||
|
tr = tr.rotated(Vector3(1, 0, 0), rng.randf() * 0.2 - 0.1)
|
||||||
|
tr = tr.rotated(Vector3(0, 0, 1), rng.randf() * 0.2 - 0.1)
|
||||||
|
tr = tr.scaled(Vector3(0.9 + rng.randf() * 0.2, 0.9 + rng.randf() * 0.2, 0.9 + rng.randf() * 0.2))
|
||||||
|
tr.origin = Vector3((x + chunk.position_x * chunk.size_x), ((val - 2) / 255.0) * chunk.world_height, (z + chunk.position_z * chunk.size_z))
|
||||||
|
|
||||||
|
chunk.voxel_world.prop_add(tr, prop_tree)
|
||||||
|
|
||||||
|
# Uncomment to test the prop texture merger system:
|
||||||
|
# if randf() > 0.5:
|
||||||
|
# chunk.voxel_world.prop_add(tr, prop_tree)
|
||||||
|
# else:
|
||||||
|
# chunk.voxel_world.prop_add(tr, prop_tree2)
|
||||||
|
|
||||||
|
|
||||||
|
func spawn_dungeon(chunk: TerraChunk, dungeon_seed : int, spawn_mobs : bool) -> void:
|
||||||
|
var x : float = chunk.position_x * chunk.voxel_scale * chunk.size_x
|
||||||
|
var z : float = chunk.position_z * chunk.voxel_scale * chunk.size_z
|
||||||
|
|
||||||
|
var vh : int = chunk.get_voxel(6, 6, TerraChunkDefault.DEFAULT_CHANNEL_ISOLEVEL)
|
||||||
|
var vwh : float = chunk.get_voxel_scale() * chunk.get_world_height() * (vh / 256.0)
|
||||||
|
|
||||||
|
var dt : Spatial = dungeon_teleporter.instance()
|
||||||
|
chunk.voxel_world.add_child(dt)
|
||||||
|
dt.owner_chunk = chunk
|
||||||
|
|
||||||
|
var level : int = 2
|
||||||
|
|
||||||
|
if chunk.get_voxel_world().has_method("get_mob_level"):
|
||||||
|
level = chunk.get_voxel_world().get_mob_level()
|
||||||
|
|
||||||
|
dt.min_level = level - 1
|
||||||
|
dt.max_level = level + 1
|
||||||
|
dt.dungeon_seed = dungeon_seed
|
||||||
|
dt.spawn_mobs = spawn_mobs
|
||||||
|
dt.transform = Transform(Basis().scaled(Vector3(chunk.voxel_scale, chunk.voxel_scale, chunk.voxel_scale)), Vector3(x, vwh, z))
|
||||||
|
|
||||||
|
20
game/world_generator/subzones/spawner.gd
Normal file
20
game/world_generator/subzones/spawner.gd
Normal file
@ -0,0 +1,20 @@
|
|||||||
|
tool
|
||||||
|
extends SubZone
|
||||||
|
|
||||||
|
func get_editor_rect_border_color() -> Color:
|
||||||
|
return Color(0.8, 0.8, 0.8, 1)
|
||||||
|
|
||||||
|
func get_editor_rect_color() -> Color:
|
||||||
|
return Color(0.8, 0.8, 0.8, 0.9)
|
||||||
|
|
||||||
|
func get_editor_rect_border_size() -> int:
|
||||||
|
return 2
|
||||||
|
|
||||||
|
func get_editor_font_color() -> Color:
|
||||||
|
return Color(0, 0, 0, 1)
|
||||||
|
|
||||||
|
func get_editor_class() -> String:
|
||||||
|
return "Spawner"
|
||||||
|
|
||||||
|
func get_editor_additional_text() -> String:
|
||||||
|
return "Spawner"
|
Loading…
Reference in New Issue
Block a user