diff --git a/src/ares/build_runner/build_order_runner.py b/src/ares/build_runner/build_order_runner.py index afe5d99..e162955 100644 --- a/src/ares/build_runner/build_order_runner.py +++ b/src/ares/build_runner/build_order_runner.py @@ -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 diff --git a/src/ares/managers/placement_manager.py b/src/ares/managers/placement_manager.py index 1dc130f..fb4cc47 100644 --- a/src/ares/managers/placement_manager.py +++ b/src/ares/managers/placement_manager.py @@ -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( @@ -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]: @@ -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: