-
Notifications
You must be signed in to change notification settings - Fork 0
/
genmgr.py
98 lines (85 loc) · 3.57 KB
/
genmgr.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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
from sc2.unit import UnitTypeId
from creepmgr import CreepManager
from combatmgr import CombatManager
from macromgr import MacroManager
from pathmgr import PathManager
from queens_sc2.queens import Queens
from queen_policy import QueenPolicy
from MapAnalyzer import MapData
class GeneralManager:
def __init__(self, bot) -> None:
self.bot = bot
self.mm = MacroManager(bot)
self.cm = CombatManager(bot)
self.cp = CreepManager(bot)
self.pm = PathManager(bot)
self.map_data = None
self.queens = None
self.qp = None
def setup(self) -> None:
"""
Setting MapData here in case we need to pass this to other managers.
Though we could use a # function in PathManager: get_map_data, but I think this is fine
Returns
-------
"""
self.map_data = MapData(self.bot)
self.setup_queens()
self.pm.setup(self.map_data)
self.cp.setup(self.pm)
# self.mm.setup()
# self.cm.setup()
async def manage(self, iteration: int) -> None:
# TODO: It might be better to manaege iteration calls here
await self.mm.manage()
await self.cm.manage()
if self.bot.iteration % 90 == 0 and self.bot.units(UnitTypeId.QUEEN):
targets = self.cp.get_creep_targets()
if targets:
self.queens.update_creep_targets(targets)
await self.queens.manage_queens(iteration)
await self.build_queens()
def setup_queens(self):
self.qp = QueenPolicy(self.bot)
self.queens = Queens(self.bot, True, self.qp.queen_policy)
async def build_queens(self) -> None:
"""
If a pool exists and bot can afford build a queen.
:params: Queens object
"""
queen_count: int = self.bot.units(UnitTypeId.QUEEN).amount
queens: Queens = self.queens
# hatches = dictops.get_values(self.structures, 'Hatchery')
# TODO: Probably want to keep this in case we update the queen count in the policy.
cq: int = queens.policies.get('creep_policy').max_queens
dq: int = queens.policies.get('defence_policy').max_queens
iq: int = queens.policies.get('inject_policy').max_queens
if (queen_count + self.bot.already_pending(UnitTypeId.QUEEN)) < (cq + dq + iq):
if self.bot.structures(UnitTypeId.SPAWNINGPOOL).ready:
if self.bot.can_afford(UnitTypeId.QUEEN):
for hatchery in self.bot.townhalls.ready:
if hatchery.is_idle:
hatchery.train(UnitTypeId.QUEEN)
# def get_pos_around_unit(
# self, unit, min_range=0, max_range=500, step_size=1, loc_amt=32
# ):
# """
# TODO: need to fix loc_amt - despite having a value in there, get_pos_around_unit was retuning 70+ positions - could possibly be hard on system
# resources at a later date
# # e.g. loc_amt=4 would only consider 4 points: north, west, east, south
# """
# loc = unit.position.to2
# # loc = unit
# positions = [
# Point2(
# (
# loc.x + distance * math.cos(math.pi * 2 * alpha / loc_amt),
# loc.y + distance * math.sin(math.pi * 2 * alpha / loc_amt),
# )
# )
# for alpha in range(
# loc_amt
# ) # alpha is the angle here, locationAmount is the variable on how accurate the attempts look like a circle (= how many points on a circle)
# for distance in range(min_range, max_range + 1)
# ] # distance depending on minrange and maxrange
# return positions