View Javadoc

1   package SteeringProperties;
2   
3   import SteeringStuff.SteeringType;
4   import XMLSteeringProperties.XMLLeaderFollowingProperties;
5   
6   /**
7    * The steering properties of the Leader Following Steering.
8    * @author Marki
9    */
10  public class LeaderFollowingProperties extends SteeringProperties {
11  
12      public enum LFtype {BASIC, FORMATION};
13  
14      /**The magnitude of the force of this steering. (It is used in attractive force to the leader, repulsive force from the leader.)*/
15      private int leaderForce;
16  
17      /**The name of the leader bot.*/
18      private String leaderName;
19  
20      /**The ideal distance from the leader.*/
21      private int distance;
22      
23      /**V této vzdálenosti od ideální pozice bude na agenta působit síla k pozici velikostí leaderForce. O každých forceDistance dál na něj působí síla o leaderForce větší (lineární závislost).
24       * Je-li tato vzdálenost větší, na agenta tedy obecně působí menší síla k pozici. Nemusí se tedy na ni dostat hned, či může být vždy kus za ní. Nicémě jeho pohyb bude plynulejší a lépe se
25       * budou plnit potřeby i dalších steeringů. Je-li tato vzdálenost menší (třeba 80), agentovi se bude lépe dařit být na správné pozici, avšak jeho pohyb bude vrtkavější (více se budou zvelišovat
26       * změny pohybu vůdce apod.) a např. se bude hůře vyhýbat překážkám, neboť OA nebude mít takový vliv. I kdyby měl (např. vyšší váhou), tak pohyb nebude tak plynulý.
27       * Tento parametr funguje stejně pro základní i formační typ. Rozdíl je ovšem v tom, co to je ideální pozice. U základního je to místo na spojnici agenta a vůdce ve vzdálenosti
28       * distanceFromTheLeader od vůdce. U formačního typu je to přesně dané úhlem a opět vzdáleností od vůdce.*/
29  
30      /**At this distance the attractive force to the leader has the magnitude leaderForce.*/
31      private int forceDistance;
32  
33      /**The type of the LF steering. The BASIC type is default. The FORMATION type enables to form simple formations. You can use angl to set the ideal position of the follower.*/
34      private LFtype myLFtype;
35  
36      /**This parameter helps the agent to decelerate, when it is reasonable. Used just in BASIC type. Recommended value is true.*/
37      private boolean deceleration;
38  
39      /**The angle, which sets the position of the follower. The value Math.PI/2 means right from the leader, Matgh.PI behind the leader, -Math.PI left from the leader, 0 in front of the leader, etc.*/
40      private double angleFromTheLeader;
41  
42      /**This parameter help to the more fluent motion in the case of formation type. Recommended value is true.*/
43      private boolean velocityMemory;
44  
45      /**The size of the memory of leaders velocities (in the case of velocityMemory). Recommended value is 5.*/
46      private int sizeOfMemory;
47  
48      /**This parameter helps the agent to go round the leader, if it's reasonable. Just in the case of the FORMATION type. Recommended value is true.*/
49      private boolean circumvention;
50  
51      public LeaderFollowingProperties() {
52          super(SteeringType.LEADER_FOLLOWING);
53          leaderForce = 200;
54          leaderName = "Leader";
55          distance = 300;
56          forceDistance = 50; //200
57          myLFtype = LFtype.BASIC;
58  
59          deceleration = true;
60  
61          angleFromTheLeader = Math.PI;
62          velocityMemory = true;
63          sizeOfMemory = 5;
64          circumvention = true;
65      }
66  
67      public LeaderFollowingProperties(BehaviorType behaviorType) {
68          super(SteeringType.LEADER_FOLLOWING, behaviorType);
69          leaderForce = 200;
70          leaderName = "Leader";
71          distance = 300;
72          forceDistance = 50; //200
73          myLFtype = LFtype.BASIC;
74  
75          deceleration = true;
76  
77          angleFromTheLeader = Math.PI;
78          velocityMemory = true;
79          sizeOfMemory = 5;
80          circumvention = true;
81          setNewBehaviorType(behaviorType);
82      }
83  
84      public LeaderFollowingProperties(XMLLeaderFollowingProperties xml) {
85          super(SteeringType.LEADER_FOLLOWING, xml.active, xml.weight, xml.behavior);
86          leaderForce = xml.leaderForce;
87          leaderName = xml.leaderName;
88          distance = xml.distance;
89          forceDistance = xml.forceDistance;
90          myLFtype = xml.myLFtype;
91          deceleration = xml.deceleration;
92          angleFromTheLeader = xml.angle;
93          velocityMemory = xml.velocityMemory;
94          sizeOfMemory = xml.sizeOfMemory;
95          circumvention = xml.circumvention;
96      }
97  
98      /**
99       * 
100      * @param leaderForce
101      * @param leaderName
102      * @param distanceFromTheLeader
103      * @param forceDistance
104      * @param myLFtype
105      * @param deceleration
106      * @param angleFromTheLeader
107      * @param velocityMemory
108      * @param sizeOfMemory
109      * @param goRound
110      */
111     public LeaderFollowingProperties(int leaderForce, String leaderName, int distanceFromTheLeader, int forceDistance, LFtype myLFtype, boolean deceleration, double angleFromTheLeader, boolean velocityMemory, int sizeOfMemory, boolean goRound) {
112         super(SteeringType.LEADER_FOLLOWING);
113         this.leaderForce = leaderForce;
114         this.leaderName = leaderName;
115         this.distance = distanceFromTheLeader;
116         this.forceDistance = forceDistance;
117         this.myLFtype = myLFtype;
118         this.deceleration = deceleration;
119         this.angleFromTheLeader = angleFromTheLeader;
120         this.velocityMemory = velocityMemory;
121         this.sizeOfMemory = sizeOfMemory;
122         this.circumvention = goRound;
123     }
124 
125     protected void setNewBehaviorType(BehaviorType behaviorType) {
126         if (behaviorType.equals(BehaviorType.BASIC)) {
127             myLFtype = LFtype.BASIC;
128             sizeOfMemory = 0;
129             deceleration = false;
130             velocityMemory = false;
131             circumvention = false;
132         } else if (behaviorType.equals(BehaviorType.ADVANCED)) {
133             myLFtype = LFtype.FORMATION;
134             sizeOfMemory = 5;
135             deceleration = true;
136             velocityMemory = true;
137             circumvention = true;
138         }
139     }
140 
141     public double getAngleFromTheLeader() {
142         return angleFromTheLeader;
143     }
144 
145     /**The angle, which sets the position of the follower. The value Math.PI/2 means right from the leader, Matgh.PI behind the leader, -Math.PI left from the leader, 0 in front of the leader, etc.*/
146     public void setAngleFromTheLeader(double angleFromTheLeader) {
147         this.angleFromTheLeader = angleFromTheLeader;
148     }
149 
150     public int getDistanceFromTheLeader() {
151         return distance;
152     }
153 
154     public void setDistanceFromTheLeader(int distanceFromTheLeader) {
155         this.distance = distanceFromTheLeader;
156     }
157 
158     public int getForceDistance() {
159         return forceDistance;
160     }
161 
162     public void setForceDistance(int forceDistance) {
163         this.forceDistance = forceDistance;
164     }
165 
166     public String getLeaderName() {
167         return leaderName;
168     }
169 
170     public void setLeaderName(String leaderName) {
171         this.leaderName = leaderName;
172     }
173 
174     public int getSizeOfMemory() {
175         return sizeOfMemory;
176     }
177 
178     public void setSizeOfMemory(int sizeOfMemory) {
179         this.sizeOfMemory = sizeOfMemory;
180     }
181 
182     public boolean isVelocityMemory() {
183         return velocityMemory;
184     }
185 
186     public void setVelocityMemory(boolean velocityMemory) {
187         this.velocityMemory = velocityMemory;
188     }
189 
190     public boolean isDeceleration() {
191         return deceleration;
192     }
193 
194     public void setDeceleration(boolean deceleration) {
195         this.deceleration = deceleration;
196     }
197 
198     public boolean isCircumvention() {
199         return circumvention;
200     }
201 
202     public void setCircumvention(boolean circumvention) {
203         this.circumvention = circumvention;
204     }
205 
206     public int getLeaderForce() {
207         return leaderForce;
208     }
209 
210     public void setLeaderForce(int leaderForce) {
211         this.leaderForce = leaderForce;
212     }
213 
214     public LFtype getMyLFtype() {
215         return myLFtype;
216     }
217 
218     public void setMyLFtype(LFtype myLFtype) {
219         this.myLFtype = myLFtype;
220     }
221 
222     @Override
223     public String getSpecialText() {
224         String text = "";
225         text += "  * Leader Force: " + leaderName + "\n";
226         text += "  * Leader: " + leaderName + "\n";
227         text += "  * Distance: " + distance + "\n";
228         text += "  * Force Distance: " + forceDistance + "\n";
229         text += "  * LF type: " + myLFtype + "\n";
230         if (myLFtype.equals(LFtype.BASIC)) {
231             text += "  * Deceleration: " + deceleration + "\n";
232         } else {
233             text += "  * Angle: " + angleFromTheLeader + "\n";
234             text += "  * Memory: " + velocityMemory + "\n";
235             if (velocityMemory) {
236                 text += "  * Memory size: " + sizeOfMemory + "\n";
237             }
238             text += "  * Circumvention: " + circumvention + "\n";
239         }
240         return text;
241     }
242 
243     @Override
244     public void setProperties(SteeringProperties newProperties) {
245         this.leaderForce = ((LeaderFollowingProperties)newProperties).getLeaderForce();
246         this.leaderName = ((LeaderFollowingProperties)newProperties).getLeaderName();
247         this.distance = ((LeaderFollowingProperties)newProperties).getDistanceFromTheLeader();
248         this.forceDistance = ((LeaderFollowingProperties)newProperties).getForceDistance();
249         this.myLFtype = ((LeaderFollowingProperties)newProperties).getMyLFtype();
250         this.deceleration = ((LeaderFollowingProperties)newProperties).isDeceleration();
251         this.angleFromTheLeader = ((LeaderFollowingProperties)newProperties).getAngleFromTheLeader();
252         this.velocityMemory = ((LeaderFollowingProperties)newProperties).isVelocityMemory();
253         this.sizeOfMemory = ((LeaderFollowingProperties)newProperties).getSizeOfMemory();
254         this.circumvention = ((LeaderFollowingProperties)newProperties).isCircumvention();
255     }
256 
257     public XMLLeaderFollowingProperties getXMLProperties() {
258         XMLLeaderFollowingProperties xmlProp = new XMLLeaderFollowingProperties();
259         xmlProp.leaderForce = leaderForce;
260         xmlProp.leaderName = leaderName;
261         xmlProp.distance = distance;
262         xmlProp.forceDistance = forceDistance;
263         xmlProp.myLFtype = myLFtype;
264         xmlProp.deceleration = deceleration;
265         xmlProp.angle = angleFromTheLeader;
266         xmlProp.sizeOfMemory = sizeOfMemory;
267         xmlProp.velocityMemory = velocityMemory;
268         xmlProp.circumvention = circumvention;
269         xmlProp.active = active;
270         xmlProp.weight = weight;
271         xmlProp.behavior = behaviorType;
272         return xmlProp;
273     }
274 }