Created a setWind(bearing, knots) in Race, which updates the Wind with new values.

MockRace now uses Wind.
VisualiserRace now uses Wind.
#story[1093]
main
fjc40 8 years ago
parent 5af3053537
commit 99f3310d8b

@ -99,10 +99,8 @@ public class MockRace extends Race {
this.shrinkBoundary = GPSCoordinate.getShrinkBoundary(this.boundary);
this.windSpeed = 12;
this.windDirection = Bearing.fromDegrees(180);
//Wind.
this.setWind(Bearing.fromDegrees(180), 12);
}
@ -288,8 +286,8 @@ public class MockRace extends Race {
//Convert wind direction and speed to ints. //TODO this conversion should be done inside the racestatus class.
int windDirectionInt = AC35UnitConverter.encodeHeading(this.windDirection.degrees());
int windSpeedInt = (int) (this.windSpeed * Constants.KnotsToMMPerSecond);
int windDirectionInt = AC35UnitConverter.encodeHeading(this.getWindDirection().degrees());
int windSpeedInt = (int) (this.getWindSpeed() * Constants.KnotsToMMPerSecond);
//Create race status object, and send it.
RaceStatus raceStatus = new RaceStatus(
@ -576,7 +574,12 @@ public class MockRace extends Race {
//Find the VMG inside these bounds.
VMG bestVMG = boat.getPolars().calculateVMG(this.windDirection, this.windSpeed, boat.calculateBearingToNextMarker(), lowerAcceptableBound, upperAcceptableBound);
VMG bestVMG = boat.getPolars().calculateVMG(
this.getWindDirection(),
this.getWindSpeed(),
boat.calculateBearingToNextMarker(),
lowerAcceptableBound,
upperAcceptableBound);
return bestVMG;
@ -884,7 +887,9 @@ public class MockRace extends Race {
*/
protected void initialiseWindDirection() {
//Set the starting bearing.
this.windDirection = Bearing.fromDegrees(MockRace.windBaselineBearing.degrees());
this.setWind(
Bearing.fromDegrees(MockRace.windBaselineBearing.degrees()),
this.getWindSpeed() );
}
@ -892,28 +897,34 @@ public class MockRace extends Race {
* Changes the wind direction randomly, while keeping it within [windLowerBound, windUpperBound].
*/
protected void changeWindDirection() {
//TODO this wind generation could probably be moved to its own object?
//Randomly add or remove 0.5 degrees.
int r = new Random().nextInt(changeWind) + 1;
double newWindBearingDegrees = this.getWindDirection().degrees();
if (r == 1) {
//Add 0.5 degrees to the wind bearing.
this.windDirection.setDegrees(this.windDirection.degrees() + 0.5);
newWindBearingDegrees += 0.5;
} else if (r == 2) {
//Minus 0.5 degrees from the wind bearing.
this.windDirection.setDegrees(this.windDirection.degrees() - 0.5);
newWindBearingDegrees -= 0.5;
}
//Ensure that the wind is in the correct bounds.
if (this.windDirection.degrees() > MockRace.windUpperBound.degrees()) {
this.windDirection.setBearing(MockRace.windUpperBound);
if (newWindBearingDegrees > MockRace.windUpperBound.degrees()) {
newWindBearingDegrees = MockRace.windUpperBound.degrees();
} else if (this.windDirection.degrees() < MockRace.windLowerBound.degrees()) {
this.windDirection.setBearing(MockRace.windLowerBound);
} else if (newWindBearingDegrees < MockRace.windLowerBound.degrees()) {
newWindBearingDegrees = MockRace.windLowerBound.degrees();
}
this.setWind(
Bearing.fromDegrees(newWindBearingDegrees),
this.getWindSpeed() );
}

@ -166,8 +166,7 @@ public abstract class Race implements Runnable {
this.raceType = raceDataSource.getRaceType();
//Wind.
Wind wind = new Wind(Bearing.fromDegrees(0), 0);
this.raceWind.setValue(wind);
this.setWind(Bearing.fromDegrees(0), 0);
}
@ -248,6 +247,18 @@ public abstract class Race implements Runnable {
return regattaName;
}
/**
* Updates the race to have a specified wind bearing and speed.
* @param windBearing New wind bearing.
* @param windSpeedKnots New wind speed, in knots.
*/
protected void setWind(Bearing windBearing, double windSpeedKnots) {
Wind wind = new Wind(windBearing, windSpeedKnots);
this.raceWind.setValue(wind);
}
/**
* Returns the wind bearing.
* @return The wind bearing.

@ -311,11 +311,10 @@ public class VisualiserRace extends Race {
//Race status enum.
this.raceStatusEnum = RaceStatusEnum.fromByte(raceStatus.getRaceStatus());
//Wind bearing.
this.windDirection.setDegrees(raceStatus.getScaledWindDirection());
//Wind speed.
this.windSpeed = raceStatus.getWindSpeedKnots();
//Wind.
this.setWind(
Bearing.fromDegrees(raceStatus.getScaledWindDirection()),
raceStatus.getWindSpeedKnots() );
//Current race time.
this.raceClock.setUTCTime(raceStatus.getCurrentTime());

Loading…
Cancel
Save