remove items_manager and make honeydew searching tied to a position

This commit is contained in:
Teatov 2024-10-07 23:11:11 +10:00
parent 50cb83ad7c
commit 0fba1ee78d
10 changed files with 110 additions and 107 deletions

View File

@ -26,7 +26,6 @@ DebugDraw="*res://scripts/globals/debug_draw.gd"
UiManager="*res://scripts/globals/ui_manager.gd"
HoveringManager="*res://scripts/globals/hovering_manager.gd"
SelectionManager="*res://scripts/globals/selection_manager.gd"
ItemsManager="*res://scripts/globals/items_manager.gd"
[debug]

View File

@ -18,7 +18,7 @@ orientation = 1
[node name="Honeydew" type="CharacterBody3D"]
collision_layer = 256
collision_mask = 0
collision_mask = 256
script = ExtResource("1_6fg3d")
[node name="MeshInstance3D" type="MeshInstance3D" parent="."]

View File

@ -11,8 +11,15 @@ radius = 15.0
script = ExtResource("2_7pblm")
[node name="Skeleton3D" parent="AntModel/Armature" index="0"]
bones/4/rotation = Quaternion(0.587858, -5.43255e-07, -3.94772e-07, 0.808964)
bones/6/rotation = Quaternion(0.330686, -3.0116e-14, -4.44141e-07, 0.943741)
bones/9/rotation = Quaternion(0.587858, 5.43255e-07, 3.94772e-07, 0.808964)
bones/11/rotation = Quaternion(0.330686, 3.0116e-14, 4.44141e-07, 0.943741)
bones/14/rotation = Quaternion(4.60304e-08, 0.0294697, 0.999566, -5.43234e-07)
bones/14/scale = Vector3(1, 1, 1)
bones/15/rotation = Quaternion(4.55913e-08, 0.0294697, 0.999566, -4.34329e-07)
bones/15/scale = Vector3(1, 1, 1)
bones/16/rotation = Quaternion(4.55913e-08, 0.0294697, 0.999566, -4.34329e-07)
bones/16/scale = Vector3(1, 1, 1)
bones/18/rotation = Quaternion(0.0294712, -6.21995e-15, 4.35675e-07, 0.999566)
bones/19/rotation = Quaternion(0.0294712, -5.33139e-15, 4.35675e-07, 0.999566)
@ -22,13 +29,23 @@ bones/22/rotation = Quaternion(0.0294712, -6.21995e-15, 4.35675e-07, 0.999566)
bones/23/rotation = Quaternion(0.0294712, -5.33139e-15, 4.35675e-07, 0.999566)
bones/24/rotation = Quaternion(0.0294712, -6.21995e-15, 4.35675e-07, 0.999566)
bones/25/rotation = Quaternion(0.0294712, -5.33139e-15, 4.35675e-07, 0.999566)
bones/26/scale = Vector3(1, 1, 1)
bones/26/rotation = Quaternion(-0.221628, 0.221633, -0.671475, 0.671477)
bones/27/rotation = Quaternion(0.583948, -8.29882e-08, 2.36539e-06, 0.811791)
bones/27/scale = Vector3(1, 1, 1)
bones/28/rotation = Quaternion(-0.84146, 6.60837e-08, -6.26108e-06, 0.54032)
bones/30/rotation = Quaternion(0.583949, -2.24752e-07, 2.46641e-06, 0.811791)
bones/31/rotation = Quaternion(-0.84146, 1.69298e-07, -6.42962e-06, 0.54032)
bones/32/scale = Vector3(1, 1, 1)
bones/34/rotation = Quaternion(-0.841459, 1.31575e-07, -6.3826e-06, 0.540321)
bones/34/scale = Vector3(1, 1, 1)
bones/35/scale = Vector3(1, 1, 1)
bones/35/rotation = Quaternion(-0.221628, -0.221633, 0.671475, 0.671477)
bones/36/rotation = Quaternion(0.583948, 8.29882e-08, -2.36539e-06, 0.811791)
bones/36/scale = Vector3(1, 1, 1)
bones/37/rotation = Quaternion(-0.84146, -6.60837e-08, 6.26108e-06, 0.54032)
bones/39/rotation = Quaternion(0.583949, 2.24752e-07, -2.46641e-06, 0.811791)
bones/40/rotation = Quaternion(-0.84146, -1.69298e-07, 6.42962e-06, 0.54032)
bones/41/scale = Vector3(1, 1, 1)
bones/43/rotation = Quaternion(-0.841459, -1.31575e-07, 6.3826e-06, 0.540321)
bones/43/scale = Vector3(1, 1, 1)
[node name="GathererMesh" parent="AntModel/Armature/Skeleton3D" index="0"]
@ -39,8 +56,8 @@ visible = true
[node name="NearbyItemsSearch" parent="Gathering" index="0"]
shape = SubResource("SphereShape3D_f7l1n")
[node name="GatheringRadius" parent="Gathering" index="1"]
transform = Transform3D(30.6826, 0, 0, 0, 30.6826, 0, 0, 0, 30.6826, 0, 0, 0)
[node name="GatheringRadius" parent="Gathering/NearbyItemsSearch" index="0"]
transform = Transform3D(30.8235, 0, 0, 0, 30.8235, 0, 0, 0, 30.8235, 0, 0, 0)
[editable path="AntModel"]
[editable path="Gathering"]

