Skip to content

Commit 130a277

Browse files
Merge branch 'schema' into client
2 parents a953b24 + 6c18594 commit 130a277

24 files changed

Lines changed: 244 additions & 108 deletions

client/src/playback/Actions.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -182,9 +182,10 @@ export const ACTION_DEFINITIONS: Record<schema.Action, typeof Action<ActionUnion
182182
// To discuss
183183
}
184184
draw(match: Match, ctx: CanvasRenderingContext2D): void {
185+
const body = match.currentRound.bodies.getById(this.robotId)
185186
const radius = Math.sqrt(4)
186187
const map = match.currentRound.map
187-
const loc = map.indexToLocation(this.actionData.loc())
188+
const loc = body.getInterpolatedCoords(match)
188189
const coords = renderUtils.getRenderCoords(loc.x, loc.y, map.dimension, true)
189190

190191
// Get the trap color, assumes only opposite team can trigger

client/src/playback/Bodies.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -449,11 +449,13 @@ export class Body {
449449
}
450450

451451
public onHoverInfo(): string[] {
452+
if (!this.game.playable) return [this.robotName]
453+
452454
const defaultInfo = [
453455
`${this.robotName}${this.level === 2 ? ' (Lvl II)' : ''}${this.level >= 3 ? ' (Lvl III)' : ''}`,
454456
`ID: ${this.id}`,
455-
`HP: ${this.hp}`,
456-
`Paint: ${this.paint}`,
457+
`HP: ${this.hp}/${this.metadata.baseHealth()}`,
458+
`Paint: ${this.paint}/${this.metadata.maxPaint()}`,
457459
`Location: (${this.pos.x}, ${this.pos.y})`,
458460
`Move Cooldown: ${this.moveCooldown}`,
459461
`Action Cooldown: ${this.actionCooldown}`,
@@ -487,6 +489,7 @@ export class Body {
487489
const metadata = this.metadata
488490

489491
this.hp = metadata.baseHealth()
492+
this.paint = metadata.basePaint()
490493
this.actionCooldown = metadata.actionCooldown()
491494
this.moveCooldown = metadata.movementCooldown()
492495
}

engine/src/main/battlecode/common/GameConstants.java

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -101,11 +101,8 @@ public class GameConstants {
101101
/** The number of defense towers a player starts with */
102102
public static final int NUMBER_INITIAL_DEFENSE_TOWERS = 0;
103103

104-
/** The amount of a paint a paint tower starts with. */
105-
public static final int INITIAL_PAINT_TOWER_PAINT = 500;
106-
107-
/** The percentage of a robot's paint capacity that is full when first built. */
108-
public static final int INITIAL_ROBOT_PAINT_PERCENTAGE = 50;
104+
/** The percentage of a unit's paint capacity that is full when first built. */
105+
public static final int INITIAL_UNIT_PAINT_PERCENTAGE = 50;
109106

110107
/** The width and height of the patterns that robots can draw */
111108
public static final int PATTERN_SIZE = 5;

engine/src/main/battlecode/schema/MopAction.java

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
12
// automatically generated by the FlatBuffers compiler, do not modify
23

34
package battlecode.schema;
@@ -27,11 +28,18 @@ public final class MopAction extends Struct {
2728
public void __init(int _i, ByteBuffer _bb) { __reset(_i, _bb); }
2829
public MopAction __assign(int _i, ByteBuffer _bb) { __init(_i, _bb); return this; }
2930

30-
public int loc() { return bb.getShort(bb_pos + 0) & 0xFFFF; }
31-
32-
public static int createMopAction(FlatBufferBuilder builder, int loc) {
33-
builder.prep(2, 2);
34-
builder.putShort((short) loc);
31+
/**
32+
* Ids of the mopped targets, possibly 0
33+
*/
34+
public int id0() { return bb.getShort(bb_pos + 0) & 0xFFFF; }
35+
public int id1() { return bb.getShort(bb_pos + 2) & 0xFFFF; }
36+
public int id2() { return bb.getShort(bb_pos + 4) & 0xFFFF; }
37+
38+
public static int createMopAction(FlatBufferBuilder builder, int id0, int id1, int id2) {
39+
builder.prep(2, 6);
40+
builder.putShort((short) id2);
41+
builder.putShort((short) id1);
42+
builder.putShort((short) id0);
3543
return builder.offset();
3644
}
3745

@@ -42,4 +50,3 @@ public static final class Vector extends BaseVector {
4250
public MopAction get(MopAction obj, int j) { return obj.__assign(__element(j), bb); }
4351
}
4452
}
45-

engine/src/main/battlecode/schema/RobotTypeMetadata.java

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -31,37 +31,45 @@ public final class RobotTypeMetadata extends Table {
3131
public int actionCooldown() { int o = __offset(6); return o != 0 ? bb.getInt(o + bb_pos) : 0; }
3232
public int movementCooldown() { int o = __offset(8); return o != 0 ? bb.getInt(o + bb_pos) : 0; }
3333
public int baseHealth() { int o = __offset(10); return o != 0 ? bb.getInt(o + bb_pos) : 0; }
34-
public int actionRadiusSquared() { int o = __offset(12); return o != 0 ? bb.getInt(o + bb_pos) : 0; }
35-
public int visionRadiusSquared() { int o = __offset(14); return o != 0 ? bb.getInt(o + bb_pos) : 0; }
36-
public int bytecodeLimit() { int o = __offset(16); return o != 0 ? bb.getInt(o + bb_pos) : 0; }
34+
public int basePaint() { int o = __offset(12); return o != 0 ? bb.getInt(o + bb_pos) : 0; }
35+
public int maxPaint() { int o = __offset(14); return o != 0 ? bb.getInt(o + bb_pos) : 0; }
36+
public int actionRadiusSquared() { int o = __offset(16); return o != 0 ? bb.getInt(o + bb_pos) : 0; }
37+
public int visionRadiusSquared() { int o = __offset(18); return o != 0 ? bb.getInt(o + bb_pos) : 0; }
38+
public int bytecodeLimit() { int o = __offset(20); return o != 0 ? bb.getInt(o + bb_pos) : 0; }
3739

3840
public static int createRobotTypeMetadata(FlatBufferBuilder builder,
3941
byte type,
4042
int actionCooldown,
4143
int movementCooldown,
4244
int baseHealth,
45+
int basePaint,
46+
int maxPaint,
4347
int actionRadiusSquared,
4448
int visionRadiusSquared,
4549
int bytecodeLimit) {
46-
builder.startTable(7);
50+
builder.startTable(9);
4751
RobotTypeMetadata.addBytecodeLimit(builder, bytecodeLimit);
4852
RobotTypeMetadata.addVisionRadiusSquared(builder, visionRadiusSquared);
4953
RobotTypeMetadata.addActionRadiusSquared(builder, actionRadiusSquared);
54+
RobotTypeMetadata.addMaxPaint(builder, maxPaint);
55+
RobotTypeMetadata.addBasePaint(builder, basePaint);
5056
RobotTypeMetadata.addBaseHealth(builder, baseHealth);
5157
RobotTypeMetadata.addMovementCooldown(builder, movementCooldown);
5258
RobotTypeMetadata.addActionCooldown(builder, actionCooldown);
5359
RobotTypeMetadata.addType(builder, type);
5460
return RobotTypeMetadata.endRobotTypeMetadata(builder);
5561
}
5662

57-
public static void startRobotTypeMetadata(FlatBufferBuilder builder) { builder.startTable(7); }
63+
public static void startRobotTypeMetadata(FlatBufferBuilder builder) { builder.startTable(9); }
5864
public static void addType(FlatBufferBuilder builder, byte type) { builder.addByte(0, type, 0); }
5965
public static void addActionCooldown(FlatBufferBuilder builder, int actionCooldown) { builder.addInt(1, actionCooldown, 0); }
6066
public static void addMovementCooldown(FlatBufferBuilder builder, int movementCooldown) { builder.addInt(2, movementCooldown, 0); }
6167
public static void addBaseHealth(FlatBufferBuilder builder, int baseHealth) { builder.addInt(3, baseHealth, 0); }
62-
public static void addActionRadiusSquared(FlatBufferBuilder builder, int actionRadiusSquared) { builder.addInt(4, actionRadiusSquared, 0); }
63-
public static void addVisionRadiusSquared(FlatBufferBuilder builder, int visionRadiusSquared) { builder.addInt(5, visionRadiusSquared, 0); }
64-
public static void addBytecodeLimit(FlatBufferBuilder builder, int bytecodeLimit) { builder.addInt(6, bytecodeLimit, 0); }
68+
public static void addBasePaint(FlatBufferBuilder builder, int basePaint) { builder.addInt(4, basePaint, 0); }
69+
public static void addMaxPaint(FlatBufferBuilder builder, int maxPaint) { builder.addInt(5, maxPaint, 0); }
70+
public static void addActionRadiusSquared(FlatBufferBuilder builder, int actionRadiusSquared) { builder.addInt(6, actionRadiusSquared, 0); }
71+
public static void addVisionRadiusSquared(FlatBufferBuilder builder, int visionRadiusSquared) { builder.addInt(7, visionRadiusSquared, 0); }
72+
public static void addBytecodeLimit(FlatBufferBuilder builder, int bytecodeLimit) { builder.addInt(8, bytecodeLimit, 0); }
6573
public static int endRobotTypeMetadata(FlatBufferBuilder builder) {
6674
int o = builder.endTable();
6775
return o;
@@ -73,5 +81,4 @@ public static final class Vector extends BaseVector {
7381
public RobotTypeMetadata get(int j) { return get(new RobotTypeMetadata(), j); }
7482
public RobotTypeMetadata get(RobotTypeMetadata obj, int j) { return obj.__assign(__indirect(__element(j), bb), bb); }
7583
}
76-
}
77-
84+
}

engine/src/main/battlecode/server/GameMaker.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -301,6 +301,8 @@ public int makeRobotTypeMetadata(FlatBufferBuilder builder){
301301
}
302302
RobotTypeMetadata.startRobotTypeMetadata(builder);
303303
RobotTypeMetadata.addType(builder, FlatHelpers.getRobotTypeFromUnitType(type));
304+
RobotTypeMetadata.addMaxPaint(builder, type.paintCapacity);
305+
RobotTypeMetadata.addBasePaint(builder, (int) Math.round(type.paintCapacity * GameConstants.INITIAL_UNIT_PAINT_PERCENTAGE / 100.0));
304306
RobotTypeMetadata.addActionCooldown(builder, type.actionCooldown);
305307
RobotTypeMetadata.addActionRadiusSquared(builder, type.actionRadiusSquared);
306308
RobotTypeMetadata.addBaseHealth(builder,type.health);
@@ -543,9 +545,9 @@ public void addAttackAction(int otherID){
543545
}
544546

545547
/// Visually indicate a mop attack
546-
public void addMopAction(MapLocation loc){
548+
public void addMopAction(int id1, int id2, int id3){
547549
applyToBuilders((builder) -> {
548-
int action = MopAction.createMopAction(builder, locationToInt(loc));
550+
int action = MopAction.createMopAction(builder, id1, id2, id3);
549551
builder.addAction(action, Action.MopAction);
550552
});
551553
}

engine/src/main/battlecode/world/GameMapIO.java

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -358,23 +358,11 @@ private static void initInitialBodiesFromSchemaBodyTable(InitialBodyTable bodyTa
358358
if (teamsReversed){
359359
bodyTeam = bodyTeam.opponent();
360360
}
361-
int initialPaint = (bodyType == UnitType.LEVEL_ONE_PAINT_TOWER) ? GameConstants.INITIAL_PAINT_TOWER_PAINT : 0;
361+
int initialPaint = (int) Math.round(bodyType.paintCapacity * GameConstants.INITIAL_UNIT_PAINT_PERCENTAGE / 100.0);
362362
initialBodies.add(new RobotInfo(curId, bodyTeam, bodyType, bodyType.health, new MapLocation(bodyX, bodyY), initialPaint));
363363
}
364364
}
365365

366-
// private static int createSpawnActionsVector(FlatBufferBuilder builder, ArrayList<Integer> ids, ArrayList<Integer> xs, ArrayList<Integer> ys, ArrayList<Byte> teams, ArrayList<Byte> types){
367-
// ByteBuffer bb = builder.createUnintializedVector(6, xs.size(), 2);
368-
// for (int i = 0; i < xs.size(); i++){
369-
// bb.putInt(ids.get(i));
370-
// bb.putShort((short)(int)xs.get(i));
371-
// bb.putShort((short)(int)ys.get(i));
372-
// bb.put(teams.get(i));
373-
// bb.put(types.get(i));
374-
// }
375-
// return builder.endVector();
376-
// }
377-
378366
private static int createSpawnActionsVector(FlatBufferBuilder builder, ArrayList<Integer> ids, ArrayList<Integer> xs, ArrayList<Integer> ys, ArrayList<Byte> teams, ArrayList<Byte> types){
379367
InitialBodyTable.startSpawnActionsVector(builder, ids.size());
380368
for (int i = 0; i < ids.size(); i++){

engine/src/main/battlecode/world/GameWorld.java

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -432,6 +432,12 @@ public int getMarker(Team team, MapLocation loc) {
432432
}
433433

434434
public void setMarker(Team team, MapLocation loc, int marker) {
435+
if (marker == 0){
436+
this.matchMaker.addUnmarkAction(loc);
437+
}
438+
else {
439+
this.matchMaker.addMarkAction(loc, !isPrimaryPaint(marker));
440+
}
435441
this.getmarkersArray(team)[locationToIndex(loc)] = marker;
436442
}
437443

@@ -947,10 +953,7 @@ public int spawnRobot(int ID, UnitType type, MapLocation location, Team team){
947953
if (type.isTowerType()){
948954
this.teamInfo.addTowers(1, team);
949955
}
950-
if (type == UnitType.LEVEL_ONE_PAINT_TOWER)
951-
robot.addPaint(GameConstants.INITIAL_PAINT_TOWER_PAINT);
952-
else if (type.isRobotType())
953-
robot.addPaint((int) Math.round(type.paintCapacity * GameConstants.INITIAL_ROBOT_PAINT_PERCENTAGE / 100.0));
956+
robot.addPaint((int) Math.round(type.paintCapacity * GameConstants.INITIAL_UNIT_PAINT_PERCENTAGE / 100.0));
954957
return ID;
955958
}
956959

engine/src/main/battlecode/world/InternalRobot.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -469,6 +469,7 @@ public void mopSwing(Direction dir) { // NOTE: only works for moppers!
469469
if(dir == Direction.SOUTH) dirIdx = 1;
470470
else if(dir == Direction.EAST) dirIdx = 2;
471471
else if(dir == Direction.WEST) dirIdx = 3;
472+
ArrayList<Integer> affectedIDs = new ArrayList<>();
472473

473474
for(int i = 0; i < 3; i ++) { // check all three spots
474475
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!
480481
InternalRobot robot = this.gameWorld.getRobot(newLoc);
481482
if(this.team != robot.getTeam()){
482483
robot.addPaint(-GameConstants.MOPPER_SWING_PAINT_DEPLETION);
483-
this.gameWorld.getMatchMaker().addAttackAction(robot.getID());
484+
affectedIDs.add(robot.ID);
484485
}
485486
}
486487
}
487-
MapLocation centerLoc = this.location.add(dir);
488-
this.gameWorld.getMatchMaker().addMopAction(centerLoc);
488+
for (int i = 0; i < 3; i++) affectedIDs.add(0);
489+
this.gameWorld.getMatchMaker().addMopAction(affectedIDs.get(0), affectedIDs.get(1), affectedIDs.get(2));
489490
}
490491

491492
/**

engine/src/main/battlecode/world/MapBuilder.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ public void addTower(int id, Team team, MapLocation loc) {
9696
UnitType.LEVEL_ONE_PAINT_TOWER,
9797
UnitType.LEVEL_ONE_PAINT_TOWER.health,
9898
loc,
99-
GameConstants.INITIAL_PAINT_TOWER_PAINT
99+
500
100100
));
101101
}
102102

0 commit comments

Comments
 (0)