001package com.fs.starfarer.api.impl.combat; 002 003import com.fs.starfarer.api.combat.CombatEngineAPI; 004import com.fs.starfarer.api.combat.EveryFrameWeaponEffectPlugin; 005import com.fs.starfarer.api.combat.WeaponAPI; 006 007public class SensorDishRotationEffect implements EveryFrameWeaponEffectPlugin { 008 009 private float currDir = Math.signum((float) Math.random() - 0.5f); 010 011 public void advance(float amount, CombatEngineAPI engine, WeaponAPI weapon) { 012 if (engine.isPaused()) return; 013 014 float curr = weapon.getCurrAngle(); 015 016 curr += currDir * amount * 10f; 017 float arc = weapon.getArc(); 018 float facing = weapon.getArcFacing() + (weapon.getShip() != null ? weapon.getShip().getFacing() : 0); 019 if (!isBetween(facing - arc/2, facing + arc/2, curr)) { 020 currDir = -currDir; 021 } 022 023 weapon.setFacing(curr); 024 } 025 026 public static boolean isBetween(float one, float two, float check) { 027 one = normalizeAngle(one); 028 two = normalizeAngle(two); 029 check = normalizeAngle(check); 030 031 //System.out.println(one + "," + two + "," + check); 032 if (check >= one && check <= two) return true; 033 034 if (one > two) { 035 if (check <= two) return true; 036 if (check >= one) return true; 037 } 038 return false; 039 } 040 041 public static float normalizeAngle(float angleDeg) { 042 return (angleDeg % 360f + 360f) % 360f; 043 } 044}