View File

@ -10,6 +10,27 @@ radius = 4.0
[node name="AntNitwit" instance=ExtResource("1_w0xhf")]
script = ExtResource("2_rfn2k")
[node name="Skeleton3D" parent="AntModel/Armature" index="0"]
bones/4/rotation = Quaternion(0.587858, -5.43255e-07, -3.94772e-07, 0.808964)
bones/6/rotation = Quaternion(0.330686, -3.0116e-14, -4.44141e-07, 0.943741)
bones/9/rotation = Quaternion(0.587858, 5.43255e-07, 3.94772e-07, 0.808964)
bones/11/rotation = Quaternion(0.330686, 3.0116e-14, 4.44141e-07, 0.943741)
bones/14/rotation = Quaternion(4.60304e-08, 0.0294697, 0.999566, -5.43234e-07)
bones/15/rotation = Quaternion(4.55913e-08, 0.0294697, 0.999566, -4.34329e-07)
bones/16/rotation = Quaternion(4.55913e-08, 0.0294697, 0.999566, -4.34329e-07)
bones/26/rotation = Quaternion(-0.221628, 0.221633, -0.671475, 0.671477)
bones/27/rotation = Quaternion(0.583948, -8.29882e-08, 2.36539e-06, 0.811791)
bones/28/rotation = Quaternion(-0.84146, 6.60837e-08, -6.26108e-06, 0.54032)
bones/30/rotation = Quaternion(0.583949, -2.24752e-07, 2.46641e-06, 0.811791)
bones/31/rotation = Quaternion(-0.84146, 1.69298e-07, -6.42962e-06, 0.54032)
bones/34/rotation = Quaternion(-0.841459, 1.31575e-07, -6.3826e-06, 0.540321)
bones/35/rotation = Quaternion(-0.221628, -0.221633, 0.671475, 0.671477)
bones/36/rotation = Quaternion(0.583948, 8.29882e-08, -2.36539e-06, 0.811791)
bones/37/rotation = Quaternion(-0.84146, -6.60837e-08, 6.26108e-06, 0.54032)
bones/39/rotation = Quaternion(0.583949, 2.24752e-07, -2.46641e-06, 0.811791)
bones/40/rotation = Quaternion(-0.84146, -1.69298e-07, 6.42962e-06, 0.54032)
bones/43/rotation = Quaternion(-0.841459, -1.31575e-07, 6.3826e-06, 0.540321)
[node name="NitwitMesh" parent="AntModel/Armature/Skeleton3D" index="1"]
visible = true
@ -18,8 +39,8 @@ visible = true
[node name="NearbyItemsSearch" parent="Gathering" index="0"]
shape = SubResource("SphereShape3D_dwl4o")
[node name="GatheringRadius" parent="Gathering" index="1"]
transform = Transform3D(8.2687, 0, 0, 0, 8.2687, 0, 0, 0, 8.2687, 0, 0, 0)
[node name="GatheringRadius" parent="Gathering/NearbyItemsSearch" index="0"]
transform = Transform3D(8.24392, 0, 0, 0, 8.24392, 0, 0, 0, 8.24392, 0, 0, 0)
[editable path="AntModel"]
[editable path="Gathering"]

