Skip to content

Commit b1a9065

Browse files
author
Ian Gonzalez Hermosillo
committed
fix building upgraded towers for cheap
1 parent 5703f52 commit b1a9065

File tree

1 file changed

+4
-16
lines changed

1 file changed

+4
-16
lines changed

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

Lines changed: 4 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -713,21 +713,8 @@ public void markResourcePattern(MapLocation loc, int rotationAngle, boolean refl
713713
this.gameWorld.markResourcePattern(getTeam(), loc, rotationAngle, reflect);
714714
}
715715

716-
private UnitType getBaseUnitType(UnitType type){
717-
UnitType baseType;
718-
switch (type){
719-
case LEVEL_TWO_DEFENSE_TOWER: baseType = UnitType.LEVEL_ONE_DEFENSE_TOWER; break;
720-
case LEVEL_THREE_DEFENSE_TOWER: baseType = UnitType.LEVEL_ONE_DEFENSE_TOWER; break;
721-
case LEVEL_TWO_MONEY_TOWER: baseType = UnitType.LEVEL_ONE_MONEY_TOWER; break;
722-
case LEVEL_THREE_MONEY_TOWER: baseType = UnitType.LEVEL_ONE_MONEY_TOWER; break;
723-
case LEVEL_TWO_PAINT_TOWER: baseType = UnitType.LEVEL_ONE_PAINT_TOWER; break;
724-
case LEVEL_THREE_PAINT_TOWER: baseType = UnitType.LEVEL_ONE_PAINT_TOWER; break;
725-
default: baseType = type;
726-
}
727-
return baseType;
728-
}
729-
730716
private void assertCanCompleteTowerPattern(UnitType type, MapLocation loc) throws GameActionException {
717+
type = type.getBaseType();
731718
assertIsRobotType(this.robot.getType());
732719
assertIsTowerType(type);
733720
assertCanActLocation(loc, GameConstants.BUILD_TOWER_RADIUS_SQUARED);
@@ -744,7 +731,7 @@ private void assertCanCompleteTowerPattern(UnitType type, MapLocation loc) throw
744731
+ ") because the center is not a ruin");
745732
}
746733

747-
if (getMoney() < getBaseUnitType(type).moneyCost){
734+
if (getMoney() < type.moneyCost){
748735
throw new GameActionException(CANT_DO_THAT,
749736
"Cannot complete tower pattern centered at (" + loc.x + ", " + loc.y
750737
+ ") because the team does not have enough money!");
@@ -790,10 +777,11 @@ public boolean canCompleteTowerPattern(UnitType type, MapLocation loc) {
790777

791778
@Override
792779
public void completeTowerPattern(UnitType type, MapLocation loc) throws GameActionException {
780+
type = type.getBaseType();
793781
assertCanCompleteTowerPattern(type, loc);
794782
this.gameWorld.completeTowerPattern(getTeam(), type, loc);
795783
InternalRobot tower = this.gameWorld.getRobot(loc);
796-
this.gameWorld.getTeamInfo().addMoney(getTeam(), -getBaseUnitType(type).moneyCost);
784+
this.gameWorld.getTeamInfo().addMoney(getTeam(), -type.moneyCost);
797785
this.gameWorld.getMatchMaker().addSpawnAction(tower.getID(), loc, tower.getTeam(), type);
798786
this.gameWorld.getMatchMaker().addBuildAction(tower.getID());
799787
}

0 commit comments

Comments
 (0)