Package net.sf.freecol.common.networking
Class ChangeSet
- java.lang.Object
-
- net.sf.freecol.common.networking.ChangeSet
-
public class ChangeSet extends java.lang.Object
Changes to be sent to the client.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description private static class
ChangeSet.AttackChange
Encapsulate an attack.private static class
ChangeSet.AttributeChange
Encapsulate an attribute change.static class
ChangeSet.Change<T extends Message>
Abstract template for all types of Change.private static class
ChangeSet.FeatureChange
Encapsulate a feature change.private static class
ChangeSet.MessageChange<T extends Message>
Encapsulate a Message.private static class
ChangeSet.MoveChange
Encapsulate a move.private static class
ChangeSet.ObjectChange
Encapsulate a FreeColGameObject update.private static class
ChangeSet.PartialObjectChange<T extends FreeColGameObject>
Encapsulate a partial update of a FreeColGameObject.private static class
ChangeSet.PlayerChange
Encapsulate a new player change.private static class
ChangeSet.RemoveChange
Encapsulates removing some objects.static class
ChangeSet.See
Class to control the visibility of a change.private static class
ChangeSet.SeeCheck
Result of a visibility check.private static class
ChangeSet.SpyChange
Encapsulates a spying action.private static class
ChangeSet.StanceChange
Encapsulate a stance change.
-
Field Summary
Fields Modifier and Type Field Description private java.util.List<ChangeSet.Change>
changes
The changes to send.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description ChangeSet
add(ChangeSet.See see, java.util.Collection<? extends FreeColGameObject> objects)
Helper function to add updates for multiple objects to a ChangeSet.ChangeSet
add(ChangeSet.See see, FreeColGameObject... objects)
Helper function to add updates for multiple objects to a ChangeSet.<T extends Message>
ChangeSetadd(ChangeSet.See see, T message)
Helper function to add a Message to a ChangeSet.ChangeSet
addAbility(Player player, FreeColGameObject object, Ability ability, boolean add)
Helper function to add or remove an Ability to a FreeColGameObject.ChangeSet
addAttack(ChangeSet.See see, Unit attacker, Unit defender, boolean success)
Helper function to add an attack to a ChangeSet.ChangeSet
addAttribute(ChangeSet.See see, java.lang.String key, java.lang.String value)
Helper function to add a mergeable attribute setting to a ChangeSet.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.ChangeSet
addGlobalHistory(Game game, HistoryEvent history)
Helper function to add a global history event to a ChangeSet.ChangeSet
addGlobalMessage(Game game, Player omit, ModelMessage message)
Helper function to add a message to all the European players.ChangeSet
addHistory(Player player, HistoryEvent history)
Helper function to add a history event to a ChangeSet.ChangeSet
addMessage(Player player, ModelMessage message)
Helper function to add a message to a ChangeSet.ChangeSet
addModifier(Player player, FreeColGameObject object, Modifier modifier, boolean add)
Helper function to add or remove a Modifier to a FreeColGameObject.ChangeSet
addMove(ChangeSet.See see, Unit unit, Location loc, Tile tile)
Helper function to add a move to a ChangeSet.ChangeSet
addNewPlayer(Player player)
Helper function to add a new player to a ChangeSet.<T extends FreeColGameObject>
ChangeSetaddPartial(ChangeSet.See see, T fcgo, java.lang.String... fields)
Helper function to add a partial update change for an object to a ChangeSet.ChangeSet
addPlayers(java.util.List<? extends Player> players)
Helper function to add new players to a ChangeSet.ChangeSet
addRemove(ChangeSet.See see, Location loc, FreeColGameObject obj)
Helper function to add a removal to a ChangeSet.ChangeSet
addRemoves(ChangeSet.See see, Location loc, java.util.List<? extends FreeColGameObject> objects)
Helper function to add removals for several objects to a ChangeSet.ChangeSet
addSale(Player player, Settlement settlement, GoodsType type, int price)
Helper function to add a sale change to a ChangeSet.ChangeSet
addSpy(Unit unit, Settlement settlement)
Helper function to add a spying change to a ChangeSet.ChangeSet
addStance(ChangeSet.See see, Player first, Stance stance, Player second)
Helper function to add a stance change to a ChangeSet.static ChangeSet
aiChange(Player player, boolean ai)
Get a new ChangeSet that changes a player AI state.Message
build(Player player)
Build an update message.void
clear()
Clear the current changes.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.static ChangeSet
clientError(Player player, StringTemplate template)
Convenience function to create an i18n client error message and wrap it into a change set.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.static ChangeSet
clientError(ChangeSet.See see, StringTemplate template)
Convenience function to create an i18n client error message and wrap it into a change set.boolean
isEmpty()
Are there changes present?void
merge(ChangeSet other)
Merge a change set into this one.void
remove(FreeColGameObject fcgo)
Sometimes we need to backtrack on making a change.static ChangeSet
simpleChange(Player player, Message message)
Convenience function to create a change set containing a message.static ChangeSet
simpleChange(ChangeSet.See see, Message message)
Convenience function to create a change set containing a message.java.lang.String
toString()
-
-
-
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 otherChangeSet
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
- AFreeColGameObject
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
- TheFreeColGameObject
s 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
- TheFreeColGameObject
s that changed.- Returns:
- The updated
ChangeSet
.
-
add
public <T extends Message> ChangeSet 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
- TheMessage
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
- TheUnit
that is attacking.defender
- TheUnit
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 keyString
.value
- The corresponding value as aString
.- 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
- ThePlayer
that owns this object.tile
- TheTile
where the object was.fcgo
- TheFreeColGameObject
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 owningPlayer
.object
- TheFreeColGameObject
to add to.ability
- TheAbility
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 owningPlayer
.object
- TheFreeColGameObject
to add to.modifier
- TheModifier
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
- TheGame
to find players in.history
- TheHistoryEvent
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
- TheGame
to find players in.omit
- An optionalPlayer
to omit.message
- TheModelMessage
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
- ThePlayer
making history.history
- TheHistoryEvent
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
- ThePlayer
to send the message to.message
- TheModelMessage
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
- TheUnit
that is moving.loc
- The location from which the unit is moving.tile
- TheTile
to which the unit is moving.- Returns:
- The updated
ChangeSet
.
-
addPartial
public <T extends FreeColGameObject> ChangeSet 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
- TheFreeColGameObject
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 newPlayer
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 newPlayer
s 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
- TheLocation
where the object was.obj
- TheFreeColGameObject
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
- TheLocation
where the object was.objects
- A list ofFreeColGameObject
s 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
- ThePlayer
making the sale.settlement
- TheSettlement
that is buying.type
- TheGoodsType
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
- TheUnit
that is spying.settlement
- TheSettlement
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
- ThePlayer
changing stance.stance
- TheStance
to change to.second
- ThePlayer
wrt with to change.- Returns:
- The updated
ChangeSet
.
-
merge
public void merge(ChangeSet other)
Merge a change set into this one.- Parameters:
other
- The otherChangeSet
.
-
build
public Message build(Player player)
Build an update message.- Parameters:
player
- ThePlayer
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 optionalPlayer
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 optionalPlayer
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 optionalPlayer
to restrict visibility to.message
- TheMessage
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
- TheMessage
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
- ThePlayer
to change.ai
- The new AI state.- Returns:
- The new
ChangeSet
.
-
toString
public java.lang.String toString()
- Overrides:
toString
in classjava.lang.Object
-
-