Skip to content

Commit 36d9181

Browse files
JasperGeurtzBytekeeper
authored andcommitted
ChokePoint & Base -> no interface
1 parent 3feab27 commit 36d9181

File tree

8 files changed

+342
-444
lines changed

8 files changed

+342
-444
lines changed

src/main/java/bwem/Base.java

Lines changed: 97 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,18 @@
1414

1515
import bwapi.Position;
1616
import bwapi.TilePosition;
17+
import bwapi.UnitType;
1718
import bwem.area.Area;
1819
import bwem.map.MapData;
1920
import bwem.unit.Geyser;
2021
import bwem.unit.Mineral;
2122
import bwem.unit.Neutral;
23+
import bwem.unit.Resource;
24+
import bwem.util.BwemExt;
2225

26+
import java.util.ArrayList;
2327
import java.util.List;
28+
import java.util.Objects;
2429

2530
/**
2631
* After Areas and ChokePoints, Bases are the third kind of object BWEM automatically computes from
@@ -29,47 +34,93 @@
2934
* Base always belongs to some Area. An Area may contain zero, one or several Bases. Like Areas and
3035
* ChokePoints, the number and the addresses of Base instances remain unchanged.
3136
*/
32-
public interface Base {
37+
public class Base {
38+
private final Area area;
39+
private final List<Mineral> minerals = new ArrayList<>();
40+
private final List<Geyser> geysers = new ArrayList<>();
41+
private final List<Mineral> blockingMinerals;
42+
private TilePosition location;
43+
private Position center;
44+
private boolean isStartingLocation = false;
45+
46+
public Base(
47+
final Area area,
48+
final TilePosition location,
49+
final List<Resource> assignedResources,
50+
final List<Mineral> blockingMinerals) {
51+
this.area = area;
52+
this.location = location;
53+
this.center = BwemExt.centerOfBuilding(location, UnitType.Terran_Command_Center.tileSize());
54+
this.blockingMinerals = blockingMinerals;
55+
56+
// bwem_assert(!AssignedResources.empty());
57+
if (assignedResources.isEmpty()) {
58+
throw new IllegalArgumentException();
59+
}
60+
61+
for (final Resource assignedResource : assignedResources) {
62+
if (assignedResource instanceof Mineral) {
63+
final Mineral assignedMineral = (Mineral) assignedResource;
64+
this.minerals.add(assignedMineral);
65+
} else if (assignedResource instanceof Geyser) {
66+
final Geyser assignedGeyser = (Geyser) assignedResource;
67+
this.geysers.add(assignedGeyser);
68+
}
69+
}
70+
}
71+
3372
/**
3473
* Tests whether this base is a start location.<br>
3574
* - Note: all players start at locations taken from {@link MapData#getStartingLocations()},<br>
3675
* which doesn't mean all the locations in {@link MapData#getStartingLocations()} are actually
3776
* used.
3877
*/
39-
boolean isStartingLocation();
78+
public boolean isStartingLocation() {
79+
return this.isStartingLocation;
80+
}
4081

4182
/**
4283
* Returns the area in which this base is located.
4384
*/
44-
Area getArea();
85+
public Area getArea() {
86+
return this.area;
87+
}
4588

4689
/**
4790
* Returns the position (top-left TilePosition) of the location for a resource depot.<br>
4891
* - Note: If {@link #isStartingLocation()} == true, it is guaranteed that the location
4992
* corresponds exactly to one of {@link MapData#getStartingLocations()}.
5093
*/
51-
TilePosition getLocation();
94+
public TilePosition getLocation() {
95+
return this.location;
96+
}
5297

5398
/**
5499
* Returns the center position of {@link #getLocation()}.
55100
*/
56-
Position getCenter();
101+
public Position getCenter() {
102+
return this.center;
103+
}
57104

58105
/**
59106
* Returns the available minerals.<br>
60107
* - These minerals are assigned to this base (it is guaranteed that no other base provides them).
61108
* <br>
62109
* - Note: The size of the returned list may decrease, as some of the minerals may get destroyed.
63110
*/
64-
List<Mineral> getMinerals();
111+
public List<Mineral> getMinerals() {
112+
return this.minerals;
113+
}
65114

66115
/**
67116
* Returns the available geysers.<br>
68117
* - These geysers are assigned to this Base (it is guaranteed that no other Base provides them).
69118
* <br>
70119
* - Note: The size of the returned list will NOT decrease, as geysers never get destroyed.
71120
*/
72-
List<Geyser> getGeysers();
121+
public List<Geyser> getGeysers() {
122+
return this.geysers;
123+
}
73124

74125
/**
75126
* Returns the blocking minerals.<br>
@@ -83,5 +134,43 @@ public interface Base {
83134
* ChokePoint#getBlockingNeutral()} and {@link Neutral#isBlocking()}:<br>
84135
* The last two refer to a Neutral blocking a ChokePoint, not a Base.
85136
*/
86-
List<Mineral> getBlockingMinerals();
137+
public List<Mineral> getBlockingMinerals() {
138+
return this.blockingMinerals;
139+
}
140+
141+
public void assignStartingLocation(final TilePosition actualLocation) {
142+
this.isStartingLocation = true;
143+
this.location = actualLocation;
144+
this.center =
145+
BwemExt.centerOfBuilding(actualLocation, UnitType.Terran_Command_Center.tileSize());
146+
}
147+
148+
public void onMineralDestroyed(final Mineral mineral) {
149+
// bwem_assert(pMineral);
150+
if (mineral == null) {
151+
throw new IllegalArgumentException();
152+
}
153+
154+
this.minerals.remove(mineral);
155+
this.blockingMinerals.remove(mineral);
156+
}
157+
158+
@Override
159+
public boolean equals(final Object object) {
160+
if (this == object) {
161+
return true;
162+
} else if (!(object instanceof Base)) {
163+
return false;
164+
} else {
165+
final Base that = (Base) object;
166+
return (getArea().equals(that.getArea())
167+
&& getLocation().equals(that.getLocation())
168+
&& getCenter().equals(that.getCenter()));
169+
}
170+
}
171+
172+
@Override
173+
public int hashCode() {
174+
return Objects.hash(this.area, this.location, this.center);
175+
}
87176
}

src/main/java/bwem/BaseImpl.java

Lines changed: 0 additions & 133 deletions
This file was deleted.

0 commit comments

Comments
 (0)