Skip to content

Commit d374fba

Browse files
authored
Merge pull request #37 from JavaBWAPI/documentation
JavaDoc
2 parents b3d8eb7 + 62d475e commit d374fba

34 files changed

+5282
-62
lines changed

pom.xml

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,16 @@
4646
</execution>
4747
</executions>
4848
</plugin>
49+
<plugin>
50+
<groupId>org.apache.maven.plugins</groupId>
51+
<artifactId>maven-site-plugin</artifactId>
52+
<version>3.7.1</version>
53+
</plugin>
54+
<plugin>
55+
<groupId>org.apache.maven.plugins</groupId>
56+
<artifactId>maven-project-info-reports-plugin</artifactId>
57+
<version>3.0.0</version>
58+
</plugin>
4959
<plugin>
5060
<groupId>org.codehaus.mojo</groupId>
5161
<artifactId>exec-maven-plugin</artifactId>
@@ -73,6 +83,20 @@
7383
</plugins>
7484
</build>
7585

86+
<reporting>
87+
<plugins>
88+
<plugin>
89+
<groupId>org.apache.maven.plugins</groupId>
90+
<artifactId>maven-javadoc-plugin</artifactId>
91+
<version>3.1.1</version>
92+
<configuration>
93+
<additionalOptions>-Xdoclint:none</additionalOptions>
94+
<additionalJOption>-Xdoclint:none</additionalJOption>
95+
</configuration>
96+
</plugin>
97+
</plugins>
98+
</reporting>
99+
76100
<dependencies>
77101
<!-- https://mvnrepository.com/artifact/net.java.dev.jna/jna -->
78102
<dependency>

src/main/java/bwapi/BWClient.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@
22

33
import java.util.Objects;
44

