mirror of
https://github.com/michaelrausch/Party-Parrots-At-Sea.git
synced 2026-05-09 14:28:43 +00:00
Fixed wind walker and bumper
Added a hack to bumper so that the collision distance is larger than the regular collision distance Wind walker now makes you go at you max speed rather than VMG speed #story[1293]
This commit is contained in:
@@ -382,8 +382,8 @@ public class GameState implements Runnable {
|
|||||||
|
|
||||||
//Get a random token location with random type
|
//Get a random token location with random type
|
||||||
Token token = allTokens.get(random.nextInt(allTokens.size()));
|
Token token = allTokens.get(random.nextInt(allTokens.size()));
|
||||||
// token.assignRandomType();
|
token.assignRandomType();
|
||||||
token.assignType(TokenType.BUMPER);
|
// token.assignType(TokenType.WIND_WALKER);
|
||||||
|
|
||||||
logger.debug("Spawned token of type " + token.getTokenType());
|
logger.debug("Spawned token of type " + token.getTokenType());
|
||||||
|
|
||||||
@@ -440,8 +440,9 @@ public class GameState implements Runnable {
|
|||||||
windWalk(yacht);
|
windWalk(yacht);
|
||||||
break;
|
break;
|
||||||
case BUMPER:
|
case BUMPER:
|
||||||
ServerYacht collidedYacht = checkYachtCollision(yacht);
|
ServerYacht collidedYacht = checkYachtCollision(yacht, true);
|
||||||
if (collidedYacht != null) {
|
if (collidedYacht != null) {
|
||||||
|
System.out.println("WE OUT HERE");
|
||||||
yacht.powerDown();
|
yacht.powerDown();
|
||||||
boatTempShutDown(collidedYacht);
|
boatTempShutDown(collidedYacht);
|
||||||
notifyMessageListeners(MessageFactory.makePowerDownMessage(yacht));
|
notifyMessageListeners(MessageFactory.makePowerDownMessage(yacht));
|
||||||
@@ -497,17 +498,12 @@ public class GameState implements Runnable {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* This function changes the wind to be at an angle that causes the yacht in question to be at
|
* This function changes the wind to be at an angle that causes the yacht in question to be at
|
||||||
* VMG.
|
* its fastest velocity
|
||||||
*
|
*
|
||||||
* @param yacht The yacht to fix the wind for
|
* @param yacht The yacht to fix the wind for
|
||||||
*/
|
*/
|
||||||
private void windWalk(ServerYacht yacht) {
|
private void windWalk(ServerYacht yacht) {
|
||||||
HashMap<Double, Double> upwindOptimal = PolarTable.getOptimalUpwindVMG(windSpeed);
|
Double optimalAngle = PolarTable.getOptimalAngle();
|
||||||
Double optimalAngle = null;
|
|
||||||
for (Double windAngle : upwindOptimal.keySet()) {
|
|
||||||
optimalAngle = windAngle;
|
|
||||||
}
|
|
||||||
|
|
||||||
Double heading = yacht.getHeading();
|
Double heading = yacht.getHeading();
|
||||||
windDirection = (double) Math.floorMod(Math.round(heading + optimalAngle), 360L);
|
windDirection = (double) Math.floorMod(Math.round(heading + optimalAngle), 360L);
|
||||||
}
|
}
|
||||||
@@ -597,7 +593,7 @@ public class GameState implements Runnable {
|
|||||||
*/
|
*/
|
||||||
public static void checkCollision(ServerYacht serverYacht) {
|
public static void checkCollision(ServerYacht serverYacht) {
|
||||||
//Yacht Collision
|
//Yacht Collision
|
||||||
ServerYacht collidedYacht = checkYachtCollision(serverYacht);
|
ServerYacht collidedYacht = checkYachtCollision(serverYacht, false);
|
||||||
Mark collidedMark = checkMarkCollision(serverYacht);
|
Mark collidedMark = checkMarkCollision(serverYacht);
|
||||||
|
|
||||||
if (collidedYacht != null) {
|
if (collidedYacht != null) {
|
||||||
@@ -946,15 +942,22 @@ public class GameState implements Runnable {
|
|||||||
* Collision detection which iterates through all the yachts and check if any yacht collided
|
* Collision detection which iterates through all the yachts and check if any yacht collided
|
||||||
* with this yacht. Return collided yacht or null if no collision.
|
* with this yacht. Return collided yacht or null if no collision.
|
||||||
*
|
*
|
||||||
|
* UPDATE: HACK!!! wmu16 - forBumperCollision is (the goddamn dirtiest) dirty flag to fix a
|
||||||
|
* weird bug where the bumper collision would not be registerd but the knock back collision would.
|
||||||
|
* In other words, only set the 'forBumperCollision' flag true if used for the bumper power up.
|
||||||
|
*
|
||||||
* @return yacht to compare to all other yachts.
|
* @return yacht to compare to all other yachts.
|
||||||
*/
|
*/
|
||||||
private static ServerYacht checkYachtCollision(ServerYacht yacht) {
|
private static ServerYacht checkYachtCollision(ServerYacht yacht, Boolean forBumperCollision) {
|
||||||
|
Double collisionDistance =
|
||||||
|
(forBumperCollision) ? YACHT_COLLISION_DISTANCE + 2.5 : YACHT_COLLISION_DISTANCE;
|
||||||
|
|
||||||
for (ServerYacht otherYacht : GameState.getYachts().values()) {
|
for (ServerYacht otherYacht : GameState.getYachts().values()) {
|
||||||
if (otherYacht != yacht) {
|
if (otherYacht != yacht) {
|
||||||
Double distance = GeoUtility
|
Double distance = GeoUtility
|
||||||
.getDistance(otherYacht.getLocation(), yacht.getLocation());
|
.getDistance(otherYacht.getLocation(), yacht.getLocation());
|
||||||
if (distance < YACHT_COLLISION_DISTANCE) {
|
;
|
||||||
|
if (distance < collisionDistance) {
|
||||||
return otherYacht;
|
return otherYacht;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,7 +4,9 @@ import java.io.BufferedReader;
|
|||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
import java.io.InputStreamReader;
|
import java.io.InputStreamReader;
|
||||||
|
import java.util.Collections;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A static class for parsing and storing the polars. Will parse the whole polar table and also store the optimised
|
* A static class for parsing and storing the polars. Will parse the whole polar table and also store the optimised
|
||||||
@@ -17,6 +19,7 @@ public final class PolarTable {
|
|||||||
private static HashMap<Double, HashMap<Double, Double>> polarTable;
|
private static HashMap<Double, HashMap<Double, Double>> polarTable;
|
||||||
private static HashMap<Double, HashMap<Double, Double>> upwindOptimal;
|
private static HashMap<Double, HashMap<Double, Double>> upwindOptimal;
|
||||||
private static HashMap<Double, HashMap<Double, Double>> downwindOptimal;
|
private static HashMap<Double, HashMap<Double, Double>> downwindOptimal;
|
||||||
|
private static Double optimalAngle;
|
||||||
|
|
||||||
private static int upTwaIndex;
|
private static int upTwaIndex;
|
||||||
private static int dnTwaIndex;
|
private static int dnTwaIndex;
|
||||||
@@ -33,11 +36,13 @@ public final class PolarTable {
|
|||||||
upwindOptimal = new HashMap<>();
|
upwindOptimal = new HashMap<>();
|
||||||
downwindOptimal = new HashMap<>();
|
downwindOptimal = new HashMap<>();
|
||||||
|
|
||||||
String line;
|
String line = null;
|
||||||
|
String check;
|
||||||
Boolean isHeaderLine = true;
|
Boolean isHeaderLine = true;
|
||||||
|
|
||||||
try (BufferedReader br = new BufferedReader(new InputStreamReader(polarFile))) {
|
try (BufferedReader br = new BufferedReader(new InputStreamReader(polarFile))) {
|
||||||
while ((line = br.readLine()) != null) {
|
while ((check = br.readLine()) != null) {
|
||||||
|
line = check;
|
||||||
String[] thisLine = line.split(",");
|
String[] thisLine = line.split(",");
|
||||||
|
|
||||||
//Initial line in file
|
//Initial line in file
|
||||||
@@ -66,7 +71,10 @@ public final class PolarTable {
|
|||||||
upwindOptimal.put(thisWindSpeed, thisUpWindPolar);
|
upwindOptimal.put(thisWindSpeed, thisUpWindPolar);
|
||||||
downwindOptimal.put(thisWindSpeed, thisDnWindPolar);
|
downwindOptimal.put(thisWindSpeed, thisDnWindPolar);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
getMaxSpeedAngle(line);
|
||||||
|
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
System.out.println("[PolarTable] IO exception");
|
System.out.println("[PolarTable] IO exception");
|
||||||
@@ -74,6 +82,27 @@ public final class PolarTable {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Passes the final line of the polar table and iterates over the speeds for each
|
||||||
|
* angle, velocity pair to find the angle that produces the highest velocity
|
||||||
|
*
|
||||||
|
* @param line The last line of the polar file
|
||||||
|
*/
|
||||||
|
private static void getMaxSpeedAngle(String line) {
|
||||||
|
String[] theLastLine = line.split(",");
|
||||||
|
Double maxWindVal = Double.parseDouble(theLastLine[0]);
|
||||||
|
Double optimalAngle = Double.parseDouble(theLastLine[1]);
|
||||||
|
Double maxSpeed = Double.parseDouble(theLastLine[2]);
|
||||||
|
for (Map.Entry<Double, Double> entry : polarTable.get(maxWindVal).entrySet()) {
|
||||||
|
if (entry.getValue() > maxSpeed) {
|
||||||
|
maxSpeed = entry.getValue();
|
||||||
|
optimalAngle = entry.getKey();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
PolarTable.optimalAngle = optimalAngle;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Parses the header line of a polar file
|
* Parses the header line of a polar file
|
||||||
@@ -85,14 +114,18 @@ public final class PolarTable {
|
|||||||
String thisItem = thisLine[i];
|
String thisItem = thisLine[i];
|
||||||
if (thisItem.toLowerCase().startsWith("uptwa")) {
|
if (thisItem.toLowerCase().startsWith("uptwa")) {
|
||||||
upTwaIndex = i;
|
upTwaIndex = i;
|
||||||
}
|
} else if (thisItem.toLowerCase().startsWith("dntwa")) {
|
||||||
else if (thisItem.toLowerCase().startsWith("dntwa")) {
|
|
||||||
dnTwaIndex = i;
|
dnTwaIndex = i;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public static Double getOptimalAngle() {
|
||||||
|
return optimalAngle;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return The entire polar table
|
* @return The entire polar table
|
||||||
*/
|
*/
|
||||||
|
|||||||
Reference in New Issue
Block a user