View Javadoc

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