Starsector API
Loading...
Searching...
No Matches
SensorDishRotationEffect.java
Go to the documentation of this file.
1package com.fs.starfarer.api.impl.combat;
2
3import com.fs.starfarer.api.combat.CombatEngineAPI;
4import com.fs.starfarer.api.combat.EveryFrameWeaponEffectPlugin;
5import com.fs.starfarer.api.combat.WeaponAPI;
6
7public class SensorDishRotationEffect implements EveryFrameWeaponEffectPlugin {
8
9 private float currDir = Math.signum((float) Math.random() - 0.5f);
10
11 public void advance(float amount, CombatEngineAPI engine, WeaponAPI weapon) {
12 if (engine.isPaused()) return;
13
14 float curr = weapon.getCurrAngle();
15
16 curr += currDir * amount * 10f;
17 float arc = weapon.getArc();
18 float facing = weapon.getArcFacing() + (weapon.getShip() != null ? weapon.getShip().getFacing() : 0);
19 if (!isBetween(facing - arc/2, facing + arc/2, curr)) {
20 currDir = -currDir;
21 }
22
23 weapon.setFacing(curr);
24 }
25
26 public static boolean isBetween(float one, float two, float check) {
27 one = normalizeAngle(one);
28 two = normalizeAngle(two);
29 check = normalizeAngle(check);
30
31 //System.out.println(one + "," + two + "," + check);
32 if (check >= one && check <= two) return true;
33
34 if (one > two) {
35 if (check <= two) return true;
36 if (check >= one) return true;
37 }
38 return false;
39 }
40
41 public static float normalizeAngle(float angleDeg) {
42 return (angleDeg % 360f + 360f) % 360f;
43 }
44}
void advance(float amount, CombatEngineAPI engine, WeaponAPI weapon)
static boolean isBetween(float one, float two, float check)