Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -856,6 +856,12 @@ private void fireBullets(List<BulletCommand> bulletCommands) {
println("SYSTEM: You cannot call fire(NaN)");
continue;
}
// Skip commands that have already fired: the command list is shared
// across turns, so a robot that stops executing would otherwise
// re-fire the same command (and its bullet id) on every cooldown.
if (bulletCmd.isConsumed()) {
continue;
}
if (gunHeat > 0 || energy == 0) {
return;
}
Expand All @@ -877,6 +883,9 @@ private void fireBullets(List<BulletCommand> bulletCommands) {
}
newBullet.setX(x);
newBullet.setY(y);

// Mark consumed so this command cannot fire again on a later cooldown.
bulletCmd.consume();
}
// there is only last bullet in one turn
if (newBullet != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,19 @@ public BulletCommand(double power, boolean fireAssistValid, double fireAssistAng
private final double fireAssistAngle;
private final int bulletId;

// Battle-side only: marks that this command has already fired a bullet, so it
// is not fired again on a later cooldown when the command list persists across
// turns (e.g. after the robot stops executing). Not part of the wire format.
private transient boolean consumed;

public boolean isConsumed() {
return consumed;
}

public void consume() {
consumed = true;
}

public boolean isFireAssistValid() {
return fireAssistValid;
}
Expand Down