diff --git a/engine/src/main/battlecode/common/GameConstants.java b/engine/src/main/battlecode/common/GameConstants.java index 7edd1c6b..8fb8c4fe 100644 --- a/engine/src/main/battlecode/common/GameConstants.java +++ b/engine/src/main/battlecode/common/GameConstants.java @@ -101,11 +101,8 @@ public class GameConstants { /** The number of defense towers a player starts with */ public static final int NUMBER_INITIAL_DEFENSE_TOWERS = 0; - /** The amount of a paint a paint tower starts with. */ - public static final int INITIAL_PAINT_TOWER_PAINT = 500; - - /** The percentage of a robot's paint capacity that is full when first built. */ - public static final int INITIAL_ROBOT_PAINT_PERCENTAGE = 50; + /** The percentage of a unit's paint capacity that is full when first built. */ + public static final int INITIAL_UNIT_PAINT_PERCENTAGE = 50; /** The width and height of the patterns that robots can draw */ public static final int PATTERN_SIZE = 5; diff --git a/engine/src/main/battlecode/schema/MopAction.java b/engine/src/main/battlecode/schema/MopAction.java index 8cc96c72..8d183bb1 100644 --- a/engine/src/main/battlecode/schema/MopAction.java +++ b/engine/src/main/battlecode/schema/MopAction.java @@ -1,3 +1,4 @@ + // automatically generated by the FlatBuffers compiler, do not modify package battlecode.schema; @@ -27,11 +28,18 @@ public final class MopAction extends Struct { public void __init(int _i, ByteBuffer _bb) { __reset(_i, _bb); } public MopAction __assign(int _i, ByteBuffer _bb) { __init(_i, _bb); return this; } - public int loc() { return bb.getShort(bb_pos + 0) & 0xFFFF; } - - public static int createMopAction(FlatBufferBuilder builder, int loc) { - builder.prep(2, 2); - builder.putShort((short) loc); + /** + * Ids of the mopped targets, possibly 0 + */ + public int id0() { return bb.getShort(bb_pos + 0) & 0xFFFF; } + public int id1() { return bb.getShort(bb_pos + 2) & 0xFFFF; } + public int id2() { return bb.getShort(bb_pos + 4) & 0xFFFF; } + + public static int createMopAction(FlatBufferBuilder builder, int id0, int id1, int id2) { + builder.prep(2, 6); + builder.putShort((short) id2); + builder.putShort((short) id1); + builder.putShort((short) id0); return builder.offset(); } @@ -42,4 +50,3 @@ public static final class Vector extends BaseVector { public MopAction get(MopAction obj, int j) { return obj.__assign(__element(j), bb); } } } - diff --git a/engine/src/main/battlecode/schema/RobotTypeMetadata.java b/engine/src/main/battlecode/schema/RobotTypeMetadata.java index ec6822f9..a63ddeb4 100644 --- a/engine/src/main/battlecode/schema/RobotTypeMetadata.java +++ b/engine/src/main/battlecode/schema/RobotTypeMetadata.java @@ -31,22 +31,28 @@ public final class RobotTypeMetadata extends Table { public int actionCooldown() { int o = __offset(6); return o != 0 ? bb.getInt(o + bb_pos) : 0; } public int movementCooldown() { int o = __offset(8); return o != 0 ? bb.getInt(o + bb_pos) : 0; } public int baseHealth() { int o = __offset(10); return o != 0 ? bb.getInt(o + bb_pos) : 0; } - public int actionRadiusSquared() { int o = __offset(12); return o != 0 ? bb.getInt(o + bb_pos) : 0; } - public int visionRadiusSquared() { int o = __offset(14); return o != 0 ? bb.getInt(o + bb_pos) : 0; } - public int bytecodeLimit() { int o = __offset(16); return o != 0 ? bb.getInt(o + bb_pos) : 0; } + public int basePaint() { int o = __offset(12); return o != 0 ? bb.getInt(o + bb_pos) : 0; } + public int maxPaint() { int o = __offset(14); return o != 0 ? bb.getInt(o + bb_pos) : 0; } + public int actionRadiusSquared() { int o = __offset(16); return o != 0 ? bb.getInt(o + bb_pos) : 0; } + public int visionRadiusSquared() { int o = __offset(18); return o != 0 ? bb.getInt(o + bb_pos) : 0; } + public int bytecodeLimit() { int o = __offset(20); return o != 0 ? bb.getInt(o + bb_pos) : 0; } public static int createRobotTypeMetadata(FlatBufferBuilder builder, byte type, int actionCooldown, int movementCooldown, int baseHealth, + int basePaint, + int maxPaint, int actionRadiusSquared, int visionRadiusSquared, int bytecodeLimit) { - builder.startTable(7); + builder.startTable(9); RobotTypeMetadata.addBytecodeLimit(builder, bytecodeLimit); RobotTypeMetadata.addVisionRadiusSquared(builder, visionRadiusSquared); RobotTypeMetadata.addActionRadiusSquared(builder, actionRadiusSquared); + RobotTypeMetadata.addMaxPaint(builder, maxPaint); + RobotTypeMetadata.addBasePaint(builder, basePaint); RobotTypeMetadata.addBaseHealth(builder, baseHealth); RobotTypeMetadata.addMovementCooldown(builder, movementCooldown); RobotTypeMetadata.addActionCooldown(builder, actionCooldown); @@ -54,14 +60,16 @@ public static int createRobotTypeMetadata(FlatBufferBuilder builder, return RobotTypeMetadata.endRobotTypeMetadata(builder); } - public static void startRobotTypeMetadata(FlatBufferBuilder builder) { builder.startTable(7); } + public static void startRobotTypeMetadata(FlatBufferBuilder builder) { builder.startTable(9); } public static void addType(FlatBufferBuilder builder, byte type) { builder.addByte(0, type, 0); } public static void addActionCooldown(FlatBufferBuilder builder, int actionCooldown) { builder.addInt(1, actionCooldown, 0); } public static void addMovementCooldown(FlatBufferBuilder builder, int movementCooldown) { builder.addInt(2, movementCooldown, 0); } public static void addBaseHealth(FlatBufferBuilder builder, int baseHealth) { builder.addInt(3, baseHealth, 0); } - public static void addActionRadiusSquared(FlatBufferBuilder builder, int actionRadiusSquared) { builder.addInt(4, actionRadiusSquared, 0); } - public static void addVisionRadiusSquared(FlatBufferBuilder builder, int visionRadiusSquared) { builder.addInt(5, visionRadiusSquared, 0); } - public static void addBytecodeLimit(FlatBufferBuilder builder, int bytecodeLimit) { builder.addInt(6, bytecodeLimit, 0); } + public static void addBasePaint(FlatBufferBuilder builder, int basePaint) { builder.addInt(4, basePaint, 0); } + public static void addMaxPaint(FlatBufferBuilder builder, int maxPaint) { builder.addInt(5, maxPaint, 0); } + public static void addActionRadiusSquared(FlatBufferBuilder builder, int actionRadiusSquared) { builder.addInt(6, actionRadiusSquared, 0); } + public static void addVisionRadiusSquared(FlatBufferBuilder builder, int visionRadiusSquared) { builder.addInt(7, visionRadiusSquared, 0); } + public static void addBytecodeLimit(FlatBufferBuilder builder, int bytecodeLimit) { builder.addInt(8, bytecodeLimit, 0); } public static int endRobotTypeMetadata(FlatBufferBuilder builder) { int o = builder.endTable(); return o; @@ -73,5 +81,4 @@ public static final class Vector extends BaseVector { public RobotTypeMetadata get(int j) { return get(new RobotTypeMetadata(), j); } public RobotTypeMetadata get(RobotTypeMetadata obj, int j) { return obj.__assign(__indirect(__element(j), bb), bb); } } -} - +} \ No newline at end of file diff --git a/engine/src/main/battlecode/server/GameMaker.java b/engine/src/main/battlecode/server/GameMaker.java index b101f506..84556871 100644 --- a/engine/src/main/battlecode/server/GameMaker.java +++ b/engine/src/main/battlecode/server/GameMaker.java @@ -301,6 +301,8 @@ public int makeRobotTypeMetadata(FlatBufferBuilder builder){ } RobotTypeMetadata.startRobotTypeMetadata(builder); RobotTypeMetadata.addType(builder, FlatHelpers.getRobotTypeFromUnitType(type)); + RobotTypeMetadata.addMaxPaint(builder, type.paintCapacity); + RobotTypeMetadata.addBasePaint(builder, (int) Math.round(type.paintCapacity * GameConstants.INITIAL_UNIT_PAINT_PERCENTAGE / 100.0)); RobotTypeMetadata.addActionCooldown(builder, type.actionCooldown); RobotTypeMetadata.addActionRadiusSquared(builder, type.actionRadiusSquared); RobotTypeMetadata.addBaseHealth(builder,type.health); @@ -543,9 +545,9 @@ public void addAttackAction(int otherID){ } /// Visually indicate a mop attack - public void addMopAction(MapLocation loc){ + public void addMopAction(int id1, int id2, int id3){ applyToBuilders((builder) -> { - int action = MopAction.createMopAction(builder, locationToInt(loc)); + int action = MopAction.createMopAction(builder, id1, id2, id3); builder.addAction(action, Action.MopAction); }); } diff --git a/engine/src/main/battlecode/world/GameMapIO.java b/engine/src/main/battlecode/world/GameMapIO.java index 7a222e95..3005f382 100644 --- a/engine/src/main/battlecode/world/GameMapIO.java +++ b/engine/src/main/battlecode/world/GameMapIO.java @@ -358,23 +358,11 @@ private static void initInitialBodiesFromSchemaBodyTable(InitialBodyTable bodyTa if (teamsReversed){ bodyTeam = bodyTeam.opponent(); } - int initialPaint = (bodyType == UnitType.LEVEL_ONE_PAINT_TOWER) ? GameConstants.INITIAL_PAINT_TOWER_PAINT : 0; + int initialPaint = (int) Math.round(bodyType.paintCapacity * GameConstants.INITIAL_UNIT_PAINT_PERCENTAGE / 100.0); initialBodies.add(new RobotInfo(curId, bodyTeam, bodyType, bodyType.health, new MapLocation(bodyX, bodyY), initialPaint)); } } - // private static int createSpawnActionsVector(FlatBufferBuilder builder, ArrayList ids, ArrayList xs, ArrayList ys, ArrayList teams, ArrayList types){ - // ByteBuffer bb = builder.createUnintializedVector(6, xs.size(), 2); - // for (int i = 0; i < xs.size(); i++){ - // bb.putInt(ids.get(i)); - // bb.putShort((short)(int)xs.get(i)); - // bb.putShort((short)(int)ys.get(i)); - // bb.put(teams.get(i)); - // bb.put(types.get(i)); - // } - // return builder.endVector(); - // } - private static int createSpawnActionsVector(FlatBufferBuilder builder, ArrayList ids, ArrayList xs, ArrayList ys, ArrayList teams, ArrayList types){ InitialBodyTable.startSpawnActionsVector(builder, ids.size()); for (int i = 0; i < ids.size(); i++){ diff --git a/engine/src/main/battlecode/world/GameWorld.java b/engine/src/main/battlecode/world/GameWorld.java index 66c27945..c7df9643 100644 --- a/engine/src/main/battlecode/world/GameWorld.java +++ b/engine/src/main/battlecode/world/GameWorld.java @@ -432,6 +432,12 @@ public int getMarker(Team team, MapLocation loc) { } public void setMarker(Team team, MapLocation loc, int marker) { + if (marker == 0){ + this.matchMaker.addUnmarkAction(loc); + } + else { + this.matchMaker.addMarkAction(loc, !isPrimaryPaint(marker)); + } this.getmarkersArray(team)[locationToIndex(loc)] = marker; } @@ -947,10 +953,7 @@ public int spawnRobot(int ID, UnitType type, MapLocation location, Team team){ if (type.isTowerType()){ this.teamInfo.addTowers(1, team); } - if (type == UnitType.LEVEL_ONE_PAINT_TOWER) - robot.addPaint(GameConstants.INITIAL_PAINT_TOWER_PAINT); - else if (type.isRobotType()) - robot.addPaint((int) Math.round(type.paintCapacity * GameConstants.INITIAL_ROBOT_PAINT_PERCENTAGE / 100.0)); + robot.addPaint((int) Math.round(type.paintCapacity * GameConstants.INITIAL_UNIT_PAINT_PERCENTAGE / 100.0)); return ID; } diff --git a/engine/src/main/battlecode/world/InternalRobot.java b/engine/src/main/battlecode/world/InternalRobot.java index 402d4112..a3cb48bb 100644 --- a/engine/src/main/battlecode/world/InternalRobot.java +++ b/engine/src/main/battlecode/world/InternalRobot.java @@ -469,6 +469,7 @@ public void mopSwing(Direction dir) { // NOTE: only works for moppers! if(dir == Direction.SOUTH) dirIdx = 1; else if(dir == Direction.EAST) dirIdx = 2; else if(dir == Direction.WEST) dirIdx = 3; + ArrayList affectedIDs = new ArrayList<>(); for(int i = 0; i < 3; i ++) { // check all three spots int x = this.getLocation().x + dx[dirIdx][i], y = this.getLocation().y + dy[dirIdx][i]; @@ -480,12 +481,12 @@ public void mopSwing(Direction dir) { // NOTE: only works for moppers! InternalRobot robot = this.gameWorld.getRobot(newLoc); if(this.team != robot.getTeam()){ robot.addPaint(-GameConstants.MOPPER_SWING_PAINT_DEPLETION); - this.gameWorld.getMatchMaker().addAttackAction(robot.getID()); + affectedIDs.add(robot.ID); } } } - MapLocation centerLoc = this.location.add(dir); - this.gameWorld.getMatchMaker().addMopAction(centerLoc); + for (int i = 0; i < 3; i++) affectedIDs.add(0); + this.gameWorld.getMatchMaker().addMopAction(affectedIDs.get(0), affectedIDs.get(1), affectedIDs.get(2)); } /** diff --git a/engine/src/main/battlecode/world/MapBuilder.java b/engine/src/main/battlecode/world/MapBuilder.java index f07b4e2f..7bed7291 100644 --- a/engine/src/main/battlecode/world/MapBuilder.java +++ b/engine/src/main/battlecode/world/MapBuilder.java @@ -96,7 +96,7 @@ public void addTower(int id, Team team, MapLocation loc) { UnitType.LEVEL_ONE_PAINT_TOWER, UnitType.LEVEL_ONE_PAINT_TOWER.health, loc, - GameConstants.INITIAL_PAINT_TOWER_PAINT + 500 )); } diff --git a/engine/src/main/battlecode/world/RobotControllerImpl.java b/engine/src/main/battlecode/world/RobotControllerImpl.java index 6ce008f9..07d96612 100644 --- a/engine/src/main/battlecode/world/RobotControllerImpl.java +++ b/engine/src/main/battlecode/world/RobotControllerImpl.java @@ -533,9 +533,7 @@ public boolean canMark(MapLocation loc) { @Override public void mark(MapLocation loc, boolean secondary) throws GameActionException { assertCanMark(loc); - this.gameWorld.setMarker(getTeam(), loc, secondary ? 2 : 1); - this.gameWorld.getMatchMaker().addMarkAction(loc, secondary); } private void assertCanRemoveMark(MapLocation loc) throws GameActionException { @@ -560,9 +558,7 @@ public boolean canRemoveMark(MapLocation loc) { @Override public void removeMark(MapLocation loc) throws GameActionException { assertCanRemoveMark(loc); - this.gameWorld.setMarker(getTeam(), loc, 0); - this.gameWorld.getMatchMaker().addUnmarkAction(loc); } private void assertCanMarkTowerPattern(MapLocation loc) throws GameActionException { diff --git a/schema/battlecode.fbs b/schema/battlecode.fbs index b28b1387..37f9cb7f 100644 --- a/schema/battlecode.fbs +++ b/schema/battlecode.fbs @@ -41,6 +41,8 @@ table RobotTypeMetadata { actionCooldown: int; movementCooldown: int; baseHealth: int; + basePaint: int; + maxPaint: int; actionRadiusSquared: int; visionRadiusSquared: int; bytecodeLimit: int; @@ -92,7 +94,10 @@ struct AttackAction { /// Visually indicate a mop attack struct MopAction { - loc: ushort; + /// Ids of the mopped targets, possibly 0 + id0: ushort; + id1: ushort; + id2: ushort; } /// Visually indicate a tower being built