View Javadoc

1   package nl.tudelft.pogamut.unreal.agent.module.shooting.weapon;
2   
3   
4   import nl.tudelft.pogamut.unreal.agent.module.shooting.AbstractWeaponShooting;
5   import nl.tudelft.pogamut.unreal.agent.module.shooting.util.FacingUtil;
6   import cz.cuni.amis.pogamut.ut2004.agent.module.sensomotoric.Weaponry;
7   import cz.cuni.amis.pogamut.ut2004.agent.module.sensor.AgentInfo;
8   import cz.cuni.amis.pogamut.ut2004.agent.module.sensor.WeaponPref;
9   import cz.cuni.amis.pogamut.ut2004.bot.command.ImprovedShooting;
10  import cz.cuni.amis.pogamut.ut2004.bot.impl.UT2004Bot;
11  import cz.cuni.amis.pogamut.ut2004.communication.messages.ItemType;
12  import cz.cuni.amis.pogamut.ut2004.communication.messages.gbinfomessages.Player;
13  
14  /**
15   * Fall back module to handle unknown weapons. Will shoot the primary mode at
16   * visible targets.
17   * 
18   * @author mpkorstanje
19   * 
20   */
21  public class GenericWeaponShooting extends AbstractWeaponShooting {
22  
23  	protected WeaponPref weaponPref;
24  
25  	public GenericWeaponShooting(UT2004Bot<?, ?, ?> agent, AgentInfo info, ImprovedShooting shoot, Weaponry weaponry,
26  			ItemType weapon) {
27  		super(agent, info, shoot, weaponry);
28  		weaponPref = new WeaponPref(weapon);
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.stopShooting();
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() || !FacingUtil.isFacing2D(info, target, FACING_ANGLE)) {
52  			shoot.stopShooting();
53  			return;
54  		} else {
55  			shoot.shoot(target);
56  		}
57  	}
58  
59  	@Override
60  	protected WeaponPref getDefaultWeaponPref() {
61  		return weaponPref;
62  	}
63  
64  }