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