View File

@ -16,6 +16,7 @@ script = ExtResource("1_ciwtf")
[node name="NearbyItemsSearch" type="CollisionShape3D" parent="."]
[node name="GatheringRadius" type="MeshInstance3D" parent="."]
[node name="GatheringRadius" type="MeshInstance3D" parent="NearbyItemsSearch"]
cast_shadow = 0
mesh = SubResource("QuadMesh_ks8es")
skeleton = NodePath("../..")

View File

@ -107,37 +107,37 @@ transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, -52.9581, 0.094905, -60.7543)
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, -53.5179, 0.0949052, -64.0861)
[node name="Honeydew14" parent="Items" instance=ExtResource("3_hea5m")]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, -53.0347, 0.094905, -63.7626)
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, -45.5821, 0.094905, -64.3186)
[node name="Honeydew15" parent="Items" instance=ExtResource("3_hea5m")]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, -52.4965, 0.094905, -64.7682)
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, -45.0439, 0.094905, -65.3242)
[node name="Honeydew16" parent="Items" instance=ExtResource("3_hea5m")]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, -52.2191, 0.094905, -63.9098)
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, -44.7665, 0.094905, -64.4658)
[node name="Honeydew17" parent="Items" instance=ExtResource("3_hea5m")]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, -52.7697, 0.094905, -62.9077)
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, -45.3171, 0.094905, -63.4637)
[node name="Honeydew18" parent="Items" instance=ExtResource("3_hea5m")]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, -53.2721, 0.094905, -63.1405)
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, -45.8195, 0.094905, -63.6965)
[node name="Honeydew19" parent="Items" instance=ExtResource("3_hea5m")]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, -52.561, 0.0949052, -64.2839)
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, -45.1084, 0.0949052, -64.8399)
[node name="Honeydew20" parent="Items" instance=ExtResource("3_hea5m")]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, -52.0778, 0.094905, -63.9604)
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, -44.6252, 0.094905, -64.5164)
[node name="Honeydew21" parent="Items" instance=ExtResource("3_hea5m")]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, -51.5396, 0.094905, -64.966)
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, -44.087, 0.094905, -65.522)
[node name="Honeydew22" parent="Items" instance=ExtResource("3_hea5m")]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, -51.2622, 0.094905, -64.1076)
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, -43.8096, 0.094905, -64.6636)
[node name="Honeydew23" parent="Items" instance=ExtResource("3_hea5m")]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, -51.8128, 0.094905, -63.1055)
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, -44.3602, 0.094905, -63.6615)
[node name="Honeydew24" parent="Items" instance=ExtResource("3_hea5m")]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, -52.3151, 0.094905, -63.3383)
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, -44.8625, 0.094905, -63.8943)
[node name="Bunches" type="Node" parent="."]

View File

@ -1,41 +0,0 @@
extends Node
var honeydews: Dictionary = {}
var honeydew_scene := preload("res://scenes/items/honeydew.tscn")
@onready var items_holder := $/root/World/Items
func _ready() -> void:
assert(items_holder != null, "items_holder missing!")
func spawn_honeydew(pos: Vector3) -> Honeydew:
var honeydew := honeydew_scene.instantiate() as Honeydew
honeydew.global_position = pos
items_holder.add_child(honeydew)
return honeydew
func spawn_a_bunch(pos: Vector3, amount: int, spread: float) -> void:
for i in amount:
var new_pos := pos
new_pos.x += randf_range(-spread, spread)
new_pos.z += randf_range(-spread, spread)
var new_honeydew := spawn_honeydew(new_pos)
put_honeydew(new_honeydew)
func put_honeydew(item: Honeydew) -> void:
var item_id := item.get_instance_id()
if honeydews.keys().has(item_id):
return
honeydews[item_id] = item
func erase_honeydew(item: Honeydew) -> void:
var item_id := item.get_instance_id()
if not honeydews.keys().has(item_id):
return
honeydews.erase(item_id)

