1package com.fs.starfarer.api.impl.campaign.enc;
3import java.util.ArrayList;
5import java.util.Random;
7import org.lwjgl.util.vector.Vector2f;
9import com.fs.starfarer.api.EveryFrameScript;
10import com.fs.starfarer.api.Global;
11import com.fs.starfarer.api.campaign.CampaignFleetAPI;
12import com.fs.starfarer.api.campaign.CampaignTerrainAPI;
13import com.fs.starfarer.api.campaign.LocationAPI;
14import com.fs.starfarer.api.campaign.listeners.ListenerUtil;
15import com.fs.starfarer.api.impl.campaign.velfield.SlipstreamTerrainPlugin2;
16import com.fs.starfarer.api.util.IntervalUtil;
17import com.fs.starfarer.api.util.Misc;
18import com.fs.starfarer.api.util.TimeoutTracker;
19import com.fs.starfarer.api.util.WeightedRandomPicker;
28 public static List<EPEncounterCreator>
CREATORS =
new ArrayList<EPEncounterCreator>();
47 String key =
"$encounterManager";
65 protected Random
random =
new Random();
66 protected IntervalUtil
interval =
new IntervalUtil(0.2f, 0.4f);
67 protected TimeoutTracker<String>
pointTimeout =
new TimeoutTracker<String>();
68 protected TimeoutTracker<String>
creatorTimeout =
new TimeoutTracker<String>();
76 if (pf ==
null)
return;
90 if (where ==
null)
return;
95 List<EncounterPoint> points = ListenerUtil.generateEncounterPoints(where);
97 float minDist = Float.MAX_VALUE;
110 float dist = Misc.getDistance(pf.getLocation(), p.loc);
111 if (dist < minRange || dist > maxRange)
continue;
112 if (dist < minDist) {
120 if (closest !=
null) {
121 WeightedRandomPicker<EPEncounterCreator> picker =
new WeightedRandomPicker<EPEncounterCreator>(
random);
124 float f = c.getFrequencyForPoint(
this, closest);
171 if (!where.isHyperspace())
return null;
173 List<EncounterPoint> result =
new ArrayList<EncounterPoint>();
175 float velAngle = Misc.getAngleInDegrees(pf.getVelocity());
176 if (pf.getVelocity().length() < 10f) {
177 velAngle = pf.getFacing();
179 for (CampaignTerrainAPI ter : where.getTerrainCopy()) {
180 if (ter.getPlugin() instanceof SlipstreamTerrainPlugin2) {
181 SlipstreamTerrainPlugin2 plugin = (SlipstreamTerrainPlugin2) ter.getPlugin();
182 List<Vector2f> points = plugin.getEncounterPoints();
183 if (points !=
null) {
184 for (Vector2f p : points) {
185 float dist = Misc.getDistance(pf.getLocation(), p);
186 if (dist > 10000f)
continue;
187 if (!Misc.isInsideSlipstream(p, 500f)) {
188 float diff = Misc.getAngleDiff(velAngle, Misc.getAngleInDegrees(pf.getLocation(), p));
190 String
id = ter.getId() +
"_" + (int)Math.round(p.x) +
"_" + (int)Math.round(p.y);
static SettingsAPI getSettings()
static SectorAPI getSector()
List< EncounterPoint > generateEncounterPoints(LocationAPI where)
TimeoutTracker< String > creatorTimeout
TimeoutTracker< String > getCreatorTimeout()
static String EP_TYPE_SLIPSTREAM
static String EP_TYPE_OUTSIDE_SYSTEM
TimeoutTracker< String > getPointTimeout()
void advance(float amount)
static EncounterManager getInstance()
TimeoutTracker< String > pointTimeout
static List< EPEncounterCreator > CREATORS
static float MAX_EP_DIST_ADD
float getPointTimeoutMin()
float getPointTimeoutMax()
float getCreatorTimeoutMax()
void createEncounter(EncounterManager manager, EncounterPoint point)
float getCreatorTimeoutMin()