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
AnAIObject
contains AI-related information and methods. EachFreeColGameObject
, that is owned by an AI-controlled player, can have a singleAIObject
attached to it.
-
-
Field Summary
Fields Modifier and Type Field Description private AIMain
aiMain
The AI this object exists within.protected boolean
initialized
Whether the object is initialized.private static java.util.logging.Logger
logger
-
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 protected
AIObject(AIMain aiMain)
Creates a new uninitializedAIObject
.protected
AIObject(AIMain aiMain, java.lang.String id)
Creates a new uninitializedAIObject
with a registerable AI identifier.protected
AIObject(AIMain aiMain, FreeColXMLReader xr)
Creates a newAIObject
.
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description protected void
addAIObjectWithId()
Adds this object to the AI main if it has a non-null identifier.Constants.IntegrityType
checkIntegrity(boolean fix)
Just do the check, short cut the logging.Constants.IntegrityType
checkIntegrity(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.void
dispose()
Disposes thisAIObject
by removing the reference to this object from the enclosing AIMain.AIMain
getAIMain()
Convenience accessor for the main AI-object.Game
getGame()
Gets the game this object belongs to.Specification
getSpecification()
Get the specification.boolean
isDisposed()
Has this AIObject been disposed?private 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)
.void
setGame(Game game)
Sets the game object this object belongs to.abstract void
setInitialized()
Set the initialized flag in this object.void
setSpecification(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 uninitializedAIObject
with 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
AIObject
is 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 thisAIObject
by 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
- ALogBuilder
to 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:
getSpecification
in classFreeColObject
- Returns:
- The
Specification
used by this object.
-
setSpecification
public final void setSpecification(Specification specification)
Sets the specification for this object.- Overrides:
setSpecification
in classFreeColObject
- Parameters:
specification
- TheSpecification
to use.
-
getGame
public final Game getGame()
Gets the game this object belongs to.- Overrides:
getGame
in classFreeColObject
- Returns:
- The
Game
this object belongs to.
-
setGame
public final void setGame(Game game)
Sets the game object this object belongs to.- Overrides:
setGame
in classFreeColObject
- Parameters:
game
- TheGame
to set.
-
copyIn
public <T extends FreeColObject> boolean copyIn(T other)
Copy another FreeColObject into this one if it is compatible.- Overrides:
copyIn
in classFreeColObject
- Type Parameters:
T
- TheFreeColObject
subclass of the object to copy in.- Parameters:
other
- The other object.- Returns:
- True if the copy in is succesful.
-
-