Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: remove requested placements #91

Merged
merged 2 commits into from
Nov 3, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion src/ares/build_runner/build_order_runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,10 +121,12 @@ async def run_build(self) -> None:
if len(self.build_order) > 0:
await self.do_step(self.build_order[self.build_step])

if not self.build_completed and self.build_step >= len(self.build_order):
if self.build_completed or len(self.ai.townhalls) > 1 or self.ai.time > 120.0:
self.mediator.switch_roles(
from_role=UnitRole.PERSISTENT_BUILDER, to_role=UnitRole.GATHERING
)

if not self.build_completed and self.build_step >= len(self.build_order):
self._opening_build_completed = True
return

Expand Down
52 changes: 30 additions & 22 deletions src/ares/managers/placement_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -301,29 +301,35 @@ def request_building_placement(
)
return
base_locations.remove(location)
location = min(
locations = sorted(
base_locations,
key=lambda k: cy_distance_to(k, base_location),
)
logger.warning(
f"No available {building_size} found near location: "
f"{base_location}, trying near {location}"
)
potential_placements: dict[Point2:dict] = self.placements_dict[
location
][building_size]
available: list[Point2] = [
placement
for placement in potential_placements
if potential_placements[placement]["available"]
and not potential_placements[placement]["worker_on_route"]
and self.can_place_structure(placement, structure_type)
]
if len(available) == 0:
for location in locations:
logger.warning(
f"No available {building_size} found near location: {location}"
f"No available {building_size} found near location: "
f"{base_location}, trying near {location}"
)
return
potential_placements: dict[Point2:dict] = self.placements_dict[
location
][building_size]
available: list[Point2] = [
placement
for placement in potential_placements
if potential_placements[placement]["available"]
and not potential_placements[placement]["worker_on_route"]
and self.can_place_structure(placement, structure_type)
]
if len(available) == 0:
logger.warning(
f"No {building_size} found near location: {location}"
)
# FOUND SOMETHING! Break out and continue
else:
break

if len(available) == 0:
logger.warning(f"No available {building_size} found, giving up")

# get closest available by default
final_placement: Point2 = min(
Expand Down Expand Up @@ -909,7 +915,9 @@ def _track_requested_placements(self) -> None:
> base_placements[two_by_two][building_location]["time_requested"]
+ self.WORKER_ON_ROUTE_TIMEOUT
):
base_placements[two_by_two][building_location]["available"] = True
self._make_placement_available(
two_by_two, base_location, building_location
)
loc_to_remove.append(building_location)

elif building_location in base_placements[three_by_three]:
Expand All @@ -920,9 +928,9 @@ def _track_requested_placements(self) -> None:
]
+ self.WORKER_ON_ROUTE_TIMEOUT
):
base_placements[three_by_three][building_location][
"available"
] = True
self._make_placement_available(
three_by_three, base_location, building_location
)
loc_to_remove.append(building_location)

for loc in loc_to_remove:
Expand Down
Loading