Created a setWind(bearing, knots) in Race, which updates the Wind with new values.
MockRace now uses Wind. VisualiserRace now uses Wind. #story[1093]
This commit is contained in:
@@ -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() );
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user