From ec5bc9c6aa8ecc08acdd534b46d1cde601d5f0fe Mon Sep 17 00:00:00 2001 From: hba56 Date: Fri, 1 Sep 2017 13:19:59 +1200 Subject: [PATCH] Wind now will occasionally back and veer (in some games, takes ~20min for full 180 degree rotation) #story[1188] --- .../model/wind/ShiftingWindGenerator.java | 54 +++++++++++++------ 1 file changed, 38 insertions(+), 16 deletions(-) diff --git a/racevisionGame/src/main/java/mock/model/wind/ShiftingWindGenerator.java b/racevisionGame/src/main/java/mock/model/wind/ShiftingWindGenerator.java index d36a843b..1b995a81 100644 --- a/racevisionGame/src/main/java/mock/model/wind/ShiftingWindGenerator.java +++ b/racevisionGame/src/main/java/mock/model/wind/ShiftingWindGenerator.java @@ -5,22 +5,23 @@ import shared.model.Wind; import java.util.Random; -/** - * Created by jjg64 on 28/08/17. - */ public class ShiftingWindGenerator implements WindGenerator { - Bearing baselineBearing; - double baseLineSpeed; - double windSpeedVariance = 5; - double bearingVariance = 5; // In degrees - double oscillationVariance = 0.25; - double oscillationPeriod = 1e3 * 60 * 1; // In milliseconds - - double timeOfLastOscillationReset = 0; - double timeOfLastChange = 0; - double timeSinceLastShift = 0; // Back / veer - - boolean anticlockwise = false; + private Bearing baselineBearing; + private double baseLineSpeed; + private double windSpeedVariance = 5; + private double bearingVariance = 5; // In degrees + private double oscillationVariance = 0.25; + private double oscillationPeriod = 1e3 * 60 * 1; // In milliseconds + private double shiftTime = 1e3 * 60; + private double shiftedSoFar = 0; + + private double timeOfLastOscillationReset = 0; + private double timeOfLastChange = 0; + 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) { this.baselineBearing = baselineBearing; @@ -41,7 +42,7 @@ public class ShiftingWindGenerator implements WindGenerator { private Wind changeWind(Wind wind) { Wind newWind = new Wind(wind.getWindDirection(), wind.getWindSpeed()); oscillateWind(newWind); - shiftWind(newWind); + if (shiftThisRace){shiftWind(newWind);} changeWindSpeed(newWind); timeOfLastChange = System.currentTimeMillis(); return newWind; @@ -78,6 +79,27 @@ public class ShiftingWindGenerator implements WindGenerator { } 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) {