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.base3d.worldview.object.ILocated;
6 import cz.cuni.amis.pogamut.base3d.worldview.object.Location;
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.bot.command.ImprovedShooting;
11 import cz.cuni.amis.pogamut.ut2004.bot.impl.UT2004Bot;
12 import cz.cuni.amis.pogamut.ut2004.communication.messages.UT2004ItemType;
13 import cz.cuni.amis.pogamut.ut2004.communication.messages.gbinfomessages.Player;
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37 public class RocketLauncherShooting extends AbstractWeaponShooting {
38
39 protected static final WeaponPref ROCKET_LAUNCHER_PRIMARY = new WeaponPref(UT2004ItemType.ROCKET_LAUNCHER, true);
40
41 protected static final double ROCKET_LAUNCHER_PROJECTILE_SPLASH_RADIUS = 250;
42
43 protected static final int ROCKET_LAUNCHER_PROJECTILE_DAMAGE = 80;
44
45 protected static final int ROCKET_LAUNCHER_THREE_PROJECTILE_DAMAGE = 3 * ROCKET_LAUNCHER_PROJECTILE_DAMAGE;
46
47 protected static final double ROCKET_LAUNCHER_CHARGE_TIME_SECONDS = 1.0;
48
49 protected Location lastLocation = null;
50
51 public RocketLauncherShooting(UT2004Bot<?, ?, ?> agent, AgentInfo info, ImprovedShooting shoot, Weaponry weaponry) {
52 super(agent, info, shoot, weaponry);
53 }
54
55 @Override
56 protected void shoot() {
57
58
59 if (!isWeaponReady()) {
60 return;
61 }
62
63
64 if (!hasTarget()) {
65 shoot.stopShooting();
66 return;
67 }
68
69 boolean facing = FacingUtil.isFacing2D(info, target, FACING_ANGLE);
70 boolean safeToShoot = isSafeToShoot(target);
71
72 if (!(target instanceof Player)) {
73 shootLocation(facing, safeToShoot);
74 return;
75 }
76
77 Player player = (Player) target;
78
79
80 if (!player.isVisible() && info.isSecondaryShooting()) {
81 shoot.shootPrimary(lastLocation.sub(BELOW_PLAYER_OFFSET));
82
83 shoot.stopShooting();
84 return;
85 }
86
87 else if (!player.isVisible()) {
88 shoot.stopShooting();
89 return;
90 }
91
92
93 lastLocation = player.getLocation();
94
95
96
97 if (facing && safeToShoot) {
98 if (weaponPref.isPrimary()) {
99 shoot.shoot(weaponPref, target);
100 } else {
101 shoot.shootSecondaryCharged(target, ROCKET_LAUNCHER_CHARGE_TIME_SECONDS);
102 }
103 } else {
104 shoot.stopShooting();
105 }
106 }
107
108 private void shootLocation(boolean facing, boolean safeToShoot) {
109 if (facing && safeToShoot) {
110 if (weaponPref.isPrimary()) {
111 shoot.shoot(weaponPref, target);
112 } else {
113 shoot.shootSecondaryCharged(target, ROCKET_LAUNCHER_CHARGE_TIME_SECONDS);
114 }
115 } else {
116 shoot.stopShooting();
117 }
118 }
119
120
121
122
123
124
125
126
127
128 protected boolean isSafeToShoot(ILocated target) {
129
130 double distance = info.getLocation().getDistance(target.getLocation());
131 boolean safeDistance = distance > ROCKET_LAUNCHER_PROJECTILE_SPLASH_RADIUS;
132 double damage = weaponPref.isPrimary() ? ROCKET_LAUNCHER_PROJECTILE_DAMAGE
133 : ROCKET_LAUNCHER_THREE_PROJECTILE_DAMAGE;
134 boolean healty = info.getHealth() > damage;
135
136 return (safeDistance || healty);
137 }
138
139 @Override
140 protected WeaponPref getDefaultWeaponPref() {
141 return ROCKET_LAUNCHER_PRIMARY;
142 }
143
144
145 }