@ -41,6 +41,7 @@ public class Race implements Runnable {
private MockOutput mockOutput ;
private MockOutput mockOutput ;
private static int boatOffset = 0 ;
private static int boatOffset = 0 ;
private int finished = 0 ;
private int finished = 0 ;
private List < GPSCoordinate > boundary ;
/ * *
/ * *
@ -50,7 +51,7 @@ public class Race implements Runnable {
* @param legs Number of marks in order that the boats pass in order to complete the race .
* @param legs Number of marks in order that the boats pass in order to complete the race .
* @param scaleFactor for race
* @param scaleFactor for race
* /
* /
public Race ( List < Boat > boats , List < Leg > legs , int raceID , int scaleFactor , MockOutput mockOutput ) {
public Race ( List < Boat > boats , List < Leg > legs , int raceID , int scaleFactor , MockOutput mockOutput , List < GPSCoordinate > boundary ) {
this . startingBoats = FXCollections . observableArrayList ( boats ) ;
this . startingBoats = FXCollections . observableArrayList ( boats ) ;
this . legs = legs ;
this . legs = legs ;
@ -58,6 +59,7 @@ public class Race implements Runnable {
this . raceId = raceID ;
this . raceId = raceID ;
this . scaleFactor = scaleFactor ;
this . scaleFactor = scaleFactor ;
this . mockOutput = mockOutput ;
this . mockOutput = mockOutput ;
this . boundary = boundary ;
//TODO refactor
//TODO refactor
this . startTime = System . currentTimeMillis ( ) + ( this . PRERACE_TIME / this . scaleFactor ) ;
this . startTime = System . currentTimeMillis ( ) + ( this . PRERACE_TIME / this . scaleFactor ) ;
@ -69,7 +71,7 @@ public class Race implements Runnable {
}
}
public Race ( RaceDataSource raceData , int scaleFactor , MockOutput mockOutput ) {
public Race ( RaceDataSource raceData , int scaleFactor , MockOutput mockOutput ) {
this ( raceData . getBoats ( ) , raceData . getLegs ( ) , raceData . getRaceId ( ) , scaleFactor , mockOutput );
this ( raceData . getBoats ( ) , raceData . getLegs ( ) , raceData . getRaceId ( ) , scaleFactor , mockOutput , raceData . getBoundary ( ) );
}
}
/ * *
/ * *
@ -298,12 +300,21 @@ public class Race implements Runnable {
boolean finish = boat . getCurrentLeg ( ) . getName ( ) . equals ( "Finish" ) ;
boolean finish = boat . getCurrentLeg ( ) . getName ( ) . equals ( "Finish" ) ;
if ( ! finish ) {
if ( ! finish ) {
boat . setHeading ( boat . calculateHeading ( ) ) ;
if ( ! GPSCoordinate . isInsideBoundary ( boat . getCurrentPosition ( ) , this . boundary ) ) {
//update boat's distance travelled
//todo - find the acceptable values for direction
boat . setDistanceTravelledInLeg ( totalDistanceTravelled ) ;
} else {
//Calculate boat's new position by adding the distance travelled onto the start point of the leg
VMG newHeading = boat . getPolars ( ) . calculateVMG ( 180 , 30 ,
boat . setCurrentPosition ( calculatePosition ( boat . getCurrentLeg ( ) . getStartMarker ( ) . getAverageGPSCoordinate ( ) ,
boat . calculateBearingToDestination ( ) ) ; //todo - get the wind speed from somewhere
totalDistanceTravelled , boat . calculateAzimuth ( ) ) ) ;
boat . setHeading ( newHeading . bearing ) ;
boat . setVelocity ( newHeading . speed ) ;
// boat.setHeading(boat.calculateHeading());
//update boat's distance travelled
boat . setDistanceTravelledInLeg ( totalDistanceTravelled ) ;
//Calculate boat's new position by adding the distance travelled onto the start point of the leg
boat . setCurrentPosition ( calculatePosition ( boat . getCurrentLeg ( ) . getStartMarker ( ) . getAverageGPSCoordinate ( ) ,
totalDistanceTravelled , boat . getHeading ( ) ) ) ;
}
}
}
}
}