Wind now will occasionally back and veer (in some games, takes ~20min for full 180 degree rotation)

#story[1188]
main
hba56 8 years ago
parent 0de7780020
commit ec5bc9c6aa

@ -5,22 +5,23 @@ import shared.model.Wind;
import java.util.Random; import java.util.Random;
/**
* Created by jjg64 on 28/08/17.
*/
public class ShiftingWindGenerator implements WindGenerator { public class ShiftingWindGenerator implements WindGenerator {
Bearing baselineBearing; private Bearing baselineBearing;
double baseLineSpeed; private double baseLineSpeed;
double windSpeedVariance = 5; private double windSpeedVariance = 5;
double bearingVariance = 5; // In degrees private double bearingVariance = 5; // In degrees
double oscillationVariance = 0.25; private double oscillationVariance = 0.25;
double oscillationPeriod = 1e3 * 60 * 1; // In milliseconds private double oscillationPeriod = 1e3 * 60 * 1; // In milliseconds
private double shiftTime = 1e3 * 60;
double timeOfLastOscillationReset = 0; private double shiftedSoFar = 0;
double timeOfLastChange = 0;
double timeSinceLastShift = 0; // Back / veer private double timeOfLastOscillationReset = 0;
private double timeOfLastChange = 0;
boolean anticlockwise = false; private double timeOfLastShift = 0; // Back / veer
private boolean anticlockwise = false;
private boolean shiftAnticlockwise = false;//true for Back, false for veer
private boolean shiftThisRace = Math.random() > 0.5;
public ShiftingWindGenerator(Bearing baselineBearing, double baseLineSpeed) { public ShiftingWindGenerator(Bearing baselineBearing, double baseLineSpeed) {
this.baselineBearing = baselineBearing; this.baselineBearing = baselineBearing;
@ -41,7 +42,7 @@ public class ShiftingWindGenerator implements WindGenerator {
private Wind changeWind(Wind wind) { private Wind changeWind(Wind wind) {
Wind newWind = new Wind(wind.getWindDirection(), wind.getWindSpeed()); Wind newWind = new Wind(wind.getWindDirection(), wind.getWindSpeed());
oscillateWind(newWind); oscillateWind(newWind);
shiftWind(newWind); if (shiftThisRace){shiftWind(newWind);}
changeWindSpeed(newWind); changeWindSpeed(newWind);
timeOfLastChange = System.currentTimeMillis(); timeOfLastChange = System.currentTimeMillis();
return newWind; return newWind;
@ -78,6 +79,27 @@ public class ShiftingWindGenerator implements WindGenerator {
} }
private void shiftWind(Wind wind) { private void shiftWind(Wind wind) {
double timeSinceLastShift = System.currentTimeMillis() - timeOfLastShift;
double newBearing = wind.getWindDirection().degrees();
double degreeChange = 7;
if (timeSinceLastShift >= shiftTime){
shiftedSoFar += degreeChange;
if (shiftedSoFar >= 180){
shiftAnticlockwise = Math.random() > 0.5;
shiftedSoFar = 0;
System.out.println("Swapping");
}
timeOfLastShift = System.currentTimeMillis();
if (shiftAnticlockwise){
newBearing -= degreeChange;
wind.setWindDirection(Bearing.fromDegrees(newBearing % 360));
} else {
newBearing += degreeChange;
wind.setWindDirection(Bearing.fromDegrees(newBearing % 360));
}
}
} }
private void changeWindSpeed(Wind wind) { private void changeWindSpeed(Wind wind) {

Loading…
Cancel
Save