Class UnitSeekAndDestroyMission

  • All Implemented Interfaces:
    java.lang.Comparable<FreeColObject>, ObjectWithId

    public final class UnitSeekAndDestroyMission
    extends Mission
    Mission for attacking a specific target, be it a Unit or a Settlement.
    • Field Detail

      • logger

        private static final java.util.logging.Logger logger
      • tag

        private static final java.lang.String tag
        The tag for this mission.
        See Also:
        Constant Field Values
      • target

        private Location target
        The object we are trying to destroy. This can be a either Settlement or a Unit.
      • transportTarget

        private Location transportTarget
        The object we are trying to destroy. This can be a either Settlement or a Unit.
    • Constructor Detail

      • UnitSeekAndDestroyMission

        public UnitSeekAndDestroyMission​(AIMain aiMain,
                                         AIUnit aiUnit,
                                         Location target)
        Creates a mission for the given AIUnit.
        Parameters:
        aiMain - The main AI-object.
        aiUnit - The AIUnit this mission is created for.
        target - The object we are trying to destroy. This can be either a Settlement or a Unit.
      • UnitSeekAndDestroyMission

        public UnitSeekAndDestroyMission​(AIMain aiMain,
                                         AIUnit aiUnit,
                                         FreeColXMLReader xr)
                                  throws javax.xml.stream.XMLStreamException
        Creates a new UnitSeekAndDestroyMission from a reader.
        Parameters:
        aiMain - The main AI-object.
        aiUnit - The AIUnit this mission is created for.
        xr - The input stream containing the XML.
        Throws:
        javax.xml.stream.XMLStreamException - if a problem was encountered during parsing.
        See Also:
        FreeColObject.readFromXML(net.sf.freecol.common.io.FreeColXMLReader)
    • Method Detail

      • extractTarget

        public static Location extractTarget​(AIUnit aiUnit,
                                             PathNode path)
        Extract a valid target for this mission from a path.
        Parameters:
        aiUnit - The AIUnit to perform the mission.
        path - A PathNode to extract a target from.
        Returns:
        A target for this mission, or null if none found.
      • scoreSettlementPath

        private static int scoreSettlementPath​(AIUnit aiUnit,
                                               PathNode path,
                                               Settlement settlement)
        Scores a potential attack on a settlement. Do not cheat and look inside the settlement. Just use visible facts about it. FIXME: if we are the REF and there is a significant Tory population inside, assume traitors have briefed us.
        Parameters:
        aiUnit - The AIUnit to do the mission.
        path - The PathNode to take to the settlement.
        settlement - The Settlement to attack.
        Returns:
        A score of the desirability of the mission.
      • scoreUnitPath

        private static int scoreUnitPath​(AIUnit aiUnit,
                                         PathNode path,
                                         Unit defender)
        Scores a potential attack on a unit.
        Parameters:
        aiUnit - The AIUnit to do the mission.
        path - The PathNode to take to the settlement.
        defender - The Unit to attack.
        Returns:
        A score of the desirability of the mission.
      • scorePath

        public static int scorePath​(AIUnit aiUnit,
                                    PathNode path)
        Evaluate a potential seek and destroy mission for a given unit to a given tile.
        Parameters:
        aiUnit - The AIUnit to do the mission.
        path - A PathNode to take to the target.
        Returns:
        A score for the proposed mission.
      • getGoalDecider

        private static GoalDecider getGoalDecider​(AIUnit aiUnit,
                                                  boolean deferOK)
        Gets a GoalDecider for finding the best colony Tile, optionally falling back to the nearest colony.
        Parameters:
        aiUnit - The AIUnit that is searching.
        deferOK - Not used in this mission.
        Returns:
        A suitable GoalDecider.
      • findTargetPath

        private static PathNode findTargetPath​(AIUnit aiUnit,
                                               int range,
                                               boolean deferOK)
        Finds a suitable seek-and-destroy target path for an AI unit.
        Parameters:
        aiUnit - The AIUnit to find a target for.
        range - An upper bound on the number of moves.
        deferOK - Not implemented in this mission.
        Returns:
        A path to the target, or null if none found.
      • findMissionTarget

        public static Location findMissionTarget​(AIUnit aiUnit,
                                                 int range,
                                                 boolean deferOK)
        Finds a suitable seek-and-destroy target for an AI unit.
        Parameters:
        aiUnit - The AIUnit to find a target for.
        range - An upper bound on the number of moves.
        deferOK - Not implemented in this mission.
        Returns:
        A suitable target, or null if none found.
      • invalidUnitReason

        private static java.lang.String invalidUnitReason​(AIUnit aiUnit)
        Why would a UnitSeekAndDestroyMission be invalid with the given unit.
        Parameters:
        aiUnit - The AIUnit to test.
        Returns:
        A reason why the mission would be invalid, or null if none found.
      • invalidSettlementReason

        private static java.lang.String invalidSettlementReason​(AIUnit aiUnit,
                                                                Settlement settlement)
        Why would a UnitSeekAndDestroyMission be invalid with the given unit and settlement.
        Parameters:
        aiUnit - The AIUnit to seek-and-destroy with.
        settlement - The Settlement to test.
        Returns:
        A reason why the mission would be invalid, or null if none found.
      • invalidTargetReason

        private static java.lang.String invalidTargetReason​(AIUnit aiUnit,
                                                            Unit unit)
        Why would a UnitSeekAndDestroyMission be invalid with the given unit and target unit.
        Parameters:
        aiUnit - The AIUnit to seek-and-destroy with.
        unit - The target Unit to test.
        Returns:
        A reason why the mission would be invalid, or null if none found.
      • invalidMissionReason

        public static java.lang.String invalidMissionReason​(AIUnit aiUnit)
        Why would this mission be invalid with the given AI unit?
        Parameters:
        aiUnit - The AIUnit to check.
        Returns:
        A reason for mission invalidity, or null if none found.
      • invalidMissionReason

        public static java.lang.String invalidMissionReason​(AIUnit aiUnit,
                                                            Location loc)
        Why would this mission be invalid with the given AI unit and location?
        Parameters:
        aiUnit - The AIUnit to check.
        loc - The Location to check.
        Returns:
        A reason for invalidity, or null if none found.
      • getBaseTransportPriority

        public int getBaseTransportPriority()
        Get the base transport priority for the unit performing this mission.
        Overrides:
        getBaseTransportPriority in class Mission
        Returns:
        A base transport priority.
      • getTransportDestination

        public Location getTransportDestination()
        Gets the destination of a required transport. Override this in the child mission classes if there is a useful intermediate point to deliver the unit distinct from the target.
        Overrides:
        getTransportDestination in class Mission
        Returns:
        The mission target, or null if the mission is invalid, otherwise lacks a target (e.g. UnitWanderHostile), or the unit does not need transport.
      • getTarget

        public Location getTarget()
        Gets the target of this mission, if any.
        Specified by:
        getTarget in class Mission
        Returns:
        The target of this mission, or null if none.
      • setTarget

        public void setTarget​(Location target)
        Sets the target of this mission, if any. The actual target is handled in the missions that really have them, this is a helper to make sure the unit is updated.
        Specified by:
        setTarget in class Mission
        Parameters:
        target - The new target of this mission, or null if none.
      • findTarget

        public Location findTarget()
        Finds a new target for this mission.
        Specified by:
        findTarget in class Mission
        Returns:
        A new target for this mission.
      • invalidReason

        public java.lang.String invalidReason()
        Why is this mission invalid? Mission subclasses must implement this routine, which probably should start by checking invalidAIUnitReason. A mission can be invalid for a number of subclass-specific reasons. For example: a seek-and-destroy mission could be invalid because of a improved stance towards the targeted player.
        Specified by:
        invalidReason in class Mission
        Returns:
        A reason for mission invalidity, or null if none found.
      • doMission

        public Mission doMission​(LogBuilder lb)
        Performs the mission.
        Specified by:
        doMission in class Mission
        Parameters:
        lb - A LogBuilder to log to.
        Returns:
        The Mission to continue with, or null if the current mission has completed.
      • writeAttributes

        protected void writeAttributes​(FreeColXMLWriter xw)
                                throws javax.xml.stream.XMLStreamException
        Write the attributes of this object to a stream. To be overridden if required by any object that has attributes and uses the toXML(FreeColXMLWriter, String) call.
        Overrides:
        writeAttributes in class Mission
        Parameters:
        xw - The FreeColXMLWriter to write to.
        Throws:
        javax.xml.stream.XMLStreamException - if there are any problems writing to the stream.
      • readAttributes

        protected void readAttributes​(FreeColXMLReader xr)
                               throws javax.xml.stream.XMLStreamException
        Reads the attributes of this object from an XML stream.
        Overrides:
        readAttributes in class Mission
        Parameters:
        xr - The FreeColXMLReader to read from.
        Throws:
        javax.xml.stream.XMLStreamException - if there is a problem reading the stream.
      • getXMLTagName

        public java.lang.String getXMLTagName()
        Get the serialization tag for this object.
        Specified by:
        getXMLTagName in class FreeColObject
        Returns:
        The tag.