Merge remote-tracking branch 'origin/develop' into Story66_Collision

# Conflicts:
#	src/main/java/seng302/gameServer/GameState.java
#	src/main/java/seng302/model/Yacht.java
#	src/main/java/seng302/model/mark/MarkOrder.java
#	src/main/java/seng302/visualiser/GameClient.java
This commit is contained in:
Zhi You Tan
2017-08-10 20:23:56 +12:00
14 changed files with 436 additions and 276 deletions
@@ -1,8 +1,9 @@
package seng302.model.mark;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import seng302.model.GeoPoint;
import seng302.utilities.GeoUtility;
public class CompoundMark {
@@ -10,18 +11,17 @@ public class CompoundMark {
private String name;
private List<Mark> marks = new ArrayList<>();
private GeoPoint midPoint;
public CompoundMark(int markID, String name) {
this.compoundMarkId = markID;
public CompoundMark(int markID, String name, List<Mark> marks) {
this.compoundMarkId = markID;
this.name = name;
}
public void addSubMarks(Mark... marks) {
this.marks.addAll(Arrays.asList(marks));
}
public void addSubMarks(List<Mark> marks) {
this.marks.addAll(marks);
this.marks.addAll(marks);
if (marks.size() > 1) {
this.midPoint = GeoUtility.getDirtyMidPoint(marks.get(0), marks.get(1));
} else {
this.midPoint = marks.get(0);
}
}
/**
@@ -68,6 +68,16 @@ public class CompoundMark {
}
}
/**
* NOTE: This is a 'dirty' mid point as it is simply calculated as an xy point would be.
* NO CHECKING FOR LAT / LNG WRAPPING IS DONE IN CREATION OF THIS MIDPOINT
*
* @return GeoPoint of the midpoint of the two marks, or the one mark if there is only one
*/
public GeoPoint getMidPoint() {
return midPoint;
}
/**
* Returns whether or not this CompoundMark is a Gate. It is generally cleaner to program to a
* specific singleMark or the list of marks.
@@ -87,38 +97,6 @@ public class CompoundMark {
return marks;
}
// @Override
// public boolean equals(Object other) {
// if (other == null) {
// return false;
// }
//
// if (!(other instanceof Mark)){
// return false;
// }
//
// Mark otherMark = (Mark) other;
//
// if (otherMark.getLat() != getLat() || otherMark.getLongitude() != getLongitude()) {
// return false;
// }
//
// if (otherMark.getCompoundMarkID() != getCompoundMarkID()){
// return false;
// }
//
// if (otherMark.getId() != getId()){
// return false;
// }
//
// if (!otherMark.getName().equals(name)){
// return false;
// }
//
// return true;
// }
@Override
public int hashCode() {
int hash = 0;
+31 -33
View File
@@ -21,7 +21,7 @@ import java.util.*;
* Class to hold the order of the marks in the race.
*/
public class MarkOrder {
private List<Mark> raceMarkOrder;
private List<CompoundMark> raceMarkOrder;
private Logger logger = LoggerFactory.getLogger(MarkOrder.class);
private Set<Mark> allMarks;
@@ -33,7 +33,7 @@ public class MarkOrder {
* @return An ordered list of marks in the race
* OR null if the mark order could not be loaded
*/
public List<Mark> getMarkOrder(){
public List<CompoundMark> getMarkOrder(){
if (raceMarkOrder == null){
logger.warn("Race order accessed but not instantiated");
return null;
@@ -43,26 +43,35 @@ public class MarkOrder {
}
/**
* Returns the mark in the race after the previous mark
* @param position The current race position
* @return the next race position
* OR null if there is no position
* @param seqID The seqID of the current mark the boat is heading to
* @return A Boolean indicating if this coming mark is the last one (finish line)
*/
public RacePosition getNextPosition(RacePosition position){
Mark previousMark = position.getNextMark();
Mark nextMark;
public Boolean isLastMark(Integer seqID) {
return seqID == raceMarkOrder.size() - 1;
}
if (position.getPositionIndex() + 1 >= raceMarkOrder.size() - 1){
RacePosition nextRacePosition = new RacePosition(raceMarkOrder.size() - 1, null, previousMark);
nextRacePosition.setFinishingLeg();
/**
* @param currentSeqID The seqID of the current mark the boat is heading to
* @return The mark last passed
* @throws IndexOutOfBoundsException if there is no next mark.
* Check seqID != 0 first
*/
public CompoundMark getPreviousMark(Integer currentSeqID) throws IndexOutOfBoundsException{
return raceMarkOrder.get(currentSeqID - 1);
}
return nextRacePosition;
}
public CompoundMark getCurrentMark(Integer currentSeqID) {
return raceMarkOrder.get(currentSeqID);
}
Integer nextPositionIndex = position.getPositionIndex() + 1;
RacePosition nextRacePosition = new RacePosition(nextPositionIndex, raceMarkOrder.get(nextPositionIndex), previousMark);
return nextRacePosition;
/**
* @param currentSeqID The seqID of the current mark the boat is heading to
* @return The mark following the mark that the boat is heading to
* @throws IndexOutOfBoundsException if there is no next mark.
* Check using {@link #isLastMark(Integer)}
*/
public CompoundMark getNextMark(Integer currentSeqID) throws IndexOutOfBoundsException{
return raceMarkOrder.get(currentSeqID + 1);
}
public Set<Mark> getAllMarks(){
@@ -74,7 +83,7 @@ public class MarkOrder {
* @param xml An AC35 RaceXML
* @return An ordered list of marks in the race
*/
private List<Mark> loadRaceOrderFromXML(String xml){
private List<CompoundMark> loadRaceOrderFromXML(String xml){
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
DocumentBuilder db;
@@ -95,11 +104,11 @@ public class MarkOrder {
logger.debug("Loaded RaceXML for mark order");
List<Corner> corners = data.getMarkSequence();
Map<Integer, CompoundMark> marks = data.getCompoundMarks();
List<Mark> course = new ArrayList<>();
List<CompoundMark> course = new ArrayList<>();
for (Corner corner : corners){
CompoundMark compoundMark = marks.get(corner.getCompoundMarkID());
course.add(compoundMark.getMarks().get(0));
course.add(compoundMark);
allMarks.addAll(compoundMark.getMarks());
}
@@ -109,17 +118,6 @@ public class MarkOrder {
return null;
}
/**
* @return The first position in the race
*/
public RacePosition getFirstPosition(){
if (raceMarkOrder.size() > 0){
return new RacePosition(-1, raceMarkOrder.get(0), null);
}
return null;
}
/**
* Load the raceXML and mark order
*/
@@ -136,4 +134,4 @@ public class MarkOrder {
}
raceMarkOrder = loadRaceOrderFromXML(raceXML);
}
}
}
@@ -1,55 +0,0 @@
package seng302.model.mark;
/**
* Represents a boats position between two marks
*/
public class RacePosition {
private Integer positionIndex;
private Mark nextMark;
private Mark previousMark;
private Boolean isFinishingLeg;
public RacePosition(Integer positionIndex, Mark nextMark, Mark previousMark){
this.positionIndex = positionIndex;
this.nextMark = nextMark;
this.previousMark = previousMark;
isFinishingLeg = false;
}
/**
* @return The position of the boat (0...number of marks in race - 1)
*/
public Integer getPositionIndex(){
return positionIndex;
}
/**
* @return The mark the boat is heading to
* will return NULL if this is the finishing legg
*/
public Mark getNextMark(){
return nextMark;
}
/**
* @return The mark the boat is heading away from,
* Will return NULL if this is the starting leg
*/
public Mark getPreviousMark(){
return previousMark;
}
/**
* Sets a flag that this is the last leg in the race
*/
public void setFinishingLeg(){
isFinishingLeg = true;
}
/**
* @return true if this is the last leg in the race
*/
public boolean getIsFinishingLeg() {
return isFinishingLeg;
}
}