From 33caf5b247e68e2b340ddb11092a89bcaa4caee8 Mon Sep 17 00:00:00 2001 From: tom Date: Tue, 19 Nov 2024 19:44:36 +0000 Subject: [PATCH] fix: handle gas steal edge case --- src/ares/build_runner/build_order_runner.py | 52 ++++++++++++--------- 1 file changed, 30 insertions(+), 22 deletions(-) diff --git a/src/ares/build_runner/build_order_runner.py b/src/ares/build_runner/build_order_runner.py index 3631808..4f5038b 100644 --- a/src/ares/build_runner/build_order_runner.py +++ b/src/ares/build_runner/build_order_runner.py @@ -647,6 +647,12 @@ def _get_position_and_supply_of_first_supply(self) -> tuple[Point2, float]: return self.ai.start_location, 999.9 def _handle_gas_steal(self) -> None: + can_assign: bool = True + if self.build_order[self.build_step].command in GAS_BUILDINGS and ( + len(self._geyser_tag_to_probe_tag) > 0 or self.current_step_started + ): + can_assign = False + enemy_workers: list[Unit] = [ w for w in self.ai.enemy_units @@ -654,29 +660,30 @@ def _handle_gas_steal(self) -> None: and cy_distance_to_squared(w.position, self.ai.start_location) < 144.0 ] - # there are enemy workers around - geysers: list[Unit] = [ - u - for u in self.ai.vespene_geyser - if cy_distance_to_squared(u.position, self.ai.start_location) < 144.0 - and not [ - g - for g in self.ai.all_gas_buildings - if cy_distance_to_squared(u.position, g.position) < 25.0 + if can_assign: + # there are enemy workers around + geysers: list[Unit] = [ + u + for u in self.ai.vespene_geyser + if cy_distance_to_squared(u.position, self.ai.start_location) < 144.0 + and not [ + g + for g in self.ai.all_gas_buildings + if cy_distance_to_squared(u.position, g.position) < 25.0 + ] ] - ] - if enemy_workers: - for geyser in geysers: - if geyser.tag not in self._geyser_tag_to_probe_tag: - if worker := self.mediator.select_worker( - target_position=geyser.position, force_close=True - ): - self.mediator.assign_role( - tag=worker.tag, role=UnitRole.GAS_STEAL_PREVENTER - ) - self._geyser_tag_to_probe_tag[geyser.tag] = worker.tag - worker.move(geyser.position) + if enemy_workers: + for geyser in geysers: + if geyser.tag not in self._geyser_tag_to_probe_tag: + if worker := self.mediator.select_worker( + target_position=geyser.position, force_close=True + ): + self.mediator.assign_role( + tag=worker.tag, role=UnitRole.GAS_STEAL_PREVENTER + ) + self._geyser_tag_to_probe_tag[geyser.tag] = worker.tag + worker.move(geyser.position) to_remove: (list[tuple]) = [] for geyser_tag, worker_tag in self._geyser_tag_to_probe_tag.items(): @@ -684,8 +691,9 @@ def _handle_gas_steal(self) -> None: if geyser_tag in self.ai.unit_tag_dict: geyser: Unit = self.ai.unit_tag_dict[geyser_tag] + # no enemy workers, or # gas building exists here now, clean up - if [ + if not enemy_workers or [ g for g in self.ai.all_gas_buildings if cy_distance_to_squared(geyser.position, g.position) < 25.0