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.Misc;
007
008
009public class GBIntercept extends BaseGhostBehavior {
010        
011        protected SectorEntityToken other;
012        protected int maxBurn;
013        protected boolean endOnIntercept;
014        
015        protected float desiredRange;
016        
017        public GBIntercept(SectorEntityToken other, float duration, int maxBurn, boolean endOnIntercept) {
018                this(other, duration, maxBurn, 0f, endOnIntercept);
019        }
020        
021        public GBIntercept(SectorEntityToken other, float duration, int maxBurn, float desiredRange, boolean endOnIntercept) {
022                super(duration);
023                this.other = other;
024                this.maxBurn = maxBurn;
025                this.endOnIntercept = endOnIntercept;
026                this.desiredRange = desiredRange;
027        }
028
029        @Override
030        public void advance(float amount, SensorGhost ghost) {
031                if (other.getContainingLocation() != ghost.getEntity().getContainingLocation() || !other.isAlive()) {
032                        end();
033                        return;
034                }
035                super.advance(amount, ghost);
036                
037                float speed = Misc.getSpeedForBurnLevel(maxBurn);
038                Vector2f loc = Misc.getInterceptPoint(ghost.getEntity(), other, speed);
039                if (loc != null) {
040                        ghost.moveTo(loc, maxBurn);
041                }
042                
043                if (endOnIntercept) {
044                        float dist = Misc.getDistance(ghost.getEntity(), other);
045                        if (dist < ghost.getEntity().getRadius() + other.getRadius() + desiredRange) {
046                                end();
047                                return;
048                        }
049                }
050        }
051        
052        
053        
054}
055
056
057
058
059
060
061
062
063
064
065
066
067