Skip to content

Commit

Permalink
fix: handle gas steal edge case
Browse files Browse the repository at this point in the history
  • Loading branch information
raspersc2 committed Nov 19, 2024
1 parent 0a08687 commit 33caf5b
Showing 1 changed file with 30 additions and 22 deletions.
52 changes: 30 additions & 22 deletions src/ares/build_runner/build_order_runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -647,45 +647,53 @@ 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
if w.type_id in WORKER_TYPES
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():
assigned_worker_tag: int = self._geyser_tag_to_probe_tag[geyser_tag]
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
Expand Down

0 comments on commit 33caf5b

Please sign in to comment.