Sails command now applies acceleration to boat
- Race only has control over speed while Sails command is not in action - This is governed by a default velocity property on the boat - Sails command returns control when sails are out and boat is up to speed - Speed never falls below 0 - Speed never goes above VMG velocity to prevent exploitation #story[1196]
This commit is contained in:
@@ -10,7 +10,6 @@ import java.util.Observable;
|
||||
public class SailsCommand extends ObserverCommand {
|
||||
private boolean sailsOut;
|
||||
private double goalVelocity;
|
||||
private double acceleration = 1;
|
||||
|
||||
public SailsCommand(MockRace race, MockBoat boat, boolean sailsOut) {
|
||||
super(race, boat);
|
||||
@@ -20,6 +19,8 @@ public class SailsCommand extends ObserverCommand {
|
||||
@Override
|
||||
public void execute() {
|
||||
this.boat.setSailsOut(this.sailsOut);
|
||||
boat.setVelocityDefault(false);
|
||||
|
||||
if(sailsOut) {
|
||||
// Accelerate to VMG speed
|
||||
double polarSpeed = NewPolars.calculateSpeed(race.getWindDirection(), race.getWindSpeed(), boat.getBearing());
|
||||
@@ -33,12 +34,18 @@ public class SailsCommand extends ObserverCommand {
|
||||
|
||||
@Override
|
||||
public void update(Observable o, Object arg) {
|
||||
double acceleration = 0.5;
|
||||
|
||||
if(sailsOut && boat.getCurrentSpeed() < goalVelocity) {
|
||||
// Apply acceleration
|
||||
boat.setCurrentSpeed(Math.min(goalVelocity, boat.getCurrentSpeed() + acceleration));
|
||||
} else if (!sailsOut && boat.getCurrentSpeed() > goalVelocity) {
|
||||
// Apply deceleration
|
||||
// Apply deceleration to strictly 0 speed
|
||||
boat.setCurrentSpeed(Math.max(0, boat.getCurrentSpeed() - acceleration));
|
||||
} else {
|
||||
System.out.println(goalVelocity + " " + boat.getCurrentSpeed());
|
||||
|
||||
// Release boat from SailsCommand control
|
||||
if(sailsOut) boat.setVelocityDefault(true);
|
||||
race.deleteObserver(this);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user