Added per map max player count. Handles case when map cannot fit players behind start mark. Added initial implementation for spacing out yachts.

#implement  #story[1275]
This commit is contained in:
Calum
2017-09-27 02:04:24 +13:00
parent ab5ad58237
commit e9881bb24a
4 changed files with 109 additions and 47 deletions
@@ -254,8 +254,8 @@ public class MainServerThread implements Runnable, ClientConnectionDelegate {
}
});
} else {
serverToClientThread.addConnectionListener(this::sendSetupMessages);
MessageFactory.updateBoats(new ArrayList<>(GameState.getYachts().values()));
serverToClientThread.addConnectionListener(this::sendSetupMessages);
}
serverToClientThreads.add(serverToClientThread);
serverToClientThread.addDisconnectListener(this::clientDisconnected);
@@ -366,13 +366,75 @@ public class MainServerThread implements Runnable, ClientConnectionDelegate {
// boatIndex++;
// }
final double SEPARATION = 50.0; // distance apart in meters
// final double SEPARATION = 50.0; // distance apart in meters
//
// //Reverse of the angle from start to first mark
// double angleToFirstMark = 360 - GeoUtility.getBearing(
// GameState.getMarkOrder().getMarkOrder().get(0).getMidPoint(),
// GameState.getMarkOrder().getMarkOrder().get(1).getMidPoint()
// );
//
// //Length of start line
// double startLineLength = GeoUtility.getDistance(
// GameState.getMarkOrder().getMarkOrder().get(0).getSubMark(1),
// GameState.getMarkOrder().getMarkOrder().get(0).getSubMark(2)
// );
//
// //Angle of start line
// double startMarkToMarkAngle = GeoUtility.getBearing(
// GameState.getMarkOrder().getMarkOrder().get(0).getSubMark(1),
// GameState.getMarkOrder().getMarkOrder().get(0).getSubMark(2)
// );
//
// //How many yachts can fit along the start line
// int spacesAlongLine = (int) Math.round(startLineLength / SEPARATION);
// //The free space left by the boats.
// double buffer = (startLineLength % SEPARATION) / 2;
//
// //Randomize starting order.
// List<ServerYacht> serverYachtList = new ArrayList<>(GameState.getYachts().values());
// Collections.shuffle(serverYachtList);
//
// //set the starting point away from start line.
// GeoPoint startingPoint = GeoUtility.getGeoCoordinate(
// GameState.getMarkOrder().getMarkOrder().get(0).getSubMark(1),
// angleToFirstMark, SEPARATION
// );
//
// //Move it along the start line
// startingPoint = GeoUtility.getGeoCoordinate(
// startingPoint, startMarkToMarkAngle, buffer
// );
//
// int yachtCount = 0;
// int repeats = 0;
//
// GeoPoint yachtLocation;
//
// for (ServerYacht serverYacht : serverYachtList) {
//
// //Move away from start line
// yachtLocation = GeoUtility.getGeoCoordinate(
// startingPoint, angleToFirstMark,repeats * SEPARATION
// );
// //Move along start line
// yachtLocation = GeoUtility.getGeoCoordinate(
// yachtLocation, startMarkToMarkAngle, yachtCount * SEPARATION
// );
// serverYacht.setLocation(yachtLocation);
// serverYacht.setHeading(GeoUtility.getBearing(
// yachtLocation, GameState.getMarkOrder().getMarkOrder().get(1).getMidPoint()
// ));
// //Set location for next yacht
// yachtCount++;
// if (yachtCount > spacesAlongLine) {
// yachtCount = 0;
// repeats++;
// }
// }
//Reverse of the angle from start to first mark
double angleToFirstMark = 360 - GeoUtility.getBearing(
GameState.getMarkOrder().getMarkOrder().get(0).getMidPoint(),
GameState.getMarkOrder().getMarkOrder().get(1).getMidPoint()
);
final double DISTANCE_TO_START = 75d;
final double YACHT_SEPARATION = 20d;
//Length of start line
double startLineLength = GeoUtility.getDistance(
@@ -380,57 +442,54 @@ public class MainServerThread implements Runnable, ClientConnectionDelegate {
GameState.getMarkOrder().getMarkOrder().get(0).getSubMark(2)
);
//How many yachts can fit along the start line
int spacesAlongLine = (int) Math.round(startLineLength / YACHT_SEPARATION);
//Angle of start line
double startMarkToMarkAngle = GeoUtility.getBearing(
GameState.getMarkOrder().getMarkOrder().get(0).getSubMark(1),
GameState.getMarkOrder().getMarkOrder().get(0).getSubMark(2)
);
//How many yachts can fit along the start line
int spacesAlongLine = (int) Math.round(startLineLength / SEPARATION);
//The free space left by the boats.
double buffer = (startLineLength % SEPARATION) / 2;
//angle from first mark to the start
double angleToStart = GeoUtility.getBearing(
GameState.getMarkOrder().getMarkOrder().get(1).getMidPoint(),
GameState.getMarkOrder().getMarkOrder().get(0).getMidPoint()
);
//Randomize starting order.
List<ServerYacht> serverYachtList = new ArrayList<>(GameState.getYachts().values());
Collections.shuffle(serverYachtList);
double angleFromStart = GeoUtility.getBearing(
GameState.getMarkOrder().getMarkOrder().get(0).getMidPoint(),
GameState.getMarkOrder().getMarkOrder().get(1).getMidPoint()
);
//set the starting point away from start line.
GeoPoint startingPoint = GeoUtility.getGeoCoordinate(
GameState.getMarkOrder().getMarkOrder().get(0).getSubMark(1),
angleToFirstMark, SEPARATION
GameState.getMarkOrder().getMarkOrder().get(0).getMidPoint(),
angleToStart, DISTANCE_TO_START
);
//Move it along the start line
startingPoint = GeoUtility.getGeoCoordinate(
startingPoint, startMarkToMarkAngle, buffer
);
List<ServerYacht> randomisedYachts = new ArrayList<>(GameState.getYachts().values());
Collections.shuffle(randomisedYachts);
while (randomisedYachts.size() > 0) {
int yachtCount = 0;
int repeats = 0;
int numYachtsInLine = spacesAlongLine > randomisedYachts.size() ? randomisedYachts.size() : spacesAlongLine;
double yachtSpace = numYachtsInLine * YACHT_SEPARATION / 2;
GeoPoint yachtLocation;
for (ServerYacht serverYacht : serverYachtList) {
//Move away from start line
yachtLocation = GeoUtility.getGeoCoordinate(
startingPoint, angleToFirstMark,repeats * SEPARATION
GeoPoint firstYachtPoint = GeoUtility.getGeoCoordinate(
startingPoint, startMarkToMarkAngle + 180, yachtSpace
);
//Move along start line
yachtLocation = GeoUtility.getGeoCoordinate(
yachtLocation, startMarkToMarkAngle, yachtCount * SEPARATION
);
serverYacht.setLocation(yachtLocation);
serverYacht.setHeading(GeoUtility.getBearing(
yachtLocation, GameState.getMarkOrder().getMarkOrder().get(1).getMidPoint()
));
//Set location for next yacht
yachtCount++;
if (yachtCount > spacesAlongLine) {
yachtCount = 0;
repeats++;
for (int i=0; i<numYachtsInLine; i++){
randomisedYachts.get(0).setHeading(angleFromStart);
randomisedYachts.get(0).setLocation(firstYachtPoint);
firstYachtPoint = GeoUtility.getGeoCoordinate(
firstYachtPoint, startMarkToMarkAngle, yachtSpace
);
randomisedYachts.remove(0);
}
startingPoint = GeoUtility.getGeoCoordinate(
startingPoint, angleToStart, DISTANCE_TO_START
);
}
}
}
@@ -69,6 +69,9 @@ public class MessageFactory {
}
public static void updateBoats(List<ServerYacht> yachts) {
for (ServerYacht serverYacht : yachts) {
System.out.println(serverYacht);
}
xmlGenerator.getRace().setBoats(yachts);
String xmlStr = xmlGenerator.getBoatsAsXml();
MessageFactory.boats = new XMLMessage(xmlStr, XMLMessageSubType.BOAT, xmlStr.length());
@@ -2,7 +2,6 @@ package seng302.visualiser;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Comparator;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@@ -24,7 +23,6 @@ import javafx.scene.transform.Translate;
import seng302.gameServer.messages.RoundingSide;
import seng302.model.ClientYacht;
import seng302.model.GameKeyBind;
import seng302.model.GeoPoint;
import seng302.model.KeyAction;
import seng302.model.Limit;
import seng302.model.ScaledPoint;
@@ -79,6 +77,8 @@ public class GameView3D extends GameView{
topDownCam = new TopDownCamera();
chaseCam = new ChaseCamera();
canvasWidth = canvasHeight = 300;
for (PerspectiveCamera pc : Arrays.asList(isometricCam, topDownCam, chaseCam)) {
pc.setFarClip(600);
pc.setNearClip(0.1);
+2 -2
View File
@@ -11,7 +11,7 @@
<Marks>
<CompoundMark CompoundMarkID="1">
<Mark Lat="-14.071412" Lng="47.05756"/>
<Mark Lat="-14.070814" Lng="47.058041"/>
<Mark Lat="-14.069914" Lng="47.058541"/>
</CompoundMark>
<CompoundMark CompoundMarkID="2">
<Mark Lat="-14.067194" Lng="47.053818" />
@@ -63,7 +63,7 @@
<CourseLimit>
<Limit Lat="-14.073371" Lng="47.058213" />
<Limit Lat="-14.06653" Lng="47.051003" />
<Limit Lat="-14.06453" Lng="47.050003" />
<Limit Lat="-14.059022" Lng="47.057286" />
<Limit Lat="-14.058723" Lng="47.064358" />
<Limit Lat="-14.06261" Lng="47.071293" />