Ejemplo n.º 1
0
    async def build_zerg(self, worker: Unit, count, position: Point2):
        if self.has_build_order(worker):
            action = worker.build(self.unit_type, position, queue=True)

            for order in worker.orders:
                if order.ability.id == action.ability:
                    # Don't add the same order twice
                    return

            self.do(action)

        # try the selected position first
        err: sc2.ActionResult = await self.ai.synchronous_do(
            worker.build(self.unit_type, position))
        if not err:
            self.print(f"Building {self.unit_type.name} to {position}")
            return  # success

        buildings = self.ai.structures
        creep = self.ai.state.creep

        for point in self.building_solver.building_position:
            if not buildings.closer_than(1, point) and self.is_on_creep(
                    creep, point):
                err: sc2.ActionResult = await self.ai.synchronous_do(
                    worker.build(self.unit_type, point))
                if not err:
                    return  # success
                else:
                    pass
                    # self.knowledge.print("err !!!!" + str(err.value) + " " + str(err))
        self.print("GRID POSITION NOT FOUND !!!!")
Ejemplo n.º 2
0
    async def build_protoss(self, worker: Unit, count, position: Point2):
        if self.has_build_order(worker):
            action = worker.build(self.unit_type, position, queue=True)

            for order in worker.orders:
                if order.ability.id == action.ability:
                    # Don't add the same order twice
                    return

            self.do(action)

        # try the selected position first
        err: sc2.ActionResult = await self.ai.synchronous_do(
            worker.build(self.unit_type, position))
        if not err:
            self.print(f"Building {self.unit_type.name} to {position}")
            return  # success

        is_pylon = self.unit_type == UnitTypeId.PYLON
        buildings = self.ai.structures
        matrix = self.ai.state.psionic_matrix
        iterator = self.get_iterator(is_pylon, count)

        if is_pylon:
            for point in self.building_solver.pylon_position[::iterator]:

                if not buildings.closer_than(1, point):
                    err: sc2.ActionResult = await self.ai.synchronous_do(
                        worker.build(self.unit_type, point))
                    if not err:
                        return  # success
                    else:
                        pass
                        # self.knowledge.print("err !!!!" + str(err.value) + " " + str(err))
        else:
            for point in self.building_solver.building_position[::iterator]:
                if not buildings.closer_than(1,
                                             point) and matrix.covers(point):
                    err: sc2.ActionResult = await self.ai.synchronous_do(
                        worker.build(self.unit_type, point))
                    if not err:
                        return  # success
                    else:
                        pass
                        # self.knowledge.print("err !!!!" + str(err.value) + " " + str(err))
        self.print("GRID POSITION NOT FOUND !!!!")
Ejemplo n.º 3
0
 def _upgrade_building(self, building: Unit, upgrade_to: UnitTypeId):
     """Upgrade an existing building to another phase (e.g Lair to Hive)"""
     building.build(upgrade_to)