-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSignal.java
More file actions
69 lines (49 loc) · 1.59 KB
/
Signal.java
File metadata and controls
69 lines (49 loc) · 1.59 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
package sim.app.birds;
import java.util.Iterator;
import java.util.NoSuchElementException;
import sim.util.*;
import sim.engine.*;
import sim.field.continuous.Continuous2D;
public class Signal implements Steppable {
private Double2D pos;
private double visibility;
private Bird signaller;
public Signal(Bird signaller, Double2D pos, double vis) {
this.signaller = signaller;
this.pos = pos;
this.visibility = vis;
}
public Bird getSignaller() { return signaller; }
public Double2D getPos() { return pos; }
public void setPos(Double2D pos) { this.pos = pos; }
public double getVisibility() { return visibility; }
public void setVisiblity(double vis) { this.visibility = vis; }
public double getRange() {
return sim.app.birds.BirdsModel.STD_SIGNAL_RADIUS * visibility;
}
public void step(SimState state) {
Continuous2D world = ((BirdsModel)state).getWorld();
System.out.println("X: " + pos.getX() + " Range: " + this.getRange());
sim.util.Bag birds = world.getObjectsWithinDistance(pos, this.getRange());
Iterator iter = birds.iterator();
try {
Bird b = (Bird)iter.next();
while( b != null ) {
if( b != signaller )
if( b.respond(this) )
// Only 1 response per signal.
break;
b = (Bird)iter.next();
}
} catch( NoSuchElementException e ) {
}
// Bird[] b = (Bird[])birds.toArray(new Bird[0]);
// try {
// for(int i = 0; i < b.length; i++)
// if( b[i] != signaller )
// b[i].respond(this);
// } catch( NullPointerException e ) {
// System.out.println("Null pointer");
// }
}
}