Skip to content

Commit 2afe1a2

Browse files
authored
Merge pull request #100 from JavaBWAPI/bugfix-hasPower
fix bug in hasPower fallback when no unittype is provided
2 parents f586151 + dcef547 commit 2afe1a2

2 files changed

Lines changed: 16 additions & 1 deletion

File tree

‎src/main/java/bwapi/Game.java‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1033,7 +1033,7 @@ final public boolean hasPower(final int tileX, final int tileY, final UnitType u
10331033
if (unitType.id >= 0 && unitType.id < UnitType.None.id) {
10341034
return hasPowerPrecise(tileX * 32 + unitType.tileWidth() * 16, tileY * 32 + unitType.tileHeight() * 16, unitType);
10351035
}
1036-
return hasPowerPrecise(tileY * 32, tileY * 32, UnitType.None);
1036+
return hasPowerPrecise(tileX * 32, tileY * 32, UnitType.None);
10371037
}
10381038

10391039
final public boolean hasPower(final int tileX, final int tileY, final int tileWidth, final int tileHeight) {

‎src/test/java/bwapi/GameTest.java‎

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,4 +101,19 @@ public void ifReplaySelfAndEnemyShouldBeNull() throws IOException {
101101
assertTrue(game.enemies().isEmpty());
102102
assertTrue(game.allies().isEmpty());
103103
}
104+
105+
@Test
106+
public void hasPowerOnTile() throws IOException {
107+
Game game = GameBuilder.createGame();
108+
Unit pylon = mock(Unit.class);
109+
given(pylon.getType()).willReturn(UnitType.Protoss_Pylon);
110+
given(pylon.getPlayer()).willReturn(game.self());
111+
given(pylon.exists()).willReturn(true);
112+
given(pylon.isCompleted()).willReturn(true);
113+
given(pylon.getPosition()).willReturn(new Position(1024, 512));
114+
game.setAllUnits(Collections.singletonList(pylon));
115+
116+
// tile (31, 15) is pixel (992, 480), right next to the pylon
117+
assertTrue(game.hasPower(31, 15));
118+
}
104119
}

0 commit comments

Comments
 (0)