Skip to content

Commit 22aefa8

Browse files
committed
fix getTilePosition and onUnitCreate/Destroy
1 parent 19e985a commit 22aefa8

File tree

3 files changed

+12
-3
lines changed

3 files changed

+12
-3
lines changed

.gitignore

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,6 @@ target/
33

44
#intellij
55
.idea/
6-
*.iml
6+
*.iml
7+
8+
src/test/java/jbot

src/main/java/bwapi/EventHandler.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,9 +55,11 @@ public void operation(Client.GameData.Event event) {
5555
eventListener.onUnitHide(game.getUnit(event.v1()));
5656
break;
5757
case 12: //UnitCreate
58+
game.unitShow(event.v1());
5859
eventListener.onUnitCreate(game.getUnit(event.v1()));
5960
break;
6061
case 13: //UnitDestroy
62+
game.unitHide(event.v1());
6163
eventListener.onUnitDestroy(game.getUnit(event.v1()));
6264
break;
6365
case 14: //UnitMorph

src/main/java/bwapi/Unit.java

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ public class Unit {
2626
private final int initialResources;
2727
private final int initialHitPoints;
2828
private final Position initialPosition;
29+
private final TilePosition initialTilePosition;
2930

3031
// variable
3132
private int lastCommandFrame = 0;
@@ -39,6 +40,7 @@ public class Unit {
3940
initialResources = getResources();
4041
initialHitPoints = getHitPoints();
4142
initialPosition = getPosition();
43+
initialTilePosition = getTilePosition();
4244
}
4345

4446
public int getID() {
@@ -67,7 +69,10 @@ public Position getPosition() {
6769
}
6870

6971
public TilePosition getTilePosition() {
70-
return getPosition().toTilePosition();
72+
final Position p = getPosition();
73+
final UnitType ut = getType();
74+
return new Position(Math.abs(p.x - ut.tileWidth() * 32 / 2), Math.abs(p.y - ut.tileHeight() * 32 / 2))
75+
.toTilePosition();
7176
}
7277

7378
public double getAngle() {
@@ -233,7 +238,7 @@ public Position getInitialPosition() {
233238
}
234239

235240
public TilePosition getInitialTilePosition() {
236-
return initialPosition.toTilePosition();
241+
return initialTilePosition;
237242
}
238243

239244
public int getInitialHitPoints() {

0 commit comments

Comments
 (0)