|
10 | 10 | // |
11 | 11 | ////////////////////////////////////////////////////////////////////////// |
12 | 12 |
|
13 | | -package bwem.area; |
| 13 | +package bwem; |
14 | 14 |
|
15 | 15 | import bwapi.TilePosition; |
16 | 16 | 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; |
25 | 17 |
|
26 | 18 | import java.util.ArrayList; |
27 | 19 | import java.util.HashMap; |
28 | 20 | import java.util.List; |
29 | 21 |
|
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<>(); |
37 | 29 | private final AreaId id; |
38 | 30 | private final WalkPosition walkPositionWithHighestAltitude; |
39 | 31 | 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 = |
46 | 38 | 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; |
49 | 41 |
|
50 | | - protected AreaImpl(final AreaId areaId, final WalkPosition top, final int miniTileCount) { |
| 42 | + Area(final AreaId areaId, final WalkPosition top, final int miniTileCount) { |
51 | 43 | this.id = areaId; |
52 | 44 | this.walkPositionWithHighestAltitude = top; |
53 | 45 | this.miniTileCount = miniTileCount; |
54 | 46 | } |
55 | 47 |
|
56 | | - @Override |
57 | 48 | public AreaId getId() { |
58 | 49 | return this.id; |
59 | 50 | } |
60 | 51 |
|
61 | | - @Override |
62 | | - public GroupId getGroupId() { |
| 52 | + public int getGroupId() { |
63 | 53 | return this.groupId; |
64 | 54 | } |
65 | 55 |
|
66 | | - @Override |
67 | 56 | public TilePosition getTopLeft() { |
68 | 57 | return this.topLeft; |
69 | 58 | } |
70 | 59 |
|
71 | | - @Override |
72 | 60 | public TilePosition getBottomRight() { |
73 | 61 | return this.bottomRight; |
74 | 62 | } |
75 | 63 |
|
76 | | - @Override |
77 | 64 | public TilePosition getBoundingBoxSize() { |
78 | 65 | return this.bottomRight.subtract(this.topLeft).add(new TilePosition(1, 1)); |
79 | 66 | } |
80 | 67 |
|
81 | | - @Override |
82 | 68 | public WalkPosition getWalkPositionWithHighestAltitude() { |
83 | 69 | return this.walkPositionWithHighestAltitude; |
84 | 70 | } |
85 | 71 |
|
86 | | - @Override |
87 | 72 | public WalkPosition getTop() { |
88 | 73 | return getWalkPositionWithHighestAltitude(); |
89 | 74 | } |
90 | 75 |
|
91 | | - @Override |
92 | 76 | public Altitude getHighestAltitude() { |
93 | 77 | return this.highestAltitude; |
94 | 78 | } |
95 | 79 |
|
96 | | - @Override |
97 | 80 | public int getSize() { |
98 | 81 | return this.miniTileCount; |
99 | 82 | } |
100 | 83 |
|
101 | | - @Override |
102 | 84 | public int getLowGroundPercentage() { |
103 | 85 | final int lowGroundTileCount = |
104 | 86 | this.tileCount - this.highGroundTileCount - this.veryHighGroundTileCount; |
105 | 87 | return ((lowGroundTileCount * 100) / this.tileCount); |
106 | 88 | } |
107 | 89 |
|
108 | | - @Override |
109 | 90 | public int getHighGroundPercentage() { |
110 | 91 | return ((this.highGroundTileCount * 100) / this.tileCount); |
111 | 92 | } |
112 | 93 |
|
113 | | - @Override |
114 | 94 | public int getVeryHighGroundPercentage() { |
115 | 95 | return ((this.veryHighGroundTileCount * 100) / tileCount); |
116 | 96 | } |
117 | 97 |
|
118 | | - @Override |
119 | 98 | public List<ChokePoint> getChokePoints() { |
120 | 99 | return this.chokePoints; |
121 | 100 | } |
122 | 101 |
|
123 | | - @Override |
124 | 102 | public List<ChokePoint> getChokePoints(final Area area) { |
125 | 103 | final List<ChokePoint> ret = this.chokePointsByArea.get(area); |
126 | | - // bwem_assert(it != getChokePointsByArea.end()); |
127 | 104 | if (ret == null) { |
128 | 105 | throw new IllegalArgumentException(); |
129 | 106 | } |
130 | 107 | return ret; |
131 | 108 | } |
132 | 109 |
|
133 | | - @Override |
134 | 110 | public java.util.Map<Area, List<ChokePoint>> getChokePointsByArea() { |
135 | 111 | return this.chokePointsByArea; |
136 | 112 | } |
137 | 113 |
|
138 | | - @Override |
139 | 114 | public List<Area> getAccessibleNeighbors() { |
140 | 115 | return this.accessibleNeighbors; |
141 | 116 | } |
142 | 117 |
|
143 | | - @Override |
144 | 118 | public boolean isAccessibleFrom(final Area area) { |
145 | | - return getGroupId().equals(area.getGroupId()); |
| 119 | + return groupId == area.getGroupId(); |
146 | 120 | } |
147 | 121 |
|
148 | | - @Override |
149 | 122 | public List<Mineral> getMinerals() { |
150 | 123 | return this.minerals; |
151 | 124 | } |
152 | 125 |
|
153 | | - @Override |
154 | 126 | public List<Geyser> getGeysers() { |
155 | 127 | return this.geysers; |
156 | 128 | } |
157 | 129 |
|
158 | | - @Override |
159 | 130 | public List<Base> getBases() { |
160 | 131 | return this.bases; |
161 | 132 | } |
162 | 133 |
|
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 | | - |
178 | 134 | @Override |
179 | 135 | public boolean equals(final Object object) { |
180 | 136 | if (this == object) { |
|
0 commit comments