|
|
|
|
@ -1,5 +1,7 @@
|
|
|
|
|
package mock.model;
|
|
|
|
|
|
|
|
|
|
import mock.model.commandFactory.ActiveObserverCommand;
|
|
|
|
|
import mock.model.commandFactory.ObserverCommand;
|
|
|
|
|
import mock.model.wind.WindGenerator;
|
|
|
|
|
import mock.model.collider.ColliderRegistry;
|
|
|
|
|
import network.Messages.Enums.BoatStatusEnum;
|
|
|
|
|
@ -59,6 +61,8 @@ public class MockRace extends RaceState {
|
|
|
|
|
*/
|
|
|
|
|
private Polars polars;
|
|
|
|
|
|
|
|
|
|
private ActiveObserverCommand activeObserverCommand;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
@ -76,6 +80,7 @@ public class MockRace extends RaceState {
|
|
|
|
|
this.setRaceDataSource(raceDataSource);
|
|
|
|
|
this.setRegattaDataSource(regattaDataSource);
|
|
|
|
|
|
|
|
|
|
this.activeObserverCommand = new ActiveObserverCommand();
|
|
|
|
|
this.polars = polars;
|
|
|
|
|
this.scaleFactor = timeScale;
|
|
|
|
|
|
|
|
|
|
@ -350,69 +355,24 @@ public class MockRace extends RaceState {
|
|
|
|
|
//Checks if the current boat has finished the race or not.
|
|
|
|
|
boolean finish = this.isLastLeg(boat.getCurrentLeg());
|
|
|
|
|
|
|
|
|
|
if (!finish && totalElapsedMilliseconds >= updatePeriodMilliseconds && boat.isSailsOut()) {
|
|
|
|
|
|
|
|
|
|
if (boat.getCurrentSpeed() == 0) {
|
|
|
|
|
newOptimalVMG(boat);
|
|
|
|
|
boat.setBearing(boat.calculateBearingToNextMarker());
|
|
|
|
|
}
|
|
|
|
|
if (!finish && totalElapsedMilliseconds >= updatePeriodMilliseconds) {
|
|
|
|
|
|
|
|
|
|
setBoatSpeed(boat);
|
|
|
|
|
if(boat.isVelocityDefault()) setBoatSpeed(boat);
|
|
|
|
|
|
|
|
|
|
//Calculates the distance travelled, in meters, in the current timeslice.
|
|
|
|
|
double distanceTravelledMeters = boat.calculateMetersTravelled(updatePeriodMilliseconds);
|
|
|
|
|
|
|
|
|
|
//Scale it.
|
|
|
|
|
distanceTravelledMeters = distanceTravelledMeters * this.scaleFactor;
|
|
|
|
|
double distanceTravelledMeters = boat.calculateMetersTravelled(updatePeriodMilliseconds) * this.scaleFactor;
|
|
|
|
|
|
|
|
|
|
checkPosition(boat, totalElapsedMilliseconds);
|
|
|
|
|
|
|
|
|
|
//Move the boat forwards that many meters, and advances its time counters by enough milliseconds.
|
|
|
|
|
boat.moveForwards(distanceTravelledMeters);
|
|
|
|
|
boat.setTimeSinceTackChange(boat.getTimeSinceTackChange() + updatePeriodMilliseconds);
|
|
|
|
|
|
|
|
|
|
if (boat.getAutoVMG()) {
|
|
|
|
|
newOptimalVMG(boat);
|
|
|
|
|
boat.setAutoVMG(false);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
boat.setCurrentSpeed(0);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
this.updateEstimatedTime(boat);
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void newOptimalVMG(MockBoat boat) {
|
|
|
|
|
long tackPeriod = 1000;
|
|
|
|
|
if (boat.getTimeSinceTackChange() > tackPeriod) {
|
|
|
|
|
//System.out.println("optim called");
|
|
|
|
|
//Calculate the new VMG.
|
|
|
|
|
// VMG newVMG = boat.getPolars().calculateVMG(
|
|
|
|
|
// this.getWindDirection(),
|
|
|
|
|
// this.getWindSpeed(),
|
|
|
|
|
// boat.calculateBearingToNextMarker(),
|
|
|
|
|
// Bearing.fromDegrees(0d),
|
|
|
|
|
// Bearing.fromDegrees(359.99999d));
|
|
|
|
|
|
|
|
|
|
VMG newVMG = NewPolars.setBestVMG(this.getWindDirection(), this.getWindSpeed(), boat.getBearing());
|
|
|
|
|
//System.out.println(newVMG);
|
|
|
|
|
//If the new vmg improves velocity, use it.
|
|
|
|
|
/*if (improvesVelocity(boat, newVMG)) {
|
|
|
|
|
}*/
|
|
|
|
|
boat.setVMG(newVMG);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void setBoatSpeed(MockBoat boat) {
|
|
|
|
|
// VMG vmg = boat.getPolars().calculateVMG(
|
|
|
|
|
// this.getWindDirection(),
|
|
|
|
|
// this.getWindSpeed(),
|
|
|
|
|
// boat.getBearing(),
|
|
|
|
|
// Bearing.fromDegrees(boat.getBearing().degrees() - 1),
|
|
|
|
|
// Bearing.fromDegrees(boat.getBearing().degrees() + 1));
|
|
|
|
|
//VMG vmg = boat.getPolars().setBestVMG(this.getWindDirection(), this.getWindSpeed(), boat.getBearing());
|
|
|
|
|
VMG vmg = new VMG(NewPolars.calculateSpeed(
|
|
|
|
|
this.getWindDirection(),
|
|
|
|
|
this.getWindSpeed(),
|
|
|
|
|
@ -735,4 +695,18 @@ public class MockRace extends RaceState {
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Made public, so race logic can control it
|
|
|
|
|
*/
|
|
|
|
|
public void setChanged() {
|
|
|
|
|
super.setChanged();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void addVelocityCommand(ObserverCommand c) {
|
|
|
|
|
this.activeObserverCommand.changeVelocityCommand(this, c);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void addAngularCommand(ObserverCommand c) {
|
|
|
|
|
this.activeObserverCommand.changeAngularCommand(this, c);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|