From 3857a1fb1c7da6b51f1f4523bdf98cbcaa4c4bec Mon Sep 17 00:00:00 2001 From: Tyler Arehart Date: Tue, 13 Nov 2018 03:51:22 -0800 Subject: [PATCH] Adding a DropshotTileManager. --- src/main/java/rlbotexample/SampleBot.java | 14 ++++- .../rlbotexample/dropshot/DropshotTile.java | 32 +++++++++++ .../dropshot/DropshotTileManager.java | 57 +++++++++++++++++++ .../dropshot/DropshotTileState.java | 8 +++ 4 files changed, 110 insertions(+), 1 deletion(-) create mode 100644 src/main/java/rlbotexample/dropshot/DropshotTile.java create mode 100644 src/main/java/rlbotexample/dropshot/DropshotTileManager.java create mode 100644 src/main/java/rlbotexample/dropshot/DropshotTileState.java diff --git a/src/main/java/rlbotexample/SampleBot.java b/src/main/java/rlbotexample/SampleBot.java index c927534..cc7103d 100644 --- a/src/main/java/rlbotexample/SampleBot.java +++ b/src/main/java/rlbotexample/SampleBot.java @@ -8,6 +8,9 @@ import rlbot.manager.BotLoopRenderer; import rlbot.render.Renderer; import rlbotexample.boost.BoostManager; +import rlbotexample.dropshot.DropshotTile; +import rlbotexample.dropshot.DropshotTileManager; +import rlbotexample.dropshot.DropshotTileState; import rlbotexample.input.CarData; import rlbotexample.input.DataPacket; import rlbotexample.output.ControlsOutput; @@ -71,6 +74,14 @@ private void drawDebugLines(DataPacket input, CarData myCar, boolean goLeft) { myCar.position.plus(myCar.orientation.noseVector.scaled(300))); renderer.drawString3d(goLeft ? "left" : "right", Color.WHITE, myCar.position, 2, 2); + + for (DropshotTile tile: DropshotTileManager.getTiles()) { + if (tile.getState() == DropshotTileState.DAMAGED) { + renderer.drawCenteredRectangle3d(Color.YELLOW, tile.getLocation(), 4, 4, true); + } else if (tile.getState() == DropshotTileState.DESTROYED) { + renderer.drawCenteredRectangle3d(Color.RED, tile.getLocation(), 4, 4, true); + } + } } @@ -91,8 +102,9 @@ public ControllerState processInput(GameTickPacket packet) { return new ControlsOutput(); } - // Update the boost manager with the latest data + // Update the boost manager and tile manager with the latest data BoostManager.loadGameTickPacket(packet); + DropshotTileManager.loadGameTickPacket(packet); // Translate the raw packet data (which is in an unpleasant format) into our custom DataPacket class. // The DataPacket might not include everything from GameTickPacket, so improve it if you need to! diff --git a/src/main/java/rlbotexample/dropshot/DropshotTile.java b/src/main/java/rlbotexample/dropshot/DropshotTile.java new file mode 100644 index 0000000..378a035 --- /dev/null +++ b/src/main/java/rlbotexample/dropshot/DropshotTile.java @@ -0,0 +1,32 @@ +package rlbotexample.dropshot; + + +import rlbotexample.vector.Vector3; + +/** + * Representation of one of the floor tiles in dropshot mode. + * + * This class is here for your convenience, it is NOT part of the framework. You can change it as much + * as you want, or delete it. + */ +public class DropshotTile { + + private final Vector3 location; + private DropshotTileState state; + + public DropshotTile(Vector3 location) { + this.location = location; + } + + public void setState(DropshotTileState state) { + this.state = state; + } + + public Vector3 getLocation() { + return location; + } + + public DropshotTileState getState() { + return state; + } +} diff --git a/src/main/java/rlbotexample/dropshot/DropshotTileManager.java b/src/main/java/rlbotexample/dropshot/DropshotTileManager.java new file mode 100644 index 0000000..d4659c5 --- /dev/null +++ b/src/main/java/rlbotexample/dropshot/DropshotTileManager.java @@ -0,0 +1,57 @@ +package rlbotexample.dropshot; + +import rlbot.cppinterop.RLBotDll; +import rlbot.flat.FieldInfo; +import rlbot.flat.GameTickPacket; +import rlbotexample.vector.Vector3; + +import java.io.IOException; +import java.util.ArrayList; +import java.util.List; + +/** + * Information about where dropshot tiles are located in the arena and what state they have. + * + * This class is here for your convenience, it is NOT part of the framework. You can change it as much + * as you want, or delete it. + */ +public class DropshotTileManager { + + private static final ArrayList tiles = new ArrayList<>(); + + public static List getTiles() { + return tiles; + } + + private static void loadFieldInfo(FieldInfo fieldInfo) { + + synchronized (tiles) { + + tiles.clear(); + + for (int i = 0; i < fieldInfo.goalsLength(); i++) { + rlbot.flat.GoalInfo goalInfo = fieldInfo.goals(i); + tiles.add(new DropshotTile(new Vector3(goalInfo.location()))); + } + } + } + + public static void loadGameTickPacket(GameTickPacket packet) { + + if (packet.tileInformationLength() > tiles.size()) { + try { + loadFieldInfo(RLBotDll.getFieldInfo()); + } catch (IOException e) { + e.printStackTrace(); + return; + } + } + + for (int i = 0; i < packet.tileInformationLength(); i++) { + rlbot.flat.DropshotTile tile = packet.tileInformation(i); + DropshotTile existingTile = tiles.get(i); + existingTile.setState(DropshotTileState.values()[tile.tileState()]); + } + } + +} diff --git a/src/main/java/rlbotexample/dropshot/DropshotTileState.java b/src/main/java/rlbotexample/dropshot/DropshotTileState.java new file mode 100644 index 0000000..b2dba3f --- /dev/null +++ b/src/main/java/rlbotexample/dropshot/DropshotTileState.java @@ -0,0 +1,8 @@ +package rlbotexample.dropshot; + +public enum DropshotTileState { + UNKNOWN, + FRESH, + DAMAGED, + DESTROYED +}