1 package SteeringProperties;
2
3 import SteeringStuff.SteeringType;
4 import XMLSteeringProperties.XMLLeaderFollowingProperties;
5
6
7
8
9
10 public class LeaderFollowingProperties extends SteeringProperties {
11
12 public enum LFtype {BASIC, FORMATION};
13
14
15 private int leaderForce;
16
17
18 private String leaderName;
19
20
21 private int distance;
22
23
24
25
26
27
28
29
30
31 private int forceDistance;
32
33
34 private LFtype myLFtype;
35
36
37 private boolean deceleration;
38
39
40 private double angleFromTheLeader;
41
42
43 private boolean velocityMemory;
44
45
46 private int sizeOfMemory;
47
48
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;
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;
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
101
102
103
104
105
106
107
108
109
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
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 }