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
24 changes: 15 additions & 9 deletions client/src/playback/Actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -189,12 +189,19 @@ export const ACTION_DEFINITIONS: Record<schema.Action, typeof Action<ActionUnion
const src = round.bodies.getById(this.robotId)
const target = round.bodies.getById(this.actionData.id()) // rat getting napped

target.carriedRobot = undefined
src.carriedRobot = target.id
if(src.carriedRobot === target.id) {
// drop the target
src.carriedRobot = undefined
target.size = 1
} else {
// pick up the target
src.carriedRobot = target.id
target.carriedRobot = undefined

target.lastPos = { ...target.pos }
target.pos = { x: src.pos.x + RatNapAction.OFFSET.x, y: src.pos.y + RatNapAction.OFFSET.y }
target.size = 0.6
target.lastPos = { ...target.pos }
target.pos = { x: src.pos.x + RatNapAction.OFFSET.x, y: src.pos.y + RatNapAction.OFFSET.y }
target.size = 0.6
}
}
draw(match: Match, ctx: CanvasRenderingContext2D): void {
//target rat moves onto src rat, circle around carried group thing
Expand Down Expand Up @@ -655,16 +662,15 @@ export const ACTION_DEFINITIONS: Record<schema.Action, typeof Action<ActionUnion
draw(match: Match, ctx: CanvasRenderingContext2D): void {
const body = match.currentRound.bodies.getById(this.robotId)
const renderCoords = renderUtils.getRenderCoords(
body.pos.x - 1 + body.size / 2,
body.pos.y + body.size / 2,
body.pos.x,
body.pos.y,
match.map.dimension,
true
)
renderUtils.renderCenteredImageOrLoadingIndicator(
ctx,
getImageIfLoaded('robots/squeak.png'),
renderCoords,
1
body.size
)
}
},
Expand Down
2 changes: 1 addition & 1 deletion client/src/playback/Map.ts
Original file line number Diff line number Diff line change
Expand Up @@ -318,7 +318,7 @@ export class CurrentMap {
if (ratTrap) {
info.push('Rat Trap')
}
if (ratTrap) {
if (catTrap) {
info.push('Cat Trap')
}
if (cheese) {
Expand Down
4 changes: 2 additions & 2 deletions engine/src/main/battlecode/common/GameConstants.java
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ public class GameConstants {
public static final double CHEESE_COOLDOWN_PENALTY = 0.01;

/** The amount of cheese the rat king consumes each round. */
public static final int RAT_KING_CHEESE_CONSUMPTION = 3;
public static final int RAT_KING_CHEESE_CONSUMPTION = 2;

/** The amount of health the rat king loses by not eating cheese. */
public static final int RAT_KING_HEALTH_LOSS = 10;
Expand All @@ -101,7 +101,7 @@ public class GameConstants {
public static final int SQ_CHEESE_SPAWN_RADIUS = 4;

/** How much cheese each mine spawns at once */
public static final int CHEESE_SPAWN_AMOUNT = 5;
public static final int CHEESE_SPAWN_AMOUNT = 20;

/** The number of rat kings a player starts with. */
public static final int NUMBER_INITIAL_RAT_KINGS = 1;
Expand Down
2 changes: 1 addition & 1 deletion engine/src/main/battlecode/common/TrapType.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ public enum TrapType {
/**
* Traps enemy rats
*/
RAT_TRAP(5, 50, 20, 25, 5, 0, 25, 2),
RAT_TRAP(30, 50, 20, 25, 15, 0, 25, 2),

/**
* Traps the cat
Expand Down
2 changes: 1 addition & 1 deletion engine/src/main/battlecode/common/UnitType.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ public enum UnitType {
// health, size, speed, visionRadius, actionCooldown
BABY_RAT(100, 1, 20, 90, 10, 10, 17500),
RAT_KING(500, 3, 25, 360, 10, 40, 20000),
CAT(10_000, 2, 30, 180, 15, 10, 17500);
CAT(10_000, 2, 17, 180, 15, 20, 17500);

// amount of health robot initially starts with
public final int health;
Expand Down
4 changes: 2 additions & 2 deletions engine/src/main/battlecode/server/GameMaker.java
Original file line number Diff line number Diff line change
Expand Up @@ -559,9 +559,9 @@ public void addDamageAction(int damagedRobotID, int damage) {
});
}

public void addRatNapAction(int grabberRobotID) {
public void addRatNapAction(int nappedID) {
applyToBuilders((builder) -> {
int action = RatNap.createRatNap(builder, grabberRobotID);
int action = RatNap.createRatNap(builder, nappedID);
builder.addAction(action, Action.RatNap);
});
}
Expand Down
5 changes: 3 additions & 2 deletions engine/src/main/battlecode/world/GameWorld.java
Original file line number Diff line number Diff line change
Expand Up @@ -509,14 +509,15 @@ public void spawnCheese(CheeseMine mine) {
// corresponding one

if (spawn) {
addCheese(ogSpawnLoc, GameConstants.CHEESE_SPAWN_AMOUNT);
addCheese(pairedSpawnLoc, GameConstants.CHEESE_SPAWN_AMOUNT);

mine.setLastRound(this.currentRound);
pairedMine.setLastRound(this.currentRound);

matchMaker.addCheeseSpawnAction(ogSpawnLoc, GameConstants.CHEESE_SPAWN_AMOUNT + this.getCheeseAmount(ogSpawnLoc));
matchMaker.addCheeseSpawnAction(pairedSpawnLoc, GameConstants.CHEESE_SPAWN_AMOUNT + this.getCheeseAmount(pairedSpawnLoc));

addCheese(ogSpawnLoc, GameConstants.CHEESE_SPAWN_AMOUNT);
addCheese(pairedSpawnLoc, GameConstants.CHEESE_SPAWN_AMOUNT);
}

}
Expand Down
38 changes: 16 additions & 22 deletions engine/src/main/battlecode/world/InternalRobot.java
Original file line number Diff line number Diff line change
Expand Up @@ -585,7 +585,7 @@ public void bite(MapLocation loc, int cheeseConsumed) {

if (cheeseConsumed > 0) {
this.addCheese(-cheeseConsumed);
damage += (int) Math.ceil(Math.log(cheeseConsumed));
damage += (int) Math.ceil(Math.sqrt(cheeseConsumed));
}

targetRobot.addHealth(-damage);
Expand Down Expand Up @@ -617,7 +617,7 @@ public void scratch(MapLocation loc) {
public void grabRobot(MapLocation loc) {
this.robotBeingCarried = this.gameWorld.getRobot(loc);
this.robotBeingCarried.getGrabbed(this); // Notify the grabbed robot that it has been picked up
this.gameWorld.getMatchMaker().addRatNapAction(this.getID());
this.gameWorld.getMatchMaker().addRatNapAction(this.robotBeingCarried.getID());

if (this.robotBeingCarried.getTeam() != this.getTeam()) {
this.gameWorld.isCooperation = false;
Expand Down Expand Up @@ -650,11 +650,10 @@ private void swapGrabber() {
this.gameWorld.removeRobot(dropLoc);
this.gameWorld.addRobot(dropLoc, this);

this.gameWorld.getMatchMaker().addRatNapAction(this.ID);
this.gameWorld.getMatchMaker().addRatNapAction(this.ID); // expand this rat
this.gameWorld.getMatchMaker().addRatNapAction(grabber.ID); // shrink carrier rat

if (grabber.getTeam() != this.getTeam()) {
grabber.remainingCarriedDuration = GameConstants.MAX_CARRY_DURATION;
}
grabber.remainingCarriedDuration = GameConstants.MAX_CARRY_DURATION;
}

private void getGrabbed(InternalRobot grabber) {
Expand All @@ -668,9 +667,7 @@ private void getGrabbed(InternalRobot grabber) {

this.setInternalLocationOnly(grabber.getLocation());

if (grabber.getTeam() != this.getTeam()) {
this.remainingCarriedDuration = GameConstants.MAX_CARRY_DURATION;
}
this.remainingCarriedDuration = GameConstants.MAX_CARRY_DURATION;

}

Expand All @@ -688,18 +685,11 @@ private void getThrown(Direction dir) {
this.thrownDir = dir;
this.remainingThrowDuration = 4;

MapLocation nextLoc = this.getLocation().add(dir);
this.setInternalLocationOnly(this.getLocation());
this.gameWorld.removeRobot(this.getLocation());

// Cat feeding!
if (this.gameWorld.getRobot(nextLoc) != null) { // there's a cat here
this.addHealth(-this.getHealth()); // rat dies :(
// put cat to sleep
this.gameWorld.getRobot(nextLoc).sleepTimeRemaining = GameConstants.CAT_SLEEP_TIME;
this.gameWorld.getMatchMaker().addCatFeedAction(this.getID());
} else {
this.setInternalLocationOnly(this.getLocation().add(dir));
this.gameWorld.removeRobot(this.getLocation());
}
this.travelFlying(true);
this.travelFlying(false);
}

public void getDropped(MapLocation loc) {
Expand All @@ -714,6 +704,8 @@ public void getDropped(MapLocation loc) {
this.grabbedByRobot = null;
this.remainingCarriedDuration = 0;
this.setInternalLocationOnly(loc);

this.gameWorld.getMatchMaker().addRatNapAction(this.getID());

if (this.getHealth() > 0)
this.gameWorld.addRobot(this.getLocation(), this);
Expand All @@ -729,6 +721,8 @@ public void hitGround() {
this.addHealth(-damage);

this.gameWorld.getMatchMaker().addDamageAction(this.ID, damage);
this.gameWorld.getMatchMaker().addRatNapAction(this.getID());


if (this.health > 0) {
this.gameWorld.addRobot(this.location, this);
Expand Down Expand Up @@ -760,6 +754,7 @@ public void hitTarget(boolean isSecondMove) {
setActionCooldownTurns(this.actionCooldownTurns + GameConstants.HIT_TARGET_COOLDOWN);
setTurningCooldownTurns(this.turningCooldownTurns + GameConstants.HIT_TARGET_COOLDOWN);
this.gameWorld.getMatchMaker().addDamageAction(this.ID, damage);
this.gameWorld.getMatchMaker().addRatNapAction(this.getID());

this.gameWorld.getMatchMaker().addStunAction(this.ID, GameConstants.HIT_TARGET_COOLDOWN);
}
Expand Down Expand Up @@ -1053,8 +1048,7 @@ public void processBeginningOfTurn() {
this.gameWorld.runCheeseMines();

// if rat is being carried
if (this.getType() == UnitType.BABY_RAT && this.isGrabbedByRobot()
&& this.getGrabbedByRobot().getTeam() != this.getTeam()) {
if (this.getType() == UnitType.BABY_RAT && this.isGrabbedByRobot()) {

// check if grabber has died
if (this.getGrabbedByRobot().getHealth() <= 0) {
Expand Down
24 changes: 21 additions & 3 deletions engine/src/main/battlecode/world/RobotControllerImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -950,12 +950,14 @@ private void assertCanAttackRat(MapLocation loc, int cheeseConsumed) throws Game
assertIsActionReady();
// Attack is limited to vision radius
assertCanActLocation(loc, this.getType().getVisionRadiusSquared());

if (!this.getLocation().isAdjacentTo(loc)) {
throw new GameActionException(CANT_DO_THAT, "Rats can only attack adjacent squares!");
}

if (!this.gameWorld.isPassable(loc))
if (!this.gameWorld.isPassable(loc)) {
throw new GameActionException(CANT_DO_THAT, "Rats cannot attack squares with walls or dirt on them!");
}

if (this.gameWorld.getTeamInfo().getCheese(this.getTeam()) + this.getAllCheese() < cheeseConsumed) {
throw new GameActionException(CANT_DO_THAT, "Not enough cheese to bite!");
Expand All @@ -964,13 +966,29 @@ private void assertCanAttackRat(MapLocation loc, int cheeseConsumed) throws Game
if (this.getType() == UnitType.CAT) {
throw new GameActionException(CANT_DO_THAT, "Unit must be a baby rat or rat king to bite!");
}

if (cheeseConsumed < 0) {
throw new GameActionException(CANT_DO_THAT, "Cheese consumed must be non-negative!");
}

if (this.gameWorld.getRobot(loc) == null) {
throw new GameActionException(CANT_DO_THAT, "No robot to attack at the specified location!");
}
}

private void assertCanAttackCat(MapLocation loc) throws GameActionException {
assertIsActionReady();
assertCanActLocation(loc, this.getType().getVisionRadiusSquared());
if (!this.gameWorld.isPassable(loc))

if (!this.gameWorld.isPassable(loc)) {
throw new GameActionException(CANT_DO_THAT, "Cats cannot attack squares with walls or dirt on them!");
}
if (this.gameWorld.getRobot(loc) == null) {
throw new GameActionException(CANT_DO_THAT, "No robot to attack at the specified location!");
}
if (this.gameWorld.getRobot(loc) != null && this.gameWorld.getRobot(loc).getID() == this.robot.getID()) {
throw new GameActionException(CANT_DO_THAT, "Cannot attack self");
}
}

private void assertCanAttack(MapLocation loc, int cheeseConsumed) throws GameActionException {
Expand Down Expand Up @@ -1316,7 +1334,7 @@ public void assertCanCarryRat(MapLocation loc) throws GameActionException {
}

// adjacency
if (!loc.isAdjacentTo(this.getLocation())) {
if (!loc.isAdjacentTo(this.getLocation()) && !this.getLocation().equals(loc)) {
throw new GameActionException(CANT_DO_THAT, "A rat can only grab adjacent robots!");
}

Expand Down