diff --git a/mock/src/main/java/seng302/Model/Race.java b/mock/src/main/java/seng302/Model/Race.java index 99a78e87..a5de88c9 100644 --- a/mock/src/main/java/seng302/Model/Race.java +++ b/mock/src/main/java/seng302/Model/Race.java @@ -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 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 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; + } +} \ No newline at end of file diff --git a/mock/src/test/java/seng302/Model/RaceTest.java b/mock/src/test/java/seng302/Model/RaceTest.java index 6de72f22..7365e320 100644 --- a/mock/src/test/java/seng302/Model/RaceTest.java +++ b/mock/src/test/java/seng302/Model/RaceTest.java @@ -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(); +// } } diff --git a/network/src/main/java/seng302/Networking/Messages/RaceStatus.java b/network/src/main/java/seng302/Networking/Messages/RaceStatus.java index 63c41e69..89c7b90c 100644 --- a/network/src/main/java/seng302/Networking/Messages/RaceStatus.java +++ b/network/src/main/java/seng302/Networking/Messages/RaceStatus.java @@ -19,8 +19,6 @@ public class RaceStatus extends AC35Data { private int raceType; private List boatStatuses; private static final double windDirectionScalar = 360.0 / 32768.0; // 0x8000 / 360 - private ArrayList 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 boatStatuses){ super(MessageType.RACESTATUS); diff --git a/visualiser/src/main/java/seng302/Model/Boat.java b/visualiser/src/main/java/seng302/Model/Boat.java index 5715927b..6e553318 100644 --- a/visualiser/src/main/java/seng302/Model/Boat.java +++ b/visualiser/src/main/java/seng302/Model/Boat.java @@ -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();