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 GBCircle extends BaseGhostBehavior {
010        
011        protected SectorEntityToken other;
012        protected int maxBurn;
013        protected float desiredRange;
014        protected float circleDir;
015        
016        public GBCircle(SectorEntityToken other, float duration, int maxBurn, float desiredRange, float circleDir) {
017                super(duration);
018                this.other = other;
019                this.maxBurn = maxBurn;
020                this.desiredRange = desiredRange;
021                this.circleDir = circleDir;
022        }
023
024        @Override
025        public void advance(float amount, SensorGhost ghost) {
026                if (other.getContainingLocation() != ghost.getEntity().getContainingLocation() || !other.isAlive()) {
027                        end();
028                        return;
029                }
030                super.advance(amount, ghost);
031                
032                float dist = Misc.getDistance(ghost.getEntity(), other) - ghost.getEntity().getRadius() - other.getRadius();
033                
034                float dirToOther = Misc.getAngleInDegrees(ghost.getEntity().getLocation(), other.getLocation());
035                //Vector2f toOther = Misc.getUnitVectorAtDegreeAngle(dirToOther);
036                
037                float clockwiseDir = dirToOther + 90f;
038                
039                float bandRadius = desiredRange * 0.25f;
040                float distOffset = (dist - desiredRange);
041                if (distOffset > bandRadius) distOffset = bandRadius;
042                if (distOffset < -bandRadius) distOffset = -bandRadius;
043                
044                float angleOffset = distOffset / bandRadius * -60f;
045                //if (angleOffset > 30f) angleOffset = 30f;
046                                
047                
048                float useCircleDir = circleDir;
049                if (Misc.isReversePolarity(other)) {
050                        useCircleDir = -useCircleDir;
051                }
052                if (useCircleDir == 0f) {
053                        float velDir = Misc.getAngleInDegrees(ghost.getEntity().getVelocity());
054                        float angleDiffCW = Misc.getAngleDiff(dirToOther + 90f, velDir);
055                        float angleDiffCCW = Misc.getAngleDiff(dirToOther - 90f, velDir);
056                        if (angleDiffCW > angleDiffCCW) {
057                                useCircleDir = 1f;
058                        } else {
059                                useCircleDir = -1f;
060                        }
061                }
062                
063                
064                float moveDir = clockwiseDir;
065                if (useCircleDir > 0) {
066                        moveDir += 180f;
067                        angleOffset = -angleOffset;
068                }
069                
070                moveDir += angleOffset;
071                moveDir = Misc.normalizeAngle(moveDir);
072                
073                Vector2f dest = Misc.getUnitVectorAtDegreeAngle(moveDir);
074                dest.scale(10000f);
075                Vector2f.add(dest, ghost.getEntity().getLocation(), dest);
076                
077                ghost.moveTo(dest, maxBurn);
078        }
079        
080}
081
082
083
084
085
086
087
088
089
090
091
092
093