Class FreeColGameObject

    • Field Detail

      • logger

        private static final java.util.logging.Logger logger
      • FREECOL_GAME_OBJECT_CLASS_INDEX

        private static final int FREECOL_GAME_OBJECT_CLASS_INDEX
        Default class index for FreeColGameObjects.
        See Also:
        Constant Field Values
      • game

        private Game game
        The game this object belongs to.
      • disposed

        private boolean disposed
        Has this object been disposed?
      • initialized

        protected boolean initialized
        Has this object been initialized?
    • Constructor Detail

      • FreeColGameObject

        protected FreeColGameObject()
        Special constructor solely for initializing a Game. Do *not* call internId as the Game is not ready to register objects.
      • FreeColGameObject

        public FreeColGameObject​(Game game)
        Create and initialize a new FreeColGameObject.
        Parameters:
        game - The enclosing Game.
      • FreeColGameObject

        public FreeColGameObject​(Game game,
                                 java.lang.String id)
        Creates a new FreeColGameObject. If an identifier is supplied, use that, otherwise leave it undefined. This routine should be used when we know that the object will need further initialization.
        Parameters:
        game - The enclosing Game.
        id - The object identifier.
    • Method Detail

      • internId

        public final void internId​(java.lang.String newId)
        Sets the unique identifier of this object and registers it in its Game with that identifier, i.e. "intern" this object.
        Parameters:
        newId - The unique identifier of this object.
      • intern

        public void intern()
        Intern this object.
      • isInitialized

        public final boolean isInitialized()
        Has this object been initialized?
        Returns:
        True if this object is initialized.
      • isDisposed

        public final boolean isDisposed()
        Has this object been disposed?
        Returns:
        True if this object has been disposed.
        See Also:
        dispose()
      • dispose

        public final void dispose()
        Destroy this object and all its parts, releasing resources and removing references.
      • fundamentalDispose

        public final void fundamentalDispose()
        Low level base dispose, removing the object from the game.
      • copyIn

        public <T extends FreeColObject> boolean copyIn​(T other)
        Copy another FreeColObject into this one if it is compatible.
        Overrides:
        copyIn in class FreeColObject
        Type Parameters:
        T - The FreeColObject subclass of the object to copy in.
        Parameters:
        other - The other object.
        Returns:
        True if the copy in is succesful.
      • isInternable

        public boolean isInternable()
        Should this object be interned into its Game? Usually true, but there are some special containers that have to be FCGOs but are unsuitable to be interned. These classes will override this routine.
        Returns:
        True if this object should be interned.
      • getDisposables

        public java.util.stream.Stream<FreeColGameObject> getDisposables()
        Collect this object and all its subparts that should be disposed of when this object goes away. Overriding routines should call upwards towards this routine, arranging that the object itself is last.
        Returns:
        A stream of FreeColGameObjects to dispose of.
      • disposeResources

        public void disposeResources()
        Dispose of the resources of this object, and finally remove it from the game. To be extended by subclasses, but they must tail call up towards this.
      • getLinkTarget

        public FreeColGameObject getLinkTarget​(Player player)
        Get a suitable game object to use as a clickable link in messages to a player. Objects do not have links by default, hence the null return here. However, for example, a player's colony should return itself as a link target.
        Parameters:
        player - The Player to make a link for.
        Returns:
        A suitable link target if available, although usually null.
      • checkIntegrity

        public Constants.IntegrityType checkIntegrity​(boolean fix,
                                                      LogBuilder lb)
        Checks the integrity of this game object.
        Parameters:
        fix - If true, fix problems if possible.
        lb - A LogBuilder to log to.
        Returns:
        A suitable IntegrityType.
      • setSpecification

        public void setSpecification​(Specification specification)
        Sets the specification for this object.
        Overrides:
        setSpecification in class FreeColObject
        Parameters:
        specification - The Specification to use.
      • getGame

        public final Game getGame()
        Gets the game this object belongs to.
        Overrides:
        getGame in class FreeColObject
        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 class FreeColObject
        Parameters:
        game - The Game to set.
      • readAttributes

        protected void readAttributes​(FreeColXMLReader xr)
                               throws javax.xml.stream.XMLStreamException
        Reads the attributes of this object from an XML stream.
        Overrides:
        readAttributes in class FreeColObject
        Parameters:
        xr - The FreeColXMLReader to read from.
        Throws:
        javax.xml.stream.XMLStreamException - if there is a problem reading the stream.
      • readFromXML

        public void readFromXML​(FreeColXMLReader xr)
                         throws javax.xml.stream.XMLStreamException
        Initializes this object from an XML-representation of this object, unless the PARTIAL_ATTRIBUTE tag is present which indicates a partial update of an existing object.
        Overrides:
        readFromXML in class FreeColObject
        Parameters:
        xr - The input stream with the XML.
        Throws:
        javax.xml.stream.XMLStreamException - if there are any problems reading the stream.
      • equals

        public boolean equals​(java.lang.Object o)
        Overrides:
        equals in class FreeColObject