Class MissionAIPlayer

    • Field Detail

      • logger

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

        private static final java.util.Comparator<AIUnit> aiUnitLocationComparator
        A comparator to sort AI units by location.
      • aiUnits

        private java.util.List<AIUnit> aiUnits
        Temporary variable, used to hold all AIUnit objects belonging to this AI. Any implementation of AIPlayer needs to make sure this list is invalidated as necessary, using clearAIUnits().
    • Constructor Detail

      • MissionAIPlayer

        public MissionAIPlayer​(AIMain aiMain,
                               Player player)
        Creates a new AI player.
        Parameters:
        aiMain - The AIMain the player exists within.
        player - The Player to associate this AI player with.
      • MissionAIPlayer

        public MissionAIPlayer​(AIMain aiMain,
                               FreeColXMLReader xr)
                        throws javax.xml.stream.XMLStreamException
        Creates a new AIPlayer from the given XML-representation.
        Parameters:
        aiMain - The main AI-object.
        xr - The input stream containing the XML.
        Throws:
        javax.xml.stream.XMLStreamException - if a problem was encountered during parsing.
    • Method Detail

      • removeAIObject

        public void removeAIObject​(AIObject ao)
        Remove one of our owned objects. Subclasses to override.
        Overrides:
        removeAIObject in class AIPlayer
        Parameters:
        ao - The AIObject to remove.
      • clearAIUnits

        protected void clearAIUnits()
        Clears the cache of AI units.
      • addAIUnit

        public void addAIUnit​(AIUnit aiUnit)
        Add an AI unit owned by this player.
        Parameters:
        aiUnit - The AIUnit to add.
      • removeAIUnit

        private void removeAIUnit​(AIUnit aiu)
        Remove an AI unit.
        Parameters:
        aiu - The AIUnit to remove.
      • getAIUnits

        protected java.util.List<AIUnit> getAIUnits()
        Gets a list of AIUnits for the player.
        Overrides:
        getAIUnits in class AIPlayer
        Returns:
        A list of AIUnits.
      • getSettlementDefenders

        public int getSettlementDefenders​(Settlement settlement)
        Counts the number of defenders allocated to a settlement.
        Parameters:
        settlement - The Settlement to examine.
        Returns:
        The number of defenders.
      • isTargetValidForSeekAndDestroy

        public boolean isTargetValidForSeekAndDestroy​(Unit attacker,
                                                      Tile tile)
        Find out if a tile contains a suitable target for seek-and-destroy. FIXME: Package for access by a test only - necessary?
        Parameters:
        attacker - The attacking Unit.
        tile - The Tile to attack into.
        Returns:
        True if an attack can be launched.
      • logMissions

        protected void logMissions​(java.util.Map<Unit,​java.lang.String> reasons,
                                   LogBuilder lb)
        Log the missions of this player.
        Parameters:
        reasons - A map of reasons for the current mission by unit.
        lb - A LogBuilder to log to.
      • getDefendCurrentSettlementMission

        public Mission getDefendCurrentSettlementMission​(AIUnit aiUnit)
        Get a DefendSettlementMission for the current settlement of a unit if it is badly defended.
        Parameters:
        aiUnit - The AIUnit to check.
        Returns:
        A new misison, or null if impossible or not worthwhile.
      • getDefendSettlementMission

        public Mission getDefendSettlementMission​(AIUnit aiUnit,
                                                  Settlement target)
        Gets a new DefendSettlementMission for a unit.
        Parameters:
        aiUnit - The AIUnit to check.
        target - The Settlement to defend.
        Returns:
        A new mission, or null if impossible.
      • getIdleAtSettlementMission

        public Mission getIdleAtSettlementMission​(AIUnit aiUnit)
        Gets a new IdleAtSettlementMission for a unit.
        Parameters:
        aiUnit - The AIUnit to use.
        Returns:
        A new mission, or null if impossible.
      • getSeekAndDestroyMission

        public Mission getSeekAndDestroyMission​(AIUnit aiUnit,
                                                int range)
        Gets a UnitSeekAndDestroyMission for a unit.
        Parameters:
        aiUnit - The AIUnit to check.
        range - A maximum range to search for a target within.
        Returns:
        A new mission, or null if impossible.
      • getSeekAndDestroyMission

        public Mission getSeekAndDestroyMission​(AIUnit aiUnit,
                                                Location loc)
        Gets a UnitSeekAndDestroyMission for a unit.
        Parameters:
        aiUnit - The AIUnit to check.
        loc - The target Location.
        Returns:
        A new mission, or null if impossible.
      • getWanderHostileMission

        public Mission getWanderHostileMission​(AIUnit aiUnit)
        Gets a new UnitWanderHostileMission for a unit.
        Parameters:
        aiUnit - The AIUnit to check.
        Returns:
        A new mission, or null if impossible.
      • doMissions

        protected java.util.List<AIUnit> doMissions​(java.util.List<AIUnit> aiUnits,
                                                    LogBuilder lb)
        Makes every unit perform their mission.
        Parameters:
        aiUnits - A list of AIUnits to perform missions.
        lb - A LogBuilder to log to.
        Returns:
        A list of AIUnits that have moves left.
      • adjustMission

        public abstract int adjustMission​(AIUnit aiUnit,
                                          PathNode path,
                                          java.lang.Class type,
                                          int value)
        Adjusts the score of this proposed mission for this player type. Subclasses should override and refine this.
        Parameters:
        aiUnit - The AIUnit to perform the mission.
        path - A PathNode to the target of this mission.
        value - The proposed value.
        type - The mission type.
        Returns:
        A score representing the desirability of this mission.