1package com.fs.starfarer.api.impl.campaign.procgen;
3import org.lwjgl.util.vector.Vector2f;
5import com.fs.starfarer.api.impl.campaign.terrain.BaseTiledTerrain;
6import com.fs.starfarer.api.util.Misc;
17 private float [][] noise;
28 cx =
plugin.getEntity().getLocation().x;
29 cy =
plugin.getEntity().getLocation().y;
40 int [][] copy =
new int[
w][
h];
41 for (
int i = 0; i <
w; i++) {
42 for (
int j = 0; j <
h; j++) {
43 copy[i][j] =
tiles[i][j];
65 Misc.normalizeNoise(noise);
90 float [] counts =
new float[100];
91 for (
int i = 0; i <
w; i++) {
92 for (
int j = 0; j <
h; j++) {
93 float f = noise[i][j];
94 int index = (int) (f * 100f);
95 if (index < 0) index = 0;
96 if (index > 99) index = 99;
102 float keep = fractionKeep * total;
103 float threshold = 0f;
104 float totalKept = 0f;
105 for (
int i = 0; i < 100; i++) {
106 totalKept += counts[i];
107 if (totalKept >= keep) {
108 threshold = (float) i / 100f;
114 for (
int i = 0; i <
w; i++) {
115 for (
int j = 0; j <
h; j++) {
116 if (noise[i][j] > threshold) {
126 public void clearArc(
float x,
float y,
float innerRadius,
float outerRadius,
float startAngle,
float endAngle) {
127 clearArc(x, y, innerRadius, outerRadius, startAngle, endAngle, 0f);
130 public void clearArc(
float x,
float y,
float innerRadius,
float outerRadius,
float startAngle,
float endAngle,
float noiseThresholdToClear) {
131 clearArc(x, y, innerRadius, outerRadius, startAngle, endAngle, 1f, noiseThresholdToClear);
134 public void clearArc(
float x,
float y,
float innerRadius,
float outerRadius,
float startAngle,
float endAngle,
float endRadiusMult,
float noiseThresholdToClear) {
135 float circumference = (float) Math.PI * 2f * outerRadius;
136 float degreesPerIteration = 360f / (circumference / (
ts * 0.5f));
138 for (
float angle = startAngle; angle < endAngle; angle += degreesPerIteration) {
139 Vector2f dir = Misc.getUnitVectorAtDegreeAngle(angle);
141 if (endAngle > startAngle) {
142 float p = (angle - startAngle) / (endAngle - startAngle);
143 distMult = 1f + (endRadiusMult - 1f) * p;
147 for (
float dist = innerRadius * distMult; dist <= innerRadius * distMult + (outerRadius - innerRadius); dist +=
ts * 0.5f) {
148 Vector2f curr =
new Vector2f(dir);
170 public void setTileAt(
float x,
float y,
int value,
float noiseThresholdToClear) {
171 setTileAt(x, y, value, noiseThresholdToClear,
false);
173 public void setTileAt(
float x,
float y,
int value,
float noiseThresholdToClear,
boolean setToOrigTile) {
174 int cellX = (int) ((
width / 2f + x -
cx) /
ts);
175 int cellY = (int) ((
height / 2f + y -
cy) /
ts);
182 if (cellX < 0)
return;
183 if (cellY < 0)
return;
184 if (cellX >
tiles.length - 1)
return;
185 if (cellY >
tiles[0].length - 1)
return;
192 value =
orig[cellX][cellY];
194 if (noiseThresholdToClear <= 0 || noise[cellX][cellY] > noiseThresholdToClear) {
195 tiles[cellX][cellY] = value;
void clearArc(float x, float y, float innerRadius, float outerRadius, float startAngle, float endAngle, float endRadiusMult, float noiseThresholdToClear)
void noisePrune(float fractionKeep)
void setTileAt(float x, float y, int value, float noiseThresholdToClear)
void setTileAt(float x, float y, int value, float noiseThresholdToClear, boolean setToOrigTile)
void setSetToOrigInsteadOfClear(boolean setToOrigInsteadOfClear)
void clearArc(float x, float y, float innerRadius, float outerRadius, float startAngle, float endAngle, float noiseThresholdToClear)
NebulaEditor(BaseTiledTerrain plugin)
boolean setToOrigInsteadOfClear
void clearArc(float x, float y, float innerRadius, float outerRadius, float startAngle, float endAngle)
boolean isSetToOrigInsteadOfClear()
void setTileAt(float x, float y, int value)