def issue_order(self): if not super(OrderSplitFleet, self).issue_order(): return ship_id = self.target.id fleet = self.fleet.get_object() if ship_id in fleet.shipIDs: fo.issueNewFleetOrder(str(ship_id), ship_id) print "Order issued: %s fleet: %s target: %s" % (self.ORDER_NAME, self.fleet, self.target) self.order_issued = True
def issueOrder(self): if not self.canIssueOrder(): print "can't issue " + self else: self.__setExecuted() # outpost if AIFleetOrderType.ORDER_OUTPOST == self.getAIFleetOrderType(): shipID = None if AITargetType.TARGET_SHIP == self.getSourceAITarget().getAITargetType(): shipID = self.getSourceAITarget().getTargetID() elif AITargetType.TARGET_FLEET == self.getSourceAITarget().getAITargetType(): fleetID = self.getSourceAITarget().getTargetID() shipID = FleetUtilsAI.getShipIDWithRole(fleetID, AIShipRoleType.SHIP_ROLE_CIVILIAN_OUTPOST) fo.issueColonizeOrder(shipID, self.getTargetAITarget().getTargetID()) # colonise elif AIFleetOrderType.ORDER_COLONISE == self.getAIFleetOrderType(): shipID = None if AITargetType.TARGET_SHIP == self.getSourceAITarget().getAITargetType(): shipID = self.getSourceAITarget().getTargetID() elif AITargetType.TARGET_FLEET == self.getSourceAITarget().getAITargetType(): fleetID = self.getSourceAITarget().getTargetID() shipID = FleetUtilsAI.getShipIDWithRole(fleetID, AIShipRoleType.SHIP_ROLE_CIVILIAN_COLONISATION) fo.issueColonizeOrder(shipID, self.getTargetAITarget().getTargetID()) # invade elif AIFleetOrderType.ORDER_INVADE == self.getAIFleetOrderType(): shipID = None if AITargetType.TARGET_SHIP == self.getSourceAITarget().getAITargetType(): shipID = self.getSourceAITarget().getTargetID() elif AITargetType.TARGET_FLEET == self.getSourceAITarget().getAITargetType(): fleetID = self.getSourceAITarget().getTargetID() shipID = FleetUtilsAI.getShipIDWithRole(fleetID, AIShipRoleType.SHIP_ROLE_MILITARY_INVASION) fo.issueInvadeOrder(shipID, self.getTargetAITarget().getTargetID()) # move or resupply elif (AIFleetOrderType.ORDER_MOVE == self.getAIFleetOrderType()) or (AIFleetOrderType.ORDER_RESUPPLY == self.getAIFleetOrderType()): fleetID = self.getSourceAITarget().getTargetID() systemID = self.getTargetAITarget().getTargetID() fo.issueFleetMoveOrder(fleetID, systemID) # split fleet elif AIFleetOrderType.ORDER_SPLIT_FLEET == self.getAIFleetOrderType(): fleetID = self.getSourceAITarget().getTargetID() shipID = self.getTargetAITarget().getTargetID() fo.issueNewFleetOrder(str(shipID), shipID) self.__setExecutionCompleted() elif (AIFleetOrderType.ORDER_ATACK == self.getAIFleetOrderType()): fleetID = self.getSourceAITarget().getTargetID() systemID = self.getTargetAITarget().getRequiredSystemAITargets()[0].getTargetID() fo.issueFleetMoveOrder(fleetID, systemID)
def splitFleet(fleetID): "splits a fleet into its ships" universe = fo.getUniverse() empireID = fo.empireID() fleet = universe.getFleet(fleetID) if fleet == None: return if not fleet.ownedBy(empireID): return for shipID in fleet.shipIDs: if len(fleet.shipIDs) <= 1: break # fleet with only one ship cannot be split fo.issueNewFleetOrder(str(shipID), shipID)
def splitFleet(fleetID): "splits a fleet into its ships" universe = fo.getUniverse() empireID = fo.empireID() fleet = universe.getFleet(fleetID) newfleets = [] if fleet == None: return [] if not fleet.ownedBy(empireID): return [] if len(list(fleet.shipIDs)) <= 1: # fleet with only one ship cannot be split return [fleetID] shipIDs = list( fleet.shipIDs ) for shipID in shipIDs[1:]: newFleetID = fo.issueNewFleetOrder("Fleet %d"%(shipID), shipID) if newFleetID: newFleet=universe.getFleet(newFleetID) if not newFleet: print "Error: newly split fleet %d not available from universe"%newFleetID fo.issueRenameOrder(newFleetID, "Fleet %5d"%newFleetID) #to ease review of debugging logs fo.issueAggressionOrder(newFleetID, True) role = foAI.foAIstate.getFleetRole(newFleetID) #and mission? foAI.foAIstate.getRating(newFleetID) # newfleets.append(newFleetID) foAI.foAIstate.newlySplitFleets[newFleetID]=True else: print "Error - got no fleet ID back after trying to split a ship from fleet %d"%fleetID foAI.foAIstate.getFleetRole(fleetID, forceNew=True) # foAI.foAIstate.updateFleetRating(fleetID) # foAI.foAIstate.ensureHaveFleetMissions(newfleets) return newfleets
def split_fleet(fleet_id): """Split a fleet into its ships. :param fleet_id: fleet to be split. :type fleet_id: int :return: New fleets. Empty if couldn't split. :rtype: list[int] """ universe = fo.getUniverse() empire_id = fo.empireID() fleet = universe.getFleet(fleet_id) newfleets = [] if fleet is None: return [] if not fleet.ownedBy(empire_id): return [] if len(list( fleet.shipIDs)) <= 1: # fleet with only one ship cannot be split return [] ship_ids = list(fleet.shipIDs) aistate = get_aistate() for ship_id in ship_ids[1:]: new_fleet_id = fo.issueNewFleetOrder("Fleet %4d" % ship_id, ship_id) if new_fleet_id: new_fleet = universe.getFleet(new_fleet_id) if not new_fleet: warn("Newly split fleet %d not available from universe" % new_fleet_id) fo.issueRenameOrder( new_fleet_id, "Fleet %4d" % new_fleet_id) # to ease review of debugging logs fo.issueAggressionOrder(new_fleet_id, True) aistate.update_fleet_rating(new_fleet_id) newfleets.append(new_fleet_id) aistate.newlySplitFleets[new_fleet_id] = True else: if fleet.systemID == INVALID_ID: warn( "Tried to split ship id (%d) from fleet %d when fleet is in starlane" % (ship_id, fleet_id)) else: warn( "Got no fleet ID back after trying to split ship id (%d) from fleet %d" % (ship_id, fleet_id)) aistate.get_fleet_role(fleet_id, force_new=True) aistate.update_fleet_rating(fleet_id) if newfleets: aistate.ensure_have_fleet_missions(newfleets) return newfleets
def split_fleet(fleet_id): """Split a fleet into its ships. :param fleet_id: fleet to be split. :type fleet_id: int :return: New fleets. Empty if couldn't split. :rtype: list[int] """ universe = fo.getUniverse() empire_id = fo.empireID() fleet = universe.getFleet(fleet_id) newfleets = [] if fleet is None: return [] if not fleet.ownedBy(empire_id): return [] if len(list(fleet.shipIDs)) <= 1: # fleet with only one ship cannot be split return [] ship_ids = list(fleet.shipIDs) aistate = get_aistate() for ship_id in ship_ids[1:]: new_fleet_id = fo.issueNewFleetOrder("Fleet %4d" % ship_id, ship_id) if new_fleet_id: new_fleet = universe.getFleet(new_fleet_id) if not new_fleet: warn("Newly split fleet %d not available from universe" % new_fleet_id) fo.issueRenameOrder(new_fleet_id, "Fleet %4d" % new_fleet_id) # to ease review of debugging logs fo.issueAggressionOrder(new_fleet_id, True) aistate.update_fleet_rating(new_fleet_id) newfleets.append(new_fleet_id) aistate.newlySplitFleets[new_fleet_id] = True else: if fleet.systemID == INVALID_ID: warn("Tried to split ship id (%d) from fleet %d when fleet is in starlane" % ( ship_id, fleet_id)) else: warn("Got no fleet ID back after trying to split ship id (%d) from fleet %d" % ( ship_id, fleet_id)) aistate.get_fleet_role(fleet_id, force_new=True) aistate.update_fleet_rating(fleet_id) if newfleets: aistate.ensure_have_fleet_missions(newfleets) return newfleets
def split_ship_from_fleet(fleet_id, ship_id) -> int: """Try to split a ship from the fleet, creating a new fleet. :return: ID of the newly created fleet or INVALID_ID if failed """ universe = fo.getUniverse() fleet = universe.getFleet(fleet_id) if assertion_fails(fleet is not None): return INVALID_ID if assertion_fails(ship_id in fleet.shipIDs): return INVALID_ID if assertion_fails(fleet.numShips > 1, "Can't split last ship from fleet"): return INVALID_ID new_fleet_id = fo.issueNewFleetOrder("Fleet %4d" % ship_id, ship_id) if new_fleet_id != INVALID_ID: aistate = get_aistate() new_fleet = universe.getFleet(new_fleet_id) if not new_fleet: warning("Newly split fleet %d not available from universe" % new_fleet_id) debug("Successfully split ship %d from fleet %d into new fleet %d", ship_id, fleet_id, new_fleet_id) fo.issueRenameOrder(new_fleet_id, "Fleet %4d" % new_fleet_id) # to ease review of debugging logs fo.issueAggressionOrder(new_fleet_id, True) aistate.update_fleet_rating(new_fleet_id) aistate.newlySplitFleets[new_fleet_id] = True # register the new fleets so AI logic is aware of them sys_status = aistate.systemStatus.setdefault(fleet.systemID, {}) sys_status["myfleets"].append(new_fleet_id) sys_status["myFleetsAccessible"].append(new_fleet_id) else: if fleet.systemID == INVALID_ID: warning( "Tried to split ship id (%d) from fleet %d when fleet is in starlane" % (ship_id, fleet_id)) else: warning( "Got no fleet ID back after trying to split ship id (%d) from fleet %d" % (ship_id, fleet_id)) return new_fleet_id
def split_fleet(fleet_id): """Splits a fleet into its ships.""" universe = fo.getUniverse() empire_id = fo.empireID() fleet = universe.getFleet(fleet_id) newfleets = [] if fleet is None: return [] if not fleet.ownedBy(empire_id): return [] if len(list( fleet.shipIDs)) <= 1: # fleet with only one ship cannot be split return [] ship_ids = list(fleet.shipIDs) for ship_id in ship_ids[1:]: new_fleet_id = fo.issueNewFleetOrder("Fleet %4d" % ship_id, ship_id) if new_fleet_id: new_fleet = universe.getFleet(new_fleet_id) if not new_fleet: print "Error: newly split fleet %d not available from universe" % new_fleet_id fo.issueRenameOrder( new_fleet_id, "Fleet %4d" % new_fleet_id) # to ease review of debugging logs fo.issueAggressionOrder(new_fleet_id, True) foAI.foAIstate.get_rating(new_fleet_id) newfleets.append(new_fleet_id) foAI.foAIstate.newlySplitFleets[new_fleet_id] = True else: if fleet.systemID == -1: print "Error - tried to split ship id (%d) from fleet %d when fleet is in starlane" % ( ship_id, fleet_id) else: print "Error - got no fleet ID back after trying to split ship id (%d) from fleet %d" % ( ship_id, fleet_id) foAI.foAIstate.get_fleet_role(fleet_id, force_new=True) foAI.foAIstate.update_fleet_rating(fleet_id) if newfleets: foAI.foAIstate.ensure_have_fleet_missions(newfleets) return newfleets
def split_fleet(fleetID): """splits a fleet into its ships""" universe = fo.getUniverse() empireID = fo.empireID() fleet = universe.getFleet(fleetID) newfleets = [] if fleet is None: return [] if not fleet.ownedBy(empireID): return [] if len(list(fleet.shipIDs)) <= 1: # fleet with only one ship cannot be split return [] shipIDs = list( fleet.shipIDs ) for shipID in shipIDs[1:]: newFleetID = fo.issueNewFleetOrder("Fleet %d"% shipID, shipID) if newFleetID: newFleet=universe.getFleet(newFleetID) if not newFleet: print "Error: newly split fleet %d not available from universe"%newFleetID fo.issueRenameOrder(newFleetID, "Fleet %5d"%newFleetID) #to ease review of debugging logs fo.issueAggressionOrder(newFleetID, True) role = foAI.foAIstate.get_fleet_role(newFleetID) #and mission? foAI.foAIstate.get_rating(newFleetID) # newfleets.append(newFleetID) foAI.foAIstate.newlySplitFleets[newFleetID]=True else: if fleet.systemID==-1: print "Error - tried to split ship id (%d) from fleet %d when fleet is in starlane"%(shipID, fleetID) else: print "Error - got no fleet ID back after trying to split ship id (%d) from fleet %d"%(shipID, fleetID) foAI.foAIstate.get_fleet_role(fleetID, forceNew=True) # foAI.foAIstate.update_fleet_rating(fleetID) # if newfleets: foAI.foAIstate.ensure_have_fleet_missions(newfleets) return newfleets
def split_ship_from_fleet(fleet_id, ship_id): universe = fo.getUniverse() fleet = universe.getFleet(fleet_id) if assertion_fails(fleet is not None): return if assertion_fails(ship_id in fleet.shipIDs): return if assertion_fails(fleet.numShips > 1, "Can't split last ship from fleet"): return new_fleet_id = fo.issueNewFleetOrder("Fleet %4d" % ship_id, ship_id) if new_fleet_id: aistate = get_aistate() new_fleet = universe.getFleet(new_fleet_id) if not new_fleet: warn("Newly split fleet %d not available from universe" % new_fleet_id) debug("Successfully split ship %d from fleet %d into new fleet %d", ship_id, fleet_id, new_fleet_id) fo.issueRenameOrder(new_fleet_id, "Fleet %4d" % new_fleet_id) # to ease review of debugging logs fo.issueAggressionOrder(new_fleet_id, True) aistate.update_fleet_rating(new_fleet_id) aistate.newlySplitFleets[new_fleet_id] = True else: if fleet.systemID == INVALID_ID: warn( "Tried to split ship id (%d) from fleet %d when fleet is in starlane" % (ship_id, fleet_id)) else: warn( "Got no fleet ID back after trying to split ship id (%d) from fleet %d" % (ship_id, fleet_id)) return new_fleet_id
def issueOrder(self, considerMergers=False): global dumpTurn if not self.canIssueOrder(considerMergers=False): #appears to be redundant with check in IAFleetMission? print "\tcan't issue %s"%self else: universe=fo.getUniverse() self.__setExecuted() # outpost if AIFleetOrderType.ORDER_OUTPOST == self.getAIFleetOrderType(): planet=universe.getPlanet(self.getTargetAITarget().target_id) if not planet.unowned: self.__setExecutionCompleted() return shipID = None if AITargetType.TARGET_SHIP == self.getSourceAITarget().target_type: shipID = self.getSourceAITarget().target_id elif AITargetType.TARGET_FLEET == self.getSourceAITarget().target_type: fleetID = self.getSourceAITarget().target_id shipID = FleetUtilsAI.getShipIDWithRole(fleetID, AIShipRoleType.SHIP_ROLE_CIVILIAN_OUTPOST) if shipID is None: shipID = FleetUtilsAI.getShipIDWithRole(fleetID, AIShipRoleType.SHIP_ROLE_BASE_OUTPOST) result=fo.issueColonizeOrder(shipID, self.getTargetAITarget().target_id) if result==0: self.__executed = False # colonise elif AIFleetOrderType.ORDER_COLONISE == self.getAIFleetOrderType(): shipID = None if AITargetType.TARGET_SHIP == self.getSourceAITarget().target_type: shipID = self.getSourceAITarget().target_id elif AITargetType.TARGET_FLEET == self.getSourceAITarget().target_type: fleetID = self.getSourceAITarget().target_id shipID = FleetUtilsAI.getShipIDWithRole(fleetID, AIShipRoleType.SHIP_ROLE_CIVILIAN_COLONISATION) if shipID is None: shipID = FleetUtilsAI.getShipIDWithRole(fleetID, AIShipRoleType.SHIP_ROLE_BASE_COLONISATION) planetID = self.getTargetAITarget().target_id planet=universe.getPlanet(planetID) planetName = (planet and planet.name) or "apparently invisible" result = fo.issueColonizeOrder(shipID, planetID) print "Ordered colony ship ID %d to colonize %s, got result %d"%(shipID, planetName, result) if result==0: self.__executed = False # invade elif AIFleetOrderType.ORDER_INVADE == self.getAIFleetOrderType(): result = False shipID = None planetID = self.getTargetAITarget().target_id planet=universe.getPlanet(planetID) planetName = (planet and planet.name) or "invisible" if AITargetType.TARGET_SHIP == self.getSourceAITarget().target_type: shipID = self.getSourceAITarget().target_id elif AITargetType.TARGET_FLEET == self.getSourceAITarget().target_type: fleetID = self.getSourceAITarget().target_id fleet = fo.getUniverse().getFleet(fleetID) for shipID in fleet.shipIDs: ship = universe.getShip(shipID) if (foAI.foAIstate.getShipRole(ship.design.id) in [AIShipRoleType.SHIP_ROLE_MILITARY_INVASION, AIShipRoleType.SHIP_ROLE_BASE_INVASION]): result = fo.issueInvadeOrder(shipID, planetID) or result #will track if at least one invasion troops successfully deployed detailStr = "" if result == 0: pstealth = planet.currentMeterValue(fo.meterType.stealth) pop = planet.currentMeterValue(fo.meterType.population) shields = planet.currentMeterValue(fo.meterType.shield) owner = planet.owner detailStr= " -- planet has %.1f stealth, shields %.1f, %.1f population and is owned by empire %d"%(pstealth, shields, pop, owner) print "Ordered troop ship ID %d to invade %s, got result %d"%(shipID, planetName, result), detailStr if result == 0: if 'needsEmergencyExploration' not in dir(foAI.foAIstate): foAI.foAIstate.needsEmergencyExploration=[] if fleet.systemID not in foAI.foAIstate.needsEmergencyExploration: foAI.foAIstate.needsEmergencyExploration.append(fleet.systemID) print "Due to trouble invading, adding system %d to Emergency Exploration List"%fleet.systemID self.__executed = False if shields >0 and owner==-1 and dumpTurn<fo.currentTurn(): dumpTurn=fo.currentTurn() print "Universe Dump to debug invasions:" universe.dump() break if result: print "Successfully ordered troop ship(s) to invade %s, with detail%s "%(planetName, detailStr) # military elif AIFleetOrderType.ORDER_MILITARY == self.getAIFleetOrderType(): shipID = None if AITargetType.TARGET_SHIP == self.getSourceAITarget().target_type: shipID = self.getSourceAITarget().target_id elif AITargetType.TARGET_FLEET == self.getSourceAITarget().target_type: fleetID = self.getSourceAITarget().target_id shipID = FleetUtilsAI.getShipIDWithRole(fleetID, AIShipRoleType.SHIP_ROLE_MILITARY) #fo.issueFleetMoveOrder(fleetID, self.getTargetAITarget().target_id) #moving is already taken care of separately targetSysID = self.getTargetAITarget().target_id fleet = fo.getUniverse().getFleet(fleetID) systemStatus = foAI.foAIstate.systemStatus.get(targetSysID, {}) if (fleet )and ( fleet.systemID==targetSysID ) and ((systemStatus.get('fleetThreat', 0) + systemStatus.get('planetThreat', 0)+ systemStatus.get('monsterThreat', 0))==0): self.__setExecutionCompleted() # move or resupply elif (AIFleetOrderType.ORDER_MOVE == self.getAIFleetOrderType()) or (AIFleetOrderType.ORDER_RESUPPLY == self.getAIFleetOrderType()): fleetID = self.getSourceAITarget().target_id systemID = self.getTargetAITarget().target_id fleet = fo.getUniverse().getFleet(fleetID) if systemID not in [fleet.systemID, fleet.nextSystemID] : fo.issueFleetMoveOrder(fleetID, systemID) if systemID == fleet.systemID: if foAI.foAIstate.getFleetRole(fleetID) == AIFleetMissionType.FLEET_MISSION_EXPLORATION : if 'needsEmergencyExploration' not in dir(foAI.foAIstate): foAI.foAIstate.needsEmergencyExploration=[] if systemID in foAI.foAIstate.needsEmergencyExploration: del foAI.foAIstate.needsEmergencyExploration[ foAI.foAIstate.needsEmergencyExploration.index(systemID) ] self.__setExecutionCompleted() # split fleet elif AIFleetOrderType.ORDER_SPLIT_FLEET == self.getAIFleetOrderType(): fleetID = self.getSourceAITarget().target_id shipID = self.getTargetAITarget().target_id fleet = fo.getUniverse().getFleet(fleetID) if shipID in fleet.shipIDs: fo.issueNewFleetOrder(str(shipID), shipID) self.__setExecutionCompleted() # attack elif (AIFleetOrderType.ORDER_ATTACK == self.getAIFleetOrderType()): fleetID = self.getSourceAITarget().target_id systemID = self.getTargetAITarget().get_required_system_ai_targets()[0].target_id fo.issueFleetMoveOrder(fleetID, systemID)
def issueOrder(self, considerMergers=False): if not self.canIssueOrder(considerMergers=False): #appears to be redundant with check in IAFleetMission? print "\tcan't issue %s"%self else: universe=fo.getUniverse() self.__setExecuted() # outpost if AIFleetOrderType.ORDER_OUTPOST == self.getAIFleetOrderType(): shipID = None if AITargetType.TARGET_SHIP == self.getSourceAITarget().getAITargetType(): shipID = self.getSourceAITarget().getTargetID() elif AITargetType.TARGET_FLEET == self.getSourceAITarget().getAITargetType(): fleetID = self.getSourceAITarget().getTargetID() shipID = FleetUtilsAI.getShipIDWithRole(fleetID, AIShipRoleType.SHIP_ROLE_CIVILIAN_OUTPOST) fo.issueColonizeOrder(shipID, self.getTargetAITarget().getTargetID()) # colonise elif AIFleetOrderType.ORDER_COLONISE == self.getAIFleetOrderType(): shipID = None if AITargetType.TARGET_SHIP == self.getSourceAITarget().getAITargetType(): shipID = self.getSourceAITarget().getTargetID() elif AITargetType.TARGET_FLEET == self.getSourceAITarget().getAITargetType(): fleetID = self.getSourceAITarget().getTargetID() shipID = FleetUtilsAI.getShipIDWithRole(fleetID, AIShipRoleType.SHIP_ROLE_CIVILIAN_COLONISATION) planetID = self.getTargetAITarget().getTargetID() planet=universe.getPlanet(planetID) planetName = (planet and planet.name) or "apparently nvisible" result = fo.issueColonizeOrder(shipID, planetID) print "Ordered colony ship ID %d to colonize %s, got result %d"%(shipID, planetName, result) # invade elif AIFleetOrderType.ORDER_INVADE == self.getAIFleetOrderType(): result = False shipID = None planetID = self.getTargetAITarget().getTargetID() planet=universe.getPlanet(planetID) planetName = (planet and planet.name) or "invisible" if AITargetType.TARGET_SHIP == self.getSourceAITarget().getAITargetType(): shipID = self.getSourceAITarget().getTargetID() elif AITargetType.TARGET_FLEET == self.getSourceAITarget().getAITargetType(): fleetID = self.getSourceAITarget().getTargetID() fleet = fo.getUniverse().getFleet(fleetID) for shipID in fleet.shipIDs: ship = universe.getShip(shipID) if (foAI.foAIstate.getShipRole(ship.design.id) == AIShipRoleType.SHIP_ROLE_MILITARY_INVASION): result = fo.issueInvadeOrder(shipID, planetID) or result #will track if at least one invasion troops successfully deployed print "Ordered troop ship ID %d to invade %s, got result %d"%(shipID, planetName, result) if result == 0: if 'needsEmergencyExploration' not in dir(foAI.foAIstate): foAI.foAIstate.needsEmergencyExploration=[] foAI.foAIstate.needsEmergencyExploration.append(fleet.systemID) print "Due to trouble invading, adding system %d to Emergency Exploration List"%fleet.systemID # military elif AIFleetOrderType.ORDER_MILITARY == self.getAIFleetOrderType(): shipID = None if AITargetType.TARGET_SHIP == self.getSourceAITarget().getAITargetType(): shipID = self.getSourceAITarget().getTargetID() elif AITargetType.TARGET_FLEET == self.getSourceAITarget().getAITargetType(): fleetID = self.getSourceAITarget().getTargetID() shipID = FleetUtilsAI.getShipIDWithRole(fleetID, AIShipRoleType.SHIP_ROLE_MILITARY) #fo.issueFleetMoveOrder(fleetID, self.getTargetAITarget().getTargetID()) #moving is already taken care of separately targetSysID = self.getTargetAITarget().getTargetID() fleet = fo.getUniverse().getFleet(fleetID) systemStatus = foAI.foAIstate.systemStatus.get(targetSysID, {}) if (fleet )and ( fleet.systemID==targetSysID ) and ((systemStatus.get('fleetThreat', 0) + systemStatus.get('planetThreat', 0))==0): self.__setExecutionCompleted() # move or resupply elif (AIFleetOrderType.ORDER_MOVE == self.getAIFleetOrderType()) or (AIFleetOrderType.ORDER_RESUPPLY == self.getAIFleetOrderType()): fleetID = self.getSourceAITarget().getTargetID() systemID = self.getTargetAITarget().getTargetID() fleet = fo.getUniverse().getFleet(fleetID) if systemID not in [fleet.systemID, fleet.nextSystemID] : fo.issueFleetMoveOrder(fleetID, systemID) if systemID == fleet.systemID: if fleetID in ExplorationAI.currentScoutFleetIDs: if 'needsEmergencyExploration' not in dir(foAI.foAIstate): foAI.foAIstate.needsEmergencyExploration=[] if systemID in foAI.foAIstate.needsEmergencyExploration: del foAI.foAIstate.needsEmergencyExploration[ foAI.foAIstate.needsEmergencyExploration.index(systemID) ] self.__setExecutionCompleted() # split fleet elif AIFleetOrderType.ORDER_SPLIT_FLEET == self.getAIFleetOrderType(): fleetID = self.getSourceAITarget().getTargetID() shipID = self.getTargetAITarget().getTargetID() fleet = fo.getUniverse().getFleet(fleetID) if shipID in fleet.shipIDs: fo.issueNewFleetOrder(str(shipID), shipID) self.__setExecutionCompleted() # attack elif (AIFleetOrderType.ORDER_ATTACK == self.getAIFleetOrderType()): fleetID = self.getSourceAITarget().getTargetID() systemID = self.getTargetAITarget().getRequiredSystemAITargets()[0].getTargetID() fo.issueFleetMoveOrder(fleetID, systemID)
def issue_order(self): global dumpTurn if not self.can_issue_order(): # appears to be redundant with check in IAFleetMission? print "\tcan't issue %s" % self else: universe = fo.getUniverse() self.executed = True # outpost if AIFleetOrderType.ORDER_OUTPOST == self.order_type: planet = universe.getPlanet(self.target.target_id) if not planet.unowned: self.execution_completed = True return fleet_id = self.fleet.target_id ship_id = FleetUtilsAI.get_ship_id_with_role(fleet_id, AIShipRoleType.SHIP_ROLE_CIVILIAN_OUTPOST) if ship_id is None: ship_id = FleetUtilsAI.get_ship_id_with_role(fleet_id, AIShipRoleType.SHIP_ROLE_BASE_OUTPOST) result = fo.issueColonizeOrder(ship_id, self.target.target_id) if not result: self.executed = False # colonise elif AIFleetOrderType.ORDER_COLONISE == self.order_type: fleet_id = self.fleet.target_id ship_id = FleetUtilsAI.get_ship_id_with_role(fleet_id, AIShipRoleType.SHIP_ROLE_CIVILIAN_COLONISATION) if ship_id is None: ship_id = FleetUtilsAI.get_ship_id_with_role(fleet_id, AIShipRoleType.SHIP_ROLE_BASE_COLONISATION) planet_id = self.target.target_id planet = universe.getPlanet(planet_id) planet_name = planet and planet.name or "apparently invisible" result = fo.issueColonizeOrder(ship_id, planet_id) print "Ordered colony ship ID %d to colonize %s, got result %d" % (ship_id, planet_name, result) if not result: self.executed = False # invade elif AIFleetOrderType.ORDER_INVADE == self.order_type: result = False planet_id = self.target.target_id planet = universe.getPlanet(planet_id) planet_name = planet and planet.name or "invisible" fleet_id = self.fleet.target_id fleet = fo.getUniverse().getFleet(fleet_id) detail_str = "" for ship_id in fleet.shipIDs: ship = universe.getShip(ship_id) if foAI.foAIstate.get_ship_role(ship.design.id) in [AIShipRoleType.SHIP_ROLE_MILITARY_INVASION, AIShipRoleType.SHIP_ROLE_BASE_INVASION]: result = fo.issueInvadeOrder(ship_id, planet_id) or result # will track if at least one invasion troops successfully deployed shields = planet.currentMeterValue(fo.meterType.shield) owner = planet.owner if not result: pstealth = planet.currentMeterValue(fo.meterType.stealth) pop = planet.currentMeterValue(fo.meterType.population) detail_str = " -- planet has %.1f stealth, shields %.1f, %.1f population and is owned by empire %d" % (pstealth, shields, pop, owner) print "Ordered troop ship ID %d to invade %s, got result %d" % (ship_id, planet_name, result), detail_str if not result: if 'needsEmergencyExploration' not in dir(foAI.foAIstate): foAI.foAIstate.needsEmergencyExploration = [] if fleet.systemID not in foAI.foAIstate.needsEmergencyExploration: foAI.foAIstate.needsEmergencyExploration.append(fleet.systemID) print "Due to trouble invading, adding system %d to Emergency Exploration List" % fleet.systemID self.executed = False if shields > 0 and owner == -1 and dumpTurn < fo.currentTurn(): dumpTurn = fo.currentTurn() print "Universe Dump to debug invasions:" universe.dump() break if result: print "Successfully ordered troop ship(s) to invade %s, with detail %s" % (planet_name, detail_str) # military elif AIFleetOrderType.ORDER_MILITARY == self.order_type: fleet_id = self.fleet.target_id #fo.issueFleetMoveOrder(fleet_id, self.target.target_id) #moving is already taken care of separately target_sys_id = self.target.target_id fleet = fo.getUniverse().getFleet(fleet_id) system_status = foAI.foAIstate.systemStatus.get(target_sys_id, {}) if fleet and fleet.systemID == target_sys_id and not (system_status.get('fleetThreat', 0) + system_status.get('planetThreat', 0) + system_status.get('monsterThreat', 0)): self.execution_completed = True # move or resupply elif self.order_type in [AIFleetOrderType.ORDER_MOVE, AIFleetOrderType.ORDER_REPAIR, AIFleetOrderType.ORDER_RESUPPLY]: fleet_id = self.fleet.target_id system_id = self.target.target_id fleet = fo.getUniverse().getFleet(fleet_id) 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 = [fleet.systemID, fleet.nextSystemID][fleet.systemID == -1] 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, AIFleetOrderTypeNames.name(self.order_type), PlanetUtilsAI.sys_name_ids([dest_id]), PlanetUtilsAI.sys_name_ids([system_id])) fo.issueFleetMoveOrder(fleet_id, dest_id) if system_id == fleet.systemID: if foAI.foAIstate.get_fleet_role(fleet_id) == AIFleetMissionType.FLEET_MISSION_EXPLORATION: if system_id in foAI.foAIstate.needsEmergencyExploration: del foAI.foAIstate.needsEmergencyExploration[foAI.foAIstate.needsEmergencyExploration.index(system_id)] self.execution_completed = True # split fleet elif AIFleetOrderType.ORDER_SPLIT_FLEET == self.order_type: fleet_id = self.fleet.target_id ship_id = self.target.target_id fleet = fo.getUniverse().getFleet(fleet_id) if ship_id in fleet.shipIDs: fo.issueNewFleetOrder(str(ship_id), ship_id) self.execution_completed = True # attack elif AIFleetOrderType.ORDER_ATTACK == self.order_type: fleet_id = self.fleet.target_id fo.issueFleetMoveOrder(fleet_id, self.target.get_required_system_ai_targets()[0].target_id)