Had to changed race to fit the merge
This commit is contained in:
@@ -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;
|
||||
}
|
||||
}
|
||||
@@ -297,19 +297,19 @@ public class RaceTest{
|
||||
@Ignore
|
||||
@Test
|
||||
public void windDirectionCorrectValues(){
|
||||
try {
|
||||
MockOutput mockOutput = Mockito.mock(MockOutput.class);
|
||||
BoatDataSource boatDataSource = new BoatXMLReader("mockXML/boatTest.xml");
|
||||
RaceDataSource raceDataSource = new RaceXMLReader("mockXML/raceTest.xml", boatDataSource);
|
||||
Race testRace = new Race(raceDataSource, mockOutput);
|
||||
testRace.setChangeWind(1);
|
||||
testRace.setWindDir(65535);
|
||||
testRace.changeWindDir();
|
||||
assertEquals(100, testRace.getWind());
|
||||
} catch (ParserConfigurationException | IOException | SAXException | ParseException | StreamedCourseXMLException e) {
|
||||
e.printStackTrace();
|
||||
fail();
|
||||
}
|
||||
// try {
|
||||
// MockOutput mockOutput = Mockito.mock(MockOutput.class);
|
||||
// BoatDataSource boatDataSource = new BoatXMLReader("mockXML/boatTest.xml");
|
||||
// RaceDataSource raceDataSource = new RaceXMLReader("mockXML/raceTest.xml", boatDataSource);
|
||||
// Race testRace = new Race(raceDataSource, mockOutput);
|
||||
// testRace.setChangeWind(1);
|
||||
// testRace.setWindDir(65535);
|
||||
// testRace.changeWindDir();
|
||||
// assertEquals(100, testRace.getWind());
|
||||
// } catch (ParserConfigurationException | IOException | SAXException | ParseException | StreamedCourseXMLException e) {
|
||||
// e.printStackTrace();
|
||||
// fail();
|
||||
// }
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -19,8 +19,6 @@ public class RaceStatus extends AC35Data {
|
||||
private int raceType;
|
||||
private List<BoatStatus> boatStatuses;
|
||||
private static final double windDirectionScalar = 360.0 / 32768.0; // 0x8000 / 360
|
||||
private ArrayList<BoatStatus> boatStatuses;
|
||||
private static final double windDirectionScalar = 360.0 / 49152; // 0xC000 / 360
|
||||
|
||||
public RaceStatus(long currentTime, int raceID, int raceStatus, long expectedStartTime, int windDirection, int windSpeed, int raceType, List<BoatStatus> boatStatuses){
|
||||
super(MessageType.RACESTATUS);
|
||||
|
||||
@@ -66,7 +66,7 @@ public class Boat {
|
||||
*/
|
||||
public GPSCoordinate getWake() {
|
||||
double reverseHeading = getHeading() - 180;
|
||||
double wakeScale = 3;
|
||||
double wakeScale = 5;
|
||||
double distance = wakeScale * getVelocity();
|
||||
|
||||
GeodeticCalculator calc = new GeodeticCalculator();
|
||||
|
||||
Reference in New Issue
Block a user