-
Notifications
You must be signed in to change notification settings - Fork 4
/
combat_group_behavior.py
79 lines (65 loc) · 2.35 KB
/
combat_group_behavior.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
from typing import TYPE_CHECKING, Protocol, Union
from cython_extensions import cy_distance_to_squared
from sc2.ids.ability_id import AbilityId
from sc2.position import Point2
from sc2.unit import Unit
from ares.behaviors.behavior import Behavior
from ares.managers.manager_mediator import ManagerMediator
if TYPE_CHECKING:
from ares import AresBot
class CombatGroupBehavior(Behavior, Protocol):
"""Interface that all group combat behaviors should adhere to."""
def execute(self, ai: "AresBot", config: dict, mediator: ManagerMediator) -> bool:
"""Execute the implemented behavior.
Parameters
----------
ai :
Bot object that will be running the game.
config :
Dictionary with the data from the configuration file.
mediator :
ManagerMediator used for getting information from other managers.
Returns
----------
bool :
CombatGroupBehavior carried out an action.
"""
...
def duplicate_or_similar_order(
self,
unit: Unit,
target: Union[Point2, Unit],
order_type: AbilityId,
distance_check_squared: float = 2.0,
) -> bool:
if (
cy_distance_to_squared(unit.position, target.position)
< distance_check_squared
):
return True
if order_target := unit.order_target:
# definitely not the same
if unit.orders[0].ability.id != order_type:
return False
# the pos we calculated is not that different to previous target
if (
isinstance(order_target, Point2)
and order_target.rounded == target.position.rounded
):
return True
if isinstance(order_target, Unit) and order_target == target:
return True
return False
def group_weapons_on_cooldown(
self, group: list[Unit], stutter_forward: bool
) -> bool:
avg_weapon_cooldown: float = sum([u.weapon_cooldown for u in group]) / len(
group
)
# all weapons are ready, should stay on attack command
if avg_weapon_cooldown <= 0.0:
return False
if stutter_forward:
return avg_weapon_cooldown > 2.5
else:
return avg_weapon_cooldown > 5.0