improve select_build_worker
@@ -386,13 +386,12 @@ class BotAI:
return False
def select_build_worker(self, pos: Union[Unit, Point2, Point3], force: bool=False) -> Optional[Unit]:
- """Select a worker to build a bulding with."""
-
- workers = self.workers.closer_than(20, pos) or self.workers
+ """Select a worker to build a building with."""
+ workers = self.workers.filter(lambda w: (w.is_gathering or w.is_idle) and w.distance_to(pos) < 20) or self.workers
+ if workers:
for worker in workers.sorted_by_distance_to(pos).prefer_idle:
if not worker.orders or len(worker.orders) == 1 and worker.orders[0].ability.id in {AbilityId.MOVE,
- AbilityId.HARVEST_GATHER,
- AbilityId.HARVEST_RETURN}:
+ AbilityId.HARVEST_GATHER}:
return worker
return workers.random if force else None
