Class ChangeSet


  • public class ChangeSet
    extends java.lang.Object
    Changes to be sent to the client.
    • Field Detail

      • changes

        private final java.util.List<ChangeSet.Change> changes
        The changes to send.
    • Constructor Detail

      • ChangeSet

        public ChangeSet()
        Simple constructor.
      • ChangeSet

        public ChangeSet​(ChangeSet other)
        Copying constructor.
        Parameters:
        other - The other ChangeSet to copy.
    • Method Detail

      • isEmpty

        public boolean isEmpty()
        Are there changes present?
        Returns:
        True if there is no changes present.
      • clear

        public void clear()
        Clear the current changes.
      • remove

        public void remove​(FreeColGameObject fcgo)
        Sometimes we need to backtrack on making a change.
        Parameters:
        fcgo - A FreeColGameObject to remove a matching change for.
      • add

        public ChangeSet add​(ChangeSet.See see,
                             FreeColGameObject... objects)
        Helper function to add updates for multiple objects to a ChangeSet.
        Parameters:
        see - The visibility of this change.
        objects - The FreeColGameObjects that changed.
        Returns:
        The updated ChangeSet.
      • add

        public ChangeSet add​(ChangeSet.See see,
                             java.util.Collection<? extends FreeColGameObject> objects)
        Helper function to add updates for multiple objects to a ChangeSet.
        Parameters:
        see - The visibility of this change.
        objects - The FreeColGameObjects that changed.
        Returns:
        The updated ChangeSet.
      • add

        public <T extends MessageChangeSet add​(ChangeSet.See see,
                                                 T message)
        Helper function to add a Message to a ChangeSet.
        Type Parameters:
        T - The actual message type.
        Parameters:
        see - The visibility of this change.
        message - The Message to add.
        Returns:
        The updated ChangeSet.
      • addAttack

        public ChangeSet addAttack​(ChangeSet.See see,
                                   Unit attacker,
                                   Unit defender,
                                   boolean success)
        Helper function to add an attack to a ChangeSet.
        Parameters:
        see - The visibility of this change.
        attacker - The Unit that is attacking.
        defender - The Unit that is defending.
        success - Did the attack succeed?
        Returns:
        The updated ChangeSet.
      • addAttribute

        public ChangeSet addAttribute​(ChangeSet.See see,
                                      java.lang.String key,
                                      java.lang.String value)
        Helper function to add a mergeable attribute setting to a ChangeSet.
        Parameters:
        see - The visibility of this change.
        key - A key String.
        value - The corresponding value as a String.
        Returns:
        The updated ChangeSet.
      • addDisappear

        public ChangeSet addDisappear​(Player owner,
                                      Tile tile,
                                      FreeColGameObject fcgo)
        Helper function to add a removal for an object that disappears (that is, moves where it can not be seen) to a ChangeSet.
        Parameters:
        owner - The Player that owns this object.
        tile - The Tile where the object was.
        fcgo - The FreeColGameObject that disappears.
        Returns:
        The updated ChangeSet.
      • addAbility

        public ChangeSet addAbility​(Player player,
                                    FreeColGameObject object,
                                    Ability ability,
                                    boolean add)
        Helper function to add or remove an Ability to a FreeColGameObject.
        Parameters:
        player - The owning Player.
        object - The FreeColGameObject to add to.
        ability - The Ability to add/remove.
        add - If true, add the ability.
        Returns:
        The updated ChangeSet.
      • addModifier

        public ChangeSet addModifier​(Player player,
                                     FreeColGameObject object,
                                     Modifier modifier,
                                     boolean add)
        Helper function to add or remove a Modifier to a FreeColGameObject.
        Parameters:
        player - The owning Player.
        object - The FreeColGameObject to add to.
        modifier - The Modifier to add/remove.
        add - If true, add the modifier.
        Returns:
        The updated ChangeSet.
      • addGlobalHistory

        public ChangeSet addGlobalHistory​(Game game,
                                          HistoryEvent history)
        Helper function to add a global history event to a ChangeSet. Also adds the history to all the European players.
        Parameters:
        game - The Game to find players in.
        history - The HistoryEvent to add.
        Returns:
        The updated ChangeSet.
      • addGlobalMessage

        public ChangeSet addGlobalMessage​(Game game,
                                          Player omit,
                                          ModelMessage message)
        Helper function to add a message to all the European players.
        Parameters:
        game - The Game to find players in.
        omit - An optional Player to omit.
        message - The ModelMessage to add.
        Returns:
        The updated ChangeSet.
      • addHistory

        public ChangeSet addHistory​(Player player,
                                    HistoryEvent history)
        Helper function to add a history event to a ChangeSet. Also adds the history to the owner.
        Parameters:
        player - The Player making history.
        history - The HistoryEvent to add.
        Returns:
        The updated ChangeSet.
      • addMessage

        public ChangeSet addMessage​(Player player,
                                    ModelMessage message)
        Helper function to add a message to a ChangeSet.
        Parameters:
        player - The Player to send the message to.
        message - The ModelMessage to add.
        Returns:
        The updated ChangeSet.
      • addMove

        public ChangeSet addMove​(ChangeSet.See see,
                                 Unit unit,
                                 Location loc,
                                 Tile tile)
        Helper function to add a move to a ChangeSet.
        Parameters:
        see - The visibility of this change.
        unit - The Unit that is moving.
        loc - The location from which the unit is moving.
        tile - The Tile to which the unit is moving.
        Returns:
        The updated ChangeSet.
      • addPartial

        public <T extends FreeColGameObjectChangeSet addPartial​(ChangeSet.See see,
                                                                  T fcgo,
                                                                  java.lang.String... fields)
        Helper function to add a partial update change for an object to a ChangeSet.
        Type Parameters:
        T - The actual type of object to add.
        Parameters:
        see - The visibility of this change.
        fcgo - The FreeColGameObject to update.
        fields - The fields to update.
        Returns:
        The updated ChangeSet.
      • addNewPlayer

        public ChangeSet addNewPlayer​(Player player)
        Helper function to add a new player to a ChangeSet. The added player should not be visible, as this is called pre-game to update other players, but the actual player may not yet even have a Game.
        Parameters:
        player - The new Player to add.
        Returns:
        The updated ChangeSet.
      • addPlayers

        public ChangeSet addPlayers​(java.util.List<? extends Player> players)
        Helper function to add new players to a ChangeSet. Used when adding the AI players en masse, or when adding the REF. No care need be taken with visibility wrt AIs.
        Parameters:
        players - A list of new Players to add.
        Returns:
        The updated ChangeSet.
      • addRemove

        public ChangeSet addRemove​(ChangeSet.See see,
                                   Location loc,
                                   FreeColGameObject obj)
        Helper function to add a removal to a ChangeSet. -vis: If disposing of units or colonies, this routine changes player visibility.
        Parameters:
        see - The visibility of this change.
        loc - The Location where the object was.
        obj - The FreeColGameObject to remove.
        Returns:
        The updated ChangeSet.
      • addRemoves

        public ChangeSet addRemoves​(ChangeSet.See see,
                                    Location loc,
                                    java.util.List<? extends FreeColGameObject> objects)
        Helper function to add removals for several objects to a ChangeSet.
        Parameters:
        see - The visibility of this change.
        loc - The Location where the object was.
        objects - A list of FreeColGameObjects to remove.
        Returns:
        The updated ChangeSet.
      • addSale

        public ChangeSet addSale​(Player player,
                                 Settlement settlement,
                                 GoodsType type,
                                 int price)
        Helper function to add a sale change to a ChangeSet.
        Parameters:
        player - The Player making the sale.
        settlement - The Settlement that is buying.
        type - The GoodsType bought.
        price - The per unit price.
        Returns:
        The updated ChangeSet.
      • addSpy

        public ChangeSet addSpy​(Unit unit,
                                Settlement settlement)
        Helper function to add a spying change to a ChangeSet.
        Parameters:
        unit - The Unit that is spying.
        settlement - The Settlement to spy on.
        Returns:
        The updated ChangeSet.
      • addStance

        public ChangeSet addStance​(ChangeSet.See see,
                                   Player first,
                                   Stance stance,
                                   Player second)
        Helper function to add a stance change to a ChangeSet.
        Parameters:
        see - The visibility of this change.
        first - The Player changing stance.
        stance - The Stance to change to.
        second - The Player wrt with to change.
        Returns:
        The updated ChangeSet.
      • merge

        public void merge​(ChangeSet other)
        Merge a change set into this one.
        Parameters:
        other - The other ChangeSet.
      • build

        public Message build​(Player player)
        Build an update message.
        Parameters:
        player - The Player to send the update to.
        Returns:
        A Message encapsulating an update of the objects to consider, or null if there is nothing to report.
      • clientError

        public static ChangeSet clientError​(Player player,
                                            StringTemplate template)
        Convenience function to create an i18n client error message and wrap it into a change set.
        Parameters:
        player - An optional Player to restrict visibility to.
        template - An i18n template.
        Returns:
        A new ChangeSet.
      • clientError

        public static ChangeSet clientError​(ChangeSet.See see,
                                            StringTemplate template)
        Convenience function to create an i18n client error message and wrap it into a change set.
        Parameters:
        see - The message visibility.
        template - An i18n template.
        Returns:
        A new ChangeSet.
      • clientError

        public static ChangeSet clientError​(Player player,
                                            java.lang.String message)
        Convenience function to create a non-i18n client error message and wrap it into a change set.
        Parameters:
        player - An optional Player to restrict visibility to.
        message - The message.
        Returns:
        A new ChangeSet.
      • clientError

        public static ChangeSet clientError​(ChangeSet.See see,
                                            java.lang.String message)
        Convenience function to create a non-i18n client error message and wrap it into a change set.
        Parameters:
        see - The message visibility.
        message - A non-i18n message.
        Returns:
        A new ChangeSet.
      • simpleChange

        public static ChangeSet simpleChange​(Player player,
                                             Message message)
        Convenience function to create a change set containing a message.
        Parameters:
        player - An optional Player to restrict visibility to.
        message - The Message to wrap.
        Returns:
        A new ChangeSet.
      • simpleChange

        public static ChangeSet simpleChange​(ChangeSet.See see,
                                             Message message)
        Convenience function to create a change set containing a message.
        Parameters:
        see - The message visibility.
        message - The Message to wrap.
        Returns:
        A new ChangeSet.
      • aiChange

        public static ChangeSet aiChange​(Player player,
                                         boolean ai)
        Get a new ChangeSet that changes a player AI state.
        Parameters:
        player - The Player to change.
        ai - The new AI state.
        Returns:
        The new ChangeSet.
      • toString

        public java.lang.String toString()
        Overrides:
        toString in class java.lang.Object