Skip to content

Commit

Permalink
Merge pull request #122 from AresSC2/feat/persistent-worker-improvement
Browse files Browse the repository at this point in the history
feat: only select persistent worker generically
  • Loading branch information
raspersc2 authored Mar 21, 2024
2 parents 5e21c4b + afa60d3 commit e99bddc
Showing 1 changed file with 18 additions and 8 deletions.
26 changes: 18 additions & 8 deletions src/ares/build_runner/build_order_runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
BUILDS,
GAS_BUILDINGS,
OPENING_BUILD_ORDER,
TARGET,
BuildOrderTargetOptions,
UnitRole,
)
Expand Down Expand Up @@ -189,18 +190,27 @@ async def do_step(self, step: BuildOrderStep) -> None:
if command in ADD_ONS:
self.current_step_started = True
elif command in ALL_STRUCTURES:
persistent_workers: Units = self.mediator.get_units_from_role(
role=UnitRole.PERSISTENT_BUILDER
)
building_tracker: dict = self.mediator.get_building_tracker_dict
persistent_worker_available: bool = False
if self.persistent_worker:
for worker in persistent_workers:
if worker.tag in building_tracker:
target: Point2 = building_tracker[worker.tag][TARGET]
if [
s
for s in self.ai.structures
if cy_distance_to_squared(s.position, target) < 6
and s.build_progress > 0.95
]:
persistent_worker_available = True
if worker := self.mediator.select_worker(
target_position=self.current_build_position,
force_close=True,
select_persistent_builder=command != UnitID.REFINERY,
only_select_persistent_builder=self.persistent_worker
and command
in {UnitID.BARRACKS, UnitID.FACTORY, UnitID.COMMANDCENTER}
and (
not self.ai.already_pending(UnitID.BARRACKS)
or command != UnitID.BARRACKS
)
and self.ai.time < 125.0,
only_select_persistent_builder=persistent_worker_available,
):
if next_building_position := await self.get_position(
step.command, step.target
Expand Down

0 comments on commit e99bddc

Please sign in to comment.