001package com.fs.starfarer.api.impl.campaign.ghosts;
002
003import java.util.ArrayList;
004import java.util.Iterator;
005import java.util.List;
006
007import org.lwjgl.util.vector.Vector2f;
008
009import com.fs.starfarer.api.Global;
010import com.fs.starfarer.api.campaign.SectorEntityToken;
011
012
013public class GBEchoMovement extends BaseGhostBehavior {
014        
015        public static class GBEchoSnapshot {
016                Vector2f vel;
017                long timestamp;
018        }
019        
020        protected List<GBEchoSnapshot> snapshots = new ArrayList<GBEchoSnapshot>();
021        protected SectorEntityToken other;
022        protected float delayDays;
023        
024        
025        public GBEchoMovement(SectorEntityToken other, float delayDays, float duration) {
026                super(duration);
027                this.other = other;
028                this.delayDays = delayDays;
029        }
030
031        @Override
032        public void advance(float amount, SensorGhost ghost) {
033                if (other.getContainingLocation() != ghost.getEntity().getContainingLocation() || !other.isAlive()) {
034                        end();
035                        return;
036                }
037                
038                super.advance(amount, ghost);
039                
040                GBEchoSnapshot curr = new GBEchoSnapshot();
041                curr.vel = new Vector2f(other.getVelocity());
042                curr.timestamp = Global.getSector().getClock().getTimestamp();
043                snapshots.add(curr);
044                
045                Iterator<GBEchoSnapshot> iter = snapshots.iterator();
046                GBEchoSnapshot use = null;
047                while (iter.hasNext()) {
048                        curr = iter.next();
049                        float ago = Global.getSector().getClock().getElapsedDaysSince(curr.timestamp);
050                        if (ago >= delayDays) {
051                                use = curr;
052                                iter.remove();
053                        } else {
054                                break;
055                        }
056                }
057                
058                if (use != null) {
059                        ghost.getMovement().getVelocity().set(use.vel);
060                }
061        }
062        
063        
064        
065}
066
067
068
069
070
071
072
073
074