@ -8,6 +8,7 @@ import network.Messages.BoatLocation;
import network.Messages.BoatStatus ;
import network.Messages.Enums.BoatStatusEnum ;
import network.Messages.Enums.RaceStatusEnum ;
import network.Utils.AC35UnitConverter ;
import shared.dataInput.BoatDataSource ;
import shared.dataInput.RaceDataSource ;
import shared.dataInput.RegattaDataSource ;
@ -524,12 +525,22 @@ public class MockRace extends RaceState {
boolean gateCheck = boat . getCurrentLeg ( ) . getEndCompoundMark ( ) . getMark2 ( ) = = null | | boat . isBetweenGate ( boat . getCurrentLeg ( ) . getEndCompoundMark ( ) ) ;
Mark roundingMark = boat . getCurrentLeg ( ) . getEndCompoundMark ( ) . getMarkForRounding ( legBearing ) ;
System . out . println ( "boat rounding state: " + boat . getRoundingStatus ( ) ) ; //TEMP REMOVE
switch ( boat . getRoundingStatus ( ) ) {
case 0 : //hasn't started rounding
System . out . println ( "portside? " + boat . isPortSide ( roundingMark ) ) ; //TEMP REMOVE
System . out . println ( "passes line? " + GPSCoordinate . passesLine ( roundingMark . getPosition ( ) , roundingChecks . get ( 0 ) , boat . getPosition ( ) , legBearing ) ) ; //TEMP REMOVE
System . out . println ( "gatecheck? " + gateCheck ) ; //TEMP REMOVE
System . out . println ( "between gates? " + boat . isBetweenGate ( roundingMark , Mark . tempMark ( roundingChecks . get ( 0 ) ) ) ) ; //TEMP REMOVE
if ( boat . isPortSide ( roundingMark ) & &
GPSCoordinate . passesLine ( roundingMark . getPosition ( ) ,
roundingChecks . get ( 0 ) , boat . getPosition ( ) , legBearing ) & &
gateCheck & & boat . isBetweenGate ( roundingMark , Mark . tempMark ( roundingChecks . get ( 0 ) ) ) ) {
GPSCoordinate . passesLine (
roundingMark . getPosition ( ) ,
roundingChecks . get ( 0 ) ,
boat . getPosition ( ) ,
legBearing ) & &
gateCheck & &
boat . isBetweenGate ( roundingMark , Mark . tempMark ( roundingChecks . get ( 0 ) ) ) ) {
boat . increaseRoundingStatus ( ) ;
if ( boat . getCurrentLeg ( ) . getLegNumber ( ) + 2 > = getLegs ( ) . size ( ) ) {
//boat has finished race
@ -539,8 +550,10 @@ public class MockRace extends RaceState {
break ;
case 1 : //has been parallel to the mark;
if ( boat . isPortSide ( roundingMark ) & &
GPSCoordinate . passesLine ( roundingMark . getPosition ( ) ,
roundingChecks . get ( 1 ) , boat . getPosition ( ) ,
GPSCoordinate . passesLine (
roundingMark . getPosition ( ) ,
roundingChecks . get ( 1 ) ,
boat . getPosition ( ) ,
Bearing . fromDegrees ( legBearing . degrees ( ) - 90 ) ) & & //negative 90 from bearing because of port rounding
boat . isBetweenGate ( roundingMark , Mark . tempMark ( roundingChecks . get ( 1 ) ) ) ) {
boat . increaseRoundingStatus ( ) ;
@ -568,6 +581,8 @@ public class MockRace extends RaceState {
boolean gateCheck = boat . getCurrentLeg ( ) . getEndCompoundMark ( ) . getMark2 ( ) = = null | | boat . isBetweenGate ( boat . getCurrentLeg ( ) . getEndCompoundMark ( ) ) ;
Mark roundingMark = boat . getCurrentLeg ( ) . getEndCompoundMark ( ) . getMarkForRounding ( legBearing ) ;
System . out . println ( "boat rounding state: " + boat . getRoundingStatus ( ) ) ; //TEMP REMOVE
switch ( boat . getRoundingStatus ( ) ) {
case 0 : //hasn't started rounding
if ( boat . isStarboardSide ( roundingMark ) & &
@ -606,19 +621,27 @@ public class MockRace extends RaceState {
* /
protected void checkPosition ( MockBoat boat , long timeElapsed ) {
//The distance, in nautical miles, within which the boat needs to get in order to consider that it has reached the marker.
double epsilonNauticalMiles = boat . getCurrentLeg ( ) . getEndCompoundMark ( ) . getRoundingDistance ( ) ; //250 meters.
double epsilonMeters = boat . getCurrentLeg ( ) . getEndCompoundMark ( ) . getRoundingDistance ( ) ; //250 meters.
//System.out.println("epsilon dist meters: " + epsilonMeters);//TEMP REMOVE
//System.out.println("boat dist to next point NM: " + boat.calculateDistanceToNextMarker());//TEMP REMOVE
double epsilonNM = epsilonMeters / Constants . NMToMetersConversion ;
if ( boat . calculateDistanceToNextMarker ( ) < epsilonNauticalMiles ) {
//System.out.println("epsilon NM: " + epsilonNM);//TEMP REMOVE
if ( boat . calculateDistanceToNextMarker ( ) < epsilonNM ) {
//Boat is within an acceptable distance from the mark.
GPSCoordinate startDirectionLinePoint = boat . getCurrentLeg ( ) . getStartCompoundMark ( ) . getMark1Position ( ) ;
GPSCoordinate endDirectionLinePoint = boat . getCurrentLeg ( ) . getEndCompoundMark ( ) . get Mark1Position ( ) ;
GPSCoordinate startDirectionLinePoint = boat . getCurrentLeg ( ) . getStartCompoundMark ( ) . get AverageGPSCoordinate ( ) ;
GPSCoordinate endDirectionLinePoint = boat . getCurrentLeg ( ) . getEndCompoundMark ( ) . get AverageGPSCoordinate ( ) ;
Bearing bearingOfDirectionLine = GPSCoordinate . calculateBearing ( startDirectionLinePoint , endDirectionLinePoint ) ;
//use the direction line to create three invisible points that act as crossover lines a boat must cross
//to round a mark
double bearingToAdd ;
//System.out.println("leg: " + boat.getCurrentLeg().getName() + " has bearing DL of: " + bearingOfDirectionLine.degrees());//TEMP REMOVE
if ( boat . getCurrentLeg ( ) . getEndCompoundMark ( ) . getRoundingType ( ) = = RoundingType . Port | |
boat . getCurrentLeg ( ) . getEndCompoundMark ( ) . getRoundingType ( ) = = RoundingType . SP ) {
bearingToAdd = 90 ;
@ -626,25 +649,32 @@ public class MockRace extends RaceState {
bearingToAdd = - 90 ;
}
GPSCoordinate roundCheck1 = GPSCoordinate . calculateNewPosition ( endDirectionLinePoint ,
epsilonNauticalMiles , Azimuth . fromDegrees ( bearingOfDirectionLine . degrees ( ) + bearingToAdd ) ) ;
//System.out.println("so new bearing is " + (bearingToAdd + bearingOfDirectionLine.degrees()));//TEMP REMOVE
GPSCoordinate roundCheck1 = GPSCoordinate . calculateNewPosition (
endDirectionLinePoint ,
epsilonMeters ,
Azimuth . fromDegrees ( bearingOfDirectionLine . degrees ( ) + bearingToAdd ) ) ;
//System.out.println("this has a rounding coordinate of (" + roundCheck1.getLongitude() + ", " + roundCheck1.getLatitude() + ")");//TEMP REMOVE
GPSCoordinate roundCheck2 ;
try {
Leg nextLeg = getLegs ( ) . get ( getLegs ( ) . indexOf ( boat . getCurrentLeg ( ) ) + 1 ) ;
GPSCoordinate startNextDirectionLinePoint = nextLeg . getStartCompoundMark ( ) . get Mark1Position ( ) ;
GPSCoordinate endNextDirectionLinePoint = nextLeg . getEndCompoundMark ( ) . get Mark1Position ( ) ;
GPSCoordinate startNextDirectionLinePoint = nextLeg . getStartCompoundMark ( ) . get AverageGPSCoordinate ( ) ;
GPSCoordinate endNextDirectionLinePoint = nextLeg . getEndCompoundMark ( ) . get AverageGPSCoordinate ( ) ;
Bearing bearingOfNextDirectionLine = GPSCoordinate . calculateBearing ( startNextDirectionLinePoint , endNextDirectionLinePoint ) ;
roundCheck2 = GPSCoordinate . calculateNewPosition ( endDirectionLinePoint ,
epsilonNauticalMiles , Azimuth . fromDegrees ( bearingOfNextDirectionLine . degrees ( ) + bearingToAdd ) ) ;
roundCheck2 = GPSCoordinate . calculateNewPosition (
endDirectionLinePoint ,
epsilonMeters ,
Azimuth . fromDegrees ( bearingOfNextDirectionLine . degrees ( ) + bearingToAdd ) ) ;
} catch ( NullPointerException e ) {
//this is caused by the last leg not being having a leg after it
roundCheck2 = roundCheck1 ;
}
List < GPSCoordinate > roundingChecks = new ArrayList < GPSCoordinate > ( Arrays . asList ( roundCheck1 , roundCheck2 ) ) ;
List < GPSCoordinate > roundingChecks = new ArrayList < > ( Arrays . asList ( roundCheck1 , roundCheck2 ) ) ;
switch ( boat . getCurrentLeg ( ) . getEndCompoundMark ( ) . getRoundingType ( ) ) {
case SP : //Not yet implemented so these gates will be rounded port side
@ -657,6 +687,8 @@ public class MockRace extends RaceState {
break ;
}
System . out . println ( "resultant boat rounding state: " + boat . getRoundingStatus ( ) ) ; //TEMP REMOVE
//Check if the boat has finished or stopped racing.
if ( this . isLastLeg ( boat . getCurrentLeg ( ) ) ) {