def requests_status_update(self): """ Logic to update the requests status """ if not self.true_start_location: command_centers = self.bot_player.units(UnitTypeId.COMMANDCENTER) if command_centers: self.true_start_location = command_centers[0].position if self._build_unit and self.bot_player.get_current_scv_unit(self._build_unit.unit_tags[0]): request = self._build_unit.info.request request_is_addon = is_addon(request.unit_type_id) if request_is_addon: if self._build_unit.build_upgraded_tag: units = self.bot_player.get_current_units([self._build_unit.build_upgraded_tag]) if units: unit = units[0] else: unit = None else: unit = None else: unit = self.bot_player.get_current_scv_unit(self._build_unit.unit_tags[0]) if unit: orders = unit.orders self._started_build_process = True for order in orders: target_unit = self.get_target_unit(order) request_status = request.status self._started_build_process = False if request_is_addon and order.ability.id in [AbilityId.BUILD_REACTOR, AbilityId.BUILD_REACTOR_BARRACKS, AbilityId.BUILD_REACTOR_FACTORY, AbilityId.BUILD_REACTOR_STARPORT, AbilityId.BUILD_TECHLAB, AbilityId.BUILD_TECHLAB_BARRACKS, AbilityId.BUILD_TECHLAB_FACTORY, AbilityId.BUILD_TECHLAB_STARPORT ]: self.bot_player.board_request.register( Request(request_priority=RequestPriority.PRIORITY_HIGHER, operation_type_id=OperationTypeId.TRAIN_MARINE_ALLOW) ) elif target_unit and target_unit.type_id == request.unit_type_id and not target_unit.is_ready: if request_status != RequestStatus.ON_GOING: self.log('Starting request: {}'.format(self._build_unit.info.request)) request.status = RequestStatus.ON_GOING elif (target_unit and target_unit.type_id == request.unit_type_id and target_unit.is_ready) or self.building_completed(request): request.status = RequestStatus.DONE self.bot_player.board_request.remove(request) elif order.ability.id in [AbilityId.HARVEST_GATHER, AbilityId.HARVEST_RETURN] and request.status == RequestStatus.START_DOING: request.status = RequestStatus.FAILED
async def requests_handler(self, iteration): """ Logic to go through the bot requests :param int iteration: Game loop iteration """ self.current_iteration = iteration for request in self.requests: if request.unit_type_id != UnitTypeId.SUPPLYDEPOT and \ self.bot_player.supply_left < 10 and self.bot_player.supply_cap < 200: Request(request_priority=RequestPriority.PRIORITY_HIGHER, unit_type_id=UnitTypeId.SUPPLYDEPOT, operation_type_id=OperationTypeId.BUILD) if not self._build_unit: self.set_build_unit(iteration=iteration, request=request) elif self._build_unit and (not self._build_unit.request or self._build_unit.request.status == RequestStatus.DONE or self._build_unit.request.status == RequestStatus.FAILED): self._build_unit.set_request(request) if not self._started_build_process and self._build_unit.request.status in [RequestStatus.TO_BE_DONE, RequestStatus.FAILED]: # evita treinar marines se precisar melhorar as barracas if is_addon(request.unit_type_id): self.bot_player.board_request.register( Request(request_priority=RequestPriority.PRIORITY_HIGHER, operation_type_id=OperationTypeId.TRAIN_MARINE_DENY) ) self._set_best_location(request) await self._build_unit.default_behavior(iteration) break if self._build_unit: await self._build_unit.depot_behaviour()
async def check_supply_dependencies(self, request, supply_dependencies, can_build): """ Check supply dependencies :param core.register_board.request.Request request: :param supply_dependencies: :param can_build: :return: """ if self.bot_player.supply_left > supply_dependencies: pass else: self.bot_player.board_request.register( Request(request_priority=request.request_priority_level, unit_type_id=UnitTypeId.SUPPLYDEPOT, operation_type_id=OperationTypeId.BUILD) ) can_build = False return can_build
async def check_build_dependencies(self, request, build_dependencies, can_build): """ Check build dependencies :param core.register_board.request.Request request: :param build_dependencies: :param can_build: :return: """ for dependency in build_dependencies: if self.bot_player.units(dependency).amount > 0: can_build = can_build and True else: self.bot_player.board_request.register( Request(request_priority=request.request_priority_level, unit_type_id=dependency, operation_type_id=OperationTypeId.BUILD) ) can_build = False break return can_build
async def check_technology_dependencies(self, request, tech_dependencies, can_build): """ Check technology dependencies :param core.register_board.request.Request request: :param tech_dependencies: :param can_build: :return: """ for dependency in tech_dependencies: if self.bot_player.get_available_abilities(dependency).amount > 0: can_build = can_build and True else: self.bot_player.board_request.register( Request(request_priority=request.request_priority_level, unit_type_id=dependency, operation_type_id=OperationTypeId.RESEARCH_TECHNOLOGY) ) can_build = False break return can_build
async def requests_handler(self, iteration): """ Logic to go through the bot requests :param int iteration: Game loop iteration """ await self.update_barracks_rally() have_an_army_request = False have_an_attack_request = False # self.bot_player.default_behavior(iteration) for request in self.requests: if request.operation_type_id == OperationTypeId.TRAIN_MARINE_ALLOW: self.can_train = True request.status = RequestStatus.DONE self.bot_player.board_request.remove(request) elif request.operation_type_id == OperationTypeId.TRAIN_MARINE_DENY: self.can_train = False request.status = RequestStatus.DONE self.bot_player.board_request.remove(request) elif request.status == RequestStatus.TO_BE_DONE and request.operation_type_id == OperationTypeId.ARMY: have_an_army_request = True if self.can_train: if request.unit_type_id == UnitTypeId.MARINE: barrack = self.find_ready_barracks() if barrack: await self.request_build(request, barrack) elif request.unit_type_id == UnitTypeId.MARAUDER: barrack_tech = self.find_ready_barracks_tech() if barrack_tech: await self.request_build(request, barrack_tech) elif request.status == RequestStatus.TO_BE_DONE and request.operation_type_id == OperationTypeId.ATTACK: if len(self.find_available_defense_units()) >= request.amount: self._defense_units = DefenseBot( bot_player=self.bot_player, iteration=iteration, request=request, unit_tags=util.get_units_tags( self.find_available_defense_units())) await self.attack(request, iteration, self._defense_units) elif request.status == RequestStatus.DONE and request.operation_type_id == OperationTypeId.ATTACK: #should go back to base if attack was finished...but is not working ;) if len(self.bot_player.known_enemy_units) == 0: await self.visit_base(self._defense_units) if not self._defense_units: available_defensive_units = self.find_available_defense_units() if available_defensive_units: self._defense_units = DefenseBot( bot_player=self.bot_player, iteration=iteration, request=request, unit_tags=util.get_units_tags( available_defensive_units)) if not have_an_army_request: self.bot_player.board_request.register( Request(request_priority=RequestPriority.PRIORITY_MEDIUM, unit_type_id=UnitTypeId.MARINE, amount=5, operation_type_id=OperationTypeId.ARMY))
def init_request_board(self): """ Initialize all first requests """ self.board_request.register( Request(request_priority=RequestPriority.PRIORITY_HIGH, operation_type_id=OperationTypeId.TRAIN_SCV_ALLOW)) self.board_request.register( Request(request_priority=RequestPriority.PRIORITY_HIGH, unit_type_id=UnitTypeId.SCV, operation_type_id=OperationTypeId.SCOUT)) self.board_request.register( Request(request_priority=RequestPriority.PRIORITY_HIGH, unit_type_id=UnitTypeId.SUPPLYDEPOT, operation_type_id=OperationTypeId.BUILD)) self.board_request.register( Request(request_priority=RequestPriority.PRIORITY_HIGH, unit_type_id=UnitTypeId.SUPPLYDEPOT, operation_type_id=OperationTypeId.BUILD)) self.board_request.register( Request(request_priority=RequestPriority.PRIORITY_HIGH, unit_type_id=UnitTypeId.SUPPLYDEPOT, operation_type_id=OperationTypeId.BUILD)) self.board_request.register( Request(request_priority=RequestPriority.PRIORITY_HIGH, unit_type_id=UnitTypeId.REFINERY, operation_type_id=OperationTypeId.BUILD)) self.board_request.register( Request(request_priority=RequestPriority.PRIORITY_HIGH, unit_type_id=UnitTypeId.BARRACKS, operation_type_id=OperationTypeId.BUILD)) self.board_request.register( Request(request_priority=RequestPriority.PRIORITY_HIGH, unit_type_id=UnitTypeId.COMMANDCENTER, operation_type_id=OperationTypeId.BUILD)) self.board_request.register( Request(request_priority=RequestPriority.PRIORITY_HIGH, unit_type_id=UnitTypeId.BARRACKS, operation_type_id=OperationTypeId.BUILD)) self.board_request.register( Request(request_priority=RequestPriority.PRIORITY_MEDIUM, unit_type_id=UnitTypeId.MARINE, amount=10, operation_type_id=OperationTypeId.ARMY)) self.board_request.register( Request(request_priority=RequestPriority.PRIORITY_HIGH, unit_type_id=UnitTypeId.BARRACKSTECHLAB, operation_type_id=OperationTypeId.BUILD)) self.board_request.register( Request(request_priority=RequestPriority.PRIORITY_HIGH, unit_type_id=UnitTypeId.SUPPLYDEPOT, operation_type_id=OperationTypeId.BUILD)) self.board_request.register( Request(request_priority=RequestPriority.PRIORITY_HIGH, unit_type_id=UnitTypeId.ENGINEERINGBAY, operation_type_id=OperationTypeId.BUILD)) self.board_request.register( Request(request_priority=RequestPriority.PRIORITY_HIGH, unit_type_id=UnitTypeId.FACTORY, operation_type_id=OperationTypeId.BUILD)) self.board_request.register( Request(request_priority=RequestPriority.PRIORITY_HIGH, unit_type_id=UnitTypeId.STARPORT, operation_type_id=OperationTypeId.BUILD)) self.board_request.register( Request(request_priority=RequestPriority.PRIORITY_HIGH, unit_type_id=UnitTypeId.SUPPLYDEPOT, operation_type_id=OperationTypeId.BUILD)) self.board_request.register( Request(request_priority=RequestPriority.PRIORITY_HIGH, unit_type_id=UnitTypeId.SUPPLYDEPOT, operation_type_id=OperationTypeId.BUILD)) self.board_request.register( Request(request_priority=RequestPriority.PRIORITY_MEDIUM, unit_type_id=UnitTypeId.MARINE, amount=15, operation_type_id=OperationTypeId.ARMY)) self.board_request.register( Request(request_priority=RequestPriority.PRIORITY_HIGH, unit_type_id=UnitTypeId.SUPPLYDEPOT, operation_type_id=OperationTypeId.BUILD)) self.board_request.register( Request(request_priority=RequestPriority.PRIORITY_HIGH, unit_type_id=UnitTypeId.REFINERY, operation_type_id=OperationTypeId.BUILD)) self.board_request.register( Request(request_priority=RequestPriority.PRIORITY_HIGH, unit_type_id=UnitTypeId.SUPPLYDEPOT, operation_type_id=OperationTypeId.BUILD)) self.board_request.register( Request(request_priority=RequestPriority.PRIORITY_HIGH, unit_type_id=UnitTypeId.SUPPLYDEPOT, operation_type_id=OperationTypeId.BUILD)) self.board_request.register( Request(request_priority=RequestPriority.PRIORITY_HIGH, unit_type_id=UnitTypeId.SUPPLYDEPOT, operation_type_id=OperationTypeId.BUILD)) self.board_request.register( Request(request_priority=RequestPriority.PRIORITY_HIGH, unit_type_id=UnitTypeId.SUPPLYDEPOT, operation_type_id=OperationTypeId.BUILD)) self.board_request.register( Request(request_priority=RequestPriority.PRIORITY_HIGH, unit_type_id=UnitTypeId.SUPPLYDEPOT, operation_type_id=OperationTypeId.BUILD)) self.board_request.register( Request(request_priority=RequestPriority.PRIORITY_HIGH, unit_type_id=UnitTypeId.SUPPLYDEPOT, operation_type_id=OperationTypeId.BUILD)) self.board_request.register( Request(request_priority=RequestPriority.PRIORITY_MEDIUM, unit_type_id=UnitTypeId.MARINE, operation_type_id=OperationTypeId.ARMY)) self.board_request.register( Request(request_priority=RequestPriority.PRIORITY_MEDIUM, unit_type_id=UnitTypeId.MARAUDER, amount=30, operation_type_id=OperationTypeId.ARMY)) self.board_request.register( Request(request_priority=RequestPriority.PRIORITY_MEDIUM, unit_type_id=UnitTypeId.MARINE, amount=200, operation_type_id=OperationTypeId.ARMY)) self.board_request.register( Request(request_priority=RequestPriority.PRIORITY_MEDIUM, amount=20, operation_type_id=OperationTypeId.ATTACK))
async def patrol(self): self.bot_player.board_request.register( Request(request_priority=RequestPriority.PRIORITY_HIGHER, unit_type_id=UnitTypeId.SCV, operation_type_id=OperationTypeId.PATROL)) await self.visit_base()