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.base3d.worldview.object.ILocated;
7 import cz.cuni.amis.pogamut.ut2004.agent.module.sensomotoric.Weaponry;
8 import cz.cuni.amis.pogamut.ut2004.agent.module.sensor.AgentInfo;
9 import cz.cuni.amis.pogamut.ut2004.agent.module.sensor.WeaponPref;
10 import cz.cuni.amis.pogamut.ut2004.agent.module.sensor.WeaponPrefs;
11 import cz.cuni.amis.pogamut.ut2004.bot.command.ImprovedShooting;
12 import cz.cuni.amis.pogamut.ut2004.bot.impl.UT2004Bot;
13 import cz.cuni.amis.pogamut.ut2004.communication.messages.ItemType;
14 import cz.cuni.amis.pogamut.ut2004.communication.messages.gbinfomessages.Player;
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33 public class FlakCannonShooting extends AbstractWeaponShooting {
34
35 protected static final WeaponPref FLAK_CANNON_PRIMARY = new WeaponPref(ItemType.FLAK_CANNON, true);
36
37 protected static final double FLAK_CANON_SECONDARY_PROJECTILE_SPLASH_RADIUS = 400;
38
39 protected static final int FLAK_CANON_SECONDARY_PROJECTILE_DAMAGE = 75;
40
41 public FlakCannonShooting(UT2004Bot<?, ?, ?> agent, AgentInfo info, ImprovedShooting shoot, Weaponry weaponry) {
42 super(agent, info, shoot, weaponry);
43 }
44
45 @Override
46 protected void shoot() {
47
48
49 if (!isWeaponReady()) {
50 return;
51 }
52
53
54 if(!hasTarget()){
55 shoot.stopShooting();
56 return;
57 }
58
59 boolean facing = FacingUtil.isFacing2D(info, target, FACING_ANGLE);
60 boolean safeToShoot = isSafeToShoot(target);
61
62 if (!(target instanceof Player)) {
63 shootLocation(facing, safeToShoot);
64 return;
65 }
66
67 Player player = (Player) target;
68
69
70 if (!player.isVisible()) {
71 shoot.stopShooting();
72 return;
73 }
74
75
76
77 if (facing && safeToShoot) {
78 shoot.shoot(weaponPref, player);
79 }
80
81 else if (facing) {
82 shoot.shootPrimary(player);
83 } else {
84 shoot.stopShooting();
85 }
86 }
87
88 private void shootLocation(boolean facing, boolean safeToShoot) {
89 if (facing && safeToShoot) {
90 shoot.shoot(weaponPref, target);
91 }
92
93
94 else {
95 shoot.stopShooting();
96 }
97 }
98
99
100
101
102
103
104
105
106
107 protected boolean isSafeToShoot(ILocated target) {
108 double distance = info.getLocation().getDistance(target.getLocation());
109 boolean safeDistance = distance > FLAK_CANON_SECONDARY_PROJECTILE_SPLASH_RADIUS;
110 boolean healty = info.getHealth() > FLAK_CANON_SECONDARY_PROJECTILE_DAMAGE;
111
112 return (safeDistance || healty);
113 }
114
115 @Override
116 protected WeaponPref getDefaultWeaponPref() {
117 return FLAK_CANNON_PRIMARY;
118 }
119
120
121 }