|
|
|
|
@ -112,46 +112,40 @@ public class Race implements Runnable {
|
|
|
|
|
long currentTime = System.currentTimeMillis();
|
|
|
|
|
long startTime = currentTime + (PRERACE_TIME / scaleFactor);
|
|
|
|
|
long minutes;
|
|
|
|
|
long currentTimeInSeconds;
|
|
|
|
|
long remainingSeconds;
|
|
|
|
|
long hours;
|
|
|
|
|
long timeLeft;
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void handle(long arg0) {
|
|
|
|
|
timeLeft = startTime - currentTime;
|
|
|
|
|
System.out.println(timeLeft);
|
|
|
|
|
ArrayList<BoatStatusMessage> boatStatusMessages = new ArrayList<>();
|
|
|
|
|
//For each boat, we update it's position, and generate a BoatLocationMessage.
|
|
|
|
|
for (int i = 0; i < startingBoats.size(); i++) {
|
|
|
|
|
Boat boat = startingBoats.get((i + boatOffset) % startingBoats.size());
|
|
|
|
|
if (boat != null) {
|
|
|
|
|
mockOutput.parseBoatLocation(boat.getSourceID(), boat.getCurrentPosition().getLatitude(), boat.getCurrentPosition().getLongitude(), boat.getHeading(), boat.getScaledVelocity());
|
|
|
|
|
mockOutput.parseBoatLocation(boat.getSourceID(), boat.getCurrentPosition().getLatitude(), boat.getCurrentPosition().getLongitude(), boat.getHeading(), 0);
|
|
|
|
|
boatStatusMessages.add(new BoatStatusMessage(boat.getSourceID(),
|
|
|
|
|
boat.getCurrentLeg().getLegNumber() >= 0 ? BoatStatus.RACING : BoatStatus.DNF, boat.getCurrentLeg().getLegNumber()));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
boatOffset = (boatOffset + 1) % (startingBoats.size());
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (timeLeft <= 60000/scaleFactor) {
|
|
|
|
|
if (timeLeft <= 60000/scaleFactor && timeLeft > 0) {
|
|
|
|
|
RaceStatus raceStatus = new RaceStatus(System.currentTimeMillis(), raceId, 2, 2, boatStatusMessages);
|
|
|
|
|
mockOutput.parseRaceStatus(raceStatus);
|
|
|
|
|
}
|
|
|
|
|
else if (timeLeft <= 0) {
|
|
|
|
|
countdownFinish = true;
|
|
|
|
|
stop();
|
|
|
|
|
if (runRace) {
|
|
|
|
|
simulateRace();
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
System.out.println("Stopping");
|
|
|
|
|
stop();
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
RaceStatus raceStatus = new RaceStatus(System.currentTimeMillis(), raceId, 1, 2, boatStatusMessages);
|
|
|
|
|
mockOutput.parseRaceStatus(raceStatus);
|
|
|
|
|
currentTimeInSeconds = (timeLeft * scaleFactor) / 1000;
|
|
|
|
|
minutes = currentTimeInSeconds / 60;
|
|
|
|
|
remainingSeconds = currentTimeInSeconds % 60;
|
|
|
|
|
hours = minutes / 60;
|
|
|
|
|
minutes = minutes % 60;
|
|
|
|
|
}
|
|
|
|
|
currentTime = System.currentTimeMillis();
|
|
|
|
|
}
|
|
|
|
|
|