22
33import java .util .*;
44
5- import battlecode .world .CatStateType ;
65import battlecode .common .Direction ;
76import battlecode .common .GameActionException ;
87import battlecode .common .GameConstants ;
@@ -616,7 +615,6 @@ public void scratch(MapLocation loc) {
616615 }
617616
618617 public void grabRobot (MapLocation loc ) {
619-
620618 this .robotBeingCarried = this .gameWorld .getRobot (loc );
621619 this .robotBeingCarried .getGrabbed (this ); // Notify the grabbed robot that it has been picked up
622620 this .gameWorld .getMatchMaker ().addRatNapAction (this .getID ());
@@ -627,21 +625,7 @@ public void grabRobot(MapLocation loc) {
627625 }
628626
629627 public void dropRobot (Direction dir ) {
630- if (!this .type .isThrowingType ()) {
631- throw new RuntimeException ("Unit must be a rat to drop other rats" );
632- } else if (!this .isCarryingRobot ()) {
633- throw new RuntimeException ("Not carrying a robot to drop" );
634- }
635628 MapLocation dropLoc = this .getLocation ().add (dir );
636- if (!this .gameWorld .getGameMap ().onTheMap (dropLoc )) {
637- throw new RuntimeException ("Cannot drop outside of map" );
638- } else if (this .gameWorld .getRobot (dropLoc ) != null ) {
639- throw new RuntimeException ("Cannot drop into occupied space" );
640- } else if (!this .gameWorld .isPassable (dropLoc )) {
641- throw new RuntimeException ("Cannot drop into impassable terrain" );
642- }
643-
644- // Drop the robot
645629 this .robotBeingCarried .getDropped (dropLoc );
646630 this .robotBeingCarried = null ;
647631 }
@@ -676,10 +660,12 @@ private void swapGrabber() {
676660 private void getGrabbed (InternalRobot grabber ) {
677661 this .grabbedByRobot = grabber ;
678662 this .gameWorld .removeRobot (getLocation ());
663+
679664 if (this .isCarryingRobot ()) { // If we were carrying a robot, drop it
680665 this .robotBeingCarried .getDropped (getLocation ());
681666 this .robotBeingCarried = null ;
682667 }
668+
683669 this .setInternalLocationOnly (grabber .getLocation ());
684670
685671 if (grabber .getTeam () != this .getTeam ()) {
@@ -689,19 +675,6 @@ private void getGrabbed(InternalRobot grabber) {
689675 }
690676
691677 public void throwRobot () {
692- if (!this .type .isThrowingType ()) {
693- throw new RuntimeException ("Unit must be a rat to throw other rats" );
694- } else if (!this .isCarryingRobot ()) {
695- throw new RuntimeException ("Not carrying a robot to throw" );
696- }
697- if (!this .gameWorld .getGameMap ().onTheMap (this .getLocation ().add (this .dir ))) {
698- throw new RuntimeException ("Cannot throw outside of map" );
699- } else if (this .gameWorld .getRobot (this .getLocation ().add (this .dir )) != null
700- && this .gameWorld .getRobot (this .getLocation ().add (this .dir )).getType () != UnitType .CAT ) {
701- throw new RuntimeException ("Cannot throw into a space occupied by another rat" );
702- }
703-
704- // Throw the robot
705678 this .robotBeingCarried .getThrown (this .dir );
706679 this .gameWorld .getMatchMaker ().addThrowAction (this .robotBeingCarried .getID (),
707680 this .getLocation ().add (this .dir ));
@@ -737,6 +710,7 @@ public void getDropped(MapLocation loc) {
737710 } else if (!this .gameWorld .isPassable (loc )) {
738711 throw new RuntimeException ("Cannot drop into impassable terrain" );
739712 }
713+
740714 this .grabbedByRobot = null ;
741715 this .remainingCarriedDuration = 0 ;
742716 this .setInternalLocationOnly (loc );
0 commit comments