mirror of
https://github.com/michaelrausch/Party-Parrots-At-Sea.git
synced 2026-05-09 14:28:43 +00:00
WIP: Initial commit for seperating server and client yacht classes
tags: #story[1124]
This commit is contained in:
@@ -4,9 +4,9 @@ import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import seng302.gameServer.server.messages.BoatAction;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import seng302.gameServer.server.messages.BoatAction;
|
||||
import seng302.gameServer.server.messages.MarkRoundingMessage;
|
||||
import seng302.gameServer.server.messages.MarkType;
|
||||
import seng302.gameServer.server.messages.Message;
|
||||
@@ -14,7 +14,7 @@ import seng302.gameServer.server.messages.RoundingBoatStatus;
|
||||
import seng302.model.GeoPoint;
|
||||
import seng302.model.Player;
|
||||
import seng302.model.PolarTable;
|
||||
import seng302.model.Yacht;
|
||||
import seng302.model.ServerYacht;
|
||||
import seng302.model.mark.CompoundMark;
|
||||
import seng302.model.mark.Mark;
|
||||
import seng302.model.mark.MarkOrder;
|
||||
@@ -44,7 +44,7 @@ public class GameState implements Runnable {
|
||||
|
||||
private static String hostIpAddress;
|
||||
private static List<Player> players;
|
||||
private static Map<Integer, Yacht> yachts;
|
||||
private static Map<Integer, ServerYacht> yachts;
|
||||
private static Boolean isRaceStarted;
|
||||
private static GameStages currentStage;
|
||||
private static MarkOrder markOrder;
|
||||
@@ -102,7 +102,7 @@ public class GameState implements Runnable {
|
||||
playerStringMap.remove(player);
|
||||
}
|
||||
|
||||
public static void addYacht(Integer sourceId, Yacht yacht) {
|
||||
public static void addYacht(Integer sourceId, ServerYacht yacht) {
|
||||
yachts.put(sourceId, yacht);
|
||||
}
|
||||
|
||||
@@ -146,7 +146,7 @@ public class GameState implements Runnable {
|
||||
return GeoUtility.mmsToKnots(windSpeed); // TODO: 26/07/17 cir27 - remove magic numbers
|
||||
}
|
||||
|
||||
public static Map<Integer, Yacht> getYachts() {
|
||||
public static Map<Integer, ServerYacht> getYachts() {
|
||||
return yachts;
|
||||
}
|
||||
|
||||
@@ -185,7 +185,7 @@ public class GameState implements Runnable {
|
||||
}
|
||||
|
||||
public static void updateBoat(Integer sourceId, BoatAction actionType) {
|
||||
Yacht playerYacht = yachts.get(sourceId);
|
||||
ServerYacht playerYacht = yachts.get(sourceId);
|
||||
switch (actionType) {
|
||||
case VMG:
|
||||
playerYacht.turnToVMG();
|
||||
@@ -215,7 +215,7 @@ public class GameState implements Runnable {
|
||||
public void update() {
|
||||
Double timeInterval = (System.currentTimeMillis() - previousUpdateTime) / 1000000.0;
|
||||
previousUpdateTime = System.currentTimeMillis();
|
||||
for (Yacht yacht : yachts.values()) {
|
||||
for (ServerYacht yacht : yachts.values()) {
|
||||
updateVelocity(yacht);
|
||||
yacht.runAutoPilot();
|
||||
yacht.updateLocation(timeInterval);
|
||||
@@ -226,12 +226,11 @@ public class GameState implements Runnable {
|
||||
}
|
||||
|
||||
|
||||
private void updateVelocity(Yacht yacht) {
|
||||
private void updateVelocity(ServerYacht yacht) {
|
||||
Double velocity = yacht.getCurrentVelocity();
|
||||
Double trueWindAngle = Math.abs(windDirection - yacht.getHeading());
|
||||
Double boatSpeedInKnots = PolarTable.getBoatSpeed(getWindSpeedKnots(), trueWindAngle);
|
||||
Double maxBoatSpeed = GeoUtility.knotsToMMS(boatSpeedInKnots);
|
||||
yacht.setCurrentMaxVelocity(maxBoatSpeed);
|
||||
|
||||
if (yacht.getSailIn() && yacht.getCurrentVelocity() <= maxBoatSpeed && maxBoatSpeed != 0d) {
|
||||
if (velocity < maxBoatSpeed) {
|
||||
@@ -263,7 +262,7 @@ public class GameState implements Runnable {
|
||||
* @throws IndexOutOfBoundsException If the next mark is null (ie the last mark in the race)
|
||||
* Check first using {@link seng302.model.mark.MarkOrder#isLastMark(Integer)}
|
||||
*/
|
||||
private Double calcDistanceToCurrentMark(Yacht yacht) throws IndexOutOfBoundsException {
|
||||
private Double calcDistanceToCurrentMark(ServerYacht yacht) throws IndexOutOfBoundsException {
|
||||
Integer currentMarkSeqID = yacht.getCurrentMarkSeqID();
|
||||
CompoundMark currentMark = markOrder.getCurrentMark(currentMarkSeqID);
|
||||
GeoPoint location = yacht.getLocation();
|
||||
@@ -292,7 +291,7 @@ public class GameState implements Runnable {
|
||||
* in-race Gate 3 - Passing any in-race Mark 4 - Passing the finish line
|
||||
* @param yacht the current yacht to check for progression
|
||||
*/
|
||||
private void checkForLegProgression(Yacht yacht) {
|
||||
private void checkForLegProgression(ServerYacht yacht) {
|
||||
Integer currentMarkSeqID = yacht.getCurrentMarkSeqID();
|
||||
CompoundMark currentMark = markOrder.getCurrentMark(currentMarkSeqID);
|
||||
|
||||
@@ -324,7 +323,7 @@ public class GameState implements Runnable {
|
||||
*
|
||||
* @param yacht The current yacht to check for
|
||||
*/
|
||||
private Boolean checkStartLineCrossing(Yacht yacht) {
|
||||
private Boolean checkStartLineCrossing(ServerYacht yacht) {
|
||||
Integer currentMarkSeqID = yacht.getCurrentMarkSeqID();
|
||||
CompoundMark currentMark = markOrder.getCurrentMark(currentMarkSeqID);
|
||||
GeoPoint lastLocation = yacht.getLastLocation();
|
||||
@@ -354,7 +353,7 @@ public class GameState implements Runnable {
|
||||
*
|
||||
* @param yacht The current yacht to check for
|
||||
*/
|
||||
private Boolean checkMarkRounding(Yacht yacht) {
|
||||
private Boolean checkMarkRounding(ServerYacht yacht) {
|
||||
Integer currentMarkSeqID = yacht.getCurrentMarkSeqID();
|
||||
CompoundMark currentMark = markOrder.getCurrentMark(currentMarkSeqID);
|
||||
GeoPoint lastLocation = yacht.getLastLocation();
|
||||
@@ -383,7 +382,7 @@ public class GameState implements Runnable {
|
||||
*
|
||||
* @param yacht The current yacht to check for
|
||||
*/
|
||||
private Boolean checkGateRounding(Yacht yacht) {
|
||||
private Boolean checkGateRounding(ServerYacht yacht) {
|
||||
Integer currentMarkSeqID = yacht.getCurrentMarkSeqID();
|
||||
CompoundMark currentMark = markOrder.getCurrentMark(currentMarkSeqID);
|
||||
GeoPoint lastLocation = yacht.getLastLocation();
|
||||
@@ -426,7 +425,7 @@ public class GameState implements Runnable {
|
||||
*
|
||||
* @param yacht The current yacht to check for
|
||||
*/
|
||||
private Boolean checkFinishLineCrossing(Yacht yacht) {
|
||||
private Boolean checkFinishLineCrossing(ServerYacht yacht) {
|
||||
Integer currentMarkSeqID = yacht.getCurrentMarkSeqID();
|
||||
CompoundMark currentMark = markOrder.getCurrentMark(currentMarkSeqID);
|
||||
GeoPoint lastLocation = yacht.getLastLocation();
|
||||
@@ -450,7 +449,7 @@ public class GameState implements Runnable {
|
||||
return false;
|
||||
}
|
||||
|
||||
private void sendMarkRoundingMessage(Yacht yacht) {
|
||||
private void sendMarkRoundingMessage(ServerYacht yacht) {
|
||||
Integer sourceID = yacht.getSourceId();
|
||||
Integer currentMarkSeqID = yacht.getCurrentMarkSeqID();
|
||||
CompoundMark currentMark = markOrder.getCurrentMark(currentMarkSeqID);
|
||||
@@ -468,7 +467,7 @@ public class GameState implements Runnable {
|
||||
}
|
||||
|
||||
|
||||
private void logMarkRounding(Yacht yacht) {
|
||||
private void logMarkRounding(ServerYacht yacht) {
|
||||
Mark roundingMark = yacht.getClosestCurrentMark();
|
||||
|
||||
logger.debug(
|
||||
|
||||
@@ -19,6 +19,7 @@ import java.util.zip.CRC32;
|
||||
import java.util.zip.Checksum;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import seng302.gameServer.server.messages.BoatAction;
|
||||
import seng302.gameServer.server.messages.BoatLocationMessage;
|
||||
import seng302.gameServer.server.messages.BoatStatus;
|
||||
import seng302.gameServer.server.messages.BoatSubMessage;
|
||||
@@ -32,13 +33,12 @@ import seng302.gameServer.server.messages.RegistrationResponseStatus;
|
||||
import seng302.gameServer.server.messages.XMLMessage;
|
||||
import seng302.gameServer.server.messages.XMLMessageSubType;
|
||||
import seng302.model.Player;
|
||||
import seng302.model.Yacht;
|
||||
import seng302.model.ServerYacht;
|
||||
import seng302.model.stream.packets.PacketType;
|
||||
import seng302.model.stream.packets.StreamPacket;
|
||||
import seng302.model.stream.xml.generator.Race;
|
||||
import seng302.model.stream.xml.generator.Regatta;
|
||||
import seng302.utilities.XMLGenerator;
|
||||
import seng302.gameServer.server.messages.BoatAction;
|
||||
|
||||
/**
|
||||
* A class describing a single connection to a Client for the purposes of sending and receiving on
|
||||
@@ -115,8 +115,7 @@ public class ServerToClientThread implements Runnable, Observer {
|
||||
all = ln.lines().collect(Collectors.toList());
|
||||
lName = all.get(ThreadLocalRandom.current().nextInt(0, all.size()));
|
||||
|
||||
|
||||
Yacht yacht = new Yacht(
|
||||
ServerYacht yacht = new ServerYacht(
|
||||
"Yacht", sourceId, sourceId.toString(), fName, fName + " " + lName, "NZ"
|
||||
);
|
||||
|
||||
@@ -221,7 +220,7 @@ public class ServerToClientThread implements Runnable, Observer {
|
||||
xml = new XMLGenerator();
|
||||
Race race = new Race();
|
||||
|
||||
for (Yacht yacht : GameState.getYachts().values()) {
|
||||
for (ServerYacht yacht : GameState.getYachts().values()) {
|
||||
race.addBoat(yacht);
|
||||
}
|
||||
|
||||
@@ -299,8 +298,8 @@ public class ServerToClientThread implements Runnable, Observer {
|
||||
|
||||
|
||||
public void sendBoatLocationPackets() {
|
||||
ArrayList<Yacht> yachts = new ArrayList<>(GameState.getYachts().values());
|
||||
for (Yacht yacht : yachts) {
|
||||
ArrayList<ServerYacht> yachts = new ArrayList<>(GameState.getYachts().values());
|
||||
for (ServerYacht yacht : yachts) {
|
||||
BoatLocationMessage boatLocationMessage =
|
||||
new BoatLocationMessage(
|
||||
yacht.getSourceId(),
|
||||
@@ -326,7 +325,7 @@ public class ServerToClientThread implements Runnable, Observer {
|
||||
RaceStatus raceStatus;
|
||||
|
||||
for (Player player : GameState.getPlayers()) {
|
||||
Yacht y = player.getYacht();
|
||||
ServerYacht y = player.getYacht();
|
||||
|
||||
if (GameState.getCurrentStage() == GameStages.PRE_RACE) {
|
||||
boatStatus = BoatStatus.PRESTART;
|
||||
|
||||
@@ -9,11 +9,11 @@ import java.net.Socket;
|
||||
public class Player {
|
||||
|
||||
private Socket socket;
|
||||
private Yacht yacht;
|
||||
private ServerYacht yacht;
|
||||
private Integer lastMarkPassed;
|
||||
|
||||
|
||||
public Player(Socket socket, Yacht yacht) {
|
||||
public Player(Socket socket, ServerYacht yacht) {
|
||||
this.socket = socket;
|
||||
this.yacht = yacht;
|
||||
}
|
||||
@@ -30,7 +30,7 @@ public class Player {
|
||||
this.lastMarkPassed = lastMarkPassed;
|
||||
}
|
||||
|
||||
public Yacht getYacht() {
|
||||
public ServerYacht getYacht() {
|
||||
return yacht;
|
||||
}
|
||||
|
||||
|
||||
@@ -4,13 +4,14 @@ import java.time.LocalDateTime;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import seng302.model.Yacht;
|
||||
import seng302.model.ServerYacht;
|
||||
|
||||
/**
|
||||
* A Race object that can be parsed into XML
|
||||
*/
|
||||
public class Race {
|
||||
private List<Yacht> yachts;
|
||||
|
||||
private List<ServerYacht> yachts;
|
||||
private LocalDateTime startTime;
|
||||
|
||||
public Race(){
|
||||
@@ -22,7 +23,7 @@ public class Race {
|
||||
* Add a boat to the race
|
||||
* @param yacht The boat to add
|
||||
*/
|
||||
public void addBoat(Yacht yacht){
|
||||
public void addBoat(ServerYacht yacht) {
|
||||
yachts.add(yacht);
|
||||
}
|
||||
|
||||
@@ -30,7 +31,7 @@ public class Race {
|
||||
* Get a list of boats in the race
|
||||
* @return A List of boats
|
||||
*/
|
||||
public List<Yacht> getBoats(){
|
||||
public List<ServerYacht> getBoats() {
|
||||
return Collections.unmodifiableList(yachts);
|
||||
}
|
||||
|
||||
|
||||
@@ -9,6 +9,7 @@ import seng302.gameServer.GameStages;
|
||||
import seng302.gameServer.GameState;
|
||||
import seng302.gameServer.MainServerThread;
|
||||
import seng302.gameServer.server.messages.BoatAction;
|
||||
import seng302.model.ServerYacht;
|
||||
import seng302.model.Yacht;
|
||||
import seng302.visualiser.ClientToServerThread;
|
||||
|
||||
@@ -33,7 +34,7 @@ public class RegularPacketsTest {
|
||||
final double TEST_DISTANCE = 10.0;
|
||||
serverThread.startGame();
|
||||
SleepThreadMaxDelay();
|
||||
Yacht yacht = new ArrayList<>(GameState.getYachts().values()).get(0);
|
||||
ServerYacht yacht = new ArrayList<>(GameState.getYachts().values()).get(0);
|
||||
double startAngle = yacht.getHeading();
|
||||
long startTime = System.currentTimeMillis();
|
||||
clientThread.sendBoatAction(BoatAction.UPWIND);
|
||||
|
||||
Reference in New Issue
Block a user