Skip to content

Commit ab93a67

Browse files
committed
implement game.getBullets
1 parent c82b851 commit ab93a67

File tree

2 files changed

+34
-47
lines changed

2 files changed

+34
-47
lines changed

src/main/java/JavaBWAPIBackend/Client.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -287,7 +287,7 @@ public class BulletData {
287287
static final int SIZE = 80;
288288
}
289289

290-
public BulletData bullet(int index) { return new BulletData(index); }
290+
public BulletData getBullet(int index) { return new BulletData(index); }
291291

292292
private static final int NukeOffset = 0x348ee8;
293293

src/main/java/bwapi/Game.java

Lines changed: 33 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ public class Game {
3434

3535
final Map<Integer, Bullet> bullets = new HashMap<>();
3636

37-
public Game(GameData gameData) {
37+
public Game(final GameData gameData) {
3838
this.gameData = gameData;
3939
}
4040

@@ -58,32 +58,18 @@ private void clear() {
5858
bullets.clear();
5959
}
6060

61-
void unitShow(final int id) {
62-
if (!units.containsKey(id)) {
63-
units.put(id, new Unit(gameData.getUnit(id), this));
64-
}
65-
visibleUnits.add(id);
66-
}
67-
68-
void unitHide(final int id) {
69-
visibleUnits.remove(id);
70-
}
71-
72-
void unitCommand(final int type, final int unit, final int target, final int x, final int y, final int extra) {
73-
gameData.addUnitCommand(new Client.UnitCommand(type, unit, target, x, y, extra));
74-
}
75-
76-
void command(final int type, final int value1, final int value2) {
77-
gameData.addCommand(new Client.Command(type, value1, value2));
78-
}
79-
8061
private void init() {
8162
for (int id=0; id < gameData.getForceCount(); id++) {
8263
forces.put(id, new Force(gameData.getForce(id), this));
8364
}
8465
for (int id=0; id < gameData.getPlayerCount(); id++) {
8566
players.put(id, new Player(gameData.getPlayer(id), this));
8667
}
68+
69+
for (int id=0; id < gameData.bulletCount(); id++) {
70+
bullets.put(id, new Bullet(gameData.getBullet(id), this));
71+
}
72+
8773
for (int id=0; id < gameData.regionCount(); id++) {
8874
regions.put(id, new Region(gameData.getRegion(id), this));
8975
}
@@ -107,6 +93,25 @@ private void init() {
10793
}
10894
}
10995

96+
void unitShow(final int id) {
97+
if (!units.containsKey(id)) {
98+
units.put(id, new Unit(gameData.getUnit(id), this));
99+
}
100+
visibleUnits.add(id);
101+
}
102+
103+
void unitHide(final int id) {
104+
visibleUnits.remove(id);
105+
}
106+
107+
void unitCommand(final int type, final int unit, final int target, final int x, final int y, final int extra) {
108+
gameData.addUnitCommand(new Client.UnitCommand(type, unit, target, x, y, extra));
109+
}
110+
111+
void command(final int type, final int value1, final int value2) {
112+
gameData.addCommand(new Client.Command(type, value1, value2));
113+
}
114+
110115
public Set<Force> getForces() {
111116
return new HashSet<>(forces.values());
112117
}
@@ -117,7 +122,6 @@ public Set<Player> getPlayers() {
117122

118123

119124
public Set<Unit> getAllUnits() {
120-
// simulate current BWAPI behavior
121125
if (getFrameCount() == 0) {
122126
return new HashSet<>(units.values());
123127
}
@@ -157,9 +161,9 @@ public Set<Unit> getStaticNeutralUnits() {
157161
}
158162

159163
public Set<Bullet> getBullets() {
160-
// TODO
161-
// for (int i=0; i < gameData.bulletCount(); i++) {bullets.add(new Bullet(gameData.bullet(i), this))};
162-
return null;
164+
return bullets.values().stream()
165+
.filter(Bullet::exists)
166+
.collect(Collectors.toSet());
163167
}
164168

165169
public Set<Position> getNukeDots() {
@@ -873,19 +877,12 @@ public int getAPM(final boolean includeSelects) {
873877
return includeSelects ? gameData.getBotAPM_selects() : gameData.getBotAPM_noselects();
874878
}
875879

876-
//please just use a valid map here, not going to add checks for this to the java client
877-
public boolean setMap(final String cstr_mapFileName) {
878-
command(SetMap.value, gameData.addString(cstr_mapFileName), 0);
879-
return true;
880-
}
881-
882880
public void setFrameSkip(int frameSkip) {
883881
command(SetFrameSkip.value, frameSkip, 0);
884882
}
885883

886-
887884
//TODO
888-
public boolean hasPath(Position source, Position destination) {
885+
public boolean hasPath(final Position source, final Position destination) {
889886
return false;
890887
}
891888

@@ -898,6 +895,9 @@ public boolean hasPath(Position source, Position destination) {
898895
// public int getLastEventTime();
899896
// public void setTextSize();
900897
// public void setTextSize(final TextSize size);
898+
// public boolean setMap(final String cstr_mapFileName);
899+
// public boolean setRevealAll();return true;
900+
// public boolean setRevealAll(boolean reveal);
901901

902902
public int elapsedTime() {
903903
return gameData.elapsedTime();
@@ -922,22 +922,9 @@ public Region getRegionAt(final int x, final int y) {
922922

923923
//TODO
924924
public Region getRegionAt(final Position position) {
925-
return null;
925+
return getRegionAt(position.x, position.y);
926926
}
927927

928-
929-
930-
public boolean setRevealAll() {
931-
setRevealAll(false);
932-
return true;
933-
}
934-
935-
public boolean setRevealAll(boolean reveal) {
936-
command(SetRevealAll.value, reveal ? 1 : 0, 0);
937-
return true;
938-
}
939-
940-
941928
/*
942929
public TilePosition getBuildLocation(UnitType type, TilePosition desiredPosition, int maxRange);
943930

0 commit comments

Comments
 (0)