diff --git a/assets/textures/gui/unit_state.png b/assets/textures/gui/unit_state.png index 807361b..05c068e 100644 --- a/assets/textures/gui/unit_state.png +++ b/assets/textures/gui/unit_state.png @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:a6255c2fd3b6032d7089c43733330f1420282ddb8752b39365a357f20e8070e0 -size 34352 +oid sha256:3e0a2a056bfbec1598030a1ef675768693d319a828346cb3611ff16efb8982d4 +size 70138 diff --git a/scripts/anthill.gd b/scripts/anthill.gd index 2937128..10e8d2f 100644 --- a/scripts/anthill.gd +++ b/scripts/anthill.gd @@ -1,6 +1,8 @@ extends Interactable class_name Anthill +signal buy_ant + const SPAWN_RADIUS: float = 1 const DEFAULT_MAX_HONEYDEW: int = 120 @@ -82,4 +84,5 @@ func _create_unit( ) if ding: audio_player.play_sound(SoundManager.ding()) + buy_ant.emit() return new_unit diff --git a/scripts/ui/unit_info.gd b/scripts/ui/unit_info.gd index 8a7caf8..f077524 100644 --- a/scripts/ui/unit_info.gd +++ b/scripts/ui/unit_info.gd @@ -7,7 +7,8 @@ enum State { ANT_MOVING, ANT_PICKING_UP, ANT_DEPOSITING, - ANT_AWAITING, + ANT_WAITING_FOR_NEW_ITEMS, + ANT_WAITING_FOR_MORE_SPACE, APHID_IDLE, APHID_PANIC, APHID_EAT, @@ -90,7 +91,9 @@ func _get_gathering_state(gather_state: Gathering.State) -> void: _state = State.ANT_PICKING_UP Gathering.State.DEPOSITING: _state = State.ANT_DEPOSITING - Gathering.State.AWAITING: - _state = State.ANT_AWAITING + Gathering.State.WAITING_FOR_NEW_ITEMS: + _state = State.ANT_WAITING_FOR_NEW_ITEMS + Gathering.State.WAITING_FOR_MORE_SPACE: + _state = State.ANT_WAITING_FOR_MORE_SPACE Gathering.State.STOP: _state = State.NONE diff --git a/scripts/units/components/gathering.gd b/scripts/units/components/gathering.gd index 68484db..00598ae 100644 --- a/scripts/units/components/gathering.gd +++ b/scripts/units/components/gathering.gd @@ -4,7 +4,8 @@ class_name Gathering const ANTHILL_DEPOSIT_RADIUS: float = 0.5 enum State { - AWAITING, + WAITING_FOR_NEW_ITEMS, + WAITING_FOR_MORE_SPACE, PICKING_UP, DEPOSITING, STOP, @@ -88,6 +89,7 @@ func initialize( _skeleton = skeleton_3d _item_bones = bones _unit.moving_started.connect(_on_unit_moving_started) + _unit.anthill.buy_ant.connect(_on_anthill_buy_ant) _unit.nav_agent.navigation_finished.connect( _on_nav_agent_navigation_finished ) @@ -100,10 +102,7 @@ func start_gathering(item: Honeydew) -> void: func _go_pick_up(item: Honeydew) -> void: - if _unit.anthill.space_left() <= 0: - state = State.AWAITING - return - if _carrying_items.size() >= _max_carrying: + if _carrying_items.size() == _max_carrying: _go_deposit() return _target = item @@ -112,8 +111,8 @@ func _go_pick_up(item: Honeydew) -> void: func _go_deposit() -> void: - if _unit.anthill.space_left() <= 0: - state = State.AWAITING + if _unit.anthill.space_left() == 0: + state = State.WAITING_FOR_MORE_SPACE return state = State.DEPOSITING var dir := _unit.anthill.global_position.direction_to(global_position) @@ -132,8 +131,8 @@ func _get_nth_pile_pos(n: int) -> Vector3: func _pick_up() -> void: if _target == null or _target.carried: - state = State.AWAITING - if _nearby_items.size() != 0: + state = State.WAITING_FOR_NEW_ITEMS + if _nearby_items.size() > 0: _go_pick_up(_find_nearest(_nearby_items.values())) elif _carrying_items.size() > 0: _go_deposit() @@ -148,7 +147,7 @@ func _pick_up() -> void: audio_player.play_sound(SoundManager.pop()) await get_tree().create_timer(_pickup_interval).timeout - if _carrying_items.size() >= _max_carrying or _nearby_items.size() == 0: + if _carrying_items.size() == _max_carrying or _nearby_items.size() == 0: _go_deposit() return @@ -161,8 +160,8 @@ func _deposit() -> void: if state != State.DEPOSITING: return - if _unit.anthill.space_left() <= 0: - state = State.AWAITING + if _unit.anthill.space_left() == 0: + state = State.WAITING_FOR_MORE_SPACE return var item := _carrying_items.pop_back() as Honeydew @@ -178,7 +177,7 @@ func _deposit() -> void: await get_tree().create_timer(_drop_interval).timeout if _nearby_items.size() == 0: - state = State.AWAITING + state = State.WAITING_FOR_NEW_ITEMS _unit.navigate(gathering_center) return @@ -215,7 +214,10 @@ func _on_body_entered(item: Node3D) -> void: return _nearby_items[item_id] = item as Honeydew - if state == State.AWAITING: + if ( + state == State.WAITING_FOR_NEW_ITEMS + or state == State.WAITING_FOR_MORE_SPACE + ): _go_pick_up(item as Honeydew) @@ -237,3 +239,20 @@ func _on_nav_agent_navigation_finished() -> void: if state == State.DEPOSITING: _deposit() + + +func _on_anthill_buy_ant() -> void: + if state != State.WAITING_FOR_MORE_SPACE: + return + + if ( + _carrying_items.size() == _max_carrying + or (_carrying_items.size() > 0 and _nearby_items.size() == 0) + ): + _go_deposit() + return + + if _nearby_items.size() > 0: + _go_pick_up(_find_nearest(_nearby_items.values())) + else: + state = State.WAITING_FOR_NEW_ITEMS