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 issue_order(self): if not super(OrderResupply, self).issue_order(): return fleet_id = self.fleet.id system_id = self.target.get_system().id fleet = self.fleet.get_object() if system_id not in [fleet.systemID, fleet.nextSystemID]: # if self.order_type == AIFleetOrderType.ORDER_MOVE: # dest_id = system_id # else: # if self.order_type == AIFleetOrderType.ORDER_REPAIR: # 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) print "fleet %d with order type(%s) sent to safe leg dest %s and ultimate dest %s" % ( fleet_id, self.ORDER_NAME, PlanetUtilsAI.sys_name_ids([dest_id]), PlanetUtilsAI.sys_name_ids([system_id])) fo.issueFleetMoveOrder(fleet_id, dest_id) print "Order issued: %s fleet: %s target: %s" % (self.ORDER_NAME, self.fleet, self.target) 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) self.order_issued = True
def issue_order(self): if not super(OrderResupply, self).issue_order(): return False fleet_id = self.fleet.id system_id = self.target.get_system().id fleet = self.fleet.get_object() aistate = get_aistate() if system_id == fleet.systemID: if aistate.get_fleet_role(fleet_id) == MissionType.EXPLORATION: if system_id in aistate.needsEmergencyExploration: aistate.needsEmergencyExploration.remove(system_id) return True if system_id != fleet.nextSystemID: self.executed = 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)) return True
def issue_order(self): if not super(OrderRepair, self).issue_order(): return fleet_id = self.fleet.id system_id = self.target.get_system().id fleet = self.fleet.get_object() if system_id not in [fleet.systemID, 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) 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) self.order_issued = True
def issue_order(self): if not super(OrderResupply, self).issue_order(): return False fleet_id = self.fleet.id system_id = self.target.get_system().id fleet = self.fleet.get_object() 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) return True if system_id != fleet.nextSystemID: self.executed = 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) return True
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
def assign_military_fleets_to_systems(use_fleet_id_list=None, allocations=None, round=1): # assign military fleets to military theater systems global _military_allocations universe = fo.getUniverse() if allocations is None: allocations = [] doing_main = (use_fleet_id_list is None) aistate = get_aistate() if doing_main: aistate.misc['ReassignedFleetMissions'] = [] base_defense_ids = FleetUtilsAI.get_empire_fleet_ids_by_role(MissionType.ORBITAL_DEFENSE) unassigned_base_defense_ids = FleetUtilsAI.extract_fleet_ids_without_mission_types(base_defense_ids) for fleet_id in unassigned_base_defense_ids: fleet = universe.getFleet(fleet_id) if not fleet: continue sys_id = fleet.systemID target = TargetSystem(sys_id) fleet_mission = aistate.get_fleet_mission(fleet_id) fleet_mission.clear_fleet_orders() fleet_mission.clear_target() mission_type = MissionType.ORBITAL_DEFENSE fleet_mission.set_target(mission_type, target) all_military_fleet_ids = FleetUtilsAI.get_empire_fleet_ids_by_role(MissionType.MILITARY) if not all_military_fleet_ids: _military_allocations = [] return avail_mil_fleet_ids = list(FleetUtilsAI.extract_fleet_ids_without_mission_types(all_military_fleet_ids)) mil_needing_repair_ids, avail_mil_fleet_ids = avail_mil_needing_repair(avail_mil_fleet_ids) these_allocations = _military_allocations debug("==================================================") debug("Assigning military fleets") debug("---------------------------------") else: avail_mil_fleet_ids = list(use_fleet_id_list) mil_needing_repair_ids, avail_mil_fleet_ids = avail_mil_needing_repair(avail_mil_fleet_ids) these_allocations = allocations # send_for_repair(mil_needing_repair_ids) #currently, let get taken care of by AIFleetMission.generate_fleet_orders() # get systems to defend avail_mil_fleet_ids = set(avail_mil_fleet_ids) for sys_id, alloc, minalloc, rvp, takeAny in these_allocations: if not doing_main and not avail_mil_fleet_ids: break debug("Allocating for: %s", TargetSystem(sys_id)) found_fleets = [] found_stats = {} ensure_return = sys_id not in set(AIstate.colonyTargetedSystemIDs + AIstate.outpostTargetedSystemIDs + AIstate.invasionTargetedSystemIDs) these_fleets = FleetUtilsAI.get_fleets_for_mission( target_stats={'rating': alloc, 'ratingVsPlanets': rvp, 'target_system': TargetSystem(sys_id)}, min_stats={'rating': minalloc, 'ratingVsPlanets': rvp, 'target_system': TargetSystem(sys_id)}, cur_stats=found_stats, starting_system=sys_id, fleet_pool_set=avail_mil_fleet_ids, fleet_list=found_fleets, ensure_return=ensure_return) if not these_fleets: debug("Could not allocate any fleets.") if not found_fleets or not (FleetUtilsAI.stats_meet_reqs(found_stats, {'rating': minalloc}) or takeAny): if doing_main: if _verbose_mil_reporting: debug("NO available/suitable military allocation for system %d ( %s ) " "-- requested allocation %8d, found available rating %8d in fleets %s" % (sys_id, universe.getSystem(sys_id).name, minalloc, found_stats.get('rating', 0), found_fleets)) avail_mil_fleet_ids.update(found_fleets) continue else: these_fleets = found_fleets else: debug("Assigning fleets %s to target %s", these_fleets, TargetSystem(sys_id)) if doing_main and _verbose_mil_reporting: debug("FULL+ military allocation for system %d ( %s )" " -- requested allocation %8d, got %8d with fleets %s" % (sys_id, universe.getSystem(sys_id).name, alloc, found_stats.get('rating', 0), these_fleets)) target = TargetSystem(sys_id) for fleet_id in these_fleets: fo.issueAggressionOrder(fleet_id, True) fleet_mission = aistate.get_fleet_mission(fleet_id) fleet_mission.clear_fleet_orders() fleet_mission.clear_target() if sys_id in set(AIstate.colonyTargetedSystemIDs + AIstate.outpostTargetedSystemIDs + AIstate.invasionTargetedSystemIDs): mission_type = MissionType.SECURE elif state.get_empire_planets_by_system(sys_id): mission_type = MissionType.PROTECT_REGION else: mission_type = MissionType.MILITARY fleet_mission.set_target(mission_type, target) fleet_mission.generate_fleet_orders() if not doing_main: aistate.misc.setdefault('ReassignedFleetMissions', []).append(fleet_mission) if doing_main: debug("---------------------------------") last_round = 3 last_round_name = "LastRound" if round <= last_round: # check if any fleets remain unassigned all_military_fleet_ids = FleetUtilsAI.get_empire_fleet_ids_by_role(MissionType.MILITARY) avail_mil_fleet_ids = list(FleetUtilsAI.extract_fleet_ids_without_mission_types(all_military_fleet_ids)) allocations = [] round += 1 thisround = "Extras Remaining Round %d" % round if round < last_round else last_round_name if avail_mil_fleet_ids: debug("Round %s - still have available military fleets: %s", thisround, avail_mil_fleet_ids) allocations = get_military_fleets(mil_fleets_ids=avail_mil_fleet_ids, try_reset=False, thisround=thisround) if allocations: assign_military_fleets_to_systems(use_fleet_id_list=avail_mil_fleet_ids, allocations=allocations, round=round) else: # assign remaining fleets to nearest systems to protect. all_military_fleet_ids = FleetUtilsAI.get_empire_fleet_ids_by_role(MissionType.MILITARY) avail_mil_fleet_ids = list(FleetUtilsAI.extract_fleet_ids_without_mission_types(all_military_fleet_ids)) def system_score(_fid, _sys_id): """Helper function to rank systems by priority""" jump_distance = universe.jumpDistance(_fid, _sys_id) if get_system_local_threat(_sys_id): weight = 10 elif get_system_neighbor_threat(_sys_id): weight = 3 elif get_system_jump2_threat(_sys_id): weight = 1 else: weight = 1 / max(.5, float(state.get_distance_to_enemy_supply(_sys_id)))**1.25 return float(weight) / (jump_distance+1) for fid in avail_mil_fleet_ids: fleet = universe.getFleet(fid) FleetUtilsAI.get_fleet_system(fleet) systems = state.get_empire_planets_by_system().keys() if not systems: continue sys_id = max(systems, key=lambda x: system_score(fid, x)) debug("Assigning leftover %s to system %d " "- nothing better to do.", fleet, sys_id) fleet_mission = aistate.get_fleet_mission(fid) fleet_mission.clear_fleet_orders() target_system = TargetSystem(sys_id) fleet_mission.set_target(MissionType.PROTECT_REGION, target_system) fleet_mission.generate_fleet_orders()