View Javadoc

1   package nl.tudelft.pogamut.ut2004.agent.module.sensor;
2   
3   import java.util.Collection;
4   import nl.tudelft.pogamut.unreal.agent.module.sensor.Projectiles;
5   import cz.cuni.amis.pogamut.ut2004.agent.module.sensor.AgentInfo;
6   import cz.cuni.amis.pogamut.ut2004.bot.impl.UT2004Bot;
7   import cz.cuni.amis.pogamut.ut2004.communication.messages.ItemType;
8   import cz.cuni.amis.pogamut.ut2004.communication.messages.ItemType.Category;
9   import cz.cuni.amis.pogamut.ut2004.communication.messages.UT2004ItemType;
10  import cz.cuni.amis.pogamut.ut2004.communication.messages.gbinfomessages.IncomingProjectile;
11  import cz.cuni.amis.utils.IFilter;
12  import cz.cuni.amis.utils.collections.MyCollections;
13  
14  /**
15   * Module to keep track of projectiles.
16   * 
17   * TODO: Horribly inefficient, use listeners. TODO: Needs ILocated on
18   * {@link IncomingProjectile}.
19   * 
20   * @author mpkorstanje
21   * 
22   */
23  public class UT2004Projectiles extends Projectiles {
24  
25  	protected AgentInfo info;
26  
27  	public UT2004Projectiles(UT2004Bot<?, ?, ?> agent, AgentInfo info) {
28  		super(agent, info);
29  		this.info = info;
30  	}
31  
32  	public Collection<IncomingProjectile> getProjectiles(final ItemType type) {
33  		if (type == null)
34  			return null;
35  		if (type.getCategory() != Category.PROJECTILE)
36  			return null;
37  
38  		return MyCollections.getFiltered(
39  				worldView.getAll(IncomingProjectile.class).values(),
40  				new IFilter<IncomingProjectile>() {
41  
42  					@Override
43  					public boolean isAccepted(IncomingProjectile object) {
44  						return type.equals(UT2004ItemType.getItemType(object
45  								.getType()));
46  					}
47  				});
48  	}
49  
50  }