5+
/**
6+
* Client class to connect to the game with.
7+
*/
58
public class BWClient {
69
private final BWEventListener eventListener;
710

@@ -14,10 +17,16 @@ public BWClient(final BWEventListener eventListener) {
1417
this.eventListener = eventListener;
1518
}
1619

20+
/**
21+
* Get the {@link Game} instance of the currently running game.
22+
*/
1723
public Game getGame() {
1824
return handler == null ? null : handler.getGame();
1925
}
2026

27+
/**
28+
* Start the game.
29+
*/
2130
public void startGame() {
2231
while (client == null) {
2332
try {

src/main/java/bwapi/BWEventListener.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
package bwapi;
22

3-
3+
/**
4+
* Interface to extend to be given to a {@link BWClient}.
5+
*/
46
public interface BWEventListener {
57

68
void onStart();

src/main/java/bwapi/Bullet.java

Lines changed: 118 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,28 @@
44

55
import java.util.Objects;
66

7+
/**
8+
* An object representing a bullet or missile spawned from an attack.
9+
*
10+
* The Bullet interface allows you to detect bullets, missiles, and other types
11+
* of non-melee attacks or special abilities that would normally be visible through
12+
* human eyes (A lurker spike or a Queen's flying parasite), allowing quicker reaction
13+
* to unavoidable consequences.
14+
*
15+
* For example, ordering medics to restore units that are about to receive a lockdown
16+
* to compensate for latency and minimize its effects. You can't know entirely which unit
17+
* will be receiving a lockdown unless you can detect the lockdown missile using the
18+
* {@link Bullet} class.
19+
*
20+
* {@link Bullet} objects are re-used after they are destroyed, however their ID is updated when it
21+
* represents a new Bullet.
22+
*
23+
* If {@link Flag#CompleteMapInformation} is disabled, then a {@link Bullet} is accessible if and only if
24+
* it is visible. Otherwise if {@link Flag#CompleteMapInformation} is enabled, then all Bullets
25+
* in the game are accessible.
26+
* @see Game#getBullets
27+
* @see Bullet#exists
28+
*/
729
public class Bullet implements Comparable<Bullet> {
830
private final BulletData bulletData;
931
private final int id;
@@ -15,50 +37,136 @@ public class Bullet implements Comparable<Bullet> {
1537
this.game = game;
1638
}
1739

40+
/**
41+
* Retrieves a unique identifier for the current {@link Bullet}.
42+
*
43+
* @return An integer value containing the identifier.
44+
*/
1845
public int getID() {
1946
return id;
2047
}
2148

49+
/**
50+
* Checks if the {@link Bullet} exists in the view of the BWAPI player.
51+
*
52+
* If {@link Flag#CompleteMapInformation} is disabled, and a {@link Bullet} is not visible, then the
53+
* return value will be false regardless of the Bullet's true existence. This is because
54+
* absolutely no state information on invisible enemy bullets is made available to the AI.
55+
*
56+
* If {@link Flag#CompleteMapInformation} is enabled, then this function is accurate for all
57+
* {@link Bullet} information.
58+
*
59+
* @return true if the bullet exists or is visible, false if the bullet was destroyed or has gone out of scope.
60+
* @see #isVisible
61+
* @see Unit#exists
62+
*/
2263
public boolean exists() {
2364
return bulletData.getExists();
2465
}
2566

67+
/**
68+
* Retrieves the {@link Player} interface that owns the Bullet.
69+
*
70+
* @return The owning {@link Player} object. Returns null if the {@link Player} object for this {@link Bullet} is inaccessible.
71+
*/
2672
public Player getPlayer() {
2773
return game.getPlayer(bulletData.getPlayer());
2874
}
2975

76+
/**
77+
* Retrieves the type of this {@link Bullet}.
78+
*
79+
* @return A {@link BulletType} representing the Bullet's type. Returns {@link BulletType#Unknown} if the {@link Bullet} is inaccessible.
80+
*/
3081
public BulletType getType() {
3182
return BulletType.idToEnum[bulletData.getType()];
3283
}
3384

85+
/**
86+
* Retrieves the {@link Unit} that the {@link Bullet} spawned from.
87+
*
88+
* @return The owning {@link Unit} object. Returns null if the source can not be identified or is inaccessible.
89+
* @see #getTarget
90+
*/
3491
public Unit getSource() {
3592
return game.getUnit(bulletData.getSource());
3693
}
3794

95+
/**
96+
* Retrieves the Bullet's current position.
97+
*
98+
* @return A {@link Position} containing the Bullet's current coordinates. Returns {@link Position#Unknown} if the {@link Bullet} is inaccessible.
99+
* @see #getTargetPosition
100+
*/
38101
public Position getPosition() {
39102
return new Position(bulletData.getPositionX(), bulletData.getPositionY());
40103
}
41104

105+
/**
106+
* Retrieve's the direction the {@link Bullet} is facing. If the angle is 0, then
107+
* the {@link Bullet} is facing right.
108+
*
109+
* @return A double representing the direction the {@link Bullet} is facing. Returns 0.0 if the bullet is inaccessible.
110+
*/
42111
public double getAngle() {
43112
return bulletData.getAngle();
44113
}
45114

115+
/**
116+
* Retrieves the X component of the Bullet's velocity, measured in pixels per frame.
117+
*
118+
* @return A double representing the number of pixels moved on the X axis per frame. Returns 0.0 if the {@link Bullet} is inaccessible.
119+
*
120+
* @see #getVelocityY
121+
* @see #getAngle
122+
*/
46123
public double getVelocityX() {
47124
return bulletData.getVelocityX();
48125
}
49126

127+
/**
128+
* Retrieves the Y component of the Bullet's velocity, measured in pixels per frame.
129+
*
130+
* @return A double representing the number of pixels moved on the Y axis per frame. Returns 0.0 if the {@link Bullet} is inaccessible.
131+
*
132+
* @see #getVelocityX
133+
* @see #getAngle
134+
*/
50135
public double getVelocityY() {
51136
return bulletData.getVelocityY();
52137
}
53138

139+
/**
140+
* Retrieves the Unit interface that the {@link Bullet} is heading to.
141+
*
142+
* @return The target Unit object, if one exists. Returns null if the Bullet's target {@link Unit} is inaccessible, the {@link Bullet} is targetting the ground, or if the {@link Bullet} itself is inaccessible.
143+
* @see #getTargetPosition
144+
* @see #getSource
145+
*/
54146
public Unit getTarget() {
55147
return game.getUnit(bulletData.getTarget());
56148
}
57149

150+
/**
151+
* Retrieves the target position that the {@link Bullet} is heading to.
152+
*
153+
* @return A {@link Position} indicating where the {@link Bullet} is headed. Returns {@link Position#Unknown} if the bullet is inaccessible.
154+
* @see #getTarget
155+
* @see #getPosition
156+
*/
58157
public Position getTargetPosition() {
59158
return new Position(bulletData.getTargetPositionX(), bulletData.getTargetPositionY());
60159
}
61160

161+
/**
162+
* Retrieves the timer that indicates the Bullet's life span.
163+
*
164+
* Bullets are not permanent objects, so they will often have a limited life span.
165+
* This life span is measured in frames. Normally a Bullet will reach its target
166+
* before being removed.
167+
*
168+
* @return An integer representing the remaining number of frames until the {@link Bullet} self-destructs. Returns 0 if the {@link Bullet} is inaccessible.
169+
*/
62170
public int getRemoveTimer() {
63171
return bulletData.getRemoveTimer();
64172
}
@@ -67,7 +175,17 @@ public boolean isVisible() {
67175
return isVisible(game.self());
68176
}
69177

178+
/**
179+
* Retrieves the visibility state of the Bullet.
180+
*
181+
* @param player If this parameter is specified, then the Bullet's visibility to the given player is checked. If this parameter is omitted, then a default value of null is used, which will check if the BWAPI player has vision of the {@link Bullet}.
182+
*
183+
* @return true if the {@link Bullet} is visible to the specified player, false if the {@link Bullet} is not visible to the specified player.
184+
*/
70185
public boolean isVisible(final Player player) {
186+
if (player == null) {
187+
return isVisible();
188+
}
71189
return bulletData.isVisible(player.getID());
72190
}
73191

src/main/java/bwapi/BulletType.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,11 @@
22

33
import java.util.Arrays;
44

5+
/**
6+
* This enum represents a type of bullet.
7+
*
8+
* Internally, these are the same IDs as flingy types in Broodwar.
9+
*/
510
public enum BulletType {
611
Melee(0),
712

src/main/java/bwapi/Color.java

Lines changed: 59 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,60 @@
33

44
import java.util.Objects;
55

6+
/**
7+
* The Color object is used in drawing routines to specify the color to use.
8+
*
9+
* Starcraft uses a 256 color palette for rendering. Thus, the colors available are
10+
* limited to this palette.
11+
*/
612
public class Color {
13+
/**
14+
* The default color for Player 1.
15+
*/
716
public final static Color Red = new Color(111);
17+
/**
18+
* The default color for Player 2.
19+
*/
820
public final static Color Blue = new Color(165);
21+
/**
22+
* The default color for Player 3.
23+
*/
924
public final static Color Teal = new Color(159);
25+
/**
26+
* The default color for Player 4.
27+
*/
1028
public final static Color Purple = new Color(164);
29+
/**
30+
* The default color for Player 5.
31+
*/
1132
public final static Color Orange = new Color(156);
33+
/**
34+
* The default color for Player 6.
35+
*/
1236
public final static Color Brown = new Color(19);
37+
/**
38+
* A bright white. Note that this is lighter than Player 7's white.
39+
*/
1340
public final static Color White = new Color(255);
41+
/**
42+
* The default color for Player 8.
43+
*/
1444
public final static Color Yellow = new Color(135);
45+
/**
46+
* The alternate color for Player 7 on Ice tilesets.
47+
*/
1548
public final static Color Green = new Color(117);
49+
/**
50+
* The default color for Neutral (Player 12).
51+
*/
1652
public final static Color Cyan = new Color(128);
53+
/**
54+
* The color black.
55+
*/
1756
public final static Color Black = new Color(0);
57+
/**
58+
* The color grey.
59+
*/
1860
public final static Color Grey = new Color(74);
1961

2062
private static final RGBQUAD RGBRESERVE = new RGBQUAD(0, 0, 0, 0xFF);
@@ -66,10 +108,25 @@ RGBRESERVE, RGBRESERVE, RGBRESERVE, RGBRESERVE, RGBRESERVE, RGBRESERVE, RGBRESER
66108
}
67109
public final int id;
68110

69-
public Color(final int r, final int g, final int b) {
70-
id = getRGBIndex(r, g, b);
111+
/**
112+
* A constructor that uses the color index in the palette that is closest to the
113+
* given rgb values. On its first call, the colors in the palette will be sorted for fast indexing.
114+
*
115+
* This function computes the distance of the RGB values and may not be accurate.
116+
*
117+
* @param red The amount of red.
118+
* @param green The amount of green.
119+
* @param blue The amount of blue.
120+
*/
121+
public Color(final int red, final int green, final int blue) {
122+
id = getRGBIndex(red, green, blue);
71123
}
72124

125+
/**
126+
* A constructor that uses the color at the specified palette index.
127+
*
128+
* @param id The index of the color in the 256-color palette.
129+
*/
73130
public Color(final int id) {
74131
this.id = id;
75132
}

src/main/java/bwapi/CommandType.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@
22

33
import java.util.Arrays;
44

5+
/**
6+
* Used in {@link UnitCommand}.
7+
*/
58
public enum CommandType {
69
None(0),
710
SetScreenPosition(1),

0 commit comments

Comments
 (0)