View Javadoc

1   package SteeringProperties;
2   
3   import SteeringStuff.SteeringType;
4   import XMLSteeringProperties.XMLPeopleAvoidanceProperties;
5   
6   /**
7    * The steering properties of the People Avoidance Steering.
8    * @author Marki
9    */
10  public class PeopleAvoidanceProperties extends SteeringProperties {
11  
12      /**Steering properties: the magnitude of the repulsive force from other agents.
13       * Reasonable values are 0 - 1000, the default value is 200.*/
14      
15      private int repulsiveForce;
16      /**Steering properties: the ideal distance from other people.
17       * Reasonable values are 0 - 2000, the default value is 300.
18       * The steering doesn't guarantee that other agents won't get closer,
19       * but if they get, the agent will be repulsed from them.*/
20      private int distance;
21  
22      /**This parameter causes that agent is able to go round other agent, if it's reasonable. Recommended value is true.*/
23      private boolean circumvention;
24  
25      /**This parameter causes that agent is able to decelerate, if it's reasonable. Recommended value is true.*/
26      private boolean deceleration;
27  
28      /**This parameter causes that agent is able to accelerate, if it's reasonable. Recommended value is true.*/
29      private boolean acceleration;
30  
31      /**The projection is used in the case of the parameters circumvention, deceleration and acceleration. The motion is projection ahead for projection ticks.*/
32      private double projection;
33  
34      public PeopleAvoidanceProperties() {
35          super(SteeringType.PEOPLE_AVOIDANCE);
36          this.repulsiveForce = 200;
37          this.distance = 300;
38          this.circumvention = false;
39          this.deceleration = false;
40          this.acceleration = false;
41          this.projection = 16;
42      }
43  
44      public PeopleAvoidanceProperties(BehaviorType behaviorType) {
45          super(SteeringType.PEOPLE_AVOIDANCE, behaviorType);
46          this.repulsiveForce = 200;
47          this.distance = 300;
48          this.circumvention = false;
49          this.deceleration = false;
50          this.acceleration = false;
51          this.projection = 16;
52          setNewBehaviorType(behaviorType);
53      }
54  
55      public PeopleAvoidanceProperties(XMLPeopleAvoidanceProperties xml) {
56          super(SteeringType.PEOPLE_AVOIDANCE, xml.active, xml.weight, xml.behavior);
57          this.repulsiveForce = xml.repulsiveForce;
58          this.distance = xml.distance;
59          this.circumvention = xml.circumvention;
60          this.deceleration = xml.deceleration;
61          this.acceleration = xml.acceleration;
62          this.projection = xml.projection;
63      }
64  
65      public PeopleAvoidanceProperties(int forceFromOtherPeople, int distanceFromOtherPeople, boolean goRoundPartner, boolean deceleration, boolean acceleration, double visionInTicks) {
66          super(SteeringType.PEOPLE_AVOIDANCE);
67          this.repulsiveForce = forceFromOtherPeople;
68          this.distance = distanceFromOtherPeople;
69          this.circumvention = goRoundPartner;
70          this.deceleration = false;
71          this.acceleration = false;
72          this.projection = visionInTicks;
73      }
74  
75      protected void setNewBehaviorType(BehaviorType behaviorType) {
76          if (behaviorType.equals(BehaviorType.BASIC)) {
77              circumvention = false;
78              deceleration = false;
79              acceleration = false;
80              projection = 0;
81          }
82          else if (behaviorType.equals(BehaviorType.ADVANCED)) {
83              circumvention = true;
84              deceleration = true;
85              acceleration = true;
86              projection = 16;
87          }
88      }
89  
90      public int getRepulsiveForce() {
91          return repulsiveForce;
92      }
93  
94      public void setRepulsiveForce(int orderOfTheForce) {
95          this.repulsiveForce = orderOfTheForce;
96      }
97  
98      public int getDistanceFromOtherPeople() {
99          return distance;
100     }
101 
102     public void setDistanceFromOtherPeople(int distanceFromOtherPeople) {
103         this.distance = distanceFromOtherPeople;
104     }
105 
106     public boolean isCircumvention() {
107         return circumvention;
108     }
109 
110     public void setCircumvention(boolean goRoundPartner) {
111         this.circumvention = goRoundPartner;
112     }
113 
114     /**
115      *
116      * @return projection in ticks (how many ticks ahead we anticipate).
117      */
118     public double getProjection() {
119         return projection;
120     }
121 
122     /**
123      * Sets the projection - how many tick ahead we anticipate.
124      * @param projection
125      */
126     public void setProjection(double projection) {
127         this.projection = projection;
128     }
129 
130     public boolean isAcceleration() {
131         return acceleration;
132     }
133 
134     public void setAcceleration(boolean acceleration) {
135         this.acceleration = acceleration;
136     }
137 
138     public boolean isDeceleration() {
139         return deceleration;
140     }
141 
142     public void setDeceleration(boolean deceleration) {
143         this.deceleration = deceleration;
144     }
145 
146     @Override
147     public String getSpecialText() {
148         String text = "";
149         text += "  * Repulsive Force: " + repulsiveForce + "\n";
150         text += "  * Distance: " + distance + "\n";
151         text += "  * Circumvention: " + circumvention + "\n";
152         text += "  * Deceleration: " + deceleration + "\n";
153         text += "  * Acceleration: " + deceleration + "\n";
154         text += "  * Projection: " + projection + "\n";
155         return text;
156     }
157 
158     @Override
159     public void setProperties(SteeringProperties newProperties) {
160         this.repulsiveForce = ((PeopleAvoidanceProperties)newProperties).getRepulsiveForce();
161         this.distance = ((PeopleAvoidanceProperties)newProperties).getDistanceFromOtherPeople();
162         this.circumvention = ((PeopleAvoidanceProperties)newProperties).isCircumvention();
163         this.deceleration = ((PeopleAvoidanceProperties)newProperties).isDeceleration();
164         this.acceleration = ((PeopleAvoidanceProperties)newProperties).isAcceleration();
165         this.projection = ((PeopleAvoidanceProperties)newProperties).getProjection();
166     }
167     
168     public XMLPeopleAvoidanceProperties getXMLProperties() {
169         XMLPeopleAvoidanceProperties xmlProp = new XMLPeopleAvoidanceProperties();
170         xmlProp.repulsiveForce = repulsiveForce;
171         xmlProp.distance = distance;
172         xmlProp.circumvention = circumvention;
173         xmlProp.deceleration = deceleration;
174         xmlProp.acceleration = acceleration;
175         xmlProp.projection = projection;
176         xmlProp.active = active;
177         xmlProp.weight = weight;
178         xmlProp.behavior = behaviorType;
179         return xmlProp;
180     }
181 }