net.sf.freecol.server.ai
Class AIUnit

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.AIUnit
All Implemented Interfaces:
Transportable

public class AIUnit
extends AIObject
implements Transportable

Objects of this class contains AI-information for a single Unit.

The method doMission(Connection) is called once each turn, by AIPlayer.startWorking(), to perform the assigned Mission. Most of the methods in this class just delegates the call to that mission.

See Also:
Mission

Field Summary
private  int dynamicPriority
          The dynamic part of the transport priority.
private  Goal goal
          The goal this AIUnit belongs to, if one has been assigned.
private static java.util.logging.Logger logger
           
private  Mission mission
          The mission this unit has been assigned.
private  AIUnit transport
          The AIUnit which has this Transportable in it's transport list.
private  Unit unit
          The FreeColGameObject this AIObject contains AI-information for.
 
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, INFINITY, NO_ID, PARTIAL_ATTRIBUTE, UNDEFINED, VALUE_TAG
 
Constructor Summary
AIUnit(AIMain aiMain, org.w3c.dom.Element element)
          Creates a new AIUnit.
AIUnit(AIMain aiMain, java.lang.String id)
          Creates a new AIUnit.
AIUnit(AIMain aiMain, Unit unit)
          Creates a new AIUnit.
AIUnit(AIMain aiMain, javax.xml.stream.XMLStreamReader in)
          Creates a new AIUnit.
 
Method Summary
 void abortWish(Wish w)
          Aborts the given Wish.
 void dispose()
          Disposes this object and any attached mission.
 void doMission(Connection connection)
          Performs the mission this unit has been assigned.
 AIPlayer getAIOwner()
          Gets the AIPlayer that owns this AIUnit.
 Connection getConnection()
           
 Goal getGoal()
           
 java.lang.String getId()
          Returns the ID of this AIObject.
 Mission getMission()
          Gets the mission this unit has been assigned.
 AIUnit getTransport()
          Gets the carrier responsible for transporting this Transportable.
 Location getTransportDestination()
          Returns the destination for this Transportable.
 Locatable getTransportLocatable()
          Gets the Locatable which should be transported.
 int getTransportPriority()
          Gets the priority of transporting this Transportable to it's destination.
 Location getTransportSource()
          Returns the source for this Transportable.
 Unit getUnit()
          Gets the Unit this AIUnit controls.
static java.lang.String getXMLElementTagName()
          Returns the tag name of the root element representing this object.
 boolean hasMission()
          Checks if this unit has been assigned a mission.
 void increaseTransportPriority()
          Increases the transport priority of this Transportable.
protected  void readFromXMLImpl(javax.xml.stream.XMLStreamReader in)
          Reads information for this object from an XML stream.
 void setGoal(Goal g)
           
 void setMission(Mission mission)
          Assignes a mission to unit.
 void setTransport(AIUnit transport)
          Sets the carrier responsible for transporting this Transportable.
 java.lang.String toString()
          Returns a String-representation of this object.
protected  void toXMLImpl(javax.xml.stream.XMLStreamWriter out)
          Writes this object to an XML stream.
 
Methods inherited from class net.sf.freecol.server.ai.AIObject
getAIMain, getAIRandom, getGame, isUninitialized, readFromXML
 
Methods inherited from class net.sf.freecol.common.model.FreeColObject
addPropertyChangeListener, addPropertyChangeListener, dumpObject, fireIndexedPropertyChange, fireIndexedPropertyChange, fireIndexedPropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, getAttribute, getAttribute, getAttribute, getAttribute, getAttribute, getPropertyChangeListeners, getPropertyChangeListeners, getSpecification, hasAbility, hasAttribute, hasListeners, readAttributes, readAttributes, readChild, readChild, readChildren, readChildren, readFromArrayElement, readFromArrayElement, readFromListElement, readFromXMLElement, readFromXMLImpl, readFromXMLPartialImpl, removePropertyChangeListener, removePropertyChangeListener, save, save, setId, toXML, toXML, toXML, toXMLElement, toXMLElement, toXMLElement, toXMLElement, toXMLElementPartial, toXMLPartialImpl, writeAttribute, writeAttributes, writeChildren
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

logger

private static final java.util.logging.Logger logger

unit

private Unit unit
The FreeColGameObject this AIObject contains AI-information for.


mission

private Mission mission
The mission this unit has been assigned.


goal

private Goal goal
The goal this AIUnit belongs to, if one has been assigned.


dynamicPriority

private int dynamicPriority
The dynamic part of the transport priority.


transport

private AIUnit transport
The AIUnit which has this Transportable in it's transport list. This Transportable has not been scheduled for transport if this value is null.

Constructor Detail

