Had to changed race to fit the merge

This commit is contained in:
Joseph Gardner
2017-05-22 16:39:26 +12:00
parent 40421e5a83
commit 06359fb138
4 changed files with 68 additions and 73 deletions
+54 -57
View File
@@ -92,21 +92,22 @@ public class Race implements Runnable {
* The mockOutput to send messages to.
*/
private MockOutput mockOutput;
private int windDir;
private int changeWind = 4;
/**
* Wind direction bearing.
*/
* Wind direction bearing.
*/
private Bearing windDirection;
/**
* Wind speed (knots).
* Convert this to millimeters per second before passing to RaceStatus.
*/
* Wind speed (knots).
* Convert this to millimeters per second before passing to RaceStatus.
*/
private double windSpeed;
private int windDir;
private int changeWind = 4;
/**
@@ -142,30 +143,11 @@ public class Race implements Runnable {
* Runnable for the thread.
*/
public void run() {
initialiseWindDir();
initialiseBoats();
initialiseWindDir();
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.
*/
@@ -325,6 +307,9 @@ public class Race implements Runnable {
//Parse the marks.
parseMarks();
// Change wind direction
changeWindDir();
//Parse the race status.
parseRaceStatus();
@@ -336,20 +321,7 @@ public class Race implements Runnable {
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.
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();
}
};
@@ -407,6 +379,9 @@ public class Race implements Runnable {
this.stop();
}
// Change wind direction
changeWindDir();
//Parse the boat locations.
parseBoatLocations();
@@ -801,22 +776,6 @@ public class Race implements Runnable {
* Decides if a boat should received a DNF status.
* @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() {
Random rand = new Random();
return rand.nextInt(100) < dnfChance;
@@ -878,4 +837,42 @@ public class Race implements Runnable {
public ObservableList<Boat> getBoats() {
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;
}
}