View Javadoc

1   package nl.tudelft.pogamut.unreal.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.gbinfomessages.IncomingProjectile;
14  
15  /**
16   * Module to keep track of projectiles.
17   * 
18   * TODO: Horribly inefficient, use listeners.
19   * TODO: Needs ILocated on {@link IncomingProjectile}.
20   * 
21   * @author mpkorstanje
22   *
23   */
24  @SuppressWarnings("rawtypes")
25  public abstract class Projectiles extends SensorModule<UT2004Bot> {
26  
27  	protected AgentInfo info;
28  
29  	public Projectiles(UT2004Bot<?, ?, ?> agent, AgentInfo info) {
30  		super(agent);
31  		this.info = info;
32  		//incomingProjectileListener = new IncomingProjectileListener(worldView);
33  	}
34  
35  
36  	public IncomingProjectile getNearestProjectile() {
37  		return DistanceUtils.getNearest(worldView.getAll(IncomingProjectile.class).values(), info.getLocation());
38  	}
39  
40  
41  	public Map<WorldObjectId, IncomingProjectile> getProjectiles() {
42  		return worldView.getAll(IncomingProjectile.class);
43  	}
44  
45  	public IncomingProjectile getNearestProjectile(ILocated location) {
46  		return DistanceUtils.getNearest(worldView.getAll(IncomingProjectile.class).values(), location);
47  	}
48  
49  	public IncomingProjectile getNearestProjectile(ILocated location, double maxDistance) {
50  		return DistanceUtils.getNearest(worldView.getAll(IncomingProjectile.class).values(), location, maxDistance);
51  	}
52  
53  
54  	public IncomingProjectile getNearestProjectile(ILocated location, ItemType type) {
55  		return DistanceUtils.getNearest(getProjectiles(type), location);
56  	}
57  
58  	public abstract Collection<IncomingProjectile> getProjectiles(final ItemType type);
59  	
60  	
61  	public IncomingProjectile getNearestProjectile(ILocated location, double maxDistance, ItemType type) {
62  		return DistanceUtils.getNearest(getProjectiles(type), location, maxDistance);
63  	}
64  
65  
66  
67  
68  	
69  //	/**
70  //	 * {@link IncomingProjectile} listener.
71  //	 */
72  //	private class IncomingProjectileListener implements IWorldEventListener<IncomingProjectile> {
73  //
74  //		/**
75  //		 * Constructor. Registers itself on the given WorldView object.
76  //		 * 
77  //		 * @param worldView
78  //		 *            WorldView object to listen to.
79  //		 */
80  //		public IncomingProjectileListener(IWorldView worldView) {
81  //			// FIXME: Doesn't work.
82  //
83  //			worldView.addEventListener(IncomingProjectile.class, this);
84  //		}
85  //
86  //		@Override
87  //		public void notify(IncomingProjectile event) {
88  //			projectiles.add(event);
89  //		}
90  //	}
91  //
92  //	/** {@link IncomingProjectile} listener */
93  //	IncomingProjectileListener incomingProjectileListener;
94  
95  }