@@ -72,9 +72,10 @@ private InternalRobot getRobotByID(int id) {
7272 // }
7373
7474 private MapInfo getMapInfo (MapLocation loc ) throws GameActionException {
75+ Team team = this .getTeam ();
7576 GameWorld gw = this .gameWorld ;
76- Trap trap = gw .getTrap (loc );
77- TrapType trapType = (trap != null && trap . getTeam () == this . getTeam () ) ? trap .getType () : TrapType .NONE ;
77+ Trap trap = gw .getTrap (loc , team );
78+ TrapType trapType = (trap != null ) ? trap .getType () : TrapType .NONE ;
7879 MapInfo currentLocInfo = new MapInfo (loc , gw .isPassable (loc ), gw .getWall (loc ), gw .getDirt (loc ),
7980 gw .getCheeseAmount (loc ), trapType ,
8081 gw .hasCheeseMine (loc ));
@@ -212,9 +213,11 @@ private void assertCanActLocation(MapLocation loc, int maxRadiusSquared) throws
212213 ? (getLocation ().bottomLeftDistanceSquaredTo (loc ))
213214 : (getLocation ().distanceSquaredTo (loc ));
214215
215- float addDistance = (float ) Math .ceil ((this .getType ().size / (2.0 ) + Math .sqrt ((double ) maxRadiusSquared ))
216- * (this .getType ().size / 2.0 + Math .sqrt ((double ) maxRadiusSquared )));
217- if (distance > (addDistance ))
216+ // float addDistance = (float) Math.ceil((this.getType().size / (2.0) + Math.sqrt((double) maxRadiusSquared))
217+ // * (this.getType().size / 2.0 + Math.sqrt((double) maxRadiusSquared)));
218+ float addDistance = maxRadiusSquared ;
219+
220+ if (distance > addDistance )
218221 throw new GameActionException (OUT_OF_RANGE ,
219222 "Target location not within action range" );
220223 }
@@ -304,16 +307,16 @@ public boolean canRemoveDirt(MapLocation loc) {
304307
305308 private void assertCanRemoveRatTrap (MapLocation loc ) throws GameActionException {
306309 UnitType myType = this .robot .getType ();
310+ Team myTeam = this .getTeam ();
307311
308312 assertIsRobotType (myType );
309313 assertCanActLocation (loc , myType == UnitType .RAT_KING
310314 ? GameConstants .RAT_KING_BUILD_DISTANCE_SQUARED
311315 : GameConstants .BUILD_DISTANCE_SQUARED );
312316
313- if (!this .gameWorld .hasRatTrap (loc ))
317+ if (!this .gameWorld .hasRatTrap (loc , myTeam )) {
314318 throw new GameActionException (CANT_DO_THAT , "No rat trap to remove at that location!" );
315- if (this .gameWorld .getTrap (loc ).getTeam () != this .getTeam ())
316- throw new GameActionException (CANT_DO_THAT , "Can't remove an enemy team's rat trap!" );
319+ }
317320 }
318321
319322 private void assertCanPlaceTrap (MapLocation loc , TrapType trapType ) throws GameActionException {
@@ -331,7 +334,7 @@ private void assertCanPlaceTrap(MapLocation loc, TrapType trapType) throws GameA
331334 throw new GameActionException (CANT_DO_THAT , "Can't place trap on a wall or dirt!" );
332335 if (this .gameWorld .getRobot (loc ) != null )
333336 throw new GameActionException (CANT_DO_THAT , "Can't place trap on an occupied tile!" );
334- if (this .gameWorld .hasTrap (loc ))
337+ if (this .gameWorld .hasTrap (loc , this . robot . getTeam () ))
335338 throw new GameActionException (CANT_DO_THAT , "Tile already has a trap!" );
336339 if (this .gameWorld .getTrapCount (trapType , this .robot .getTeam ()) >= trapType .maxCount )
337340 throw new GameActionException (CANT_DO_THAT ,
@@ -344,11 +347,16 @@ private void assertCanPlaceTrap(MapLocation loc, TrapType trapType) throws GameA
344347 }
345348
346349 private void assertCanRemoveCatTrap (MapLocation loc ) throws GameActionException {
347- assertIsRobotType (this .robot .getType ());
348- assertCanActLocation (loc , GameConstants .BUILD_DISTANCE_SQUARED );
350+ UnitType myType = this .robot .getType ();
349351
350- if (!this .gameWorld .hasCatTrap (loc ))
352+ assertIsRobotType (myType );
353+ assertCanActLocation (loc , myType == UnitType .RAT_KING
354+ ? GameConstants .RAT_KING_BUILD_DISTANCE_SQUARED
355+ : GameConstants .BUILD_DISTANCE_SQUARED );
356+
357+ if (!this .gameWorld .hasCatTrap (loc , this .getTeam ())) {
351358 throw new GameActionException (CANT_DO_THAT , "No cat trap to remove at that location!" );
359+ }
352360 }
353361
354362 @ Override
@@ -379,9 +387,10 @@ public boolean canRemoveRatTrap(MapLocation loc) {
379387
380388 @ Override
381389 public void removeRatTrap (MapLocation loc ) throws GameActionException {
390+ Team team = this .getTeam ();
382391 assertCanRemoveRatTrap (loc );
383- Trap trap = this .gameWorld .getTrap (loc );
384- this .gameWorld .removeTrap (loc );
392+ Trap trap = this .gameWorld .getTrap (loc , team );
393+ this .gameWorld .removeTrap (loc , team );
385394 this .gameWorld .getMatchMaker ().addRemoveTrapAction (trap .getLocation (), trap .getTeam ());
386395 }
387396
@@ -413,9 +422,10 @@ public boolean canRemoveCatTrap(MapLocation loc) {
413422
414423 @ Override
415424 public void removeCatTrap (MapLocation loc ) throws GameActionException {
425+ Team team = this .getTeam ();
416426 assertCanRemoveCatTrap (loc );
417- Trap trap = this .gameWorld .getTrap (loc );
418- this .gameWorld .removeTrap (loc );
427+ Trap trap = this .gameWorld .getTrap (loc , team );
428+ this .gameWorld .removeTrap (loc , team );
419429 this .gameWorld .getMatchMaker ().addRemoveTrapAction (trap .getLocation (), trap .getTeam ());
420430 }
421431
@@ -959,11 +969,12 @@ public void buildTrap(TrapType type, MapLocation loc) throws GameActionException
959969 this .robot .addActionCooldownTurns (type .actionCooldown );
960970 this .robot .addCheese (-type .buildCost );
961971
972+ Team team = this .getTeam ();
962973 int trapId = this .gameWorld .idGenerator .nextID ();
963- Trap newTrap = new Trap (loc , type , this . getTeam () , trapId );
974+ Trap newTrap = new Trap (loc , type , team , trapId );
964975
965976 this .gameWorld .placeTrap (loc , newTrap );
966- this .gameWorld .getMatchMaker ().addPlaceTrapAction (trapId , loc , getTeam () , type );
977+ this .gameWorld .getMatchMaker ().addPlaceTrapAction (trapId , loc , team , type );
967978 }
968979
969980 // *****************************
@@ -1284,7 +1295,7 @@ private void assertCanTransferCheese(MapLocation loc, int amount) throws GameAct
12841295 throw new GameActionException (CANT_DO_THAT , "Cannot transfer resources to the enemy team!" );
12851296 }
12861297 if (!this .robot .getType ().isBabyRatType ()) {
1287- throw new GameActionException (CANT_DO_THAT , "Only rats can transfer cheese!" );
1298+ throw new GameActionException (CANT_DO_THAT , "Only baby rats can transfer cheese!" );
12881299 }
12891300 if (!robot .getType ().isRatKingType ()) {
12901301 throw new GameActionException (CANT_DO_THAT , "Only rat kings can receive cheese!" );
0 commit comments