Skip to content

Commit f102be0

Browse files
authored
Merge pull request #30 from JavaBWAPI/bwem-cleanup
Bwem cleanup
2 parents 761bff3 + a4b4b79 commit f102be0

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

56 files changed

+1490
-3029
lines changed
Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,26 +10,23 @@
1010
//
1111
//////////////////////////////////////////////////////////////////////////
1212

13-
package bwem.typedef;
14-
15-
import bwem.util.IWrappedInteger;
13+
package bwem;
1614

1715
/**
1816
* Immutable wrapper of the integer primitive to satisfy the original C++ definition:
1917
* defs.h:54:typedef int16_t altitude_t;
2018
*
2119
* <p>Type of the altitudes in pixels.
2220
*/
23-
public final class Altitude implements IWrappedInteger<Altitude>, Comparable<Altitude> {
21+
public final class Altitude implements Comparable<Altitude> {
2422
public static final Altitude UNINITIALIZED = new Altitude(-1);
2523
public static final Altitude ZERO = new Altitude(0);
2624
private final int val;
2725

28-
public Altitude(final int val) {
26+
Altitude(final int val) {
2927
this.val = val;
3028
}
3129

32-
@Override
3330
public int intValue() {
3431
return this.val;
3532
}
Lines changed: 19 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -10,171 +10,127 @@
1010
//
1111
//////////////////////////////////////////////////////////////////////////
1212

13-
package bwem.area;
13+
package bwem;
1414

1515
import bwapi.TilePosition;
1616
import bwapi.WalkPosition;
17-
import bwem.Base;
18-
import bwem.BaseImpl;
19-
import bwem.ChokePoint;
20-
import bwem.area.typedef.AreaId;
21-
import bwem.area.typedef.GroupId;
22-
import bwem.typedef.Altitude;
23-
import bwem.unit.Geyser;
24-
import bwem.unit.Mineral;
2517

2618
import java.util.ArrayList;
2719
import java.util.HashMap;
2820
import java.util.List;
2921

30-
public abstract class AreaImpl implements Area {
31-
protected final java.util.Map<Area, List<ChokePoint>> chokePointsByArea = new HashMap<>();
32-
protected final List<Area> accessibleNeighbors = new ArrayList<>();
33-
protected final List<ChokePoint> chokePoints = new ArrayList<>();
34-
protected final List<Mineral> minerals = new ArrayList<>();
35-
protected final List<Geyser> geysers = new ArrayList<>();
36-
protected final List<Base> bases = new ArrayList<>();
22+
public abstract class Area {
23+
final java.util.Map<Area, List<ChokePoint>> chokePointsByArea = new HashMap<>();
24+
final List<Area> accessibleNeighbors = new ArrayList<>();
25+
final List<ChokePoint> chokePoints = new ArrayList<>();
26+
final List<Mineral> minerals = new ArrayList<>();
27+
final List<Geyser> geysers = new ArrayList<>();
28+
final List<Base> bases = new ArrayList<>();
3729
private final AreaId id;
3830
private final WalkPosition walkPositionWithHighestAltitude;
3931
private final int miniTileCount;
40-
protected GroupId groupId = GroupId.ZERO;
41-
protected Altitude highestAltitude;
42-
protected TilePosition topLeft = new TilePosition(Integer.MAX_VALUE, Integer.MAX_VALUE);
43-
protected TilePosition bottomRight = new TilePosition(Integer.MIN_VALUE, Integer.MIN_VALUE);
44-
protected int tileCount = 0;
45-
protected int buildableTileCount =
32+
int groupId = 0;
33+
Altitude highestAltitude;
34+
TilePosition topLeft = new TilePosition(Integer.MAX_VALUE, Integer.MAX_VALUE);
35+
TilePosition bottomRight = new TilePosition(Integer.MIN_VALUE, Integer.MIN_VALUE);
36+
int tileCount = 0;
37+
int buildableTileCount =
4638
0; /* Set and later incremented but not used in original C++ BWEM 1.4.1. Remains for portability consistency. */
47-
protected int highGroundTileCount = 0;
48-
protected int veryHighGroundTileCount = 0;
39+
int highGroundTileCount = 0;
40+
int veryHighGroundTileCount = 0;
4941

50-
protected AreaImpl(final AreaId areaId, final WalkPosition top, final int miniTileCount) {
42+
Area(final AreaId areaId, final WalkPosition top, final int miniTileCount) {
5143
this.id = areaId;
5244
this.walkPositionWithHighestAltitude = top;
5345
this.miniTileCount = miniTileCount;
5446
}
5547

56-
@Override
5748
public AreaId getId() {
5849
return this.id;
5950
}
6051

61-
@Override
62-
public GroupId getGroupId() {
52+
public int getGroupId() {
6353
return this.groupId;
6454
}
6555

66-
@Override
6756
public TilePosition getTopLeft() {
6857
return this.topLeft;
6958
}
7059

71-
@Override
7260
public TilePosition getBottomRight() {
7361
return this.bottomRight;
7462
}
7563

76-
@Override
7764
public TilePosition getBoundingBoxSize() {
7865
return this.bottomRight.subtract(this.topLeft).add(new TilePosition(1, 1));
7966
}
8067

81-
@Override
8268
public WalkPosition getWalkPositionWithHighestAltitude() {
8369
return this.walkPositionWithHighestAltitude;
8470
}
8571

86-
@Override
8772
public WalkPosition getTop() {
8873
return getWalkPositionWithHighestAltitude();
8974
}
9075

91-
@Override
9276
public Altitude getHighestAltitude() {
9377
return this.highestAltitude;
9478
}
9579

96-
@Override
9780
public int getSize() {
9881
return this.miniTileCount;
9982
}
10083

101-
@Override
10284
public int getLowGroundPercentage() {
10385
final int lowGroundTileCount =
10486
this.tileCount - this.highGroundTileCount - this.veryHighGroundTileCount;
10587
return ((lowGroundTileCount * 100) / this.tileCount);
10688
}
10789

108-
@Override
10990
public int getHighGroundPercentage() {
11091
return ((this.highGroundTileCount * 100) / this.tileCount);
11192
}
11293

113-
@Override
11494
public int getVeryHighGroundPercentage() {
11595
return ((this.veryHighGroundTileCount * 100) / tileCount);
11696
}
11797

118-
@Override
11998
public List<ChokePoint> getChokePoints() {
12099
return this.chokePoints;
121100
}
122101

123-
@Override
124102
public List<ChokePoint> getChokePoints(final Area area) {
125103
final List<ChokePoint> ret = this.chokePointsByArea.get(area);
126-
// bwem_assert(it != getChokePointsByArea.end());
127104
if (ret == null) {
128105
throw new IllegalArgumentException();
129106
}
130107
return ret;
131108
}
132109

133-
@Override
134110
public java.util.Map<Area, List<ChokePoint>> getChokePointsByArea() {
135111
return this.chokePointsByArea;
136112
}
137113

138-
@Override
139114
public List<Area> getAccessibleNeighbors() {
140115
return this.accessibleNeighbors;
141116
}
142117

143-
@Override
144118
public boolean isAccessibleFrom(final Area area) {
145-
return getGroupId().equals(area.getGroupId());
119+
return groupId == area.getGroupId();
146120
}
147121

148-
@Override
149122
public List<Mineral> getMinerals() {
150123
return this.minerals;
151124
}
152125

153-
@Override
154126
public List<Geyser> getGeysers() {
155127
return this.geysers;
156128
}
157129

158-
@Override
159130
public List<Base> getBases() {
160131
return this.bases;
161132
}
162133

163-
public void onMineralDestroyed(final Mineral mineral) {
164-
// bwem_assert(mineral);
165-
if (mineral == null) {
166-
throw new IllegalArgumentException();
167-
}
168-
169-
this.minerals.remove(mineral);
170-
171-
// let's examine the bases even if mineral was not found in this Area,
172-
// which could arise if minerals were allowed to be assigned to neighboring areas.
173-
for (final Base base : getBases()) {
174-
((BaseImpl) base).onMineralDestroyed(mineral);
175-
}
176-
}
177-
178134
@Override
179135
public boolean equals(final Object object) {
180136
if (this == object) {

src/main/java/bwem/area/typedef/AreaId.java renamed to src/main/java/bwem/AreaId.java

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,24 +10,21 @@
1010
//
1111
//////////////////////////////////////////////////////////////////////////
1212

13-
package bwem.area.typedef;
14-
15-
import bwem.util.IWrappedInteger;
13+
package bwem;
1614

1715
/**
1816
* Immutable wrapper of the integer primitive to satisfy the original C++ definition:
1917
* area.h:54:typedef int16_t id;
2018
*/
21-
public final class AreaId implements IWrappedInteger<AreaId>, Comparable<AreaId> {
19+
public final class AreaId implements Comparable<AreaId> {
2220
public static final AreaId UNINITIALIZED = new AreaId(-1);
2321
public static final AreaId ZERO = new AreaId(0);
2422
private final int val;
2523

26-
public AreaId(final int val) {
24+
AreaId(final int val) {
2725
this.val = val;
2826
}
2927

30-
@Override
3128
public int intValue() {
3229
return this.val;
3330
}

0 commit comments

Comments
 (0)