AIUnit

public AIUnit(AIMain aiMain,
              Unit unit)
Creates a new AIUnit.

Parameters:
aiMain - The main AI-object.
unit - The unit to make an AIObject for.

AIUnit

public AIUnit(AIMain aiMain,
              org.w3c.dom.Element element)
Creates a new AIUnit.

Parameters:
aiMain - The main AI-object.
element - An Element containing an XML-representation of this object.

AIUnit

public AIUnit(AIMain aiMain,
              javax.xml.stream.XMLStreamReader in)
       throws javax.xml.stream.XMLStreamException
Creates a new AIUnit.

Parameters:
aiMain - The main AI-object.
in - The input stream containing the XML.
Throws:
javax.xml.stream.XMLStreamException - if a problem was encountered during parsing.
See Also:
AIObject.readFromXML(javax.xml.stream.XMLStreamReader)

AIUnit

public AIUnit(AIMain aiMain,
              java.lang.String id)
Creates a new AIUnit.

Parameters:
aiMain - The main AI-object.
id - The unique ID of this object.
Method Detail

getUnit

public Unit getUnit()
Gets the Unit this AIUnit controls.

Returns:
The Unit.

abortWish

public void abortWish(Wish w)
Aborts the given Wish.

Specified by:
abortWish in interface Transportable
Parameters:
w - The Wish to be aborted.

getTransportLocatable

public Locatable getTransportLocatable()
Gets the Locatable which should be transported.

Specified by:
getTransportLocatable in interface Transportable
Returns:
The Locatable.

getTransportSource

public Location getTransportSource()
Returns the source for this Transportable. This is normally the location of the locatable.

Specified by:
getTransportSource in interface Transportable
Returns:
The source for this Transportable.

getTransportDestination

public Location getTransportDestination()
Returns the destination for this Transportable. This can either be the target Tile of the transport or the target for the entire Transportable's mission. The target for the tansport is determined by TransportMission in the latter case.

Specified by:
getTransportDestination in interface Transportable
Returns:
The destination for this Transportable.

getTransportPriority

public int getTransportPriority()
Gets the priority of transporting this Transportable to it's destination.

Specified by:
getTransportPriority in interface Transportable
Returns:
The priority of the transport.

increaseTransportPriority

public void increaseTransportPriority()
Increases the transport priority of this Transportable. This method gets called every turn the Transportable have not been put on a carrier's transport list.

Specified by:
increaseTransportPriority in interface Transportable

getTransport

public AIUnit getTransport()
Gets the carrier responsible for transporting this Transportable.

Specified by:
getTransport in interface Transportable
Returns:
The AIUnit which has this Transportable in it's transport list. This Transportable has not been scheduled for transport if this value is null.

setTransport

public void setTransport(AIUnit transport)
Sets the carrier responsible for transporting this Transportable.

Specified by:
setTransport in interface Transportable
Parameters:
transport - The AIUnit which has this Transportable in it's transport list. This Transportable has not been scheduled for transport if this value is null.

getMission

public Mission getMission()
Gets the mission this unit has been assigned.

Returns:
The Mission.

hasMission

public boolean hasMission()
Checks if this unit has been assigned a mission.

Returns:
true if this unit has a mission.

setMission

public void setMission(Mission mission)
Assignes a mission to unit. The dynamic priority is reset.

Parameters:
mission - The new Mission.

doMission

public void doMission(Connection connection)
Performs the mission this unit has been assigned.

Parameters:
connection - The Connection to use when communicating with the server.

dispose

public void dispose()
Disposes this object and any attached mission.

Overrides:
dispose in class AIObject

getId

public java.lang.String getId()
Returns the ID of this AIObject.

Specified by:
getId in interface Transportable
Overrides:
getId in class FreeColObject
Returns:
The same ID as the Unit this AIObject controls.

setGoal

public void setGoal(Goal g)

getGoal

public Goal getGoal()

getAIOwner

public AIPlayer getAIOwner()
Gets the AIPlayer that owns this AIUnit.

Returns:
The owning AIPlayer.

getConnection

public Connection getConnection()

toXMLImpl

protected void toXMLImpl(javax.xml.stream.XMLStreamWriter out)
                  throws javax.xml.stream.XMLStreamException
Writes this object to an XML stream.

Specified by:
toXMLImpl in class FreeColObject
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
Reads information for this object from an XML stream.

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

toString

public java.lang.String toString()
Returns a String-representation of this object.

Overrides:
toString in class java.lang.Object
Returns:
A String representing this object for debugging purposes.

getXMLElementTagName

public static java.lang.String getXMLElementTagName()
Returns the tag name of the root element representing this object.

Returns:
"aiUnit"