Wind oscillates, replaces random wind with shifting wind. #story[1187]
This commit is contained in:
@@ -23,6 +23,8 @@ import javax.xml.bind.JAXBException;
|
|||||||
import javax.xml.parsers.ParserConfigurationException;
|
import javax.xml.parsers.ParserConfigurationException;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.nio.charset.StandardCharsets;
|
import java.nio.charset.StandardCharsets;
|
||||||
|
import java.time.ZonedDateTime;
|
||||||
|
import java.time.format.DateTimeFormatter;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -13,10 +13,11 @@ public class ShiftingWindGenerator implements WindGenerator {
|
|||||||
double baseLineSpeed;
|
double baseLineSpeed;
|
||||||
double speedVariance = 4;
|
double speedVariance = 4;
|
||||||
double bearingVariance = 5; // In degrees
|
double bearingVariance = 5; // In degrees
|
||||||
double oscillationPeriod = 3e6; // In milliseconds
|
double oscillationVariance = 0.25;
|
||||||
|
double oscillationPeriod = 1e3 * 60 * 1; // In milliseconds
|
||||||
|
|
||||||
double timeOfLastOscillationReset = 0;
|
double timeOfLastOscillationReset = 0;
|
||||||
double timeSinceLastChange = 0;
|
double timeOfLastChange = 0;
|
||||||
double timeSinceLastShift = 0; // Back / veer
|
double timeSinceLastShift = 0; // Back / veer
|
||||||
|
|
||||||
boolean oscillationLeft = false;
|
boolean oscillationLeft = false;
|
||||||
@@ -42,13 +43,39 @@ public class ShiftingWindGenerator implements WindGenerator {
|
|||||||
oscillateWind(newWind);
|
oscillateWind(newWind);
|
||||||
shiftWind(newWind);
|
shiftWind(newWind);
|
||||||
changeWindSpeed(newWind);
|
changeWindSpeed(newWind);
|
||||||
|
timeOfLastChange = System.currentTimeMillis();
|
||||||
return newWind;
|
return newWind;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void oscillateWind(Wind wind) {
|
private void oscillateWind(Wind wind) {
|
||||||
double timeSinceLastOscillationReset = System.currentTimeMillis() - timeOfLastOscillationReset;
|
double timeSinceLastOscillationReset = System.currentTimeMillis() - timeOfLastOscillationReset;
|
||||||
if (oscillationLeft) {
|
double timeSinceLastChange = System.currentTimeMillis() - timeOfLastChange;
|
||||||
|
double newBearing = wind.getWindDirection().degrees();
|
||||||
|
double degreeChange = timeSinceLastChange * 2 * bearingVariance / oscillationPeriod;
|
||||||
|
degreeChange = (1 - oscillationVariance) * degreeChange + (2 * oscillationVariance) * degreeChange * Math.random();
|
||||||
|
|
||||||
|
if (timeSinceLastOscillationReset >= oscillationPeriod) {
|
||||||
|
timeOfLastOscillationReset = System.currentTimeMillis();
|
||||||
|
oscillationLeft = !oscillationLeft;
|
||||||
|
}
|
||||||
|
if (oscillationLeft) {
|
||||||
|
newBearing -= degreeChange;
|
||||||
|
if (newBearing < baselineBearing.degrees() - bearingVariance) {
|
||||||
|
System.out.println(timeSinceLastOscillationReset);
|
||||||
|
oscillationLeft = !oscillationLeft;
|
||||||
|
timeOfLastOscillationReset = System.currentTimeMillis();
|
||||||
|
} else {
|
||||||
|
wind.setWindDirection(Bearing.fromDegrees(newBearing % 360));
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
newBearing += degreeChange;
|
||||||
|
if (newBearing > baselineBearing.degrees() + bearingVariance) {
|
||||||
|
System.out.println(timeSinceLastOscillationReset);
|
||||||
|
oscillationLeft = !oscillationLeft;
|
||||||
|
timeOfLastOscillationReset = System.currentTimeMillis();
|
||||||
|
} else {
|
||||||
|
wind.setWindDirection(Bearing.fromDegrees(newBearing % 360));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user