Fixed wind direction code missing due to past merges (?)
#story[882]
This commit is contained in:
@@ -33,6 +33,8 @@ public class Race implements Runnable {
|
||||
private int raceId;
|
||||
private int dnfChance = 0; //percentage chance a boat fails at each checkpoint
|
||||
private MockOutput mockOutput;
|
||||
private int windDir;
|
||||
private int changeWind = 4;
|
||||
|
||||
public Race(RaceDataSource raceData, MockOutput mockOutput) {
|
||||
this.startingBoats = FXCollections.observableArrayList(raceData.getBoats());
|
||||
@@ -48,10 +50,30 @@ public class Race implements Runnable {
|
||||
* Runnable for the thread.
|
||||
*/
|
||||
public void run() {
|
||||
initialiseWindDir();
|
||||
initialiseBoats();
|
||||
countdownTimer.start();
|
||||
}
|
||||
|
||||
protected void initialiseWindDir(){
|
||||
windDir = new Random().nextInt(65535+1);
|
||||
}
|
||||
|
||||
protected void changeWindDir(){
|
||||
int r = new Random().nextInt(changeWind)+1;
|
||||
if(r==1){
|
||||
windDir+=100;
|
||||
} else if (r==2){
|
||||
windDir-=100;
|
||||
}
|
||||
if (windDir > 65535){
|
||||
windDir -= 65535;
|
||||
}
|
||||
if (windDir < 0){
|
||||
windDir += 65535;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Parse the marker boats through mock output
|
||||
*/
|
||||
@@ -80,7 +102,7 @@ public class Race implements Runnable {
|
||||
raceTimer.start();
|
||||
stop();
|
||||
}
|
||||
|
||||
changeWindDir();
|
||||
ArrayList<BoatStatus> boatStatuses = new ArrayList<>();
|
||||
for (Boat boat : startingBoats) {
|
||||
mockOutput.parseBoatLocation(boat.getSourceID(), boat.getCurrentPosition().getLatitude(),
|
||||
@@ -90,7 +112,7 @@ public class Race implements Runnable {
|
||||
parseMarks();
|
||||
|
||||
int raceStatusNumber = timeLeft <= 60000 / scaleFactor && timeLeft > 0? 2 : 1;
|
||||
RaceStatus raceStatus = new RaceStatus(System.currentTimeMillis(), raceId, raceStatusNumber, startTime, 0, 2300, 1, boatStatuses);
|
||||
RaceStatus raceStatus = new RaceStatus(System.currentTimeMillis(), raceId, raceStatusNumber, startTime, windDir, 2300, 1, boatStatuses);
|
||||
mockOutput.parseRaceStatus(raceStatus);
|
||||
|
||||
currentTime = System.currentTimeMillis();
|
||||
@@ -132,9 +154,10 @@ public class Race implements Runnable {
|
||||
stop();
|
||||
}
|
||||
}
|
||||
changeWindDir();
|
||||
parseMarks();
|
||||
boatOffset = (boatOffset + 1) % (startingBoats.size());
|
||||
RaceStatus raceStatus = new RaceStatus(System.currentTimeMillis(), raceId, 3, startTime, 0, 2300, 2, boatStatuses);
|
||||
RaceStatus raceStatus = new RaceStatus(System.currentTimeMillis(), raceId, 3, startTime, windDir, 2300, 2, boatStatuses);
|
||||
mockOutput.parseRaceStatus(raceStatus);
|
||||
}
|
||||
}
|
||||
@@ -276,6 +299,22 @@ public class Race implements Runnable {
|
||||
}
|
||||
}
|
||||
|
||||
protected void setWindDir(int wind){
|
||||
if (wind>=0 && wind<=65535){
|
||||
windDir = wind;
|
||||
}
|
||||
}
|
||||
|
||||
protected void setChangeWind(int changeVal){
|
||||
if (changeVal>=0){
|
||||
changeWind = changeVal;
|
||||
}
|
||||
}
|
||||
|
||||
protected int getWind(){
|
||||
return windDir;
|
||||
}
|
||||
|
||||
protected boolean doNotFinish() {
|
||||
Random rand = new Random();
|
||||
return rand.nextInt(100) < dnfChance;
|
||||
|
||||
Reference in New Issue
Block a user