1 package SteeringProperties;
2
3 import SteeringStuff.SteeringType;
4 import XMLSteeringProperties.XMLObstacleAvoidanceProperties;
5
6
7
8
9
10 public class ObstacleAvoidanceProperties extends SteeringProperties {
11
12
13
14 private int repulsiveForce;
15
16
17
18
19
20 private int forceOrder;
21
22
23
24
25 private boolean frontCollisions;
26
27
28
29
30
31 private boolean treeCollisions;
32
33
34 public ObstacleAvoidanceProperties() {
35 super(SteeringType.OBSTACLE_AVOIDANCE);
36 repulsiveForce = 240;
37 forceOrder = 1;
38 frontCollisions = true;
39 treeCollisions = true;
40 }
41
42
43 public ObstacleAvoidanceProperties(BehaviorType behaviorType) {
44 super(SteeringType.OBSTACLE_AVOIDANCE, behaviorType);
45 repulsiveForce = 240;
46 forceOrder = 1;
47 frontCollisions = true;
48 treeCollisions = true;
49 setNewBehaviorType(behaviorType);
50 }
51
52
53 public ObstacleAvoidanceProperties(XMLObstacleAvoidanceProperties xml) {
54 super(SteeringType.OBSTACLE_AVOIDANCE, xml.active, xml.weight, xml.behavior);
55 repulsiveForce = xml.repulsiveForce;
56 forceOrder = xml.forceOrder;
57 frontCollisions = xml.frontCollisions;
58 treeCollisions = xml.treeCollisions;
59 }
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77 public ObstacleAvoidanceProperties(int repulsiveForce, int orderOfTheForce, boolean frontCollisions, boolean treeCollisions) {
78 super(SteeringType.OBSTACLE_AVOIDANCE);
79 this.repulsiveForce = repulsiveForce;
80 this.forceOrder = orderOfTheForce;
81 this.frontCollisions = frontCollisions;
82 this.treeCollisions = treeCollisions;
83 }
84
85 protected void setNewBehaviorType(BehaviorType behaviorType) {
86 if (behaviorType.equals(BehaviorType.BASIC)) {
87 frontCollisions = false;
88 treeCollisions = false;
89 } else if (behaviorType.equals(BehaviorType.ADVANCED)) {
90 frontCollisions = true;
91 treeCollisions = true;
92 }
93 }
94
95 public int getRepulsiveForce() {
96 return repulsiveForce;
97 }
98
99 public void setRepulsiveForce(int repulsiveForce) {
100 this.repulsiveForce = repulsiveForce;
101 }
102
103 public int getForceOrder() {
104 return forceOrder;
105 }
106
107 public void setForceOrder(int orderOfTheForce) {
108 this.forceOrder = orderOfTheForce;
109 }
110
111 public boolean isFrontCollisions() {
112 return frontCollisions;
113 }
114
115 public void setFrontCollisions(boolean frontCollisions) {
116 this.frontCollisions = frontCollisions;
117 }
118
119 public boolean isTreeCollisions() {
120 return treeCollisions;
121 }
122
123 public void setTreeCollisions(boolean treeCollisions) {
124 this.treeCollisions = treeCollisions;
125 }
126
127 @Override
128 public String getSpecialText() {
129 String text = "";
130 text += " * Repulsive Force: " + repulsiveForce + "\n";
131 text += " * Force Order: " + forceOrder + "\n";
132 text += " * Front Collisions: " + frontCollisions + "\n";
133 text += " * Tree Collisions: " + treeCollisions + "\n";
134 return text;
135 }
136
137 @Override
138 public void setProperties(SteeringProperties newProperties) {
139 this.repulsiveForce = ((ObstacleAvoidanceProperties)newProperties).getRepulsiveForce();
140 this.forceOrder = ((ObstacleAvoidanceProperties)newProperties).getForceOrder();
141 this.frontCollisions = ((ObstacleAvoidanceProperties)newProperties).isFrontCollisions();
142 this.treeCollisions = ((ObstacleAvoidanceProperties)newProperties).isTreeCollisions();
143 }
144
145 public XMLObstacleAvoidanceProperties getXMLProperties() {
146 XMLObstacleAvoidanceProperties xmlProp = new XMLObstacleAvoidanceProperties();
147 xmlProp.repulsiveForce = repulsiveForce;
148 xmlProp.frontCollisions = frontCollisions;
149 xmlProp.forceOrder = forceOrder;
150 xmlProp.treeCollisions = treeCollisions;
151 xmlProp.active = active;
152 xmlProp.weight = weight;
153 xmlProp.behavior = behaviorType;
154 return xmlProp;
155 }
156 }