Class PioneeringMission

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

    public final class PioneeringMission
    extends Mission
    Mission for controlling a pioneer.
    • 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
      • DEFAULT_THREAT_TURNS

        private static final int DEFAULT_THREAT_TURNS
        Default distance in turns to a threatening unit.
        See Also:
        Constant Field Values
      • tileImprovementPlan

        private TileImprovementPlan tileImprovementPlan
        The improvement this pioneer is to work on.
      • target

        private Location target
        The target location to go to: - a tile where the tileImprovement is - a colony to go to to equip - just an initial colony to retarget from
    • Constructor Detail

      • PioneeringMission

        public PioneeringMission​(AIMain aiMain,
                                 AIUnit aiUnit,
                                 Location target)
        Creates a pioneering mission for the given AIUnit. Note that PioneeringMission.isValid(aiUnit) should be called before this, to guarantee that findTileImprovementPlan/findColonyWithTools succeed.
        Parameters:
        aiMain - The main AI-object.
        aiUnit - The AIUnit this mission is created for.
        target - The target Location.
      • PioneeringMission

        public PioneeringMission​(AIMain aiMain,
                                 AIUnit aiUnit,
                                 FreeColXMLReader xr)
                          throws javax.xml.stream.XMLStreamException
        Creates a new PioneeringMission 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

      • getBestPlan

        private TileImprovementPlan getBestPlan​(Tile tile)
        Get the best improvement associated with a tile.
        Parameters:
        tile - The Tile to get a plan for.
        Returns:
        The TileImprovementPlan, or null if not found.
      • getBestMissionPlan

        private static TileImprovementPlan getBestMissionPlan​(AIUnit aiUnit,
                                                              Tile tile)
        Get the best improvement associated with a tile for a given unit. Take care to first check if the unit has a plan already, if so, return that.
        Parameters:
        aiUnit - The AIUnit to get a plan for.
        tile - The Tile to get a plan for.
        Returns:
        The TileImprovementPlan, or null if not found.
      • getTileImprovementPlan

        public TileImprovementPlan getTileImprovementPlan()
        Gets the TileImprovementPlan for this mission.
        Returns:
        The TileImprovementPlan.
      • setTileImprovementPlan

        public void setTileImprovementPlan​(TileImprovementPlan tip)
        Sets the TileImprovementPlan which should be the next target.
        Parameters:
        tip - The TileImprovementPlan.
      • abandonTileImprovementPlan

        private void abandonTileImprovementPlan()
        Abandons the current plan if any.
      • dispose

        public void dispose()
        Disposes of this pioneering mission.
        Overrides:
        dispose in class Mission
      • hasMissionTools

        private static boolean hasMissionTools​(AIUnit aiUnit)
        Does a supplied unit have tools?
        Parameters:
        aiUnit - The pioneer AIUnit to check.
        Returns:
        True if the pioneer has tools.
      • hasTools

        private boolean hasTools()
        Does this pioneer have tools?
        Returns:
        True if the pioneer has tools.
      • extractTarget

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

        public static int scorePath​(AIUnit aiUnit,
                                    PathNode path)
        Evaluate a potential pioneering mission for a given unit and path.
        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)
        Makes a goal decider that checks pioneering sites.
        Parameters:
        aiUnit - The AIUnit to search with.
        deferOK - Keep track of the nearest colonies to use as a fallback destination.
        Returns:
        A suitable GoalDecider.
      • findTargetPath

        private static PathNode findTargetPath​(AIUnit aiUnit,
                                               int range,
                                               boolean deferOK)
        Finds a suitable pioneering target for the supplied unit.
        Parameters:
        aiUnit - The AIUnit to execute this mission.
        range - An upper bound on the number of moves.
        deferOK - Enables deferring to a fallback colony.
        Returns:
        A path to the new target, or null if none found.
      • getBestPioneeringColony

        private static Colony getBestPioneeringColony​(AIUnit aiUnit)
        Gets the Colony that most needs a pioneer.
        Parameters:
        aiUnit - The pioneer AIUnit.
        Returns:
        The colony with the most outstanding tile improvement plans.
      • findMissionTarget

        public static Location findMissionTarget​(AIUnit aiUnit,
                                                 int range,
                                                 boolean deferOK)
        Finds a suitable pioneering target for the supplied unit. Falls back to the best settlement if the unit is not on the map.
        Parameters:
        aiUnit - The AIUnit to test.
        range - An upper bound on the number of moves.
        deferOK - Enables deferring to a fallback colony.
        Returns:
        A target for this mission.
      • prepare

        public static java.lang.String prepare​(AIUnit aiUnit)
        Prepare a unit for this mission.
        Parameters:
        aiUnit - The AIUnit to prepare.
        Returns:
        A reason why the unit can not perform this mission, or null if none.
      • invalidUnitReason

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

        private static java.lang.String invalidColonyReason​(AIUnit aiUnit,
                                                            Colony colony)
        Why would a PioneeringMission be invalid with the given unit and colony.
        Parameters:
        aiUnit - The AIUnit to check.
        colony - The Colony to check.
        Returns:
        A reason why the mission would be invalid, or null if none found.
      • getPlan

        private static TileImprovementPlan getPlan​(AIUnit aiUnit,
                                                   Tile tile)
        Gets the existing tile improvement plan for a unit and tile.
        Parameters:
        aiUnit - The AIUnit to check.
        tile - The Tile to check.
        Returns:
        The associated TileImprovementPlan.
      • invalidTileReason

        private static java.lang.String invalidTileReason​(AIUnit aiUnit,
                                                          Tile tile)
        Why would a PioneeringMission be invalid with the given unit and tile.
        Parameters:
        aiUnit - The AIUnit to check.
        tile - The Tile to check.
        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.
      • 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.
      • lbFail

        protected Mission lbFail​(LogBuilder lb,
                                 boolean cont,
                                 java.lang.Object... reasons)
        The current mission has failed.
        Overrides:
        lbFail in class Mission
        Parameters:
        lb - A LogBuilder to log to.
        cont - If true, the mission should continue, otherwise drop the mission.
        reasons - Reasons for the successful completion.
        Returns:
        The current Mission of the unit, which may not be different from this.
      • 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.