Skip to content

Commit

Permalink
Merge pull request #79 from AresSC2/feat/reduced-apm
Browse files Browse the repository at this point in the history
feat: reduce repetitive actions in mining and building
  • Loading branch information
raspersc2 authored Sep 10, 2023
2 parents d50516a + 0cb9085 commit 8c270ac
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
9 changes: 9 additions & 0 deletions src/ares/behaviors/macro/mining.py
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,7 @@ def _do_standard_mining(self, ai: AresBot, worker: Unit, resource: Unit) -> None
# moved worker from gas
if worker.is_carrying_vespene and resource.is_mineral_field:
worker.return_resource()
self.locked_action_tags[worker_tag] = ai.time
else:
# work out when we need to issue command to mine resource
if worker.is_idle or (
Expand All @@ -258,6 +259,7 @@ def _do_standard_mining(self, ai: AresBot, worker: Unit, resource: Unit) -> None
and worker.order_target != resource
):
worker.gather(resource)
self.locked_action_tags[worker_tag] = ai.time
return

# force worker to stay on correct resource
Expand Down Expand Up @@ -300,6 +302,9 @@ def _long_distance_mining(
-------
"""
if worker.is_gathering:
return

completed_bases: Units = ai.townhalls.ready
# there is nowhere to return resources!
if not completed_bases:
Expand Down Expand Up @@ -349,9 +354,13 @@ def _long_distance_mining(
)
worker.move(move_to)
elif ai.mineral_field:
if worker.order_target and worker.order_target == target_mineral:
return
worker.gather(target_mineral)
# worker is travelling back to a ready townhall
else:
if worker.is_returning:
return
return_base: Unit = cy_closest_to(worker_position, completed_bases)
return_base_position: Point2 = return_base.position
if (
Expand Down
7 changes: 7 additions & 0 deletions src/ares/managers/building_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -248,11 +248,18 @@ async def _handle_construction_orders(self) -> None:
worker.build_gas(target)

elif cy_distance_to(worker.position, target.position) > distance:
order_target: Union[int, Point2, None] = worker.order_target
point: Point2 = self.manager_mediator.find_path_next_point(
start=worker.position,
target=target.position,
grid=self.manager_mediator.get_ground_grid,
)
if (
order_target
and isinstance(order_target, Point2)
and order_target == point
):
continue
worker.move(point)

else:
Expand Down

0 comments on commit 8c270ac

Please sign in to comment.