Skip to content

Commit ec7de37

Browse files
author
Ian Gonzalez Hermosillo
committed
canMarkResourcePattern now checks for walls and ruins in 5x5 area
1 parent 353cb96 commit ec7de37

File tree

1 file changed

+14
-2
lines changed

1 file changed

+14
-2
lines changed

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

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -577,11 +577,23 @@ public int getTowerPattern(UnitType towerType) {
577577
}
578578

579579
public boolean isValidPatternCenter(MapLocation loc) {
580-
return !(loc.x < GameConstants.PATTERN_SIZE / 2
580+
return (!(loc.x < GameConstants.PATTERN_SIZE / 2
581581
|| loc.y < GameConstants.PATTERN_SIZE / 2
582582
|| loc.x >= gameMap.getWidth() - (GameConstants.PATTERN_SIZE - 1) / 2
583583
|| loc.y >= gameMap.getHeight() - (GameConstants.PATTERN_SIZE - 1) / 2
584-
);
584+
)) && areaIsPaintable(loc) ;
585+
}
586+
587+
// checks that location has no walls/ruins in the surrounding 5x5 area
588+
public boolean areaIsPaintable(MapLocation loc){
589+
for (int dx = -GameConstants.PATTERN_SIZE / 2; dx < (GameConstants.PATTERN_SIZE + 1) / 2; dx++) {
590+
for (int dy = -GameConstants.PATTERN_SIZE / 2; dy < (GameConstants.PATTERN_SIZE + 1) / 2; dy++) {
591+
MapLocation newLoc = loc.translate(dx, dy);
592+
if (!isPaintable(newLoc))
593+
return false;
594+
}
595+
}
596+
return true;
585597
}
586598

587599
public boolean isPassable(MapLocation loc) {

0 commit comments

Comments
 (0)