001package com.fs.starfarer.api.impl.campaign.ghosts; 002 003import org.lwjgl.util.vector.Vector2f; 004 005import com.fs.starfarer.api.campaign.SectorEntityToken; 006import com.fs.starfarer.api.util.IntervalUtil; 007import com.fs.starfarer.api.util.Misc; 008 009 010public class GBFollow extends BaseGhostBehavior { 011 012 protected SectorEntityToken other; 013 protected int maxBurn; 014 protected float desiredRange; 015 protected float desiredRangeMin; 016 protected float desiredRangeMax; 017 protected IntervalUtil interval = new IntervalUtil(5f, 10f); 018 protected float angleOffset = 0f; 019 protected Vector2f dest = new Vector2f(); 020 021 public GBFollow(SectorEntityToken other, float duration, int maxBurn, float desiredRangeMin, float desiredRangeMax) { 022 super(duration); 023 this.other = other; 024 this.maxBurn = maxBurn; 025 this.desiredRangeMin = desiredRangeMin; 026 this.desiredRangeMax = desiredRangeMax; 027 interval.forceIntervalElapsed(); 028 } 029 030 @Override 031 public void advance(float amount, SensorGhost ghost) { 032 if (other.getContainingLocation() != ghost.getEntity().getContainingLocation() || !other.isAlive()) { 033 end(); 034 return; 035 } 036 super.advance(amount, ghost); 037 038 float mult = 1f; 039 if (maxBurn >= 25f) mult = 3f; 040 else if (maxBurn >= 15f) mult = 2f; 041 else mult = 1.5f; 042 interval.advance(amount * mult); 043 if (interval.intervalElapsed()) { 044 angleOffset = (float) Math.random() * 120f - 60f; 045 desiredRange = desiredRangeMin + (desiredRangeMax - desiredRangeMin) * (float) Math.random(); 046 dest = Misc.getUnitVectorAtDegreeAngle( 047 angleOffset + Misc.getAngleInDegrees(other.getLocation(), ghost.getEntity().getLocation())); 048 dest.scale(desiredRange + other.getRadius() + ghost.getEntity().getRadius()); 049 Vector2f.add(dest, other.getLocation(), dest); 050 } 051 052 ghost.moveTo(dest, new Vector2f(), maxBurn); 053 } 054 055 056 057} 058 059 060 061 062 063 064 065 066 067 068 069 070