Package net.sf.freecol.common.networking
Class ChangeSet
- java.lang.Object
-
- net.sf.freecol.common.networking.ChangeSet
-
public class ChangeSet extends java.lang.ObjectChanges to be sent to the client.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description private static classChangeSet.AttackChangeEncapsulate an attack.private static classChangeSet.AttributeChangeEncapsulate an attribute change.static classChangeSet.Change<T extends Message>Abstract template for all types of Change.private static classChangeSet.FeatureChangeEncapsulate a feature change.private static classChangeSet.MessageChange<T extends Message>Encapsulate a Message.private static classChangeSet.MoveChangeEncapsulate a move.private static classChangeSet.ObjectChangeEncapsulate a FreeColGameObject update.private static classChangeSet.PartialObjectChange<T extends FreeColGameObject>Encapsulate a partial update of a FreeColGameObject.private static classChangeSet.PlayerChangeEncapsulate a new player change.private static classChangeSet.RemoveChangeEncapsulates removing some objects.static classChangeSet.SeeClass to control the visibility of a change.private static classChangeSet.SeeCheckResult of a visibility check.private static classChangeSet.SpyChangeEncapsulates a spying action.private static classChangeSet.StanceChangeEncapsulate a stance change.
-
Field Summary
Fields Modifier and Type Field Description private java.util.List<ChangeSet.Change>changesThe changes to send.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description ChangeSetadd(ChangeSet.See see, java.util.Collection<? extends FreeColGameObject> objects)Helper function to add updates for multiple objects to a ChangeSet.ChangeSetadd(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.ChangeSetaddAbility(Player player, FreeColGameObject object, Ability ability, boolean add)Helper function to add or remove an Ability to a FreeColGameObject.ChangeSetaddAttack(ChangeSet.See see, Unit attacker, Unit defender, boolean success)Helper function to add an attack to a ChangeSet.ChangeSetaddAttribute(ChangeSet.See see, java.lang.String key, java.lang.String value)Helper function to add a mergeable attribute setting to a ChangeSet.ChangeSetaddDisappear(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.ChangeSetaddGlobalHistory(Game game, HistoryEvent history)Helper function to add a global history event to a ChangeSet.ChangeSetaddGlobalMessage(Game game, Player omit, ModelMessage message)Helper function to add a message to all the European players.ChangeSetaddHistory(Player player, HistoryEvent history)Helper function to add a history event to a ChangeSet.ChangeSetaddMessage(Player player, ModelMessage message)Helper function to add a message to a ChangeSet.ChangeSetaddModifier(Player player, FreeColGameObject object, Modifier modifier, boolean add)Helper function to add or remove a Modifier to a FreeColGameObject.ChangeSetaddMove(ChangeSet.See see, Unit unit, Location loc, Tile tile)Helper function to add a move to a ChangeSet.ChangeSetaddNewPlayer(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.ChangeSetaddPlayers(java.util.List<? extends Player> players)Helper function to add new players to a ChangeSet.ChangeSetaddRemove(ChangeSet.See see, Location loc, FreeColGameObject obj)Helper function to add a removal to a ChangeSet.ChangeSetaddRemoves(ChangeSet.See see, Location loc, java.util.List<? extends FreeColGameObject> objects)Helper function to add removals for several objects to a ChangeSet.ChangeSetaddSale(Player player, Settlement settlement, GoodsType type, int price)Helper function to add a sale change to a ChangeSet.ChangeSetaddSpy(Unit unit, Settlement settlement)Helper function to add a spying change to a ChangeSet.ChangeSetaddStance(ChangeSet.See see, Player first, Stance stance, Player second)Helper function to add a stance change to a ChangeSet.static ChangeSetaiChange(Player player, boolean ai)Get a new ChangeSet that changes a player AI state.Messagebuild(Player player)Build an update message.voidclear()Clear the current changes.static ChangeSetclientError(Player player, java.lang.String message)Convenience function to create a non-i18n client error message and wrap it into a change set.static ChangeSetclientError(Player player, StringTemplate template)Convenience function to create an i18n client error message and wrap it into a change set.static ChangeSetclientError(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 ChangeSetclientError(ChangeSet.See see, StringTemplate template)Convenience function to create an i18n client error message and wrap it into a change set.booleanisEmpty()Are there changes present?voidmerge(ChangeSet other)Merge a change set into this one.voidremove(FreeColGameObject fcgo)Sometimes we need to backtrack on making a change.static ChangeSetsimpleChange(Player player, Message message)Convenience function to create a change set containing a message.static ChangeSetsimpleChange(ChangeSet.See see, Message message)Convenience function to create a change set containing a message.java.lang.StringtoString()
-
-
-
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 otherChangeSetto 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- AFreeColGameObjectto 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- TheFreeColGameObjects 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- TheFreeColGameObjects 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- TheMessageto 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- TheUnitthat is attacking.defender- TheUnitthat 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- ThePlayerthat owns this object.tile- TheTilewhere the object was.fcgo- TheFreeColGameObjectthat 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- TheFreeColGameObjectto add to.ability- TheAbilityto 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- TheFreeColGameObjectto add to.modifier- TheModifierto 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- TheGameto find players in.history- TheHistoryEventto 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- TheGameto find players in.omit- An optionalPlayerto omit.message- TheModelMessageto 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- ThePlayermaking history.history- TheHistoryEventto add.- Returns:
- The updated
ChangeSet.
-
addMessage
public ChangeSet addMessage(Player player, ModelMessage message)
Helper function to add a message to a ChangeSet.- Parameters:
player- ThePlayerto send the message to.message- TheModelMessageto 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- TheUnitthat is moving.loc- The location from which the unit is moving.tile- TheTileto 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- TheFreeColGameObjectto 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 newPlayerto 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 newPlayers 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- TheLocationwhere the object was.obj- TheFreeColGameObjectto 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- TheLocationwhere the object was.objects- A list ofFreeColGameObjects 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- ThePlayermaking the sale.settlement- TheSettlementthat is buying.type- TheGoodsTypebought.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- TheUnitthat is spying.settlement- TheSettlementto 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- ThePlayerchanging stance.stance- TheStanceto change to.second- ThePlayerwrt 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- ThePlayerto send the update to.- Returns:
- A
Messageencapsulating 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 optionalPlayerto 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 optionalPlayerto 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 optionalPlayerto restrict visibility to.message- TheMessageto 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- TheMessageto 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- ThePlayerto change.ai- The new AI state.- Returns:
- The new
ChangeSet.
-
toString
public java.lang.String toString()
- Overrides:
toStringin classjava.lang.Object
-
-