Merge remote-tracking branch 'origin/issue58_sails_collision_fix' into story1297_sails
This commit is contained in:
@@ -61,7 +61,7 @@ public class MockRace extends RaceState {
|
|||||||
*/
|
*/
|
||||||
private Polars polars;
|
private Polars polars;
|
||||||
|
|
||||||
private ActiveObserverCommand activeObserverCommand;
|
private Map<Integer, ActiveObserverCommand> activeObserverCommands;
|
||||||
|
|
||||||
private long racePreStartTime = Constants.RacePreStartTime;
|
private long racePreStartTime = Constants.RacePreStartTime;
|
||||||
|
|
||||||
@@ -87,7 +87,7 @@ public class MockRace extends RaceState {
|
|||||||
this.setRaceDataSource(raceDataSource);
|
this.setRaceDataSource(raceDataSource);
|
||||||
this.setRegattaDataSource(regattaDataSource);
|
this.setRegattaDataSource(regattaDataSource);
|
||||||
|
|
||||||
this.activeObserverCommand = new ActiveObserverCommand();
|
this.activeObserverCommands = new HashMap<>();
|
||||||
this.polars = polars;
|
this.polars = polars;
|
||||||
this.scaleFactor = timeScale;
|
this.scaleFactor = timeScale;
|
||||||
|
|
||||||
@@ -132,6 +132,7 @@ public class MockRace extends RaceState {
|
|||||||
getRaceDataSource().getParticipants().add(sourceID);
|
getRaceDataSource().getParticipants().add(sourceID);
|
||||||
|
|
||||||
this.boats.add(mockBoat);
|
this.boats.add(mockBoat);
|
||||||
|
this.activeObserverCommands.put(boat.getSourceID(), new ActiveObserverCommand());
|
||||||
|
|
||||||
getRaceDataSource().incrementSequenceNumber();
|
getRaceDataSource().incrementSequenceNumber();
|
||||||
|
|
||||||
@@ -752,11 +753,11 @@ public class MockRace extends RaceState {
|
|||||||
super.setChanged();
|
super.setChanged();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void addVelocityCommand(ObserverCommand c) {
|
public void addVelocityCommand(ObserverCommand c, int boatId) {
|
||||||
this.activeObserverCommand.changeVelocityCommand(this, c);
|
this.activeObserverCommands.get(boatId).changeVelocityCommand(this, c);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void addAngularCommand(ObserverCommand c) {
|
public void addAngularCommand(ObserverCommand c, int boatId) {
|
||||||
this.activeObserverCommand.changeAngularCommand(this, c);
|
this.activeObserverCommands.get(boatId).changeAngularCommand(this, c);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -36,6 +36,7 @@ public class CollisionCommand extends ObserverCommand {
|
|||||||
@Override
|
@Override
|
||||||
public void update(Observable o, Object arg) {
|
public void update(Observable o, Object arg) {
|
||||||
if(GPSCoordinate.calculateDistanceMeters(boat.getPosition(), startingPosition) < distance) {
|
if(GPSCoordinate.calculateDistanceMeters(boat.getPosition(), startingPosition) < distance) {
|
||||||
|
boat.setVelocityDefault(false);
|
||||||
boat.setPosition(GPSCoordinate.calculateNewPosition(boat.getPosition(), 3, azimuth));
|
boat.setPosition(GPSCoordinate.calculateNewPosition(boat.getPosition(), 3, azimuth));
|
||||||
} else {
|
} else {
|
||||||
race.deleteObserver(this);
|
race.deleteObserver(this);
|
||||||
|
|||||||
@@ -13,7 +13,7 @@ public class SailsCommand extends ObserverCommand {
|
|||||||
|
|
||||||
public SailsCommand(MockRace race, MockBoat boat, boolean sailsOut) {
|
public SailsCommand(MockRace race, MockBoat boat, boolean sailsOut) {
|
||||||
super(race, boat);
|
super(race, boat);
|
||||||
race.addVelocityCommand(this);
|
race.addVelocityCommand(this, boat.getSourceID());
|
||||||
this.sailsOut = sailsOut;
|
this.sailsOut = sailsOut;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -37,6 +37,8 @@ public class SailsCommand extends ObserverCommand {
|
|||||||
public void update(Observable o, Object arg) {
|
public void update(Observable o, Object arg) {
|
||||||
double acceleration = 0.5;
|
double acceleration = 0.5;
|
||||||
|
|
||||||
|
if (!boat.isColliding()) {
|
||||||
|
boat.setVelocityDefault(false);
|
||||||
if (sailsOut && boat.getCurrentSpeed() < goalVelocity) {
|
if (sailsOut && boat.getCurrentSpeed() < goalVelocity) {
|
||||||
boat.setCurrentSpeed(Math.min(goalVelocity, boat.getCurrentSpeed() + acceleration));
|
boat.setCurrentSpeed(Math.min(goalVelocity, boat.getCurrentSpeed() + acceleration));
|
||||||
} else if (!sailsOut && boat.getCurrentSpeed() > goalVelocity) {
|
} else if (!sailsOut && boat.getCurrentSpeed() > goalVelocity) {
|
||||||
@@ -49,3 +51,4 @@ public class SailsCommand extends ObserverCommand {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -22,7 +22,7 @@ public class TackGybeCommand extends ObserverCommand {
|
|||||||
*/
|
*/
|
||||||
public TackGybeCommand(MockRace race, MockBoat boat) {
|
public TackGybeCommand(MockRace race, MockBoat boat) {
|
||||||
super(race, boat);
|
super(race, boat);
|
||||||
race.addAngularCommand(this);
|
race.addAngularCommand(this, boat.getSourceID());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -24,7 +24,7 @@ public class VMGCommand extends ObserverCommand {
|
|||||||
*/
|
*/
|
||||||
public VMGCommand(MockRace race, MockBoat boat) {
|
public VMGCommand(MockRace race, MockBoat boat) {
|
||||||
super(race, boat);
|
super(race, boat);
|
||||||
race.addAngularCommand(this);
|
race.addAngularCommand(this, boat.getSourceID());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -20,7 +20,7 @@ public class WindCommand extends ObserverCommand {
|
|||||||
*/
|
*/
|
||||||
public WindCommand(MockRace race, MockBoat boat, boolean upwind) {
|
public WindCommand(MockRace race, MockBoat boat, boolean upwind) {
|
||||||
super(race, boat);
|
super(race, boat);
|
||||||
race.addAngularCommand(this);
|
race.addAngularCommand(this, boat.getSourceID());
|
||||||
this.direction = upwind? -1 : 1;
|
this.direction = upwind? -1 : 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user