Class ColonyPlan

    • Field Detail

      • logger

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

        private static final java.util.Comparator<ColonyPlan.BuildPlan> buildPlanComparator
        Comparator to sort buildable by descending value.
      • LOW_PRODUCTION_THRESHOLD

        private static final int LOW_PRODUCTION_THRESHOLD
        Require production plans to always produce an amount exceeding this.
        See Also:
        Constant Field Values
      • PRODUCTION_TURNOVER_TURNS

        private static final int PRODUCTION_TURNOVER_TURNS
        Number of turns to require production of without exhausting the input goods.
        See Also:
        Constant Field Values
      • aiMain

        private final AIMain aiMain
        Private copy of the AIMain.
      • colony

        private final Colony colony
        The colony this AIColony manages.
      • workPlans

        private final java.util.List<WorkLocationPlan> workPlans
        Plans for work locations available to this colony.
      • produce

        private final java.util.List<GoodsType> produce
        The goods types to produce.
      • libertyGoodsTypes

        private final java.util.Set<GoodsType> libertyGoodsTypes
        Sets of goods types to be produced in this colony. Temporary variables that do not need to be serialized. Note: food and luxury groups disabled as not currently used, but will probably be needed in due course. Raw building goods types need to be sorted so they are a list.
      • immigrationGoodsTypes

        private final java.util.Set<GoodsType> immigrationGoodsTypes
      • militaryGoodsTypes

        private final java.util.Set<GoodsType> militaryGoodsTypes
      • rawBuildingGoodsTypes

        private final java.util.List<GoodsType> rawBuildingGoodsTypes
      • buildingGoodsTypes

        private final java.util.Set<GoodsType> buildingGoodsTypes
      • rawLuxuryGoodsTypes

        private final java.util.Set<GoodsType> rawLuxuryGoodsTypes
      • otherRawGoodsTypes

        private final java.util.Set<GoodsType> otherRawGoodsTypes
    • Constructor Detail

      • ColonyPlan

        public ColonyPlan​(AIMain aiMain,
                          Colony colony)
        Creates a new ColonyPlan.
        Parameters:
        aiMain - The main AI-object.
        colony - The colony to make a ColonyPlan for.
    • Method Detail

      • getAIMain

        private AIMain getAIMain()
        Gets the main AI-object.
        Returns:
        The main AI-object.
      • spec

        private Specification spec()
        Gets the specification.
        Returns:
        The specification.
      • getPreferredProduction

        public java.util.List<GoodsType> getPreferredProduction()
        Gets the preferred goods to produce.
        Returns:
        A copy of the preferred goods production list in this plan.
      • getBuildableTypes

        public java.util.List<BuildableType> getBuildableTypes()
        Gets a copy of the current list of buildable types associated with this ColonyPlan.
        Returns:
        A copy of the of BuildableTypes list.
      • getBestBuildableType

        public BuildableType getBestBuildableType()
        Gets the best buildable type from this plan that can currently be built by the colony.
        Returns:
        The best current BuildableType.
      • getBuildableReport

        public java.lang.String getBuildableReport()
        Get a report on the build plans.
        Returns:
        A build plan report.
      • getFoodPlans

        public java.util.List<WorkLocationPlan> getFoodPlans()
        Gets the food-producing and non-autoproducing work location plans associated with this ColonyPlan.
        Returns:
        A list of food producing plans.
      • getWorkPlans

        public java.util.List<WorkLocationPlan> getWorkPlans()
        Gets the non-food-producing/non-autoproducing work location plans associated with this ColonyPlan.
        Returns:
        A list of non-food producing plans.
      • refine

        public void refine​(BuildableType build,
                           LogBuilder lb)
        Refines this plan given the colony choice of what to build.
        Parameters:
        build - The BuildableType to be built (may be null).
        lb - A LogBuilder to log to.
      • update

        public void update()
        Recreates the buildables and work location plans for this colony.
      • createProductionMap

        private java.util.Map<GoodsType,​java.util.Map<WorkLocation,​java.lang.Integer>> createProductionMap()
        Creates a map of potential production of all goods types from all available work locations using the default unit type. Includes non-workable locations (e.g. chapel, colony-center-tile) as their production can influence the choice of goods to produce.
        Returns:
        The map of potential production.
      • updateGoodsTypeLists

        private void updateGoodsTypeLists​(java.util.Map<GoodsType,​java.util.Map<WorkLocation,​java.lang.Integer>> production)
        Updates the goods type lists. The categories are:
        • food
        • liberty
        • immigration
        • military
        • raw building
        • building
        • raw luxury
        • luxury
        • raw other
        Ignore raw materials which can not be refined and refined goods that have no raw materials available. Also ignore other goods that do not fit these categories (e.g. trade goods).
        Parameters:
        production - The production map.
      • updateRawMaterials

        private void updateRawMaterials​(java.util.Map<GoodsType,​java.util.Map<WorkLocation,​java.lang.Integer>> production)
        Chooses the two best raw materials, updating the production map and lists. FIXME: scale with colony size.
        Parameters:
        production - The production map.
      • findBuildPlan

        private ColonyPlan.BuildPlan findBuildPlan​(BuildableType type)
        Finds a build plan for this type.
        Parameters:
        type - The BuildableType to search for.
        Returns:
        A BuildPlan with this type, or null if not found.
      • prioritize

        private boolean prioritize​(BuildableType type,
                                   double weight,
                                   double support)
        Adds or improves the priority of a buildable in a list.
        Parameters:
        type - The BuildableType to use.
        weight - The relative weight of this class of buildable with respect to other buildable classes.
        support - The support for this buildable within its class.
        Returns:
        True if this type was prioritized.
      • prioritizeProduction

        private boolean prioritizeProduction​(BuildableType type,
                                             GoodsType goodsType)
        Given a buildable that improves production of a goods type, prioritize it.
        Parameters:
        type - The BuildableType to consider.
        goodsType - The GoodsType improved by the buildable.
        Returns:
        True if this type was prioritized.
      • updateBuildableTypes

        private void updateBuildableTypes()
        Updates the build plans for this colony.
      • updatePlans

        private void updatePlans​(java.util.Map<GoodsType,​java.util.Map<WorkLocation,​java.lang.Integer>> production)
        Makes a plan for each type of possible production, that is those work locations that can use a unit or can auto-produce. Note that this will almost certainly include clashes over work locations. That gets sorted out elsewhere as ColonyPlans do not examine the units present. With the complete list of work plans, finish creating the list of goods to produce. Then filter out the auto-production plans as they are not going to be helpful for unit allocation. Finally sort by desirability.
        Parameters:
        production - A map of the goods type and production.
      • updateProductionList

        private void updateProductionList​(java.util.Map<GoodsType,​java.util.Map<WorkLocation,​java.lang.Integer>> production)
        Add the other goods types to the production list. When this is called the new world goods production is already present on the produce list. Ignores food which is treated separately.
        Parameters:
        production - A map of the production.
      • findPlan

        private WorkLocationPlan findPlan​(GoodsType goodsType,
                                          java.util.List<WorkLocationPlan> plans)
        Finds a plan on a list that produces a given goods type.
        Parameters:
        goodsType - The GoodsType to produce.
        plans - The list of WorkLocationPlans to check.
        Returns:
        The first plan found that produces the goods type, or null if none found.
      • getBestWorker

        protected static Unit getBestWorker​(WorkLocation wl,
                                            GoodsType goodsType,
                                            java.util.List<Unit> workers)
        Gets the best worker to execute a work location plan. - The most productive one wins (which will automatically pick a relevant expert). - If they are all relevant experts, pick any. - Pick the unit that can upgrade to the required expert with the most relevant experience or least irrelevant expertise. - Pick a unit that can not upgrade at all. - Pick an otherwise upgradeable unit with the most relevant experience or least irrelevant experience. - Pick the least skillful unit. Public for the benefit of the test suite.
        Parameters:
        wl - The WorkLocation to work at.
        goodsType - The GoodsType to make.
        workers - A list of potential Units to try.
        Returns:
        The best worker for the job.
      • fullEquipUnit

        private static boolean fullEquipUnit​(Specification spec,
                                             Unit unit,
                                             Role role,
                                             Colony colony)
        Equips a unit for a role, trying all possibilities if a military role was called for.
        Parameters:
        spec - The Specification defining the roles.
        unit - The Unit to equip if possible.
        role - The Role for the unit to take.
        colony - The Colony storing the equipment.
        Returns:
        True if the unit was equipped.
      • assignWorkers

        public Colony assignWorkers​(java.util.List<Unit> workers,
                                    boolean preferScout,
                                    LogBuilder lb)
        Tries to apply a colony plan given a list of workers.
        Parameters:
        workers - A list of Units to assign.
        preferScout - Prefer to make scouts rather than soldiers.
        lb - A LogBuilder to log to.
        Returns:
        A scratch colony with the workers in place.
      • locationDescription

        private java.lang.String locationDescription​(Location loc)
        Gets a concise textual description of a location associated with the colony. No i18n here, this is for debugging purposes.
        Parameters:
        loc - The Location to describe.
        Returns:
        The text description.
      • toString

        public java.lang.String toString()
        Overrides:
        toString in class java.lang.Object