Skip to content

Commit

Permalink
Merge pull request #146 from AresSC2/feat/group-use-ability-behavior
Browse files Browse the repository at this point in the history
feat: new group use ability behavior
  • Loading branch information
raspersc2 authored Jun 9, 2024
2 parents da13710 + 23b0e6b commit d69ba9f
Show file tree
Hide file tree
Showing 3 changed files with 73 additions and 1 deletion.
5 changes: 5 additions & 0 deletions docs/api_reference/behaviors/group_combat_behaviors.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,8 @@
options:
show_root_heading: false
show_root_toc_entry: false

::: ares.behaviors.combat.group.group_use_ability
options:
show_root_heading: false
show_root_toc_entry: false
2 changes: 1 addition & 1 deletion docs/tutorials/build_runner.md
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ Upon completion of the build, a typical bot workflow should allow for dynamic pr
has been completed or not, you can use the following method call:

```python
self.build_order_runner.opening_completed
self.build_order_runner.build_completed
```

#### Set build complete
Expand Down
67 changes: 67 additions & 0 deletions src/ares/behaviors/combat/group/group_use_ability.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
from dataclasses import dataclass
from typing import TYPE_CHECKING, Union

from sc2.ids.ability_id import AbilityId
from sc2.position import Point2
from sc2.unit import Unit

from ares.behaviors.combat.group.combat_group_behavior import CombatGroupBehavior
from ares.managers.manager_mediator import ManagerMediator

if TYPE_CHECKING:
from ares import AresBot


@dataclass
class GroupUseAbility(CombatGroupBehavior):
"""Issue a single ability command for a group of units.
Example:
```py
from ares.behaviors.combat.group import GroupUseAbility
self.register_behavior(
GroupUseAbility(
AbilityId.MOVE_MOVE,
units,
{u.tag for u in units}
self.game_info.map_center
)
)
```
Attributes
----------
ability: AbilityId
Ability we want to use.
group : list[Unit]
Units we want to control.
group_tags : set[int]
The group unit tags.
target: Union[Point2, Unit, None]
The target for this ability.
sync_command: bool (default=True)
If True, wait for all units to be ready before trying ability
"""

ability: AbilityId
group: list[Unit]
group_tags: set[int]
target: Union[Point2, Unit]
sync_command: bool = True

def execute(self, ai: "AresBot", config: dict, mediator: ManagerMediator) -> bool:
if len(self.group) == 0:
return False

issue_command: bool
if self.sync_command:
issue_command = all([self.ability in u.abilities for u in self.group])
else:
issue_command = any([self.ability in u.abilities for u in self.group])

if not issue_command:
return False

ai.give_same_action(self.ability, self.group_tags, self.target)
return True

0 comments on commit d69ba9f

Please sign in to comment.