Skip to content

Commit 79be1da

Browse files
committed
implement unit commands
1 parent e709efc commit 79be1da

File tree

6 files changed

+285
-102
lines changed

6 files changed

+285
-102
lines changed

src/main/java/JavaBWAPIBackend/Client.java

Lines changed: 10 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,16 @@ public class Client {
1818
private ByteBuffer sharedMemory;
1919
private LittleEndianPipe pipe;
2020

21+
public static class UnitCommand {
22+
public int type, unit, target, x, y, extra;
23+
private static final int SIZE = 24;
24+
}
25+
26+
public static class Command {
27+
public int type, value1, value2;
28+
private static final int SIZE = 12;
29+
}
30+
2131
public final class GameData {
2232
private String parseString(int offset, int maxLen) {
2333
byte[] buf = new byte[maxLen];
@@ -433,13 +443,6 @@ public void addShape(Shape shape) {
433443

434444
private static final int CommandOffset = 0x1ebfbcc;
435445

436-
public class Command {
437-
int type, value1, value2;
438-
public Command(int type, int value1, int value2) { this.type = type; this.value1 = value1; this.value2 = value2; }
439-
440-
private static final int SIZE = 12;
441-
}
442-
443446
public void addCommand(Command command) {
444447
int at = sharedMemory.getInt(CommandOffset);
445448
sharedMemory.putInt(CommandOffset + at * Command.SIZE + 4, command.type);
@@ -450,15 +453,6 @@ public void addCommand(Command command) {
450453

451454
private static final int UnitCommandOffset = 0x1efa550;
452455

453-
454-
public class UnitCommand {
455-
int type, unit, target, x, y, extra;
456-
public UnitCommand(int type, int unit, int target, int x, int y, int extra)
457-
{ this.type = type; this.unit = unit; this.target = target; this.x = x; this.y = y; this.extra = extra; }
458-
459-
private static final int SIZE = 24;
460-
}
461-
462456
public void addUnitCommand(UnitCommand command) {
463457
int at = sharedMemory.getInt(UnitCommandOffset);
464458
sharedMemory.putInt(UnitCommandOffset + at * UnitCommand.SIZE + 4, command.type);

src/main/java/bwapi/Game.java

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package bwapi;
22

3+
import JavaBWAPIBackend.Client;
34
import JavaBWAPIBackend.Client.GameData;
45
import bwapi.point.Position;
56
import bwapi.point.TilePosition;
@@ -70,6 +71,14 @@ void unitHide(final int id) {
7071
visibleUnits.remove(id);
7172
}
7273

74+
void addUnitCommand(final Client.UnitCommand unitCommand) {
75+
gameData.addUnitCommand(unitCommand);
76+
}
77+
78+
void addCommand(final Client.Command command) {
79+
gameData.addCommand(command);
80+
}
81+
7382
private void init() {
7483
for (int id=0; id < gameData.getForceCount(); id++) {
7584
forces.put(id, new Force(gameData.getForce(id), this));
@@ -172,9 +181,6 @@ public Unit getUnit(final int unitID) {
172181
return units.get(unitID);
173182
}
174183

175-
//TODO
176-
//public Unit indexToUnit(int unitIndex);
177-
178184
public Region getRegion(final int regionID) {
179185
return regions.get(regionID);
180186
}
@@ -836,7 +842,6 @@ public boolean isLatComEnabled() {
836842
return gameData.hasLatCom();
837843
}
838844

839-
840845
public void setLatCom(final boolean isEnabled) {
841846
gameData.setLatcom(isEnabled);
842847
}

0 commit comments

Comments
 (0)