1package com.fs.starfarer.api.impl.campaign.terrain;
3import com.fs.starfarer.api.campaign.PlanetAPI;
4import com.fs.starfarer.api.campaign.SectorEntityToken;
5import com.fs.starfarer.api.util.Misc;
9 private int resolution;
10 private float maxRange;
15 private float degreesPerUnit;
16 private float [] limits;
17 private float [] curr;
20 private boolean wasUpdated =
false;
21 private boolean isAnythingShortened =
false;
24 this.resolution = resolution;
25 this.maxRange = maxRange;
28 degreesPerUnit = 360f / (float) resolution;
30 limits =
new float [resolution];
31 curr =
new float [resolution];
50 for (
int i = 0; i < resolution; i++) {
62 float index = angle / 360f * resolution;
63 int i1 = (int) Math.floor(index);
64 int i2 = (int) Math.ceil(index);
65 while (i1 >= resolution) i1 -= resolution;
66 while (i2 >= resolution) i2 -= resolution;
71 return v1 + (v2 - v1) * (index - (
int) index);
83 public void advance(
float amount,
float minApproachSpeed,
float diffMult) {
84 for (
int i = 0; i < resolution; i++) {
85 curr[i] =
Misc.
approach(curr[i], limits[i], minApproachSpeed, diffMult, amount);
97 for (
int i = 0; i < resolution; i++) {
101 isAnythingShortened =
false;
104 if (planet == entity || planet == exclude)
continue;
106 if (dist > maxRange)
continue;
108 float graceRadius = 100f;
110 graceRadius = planet.getRadius() + 100f;
115 float offsetSize = maxRange * 0.2f;
117 float spanOffset = span * 0.4f * 1f / diffMult;
119 for (
float f = angle - span/2f - spanOffset; f <= angle + span/2f - spanOffset; f += degreesPerUnit) {
120 float offset = Math.abs(f - angle) / (span / 2f);
121 if (offset > 1) offset = 1;
122 offset = (1f - (float) Math.cos(offset * 3.1416f / 2f));
129 offset *= offsetSize;
133 limits[index] = Math.min(dist - (planet.getRadius()) * 0.5f + offset, limits[index]);
134 isAnythingShortened =
true;
141 public void block(
float angle,
float arc,
float limit) {
143 float offsetSize = Math.max(limit, maxRange * 0.1f);
145 for (
float f = angle - arc/2f; f <= angle + arc/2f; f += degreesPerUnit) {
147 float offset = Math.abs(f - angle) / (arc / 2f);
148 if (offset > 1) offset = 1;
149 offset = (1f - (float) Math.cos(offset * 3.1416f / 2f));
153 offset *= offsetSize;
155 offset = Math.abs(offset);
158 limits[index] = Math.min(limit + offset, limits[index]);
159 isAnythingShortened =
true;
166 int index = (int)Math.round(angle / 360f * (
float) resolution);
167 if (index < 0) index = 0;
169 while (index >= resolution) index -= resolution;
175 return isAnythingShortened;
RangeBlockerUtil(int resolution, float maxRange)
void block(float angle, float arc, float limit)
void advance(float amount, float minApproachSpeed, float diffMult)
boolean isAnythingShortened()
float getShortenAmountAt(float angle)
void updateLimits(SectorEntityToken entity, SectorEntityToken exclude, float diffMult)
float getAlphaAt(float angle)
void updateAndSync(SectorEntityToken entity, SectorEntityToken exclude, float diffMult)
float getCurrMaxAt(float angle)
int getIndexForAngle(float angle)
static float approach(float curr, float dest, float minSpeed, float diffSpeedMult, float amount)
static float computeAngleSpan(float radius, float range)
static float getDistance(SectorEntityToken from, SectorEntityToken to)
static float normalizeAngle(float angleDeg)
static float getAngleInDegrees(Vector2f v)
List< PlanetAPI > getPlanets()
LocationAPI getContainingLocation()