81 if (
missile.getSource() ==
null)
return;
83 ShipAPI source =
missile.getSource();
89 float sourceRejoin = source.getCollisionRadius() + 200f;
91 float sourceRepel = source.getCollisionRadius() + 50f;
92 float sourceCohesion = source.getCollisionRadius() + 600f;
94 float sin = (float) Math.sin(
data.elapsed * 1f);
95 float mult = 1f + sin * 0.25f;
98 Vector2f total =
new Vector2f();
101 if (attractor !=
null) {
102 float dist = Misc.getDistance(
missile.getLocation(), attractor);
103 Vector2f dir = Misc.getUnitVectorAtDegreeAngle(Misc.getAngleInDegrees(
missile.getLocation(), attractor));
104 float f = dist / 200f;
107 Vector2f.add(total, dir, total);
112 boolean hardAvoiding =
false;
114 float dist = Misc.getDistance(
missile.getLocation(), other.getLocation());
115 float hardAvoidRange = other.getCollisionRadius() + avoidRange + 50f;
116 if (dist < hardAvoidRange) {
117 Vector2f dir = Misc.getUnitVectorAtDegreeAngle(Misc.getAngleInDegrees(other.getLocation(),
missile.getLocation()));
118 float f = 1f - dist / (hardAvoidRange);
120 Vector2f.add(total, dir, total);
121 hardAvoiding = f > 0.5f;
127 for (MissileAPI otherMissile :
data.motes) {
128 if (otherMissile ==
missile)
continue;
130 float dist = Misc.getDistance(
missile.getLocation(), otherMissile.getLocation());
133 float w = otherMissile.getMaxHitpoints();
136 float currCohesionRange = cohesionRange;
138 if (dist < avoidRange && otherMissile !=
missile && !hardAvoiding) {
139 Vector2f dir = Misc.getUnitVectorAtDegreeAngle(Misc.getAngleInDegrees(otherMissile.getLocation(),
missile.getLocation()));
140 float f = 1f - dist / avoidRange;
142 Vector2f.add(total, dir, total);
145 if (dist < currCohesionRange) {
146 Vector2f dir =
new Vector2f(otherMissile.getVelocity());
148 float f = 1f - dist / currCohesionRange;
150 Vector2f.add(total, dir, total);
162 if (
missile.getSource() !=
null) {
163 float dist = Misc.getDistance(
missile.getLocation(), source.getLocation());
164 if (dist > sourceRejoin) {
165 Vector2f dir = Misc.getUnitVectorAtDegreeAngle(Misc.getAngleInDegrees(
missile.getLocation(), source.getLocation()));
166 float f = dist / (sourceRejoin + 400f) - 1f;
169 Vector2f.add(total, dir, total);
172 if (dist < sourceRepel) {
173 Vector2f dir = Misc.getUnitVectorAtDegreeAngle(Misc.getAngleInDegrees(source.getLocation(),
missile.getLocation()));
174 float f = 1f - dist / sourceRepel;
176 Vector2f.add(total, dir, total);
179 if (dist < sourceCohesion && source.getVelocity().length() > 20f) {
180 Vector2f dir =
new Vector2f(source.getVelocity());
182 float f = 1f - dist / sourceCohesion;
184 Vector2f.add(total, dir, total);
188 if (total.length() <= 0.05f) {
189 float offset =
r > 0.5f ? 90f : -90f;
190 Vector2f dir = Misc.getUnitVectorAtDegreeAngle(
191 Misc.getAngleInDegrees(
missile.getLocation(), source.getLocation()) + offset);
194 Vector2f.add(total, dir, total);
198 if (total.length() > 0) {
199 float dir = Misc.getAngleInDegrees(total);
200 engine.headInDirectionWithoutTurning(
missile, dir, 10000);
203 missile.giveCommand(ShipCommand.TURN_LEFT);
205 missile.giveCommand(ShipCommand.TURN_RIGHT);
207 missile.getEngineController().forceShowAccelerating();
220 if (
missile.isFizzling())
return;
221 if (
missile.getSource() ==
null)
return;
235 ((
float) Math.random() > 0.9f ||
236 (
data.attractorLock !=
null && (
float) Math.random() > 0.5f))) {
273 if (
data.attractorLock !=
null) {
274 float dist = Misc.getDistance(
missile.getLocation(),
data.attractorLock.getLocation());
284 Vector2f targetLoc = engine.getAimPointWithLeadForAutofire(
missile, 1.5f,
target, 50);
285 engine.headInDirectionWithoutTurning(
missile,
286 Misc.getAngleInDegrees(
missile.getLocation(), targetLoc),
290 missile.giveCommand(ShipCommand.TURN_LEFT);
292 missile.giveCommand(ShipCommand.TURN_RIGHT);
294 missile.getEngineController().forceShowAccelerating();
299 if (
tracker.intervalElapsed()) {
327 if (
data.attractorLock !=
null) {
335 int owner =
missile.getOwner();
337 int maxMotesPerMissile = 2;
341 float minDist = Float.MAX_VALUE;
342 CombatEntityAPI closest =
null;
343 for (MissileAPI other : engine.getMissiles()) {
344 if (other.getOwner() == owner)
continue;
345 if (other.getOwner() == 100)
continue;
346 float distToTarget = Misc.getDistance(
missile.getLocation(), other.getLocation());
348 if (distToTarget > minDist)
continue;
349 if (distToTarget > 3000 && !engine.isAwareOf(owner, other))
continue;
351 float distFromAttractor = Float.MAX_VALUE;
352 if (
data.attractorTarget !=
null) {
353 distFromAttractor = Misc.getDistance(other.getLocation(),
data.attractorTarget);
355 float distFromSource = Misc.getDistance(other.getLocation(),
missile.getSource().getLocation());
356 if (distFromSource > maxDistFromSourceShip &&
357 distFromAttractor > maxDistFromAttractor)
continue;
360 if (distToTarget < minDist) {
362 minDist = distToTarget;
366 for (ShipAPI other : engine.getShips()) {
367 if (other.getOwner() == owner)
continue;
368 if (other.getOwner() == 100)
continue;
369 if (!other.isFighter())
continue;
370 float distToTarget = Misc.getDistance(
missile.getLocation(), other.getLocation());
371 if (distToTarget > minDist)
continue;
372 if (distToTarget > 3000 && !engine.isAwareOf(owner, other))
continue;
374 float distFromAttractor = Float.MAX_VALUE;
375 if (
data.attractorTarget !=
null) {
376 distFromAttractor = Misc.getDistance(other.getLocation(),
data.attractorTarget);
378 float distFromSource = Misc.getDistance(other.getLocation(),
missile.getSource().getLocation());
379 if (distFromSource > maxDistFromSourceShip &&
380 distFromAttractor > maxDistFromAttractor)
continue;
383 if (distToTarget < minDist) {
385 minDist = distToTarget;