net.sf.freecol.server.ai.goal
Class ManageMissionariesGoal

java.lang.Object
  extended by net.sf.freecol.common.model.FreeColObject
      extended by net.sf.freecol.server.ai.AIObject
          extended by net.sf.freecol.server.ai.goal.Goal
              extended by net.sf.freecol.server.ai.goal.ManageMissionariesGoal
All Implemented Interfaces:
GoalConstants

public class ManageMissionariesGoal
extends Goal

This Goal deals with all missionaries of one AIPlayer.

For each missionary unit that is being added, this goal will try to find an IndianSettlement needing a visit. Distance and reachability from the current position of the unit are taken into account, with the implicit assumption that the current location of the unit is sensible in that a nearby settlement is even worth visiting. Since missionary units are either created in a player-owned colony, or brought there from Europe, this assumption will most often be valid.

If a settlement has been found, a CreateMissionAtSettlementGoal will be created, and the unit be moved there.


Field Summary
private static java.util.logging.Logger logger
           
private  java.util.List<Goal> subGoalList
           
 
Fields inherited from class net.sf.freecol.server.ai.goal.Goal
availableUnitsList, isFinished, needsPlanning, player
 
Fields inherited from class net.sf.freecol.server.ai.AIObject
uninitialized
 
Fields inherited from class net.sf.freecol.common.model.FreeColObject
ARRAY_SIZE, ID_ATTRIBUTE, ID_ATTRIBUTE_TAG, PARTIAL_ATTRIBUTE
 
Fields inherited from interface net.sf.freecol.server.ai.goal.GoalConstants
MAX_SEARCH_RADIUS
 
Constructor Summary
ManageMissionariesGoal(AIPlayer p, Goal g, float w)
           
 
Method Summary
private  IndianSettlement findSettlement(Tile t)
           
 java.lang.String getGoalDescription()
          Returns a string describing just this goal.
protected  java.util.Iterator<AIUnit> getOwnedAIUnitsIterator()
          Since internal implementation details may vary, each Goal will define an iterator over all of its units.
protected  java.util.Iterator<Goal> getSubGoalIterator()
          Since internal implementation details may vary, each Goal will define an iterator over all of its subgoals.
protected  void plan()
          Plans this goal.
protected  void readFromXMLImpl(javax.xml.stream.XMLStreamReader in)
          Reads information for this object from an XML stream.
protected  void removeUnit(AIUnit u)
          Ensures that a unit moved to another Goal is properly removed from this.
protected  void toXMLImpl(javax.xml.stream.XMLStreamWriter out)
          Writes this object to an XML stream.
 
Methods inherited from class net.sf.freecol.server.ai.goal.Goal
addUnit, addUnitToParent, cancelGoal, canYieldUnit, doPlanning, getAbsoluteWeight, getDebugDescription, getParentWeight, getWeight, getXMLElementTagName, getYieldedUnitWeight, isFinished, needsPlanning, normalizeSubGoalWeights, requestWorker, setNeedsPlanningRecursive, setWeight, validateOwnedUnits, yieldUnit
 
Methods inherited from class net.sf.freecol.server.ai.AIObject
dispose, getAIMain, getAIRandom, getGame, isUninitialized, readFromXML
 
Methods inherited from class net.sf.freecol.common.model.FreeColObject
addPropertyChangeListener, addPropertyChangeListener, fireIndexedPropertyChange, fireIndexedPropertyChange, fireIndexedPropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, getAttribute, getAttribute, getAttribute, getAttribute, getId, getPropertyChangeListeners, getPropertyChangeListeners, hasAbility, hasAttribute, hasListeners, readAttributes, readChildren, readFromArrayElement, readFromArrayElement, readFromArrayElement, readFromListElement, readFromXMLElement, readFromXMLPartialImpl, removePropertyChangeListener, removePropertyChangeListener, setId, toArrayElement, toArrayElement, toListElement, toXML, toXML, toXML, toXMLElement, toXMLElement, toXMLElement, toXMLElement, toXMLElementPartial, toXMLPartialImpl, writeAttribute, writeAttributes, writeChildren, writeFreeColGameObject
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

logger

private static final java.util.logging.Logger logger

subGoalList

private java.util.List<Goal> subGoalList
Constructor Detail

ManageMissionariesGoal

public ManageMissionariesGoal(AIPlayer p,
                              Goal g,
                              float w)
Method Detail

getOwnedAIUnitsIterator

protected java.util.Iterator<AIUnit> getOwnedAIUnitsIterator()
Description copied from class: Goal
Since internal implementation details may vary, each Goal will define an iterator over all of its units.

Specified by:
getOwnedAIUnitsIterator in class Goal
Returns:
An Iterator over all AIUnit currently managed by this goal.

getSubGoalIterator

protected java.util.Iterator<Goal> getSubGoalIterator()
Description copied from class: Goal
Since internal implementation details may vary, each Goal will define an iterator over all of its subgoals.

Specified by:
getSubGoalIterator in class Goal
Returns:
An Iterator over all currently existing subgoals.

removeUnit

protected void removeUnit(AIUnit u)
Description copied from class: Goal
Ensures that a unit moved to another Goal is properly removed from this. If a unit is removed from this goal via Goal.yieldUnit(UnitType,AIObject), or if the Unit contained in the AIUnit no longer is valid, this method is called to clean up any remaining references to the unit.

Any implementation of this will need to iterate over all AIUnit object references used by this goal, and remove those that equal the given parameter.

Specified by:
removeUnit in class Goal
Parameters:
u - The AIUnit supposed to be removed from this goal.

plan

protected void plan()
Plans this goal. NOTE: This goal currently does not send unit requests, but only deals with the units it gets passively.

Specified by:
plan in class Goal

getGoalDescription

public java.lang.String getGoalDescription()
Description copied from class: Goal
Returns a string describing just this goal. An implementing class may override this method to add specialized information. Used by getDebugDescription.

Overrides:
getGoalDescription in class Goal
Returns:
a string describing this goal

toXMLImpl

protected void toXMLImpl(javax.xml.stream.XMLStreamWriter out)
                  throws javax.xml.stream.XMLStreamException
Description copied from class: Goal
Writes this object to an XML stream.

Specified by:
toXMLImpl in class Goal
Parameters:
out - The target stream.
Throws:
javax.xml.stream.XMLStreamException - if there are any problems writing to the stream.

readFromXMLImpl

protected void readFromXMLImpl(javax.xml.stream.XMLStreamReader in)
                        throws javax.xml.stream.XMLStreamException
Description copied from class: Goal
Reads information for this object from an XML stream.

Specified by:
readFromXMLImpl in class Goal
Parameters:
in - The input stream with the XML.
Throws:
javax.xml.stream.XMLStreamException - if there are any problems reading from the stream.

findSettlement

private IndianSettlement findSettlement(Tile t)