Skip to content

Commit 60cb87d

Browse files
committed
reformat code with intellij refactor
1 parent 9da78b1 commit 60cb87d

38 files changed

+4011
-3210
lines changed

src/main/java/bwapi/BWClient.java

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -19,29 +19,28 @@ public Game getGame() {
1919
}
2020

2121
public void startGame() {
22-
while(client == null) {
22+
while (client == null) {
2323
try {
2424
client = new Client();
25-
}
26-
catch (Throwable t) {
25+
} catch (Throwable t) {
2726
System.err.println("Game table mapping not found.");
2827
try {
2928
Thread.sleep(1000);
29+
} catch (Throwable ignored) {
3030
}
31-
catch (Throwable ignored) { } }
31+
}
3232
}
3333

3434
handler = new EventHandler(eventListener, client.data());
3535

3636
try {
37-
while(!client.data().isInGame()) {
37+
while (!client.data().isInGame()) {
3838
client.update(handler);
3939
}
40-
while(client.data().isInGame()) {
40+
while (client.data().isInGame()) {
4141
client.update(handler);
4242
}
43-
}
44-
catch (Throwable exception) {
43+
} catch (Throwable exception) {
4544
exception.printStackTrace();
4645
}
4746
}

src/main/java/bwapi/BuildingPlacer.java

Lines changed: 122 additions & 112 deletions
Large diffs are not rendered by default.

src/main/java/bwapi/Bullet.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -65,12 +65,12 @@ public boolean isVisible(final Player player) {
6565
return bulletData.isVisible(player.getID());
6666
}
6767

68-
public boolean equals(Object that){
69-
if(!(that instanceof Bullet)) return false;
70-
return getID() == ((Bullet)that).getID();
68+
public boolean equals(Object that) {
69+
if (!(that instanceof Bullet)) return false;
70+
return getID() == ((Bullet) that).getID();
7171
}
7272

73-
public int hashCode(){
73+
public int hashCode() {
7474
return getID();
7575
}
7676

src/main/java/bwapi/BulletType.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,14 +48,15 @@ public enum BulletType {
4848
None(209),
4949
Unknown(210);
5050

51-
public static BulletType[] bulletTypes = new BulletType[210+1];
51+
public static BulletType[] bulletTypes = new BulletType[210 + 1];
52+
5253
static {
5354
Arrays.stream(BulletType.values()).forEach(v -> bulletTypes[v.id] = v);
5455
}
5556

5657
private int id;
5758

58-
BulletType(int id){
59+
BulletType(int id) {
5960
this.id = id;
6061
}
6162
}

src/main/java/bwapi/Client.java

Lines changed: 1060 additions & 357 deletions
Large diffs are not rendered by default.

src/main/java/bwapi/Color.java

Lines changed: 66 additions & 79 deletions
Original file line numberDiff line numberDiff line change
@@ -4,85 +4,19 @@
44
import java.util.Objects;
55

66
public class Color {
7-
public final int id;
8-
9-
public Color(final int r, final int g, final int b) {
10-
id = getRGBIndex(r, g, b);
11-
}
12-
13-
public Color(final int id) {
14-
this.id = id;
15-
}
16-
177
public final static Color Red = new Color(111);
18-
198
public final static Color Blue = new Color(165);
20-
219
public final static Color Teal = new Color(159);
22-
2310
public final static Color Purple = new Color(164);
24-
2511
public final static Color Orange = new Color(179);
26-
2712
public final static Color Brown = new Color(19);
28-
2913
public final static Color White = new Color(255);
30-
3114
public final static Color Yellow = new Color(135);
32-
3315
public final static Color Green = new Color(117);
34-
3516
public final static Color Cyan = new Color(128);
36-
3717
public final static Color Black = new Color(0);
38-
3918
public final static Color Grey = new Color(74);
40-
41-
int red() {
42-
return id < 256 ? defaultPalette[id].rgbRed : 0;
43-
}
44-
int green() {
45-
return id < 256 ? defaultPalette[id].rgbGreen : 0;
46-
}
47-
int blue() {
48-
return id < 256 ? defaultPalette[id].rgbBlue : 0;
49-
}
50-
51-
@Override
52-
public boolean equals(Object o) {
53-
if (!(o instanceof Color)) {
54-
return false;
55-
}
56-
return id == ((Color) o).id;
57-
}
58-
59-
@Override
60-
public int hashCode() {
61-
return Objects.hash(id);
62-
}
63-
64-
/// BROODWAR COLOR IMPLEMENTATION
65-
private static class RGBQUAD {
66-
byte rgbRed;
67-
byte rgbGreen;
68-
byte rgbBlue;
69-
byte rgbReserved;
70-
71-
RGBQUAD(int rgbRed, int rgbGreen, int rgbBlue) {
72-
this(rgbRed,rgbGreen, rgbBlue, 0);
73-
}
74-
75-
RGBQUAD(int rgbRed, int rgbGreen, int rgbBlue, int rgbReserved) {
76-
this.rgbRed = (byte)rgbRed;
77-
this.rgbGreen = (byte)rgbGreen;
78-
this.rgbBlue = (byte)rgbBlue;
79-
this.rgbReserved = (byte)rgbReserved;
80-
}
81-
}
82-
83-
private static RGBQUAD RGBRESERVE = new RGBQUAD(0,0,0,0xFF);
84-
85-
private static boolean rgbInitialized = false;
19+
private static RGBQUAD RGBRESERVE = new RGBQUAD(0, 0, 0, 0xFF);
8620
private static final RGBQUAD defaultPalette[] = {
8721
new RGBQUAD(0, 0, 0), RGBRESERVE, RGBRESERVE, RGBRESERVE, RGBRESERVE, RGBRESERVE, RGBRESERVE, RGBRESERVE,
8822
RGBRESERVE, RGBRESERVE, RGBRESERVE, RGBRESERVE, RGBRESERVE, RGBRESERVE, RGBRESERVE, RGBRESERVE,
@@ -117,12 +51,23 @@ private static class RGBQUAD {
11751
RGBRESERVE, RGBRESERVE, RGBRESERVE, RGBRESERVE, RGBRESERVE, RGBRESERVE, RGBRESERVE, RGBRESERVE,
11852
RGBRESERVE, RGBRESERVE, RGBRESERVE, RGBRESERVE, RGBRESERVE, RGBRESERVE, RGBRESERVE, new RGBQUAD(255, 255, 255)
11953
};
54+
private static boolean rgbInitialized = false;
55+
private static byte closestColor[][][] = new byte[64][64][64];
56+
public final int id;
57+
58+
public Color(final int r, final int g, final int b) {
59+
id = getRGBIndex(r, g, b);
60+
}
61+
62+
public Color(final int id) {
63+
this.id = id;
64+
}
12065

12166
private static int getBestIdFor(int red, int green, int blue) {
12267

123-
int min_dist = 3 * 256 * 256;
124-
int best_id = 0;
125-
for( int id = 0; id < 255; ++id ) {
68+
int min_dist = 3 * 256 * 256;
69+
int best_id = 0;
70+
for (int id = 0; id < 255; ++id) {
12671
RGBQUAD p = defaultPalette[id];
12772
if (p.rgbReserved != 0) {
12873
continue;
@@ -131,8 +76,8 @@ private static int getBestIdFor(int red, int green, int blue) {
13176
int g = green - p.rgbGreen;
13277
int b = blue - p.rgbBlue;
13378

134-
int distance = r*r + g*g + b*b;
135-
if ( distance < min_dist ) {
79+
int distance = r * r + g * g + b * b;
80+
if (distance < min_dist) {
13681
min_dist = distance;
13782
best_id = id;
13883
if (distance == 0) {
@@ -143,19 +88,61 @@ private static int getBestIdFor(int red, int green, int blue) {
14388
return best_id;
14489
}
14590

146-
private static byte closestColor[][][] = new byte[64][64][64];
147-
14891
private static int getRGBIndex(int red, int green, int blue) {
149-
if ( !rgbInitialized ) {
92+
if (!rgbInitialized) {
15093
rgbInitialized = true;
151-
for (int r = 0; r < 64; ++r ) {
152-
for (int g = 0; g < 64; ++g ) {
153-
for (int b = 0; b < 64; ++b ) {
94+
for (int r = 0; r < 64; ++r) {
95+
for (int g = 0; g < 64; ++g) {
96+
for (int b = 0; b < 64; ++b) {
15497
closestColor[r][g][b] = (byte) getBestIdFor(r << 2, g << 2, b << 2);
15598
}
15699
}
157100
}
158101
}
159-
return closestColor[(byte)(red >> 2)][(byte)(green >> 2)][(byte)(blue >> 2)];
102+
return closestColor[(byte) (red >> 2)][(byte) (green >> 2)][(byte) (blue >> 2)];
103+
}
104+
105+
int red() {
106+
return id < 256 ? defaultPalette[id].rgbRed : 0;
107+
}
108+
109+
int green() {
110+
return id < 256 ? defaultPalette[id].rgbGreen : 0;
111+
}
112+
113+
int blue() {
114+
return id < 256 ? defaultPalette[id].rgbBlue : 0;
115+
}
116+
117+
@Override
118+
public boolean equals(Object o) {
119+
if (!(o instanceof Color)) {
120+
return false;
121+
}
122+
return id == ((Color) o).id;
123+
}
124+
125+
@Override
126+
public int hashCode() {
127+
return Objects.hash(id);
128+
}
129+
130+
/// BROODWAR COLOR IMPLEMENTATION
131+
private static class RGBQUAD {
132+
byte rgbRed;
133+
byte rgbGreen;
134+
byte rgbBlue;
135+
byte rgbReserved;
136+
137+
RGBQUAD(int rgbRed, int rgbGreen, int rgbBlue) {
138+
this(rgbRed, rgbGreen, rgbBlue, 0);
139+
}
140+
141+
RGBQUAD(int rgbRed, int rgbGreen, int rgbBlue, int rgbReserved) {
142+
this.rgbRed = (byte) rgbRed;
143+
this.rgbGreen = (byte) rgbGreen;
144+
this.rgbBlue = (byte) rgbBlue;
145+
this.rgbReserved = (byte) rgbReserved;
146+
}
160147
}
161148
}
Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,29 @@
11
package bwapi;
22

33
public enum CommandType {
4-
None(0),
5-
SetScreenPosition(1),
6-
PingMinimap(2),
7-
EnableFlag(3),
8-
Printf(4),
9-
SendText(5),
10-
PauseGame(6),
11-
ResumeGame(7),
12-
LeaveGame(8),
13-
RestartGame(9),
14-
SetLocalSpeed(10),
15-
SetLatCom(11),
16-
SetGui(12),
17-
SetFrameSkip(13),
18-
SetMap(14),
19-
SetAllies(15),
20-
SetVision(16),
21-
SetCommandOptimizerLevel(17),
22-
SetRevealAll(18);
4+
None(0),
5+
SetScreenPosition(1),
6+
PingMinimap(2),
7+
EnableFlag(3),
8+
Printf(4),
9+
SendText(5),
10+
PauseGame(6),
11+
ResumeGame(7),
12+
LeaveGame(8),
13+
RestartGame(9),
14+
SetLocalSpeed(10),
15+
SetLatCom(11),
16+
SetGui(12),
17+
SetFrameSkip(13),
18+
SetMap(14),
19+
SetAllies(15),
20+
SetVision(16),
21+
SetCommandOptimizerLevel(17),
22+
SetRevealAll(18);
2323

24-
public final int value;
24+
public final int value;
2525

26-
CommandType(int value){
27-
this.value = value;
28-
}
26+
CommandType(int value) {
27+
this.value = value;
28+
}
2929
}

src/main/java/bwapi/Coordinate.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ public enum Coordinate {
88

99
public final int value;
1010

11-
Coordinate(final int value){
11+
Coordinate(final int value) {
1212
this.value = value;
1313
}
1414
}

src/main/java/bwapi/DamageType.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ public enum DamageType {
1111

1212
public final int id;
1313

14-
DamageType(int id){
14+
DamageType(int id) {
1515
this.id = id;
1616
}
1717
}

0 commit comments

Comments
 (0)