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
 
Fields inherited from class net.sf.freecol.common.model.FreeColObject
ID_ATTRIBUTE_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.
 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.
 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.
 
Methods inherited from class net.sf.freecol.server.ai.AIObject
getAIMain, 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, getPropertyChangeListeners, getPropertyChangeListeners, hasAbility, hasAttribute, hasListeners, readFromXMLElement, removePropertyChangeListener, removePropertyChangeListener, toXML, toXML, toXML, toXMLElement, toXMLElement, toXMLElement, toXMLElement, toXMLElementPartial, writeAttribute, writeFreeColGameObject
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

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()

getXMLElementTagName

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

Returns:
"aiUnit"