1 package Steerings;
2
3 import SocialSteeringsBeta.RefLocation;
4 import SteeringStuff.SteeringManager;
5 import SteeringStuff.RefBoolean;
6 import SteeringProperties.SteeringProperties;
7 import SteeringProperties.TargetApproachingProperties;
8 import SteeringProperties.Target_packet;
9 import cz.cuni.amis.pogamut.base3d.worldview.object.Location;
10 import javax.vecmath.Vector3d;
11 import cz.cuni.amis.pogamut.ut2004.bot.impl.UT2004Bot;
12 import SteeringStuff.ISteering;
13 import java.util.ArrayList;
14 import javax.vecmath.Tuple3d;
15
16
17
18
19
20
21
22 public class TargetApproachingSteer implements ISteering {
23
24
25 private UT2004Bot botself;
26
27 private ArrayList<Target_packet> targets = new ArrayList<Target_packet>();
28
29 private static int NEARLY_THERE_DISTANCE = 150;
30
31
32
33
34 public TargetApproachingSteer(UT2004Bot bot) {
35 botself = bot;
36 }
37
38
39 @Override
40 public Vector3d run(Vector3d scaledActualVelocity, RefBoolean wantsToGoFaster, RefBoolean wantsToStop, RefLocation focus)
41 {
42
43 Vector3d nextVelocity = new Vector3d(0,0,0);
44
45 for(Target_packet tp : targets) {
46
47
48 Location targetLocation = tp.getTargetLocation();
49
50
51 Vector3d vectorToTarget = new Vector3d(targetLocation.x - botself.getLocation().x, targetLocation.y - botself.getLocation().y, 0);
52
53 double distFromTarget = vectorToTarget.length();
54
55
56 int attractiveForce = tp.getAttractiveForce(distFromTarget);
57
58 if (distFromTarget < NEARLY_THERE_DISTANCE) {
59 wantsToStop.setValue(true);
60
61 } else {
62 vectorToTarget.normalize();
63 vectorToTarget.scale(attractiveForce);
64 nextVelocity.add((Tuple3d) vectorToTarget);
65 }
66 }
67 wantsToGoFaster.setValue(true);
68 return nextVelocity;
69 }
70
71 public void setProperties(SteeringProperties newProperties) {
72 ArrayList<Target_packet> al = ((TargetApproachingProperties)newProperties).getTargets();
73 targets.clear();
74 for(Target_packet tp : al) {
75 targets.add(new Target_packet(tp.getTargetLocation(), tp.getForce_packet()));
76 }
77 }
78
79 public TargetApproachingProperties getProperties() {
80 TargetApproachingProperties properties = new TargetApproachingProperties();
81 properties.setTargets(targets);
82 return properties;
83 }
84
85 }