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 issue_order(self): if not super(OrderOutpost, self).issue_order(): return planet = self.target.get_object() if not planet.unowned: self.order_issued = True return fleet_id = self.fleet.id ship_id = FleetUtilsAI.get_ship_id_with_role(fleet_id, ShipRoleType.CIVILIAN_OUTPOST) if ship_id is None: ship_id = FleetUtilsAI.get_ship_id_with_role(fleet_id, ShipRoleType.BASE_OUTPOST) result = fo.issueColonizeOrder(ship_id, self.target.id) print "Order issued: %s fleet: %s target: %s" % (self.ORDER_NAME, self.fleet, self.target) if not result: self.executed = False
def issue_order(self): if not super(OrderColonize, self).issue_order(): return fleet_id = self.fleet.id ship_id = FleetUtilsAI.get_ship_id_with_role(fleet_id, ShipRoleType.CIVILIAN_COLONISATION) if ship_id is None: ship_id = FleetUtilsAI.get_ship_id_with_role(fleet_id, ShipRoleType.BASE_COLONISATION) planet = self.target.get_object() planet_name = planet and planet.name or "apparently invisible" result = fo.issueColonizeOrder(ship_id, self.target.id) print "Order issued: %s fleet: %s target: %s" % (self.ORDER_NAME, self.fleet, self.target) print "Ordered colony ship ID %d to colonize %s, got result %d" % (ship_id, planet_name, result) if not result: self.executed = False
def issue_order(self): if not super(OrderColonize, self).issue_order(): return False # we can't know yet if the order will actually execute; instead, rely on the fact that if the order does get # executed, then next turn it will be invalid self.executed = False fleet_id = self.fleet.id ship_id = FleetUtilsAI.get_ship_id_with_role(fleet_id, ShipRoleType.CIVILIAN_COLONISATION) if ship_id is None: ship_id = FleetUtilsAI.get_ship_id_with_role(fleet_id, ShipRoleType.BASE_COLONISATION) if fo.issueColonizeOrder(ship_id, self.target.id): debug("Order issued: %s fleet: %s target: %s" % (self.ORDER_NAME, self.fleet, self.target)) return True else: self.order_issued = False warn("Order issuance failed: %s fleet: %s target: %s" % (self.ORDER_NAME, self.fleet, self.target)) return False
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)