1 package nl.tudelft.pogamut.ut2004.agent.module.sensor;
2
3 import java.util.Collection;
4 import java.util.Map;
5
6 import cz.cuni.amis.pogamut.base.agent.module.SensorModule;
7 import cz.cuni.amis.pogamut.base.communication.worldview.object.WorldObjectId;
8 import cz.cuni.amis.pogamut.base.utils.math.DistanceUtils;
9 import cz.cuni.amis.pogamut.base3d.worldview.object.ILocated;
10 import cz.cuni.amis.pogamut.ut2004.agent.module.sensor.AgentInfo;
11 import cz.cuni.amis.pogamut.ut2004.bot.impl.UT2004Bot;
12 import cz.cuni.amis.pogamut.ut2004.communication.messages.ItemType;
13 import cz.cuni.amis.pogamut.ut2004.communication.messages.ItemType.Category;
14 import cz.cuni.amis.pogamut.ut2004.communication.messages.gbinfomessages.IncomingProjectile;
15 import cz.cuni.amis.utils.IFilter;
16 import cz.cuni.amis.utils.collections.MyCollections;
17
18
19
20
21
22
23
24
25
26
27 @SuppressWarnings("rawtypes")
28 public class Projectiles extends SensorModule<UT2004Bot> {
29
30 protected AgentInfo info;
31
32 public Projectiles(UT2004Bot<?, ?, ?> agent, AgentInfo info) {
33 super(agent);
34 this.info = info;
35
36 }
37
38
39 public IncomingProjectile getNearestProjectile() {
40 return DistanceUtils.getNearest(worldView.getAll(IncomingProjectile.class).values(), info.getLocation());
41 }
42
43
44 public Map<WorldObjectId, IncomingProjectile> getProjectiles() {
45 return worldView.getAll(IncomingProjectile.class);
46 }
47
48 public IncomingProjectile getNearestProjectile(ILocated location) {
49 return DistanceUtils.getNearest(worldView.getAll(IncomingProjectile.class).values(), location);
50 }
51
52 public IncomingProjectile getNearestProjectile(ILocated location, double maxDistance) {
53 return DistanceUtils.getNearest(worldView.getAll(IncomingProjectile.class).values(), location, maxDistance);
54 }
55
56
57 public IncomingProjectile getNearestProjectile(ILocated location, ItemType type) {
58 return DistanceUtils.getNearest(getProjectiles(type), location);
59 }
60
61 public Collection<IncomingProjectile> getProjectiles(final ItemType type) {
62 if (type == null) return null;
63 if(type.getCategory() != Category.PROJECTILE) return null;
64
65 return MyCollections.getFiltered(worldView.getAll(IncomingProjectile.class).values(), new IFilter<IncomingProjectile>() {
66
67 @Override
68 public boolean isAccepted(IncomingProjectile object) {
69 return type.equals(ItemType.getItemType(object.getType()));
70 }
71 });
72 }
73
74
75 public IncomingProjectile getNearestProjectile(ILocated location, double maxDistance, ItemType type) {
76 return DistanceUtils.getNearest(getProjectiles(type), location, maxDistance);
77 }
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109 }