T - Type of vector, either 2D or 3D, implementing the Vector interfacepublic class Formation<T extends com.badlogic.gdx.math.Vector<T>>
extends java.lang.Object
Formation coordinates the movement of a group of characters so that they retain some group organization. Characters
belonging to a formation must implement the FormationMember interface. At its simplest, a formation can consist of
moving in a fixed geometric pattern such as a V or line abreast, but it is not limited to that. Formations can also make use of
the environment. Squads of characters can move between cover points using formation steering with only minor modifications, for
example.
Formation motion is used in team sports games, squad-based games, real-time strategy games, and sometimes in first-person shooters, driving games, and action adventures too. It is a simple and flexible technique that is much quicker to write and execute and can produce much more stable behavior than collaborative tactical decision making.
| Modifier and Type | Field and Description |
|---|---|
protected Location<T> |
anchor
The anchor point of this formation.
|
protected FormationMotionModerator<T> |
motionModerator
The formation motion moderator
|
protected FormationPattern<T> |
pattern
The formation pattern
|
protected SlotAssignmentStrategy<T> |
slotAssignmentStrategy
The strategy used to assign a member to his slot
|
| Constructor and Description |
|---|
Formation(Location<T> anchor,
FormationPattern<T> pattern)
Creates a
Formation for the specified pattern using a FreeSlotAssignmentStrategy and no motion
moderator. |
Formation(Location<T> anchor,
FormationPattern<T> pattern,
SlotAssignmentStrategy<T> slotAssignmentStrategy)
Creates a
Formation for the specified pattern and slotAssignmentStrategy using no motion moderator. |
Formation(Location<T> anchor,
FormationPattern<T> pattern,
SlotAssignmentStrategy<T> slotAssignmentStrategy,
FormationMotionModerator<T> motionModerator)
Creates a
Formation for the specified pattern, slotAssignmentStrategy and moderator. |
| Modifier and Type | Method and Description |
|---|---|
boolean |
addMember(FormationMember<T> member)
Adds a new member to the first available slot and updates slot assignments if the number of member is supported by the
current pattern.
|
boolean |
changePattern(FormationPattern<T> pattern)
Changes the pattern of this formation and updates slot assignments if the number of member is supported by the given
pattern.
|
Location<T> |
getAnchorPoint()
Returns the current anchor point of the formation.
|
FormationMotionModerator<T> |
getMotionModerator() |
FormationPattern<T> |
getPattern() |
SlotAssignment<T> |
getSlotAssignmentAt(int index) |
int |
getSlotAssignmentCount() |
SlotAssignmentStrategy<T> |
getSlotAssignmentStrategy() |
void |
removeMember(FormationMember<T> member)
Removes a member from its slot and updates slot assignments.
|
void |
setAnchorPoint(Location<T> anchor)
Sets the anchor point of the formation.
|
void |
setMotionModerator(FormationMotionModerator<T> motionModerator)
Sets the motion moderator of this formation
|
void |
setPattern(FormationPattern<T> pattern)
Sets the pattern of this formation
|
void |
setSlotAssignmentStrategy(SlotAssignmentStrategy<T> slotAssignmentStrategy)
Sets the slot assignment strategy of this formation
|
void |
updateSlotAssignments()
Updates the assignment of members to slots
|
void |
updateSlots()
Writes new slot locations to each member
|
protected Location<T extends com.badlogic.gdx.math.Vector<T>> anchor
protected FormationPattern<T extends com.badlogic.gdx.math.Vector<T>> pattern
protected SlotAssignmentStrategy<T extends com.badlogic.gdx.math.Vector<T>> slotAssignmentStrategy
protected FormationMotionModerator<T extends com.badlogic.gdx.math.Vector<T>> motionModerator
public Formation(Location<T> anchor, FormationPattern<T> pattern)
Formation for the specified pattern using a FreeSlotAssignmentStrategy and no motion
moderator.anchor - the anchor point of this formation, usually a Steerable. Cannot be null.pattern - the pattern of this formationjava.lang.IllegalArgumentException - if the anchor point is nullpublic Formation(Location<T> anchor, FormationPattern<T> pattern, SlotAssignmentStrategy<T> slotAssignmentStrategy)
Formation for the specified pattern and slotAssignmentStrategy using no motion moderator.anchor - the anchor point of this formation, usually a Steerable. Cannot be null.pattern - the pattern of this formationslotAssignmentStrategy - the strategy used to assign a member to his slotjava.lang.IllegalArgumentException - if the anchor point is nullpublic Formation(Location<T> anchor, FormationPattern<T> pattern, SlotAssignmentStrategy<T> slotAssignmentStrategy, FormationMotionModerator<T> motionModerator)
Formation for the specified pattern, slotAssignmentStrategy and moderator.anchor - the anchor point of this formation, usually a Steerable. Cannot be null.pattern - the pattern of this formationslotAssignmentStrategy - the strategy used to assign a member to his slotmotionModerator - the motion moderator. Can be null if moderation is not neededjava.lang.IllegalArgumentException - if the anchor point is nullpublic Location<T> getAnchorPoint()
public void setAnchorPoint(Location<T> anchor)
anchor - the anchor point to setpublic FormationPattern<T> getPattern()
public void setPattern(FormationPattern<T> pattern)
pattern - the pattern to setpublic SlotAssignmentStrategy<T> getSlotAssignmentStrategy()
public void setSlotAssignmentStrategy(SlotAssignmentStrategy<T> slotAssignmentStrategy)
slotAssignmentStrategy - the slot assignment strategy to setpublic FormationMotionModerator<T> getMotionModerator()
public void setMotionModerator(FormationMotionModerator<T> motionModerator)
motionModerator - the motion moderator to setpublic void updateSlotAssignments()
public boolean changePattern(FormationPattern<T> pattern)
pattern - the pattern to settrue if the pattern has effectively changed; false otherwise.public boolean addMember(FormationMember<T> member)
member - the member to addfalse if no more slots are available; true otherwise.public void removeMember(FormationMember<T> member)
member - the member to removepublic SlotAssignment<T> getSlotAssignmentAt(int index)
public int getSlotAssignmentCount()
public void updateSlots()