-
Notifications
You must be signed in to change notification settings - Fork 4
/
build_structure.py
75 lines (63 loc) · 2.29 KB
/
build_structure.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
from dataclasses import dataclass
from typing import TYPE_CHECKING, Optional
from sc2.data import Race
from sc2.ids.unit_typeid import UnitTypeId as UnitID
from sc2.position import Point2
if TYPE_CHECKING:
from ares import AresBot
from ares.behaviors.macro.macro_behavior import MacroBehavior
from ares.managers.manager_mediator import ManagerMediator
@dataclass
class BuildStructure(MacroBehavior):
"""Handy behavior for Terran and Protoss.
Especially combined with `Mining` and ares built in placement solver.
Finds an ideal mining worker, and an available precalculated placement.
Then removes worker from mining records and provides a new role.
Example:
```py
from ares.behaviors.macro import BuildStructure
self.register_behavior(
BuildStructure(self.start_location, UnitTypeId.BARRACKS)
)
```
Attributes
----------
base_location : Point2
The base location to build near.
structure_id : UnitTypeId
The structure type we want to build.
wall : bool
Find wall placement if possible.
(Only main base currently supported)
closest_to : Point2 (optional)
Find placement at this base closest to
"""
base_location: Point2
structure_id: UnitID
wall: bool = False
closest_to: Optional[Point2] = None
def execute(self, ai: "AresBot", config: dict, mediator: ManagerMediator) -> bool:
assert (
ai.race != Race.Zerg
), "BuildStructure Behavior not currently supported for Zerg."
within_psionic_matrix: bool = (
ai.race == Race.Protoss and self.structure_id != UnitID.PYLON
)
if placement := mediator.request_building_placement(
base_location=self.base_location,
structure_type=self.structure_id,
wall=self.wall,
within_psionic_matrix=within_psionic_matrix,
closest_to=self.closest_to,
):
if worker := mediator.select_worker(
target_position=placement,
force_close=True,
):
mediator.build_with_specific_worker(
worker=worker,
structure_type=self.structure_id,
pos=placement,
)
return True
return False