001package com.fs.starfarer.api.impl.campaign.enc;
002
003import org.lwjgl.util.vector.Vector2f;
004
005import com.fs.starfarer.api.Global;
006import com.fs.starfarer.api.campaign.SectorEntityToken;
007import com.fs.starfarer.api.impl.campaign.AbyssalLightEntityPlugin;
008import com.fs.starfarer.api.impl.campaign.AbyssalLightEntityPlugin.AbyssalLightParams;
009import com.fs.starfarer.api.impl.campaign.ids.Entities;
010import com.fs.starfarer.api.impl.campaign.ids.Factions;
011import com.fs.starfarer.api.impl.campaign.terrain.HyperspaceAbyssPluginImpl.AbyssalEPData;
012import com.fs.starfarer.api.util.Misc;
013import com.fs.starfarer.api.util.WeightedRandomPicker;
014
015public class AbyssalLightEPEC extends BaseEPEncounterCreator {
016        
017        public static enum LightSpawnType {
018                NORMAL,
019                PAIR,
020                CLUSTER,
021                LARGE,
022        }
023        
024        public float getFrequencyForPoint(EncounterManager manager, EncounterPoint point) {
025                return AbyssalFrequencies.getAbyssalLightFrequency(manager, point);
026        }
027        
028        protected LightSpawnType pickSpawnType(EncounterManager manager, EncounterPoint point) {
029                AbyssalEPData data = (AbyssalEPData) point.custom;
030                
031                WeightedRandomPicker<LightSpawnType> picker = new WeightedRandomPicker<LightSpawnType>(data.random);
032                picker.add(LightSpawnType.NORMAL, 100f);
033                picker.add(LightSpawnType.PAIR, 7f);
034                picker.add(LightSpawnType.CLUSTER, 3f);
035                picker.add(LightSpawnType.LARGE, 1f);
036                
037                LightSpawnType type = picker.pick();
038                return type;
039        }
040        
041        protected void modifyLightParams(EncounterManager manager, EncounterPoint point, LightSpawnType type, AbyssalLightParams params) {
042        }
043        protected void modifySpawnedLight(EncounterManager manager, EncounterPoint point, AbyssalLightParams params, SectorEntityToken light) {
044        }
045
046        @Override
047        public void createEncounter(EncounterManager manager, EncounterPoint point) {
048                
049                AbyssalEPData data = (AbyssalEPData) point.custom;
050                LightSpawnType type = pickSpawnType(manager, point);
051                
052                float minSize = AbyssalLightEntityPlugin.MIN_SIZE;
053                float maxSize = AbyssalLightEntityPlugin.MAX_SIZE;
054                if (type == LightSpawnType.NORMAL) {
055                        AbyssalLightParams params = new AbyssalLightParams();
056                        modifyLightParams(manager, point, type, params);
057                        SectorEntityToken e = Global.getSector().getHyperspace().addCustomEntity(
058                                                                        null, null, Entities.ABYSSAL_LIGHT, Factions.NEUTRAL, params);
059                        e.setLocation(point.loc.x, point.loc.y);
060                        modifySpawnedLight(manager, point, params, e);
061                } else if (type == LightSpawnType.LARGE) {
062                        AbyssalLightParams params = new AbyssalLightParams(maxSize + 800f, maxSize + 1200f);
063                        params.durationDays = 1000f + data.random.nextFloat() * 500f;
064                        params.frequencyChangeMult = 0.25f;
065                        modifyLightParams(manager, point, type, params);
066                        
067                        SectorEntityToken e = Global.getSector().getHyperspace().addCustomEntity(
068                                                                        null, null, Entities.ABYSSAL_LIGHT, Factions.NEUTRAL, params);
069                        e.setLocation(point.loc.x, point.loc.y);
070                        modifySpawnedLight(manager, point, params, e);
071                } else if (type == LightSpawnType.PAIR) {
072                        AbyssalLightParams larger = new AbyssalLightParams(maxSize - 300f, maxSize + 300f);
073                        larger.durationDays = 90f + data.random.nextFloat() * 30f;
074                        larger.frequencyChangeMult = 0.75f;
075                        modifyLightParams(manager, point, type, larger);
076                        
077                        SectorEntityToken e = Global.getSector().getHyperspace().addCustomEntity(
078                                        null, null, Entities.ABYSSAL_LIGHT, Factions.NEUTRAL, larger);
079                        e.setLocation(point.loc.x, point.loc.y);
080                        modifySpawnedLight(manager, point, larger, e);
081                        
082                        AbyssalLightParams smaller = new AbyssalLightParams(minSize * 0.2f, minSize * 0.5f);
083                        smaller.durationDays = larger.durationDays;
084                        smaller.frequencyChangeMult = larger.frequencyChangeMult;
085                        modifyLightParams(manager, point, type, smaller);
086                        
087                        Vector2f loc = Misc.getPointAtRadius(point.loc, 100f + data.random.nextFloat() * 300f);
088                        e = Global.getSector().getHyperspace().addCustomEntity(
089                                        null, null, Entities.ABYSSAL_LIGHT, Factions.NEUTRAL, smaller);
090                        e.setLocation(loc.x, loc.y);
091                        modifySpawnedLight(manager, point, smaller, e);
092                } else if (type == LightSpawnType.CLUSTER) {
093                        int num = 3 + data.random.nextInt(7);
094                        float spread = 50f + num * 10f;
095                        spread *= 0.5f;
096                        for (int i = 0; i < num; i++) {
097                                AbyssalLightParams params = new AbyssalLightParams(minSize * 0.1f, minSize * 0.2f);
098                                params.durationDays += data.random.nextFloat() * 50f;
099                                params.frequencyChangeMult = 2f + data.random.nextFloat() * 2f;;
100                                params.frequencyMultMin *= params.frequencyChangeMult;
101                                params.frequencyMultMax *= params.frequencyChangeMult;
102                                modifyLightParams(manager, point, type, params);
103                                
104                                //Vector2f loc = Misc.getPointWithinRadiusUniform(point.loc, spread, data.random);
105                                Vector2f loc = Misc.getPointWithinRadius(point.loc, spread);
106                                SectorEntityToken e = Global.getSector().getHyperspace().addCustomEntity(
107                                                                                null, null, Entities.ABYSSAL_LIGHT, Factions.NEUTRAL, params);
108                                e.setLocation(loc.x, loc.y);
109                                modifySpawnedLight(manager, point, params, e);
110                        }
111                }
112                
113        }
114        
115}
116
117
118
119
120
121
122
123
124
125
126
127
128