From 94dcb496f6d6e55eb8dae31daeccabc3a1c96be6 Mon Sep 17 00:00:00 2001 From: FredNoonienSingh Date: Sat, 11 Jan 2025 23:33:33 +0100 Subject: [PATCH] workers now premove to the build pos --- bot/HarstemsAunt/macro.py | 11 ++++++++++- bot/HarstemsAunt/utils.py | 7 ++++++- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/bot/HarstemsAunt/macro.py b/bot/HarstemsAunt/macro.py index 86ad974..519d477 100644 --- a/bot/HarstemsAunt/macro.py +++ b/bot/HarstemsAunt/macro.py @@ -5,6 +5,7 @@ from sc2.unit import Unit from sc2.units import Units from sc2.bot_ai import BotAI +from sc2.game_data import Cost from sc2.ids.buff_id import BuffId from sc2.position import Point2, Point3 from sc2.ids.ability_id import AbilityId @@ -62,7 +63,7 @@ async def __call__(self): def get_build_worker(self) -> Unit: """ returns the build worker """ - return self.bot.workers.closest_to(self.build_order.get_build_pos()) + return self.bot.workers.closest_n_units(self.build_order.get_build_pos(), 1)[0] def get_production_structure(self, unit_type: UnitTypeId) -> UnitTypeId: """ returns the appropriate production structure @@ -146,12 +147,20 @@ async def train_unit(next_step:BuildInstruction): #TODO: #77 STOP COUNTER FROM GOING CRAZY self.build_order.increment_step() + next_step: BuildInstruction = self.build_order.next_instruction() if not next_step and self.build_order.buffer: next_step = self.build_order.get_instruction_from_buffer() if not next_step and not self.build_order.buffer: return + if not next_step.type_id == UnitTypeId.ASSIMILATOR: + structure_cost:Cost = self.bot.calculate_cost(next_step.type_id) + if (self.bot.minerals > (structure_cost.minerals*0.65)): + if not Utils.unittype_in_proximity_to_point(self.bot, UnitTypeId.PROBE, next_step.position): + worker: Unit = self.get_build_worker() + worker.move(next_step.position) + match next_step.instruction_type: case InstructionType.BUILD_STRUCTURE: await construct_building(next_step) diff --git a/bot/HarstemsAunt/utils.py b/bot/HarstemsAunt/utils.py index 49e63be..bf84ca2 100644 --- a/bot/HarstemsAunt/utils.py +++ b/bot/HarstemsAunt/utils.py @@ -6,6 +6,7 @@ from sc2.unit import Unit from sc2.bot_ai import BotAI +from sc2.game_data import GameData from sc2.position import Point2, Point3 from sc2.ids.upgrade_id import UpgradeId from sc2.ids.unit_typeid import UnitTypeId @@ -133,9 +134,13 @@ def get_warp_in_pos(bot:BotAI) -> Union[Point2, Point3, Unit]: if bot.enemy_units: active_prism = bot.units(UnitTypeId.WARPPRISM).closest_to(bot.enemy_units.center) else: - active_prism = bot.units(UnitTypeId.WARPPRISM).closest_to(bot.enemy_start_locations[0]) + active_prism = bot.units(UnitTypeId.WARPPRISM).closest_to(bot.enemy_start_locations[0]) return active_prism.position + @staticmethod + def unittype_in_proximity_to_point(bot:BotAI,type_id:UnitTypeId,point:Union[Point2,Point3,Unit],max_distance:float=.5) -> bool: + return bot.units(type_id).filter(lambda unit: unit.distance_to(point) bool: if bot.structures(structure_type).filter(lambda struct: struct.distance_to(structure)