1package com.fs.starfarer.api.impl.campaign.velfield;
3import java.util.Random;
5import org.lwjgl.util.vector.Vector2f;
7import com.fs.starfarer.api.Global;
8import com.fs.starfarer.api.campaign.CampaignFleetAPI;
9import com.fs.starfarer.api.campaign.CampaignTerrainAPI;
10import com.fs.starfarer.api.impl.campaign.ids.Terrain;
11import com.fs.starfarer.api.impl.campaign.velfield.SlipstreamBuilder.StreamType;
12import com.fs.starfarer.api.impl.campaign.velfield.SlipstreamTerrainPlugin2.SlipstreamParams2;
13import com.fs.starfarer.api.util.Misc;
31 Vector2f r =
new Vector2f();
32 r.x = v.x * cos - v.y * sin;
33 r.y = v.x * sin + v.y * cos;
41 field =
new Vector2f[width][height];
44 for (
int i = 0; i <
field.length; i++) {
45 for (
int j = 0; j <
field[0].length; j++) {
46 field[i][j] =
new Vector2f();
60 if (i >=
field.length) i = field.length - 1;
61 if (j >=
field[0].length) j =
field[0].length - 1;
65 public boolean isInsideField(
float x,
float y, Vector2f bottomLeft,
float angle) {
70 Vector2f temp =
new Vector2f(x, y);
75 if (x < 0)
return false;
76 if (y < 0)
return false;
78 float w =
cellSize * (field.length - 1f);
79 if (x > w)
return false;
81 if (y > h)
return false;
85 transient float cacheKeyAngle;
86 transient float cachedSin;
87 transient float cachedCos;
89 if (cacheKeyAngle != angle) {
90 cacheKeyAngle = angle;
96 public Vector2f
getVelocity(
float x,
float y, Vector2f bottomLeft,
float angle) {
101 Vector2f temp =
new Vector2f(x, y);
108 if (x < 0) cellX1 = (int) (-1f * Math.abs(x) /
cellSize) - 1;
109 if (y < 0) cellY1 = (int) (-1f * Math.abs(y) /
cellSize) - 1;
111 int cellX2 = cellX1 + 1;
112 int cellY2 = cellY1 + 1;
114 float px = (x /
cellSize) - (
float) cellX1;
115 float py = (y /
cellSize) - (
float) cellY1;
122 Vector2f bl =
getCell(cellX1, cellY1);
123 Vector2f br =
getCell(cellX2, cellY1);
124 Vector2f tl =
getCell(cellX1, cellY2);
125 Vector2f tr =
getCell(cellX2, cellY2);
127 Vector2f result =
new Vector2f();
128 result.x = (1f - py) * (bl.x * (1f - px) + br.x * px) + py * (tl.x * (1f - px) + tr.x * px);
129 result.y = (1f - px) * (bl.y * (1f - py) + tl.y * py) + px * (br.y * (1f - py) + tr.y * py);
178 for (
int i = 0; i <
field.length; i++) {
179 for (
int j = 0; j <
field[0].length - 1; j++) {
184 for (
int i = 0; i <
field.length; i++) {
185 field[i][
field[0].length - 1] =
new Vector2f();
191 SlipstreamParams2 params =
new SlipstreamParams2();
193 params.burnLevel = 30;
194 params.minSpeed = Misc.getSpeedForBurnLevel(params.burnLevel - 5);
195 params.maxSpeed = Misc.getSpeedForBurnLevel(params.burnLevel + 5);
196 params.lineLengthFractionOfSpeed = 0.25f * Math.max(0.25f, Math.min(1f, 30f / (
float) params.burnLevel));
215 CampaignTerrainAPI slipstream = (CampaignTerrainAPI)
Global.
getSector().getCurrentLocation().addTerrain(Terrain.SLIPSTREAM, params);
216 slipstream.setLocation(pf.getLocation().x + 200f, pf.getLocation().y + 200f);
219 float spacing = 200f;
221 long seed = 23895464576452L + 4384357483229348234L;
222 seed = 1181783497276652981L ^ seed;
224 Random random =
new Random(seed);
228 Vector2f to =
new Vector2f(slipstream.getLocation());
234 Vector2f control =
new Vector2f(slipstream.getLocation());
static SectorAPI getSector()
void buildToDestination(Vector2f control, Vector2f control2, Vector2f to)
static Vector2f rotateAroundOrigin(Vector2f v, float cos, float sin)
void updateCacheIfNeeded(float angle)
VelocityField(int width, int height, float cellSize)
boolean isInsideField(float x, float y, Vector2f bottomLeft, float angle)
Vector2f getVelocity(float x, float y, Vector2f bottomLeft, float angle)
Vector2f getCell(int i, int j)