forked from Dentosal/python-sc2
-
Notifications
You must be signed in to change notification settings - Fork 0
/
action.py
34 lines (30 loc) · 1.26 KB
/
action.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
from itertools import groupby
from s2clientprotocol import raw_pb2 as raw_pb, common_pb2 as common_pb
from .position import Point2
from .unit import Unit
def combine_actions(action_iter):
for key, items in groupby(action_iter, key=lambda a: a.combining_tuple):
ability, target, queue = key
if target is None:
cmd = raw_pb.ActionRawUnitCommand(
ability_id=ability.value,
unit_tags=list({u.unit.tag for u in items}),
queue_command=queue
)
elif isinstance(target, Point2):
cmd = raw_pb.ActionRawUnitCommand(
ability_id=ability.value,
unit_tags=list({u.unit.tag for u in items}),
queue_command=queue,
target_world_space_pos=common_pb.Point2D(x=target.x, y=target.y)
)
elif isinstance(target, Unit):
cmd = raw_pb.ActionRawUnitCommand(
ability_id=ability.value,
unit_tags=[u.unit.tag for u in items],
queue_command=queue,
target_unit_tag=target.tag
)
else:
raise RuntimeError(f"Must target an unit or a point or None, found '{target !r}'")
yield raw_pb.ActionRaw(unit_command=cmd)