|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Objectnet.sf.freecol.common.model.FreeColObject
net.sf.freecol.server.ai.AIObject
net.sf.freecol.server.ai.mission.Mission
net.sf.freecol.server.ai.mission.TransportMission
public class TransportMission
Mission for transporting units and goods on a carrier.
Unit| Nested Class Summary | |
|---|---|
(package private) class |
TransportMission.Destination
|
| Field Summary | |
|---|---|
private static java.lang.String |
ELEMENT_TRANSPORTABLE
|
private static java.util.logging.Logger |
logger
|
private static int |
MINIMUM_GOLD_TO_STAY_IN_EUROPE
|
private java.util.List<Transportable> |
transportList
|
| Fields inherited from class net.sf.freecol.server.ai.mission.Mission |
|---|
MINIMUM_TRANSPORT_PRIORITY, NO_MORE_MOVES_LEFT, NO_PATH_TO_TARGET, NORMAL_TRANSPORT_PRIORITY |
| 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 | |
|---|---|
TransportMission(AIMain aiMain,
AIUnit aiUnit)
Creates a mission for the given AIUnit. |
|
TransportMission(AIMain aiMain,
org.w3c.dom.Element element)
Loads a TransportMission from the given element. |
|
TransportMission(AIMain aiMain,
javax.xml.stream.XMLStreamReader in)
Creates a new TransportMission and reads the given
element. |
|
| Method Summary | |
|---|---|
void |
addToTransportList(Transportable newTransportable)
Adds the given Transportable to the transport list. |
private boolean |
attackEnemyShips(Connection connection)
Attack suitable enemy ships. |
private boolean |
attackIfEnemyShipIsBlocking(Connection connection,
Map.Direction direction)
Attack blocking ships. |
private void |
buyCargo(Connection connection)
Buys cargo (units and goods) when the carrier is in Europe. |
AIGoods |
buyGoodsInEurope(Connection connection,
GoodsType type,
int amount,
Location destination)
Buys the given cargo. |
private boolean |
canAttackEnemyShips()
|
private boolean |
canAttackPlayer(Player target)
|
void |
dispose()
Disposes this Mission. |
void |
doMission(Connection connection)
Performs the mission. |
protected PathNode |
findNavalTarget(int maxTurns)
Finds the best target to attack within the given range. |
protected PathNode |
findPathToEurope(Tile start)
Finds the best path to Europe. |
int |
getAvailableSpace()
Returns the available space for any type of unit going to any type of location. |
int |
getAvailableSpace(Transportable t)
Returns the available space for the given Transportable. |
int |
getAvailableSpace(UnitType unitType,
Location source,
Location destination)
Returns the available space for the given type of Unit at
the given Location. |
private AIUnit |
getCheapestUnitInEurope(Connection connection)
Returns the cheapest unit which can be bought in Europe. |
java.lang.String |
getDebuggingInfo()
Gets debugging information about this mission. |
(package private) TransportMission.Destination |
getDefaultDestination()
Gets the current default destination for the unit of this mission. |
private int |
getDistanceTo(Transportable t,
Location start,
boolean source)
Gets the distance to the given Transportable. |
TransportMission.Destination |
getNextDestination()
Works out the next destination the carrier should go to to make progress with its transport list. |
static int |
getPlayerNavalTransportMissionCount(AIPlayer aiPlayer,
Unit unitExcluded)
Gives the number of naval units assigned with a Transport Mission |
Tile |
getTransportDestination()
Returns the destination of a required transport. |
PathNode |
getTransportPath(Transportable transportable)
Returns the path the carrier should use to get/drop the given Transportable. |
private PathNode |
getTransportPath(Transportable transportable,
Location start,
boolean collect)
Returns the path the carrier should use to get/drop the given Transportable. |
int |
getTransportPriority()
Returns the priority of getting the unit to the transport destination. |
private AIUnit |
getUnitInEurope(Connection connection,
UnitType unitType)
Returns the given type of Unit. |
static java.lang.String |
getXMLElementTagName()
Returns the tag name of the root element representing this object. |
private boolean |
hasCargo()
|
private void |
inEurope(Connection connection)
Unit is in Europe, unload cargo on board, buy required goods and board unit. |
private boolean |
isCarrying(Transportable t)
Checks if the carrier using this mission is carrying the given Transportable. |
boolean |
isOnTransportList(Transportable newTransportable)
Checks if the given Transportable is on the transport
list. |
boolean |
isValid()
Checks if this mission is still valid to perform. |
static boolean |
isValid(AIUnit aiUnit)
Checks if this mission is valid for the given unit. |
private boolean |
loadCargoAtDestination(Connection connection)
Loads any Transportables being in range of the carrier. |
protected void |
readChildren(javax.xml.stream.XMLStreamReader in)
Reads the children of this object from an XML stream. |
void |
removeFromTransportList(Transportable transportable)
Removes the given Transportable from the transport list. |
private boolean |
restockCargoAtDestination(Connection connection)
Loads and unloads any Transportable. |
java.lang.String |
toString()
Creates a String representation of this mission to
be used for debugging purposes. |
protected void |
toXMLImpl(javax.xml.stream.XMLStreamWriter out)
Writes all of the AIObjects and other AI-related
information to an XML-stream. |
private boolean |
unloadCargoAtDestination(Connection connection)
Unloads any Transportables which have reached their
destination. |
private void |
updateTransportList()
Adds every Goods and Unit onboard the
carrier to the transport list. |
protected void |
writeChildren(javax.xml.stream.XMLStreamWriter out)
Write the children of this object to a stream. |
| Methods inherited from class net.sf.freecol.server.ai.mission.Mission |
|---|
findNearestOtherSettlement, findTarget, getAIRandom, getAIUnit, getEuropeanAIPlayer, getPathStartTile, getUnit, isOneTime, moveButDontAttack, moveRandomly, moveTowards, moveTowards, moveUnitToAmerica, moveUnitToEurope, readAttributes, sellCargoInEurope, setAIUnit, shouldTakeTransportToTile, travelToTarget, unitLeavesShip, unloadCargoInColony, writeAttributes |
| Methods inherited from class net.sf.freecol.server.ai.AIObject |
|---|
getAIMain, getGame, getSpecification, isUninitialized, readFromXML |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
| Field Detail |
|---|
private static final java.util.logging.Logger logger
private static final java.lang.String ELEMENT_TRANSPORTABLE
private static final int MINIMUM_GOLD_TO_STAY_IN_EUROPE
private final java.util.List<Transportable> transportList
| Constructor Detail |
|---|
public TransportMission(AIMain aiMain,
AIUnit aiUnit)
AIUnit.
aiMain - The main AI-object.aiUnit - The AIUnit this mission is created for.
public TransportMission(AIMain aiMain,
org.w3c.dom.Element element)
TransportMission from the given element.
aiMain - The main AI-object.element - An Element containing an XML-representation
of this object.
public TransportMission(AIMain aiMain,
javax.xml.stream.XMLStreamReader in)
throws javax.xml.stream.XMLStreamException
TransportMission and reads the given
element.
aiMain - The main AI-object.in - The input stream containing the XML.
javax.xml.stream.XMLStreamException - if a problem was encountered during parsing.AIObject.readFromXML(javax.xml.stream.XMLStreamReader)| Method Detail |
|---|
private void updateTransportList()
Goods and Unit onboard the
carrier to the transport list.
Goods,
Unitprivate boolean isCarrying(Transportable t)
Transportable.
t - The Transportable.
true if the given Transportable is
located in the carrier.public void dispose()
Mission.
dispose in class Missionpublic boolean isOnTransportList(Transportable newTransportable)
Transportable is on the transport
list.
newTransportable - The Transportable to be checked
true if the given Transportable was
on the transport list, and false otherwise.public void removeFromTransportList(Transportable transportable)
Transportable from the transport list.
This method calls Transportable.setTransport(AIUnit).
transportable - The Transportable.public void addToTransportList(Transportable newTransportable)
Transportable to the transport list. The
method returns immediately if the Transportable has already be
added.
Location for the
Transportable is entered into the transport list if the
Transportable is not already loaded onto the transport. If
the Transportable is onboard the transport, then only the
destination is put on the transport list.
newTransportable - The Transportable.
private int getDistanceTo(Transportable t,
Location start,
boolean source)
Transportable.
start - The Location to check the distance from.
Europe is used instead of this location if
start.getTile() == null.source - Sets wether the Transportable's
source or
destination
should be used.
Location to the source
or destination of the given Transportable.private boolean canAttackEnemyShips()
private boolean hasCargo()
private boolean attackIfEnemyShipIsBlocking(Connection connection,
Map.Direction direction)
private boolean attackEnemyShips(Connection connection)
private boolean canAttackPlayer(Player target)
protected PathNode findNavalTarget(int maxTurns)
maxTurns - The maximum number of turns the unit is allowed
to spend in order to reach the target.
null if no target
can be found.public void doMission(Connection connection)
doMission in class Missionconnection - The Connection to the server.public TransportMission.Destination getNextDestination()
Destination, which may be null if none
is available.TransportMission.Destination getDefaultDestination()
Destination for the unit.private void buyCargo(Connection connection)
Europe.
Europe.
connection - The Connection to the server.
public AIGoods buyGoodsInEurope(Connection connection,
GoodsType type,
int amount,
Location destination)
Europe.
connection - The Connection to use when communicating
with the server.type - The type of goods to buy.amount - The amount of goods to buy.destination - The Location to which the goods should
be transported.
private AIUnit getUnitInEurope(Connection connection,
UnitType unitType)
Unit.
Europe.
connection - The Connection to the server.unitType - The type of Unit to be found/recruited/trained.
AIUnit.private AIUnit getCheapestUnitInEurope(Connection connection)
Europe.
connection - The connection to use when communicating with the
server.
AIUnit.public PathNode getTransportPath(Transportable transportable)
Transportable.
transportable - The Transportable.
private PathNode getTransportPath(Transportable transportable,
Location start,
boolean collect)
Transportable.
transportable - The Transportable.start - The Tile to search from. If
start == null or
start.getTile() == null then the carrier's
entry location is used instead.collect - True if the transportable must be collected.
public int getAvailableSpace(Transportable t)
Transportable.
t - The Transportable
Transportables with the
same source and
destination.
public int getAvailableSpace(UnitType unitType,
Location source,
Location destination)
Unit at
the given Location.
unitType - The type of Unit or null for
Goodssource - The source for the unit. This is where the unit is
presently located.destination - The destination for the unit.
public int getAvailableSpace()
private boolean restockCargoAtDestination(Connection connection)
Transportable.
connection - The Connection to the server.
true if something has been loaded/unloaded and
falseotherwise.private boolean unloadCargoAtDestination(Connection connection)
Transportables which have reached their
destination.
connection - The Connection to the server.
true if something has been unloaded and
falseotherwise.private boolean loadCargoAtDestination(Connection connection)
Transportables being in range of the carrier.
connection - The Connection to the server.
true if something has been unloaded and
falseotherwise.public static boolean isValid(AIUnit aiUnit)
aiUnit - The unit.
true if this mission is valid to perform
and false otherwise.public boolean isValid()
isValid in class Missiontruepublic Tile getTransportDestination()
getTransportDestination in class Missionnullpublic int getTransportPriority()
getTransportPriority in class Missionprivate void inEurope(Connection connection)
connection - The Connection to the server.protected PathNode findPathToEurope(Tile start)
Europe.
start - The starting Tile.
null if no target can be
found.Europe
public static int getPlayerNavalTransportMissionCount(AIPlayer aiPlayer,
Unit unitExcluded)
public java.lang.String getDebuggingInfo()
getDebuggingInfo in class MissionString: "(x, y) z" or "(x, y) z!" where
x and y is the coordinates of the
target tile for this mission, and z is the value
of building the colony. The exclamation mark is added if the unit
should continue searching for a colony site if the targeted site
is lost.
protected void toXMLImpl(javax.xml.stream.XMLStreamWriter out)
throws javax.xml.stream.XMLStreamException
AIObjects and other AI-related
information to an XML-stream.
toXMLImpl in class FreeColObjectout - The target stream.
javax.xml.stream.XMLStreamException - if there are any problems writing to the
stream.
protected void writeChildren(javax.xml.stream.XMLStreamWriter out)
throws javax.xml.stream.XMLStreamException
FreeColObject
writeChildren in class FreeColObjectout - The target stream.
javax.xml.stream.XMLStreamException - if there are any problems writing
to the stream.
protected void readChildren(javax.xml.stream.XMLStreamReader in)
throws javax.xml.stream.XMLStreamException
FreeColObject
readChildren in class FreeColObjectin - The XML input stream.
javax.xml.stream.XMLStreamException - if a problem was encountered
during parsing.public java.lang.String toString()
String representation of this mission to
be used for debugging purposes.
toString in class java.lang.Objectpublic static java.lang.String getXMLElementTagName()
|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||