def _need_repair(self, repair_limit=0.70): """Check if fleet needs to be repaired. If the fleet is already at a system where it can be repaired, stay there until fully repaired. Otherwise, repair if fleet health is below specified *repair_limit*. For military fleets, there is a special evaluation called, cf. *MilitaryAI.avail_mil_needing_repair()* :param repair_limit: percentage of health below which the fleet is sent to repair :type repair_limit: float :return: True if fleet needs repair :rtype: bool """ # TODO: More complex evaluation if fleet needs repair (consider self-repair, distance, threat, mission...) fleet_id = self.fleet.id # if we are already at a system where we can repair, make sure we use it... system = self.fleet.get_system() # TODO starlane obstruction is not considered in the next call nearest_dock = MoveUtilsAI.get_best_drydock_system_id( system.id, fleet_id) if nearest_dock == system.id: repair_limit = 0.99 # if combat fleet, use military repair check if get_aistate().get_fleet_role(fleet_id) in COMBAT_MISSION_TYPES: return fleet_id in MilitaryAI.avail_mil_needing_repair( [fleet_id], on_mission=bool(self.orders), repair_limit=repair_limit)[0] # TODO: Allow to split fleet to send only damaged ships to repair ships_cur_health, ships_max_health = FleetUtilsAI.get_current_and_max_structure( fleet_id) return ships_cur_health < repair_limit * ships_max_health
def issue_order(self): if not super(OrderRepair, self).issue_order(): return False fleet_id = self.fleet.id system_id = self.target.get_system().id fleet = self.fleet.get_object() # type: fo.fleet if system_id == fleet.systemID: aistate = get_aistate() if aistate.get_fleet_role(fleet_id) == MissionType.EXPLORATION: if system_id in aistate.needsEmergencyExploration: aistate.needsEmergencyExploration.remove(system_id) elif system_id != fleet.nextSystemID: fo.issueAggressionOrder(fleet_id, False) start_id = FleetUtilsAI.get_fleet_system(fleet) dest_id = MoveUtilsAI.get_safe_path_leg_to_dest( fleet_id, start_id, system_id) universe = fo.getUniverse() debug( "fleet %d with order type(%s) sent to safe leg dest %s and ultimate dest %s" % (fleet_id, self.ORDER_NAME, universe.getSystem(dest_id), universe.getSystem(system_id))) fo.issueFleetMoveOrder(fleet_id, dest_id) debug("Order issued: %s fleet: %s target: %s" % (self.ORDER_NAME, self.fleet, self.target)) ships_cur_health, ships_max_health = FleetUtilsAI.get_current_and_max_structure( fleet_id) self.executed = (ships_cur_health == ships_max_health) return True
def _need_repair(self, repair_limit=0.70): """Check if fleet needs to be repaired. If the fleet is already at a system where it can be repaired, stay there until fully repaired. Otherwise, repair if fleet health is below specified *repair_limit*. For military fleets, there is a special evaluation called, cf. *MilitaryAI.avail_mil_needing_repair()* :param repair_limit: percentage of health below which the fleet is sent to repair :type repair_limit: float :return: True if fleet needs repair :rtype: bool """ # TODO: More complex evaluation if fleet needs repair (consider self-repair, distance, threat, mission...) fleet_id = self.fleet.id # if we are already at a system where we can repair, make sure we use it... system = self.fleet.get_system() # TODO starlane obstruction is not considered in the next call nearest_dock = MoveUtilsAI.get_best_drydock_system_id(system.id, fleet_id) if nearest_dock == system.id: repair_limit = 0.99 # if combat fleet, use military repair check if get_aistate().get_fleet_role(fleet_id) in COMBAT_MISSION_TYPES: return fleet_id in MilitaryAI.avail_mil_needing_repair([fleet_id], on_mission=bool(self.orders), repair_limit=repair_limit)[0] # TODO: Allow to split fleet to send only damaged ships to repair ships_cur_health, ships_max_health = FleetUtilsAI.get_current_and_max_structure(fleet_id) return ships_cur_health < repair_limit * ships_max_health
def issue_order(self): if not super(OrderRepair, self).issue_order(): return False fleet_id = self.fleet.id system_id = self.target.get_system().id fleet = self.fleet.get_object() # type: fo.fleet if system_id == fleet.systemID: if foAI.foAIstate.get_fleet_role(fleet_id) == MissionType.EXPLORATION: if system_id in foAI.foAIstate.needsEmergencyExploration: foAI.foAIstate.needsEmergencyExploration.remove(system_id) elif system_id != fleet.nextSystemID: fo.issueAggressionOrder(fleet_id, False) start_id = FleetUtilsAI.get_fleet_system(fleet) dest_id = MoveUtilsAI.get_safe_path_leg_to_dest(fleet_id, start_id, system_id) universe = fo.getUniverse() print "fleet %d with order type(%s) sent to safe leg dest %s and ultimate dest %s" % ( fleet_id, self.ORDER_NAME, universe.getSystem(dest_id), universe.getSystem(system_id)) fo.issueFleetMoveOrder(fleet_id, dest_id) print "Order issued: %s fleet: %s target: %s" % (self.ORDER_NAME, self.fleet, self.target) ships_cur_health, ships_max_health = FleetUtilsAI.get_current_and_max_structure(fleet_id) self.executed = (ships_cur_health == ships_max_health) return True