|
|
|
|
@ -18,6 +18,8 @@ import java.util.Iterator;
|
|
|
|
|
import java.util.List;
|
|
|
|
|
import java.util.Random;
|
|
|
|
|
|
|
|
|
|
import static java.lang.Math.cos;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Represents a yacht race.
|
|
|
|
|
@ -173,7 +175,7 @@ public class Race implements Runnable {
|
|
|
|
|
*/
|
|
|
|
|
private void parseIndividualMark(Mark mark) {
|
|
|
|
|
|
|
|
|
|
this.mockOutput.parseBoatLocation(mark.getSourceID(), mark.getPosition().getLatitude(), mark.getPosition().getLongitude(),0,0);
|
|
|
|
|
this.mockOutput.parseBoatLocation(mark.getSourceID(), mark.getPosition().getLatitude(), mark.getPosition().getLongitude(),0,0, totalTimeElapsed+startTime);
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@ -202,7 +204,8 @@ public class Race implements Runnable {
|
|
|
|
|
boat.getCurrentPosition().getLatitude(),
|
|
|
|
|
boat.getCurrentPosition().getLongitude(),
|
|
|
|
|
boat.getBearing().degrees(),
|
|
|
|
|
boat.getCurrentSpeed()
|
|
|
|
|
boat.getCurrentSpeed(),
|
|
|
|
|
startTime + totalTimeElapsed
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
@ -253,7 +256,7 @@ public class Race implements Runnable {
|
|
|
|
|
//Add each boat status to the status list.
|
|
|
|
|
for (Boat boat : boats) {
|
|
|
|
|
|
|
|
|
|
BoatStatus boatStatus = new BoatStatus(boat.getSourceID(), boat.getStatus(), boat.getCurrentLeg().getLegNumber());
|
|
|
|
|
BoatStatus boatStatus = new BoatStatus(boat.getSourceID(), boat.getStatus(), boat.getCurrentLeg().getLegNumber(), boat.getEstimatedTime());
|
|
|
|
|
|
|
|
|
|
boatStatuses.add(boatStatus);
|
|
|
|
|
}
|
|
|
|
|
@ -625,7 +628,7 @@ public class Race implements Runnable {
|
|
|
|
|
|
|
|
|
|
//Check the boats position (update leg and stuff).
|
|
|
|
|
this.checkPosition(boat, totalTimeElapsed);
|
|
|
|
|
|
|
|
|
|
this.updateEstimatedTime(boat);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
@ -899,4 +902,16 @@ public class Race implements Runnable {
|
|
|
|
|
protected int getWind(){
|
|
|
|
|
return windDir;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Updates the boat's estimated time to next mark if positive
|
|
|
|
|
* @param boat to estimate time given its velocity
|
|
|
|
|
*/
|
|
|
|
|
private void updateEstimatedTime(Boat boat) {
|
|
|
|
|
double velocityToMark = boat.getCurrentSpeed() * cos(boat.getBearing().radians() - boat.calculateBearingToNextMarker().radians()) / Constants.KnotsToMMPerSecond;
|
|
|
|
|
if (velocityToMark > 0) {
|
|
|
|
|
long timeFromNow = (long)(1000*boat.calculateDistanceToNextMarker()/velocityToMark);
|
|
|
|
|
boat.setEstimatedTime(startTime + totalTimeElapsed + timeFromNow);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|