fix entity spawn for special scene + fix wagon movement

This commit is contained in:
2026-06-03 19:26:12 +02:00
parent 243f89d9d2
commit 584579afb8
8 changed files with 148 additions and 32 deletions

View File

@@ -82,6 +82,7 @@ var wire_connections: Dictionary = {}
var chunk_candidate_cache: Dictionary = {} #node cache (metadata)
var prop_candidate_cache: Dictionary = {}
var entity_candidate_cache: Dictionary = {}
var static_entity_spawn_roots: Dictionary = {}
var pending_generation_cells: Array[Vector2i] = []
var pending_cleanup_cells: Array[Vector2i] = []
var pending_wire_cells: Array[Vector2i] = []
@@ -116,6 +117,7 @@ func _ready() -> void:
_warm_rail_chunk_catalogue()
#set unique pieces
_update_set_pieces()
_spawn_entities_for_static_spawn_points()
func _update_set_pieces() -> void:
var set_pieces = get_tree().get_nodes_in_group("set_pieces")
@@ -766,6 +768,66 @@ func _spawn_prop_for_marker(marker: Node) -> void:
marker.add_child(prop_node)
prop_node.transform = Transform3D.IDENTITY
func _get_static_entity_spawn_root(root: Node) -> Node:
var current: Node = root
while current != null and current != get_tree().root:
var spawn_points: Array[Node] = []
collect_all_entity_spawn_points(current, spawn_points)
if not spawn_points.is_empty():
return current
current = current.get_parent()
return null
func _get_static_spawn_chunk_root_from_point(spawn_point: Node) -> Node:
var current: Node = spawn_point
while current != null and current != get_tree().root:
var info_list: Array[Node] = []
collect_all_chunkinfo(current, info_list)
if not info_list.is_empty():
return current
current = current.get_parent()
return null
func _spawn_entities_for_static_spawn_points() -> void:
var current_scene = get_tree().current_scene
if current_scene == null:
return
var spawn_points: Array[Node] = []
collect_all_entity_spawn_points(current_scene, spawn_points)
for spawn_point in spawn_points:
var spawn_root = _get_static_spawn_chunk_root_from_point(spawn_point)
if spawn_root == null:
continue
var point_node = spawn_point as Node3D
var grid_pos = Vector2i.ZERO
if point_node != null:
grid_pos = Vector2i(roundi(point_node.global_position.x / chunk_size), roundi(point_node.global_position.z / chunk_size))
_spawn_entities_for_static_obstacle(spawn_root, grid_pos)
func _spawn_entities_for_static_obstacle(root: Node, grid_pos: Vector2i) -> void:
if root == null or not is_instance_valid(root):
return
var spawn_root = _get_static_entity_spawn_root(root)
if spawn_root == null or not is_instance_valid(spawn_root):
return
var root_id: int = spawn_root.get_instance_id()
if static_entity_spawn_roots.has(root_id):
var tracked_root = static_entity_spawn_roots[root_id]
if is_instance_valid(tracked_root):
return
static_entity_spawn_roots.erase(root_id)
static_entity_spawn_roots[root_id] = spawn_root
_spawn_entities_for_chunk(spawn_root, _choose_biome_name_by_cell(grid_pos))
func _spawn_entities_for_chunk(root: Node, biome_name: String) -> void:
if entity_pool == null or not "available_entities" in entity_pool:
return
@@ -930,6 +992,8 @@ func _register_cell_with_ray(grid_pos: Vector2i) -> bool:
if have_lamppost:
_queue_lamppost_wire_connection(grid_pos)
_spawn_entities_for_static_obstacle(root_chunk, grid_pos)
return true
return false

View File

@@ -1,9 +1,18 @@
[gd_resource type="Resource" script_class="EntityPool" format=3 uid="uid://cmd6s6thq4f7r"]
[ext_resource type="PackedScene" uid="uid://clx701xdwelgx" path="res://core/ai/agents/base/ai_base.tscn" id="1_0kfj8"]
[ext_resource type="PackedScene" uid="uid://dd8wn62anbts8" path="res://core/ai/agents/cow/ai_cow.tscn" id="1_iqga3"]
[ext_resource type="Script" uid="uid://53ryr0fsqiq7" path="res://core/biome_generator/entity_pool.gd" id="1_vccp2"]
[ext_resource type="PackedScene" uid="uid://c2hg6hu2y5srb" path="res://core/ai/agents/pig/ai_pig.tscn" id="2_76rvd"]
[ext_resource type="PackedScene" uid="uid://2md4l83fy8kr" path="res://core/ai/agents/pug/ai_pug.tscn" id="3_hq17p"]
[ext_resource type="PackedScene" uid="uid://cayakdk7gmlyg" path="res://core/ai/agents/horse/ai_horse.tscn" id="4_5yjl1"]
[ext_resource type="PackedScene" uid="uid://mvh2v6v72stt" path="res://core/ai/agents/human/ai_human.tscn" id="5_xd1cg"]
[ext_resource type="PackedScene" uid="uid://bs1bdtm7jdtgb" path="res://core/ai/agents/sheep/ai_sheep.tscn" id="6_ql0wl"]
[ext_resource type="PackedScene" uid="uid://ceqxsqfiotm5j" path="res://core/ai/agents/human/ai_farmer.tscn" id="7_hhs8l"]
[ext_resource type="PackedScene" uid="uid://bdqeshcwwnyc4" path="res://core/ai/agents/human/ai_citizen.tscn" id="8_8l6th"]
[ext_resource type="PackedScene" uid="uid://bbseno7clbepx" path="res://core/ai/agents/human/ai_citizen_sitter.tscn" id="9_x3pn3"]
[ext_resource type="PackedScene" uid="uid://bnnuke5e7e1yr" path="res://core/ai/agents/human/ai_citizen_walker.tscn" id="10_ctysb"]
[resource]
script = ExtResource("1_vccp2")
name = "Entity Pool"
available_entities = Array[PackedScene]([ExtResource("1_0kfj8")])
available_entities = Array[PackedScene]([ExtResource("1_iqga3"), ExtResource("2_76rvd"), ExtResource("3_hq17p"), ExtResource("4_5yjl1"), ExtResource("5_xd1cg"), ExtResource("6_ql0wl"), ExtResource("7_hhs8l"), ExtResource("8_8l6th"), ExtResource("9_x3pn3"), ExtResource("10_ctysb")])

View File

@@ -538,10 +538,6 @@ func _snap_wagons_to_progress(total_length: float = 0.0) -> void:
if total_length <= 0.0:
return
var direction: float = 1.0
if train_speed < 0.0:
direction = -1.0
for i in range(wagon_instances.size()):
var wagon: Node3D = wagon_instances[i]
if not is_instance_valid(wagon):
@@ -551,7 +547,7 @@ func _snap_wagons_to_progress(total_length: float = 0.0) -> void:
if i < wagon_progress_offsets.size():
wagon_offset = wagon_progress_offsets[i]
var wagon_progress: float = train_progress - direction * wagon_offset
var wagon_progress: float = train_progress - wagon_offset
var vehicle_progress: float = wrapf(wagon_progress, 0.0, total_length)
var center_position: Vector3 = to_global(curve.sample_baked(vehicle_progress, true))