001package com.fs.starfarer.api.util;
002
003import java.util.ArrayList;
004import java.util.LinkedHashSet;
005import java.util.List;
006import java.util.Set;
007
008import org.lwjgl.util.vector.Vector2f;
009
010import com.fs.starfarer.api.Global;
011import com.fs.starfarer.api.campaign.CampaignFleetAPI;
012import com.fs.starfarer.api.campaign.StarSystemAPI;
013import com.fs.starfarer.api.campaign.econ.MarketAPI;
014
015public class RadialLattice {
016        
017        public static class RadialLatticeBucket {
018                public Set<StarSystemAPI> systems = new LinkedHashSet<StarSystemAPI>();
019                public Set<MarketAPI> markets = new LinkedHashSet<MarketAPI>();
020                public float angle;
021                
022                public RadialLatticeBucket(float angle) {
023                        this.angle = angle;
024                }
025                
026                
027        }
028        
029        protected long updateTimestamp;
030        protected List<RadialLatticeBucket> buckets = new ArrayList<RadialLatticeBucket>();
031        
032        protected int numBuckets = 8;
033        protected float arc = (360 / numBuckets * 2) + 20;
034        
035        public void update() {
036                
037                buckets.clear();
038                float anglePer = 360f / (numBuckets * 2);
039                
040                for (int i = 0; i < numBuckets; i++) {
041                        RadialLatticeBucket bucket = new RadialLatticeBucket(i * anglePer);
042                        buckets.add(bucket);
043                }
044                
045                
046                CampaignFleetAPI playerFleet = Global.getSector().getPlayerFleet();
047                Vector2f origin = playerFleet.getLocation();
048                
049                
050                for (StarSystemAPI system : Global.getSector().getStarSystems()) {
051                        float angle = Misc.getAngleInDegrees(origin, system.getLocation());
052                }
053                
054        }
055        
056        
057        public RadialLatticeBucket getBucket(float angle) {
058                angle = Misc.normalizeAngle(angle);
059                
060                float anglePer = 360f / (numBuckets * 2);
061                
062                int index = (int) (angle / anglePer);
063                if (index >= numBuckets) index -= numBuckets;
064                
065                return buckets.get(index);
066        }
067        
068        
069        
070                
071}
072
073
074
075
076
077
078
079
080
081
082