View File

@ -32,7 +32,7 @@ func _ready() -> void:
item_bones.append(skeleton.find_bone(ITEM_BONE_NAME + str(i)))
gathering.initialize(anthill, skeleton, item_bones, MAX_CARRY, 0.4, 1)
gathering.target_set.connect(_on_gathering_target_set)
gathering.stop_gathering.connect(_on_gathering_stop)
gathering.stopped_gathering.connect(_on_stopped_gathering)
func _process(delta: float) -> void:
@ -47,7 +47,7 @@ func _process(delta: float) -> void:
func _interact(with: Interactable) -> void:
if with is Honeydew:
state = AntGathererState.GATHERING
gathering.go_gather(with as Honeydew)
gathering.start_gathering(with as Honeydew)
func _handle_wandering(delta: float) -> void:
@ -67,7 +67,7 @@ func _on_moving_ended() -> void:
func _on_moving_started() -> void:
if state == AntGathererState.GATHERING:
gathering.stop_all_gathering()
gathering.stop_gathering()
state = AntGathererState.MOVING
@ -78,5 +78,5 @@ func _on_gathering_target_set(pos: Vector3) -> void:
nav_agent.set_target_position(pos)
func _on_gathering_stop() -> void:
func _on_stopped_gathering() -> void:
state = AntGathererState.WANDERING

View File

@ -31,7 +31,7 @@ func _ready() -> void:
item_bones.append(skeleton.find_bone(ITEM_BONE_NAME + str(i)))
gathering.initialize(anthill, skeleton, item_bones)
gathering.target_set.connect(_on_gathering_target_set)
gathering.stop_gathering.connect(_on_gathering_stop)
gathering.stopped_gathering.connect(_on_stopped_gathering)
func _process(delta: float) -> void:
@ -46,7 +46,7 @@ func _process(delta: float) -> void:
func _interact(with: Interactable) -> void:
if with is Honeydew:
state = AntNitwitState.GATHERING
gathering.go_gather(with as Honeydew)
gathering.start_gathering(with as Honeydew)
func _handle_wandering(delta: float) -> void:
@ -66,7 +66,7 @@ func _on_moving_ended() -> void:
func _on_moving_started() -> void:
if state == AntNitwitState.GATHERING:
gathering.stop_all_gathering()
gathering.stop_gathering()
state = AntNitwitState.MOVING
@ -77,5 +77,5 @@ func _on_gathering_target_set(pos: Vector3) -> void:
nav_agent.set_target_position(pos)
func _on_gathering_stop() -> void:
func _on_stopped_gathering() -> void:
state = AntNitwitState.WANDERING

View File

