diff --git a/racevisionGame/src/main/java/mock/model/wind/ShiftingWindGenerator.java b/racevisionGame/src/main/java/mock/model/wind/ShiftingWindGenerator.java index cb94e55c..f9e5a4be 100644 --- a/racevisionGame/src/main/java/mock/model/wind/ShiftingWindGenerator.java +++ b/racevisionGame/src/main/java/mock/model/wind/ShiftingWindGenerator.java @@ -11,7 +11,7 @@ import java.util.Random; public class ShiftingWindGenerator implements WindGenerator { Bearing baselineBearing; double baseLineSpeed; - double speedVariance = 4; + double speedVariance = 2; double bearingVariance = 5; // In degrees double oscillationVariance = 0.25; double oscillationPeriod = 1e3 * 60 * 1; // In milliseconds @@ -20,7 +20,7 @@ public class ShiftingWindGenerator implements WindGenerator { double timeOfLastChange = 0; double timeSinceLastShift = 0; // Back / veer - boolean oscillationLeft = false; + boolean anticlockwise = false; public ShiftingWindGenerator(Bearing baselineBearing, double baseLineSpeed) { this.baselineBearing = baselineBearing; @@ -56,13 +56,13 @@ public class ShiftingWindGenerator implements WindGenerator { if (timeSinceLastOscillationReset >= oscillationPeriod) { timeOfLastOscillationReset = System.currentTimeMillis(); - oscillationLeft = !oscillationLeft; + anticlockwise = !anticlockwise; } - if (oscillationLeft) { + if (anticlockwise) { newBearing -= degreeChange; if (newBearing < baselineBearing.degrees() - bearingVariance) { System.out.println(timeSinceLastOscillationReset); - oscillationLeft = !oscillationLeft; + anticlockwise = !anticlockwise; timeOfLastOscillationReset = System.currentTimeMillis(); } else { wind.setWindDirection(Bearing.fromDegrees(newBearing % 360)); @@ -71,7 +71,7 @@ public class ShiftingWindGenerator implements WindGenerator { newBearing += degreeChange; if (newBearing > baselineBearing.degrees() + bearingVariance) { System.out.println(timeSinceLastOscillationReset); - oscillationLeft = !oscillationLeft; + anticlockwise = !anticlockwise; timeOfLastOscillationReset = System.currentTimeMillis(); } else { wind.setWindDirection(Bearing.fromDegrees(newBearing % 360)); @@ -83,11 +83,14 @@ public class ShiftingWindGenerator implements WindGenerator { } private void changeWindSpeed(Wind wind) { - + double deg = wind.getWindDirection().degrees(); + double offset = deg - baselineBearing.degrees(); + double newSpeed = offset / bearingVariance * speedVariance + baseLineSpeed; + wind.setWindSpeed(newSpeed); } private void initialiseOscillationDirection() { - oscillationLeft = new Random().nextBoolean(); + anticlockwise = new Random().nextBoolean(); timeOfLastOscillationReset = System.currentTimeMillis(); }