From 1a780d6955ca82fa5b0aac8a6a566ee6a4ec5d8b Mon Sep 17 00:00:00 2001 From: Erika Savell Date: Wed, 10 May 2017 23:31:32 +1200 Subject: [PATCH] Fixed spread starting positions being reset at start of race #story[881] --- mock/src/main/java/seng302/Model/Race.java | 29 +++++++++------------- 1 file changed, 12 insertions(+), 17 deletions(-) diff --git a/mock/src/main/java/seng302/Model/Race.java b/mock/src/main/java/seng302/Model/Race.java index a1775ecc..334d1fbe 100644 --- a/mock/src/main/java/seng302/Model/Race.java +++ b/mock/src/main/java/seng302/Model/Race.java @@ -30,8 +30,8 @@ public class Race implements Runnable { protected List legs; protected int boatsFinished = 0; protected long totalTimeElapsed; - protected int scaleFactor = 25; - protected int PRERACE_TIME = 1800; //time in milliseconds to pause during pre-race. At the moment, 3 minutes + protected int scaleFactor = 20; + protected int PRERACE_TIME = 18000; //time in milliseconds to pause during pre-race. At the moment, 3 minutes private long startTime; protected boolean countdownFinish = false; protected boolean runRace = true; @@ -42,7 +42,6 @@ public class Race implements Runnable { private static int boatOffset = 0; private int finished = 0; - /** * Initailiser for Race * @@ -106,23 +105,17 @@ public class Race implements Runnable { protected void countdownTimer() { AnimationTimer timer = new AnimationTimer() { long currentTime = System.currentTimeMillis(); - //long startTime = currentTime + (PRERACE_TIME / scaleFactor); - //long minutes; - //long hours; long timeLeft; @Override public void handle(long arg0) { timeLeft = startTime - currentTime; ArrayList boatStatuses = new ArrayList<>(); - //For each boat, we update it's position, and generate a BoatLocationMessage. + //For each boat, we update its 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(), 0); - boatStatuses.add(new BoatStatus(boat.getSourceID(), - boat.getCurrentLeg().getLegNumber() >= 0 ? BoatStatusEnum.RACING : BoatStatusEnum.DNF, boat.getCurrentLeg().getLegNumber())); - } + mockOutput.parseBoatLocation(boat.getSourceID(), boat.getCurrentPosition().getLatitude(), boat.getCurrentPosition().getLongitude(), boat.getHeading(), 0); + boatStatuses.add(new BoatStatus(boat.getSourceID(), BoatStatusEnum.RACING, boat.getCurrentLeg().getLegNumber())); } boatOffset = (boatOffset + 1) % (startingBoats.size()); @@ -145,7 +138,6 @@ public class Race implements Runnable { } }; timer.start(); - //countdownFinish = true; } /** @@ -160,6 +152,7 @@ public class Race implements Runnable { boat.setStarted(true); } + new AnimationTimer() { //Start time of loop. long timeRaceStarted = System.currentTimeMillis(); @@ -171,7 +164,7 @@ public class Race implements Runnable { long currentTime = System.currentTimeMillis(); //Update the total elapsed time. totalTimeElapsed = currentTime - timeRaceStarted; - ArrayList boatStatuses = new ArrayList(); + ArrayList boatStatuses = new ArrayList<>(); finished = 0; //For each boat, we update it's position, and generate a BoatLocationMessage. for (int i = 0; i < startingBoats.size(); i++) { @@ -208,19 +201,21 @@ public class Race implements Runnable { } public void initialiseBoats() { Leg officialStart = legs.get(0); + String name = officialStart.getName(); + Marker endMark = officialStart.getEndCompoundMark(); ArrayList startingPositions = getSpreadStartingPositions(); for (int i = 0; i < startingBoats.size(); i++) { Boat boat = startingBoats.get(i); if (boat != null) { + Leg newLeg = new Leg(name, new Marker(startingPositions.get(i)), endMark, 0); + boat.setCurrentLeg(newLeg); boat.setScaledVelocity(boat.getVelocity() * scaleFactor); boat.setCurrentPosition(startingPositions.get(i)); - boat.setCurrentLeg(officialStart); boat.setHeading(boat.calculateHeading()); } } } - /** * Creates a list of starting positions for the different boats, so they do not appear cramped at the start line * @@ -231,7 +226,6 @@ public class Race implements Runnable { int nBoats = startingBoats.size(); Marker compoundMark = legs.get(0).getStartCompoundMark(); - GeodeticCalculator initialCalc = new GeodeticCalculator(); initialCalc.setStartingGeographicPoint(compoundMark.getMark1().getLongitude(), compoundMark.getMark1().getLatitude()); initialCalc.setDestinationGeographicPoint(compoundMark.getMark2().getLongitude(), compoundMark.getMark2().getLatitude()); @@ -249,6 +243,7 @@ public class Race implements Runnable { Point2D position = positionCalc.getDestinationGeographicPoint(); positions.add(new GPSCoordinate(position.getY(), position.getX())); + positionCalc = new GeodeticCalculator(); positionCalc.setStartingGeographicPoint(position); }