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 public ObstacleAvoidanceProperties(int repulsiveForce, int orderOfTheForce, boolean frontCollisions, boolean treeCollisions) {
68 super(SteeringType.OBSTACLE_AVOIDANCE);
69 this.repulsiveForce = repulsiveForce;
70 this.forceOrder = orderOfTheForce;
71 this.frontCollisions = frontCollisions;
72 this.treeCollisions = treeCollisions;
73 }
74
75 protected void setNewBehaviorType(BehaviorType behaviorType) {
76 if (behaviorType.equals(BehaviorType.BASIC)) {
77 frontCollisions = false;
78 treeCollisions = false;
79 } else if (behaviorType.equals(BehaviorType.ADVANCED)) {
80 frontCollisions = true;
81 treeCollisions = true;
82 }
83 }
84
85 public int getRepulsiveForce() {
86 return repulsiveForce;
87 }
88
89 public void setRepulsiveForce(int repulsiveForce) {
90 this.repulsiveForce = repulsiveForce;
91 }
92
93 public int getForceOrder() {
94 return forceOrder;
95 }
96
97 public void setForceOrder(int orderOfTheForce) {
98 this.forceOrder = orderOfTheForce;
99 }
100
101 public boolean isFrontCollisions() {
102 return frontCollisions;
103 }
104
105 public void setFrontCollisions(boolean frontCollisions) {
106 this.frontCollisions = frontCollisions;
107 }
108
109 public boolean isTreeCollisions() {
110 return treeCollisions;
111 }
112
113 public void setTreeCollisions(boolean treeCollisions) {
114 this.treeCollisions = treeCollisions;
115 }
116
117 @Override
118 public String getSpecialText() {
119 String text = "";
120 text += " * Repulsive Force: " + repulsiveForce + "\n";
121 text += " * Force Order: " + forceOrder + "\n";
122 text += " * Front Collisions: " + frontCollisions + "\n";
123 text += " * Tree Collisions: " + treeCollisions + "\n";
124 return text;
125 }
126
127 @Override
128 public void setProperties(SteeringProperties newProperties) {
129 this.repulsiveForce = ((ObstacleAvoidanceProperties)newProperties).getRepulsiveForce();
130 this.forceOrder = ((ObstacleAvoidanceProperties)newProperties).getForceOrder();
131 this.frontCollisions = ((ObstacleAvoidanceProperties)newProperties).isFrontCollisions();
132 this.treeCollisions = ((ObstacleAvoidanceProperties)newProperties).isTreeCollisions();
133 }
134
135 public XMLObstacleAvoidanceProperties getXMLProperties() {
136 XMLObstacleAvoidanceProperties xmlProp = new XMLObstacleAvoidanceProperties();
137 xmlProp.repulsiveForce = repulsiveForce;
138 xmlProp.frontCollisions = frontCollisions;
139 xmlProp.forceOrder = forceOrder;
140 xmlProp.treeCollisions = treeCollisions;
141 xmlProp.active = active;
142 xmlProp.weight = weight;
143 xmlProp.behavior = behaviorType;
144 return xmlProp;
145 }
146 }