View Javadoc

1   package nl.tudelft.pogamut.ut2004.agent.module.shooting.weapon;
2   
3   import nl.tudelft.pogamut.ut2004.agent.module.shooting.AbstractWeaponShooting;
4   import nl.tudelft.pogamut.ut2004.agent.module.shooting.util.FacingUtil;
5   
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   * 
16   * <p>
17   * Module to work efficiently with the lightning gun.
18   * </p>
19   * 
20   * <p>
21   * The lightning gun is merely a point & click weapon so this module does just
22   * that. As the secondary fire mode merely zooms in, it is not used.
23   * </p>
24   * 
25   * TODO: Sort out effects of secondary fire mode on accuracy.
26   * 
27   * 
28   * @author mpkorstanje
29   * 
30   */
31  public class LigthningGunShooting extends AbstractWeaponShooting {
32  
33  	protected static final WeaponPref DEFAULT_WEAPON_PREF = new WeaponPref(ItemType.LIGHTNING_GUN, true);
34  	public LigthningGunShooting(UT2004Bot<?, ?, ?> agent, AgentInfo info, ImprovedShooting shoot, Weaponry weaponry) {
35  		super(agent, info, shoot, weaponry);
36  	}
37  
38  	@Override
39  	protected void shoot() {
40  
41  		// Wrong weapon, wait up.
42  		if (!isWeaponReady()) {
43  			return;
44  		}
45  
46  		// No target, no shoot.
47  		if (!hasTarget()) {
48  			shoot.stopShooting();
49  			return;
50  		}
51  
52  		if (!(target instanceof Player)) {
53  			shoot.shoot(target);
54  			return;
55  
56  		}
57  
58  		Player player = (Player) target;
59  
60  		// Target not visible, hold fire.
61  		if (!player.isVisible() || !FacingUtil.isFacing2D(info, target, FACING_ANGLE)) {
62  			shoot.stopShooting();
63  		} else {
64  			shoot.shoot(target);
65  		}
66  	}
67  
68  	@Override
69  	protected WeaponPref getDefaultWeaponPref() {
70  		return DEFAULT_WEAPON_PREF;
71  	}
72  
73  
74  }