View Javadoc

1   package nl.tudelft.pogamut.ut2004.agent.module.shooting.weapon;
2   
3   import nl.tudelft.pogamut.ut2004.agent.module.shooting.AbstractWeaponShooting;
4   
5   import cz.cuni.amis.pogamut.ut2004.agent.module.sensomotoric.Weaponry;
6   import cz.cuni.amis.pogamut.ut2004.agent.module.sensor.AgentInfo;
7   import cz.cuni.amis.pogamut.ut2004.agent.module.sensor.WeaponPref;
8   import cz.cuni.amis.pogamut.ut2004.bot.command.ImprovedShooting;
9   import cz.cuni.amis.pogamut.ut2004.bot.impl.UT2004Bot;
10  import cz.cuni.amis.pogamut.ut2004.communication.messages.ItemType;
11  import cz.cuni.amis.pogamut.ut2004.communication.messages.gbinfomessages.Player;
12  
13  /**
14   * Fall back module to handle unknown weapons. Will shoot the primary mode at
15   * visible targets.
16   * 
17   * @author mpkorstanje
18   * 
19   */
20  public class GenericWeaponShooting extends AbstractWeaponShooting {
21  
22  	protected WeaponPref weaponPref;
23  
24  	public GenericWeaponShooting(UT2004Bot<?, ?, ?> agent, AgentInfo info, ImprovedShooting shoot, Weaponry weaponry,
25  			ItemType weapon) {
26  		super(agent, info, shoot, weaponry);
27  		weaponPref = new WeaponPref(weapon);
28  	}
29  
30  
31  	@Override
32  	protected void shoot() {
33  		if(!isWeaponReady()){
34  			return;
35  		}
36  		
37  		// No target, no shoot.
38  		if (!hasTarget()) {
39  			shoot.stopShoot();
40  			return;
41  		}
42  
43  		if (!(target instanceof Player)) {
44  			shoot.shoot(target);
45  			return;
46  		}
47  
48  		Player player = (Player) target;
49  
50  		// Target not visible, hold fire.
51  		if (!player.isVisible()) {
52  			shoot.stopShoot();
53  			return;
54  		} else {
55  			shoot.shoot(target);
56  		}
57  	}
58  
59  	@Override
60  	protected WeaponPref getDefaultWeaponPref() {
61  		return weaponPref;
62  	}
63  
64  }