net.sf.freecol.server.ai
Class AIMain

java.lang.Object
  extended by net.sf.freecol.common.model.FreeColObject
      extended by net.sf.freecol.server.ai.AIMain
All Implemented Interfaces:
FreeColGameObjectListener

public class AIMain
extends FreeColObject
implements FreeColGameObjectListener

The main AI-class. Keeps references to all other AI-classes.


Field Summary
 
Fields inherited from class net.sf.freecol.common.model.FreeColObject
ID_ATTRIBUTE_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.
 void findNewObjects(boolean overwrite)
          Searches for new FreeColGameObjects.
 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.
 java.util.Random getAIRandom()
          Gets the random number generator to be used in the AI.
 java.util.HashMap<java.lang.String,java.lang.Long> getAIStatistics()
          Computes how many objects of each class have been created, to track memory leaks over time
 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)
           
 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.
 
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, readFromXML, 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

AIMain

public AIMain(FreeColServer freeColServer)
Creates a new AIMain and searches the current game for FreeColGameObjects.

Parameters:
freeColServer - The main controller object for the server.
See Also:
findNewObjects()

AIMain

public AIMain(FreeColServer freeColServer,
              org.w3c.dom.Element element)
Creates a new AIMain and reads the given element.

Parameters:
freeColServer - The main controller object for the server.
element - The Element (in a DOM-parsed XML-tree) that describes this object.
See Also:
FreeColObject.readFromXMLElement(org.w3c.dom.Element)

AIMain

public AIMain(FreeColServer freeColServer,
              javax.xml.stream.XMLStreamReader in)
       throws javax.xml.stream.XMLStreamException
Creates a new AIMain and reads the given element.

Parameters:
freeColServer - The main controller object for the server.
in - The input stream containing the XML.
Throws:
javax.xml.stream.XMLStreamException - if a problem was encountered during parsing.
See Also:
FreeColObject.readFromXML(javax.xml.stream.XMLStreamReader)
Method Detail

getFreeColServer

public FreeColServer getFreeColServer()
Gets the main controller object for the server.

Returns:
The FreeColServer-object.

getNextID

public java.lang.String getNextID()
Gets a unique ID for identifying an AIObject.

Returns:
A unique ID.

checkIntegrity

public boolean checkIntegrity()
Checks the integrity of this AIMain by checking if there are any uninitialized objects. Detected problems gets written to the log.

Returns:
true if the Game has been loaded properly.

getGame

public Game getGame()
Returns the game.

Returns:
The Game.

getAIRandom

public java.util.Random getAIRandom()
Gets the random number generator to be used in the AI.

Returns:
The AI random number generator.

findNewObjects

public void findNewObjects(boolean overwrite)
Searches for new FreeColGameObjects. An AI-object is created for each new object.

Parameters:
overwrite - Determines wether any old AIObject should be overwritten or not.

getAIObject

public AIObject getAIObject(FreeColGameObject fcgo)
Gets the AIObject for the given FreeColGameObject.

Parameters:
fcgo - The FreeColGameObject to find the AIObject for.
Returns:
The AIObject.
See Also:
getAIObject(String)

getAIObject

public AIObject getAIObject(java.lang.String id)
Gets the AIObject identified by the given ID.

Parameters:
id - The ID of the AIObject.
Returns:
The AIObject.
See Also:
getAIObject(FreeColGameObject)

addAIObject

public void addAIObject(java.lang.String id,
                        AIObject aiObject)
Adds a reference to the given AIObject.

Parameters:
id - The ID of the AIObject.
aiObject - The AIObject to store a reference for.
Throws:
java.lang.IllegalStateException - if an AIObject with the same id has already been created.

removeAIObject

public void removeAIObject(java.lang.String id)
Removes a reference to the given AIObject.

Parameters:
id - The ID of the AIObject.

getFreeColGameObject

public FreeColGameObject getFreeColGameObject(java.lang.String id)
Gets the FreeColGameObject with the given ID. This is just a convenience method for: Game.getFreeColGameObject(java.lang.String)

Parameters:
id - The ID of the FreeColGameObject to find.
Returns:
The FreeColGameObject.

ownerChanged

public void ownerChanged(FreeColGameObject source,
                         Player oldOwner,
                         Player newOwner)
Specified by:
ownerChanged in interface FreeColGameObjectListener

setFreeColGameObject

public void setFreeColGameObject(java.lang.String id,
                                 FreeColGameObject freeColGameObject)
Creates a new AIObject for a given FreeColGameObject. This method gets called whenever a new object gets added to the Game.

Specified by:
setFreeColGameObject in interface FreeColGameObjectListener
Parameters:
id - The ID of the FreeColGameObject to add.
freeColGameObject - The FreeColGameObject to add.
See Also:
AIObject, FreeColGameObject, FreeColObject.getId()

removeFreeColGameObject

public void removeFreeColGameObject(java.lang.String id)
Removes the AIObject for the given FreeColGameObject.

Specified by:
removeFreeColGameObject in interface FreeColGameObjectListener
Parameters:
id - The ID of the FreeColGameObject.

getXMLElementTagName

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

Returns:
"aiMain"

getAIStatistics

public java.util.HashMap<java.lang.String,java.lang.Long> getAIStatistics()
Computes how many objects of each class have been created, to track memory leaks over time