|
|
|
@ -92,21 +92,22 @@ public class Race implements Runnable {
|
|
|
|
* The mockOutput to send messages to.
|
|
|
|
* The mockOutput to send messages to.
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
private MockOutput mockOutput;
|
|
|
|
private MockOutput mockOutput;
|
|
|
|
private int windDir;
|
|
|
|
|
|
|
|
private int changeWind = 4;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* Wind direction bearing.
|
|
|
|
* Wind direction bearing.
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
private Bearing windDirection;
|
|
|
|
private Bearing windDirection;
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* Wind speed (knots).
|
|
|
|
* Wind speed (knots).
|
|
|
|
* Convert this to millimeters per second before passing to RaceStatus.
|
|
|
|
* Convert this to millimeters per second before passing to RaceStatus.
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
private double windSpeed;
|
|
|
|
private double windSpeed;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private int windDir;
|
|
|
|
|
|
|
|
private int changeWind = 4;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
@ -142,30 +143,11 @@ public class Race implements Runnable {
|
|
|
|
* Runnable for the thread.
|
|
|
|
* Runnable for the thread.
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
public void run() {
|
|
|
|
public void run() {
|
|
|
|
initialiseWindDir();
|
|
|
|
|
|
|
|
initialiseBoats();
|
|
|
|
initialiseBoats();
|
|
|
|
|
|
|
|
initialiseWindDir();
|
|
|
|
countdownTimer.start();
|
|
|
|
countdownTimer.start();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
protected void initialiseWindDir(){
|
|
|
|
|
|
|
|
windDir = new Random().nextInt(65535+1);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
protected void changeWindDir(){
|
|
|
|
|
|
|
|
int r = new Random().nextInt(changeWind)+1;
|
|
|
|
|
|
|
|
if(r==1){
|
|
|
|
|
|
|
|
windDir+=100;
|
|
|
|
|
|
|
|
} else if (r==2){
|
|
|
|
|
|
|
|
windDir-=100;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if (windDir > 65535){
|
|
|
|
|
|
|
|
windDir -= 65535;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if (windDir < 0){
|
|
|
|
|
|
|
|
windDir += 65535;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* Parse the compound marker boats through mock output.
|
|
|
|
* Parse the compound marker boats through mock output.
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
@ -325,6 +307,9 @@ public class Race implements Runnable {
|
|
|
|
//Parse the marks.
|
|
|
|
//Parse the marks.
|
|
|
|
parseMarks();
|
|
|
|
parseMarks();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Change wind direction
|
|
|
|
|
|
|
|
changeWindDir();
|
|
|
|
|
|
|
|
|
|
|
|
//Parse the race status.
|
|
|
|
//Parse the race status.
|
|
|
|
parseRaceStatus();
|
|
|
|
parseRaceStatus();
|
|
|
|
|
|
|
|
|
|
|
|
@ -336,20 +321,7 @@ public class Race implements Runnable {
|
|
|
|
this.stop();
|
|
|
|
this.stop();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
changeWindDir();
|
|
|
|
|
|
|
|
ArrayList<BoatStatus> boatStatuses = new ArrayList<>();
|
|
|
|
|
|
|
|
for (Boat boat : startingBoats) {
|
|
|
|
|
|
|
|
mockOutput.parseBoatLocation(boat.getSourceID(), boat.getCurrentPosition().getLatitude(),
|
|
|
|
|
|
|
|
boat.getCurrentPosition().getLongitude(), boat.getHeading(), 0);
|
|
|
|
|
|
|
|
boatStatuses.add(new BoatStatus(boat.getSourceID(), BoatStatusEnum.PRESTART, 0));
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
parseMarks();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//Update the animations timer's time.
|
|
|
|
//Update the animations timer's time.
|
|
|
|
int raceStatusNumber = timeLeft <= 60000 / scaleFactor && timeLeft > 0? 2 : 1;
|
|
|
|
|
|
|
|
RaceStatus raceStatus = new RaceStatus(System.currentTimeMillis(), raceId, raceStatusNumber, startTime, windDir, 2300, 1, boatStatuses);
|
|
|
|
|
|
|
|
mockOutput.parseRaceStatus(raceStatus);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
currentTime = System.currentTimeMillis();
|
|
|
|
currentTime = System.currentTimeMillis();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
};
|
|
|
|
@ -407,6 +379,9 @@ public class Race implements Runnable {
|
|
|
|
this.stop();
|
|
|
|
this.stop();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Change wind direction
|
|
|
|
|
|
|
|
changeWindDir();
|
|
|
|
|
|
|
|
|
|
|
|
//Parse the boat locations.
|
|
|
|
//Parse the boat locations.
|
|
|
|
parseBoatLocations();
|
|
|
|
parseBoatLocations();
|
|
|
|
|
|
|
|
|
|
|
|
@ -801,22 +776,6 @@ public class Race implements Runnable {
|
|
|
|
* Decides if a boat should received a DNF status.
|
|
|
|
* Decides if a boat should received a DNF status.
|
|
|
|
* @return True means it should DNF, false means it shouldn't.
|
|
|
|
* @return True means it should DNF, false means it shouldn't.
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
protected void setWindDir(int wind){
|
|
|
|
|
|
|
|
if (wind>=0 && wind<=65535){
|
|
|
|
|
|
|
|
windDir = wind;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
protected void setChangeWind(int changeVal){
|
|
|
|
|
|
|
|
if (changeVal>=0){
|
|
|
|
|
|
|
|
changeWind = changeVal;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
protected int getWind(){
|
|
|
|
|
|
|
|
return windDir;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
protected boolean doNotFinish() {
|
|
|
|
protected boolean doNotFinish() {
|
|
|
|
Random rand = new Random();
|
|
|
|
Random rand = new Random();
|
|
|
|
return rand.nextInt(100) < dnfChance;
|
|
|
|
return rand.nextInt(100) < dnfChance;
|
|
|
|
@ -878,4 +837,42 @@ public class Race implements Runnable {
|
|
|
|
public ObservableList<Boat> getBoats() {
|
|
|
|
public ObservableList<Boat> getBoats() {
|
|
|
|
return boats;
|
|
|
|
return boats;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
protected void initialiseWindDir(){
|
|
|
|
|
|
|
|
windDir = new Random().nextInt(65535+1);
|
|
|
|
|
|
|
|
this.windDirection = new Bearing(BoatLocation.convertHeadingIntToDouble(windDir));
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
protected void changeWindDir(){
|
|
|
|
|
|
|
|
int r = new Random().nextInt(changeWind)+1;
|
|
|
|
|
|
|
|
if(r==1){
|
|
|
|
|
|
|
|
windDir+=100;
|
|
|
|
|
|
|
|
} else if (r==2){
|
|
|
|
|
|
|
|
windDir-=100;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if (windDir > 65535){
|
|
|
|
|
|
|
|
windDir -= 65535;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if (windDir < 0){
|
|
|
|
|
|
|
|
windDir += 65535;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
this.windDirection = new Bearing(BoatLocation.convertHeadingIntToDouble(windDir));
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
protected void setWindDir(int wind){
|
|
|
|
|
|
|
|
if (wind>=0 && wind<=65535){
|
|
|
|
|
|
|
|
windDir = wind;
|
|
|
|
|
|
|
|
this.windDirection = new Bearing(BoatLocation.convertHeadingIntToDouble(windDir));
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
protected void setChangeWind(int changeVal){
|
|
|
|
|
|
|
|
if (changeVal>=0){
|
|
|
|
|
|
|
|
changeWind = changeVal;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
protected int getWind(){
|
|
|
|
|
|
|
|
return windDir;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|