|
|||||||||
| 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.AIMain
public class AIMain
The main AI-class. Keeps references to all other AI-classes.
| Field Summary | |
|---|---|
private java.util.HashMap<java.lang.String,AIObject> |
aiObjects
Contains mappings between FreeColGameObjects
and AIObjects. |
private FreeColServer |
freeColServer
|
private static java.util.logging.Logger |
logger
|
private int |
nextID
|
| 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 | |
|---|---|
AIMain(FreeColServer freeColServer)
Creates a new AIMain and searches the current
game for FreeColGameObjects. |
|
AIMain(FreeColServer freeColServer,
org.w3c.dom.Element element)
Creates a new AIMain and reads the given element. |
|
AIMain(FreeColServer freeColServer,
javax.xml.stream.XMLStreamReader in)
Creates a new AIMain and reads the given element. |
|
| Method Summary | |
|---|---|
void |
addAIObject(java.lang.String id,
AIObject aiObject)
Adds a reference to the given AIObject. |
boolean |
checkIntegrity()
Checks the integrity of this AIMain
by checking if there are any
uninitialized objects. |
private void |
findNewObjects()
Searches for new FreeColGameObjects. |
void |
findNewObjects(boolean overwrite)
Searches for new FreeColGameObjects. |
AIColony |
getAIColony(Colony colony)
Gets the AI colony corresponding to a given colony. |
AIObject |
getAIObject(FreeColGameObject fcgo)
Gets the AIObject for the given
FreeColGameObject. |
AIObject |
getAIObject(java.lang.String id)
Gets the AIObject identified by the given ID. |
AIPlayer |
getAIPlayer(Player player)
Gets the AI player corresponding to a given player. |
java.util.Random |
getAIRandom()
Gets the random number generator to be used in the AI. |
java.util.HashMap<java.lang.String,java.lang.String> |
getAIStatistics()
Computes how many objects of each class have been created, to track memory leaks over time |
AIUnit |
getAIUnit(Unit unit)
Gets the AI unit corresponding to a given unit. |
FreeColGameObject |
getFreeColGameObject(java.lang.String id)
Gets the FreeColGameObject with the given ID. |
FreeColServer |
getFreeColServer()
Gets the main controller object for the server. |
Game |
getGame()
Returns the game. |
java.lang.String |
getNextID()
Gets a unique ID for identifying an AIObject. |
static java.lang.String |
getXMLElementTagName()
Returns the tag name of the root element representing this object. |
void |
ownerChanged(FreeColGameObject source,
Player oldOwner,
Player newOwner)
|
protected void |
readFromXMLImpl(javax.xml.stream.XMLStreamReader in)
Reads all the AIObjects and other AI-related information
from XML data. |
void |
removeAIObject(java.lang.String id)
Removes a reference to the given AIObject. |
void |
removeFreeColGameObject(java.lang.String id)
Removes the AIObject for the given FreeColGameObject. |
void |
setFreeColGameObject(java.lang.String id,
FreeColGameObject freeColGameObject)
Creates a new AIObject for a given
FreeColGameObject. |
protected void |
toXMLImpl(javax.xml.stream.XMLStreamWriter out)
Writes all of the AIObjects and other AI-related
information to an XML-stream. |
protected void |
writeAttributes(javax.xml.stream.XMLStreamWriter out)
Write the attributes of this object to a stream. |
protected void |
writeChildren(javax.xml.stream.XMLStreamWriter out)
Write the children of this object to a stream. |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
|---|
private static final java.util.logging.Logger logger
private FreeColServer freeColServer
private int nextID
private java.util.HashMap<java.lang.String,AIObject> aiObjects
FreeColGameObjects
and AIObjects.
| Constructor Detail |
|---|
public AIMain(FreeColServer freeColServer)
AIMain and searches the current
game for FreeColGameObjects.
freeColServer - The main controller object for the
server.findNewObjects()
public AIMain(FreeColServer freeColServer,
org.w3c.dom.Element element)
AIMain and reads the given element.
freeColServer - The main controller object for the
server.element - The Element (in a DOM-parsed XML-tree)
that describes this object.FreeColObject.readFromXMLElement(org.w3c.dom.Element)
public AIMain(FreeColServer freeColServer,
javax.xml.stream.XMLStreamReader in)
throws javax.xml.stream.XMLStreamException
AIMain and reads the given element.
freeColServer - The main controller object for the
server.in - The input stream containing the XML.
javax.xml.stream.XMLStreamException - if a problem was encountered
during parsing.FreeColObject.readFromXML(javax.xml.stream.XMLStreamReader)| Method Detail |
|---|
public FreeColServer getFreeColServer()
FreeColServer-object.public java.lang.String getNextID()
AIObject.
public boolean checkIntegrity()
AIMain
by checking if there are any
uninitialized objects.
Detected problems gets written to the log.
true if the Game has
been loaded properly.public Game getGame()
Game.public java.util.Random getAIRandom()
private void findNewObjects()
FreeColGameObjects. An AI-object is
created for each object.
AIObjects will be overwritten.
findNewObjects(boolean)public void findNewObjects(boolean overwrite)
FreeColGameObjects. An AI-object is
created for each new object.
overwrite - Determines wether any old AIObject
should be overwritten or not.public AIObject getAIObject(FreeColGameObject fcgo)
AIObject for the given
FreeColGameObject.
fcgo - The FreeColGameObject to find
the AIObject for.
AIObject.getAIObject(String)public AIObject getAIObject(java.lang.String id)
AIObject identified by the given ID.
id - The ID of the AIObject.
AIObject.getAIObject(FreeColGameObject)public AIColony getAIColony(Colony colony)
colony - The Colony to look up.
public AIPlayer getAIPlayer(Player player)
player - The Player to look up.
public AIUnit getAIUnit(Unit unit)
unit - The Unit to look up.
public void addAIObject(java.lang.String id,
AIObject aiObject)
AIObject.
id - The ID of the AIObject.aiObject - The AIObject to store a reference
for.
java.lang.IllegalStateException - if an AIObject with
the same id has already been created.public void removeAIObject(java.lang.String id)
AIObject.
id - The ID of the AIObject.public FreeColGameObject getFreeColGameObject(java.lang.String id)
FreeColGameObject with the given ID.
This is just a convenience method for:
Game.getFreeColGameObject(java.lang.String)
id - The ID of the FreeColGameObject to find.
FreeColGameObject.
public void ownerChanged(FreeColGameObject source,
Player oldOwner,
Player newOwner)
ownerChanged in interface FreeColGameObjectListener
public void setFreeColGameObject(java.lang.String id,
FreeColGameObject freeColGameObject)
AIObject for a given
FreeColGameObject. This method gets called
whenever a new object gets added to the Game.
setFreeColGameObject in interface FreeColGameObjectListenerid - The ID of the FreeColGameObject to add.freeColGameObject - The FreeColGameObject to add.AIObject,
FreeColGameObject,
FreeColObject.getId()public void removeFreeColGameObject(java.lang.String id)
AIObject for the given FreeColGameObject.
removeFreeColGameObject in interface FreeColGameObjectListenerid - The ID of the FreeColGameObject.public java.util.HashMap<java.lang.String,java.lang.String> getAIStatistics()
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 writeAttributes(javax.xml.stream.XMLStreamWriter out)
throws javax.xml.stream.XMLStreamException
writeAttributes 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
writeChildren in class FreeColObjectout - The target stream.
javax.xml.stream.XMLStreamException - if there are any problems writing
to the stream.
protected void readFromXMLImpl(javax.xml.stream.XMLStreamReader in)
throws javax.xml.stream.XMLStreamException
AIObjects and other AI-related information
from XML data.
readFromXMLImpl in class FreeColObjectin - The input stream with the XML.
javax.xml.stream.XMLStreamException - if an error occured during parsing.public static java.lang.String getXMLElementTagName()
|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||