@ -2,7 +2,7 @@ extends Area3D
class_name Gathering
signal target_set(pos: Vector3)
signal stop_gathering
signal stopped_gathering
const DEFAULT_MAX_CARRYING = 3
const DEFAULT_DROP_INTERVAL = 0.25
@ -21,7 +21,6 @@ var state: GatherState = GatherState.STOP
var nearby_items: Dictionary = {}
var carrying_items: Array[Honeydew] = []
var max_carrying: int = DEFAULT_MAX_CARRYING
var deposit_leftover: int = 0
var target: Honeydew
var anthill: Anthill
@ -31,8 +30,16 @@ var drop_interval: float = DEFAULT_DROP_INTERVAL
var pickup_interval: float = DEFAULT_PICKUP_INTERVAL
var item_bones: Array[int] = []
@onready var gathering_center: Vector3 = global_position
@onready var collision_shape: CollisionShape3D = $NearbyItemsSearch
@onready var radius_indicator: VisualInstance3D = (
$NearbyItemsSearch/GatheringRadius
)
func _ready() -> void:
assert(collision_shape != null, "collision_shape missing!")
assert(radius_indicator != null, "radius_indicator missing!")
body_entered.connect(_on_body_entered)
body_exited.connect(_on_body_exited)
@ -62,28 +69,19 @@ func initialize(
item_bones = bones
func go_gather(item: Honeydew) -> void:
if anthill.space_left() <= 0:
return
if carrying_items.size() >= max_carrying:
go_deposit()
return
target = item
state = GatherState.PICKING_UP
target_set.emit(item.global_position)
func start_gathering(item: Honeydew) -> void:
gathering_center = item.global_position
_go_gather(item)
func go_deposit() -> void:
state = GatherState.DEPOSITING
var dir := anthill.global_position.direction_to(global_position)
target_set.emit(
anthill.global_position
+ dir
* ANTHILL_DEPOSIT_RADIUS
)
func stop_gathering() -> void:
state = GatherState.STOP
target = null
func handle_gathering(stop: bool) -> void:
collision_shape.global_position = gathering_center
collision_shape.global_rotation = Vector3.ZERO
if stop:
state = GatherState.STOP
@ -96,13 +94,25 @@ func on_nav_agent_navigation_finished() -> void:
_deposit()
func set_leftover(value: int) -> void:
deposit_leftover = value
func _go_gather(item: Honeydew) -> void:
if anthill.space_left() <= 0:
return
if carrying_items.size() >= max_carrying:
_go_deposit()
return
target = item
state = GatherState.PICKING_UP
target_set.emit(item.global_position)
func stop_all_gathering() -> void:
state = GatherState.STOP
target = null
func _go_deposit() -> void:
state = GatherState.DEPOSITING
var dir := anthill.global_position.direction_to(global_position)
target_set.emit(
anthill.global_position
+ dir
* ANTHILL_DEPOSIT_RADIUS
)
func _get_nth_pile_pos(n: int) -> Vector3:
@ -119,15 +129,15 @@ func _pick_up() -> void:
await get_tree().create_timer(pickup_interval).timeout
if carrying_items.size() >= max_carrying:
go_deposit()
_go_deposit()
return
var nearest := _find_nearest(nearby_items.values())
if nearest != null:
go_gather(nearest)
_go_gather(nearest)
return
go_deposit()
_go_deposit()
func _deposit() -> void:
@ -139,13 +149,12 @@ func _deposit() -> void:
if anthill.space_left() <= 0:
print('DROP!')
_drop_everything()
stop_all_gathering()
stop_gathering.emit()
stop_gathering()
stopped_gathering.emit()
return
var item := carrying_items.pop_back() as Honeydew
await item.start_moving(anthill.global_position).moved
ItemsManager.erase_honeydew(item)
_erase_honeydew(item)
item.queue_free()
anthill.deposit_honeydew(1)
@ -154,16 +163,11 @@ func _deposit() -> void:
state = GatherState.PICKING_UP
var nearest := _find_nearest(nearby_items.values())
if nearest != null:
go_gather(nearest)
return
var nearest_global := _find_nearest(ItemsManager.honeydews.values())
if nearest_global != null:
go_gather(nearest_global)
_go_gather(nearest)
return
stop_all_gathering()
stop_gathering.emit()
stop_gathering()
stopped_gathering.emit()
func _drop_everything() -> void:
@ -201,6 +205,7 @@ func _erase_honeydew(item: Honeydew) -> void:
func _on_body_entered(item: Node3D) -> void:
print(item, ' entered')
if item is not Honeydew:
return
@ -212,6 +217,7 @@ func _on_body_entered(item: Node3D) -> void:
func _on_body_exited(item: Node3D) -> void:
print(item, ' exited')
if item is not Honeydew:
return