2021-03-22 23:41:58 +01:00
|
|
|
tool
|
2020-07-21 23:02:06 +02:00
|
|
|
extends Biome
|
2020-04-26 15:43:07 +02:00
|
|
|
|
2021-04-15 11:52:32 +02:00
|
|
|
# Copyright (c) 2019-2021 Péter Magyar
|
2020-04-26 15:43:07 +02:00
|
|
|
#
|
|
|
|
# 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.
|
|
|
|
|
2021-08-06 22:33:50 +02:00
|
|
|
export(PackedScene) var tree : PackedScene
|
2021-08-07 10:14:17 +02:00
|
|
|
export(PropData) var prop_tree : PropData
|
2021-08-06 22:33:50 +02:00
|
|
|
|
2020-07-21 23:02:06 +02:00
|
|
|
var terrarin_gen : BiomeTerrarinGenerator = BiomeTerrarinGenerator.new()
|
|
|
|
|
2020-07-23 19:44:15 +02:00
|
|
|
var voxel_scale : float = -1
|
|
|
|
|
2020-07-18 12:50:17 +02:00
|
|
|
func _setup():
|
2020-07-21 23:02:06 +02:00
|
|
|
terrarin_gen.set_current_seed(current_seed)
|
2020-07-18 12:50:17 +02:00
|
|
|
|
2021-04-19 22:30:51 +02:00
|
|
|
for i in range(get_building_count()):
|
|
|
|
var d : Building = get_building(i)
|
2020-07-18 12:50:17 +02:00
|
|
|
d.setup()
|
2020-10-06 19:26:13 +02:00
|
|
|
|
2021-08-06 22:33:50 +02:00
|
|
|
func _instance(p_seed, p_instance):
|
|
|
|
p_instance.tree = tree
|
2021-08-07 10:14:17 +02:00
|
|
|
p_instance.prop_tree = prop_tree
|
2021-08-06 22:33:50 +02:00
|
|
|
|
|
|
|
return ._instance(p_seed, p_instance)
|
|
|
|
|
2021-04-18 23:56:44 +02:00
|
|
|
func _generate_terra_chunk(chunk, spawn_mobs):
|
|
|
|
if voxel_scale < 0:
|
|
|
|
voxel_scale = chunk.voxel_scale
|
|
|
|
|
|
|
|
#todo generate this properly
|
|
|
|
var entrance_position : Vector3 = Vector3(7, 5, 7)
|
|
|
|
|
2021-04-19 22:30:51 +02:00
|
|
|
for i in range(get_building_count()):
|
|
|
|
var d : Building = get_building(i)
|
2021-04-18 23:56:44 +02:00
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
|
#terrarin_gen.generate_simple_terrarin(chunk, spawn_mobs)
|
|
|
|
gen_terra_chunk(chunk)
|
|
|
|
|
2021-04-19 22:30:51 +02:00
|
|
|
for i in range(get_building_count()):
|
|
|
|
get_building(i).generate_terra_chunk(chunk, spawn_mobs)
|
2021-04-18 23:56:44 +02:00
|
|
|
|
|
|
|
if not Engine.editor_hint and spawn_mobs and 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) -> void:
|
|
|
|
chunk.channel_ensure_allocated(TerraChunkDefault.DEFAULT_CHANNEL_TYPE, 1)
|
|
|
|
chunk.channel_ensure_allocated(TerraChunkDefault.DEFAULT_CHANNEL_ISOLEVEL, 0)
|
|
|
|
|
2021-08-06 19:24:13 +02:00
|
|
|
var s : FastNoise = FastNoise.new()
|
|
|
|
s.set_noise_type(FastNoise.TYPE_SIMPLEX)
|
|
|
|
s.set_seed(current_seed)
|
2021-04-18 23:56:44 +02:00
|
|
|
|
2021-08-06 20:38:47 +02:00
|
|
|
var sdet : FastNoise = FastNoise.new()
|
|
|
|
sdet.set_noise_type(FastNoise.TYPE_SIMPLEX)
|
|
|
|
sdet.set_seed(current_seed)
|
|
|
|
|
2021-04-18 23:56:44 +02:00
|
|
|
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)
|
|
|
|
|
2021-08-06 20:38:47 +02:00
|
|
|
var val : float = (s.get_noise_2d(vx * 0.05, vz * 0.05) + 2)
|
2021-04-18 23:56:44 +02:00
|
|
|
val *= val
|
|
|
|
val *= 20.0
|
2021-08-06 20:38:47 +02:00
|
|
|
val += abs(sdet.get_noise_2d(vx * 0.8, vz * 0.8)) * 20
|
2021-04-18 23:56:44 +02:00
|
|
|
|
|
|
|
chunk.set_voxel(val, x, z, TerraChunkDefault.DEFAULT_CHANNEL_ISOLEVEL)
|
|
|
|
|
|
|
|
if val < 50:
|
|
|
|
chunk.set_voxel(2, x, z, TerraChunkDefault.DEFAULT_CHANNEL_TYPE)
|
2021-08-06 21:53:15 +02:00
|
|
|
elif val > 90:
|
2021-04-18 23:56:44 +02:00
|
|
|
chunk.set_voxel(4, x, z, TerraChunkDefault.DEFAULT_CHANNEL_TYPE)
|
2021-08-06 22:33:50 +02:00
|
|
|
else:
|
|
|
|
#Todo use the prop system for this
|
|
|
|
if randf() > 0.992:
|
2021-08-07 10:14:17 +02:00
|
|
|
# var t = tree.instance()
|
|
|
|
#
|
|
|
|
# var spat : Spatial = t as Spatial
|
|
|
|
#
|
|
|
|
# spat.rotate(Vector3(0, 1, 0), randf() * PI)
|
|
|
|
# spat.rotate(Vector3(1, 0, 0), randf() * 0.2 - 0.1)
|
|
|
|
# spat.rotate(Vector3(0, 0, 1), randf() * 0.2 - 0.1)
|
|
|
|
# spat.transform = spat.transform.scaled(Vector3(0.9 + 0.8 - randf(), 0.9 + 0.8 - randf(), 0.9 + 0.8 - randf()))
|
|
|
|
# spat.transform.origin = Vector3((x + chunk.position_x * chunk.size_x) * chunk.voxel_scale, ((val - 2) / 255.0) * chunk.world_height * chunk.voxel_scale, (z + chunk.position_z * chunk.size_z) * chunk.voxel_scale)
|
|
|
|
# chunk.voxel_world.call_deferred("add_child", spat)
|
|
|
|
|
|
|
|
|
|
|
|
var tr : Transform = Transform()
|
|
|
|
|
|
|
|
tr = tr.rotated(Vector3(0, 1, 0), randf() * PI)
|
|
|
|
tr = tr.rotated(Vector3(1, 0, 0), randf() * 0.2 - 0.1)
|
|
|
|
tr = tr.rotated(Vector3(0, 0, 1), randf() * 0.2 - 0.1)
|
|
|
|
tr = tr.scaled(Vector3(0.9 + 0.8 - randf(), 0.9 + 0.8 - randf(), 0.9 + 0.8 - randf()))
|
|
|
|
tr.origin = Vector3((x + chunk.position_x * chunk.size_x) * chunk.voxel_scale, ((val - 2) / 255.0) * chunk.world_height * chunk.voxel_scale, (z + chunk.position_z * chunk.size_z) * chunk.voxel_scale)
|
|
|
|
|
|
|
|
chunk.voxel_world.prop_add(tr, prop_tree, false)
|
|
|
|
|
2021-08-06 22:33:50 +02:00
|
|
|
|
|
|
|
|
|
|
|
|