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 cz.cuni.amis.pogamut.ut2004.agent.module.sensomotoric.Weaponry;
5   import cz.cuni.amis.pogamut.ut2004.agent.module.sensor.AgentInfo;
6   import cz.cuni.amis.pogamut.ut2004.agent.module.sensor.WeaponPref;
7   import cz.cuni.amis.pogamut.ut2004.bot.command.ImprovedShooting;
8   import cz.cuni.amis.pogamut.ut2004.bot.impl.UT2004Bot;
9   import cz.cuni.amis.pogamut.ut2004.communication.messages.ItemType;
10  import cz.cuni.amis.pogamut.ut2004.communication.messages.gbinfomessages.Player;
11  
12  public class MinigunShooting extends AbstractWeaponShooting {
13  
14  	protected static final WeaponPref DEFAULT_WEAPON_PREF = new WeaponPref(ItemType.MINIGUN, true);
15  
16  	public MinigunShooting(UT2004Bot<?, ?, ?> agent, AgentInfo info, ImprovedShooting shoot, Weaponry weaponry) {
17  		super(agent, info, shoot, weaponry);
18  	}
19  
20  	@Override
21  	protected void shoot() {
22  
23  		// Wrong weapon, wait up.
24  		if (!isWeaponReady()) {
25  			return;
26  		}
27  
28  		// No target, no shoot.
29  		if (!hasTarget()) {
30  			shoot.stopShooting();
31  			return;
32  		}
33  
34  		if (!(target instanceof Player)) {
35  			shoot.shoot(target);
36  			return;
37  		}
38  
39  		Player player = (Player) target;
40  
41  		// Target not visible, hold fire.
42  		// Keep firing even if not facing, gives time to spin up minigun.
43  		if (!player.isVisible()) {
44  			shoot.stopShooting();
45  			return;
46  		} else {
47  			shoot.shoot(weaponPref, target);
48  		}
49  	}
50  
51  	@Override
52  	protected WeaponPref getDefaultWeaponPref() {
53  		return DEFAULT_WEAPON_PREF;
54  	}
55  
56  }