remove items_manager and make honeydew searching tied to a position
This commit is contained in:
@@ -26,7 +26,6 @@ DebugDraw="*res://scripts/globals/debug_draw.gd"
|
|||||||
UiManager="*res://scripts/globals/ui_manager.gd"
|
UiManager="*res://scripts/globals/ui_manager.gd"
|
||||||
HoveringManager="*res://scripts/globals/hovering_manager.gd"
|
HoveringManager="*res://scripts/globals/hovering_manager.gd"
|
||||||
SelectionManager="*res://scripts/globals/selection_manager.gd"
|
SelectionManager="*res://scripts/globals/selection_manager.gd"
|
||||||
ItemsManager="*res://scripts/globals/items_manager.gd"
|
|
||||||
|
|
||||||
[debug]
|
[debug]
|
||||||
|
|
||||||
|
|||||||
@@ -18,7 +18,7 @@ orientation = 1
|
|||||||
|
|
||||||
[node name="Honeydew" type="CharacterBody3D"]
|
[node name="Honeydew" type="CharacterBody3D"]
|
||||||
collision_layer = 256
|
collision_layer = 256
|
||||||
collision_mask = 0
|
collision_mask = 256
|
||||||
script = ExtResource("1_6fg3d")
|
script = ExtResource("1_6fg3d")
|
||||||
|
|
||||||
[node name="MeshInstance3D" type="MeshInstance3D" parent="."]
|
[node name="MeshInstance3D" type="MeshInstance3D" parent="."]
|
||||||
|
|||||||
@@ -11,8 +11,15 @@ radius = 15.0
|
|||||||
script = ExtResource("2_7pblm")
|
script = ExtResource("2_7pblm")
|
||||||
|
|
||||||
[node name="Skeleton3D" parent="AntModel/Armature" index="0"]
|
[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/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/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/16/scale = Vector3(1, 1, 1)
|
||||||
bones/18/rotation = Quaternion(0.0294712, -6.21995e-15, 4.35675e-07, 0.999566)
|
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)
|
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/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/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/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/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/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/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/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/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)
|
bones/43/scale = Vector3(1, 1, 1)
|
||||||
|
|
||||||
[node name="GathererMesh" parent="AntModel/Armature/Skeleton3D" index="0"]
|
[node name="GathererMesh" parent="AntModel/Armature/Skeleton3D" index="0"]
|
||||||
@@ -39,8 +56,8 @@ visible = true
|
|||||||
[node name="NearbyItemsSearch" parent="Gathering" index="0"]
|
[node name="NearbyItemsSearch" parent="Gathering" index="0"]
|
||||||
shape = SubResource("SphereShape3D_f7l1n")
|
shape = SubResource("SphereShape3D_f7l1n")
|
||||||
|
|
||||||
[node name="GatheringRadius" parent="Gathering" index="1"]
|
[node name="GatheringRadius" parent="Gathering/NearbyItemsSearch" index="0"]
|
||||||
transform = Transform3D(30.6826, 0, 0, 0, 30.6826, 0, 0, 0, 30.6826, 0, 0, 0)
|
transform = Transform3D(30.8235, 0, 0, 0, 30.8235, 0, 0, 0, 30.8235, 0, 0, 0)
|
||||||
|
|
||||||
[editable path="AntModel"]
|
[editable path="AntModel"]
|
||||||
[editable path="Gathering"]
|
[editable path="Gathering"]
|
||||||
|
|||||||
@@ -10,6 +10,27 @@ radius = 4.0
|
|||||||
[node name="AntNitwit" instance=ExtResource("1_w0xhf")]
|
[node name="AntNitwit" instance=ExtResource("1_w0xhf")]
|
||||||
script = ExtResource("2_rfn2k")
|
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"]
|
[node name="NitwitMesh" parent="AntModel/Armature/Skeleton3D" index="1"]
|
||||||
visible = true
|
visible = true
|
||||||
|
|
||||||
@@ -18,8 +39,8 @@ visible = true
|
|||||||
[node name="NearbyItemsSearch" parent="Gathering" index="0"]
|
[node name="NearbyItemsSearch" parent="Gathering" index="0"]
|
||||||
shape = SubResource("SphereShape3D_dwl4o")
|
shape = SubResource("SphereShape3D_dwl4o")
|
||||||
|
|
||||||
[node name="GatheringRadius" parent="Gathering" index="1"]
|
[node name="GatheringRadius" parent="Gathering/NearbyItemsSearch" index="0"]
|
||||||
transform = Transform3D(8.2687, 0, 0, 0, 8.2687, 0, 0, 0, 8.2687, 0, 0, 0)
|
transform = Transform3D(8.24392, 0, 0, 0, 8.24392, 0, 0, 0, 8.24392, 0, 0, 0)
|
||||||
|
|
||||||
[editable path="AntModel"]
|
[editable path="AntModel"]
|
||||||
[editable path="Gathering"]
|
[editable path="Gathering"]
|
||||||
|
|||||||
@@ -16,6 +16,7 @@ script = ExtResource("1_ciwtf")
|
|||||||
|
|
||||||
[node name="NearbyItemsSearch" type="CollisionShape3D" parent="."]
|
[node name="NearbyItemsSearch" type="CollisionShape3D" parent="."]
|
||||||
|
|
||||||
[node name="GatheringRadius" type="MeshInstance3D" parent="."]
|
[node name="GatheringRadius" type="MeshInstance3D" parent="NearbyItemsSearch"]
|
||||||
cast_shadow = 0
|
cast_shadow = 0
|
||||||
mesh = SubResource("QuadMesh_ks8es")
|
mesh = SubResource("QuadMesh_ks8es")
|
||||||
|
skeleton = NodePath("../..")
|
||||||
|
|||||||
@@ -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)
|
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")]
|
[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")]
|
[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")]
|
[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")]
|
[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")]
|
[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")]
|
[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")]
|
[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")]
|
[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")]
|
[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")]
|
[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")]
|
[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="."]
|
[node name="Bunches" type="Node" parent="."]
|
||||||
|
|
||||||
|
|||||||
@@ -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)
|
|
||||||
@@ -32,7 +32,7 @@ func _ready() -> void:
|
|||||||
item_bones.append(skeleton.find_bone(ITEM_BONE_NAME + str(i)))
|
item_bones.append(skeleton.find_bone(ITEM_BONE_NAME + str(i)))
|
||||||
gathering.initialize(anthill, skeleton, item_bones, MAX_CARRY, 0.4, 1)
|
gathering.initialize(anthill, skeleton, item_bones, MAX_CARRY, 0.4, 1)
|
||||||
gathering.target_set.connect(_on_gathering_target_set)
|
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:
|
func _process(delta: float) -> void:
|
||||||
@@ -47,7 +47,7 @@ func _process(delta: float) -> void:
|
|||||||
func _interact(with: Interactable) -> void:
|
func _interact(with: Interactable) -> void:
|
||||||
if with is Honeydew:
|
if with is Honeydew:
|
||||||
state = AntGathererState.GATHERING
|
state = AntGathererState.GATHERING
|
||||||
gathering.go_gather(with as Honeydew)
|
gathering.start_gathering(with as Honeydew)
|
||||||
|
|
||||||
|
|
||||||
func _handle_wandering(delta: float) -> void:
|
func _handle_wandering(delta: float) -> void:
|
||||||
@@ -67,7 +67,7 @@ func _on_moving_ended() -> void:
|
|||||||
|
|
||||||
func _on_moving_started() -> void:
|
func _on_moving_started() -> void:
|
||||||
if state == AntGathererState.GATHERING:
|
if state == AntGathererState.GATHERING:
|
||||||
gathering.stop_all_gathering()
|
gathering.stop_gathering()
|
||||||
state = AntGathererState.MOVING
|
state = AntGathererState.MOVING
|
||||||
|
|
||||||
|
|
||||||
@@ -78,5 +78,5 @@ func _on_gathering_target_set(pos: Vector3) -> void:
|
|||||||
nav_agent.set_target_position(pos)
|
nav_agent.set_target_position(pos)
|
||||||
|
|
||||||
|
|
||||||
func _on_gathering_stop() -> void:
|
func _on_stopped_gathering() -> void:
|
||||||
state = AntGathererState.WANDERING
|
state = AntGathererState.WANDERING
|
||||||
|
|||||||
@@ -31,7 +31,7 @@ func _ready() -> void:
|
|||||||
item_bones.append(skeleton.find_bone(ITEM_BONE_NAME + str(i)))
|
item_bones.append(skeleton.find_bone(ITEM_BONE_NAME + str(i)))
|
||||||
gathering.initialize(anthill, skeleton, item_bones)
|
gathering.initialize(anthill, skeleton, item_bones)
|
||||||
gathering.target_set.connect(_on_gathering_target_set)
|
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:
|
func _process(delta: float) -> void:
|
||||||
@@ -46,7 +46,7 @@ func _process(delta: float) -> void:
|
|||||||
func _interact(with: Interactable) -> void:
|
func _interact(with: Interactable) -> void:
|
||||||
if with is Honeydew:
|
if with is Honeydew:
|
||||||
state = AntNitwitState.GATHERING
|
state = AntNitwitState.GATHERING
|
||||||
gathering.go_gather(with as Honeydew)
|
gathering.start_gathering(with as Honeydew)
|
||||||
|
|
||||||
|
|
||||||
func _handle_wandering(delta: float) -> void:
|
func _handle_wandering(delta: float) -> void:
|
||||||
@@ -66,7 +66,7 @@ func _on_moving_ended() -> void:
|
|||||||
|
|
||||||
func _on_moving_started() -> void:
|
func _on_moving_started() -> void:
|
||||||
if state == AntNitwitState.GATHERING:
|
if state == AntNitwitState.GATHERING:
|
||||||
gathering.stop_all_gathering()
|
gathering.stop_gathering()
|
||||||
state = AntNitwitState.MOVING
|
state = AntNitwitState.MOVING
|
||||||
|
|
||||||
|
|
||||||
@@ -77,5 +77,5 @@ func _on_gathering_target_set(pos: Vector3) -> void:
|
|||||||
nav_agent.set_target_position(pos)
|
nav_agent.set_target_position(pos)
|
||||||
|
|
||||||
|
|
||||||
func _on_gathering_stop() -> void:
|
func _on_stopped_gathering() -> void:
|
||||||
state = AntNitwitState.WANDERING
|
state = AntNitwitState.WANDERING
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ extends Area3D
|
|||||||
class_name Gathering
|
class_name Gathering
|
||||||
|
|
||||||
signal target_set(pos: Vector3)
|
signal target_set(pos: Vector3)
|
||||||
signal stop_gathering
|
signal stopped_gathering
|
||||||
|
|
||||||
const DEFAULT_MAX_CARRYING = 3
|
const DEFAULT_MAX_CARRYING = 3
|
||||||
const DEFAULT_DROP_INTERVAL = 0.25
|
const DEFAULT_DROP_INTERVAL = 0.25
|
||||||
@@ -21,7 +21,6 @@ var state: GatherState = GatherState.STOP
|
|||||||
var nearby_items: Dictionary = {}
|
var nearby_items: Dictionary = {}
|
||||||
var carrying_items: Array[Honeydew] = []
|
var carrying_items: Array[Honeydew] = []
|
||||||
var max_carrying: int = DEFAULT_MAX_CARRYING
|
var max_carrying: int = DEFAULT_MAX_CARRYING
|
||||||
var deposit_leftover: int = 0
|
|
||||||
|
|
||||||
var target: Honeydew
|
var target: Honeydew
|
||||||
var anthill: Anthill
|
var anthill: Anthill
|
||||||
@@ -31,8 +30,16 @@ var drop_interval: float = DEFAULT_DROP_INTERVAL
|
|||||||
var pickup_interval: float = DEFAULT_PICKUP_INTERVAL
|
var pickup_interval: float = DEFAULT_PICKUP_INTERVAL
|
||||||
var item_bones: Array[int] = []
|
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:
|
func _ready() -> void:
|
||||||
|
assert(collision_shape != null, "collision_shape missing!")
|
||||||
|
assert(radius_indicator != null, "radius_indicator missing!")
|
||||||
body_entered.connect(_on_body_entered)
|
body_entered.connect(_on_body_entered)
|
||||||
body_exited.connect(_on_body_exited)
|
body_exited.connect(_on_body_exited)
|
||||||
|
|
||||||
@@ -62,28 +69,19 @@ func initialize(
|
|||||||
item_bones = bones
|
item_bones = bones
|
||||||
|
|
||||||
|
|
||||||
func go_gather(item: Honeydew) -> void:
|
func start_gathering(item: Honeydew) -> void:
|
||||||
if anthill.space_left() <= 0:
|
gathering_center = item.global_position
|
||||||
return
|
_go_gather(item)
|
||||||
if carrying_items.size() >= max_carrying:
|
|
||||||
go_deposit()
|
|
||||||
return
|
|
||||||
target = item
|
|
||||||
state = GatherState.PICKING_UP
|
|
||||||
target_set.emit(item.global_position)
|
|
||||||
|
|
||||||
|
|
||||||
func go_deposit() -> void:
|
func stop_gathering() -> void:
|
||||||
state = GatherState.DEPOSITING
|
state = GatherState.STOP
|
||||||
var dir := anthill.global_position.direction_to(global_position)
|
target = null
|
||||||
target_set.emit(
|
|
||||||
anthill.global_position
|
|
||||||
+ dir
|
|
||||||
* ANTHILL_DEPOSIT_RADIUS
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
func handle_gathering(stop: bool) -> void:
|
func handle_gathering(stop: bool) -> void:
|
||||||
|
collision_shape.global_position = gathering_center
|
||||||
|
collision_shape.global_rotation = Vector3.ZERO
|
||||||
if stop:
|
if stop:
|
||||||
state = GatherState.STOP
|
state = GatherState.STOP
|
||||||
|
|
||||||
@@ -96,13 +94,25 @@ func on_nav_agent_navigation_finished() -> void:
|
|||||||
_deposit()
|
_deposit()
|
||||||
|
|
||||||
|
|
||||||
func set_leftover(value: int) -> void:
|
func _go_gather(item: Honeydew) -> void:
|
||||||
deposit_leftover = value
|
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:
|
func _go_deposit() -> void:
|
||||||
state = GatherState.STOP
|
state = GatherState.DEPOSITING
|
||||||
target = null
|
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:
|
func _get_nth_pile_pos(n: int) -> Vector3:
|
||||||
@@ -119,15 +129,15 @@ func _pick_up() -> void:
|
|||||||
|
|
||||||
await get_tree().create_timer(pickup_interval).timeout
|
await get_tree().create_timer(pickup_interval).timeout
|
||||||
if carrying_items.size() >= max_carrying:
|
if carrying_items.size() >= max_carrying:
|
||||||
go_deposit()
|
_go_deposit()
|
||||||
return
|
return
|
||||||
|
|
||||||
var nearest := _find_nearest(nearby_items.values())
|
var nearest := _find_nearest(nearby_items.values())
|
||||||
if nearest != null:
|
if nearest != null:
|
||||||
go_gather(nearest)
|
_go_gather(nearest)
|
||||||
return
|
return
|
||||||
|
|
||||||
go_deposit()
|
_go_deposit()
|
||||||
|
|
||||||
|
|
||||||
func _deposit() -> void:
|
func _deposit() -> void:
|
||||||
@@ -139,13 +149,12 @@ func _deposit() -> void:
|
|||||||
if anthill.space_left() <= 0:
|
if anthill.space_left() <= 0:
|
||||||
print('DROP!')
|
print('DROP!')
|
||||||
_drop_everything()
|
_drop_everything()
|
||||||
stop_all_gathering()
|
stop_gathering()
|
||||||
stop_gathering.emit()
|
stopped_gathering.emit()
|
||||||
return
|
return
|
||||||
|
|
||||||
var item := carrying_items.pop_back() as Honeydew
|
var item := carrying_items.pop_back() as Honeydew
|
||||||
await item.start_moving(anthill.global_position).moved
|
await item.start_moving(anthill.global_position).moved
|
||||||
ItemsManager.erase_honeydew(item)
|
|
||||||
_erase_honeydew(item)
|
_erase_honeydew(item)
|
||||||
item.queue_free()
|
item.queue_free()
|
||||||
anthill.deposit_honeydew(1)
|
anthill.deposit_honeydew(1)
|
||||||
@@ -154,16 +163,11 @@ func _deposit() -> void:
|
|||||||
state = GatherState.PICKING_UP
|
state = GatherState.PICKING_UP
|
||||||
var nearest := _find_nearest(nearby_items.values())
|
var nearest := _find_nearest(nearby_items.values())
|
||||||
if nearest != null:
|
if nearest != null:
|
||||||
go_gather(nearest)
|
_go_gather(nearest)
|
||||||
return
|
|
||||||
|
|
||||||
var nearest_global := _find_nearest(ItemsManager.honeydews.values())
|
|
||||||
if nearest_global != null:
|
|
||||||
go_gather(nearest_global)
|
|
||||||
return
|
return
|
||||||
|
|
||||||
stop_all_gathering()
|
stop_gathering()
|
||||||
stop_gathering.emit()
|
stopped_gathering.emit()
|
||||||
|
|
||||||
|
|
||||||
func _drop_everything() -> void:
|
func _drop_everything() -> void:
|
||||||
@@ -201,6 +205,7 @@ func _erase_honeydew(item: Honeydew) -> void:
|
|||||||
|
|
||||||
|
|
||||||
func _on_body_entered(item: Node3D) -> void:
|
func _on_body_entered(item: Node3D) -> void:
|
||||||
|
print(item, ' entered')
|
||||||
if item is not Honeydew:
|
if item is not Honeydew:
|
||||||
return
|
return
|
||||||
|
|
||||||
@@ -212,6 +217,7 @@ func _on_body_entered(item: Node3D) -> void:
|
|||||||
|
|
||||||
|
|
||||||
func _on_body_exited(item: Node3D) -> void:
|
func _on_body_exited(item: Node3D) -> void:
|
||||||
|
print(item, ' exited')
|
||||||
if item is not Honeydew:
|
if item is not Honeydew:
|
||||||
return
|
return
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user