Package net.sf.freecol.server.ai
Class AIObject
- java.lang.Object
-
- net.sf.freecol.common.model.FreeColObject
-
- net.sf.freecol.server.ai.AIObject
-
- All Implemented Interfaces:
java.lang.Comparable<FreeColObject>,ObjectWithId
- Direct Known Subclasses:
AIColony,AIPlayer,Mission,ValuedAIObject,WorkLocationPlan
public abstract class AIObject extends FreeColObject
AnAIObjectcontains AI-related information and methods. EachFreeColGameObject, that is owned by an AI-controlled player, can have a singleAIObjectattached to it.
-
-
Field Summary
Fields Modifier and Type Field Description private AIMainaiMainThe AI this object exists within.protected booleaninitializedWhether the object is initialized.private static java.util.logging.Loggerlogger-
Fields inherited from class net.sf.freecol.common.model.FreeColObject
ARRAY_SIZE_TAG, DEFAULT_CLASS_INDEX, fcoComparator, ID_ATTRIBUTE_TAG, PARTIAL_ATTRIBUTE_TAG, VALUE_TAG
-
-
Constructor Summary
Constructors Modifier Constructor Description protectedAIObject(AIMain aiMain)Creates a new uninitializedAIObject.protectedAIObject(AIMain aiMain, java.lang.String id)Creates a new uninitializedAIObjectwith a registerable AI identifier.protectedAIObject(AIMain aiMain, FreeColXMLReader xr)Creates a newAIObject.
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description protected voidaddAIObjectWithId()Adds this object to the AI main if it has a non-null identifier.Constants.IntegrityTypecheckIntegrity(boolean fix)Just do the check, short cut the logging.Constants.IntegrityTypecheckIntegrity(boolean fix, LogBuilder lb)AIObjects need integrity checking too.<T extends FreeColObject>
booleancopyIn(T other)Copy another FreeColObject into this one if it is compatible.voiddispose()Disposes thisAIObjectby removing the reference to this object from the enclosing AIMain.AIMaingetAIMain()Convenience accessor for the main AI-object.GamegetGame()Gets the game this object belongs to.SpecificationgetSpecification()Get the specification.booleanisDisposed()Has this AIObject been disposed?private booleanisInitialized()Is this AI object initialized? That is: it has been fully initialized by a detailed constructor, or built with a simple constructor due to being referenced by another object, but then updated withFreeColObject.readFromXML(net.sf.freecol.common.io.FreeColXMLReader).voidsetGame(Game game)Sets the game object this object belongs to.abstract voidsetInitialized()Set the initialized flag in this object.voidsetSpecification(Specification specification)Sets the specification for this object.-
Methods inherited from class net.sf.freecol.common.model.FreeColObject
addAbility, addFeatures, addModifier, addPropertyChangeListener, addPropertyChangeListener, apply, apply, applyModifiers, applyModifiers, arrayKey, compareIds, compareTo, containsAbilityKey, containsModifierKey, copy, copy, copy, copy, copyInCast, dumpObject, equals, fireIndexedPropertyChange, fireIndexedPropertyChange, fireIndexedPropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, getAbilities, getAbilities, getAbilities, getAbilities, getClassIndex, getDefenceModifiers, getDisplayObject, getFeatureContainer, getFreeColObjectClass, getFreeColObjectClassByName, getId, getIdNumber, getIdType, getIdTypeByName, getModifiers, getModifiers, getModifiers, getModifiers, getObjectClassIndex, getPropertyChangeListeners, getPropertyChangeListeners, getPropertyChangeSupport, getSortedAbilities, getSortedModifiers, getSuffix, getSuffix, getXMLTagName, hasAbility, hasAbility, hasAbility, hashCode, hasListeners, hasModifier, hasModifier, hasModifier, idEquals, invokeMethod, logFreeColObjects, readAttributes, readChild, readChildren, readFromXML, readFromXMLPartial, removeAbilities, removeAbility, removeFeatures, removeModifier, removeModifiers, removePropertyChangeListener, removePropertyChangeListener, save, save, save, save, serialize, serialize, serialize, serialize, setId, toString, toXML, toXML, toXMLPartial, toXMLPartial, writeAttributes, writeChildren
-
-
-
-
Field Detail
-
logger
private static final java.util.logging.Logger logger
-
aiMain
private final AIMain aiMain
The AI this object exists within.
-
initialized
protected boolean initialized
Whether the object is initialized.
-
-
Constructor Detail
-
AIObject
protected AIObject(AIMain aiMain)
Creates a new uninitializedAIObject.- Parameters:
aiMain- The main AI-object.
-
AIObject
protected AIObject(AIMain aiMain, java.lang.String id)
Creates a new uninitializedAIObjectwith a registerable AI identifier.- Parameters:
aiMain- The main AI-object.id- The object identifier.- See Also:
AIMain.addAIObject(String, AIObject)
-
AIObject
protected AIObject(AIMain aiMain, FreeColXMLReader xr) throws javax.xml.stream.XMLStreamException
Creates a newAIObject.- Parameters:
aiMain- The main AI-object.xr- The input stream containing the XML.- Throws:
javax.xml.stream.XMLStreamException- if a problem was encountered during parsing.- See Also:
FreeColObject.readFromXML(net.sf.freecol.common.io.FreeColXMLReader)
-
-
Method Detail
-
isInitialized
private final boolean isInitialized()
Is this AI object initialized? That is: it has been fully initialized by a detailed constructor, or built with a simple constructor due to being referenced by another object, but then updated withFreeColObject.readFromXML(net.sf.freecol.common.io.FreeColXMLReader).- Returns:
- True if this
AIObjectis initialized.
-
setInitialized
public abstract void setInitialized()
Set the initialized flag in this object. To be implemented by leaf classes, and called in their constructors plus the special case in readChild below where we resolve forward references.
-
getAIMain
public final AIMain getAIMain()
Convenience accessor for the main AI-object.- Returns:
- The
AIMain.
-
dispose
public void dispose()
Disposes thisAIObjectby removing the reference to this object from the enclosing AIMain.
-
isDisposed
public final boolean isDisposed()
Has this AIObject been disposed?- Returns:
- True if this AIObject was disposed.
-
addAIObjectWithId
protected final void addAIObjectWithId()
Adds this object to the AI main if it has a non-null identifier.
-
checkIntegrity
public Constants.IntegrityType checkIntegrity(boolean fix, LogBuilder lb)
AIObjects need integrity checking too.- Parameters:
fix- If true, fix problems if possible.lb- ALogBuilderto log to.- Returns:
- -1 if there are problems remaining, zero if problems were fixed, +1 if no problems found at all.
-
checkIntegrity
public Constants.IntegrityType checkIntegrity(boolean fix)
Just do the check, short cut the logging.- Parameters:
fix- Fix problems if possible.- Returns:
- Negative if there are problems remaining, zero if problems were fixed, positive if no problems found at all.
-
getSpecification
public final Specification getSpecification()
Get the specification.- Overrides:
getSpecificationin classFreeColObject- Returns:
- The
Specificationused by this object.
-
setSpecification
public final void setSpecification(Specification specification)
Sets the specification for this object.- Overrides:
setSpecificationin classFreeColObject- Parameters:
specification- TheSpecificationto use.
-
getGame
public final Game getGame()
Gets the game this object belongs to.- Overrides:
getGamein classFreeColObject- Returns:
- The
Gamethis object belongs to.
-
setGame
public final void setGame(Game game)
Sets the game object this object belongs to.- Overrides:
setGamein classFreeColObject- Parameters:
game- TheGameto set.
-
copyIn
public <T extends FreeColObject> boolean copyIn(T other)
Copy another FreeColObject into this one if it is compatible.- Overrides:
copyInin classFreeColObject- Type Parameters:
T- TheFreeColObjectsubclass of the object to copy in.- Parameters:
other- The other object.- Returns:
- True if the copy in is succesful.
-
-