1 package SteeringProperties;
2
3 import SteeringStuff.SteeringType;
4 import XMLSteeringProperties.XMLTargetApproachingProperties;
5 import XMLSteeringProperties.XMLTarget_packet;
6 import cz.cuni.amis.pogamut.base3d.worldview.object.Location;
7 import java.util.ArrayList;
8
9
10
11
12
13
14 public class TargetApproachingProperties extends SteeringProperties {
15
16
17 private ArrayList<Target_packet> targets = new ArrayList<Target_packet>();
18
19 public TargetApproachingProperties() {
20 super(SteeringType.TARGET_APPROACHING);
21 targets.add(new Target_packet());
22 }
23
24 public TargetApproachingProperties(BehaviorType behaviorType) {
25 super(SteeringType.TARGET_APPROACHING, behaviorType);
26 targets.add(new Target_packet());
27 setNewBehaviorType(behaviorType);
28 }
29
30 public TargetApproachingProperties(XMLTargetApproachingProperties xml) {
31 super(SteeringType.TARGET_APPROACHING, xml.active, xml.weight, xml.behavior);
32 for(XMLTarget_packet tp : xml.targets) {
33 targets.add(new Target_packet(tp));
34 }
35 }
36
37 public TargetApproachingProperties(int attractiveForce, Location endLocation) {
38 super(SteeringType.TARGET_APPROACHING);
39 targets.add(new Target_packet(endLocation, new Force_packet(attractiveForce)));
40 }
41
42 protected void setNewBehaviorType(BehaviorType behaviorType) {
43 if (behaviorType.equals(BehaviorType.BASIC)) {
44 Target_packet first = targets.get(0);
45 first.setForce_packet(new Force_packet(first.getAttractiveForce()));
46 targets.clear();
47 targets.add(new Target_packet(first.getTargetLocation(), first.getForce_packet()));
48 }
49 }
50
51
52 public int getAttractiveForce() {
53 if (!targets.isEmpty() && !targets.get(0).getForce_packet().getForcePoints().isEmpty()) {
54 return targets.get(0).getForce_packet().getForcePoints().get(0).forceValue;
55 } else return 100;
56 }
57
58 public void setAttractiveForce(int attractiveForce) {
59 if (!targets.isEmpty() && !targets.get(0).getForce_packet().getForcePoints().isEmpty()) {
60 targets.get(0).getForce_packet().getForcePoints().get(0).forceValue = attractiveForce;
61 }
62 }
63
64 public ArrayList<Target_packet> getTargets() {
65 return targets;
66 }
67
68 public void setTargets(ArrayList<Target_packet> targets) {
69 this.targets = targets;
70 }
71
72 public Target_packet getTarget_packet(int index) {
73 return targets.get(index);
74 }
75
76
77 public void setTarget_packet(int index, Target_packet tp) {
78 if (index >= 0 && index < targets.size()) {
79
80 targets.get(index).setTarget_Packet(tp);
81 }
82 }
83
84
85 public void removeTarget_packet(int index) {
86 if (index >= 0 && index < targets.size()) {
87 targets.remove(index);
88 }
89 }
90
91 public void setTargetLocation(int index, Location loc) {
92 if (index >= 0 && index < targets.size()) {
93 targets.get(index).setTargetLocation(loc);
94 }
95 }
96
97 public void addTarget_packet(Target_packet tp) {
98 targets.add(tp);
99 }
100
101 @Override
102 public String getSpecialText() {
103 String text = "";
104 int index = 0;
105 for(Target_packet t : targets) {
106 text += " * Target Number " + index + ":\n" + t.getSpecialText();
107 index++;
108 }
109 return text;
110 }
111
112 @Override
113 public void setProperties(SteeringProperties newProperties) {
114 this.targets = ((TargetApproachingProperties)newProperties).getTargets();
115 }
116
117 public XMLTargetApproachingProperties getXMLProperties() {
118 XMLTargetApproachingProperties xmlProp = new XMLTargetApproachingProperties();
119 xmlProp.targets = new ArrayList<XMLTarget_packet>();
120 for(Target_packet t : targets) {
121 xmlProp.targets.add(t.getXMLProperties());
122 }
123 xmlProp.active = active;
124 xmlProp.weight = weight;
125 xmlProp.behavior = behaviorType;
126 return xmlProp;
127 }
128 }