View Javadoc

1   package SteeringProperties;
2   
3   import XMLSteeringProperties.XMLTarget_packet;
4   import cz.cuni.amis.pogamut.base3d.worldview.object.Location;
5   
6   /**
7    * This is one packet of the location and it's definition of force. The class TargetApproachingProperties uses this Target_packet.
8    * @author Marki
9    */
10  public class Target_packet {
11  
12      /**The target location. Bot is attracted to or repulsed from this location - accordingly to the force, which is defined in the force_packet.*/
13      private Location targetLocation;
14      
15      /**this packet contains the whole function of the force to the target.*/
16      private Force_packet force_packet;
17  
18      public Target_packet() {
19          force_packet = new Force_packet(100);
20          targetLocation = new Location(9440,-10500,-3446.65); //At the edge.
21      }
22  
23      public Target_packet(XMLTarget_packet xml_packet) {
24          force_packet = new Force_packet(xml_packet.force_packet);
25          targetLocation = new Location(xml_packet.xTargetLocation,xml_packet.yTargetLocation,xml_packet.zTargetLocation);
26      }
27  
28      public Target_packet(Location targetLocation, Force_packet force_packet) {
29          this.targetLocation = targetLocation;
30          this.force_packet = force_packet;
31      }
32  
33      public Location getTargetLocation() {
34          return targetLocation;
35      }
36  
37      public void setTargetLocation(Location endLocation) {
38          this.targetLocation = endLocation;
39      }
40  
41      public void setTarget_Packet(Target_packet tp) {
42          if (!this.equals(tp)) {
43              if (!this.force_packet.equals(tp.force_packet)) {
44                  this.force_packet.setForcePacket(tp.force_packet);
45              }
46              this.targetLocation = tp.targetLocation;
47          }
48      }
49  
50      public Force_packet getForce_packet() {
51          return force_packet;
52      }
53  
54      public void setForce_packet(Force_packet f_packet) {
55          if (!this.force_packet.equals(f_packet)) {
56              this.force_packet.setForcePacket(f_packet);
57          }
58      }
59  
60      public int getAttractiveForce(double distance) {
61          return force_packet.getValueOfTheDistance(distance);
62      }
63  
64      /**Sets the attractive force at the distance 0.*/
65      public void setAttractiveForce(int force) {
66          force_packet.getForcePoints().get(0).forceValue = force;
67      }
68  
69      /**Returns the attractive force at the distance 0.*/
70      public int getAttractiveForce() {
71          if (force_packet.getForcePoints().size() > 0) return force_packet.getForcePoints().get(0).forceValue;
72          else {
73              return 0;
74          }
75      }
76  
77      public String getSpecialText() {
78          String result = "";
79          result += "  * Target Location: " + targetLocation.toString() + "\n";
80          result += force_packet.getSpecialText();
81          return result;
82      }
83  
84      public XMLTarget_packet getXMLProperties() {
85          XMLTarget_packet xmlProp = new XMLTarget_packet();
86          xmlProp.force_packet = force_packet.getXMLForce_packet();
87          xmlProp.xTargetLocation = (int) targetLocation.x;
88          xmlProp.yTargetLocation = (int) targetLocation.y;
89          xmlProp.zTargetLocation = (int) targetLocation.z;
90          return xmlProp;
91      }
92  }